Subject: [PATCH v3 5/5] gnu: bootloader: Add ASUS Tinker Board S bootloader.

From: Herman Rimm <[email-masked]>
Date: Fri, 13 Dec 2024 22:07:36 +0100

* gnu/bootloader/u-boot.scm (install-tinker-s-rk3288-u-boot,
u-boot-tinker-s-rk3288-bootloader): Add variables.
* gnu/packages/bootloaders.scm (u-boot)[native-inputs]: Add bc.
(u-boot-tinker-s-rk3288): Add variable.
* gnu/packages/firmware.scm (arm-trusted-firmware-rk3288): Add variable.

Change-Id: Ic28193d4377c672f4cbbac4cc059e283fcfb06e0
---
 gnu/bootloader/u-boot.scm    | 10 ++++++++++
 gnu/packages/bootloaders.scm | 20 +++++++++++++++++++-
 gnu/packages/firmware.scm    |  6 ++++++
 3 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/gnu/bootloader/u-boot.scm b/gnu/bootloader/u-boot.scm
index 52527ab0db..0d6cd5c6a8 100644
--- a/gnu/bootloader/u-boot.scm
+++ b/gnu/bootloader/u-boot.scm
@@ -53,6 +53,7 @@ (define-module (gnu bootloader u-boot)
             u-boot-sifive-unmatched-bootloader
             u-boot-qemu-riscv64-bootloader
             u-boot-starfive-visionfive2-bootloader
+            u-boot-tinker-s-rk3288-bootloader
             u-boot-ts7970-q-2g-1000mhz-c-bootloader
             u-boot-wandboard-bootloader))
 
@@ -115,6 +116,9 @@ (define install-puma-rk3399-u-boot
 (define install-rockchip-u-boot
   (write-u-boot-image '(("idbloader.img" 64) ("u-boot.itb" 16384)) 512))
 
+(define install-tinker-s-rk3288-u-boot
+  (write-u-boot-image '(("idbloader.img" 64) ("u-boot.img" 16384)) 512))
+
 (define install-sifive-unmatched-u-boot
   (write-u-boot-image '(("spl/u-boot-spl.bin" 34) ("u-boot.itb" 2082))
                       512))
@@ -273,6 +277,12 @@ (define u-boot-pinebook-pro-rk3399-bootloader
    (inherit u-boot-rockchip-bootloader)
    (package u-boot-pinebook-pro-rk3399)))
 
+(define u-boot-tinker-s-rk3288-bootloader
+  (bootloader
+    (inherit u-boot-bootloader)
+    (package u-boot-tinker-s-rk3288)
+    (disk-image-installer install-tinker-s-rk3288-u-boot)))
+
 (define u-boot-ts7970-q-2g-1000mhz-c-bootloader
   ;; This bootloader doesn't really need to be installed, as it is read from
   ;; an SPI memory chip, not the SD card.  It is copied to /boot/u-boot.imx
diff --git a/gnu/packages/bootloaders.scm b/gnu/packages/bootloaders.scm
index b91ff00e28..4516e343b2 100644
--- a/gnu/packages/bootloaders.scm
+++ b/gnu/packages/bootloaders.scm
@@ -39,6 +39,7 @@
 
 (define-module (gnu packages bootloaders)
   #:use-module (gnu packages)
+  #:use-module (gnu packages algebra)
   #:use-module (gnu packages assembly)
   #:use-module (gnu packages base)
   #:use-module (gnu packages disk)
@@ -763,7 +764,8 @@ (define u-boot
                                 "u-boot-rockchip-inno-usb.patch"))))
     (build-system gnu-build-system)
     (native-inputs
-     (list bison
+     (list bc
+           bison
            dtc
            gnutls
            flex
@@ -1308,6 +1310,22 @@ (define-public u-boot-cubietruck
 (define-public u-boot-puma-rk3399
   (make-u-boot-rockchip-package "puma" 'rk3399))
 
+(define-public u-boot-tinker-s-rk3288
+  (let ((base (make-u-boot-package "tinker-s-rk3288" "arm-linux-gnueabihf")))
+    (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)
+                  ;; ARMv7 does not have the BL31 stage.
+                  (setenv "BL32" (search-input-file inputs "/bl32.elf"))))))))
+      (inputs
+       (modify-inputs (package-inputs base)
+         (append arm-trusted-firmware-rk3288))))))
+
 (define-public u-boot-qemu-arm
   (make-u-boot-package "qemu_arm" "arm-linux-gnueabihf"
                        ;; Disable features that require OpenSSL due
diff --git a/gnu/packages/firmware.scm b/gnu/packages/firmware.scm
index d89b136c86..670cef5a02 100644
--- a/gnu/packages/firmware.scm
+++ b/gnu/packages/firmware.scm
@@ -1171,6 +1171,12 @@ (define-public arm-trusted-firmware-sun50i-a64
 (define-public arm-trusted-firmware-sun50i-h616
   (make-arm-trusted-firmware "sun50i_h616"))
 
+(define-public arm-trusted-firmware-rk3288
+  (make-arm-trusted-firmware "rk3288" #:triplet "arm-linux-gnueabihf"
+                             #:make-flags '("ARCH=aarch32"
+                                            "AARCH32_SP=sp_min"
+                                            "DEBUG=1")))
+
 (define-public arm-trusted-firmware-rk3328
   (make-arm-trusted-firmware "rk3328"))
 
-- 
2.45.2