Subject: [PATCH 2/3] gnu: bootloader: Add orangepi-r1-plus-lts-rk3328 bootloader.

From: Herman Rimm <[email-masked]>
Date: Sat, 18 Nov 2023 17:01:27 +0100

* gnu/bootloader/u-boot.scm (install-orangepi-r1-plus-lts-rk3328-u-boot,
  u-boot-orangepi-r1-plus-lts-rk3328-bootloader): New variables.
* gnu/packages/bootloaders.scm (u-boot-orangepi-r1-plus-lts-rk3328): New
  variable.
---
 gnu/bootloader/u-boot.scm    | 17 +++++++++++++++++
 gnu/packages/bootloaders.scm | 15 +++++++++++++++
 2 files changed, 32 insertions(+)

diff --git a/gnu/bootloader/u-boot.scm b/gnu/bootloader/u-boot.scm
index 712db15b02..d20aabd538 100644
--- a/gnu/bootloader/u-boot.scm
+++ b/gnu/bootloader/u-boot.scm
@@ -5,6 +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]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -37,6 +38,7 @@ (define-module (gnu bootloader u-boot)
             u-boot-mx6cuboxi-bootloader
             u-boot-nintendo-nes-classic-edition-bootloader
             u-boot-novena-bootloader
+            u-boot-orangepi-r1-plus-lts-rk3328-bootloader
             u-boot-pine64-plus-bootloader
             u-boot-pine64-lts-bootloader
             u-boot-pinebook-bootloader
@@ -93,6 +95,15 @@ (define install-imx-u-boot
         (write-file-on-device u-boot (stat:size (stat u-boot))
                               image (* 69 1024)))))
 
+(define install-orangepi-r1-plus-lts-rk3328-u-boot
+  #~(lambda (bootloader root-index image)
+      (let ((idb (string-append bootloader "/libexec/idbloader.img"))
+            (u-boot (string-append bootloader "/libexec/u-boot.itb")))
+        (write-file-on-device idb (stat:size (stat idb))
+                              image (* 64 512))
+        (write-file-on-device u-boot (stat:size (stat u-boot))
+                              image (* 16384 512)))))
+
 (define install-puma-rk3399-u-boot
   #~(lambda (bootloader root-index image)
       (let ((spl (string-append bootloader "/libexec/idbloader.img"))
@@ -233,6 +244,12 @@ (define u-boot-novena-bootloader
    (inherit u-boot-imx-bootloader)
    (package u-boot-novena)))
 
+(define u-boot-orangepi-r1-plus-lts-rk3328-bootloader
+  (bootloader
+   (inherit u-boot-bootloader)
+   (package u-boot-orangepi-r1-plus-lts-rk3328)
+   (disk-image-installer install-orangepi-r1-plus-lts-rk3328-u-boot)))
+
 (define u-boot-pine64-plus-bootloader
   (bootloader
    (inherit u-boot-allwinner64-bootloader)
diff --git a/gnu/packages/bootloaders.scm b/gnu/packages/bootloaders.scm
index 5da696388a..e88abe2dec 100644
--- a/gnu/packages/bootloaders.scm
+++ b/gnu/packages/bootloaders.scm
@@ -1128,6 +1128,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-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))))))
+
 (define-public u-boot-cubieboard
   (make-u-boot-package "Cubieboard" "arm-linux-gnueabihf"))
 
-- 
2.41.0