Subject: [PATCH 4/4] gnu: Add make-u-boot-rockchip-package procedure.

From: Herman Rimm <[email-masked]>
Date: Thu, 12 Dec 2024 22:07:11 +0100

* gnu/packages/bootloaders.scm (make-u-boot-rockchip-package): Add.
(u-boot-orangepi-r1-plus-lts-rk3328, u-boot-puma-rk3399,
u-boot-rock64-rk3328, u-boot-firefly-rk3399, u-boot-rockpro64-rk3399,
u-boot-pinebook-pro-rk3399): Use procedure.

Change-Id: I0d7632e46cfed312f8b2843c6fafc912077bc241
---
 gnu/packages/bootloaders.scm | 136 +++++++++++------------------------
 1 file changed, 41 insertions(+), 95 deletions(-)

diff --git a/gnu/packages/bootloaders.scm b/gnu/packages/bootloaders.scm
index 15cdaddd7e..8d3cda760a 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, 2024 Maxim Cournoyer <[email-masked]>
-;;; Copyright © 2023 Herman Rimm <[email-masked]>
+;;; Copyright © 2023-2024 Herman Rimm <[email-masked]>
 ;;; Copyright © 2023 Simon Tournier <[email-masked]>
 ;;; Copyright © 2024 Zheng Junjie <[email-masked]>
 ;;;
@@ -1145,6 +1145,27 @@ (define*-public (make-u-boot-package board triplet
                          (copy-file file target-file)))
                      uboot-files)))))))))))
 
+(define* (make-u-boot-rockchip-package board soc #:optional configs)
+  "Return the U-Boot package for BOARD with AAarch64 Rockchip SOC
+(System on Chip)."
+  (let* ((board (string-append board "-" (symbol->string soc)))
+         (base (make-u-boot-package board "aarch64-linux-gnu"
+                                    #:configs configs))
+         (atf (match soc
+                ('rk3399 arm-trusted-firmware-rk3399)
+                ('rk3328 arm-trusted-firmware-rk3328))))
+    (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)
+                  (let ((atf (assoc-ref inputs #$(package-name atf))))
+                    (setenv "BL31" (string-append atf "/bl31.elf")))))))))
+      (inputs (modify-inputs (package-inputs base) (append atf))))))
+
 (define-public u-boot-am335x-boneblack
   (let ((base (make-u-boot-package
                "am335x_evm" "arm-linux-gnueabihf"
@@ -1260,19 +1281,7 @@ (define-public u-boot-novena
 partition."))
 
 (define-public u-boot-orangepi-r1-plus-lts-rk3328
-  (let ((base (make-u-boot-package "orangepi-r1-plus-lts-rk3328" "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 native-inputs inputs #:allow-other-keys)
-                  (setenv "BL31" (search-input-file inputs "bl31.elf"))))))))
-      (inputs
-       (modify-inputs (package-inputs base)
-         (append arm-trusted-firmware-rk3328))))))
+  (make-u-boot-rockchip-package "orangepi-r1-plus-lts" 'rk3328))
 
 (define-public u-boot-cubieboard
   (make-u-boot-package "Cubieboard" "arm-linux-gnueabihf"))
@@ -1281,22 +1290,7 @@ (define-public u-boot-cubietruck
   (make-u-boot-package "Cubietruck" "arm-linux-gnueabihf"))
 
 (define-public u-boot-puma-rk3399
-  (let ((base (make-u-boot-package "puma-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"))))
-              ;; Phases do not succeed on the bl31 ELF.
-              (delete 'strip)
-              (delete 'validate-runpath)))))
-      (inputs
-       (modify-inputs (package-inputs base)
-         (append arm-trusted-firmware-rk3399))))))
+  (make-u-boot-rockchip-package "puma" 'rk3399))
 
 (define-public u-boot-qemu-arm
   (make-u-boot-package "qemu_arm" "arm-linux-gnueabihf"
@@ -1417,87 +1411,39 @@ (define-public u-boot-starfive-visionfive2
          (append opensbi-for-visionfive2))))))
 
 (define-public u-boot-rock64-rk3328
-  (let ((base (make-u-boot-package "rock64-rk3328" "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 native-inputs inputs #:allow-other-keys)
-                  (setenv "BL31" (search-input-file inputs "bl31.elf"))))))))
-      (inputs
-       (modify-inputs (package-inputs base)
-         (append arm-trusted-firmware-rk3328))))))
+  (make-u-boot-rockchip-package "rock64" 'rk3328))
 
 (define-public u-boot-firefly-rk3399
-  (let ((base (make-u-boot-package "firefly-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 native-inputs inputs #:allow-other-keys)
-                  (setenv "BL31" (search-input-file inputs "bl31.elf"))))
-              ;; Phases do not succeed on the bl31 ELF.
-              (delete 'strip)
-              (delete 'validate-runpath)))))
-      (inputs
-       (modify-inputs (package-inputs base)
-         (append arm-trusted-firmware-rk3399))))))
+  (make-u-boot-rockchip-package "firefly" 'rk3399))
 
 (define-public u-boot-rockpro64-rk3399
-  (let ((base (make-u-boot-package "rockpro64-rk3399" "aarch64-linux-gnu"
-                                   #:configs '("CONFIG_USB=y"
-                                               "CONFIG_AHCI=y"
-                                               "CONFIG_AHCI_PCI=y"
-                                               "CONFIG_SATA=y"
-                                               "CONFIG_SATA_SIL=y"
-                                               "CONFIG_SCSI=y"
-                                               "CONFIG_SCSI_AHCI=y"
-                                               "CONFIG_DM_SCSI=y"
-                                               ;; Disable SPL FIT signatures,
-                                               ;; due to GPLv2 and Openssl
-                                               ;; license incompatibilities
-                                               "# CONFIG_SPL_FIT_SIGNATURE is not set"))))
+  (let ((base (make-u-boot-rockchip-package
+                "rockpro64" 'rk3399
+                '("CONFIG_USB=y"
+                  "CONFIG_AHCI=y"
+                  "CONFIG_AHCI_PCI=y"
+                  "CONFIG_SATA=y"
+                  "CONFIG_SATA_SIL=y"
+                  "CONFIG_SCSI=y"
+                  "CONFIG_SCSI_AHCI=y"
+                  "CONFIG_DM_SCSI=y"
+                  ;; Disable SPL FIT signatures, due to GPLv2 and
+                  ;; OpenSSL license incompatibilities.
+                  "# CONFIG_SPL_FIT_SIGNATURE is not set"))))
     (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"))))
               (add-after 'unpack 'patch-header
                 (lambda _
                   (substitute* "include/config_distro_bootcmd.h"
                     (("\"scsi_need_init=")
-                     "\"setenv scsi_need_init"))))))))
-      (inputs
-       (modify-inputs (package-inputs base)
-         (append arm-trusted-firmware-rk3399))))))
+                     "\"setenv scsi_need_init")))))))))))
 
 (define-public u-boot-pinebook-pro-rk3399
-  (let ((base (make-u-boot-package "pinebook-pro-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 native-inputs inputs #:allow-other-keys)
-                  (setenv "BL31" (search-input-file inputs "bl31.elf"))))
-              ;; Phases do not succeed on the bl31 ELF.
-              (delete 'strip)
-              (delete 'validate-runpath)))))
-      (inputs
-       (modify-inputs (package-inputs base)
-         (append arm-trusted-firmware-rk3399))))))
+  (make-u-boot-rockchip-package "pinebook-pro" 'rk3399))
 
 (define*-public (make-u-boot-bin-package u-boot-package
                                          #:key
-- 
2.45.2