Subject: [PATCH v2 1/8] gnu: bootloader: Add nanopi-r4s-rk3399 bootloader.

From: Herman Rimm <[email-masked]>
Date: Mon, 26 Aug 2024 16:45:00 +0200

* gnu/bootloader/u-boot.scm (install-nanopi-r4s-rk3399-u-boot,
u-boot-nanopi-r4s-rk3399-bootloader): Add variable.
* gnu/packages/bootloaders.scm (u-boot-nanopi-r4s-rk3399): Add variable.

Change-Id: I6d4cb098727fe4027aea33a39c59d34000dfc4db
---
 gnu/bootloader/u-boot.scm    | 18 +++++++++++++++++-
 gnu/packages/bootloaders.scm | 17 ++++++++++++++++-
 2 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/gnu/bootloader/u-boot.scm b/gnu/bootloader/u-boot.scm
index c5437a7b63..7888a4e030 100644
--- a/gnu/bootloader/u-boot.scm
+++ b/gnu/bootloader/u-boot.scm
@@ -5,7 +5,7 @@
 ;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <[email-masked]>
 ;;; Copyright © 2022 Maxim Cournoyer <[email-masked]>
 ;;; Copyright © 2023 Efraim Flashner <[email-masked]>
-;;; Copyright © 2023 Herman Rimm <[email-masked]>
+;;; Copyright © 2023-2024 Herman Rimm <[email-masked]>
 ;;; Copyright © 2024 Zheng Junjie <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
@@ -37,6 +37,7 @@ (define-module (gnu bootloader u-boot)
             u-boot-cubietruck-bootloader
             u-boot-firefly-rk3399-bootloader
             u-boot-mx6cuboxi-bootloader
+            u-boot-nanopi-r4s-rk3399-bootloader
             u-boot-nintendo-nes-classic-edition-bootloader
             u-boot-novena-bootloader
             u-boot-orangepi-r1-plus-lts-rk3328-bootloader
@@ -98,6 +99,15 @@ (define install-imx-u-boot
         (write-file-on-device u-boot (stat:size (stat u-boot))
                               image (* 69 1024)))))
 
+(define install-nanopi-r4s-rk3399-u-boot
+  #~(lambda (bootloader root-index image)
+      (let ((spl (string-append bootloader "/libexec/idbloader.img"))
+            (u-boot (string-append bootloader "/libexec/u-boot.itb")))
+        (write-file-on-device spl (stat:size (stat spl))
+                              image (* 64 512))
+        (write-file-on-device u-boot (stat:size (stat u-boot))
+                              image (* 16384 512)))))
+
 (define install-orangepi-r1-plus-lts-rk3328-u-boot
   #~(lambda (bootloader root-index image)
       (let ((idb (string-append bootloader "/libexec/idbloader.img"))
@@ -274,6 +284,12 @@ (define u-boot-novena-bootloader
    (inherit u-boot-imx-bootloader)
    (package u-boot-novena)))
 
+(define u-boot-nanopi-r4s-rk3399-bootloader
+  (bootloader
+   (inherit u-boot-bootloader)
+   (package u-boot-nanopi-r4s-rk3399)
+   (disk-image-installer install-nanopi-r4s-rk3399-u-boot)))
+
 (define u-boot-orangepi-r1-plus-lts-rk3328-bootloader
   (bootloader
    (inherit u-boot-bootloader)
diff --git a/gnu/packages/bootloaders.scm b/gnu/packages/bootloaders.scm
index 4072df50d7..f42d42c1c4 100644
--- a/gnu/packages/bootloaders.scm
+++ b/gnu/packages/bootloaders.scm
@@ -18,7 +18,7 @@
 ;;; Copyright © 2022, 2023 Denis 'GNUtoo' Carikli <[email-masked]>
 ;;; Copyright © 2021 Stefan <[email-masked]>
 ;;; Copyright © 2022, 2023 Maxim Cournoyer <[email-masked]>
-;;; Copyright © 2023 Herman Rimm <[email-masked]>
+;;; Copyright © 2023-2024 Herman Rimm <[email-masked]>
 ;;; Copyright © 2024 Zheng Junjie <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
@@ -1237,6 +1237,21 @@ (define-public u-boot-novena
 version, contrary to Novena upstream, does not load u-boot.img from the first
 partition."))
 
+(define-public u-boot-nanopi-r4s-rk3399
+  (let ((base (make-u-boot-package "nanopi-r4s-rk3399" "aarch64-linux-gnu")))
+    (package
+      (inherit base)
+      (arguments
+       (substitute-keyword-arguments (package-arguments base)
+         ((#:phases phases)
+          #~(modify-phases #$phases
+              (add-after 'unpack 'set-environment
+                (lambda* (#:key inputs #:allow-other-keys)
+                  (setenv "BL31" (search-input-file inputs "/bl31.elf"))))))))
+      (inputs
+       (modify-inputs (package-inputs base)
+         (append arm-trusted-firmware-rk3399))))))
+
 (define-public u-boot-orangepi-r1-plus-lts-rk3328
   (let ((base (make-u-boot-package "orangepi-r1-plus-lts-rk3328" "aarch64-linux-gnu")))
     (package
-- 
2.45.2