summary refs log tree commit diff
path: root/gnu/packages/firmware.scm
diff options
context:
space:
mode:
authorMaxim Cournoyer <maxim.cournoyer@gmail.com>2023-01-11 09:40:36 -0500
committerMaxim Cournoyer <maxim.cournoyer@gmail.com>2023-01-18 21:04:25 -0500
commit4276283b30eb73359e27c7737b78655fed0a664f (patch)
treed224af986cc48faa6b95a84438e98496afdfd40b /gnu/packages/firmware.scm
parentea0d3e1ec47171eb70f5c5ef25cff583138abfb9 (diff)
downloadguix-4276283b30eb73359e27c7737b78655fed0a664f.tar.gz
gnu: make-arm-trusted-firmware: Simplify build.
Reuse knowledge from recent U-Boot modifications to streamline the package
definition.

* gnu/packages/firmware.scm (make-arm-trusted-firmware): Change optional
argument ARCH to keyword TRIPLET.  Default to aarch64-linux-gnu.
[arguments]: Use gexps.  Add a #:target argument.  Streamline how the
CROSS_COMPILE make flag is computed.
[native-inputs]: Delete field.

Signed-off-by: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Diffstat (limited to 'gnu/packages/firmware.scm')
-rw-r--r--gnu/packages/firmware.scm116
1 files changed, 52 insertions, 64 deletions
diff --git a/gnu/packages/firmware.scm b/gnu/packages/firmware.scm
index b6ee4c0565..029e84d5c2 100644
--- a/gnu/packages/firmware.scm
+++ b/gnu/packages/firmware.scm
@@ -8,7 +8,7 @@
 ;;; Copyright © 2019 Mathieu Othacehe <m.othacehe@gmail.com>
 ;;; Copyright © 2020, 2021, 2022 Marius Bakke <marius@gnu.org>
 ;;; Copyright © 2021 Petr Hodina <phodina@protonmail.com>
-;;; Copyright © 2022 Maxim Cournoyer <maxim.cournoyer@gmail.com>
+;;; Copyright © 2022, 2023 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -944,70 +944,58 @@ Virtual Machines.  OVMF contains a sample UEFI firmware for QEMU and KVM.")
                              (string-append fmw "/ovmf_arm.bin")))))))))
     (supported-systems %supported-systems)))
 
-(define* (make-arm-trusted-firmware platform #:optional (arch "aarch64"))
-  (package
-    (name (string-append "arm-trusted-firmware-" platform))
-    (version "2.8")
-    (source
-      (origin
-        (method git-fetch)
-        (uri (git-reference
+(define* (make-arm-trusted-firmware platform
+                                    #:key (triplet "aarch64-linux-gnu"))
+  (let ((native-build? (lambda ()
+                         ;; Note: %current-system is a *triplet*, unlike its
+                         ;; name would suggest.
+                         (or (not triplet) ;disable cross-compilation
+                             (string=? (%current-system)
+                                       (gnu-triplet->nix-system triplet))))))
+    (package
+      (name (string-append "arm-trusted-firmware-" platform))
+      (version "2.8")
+      (source
+       (origin
+         (method git-fetch)
+         (uri (git-reference
                ;; There are only GitHub generated release snapshots.
                (url "https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/")
                (commit (string-append "v" version))))
-        (file-name (git-file-name "arm-trusted-firmware" version))
-       (sha256
-        (base32
-         "0grq3fgxi9xhcljnhwlxjvdghyz15gaq50raw41xy4lm8rkmnzp3"))
-       (snippet
-        #~(begin
-            (use-modules (guix build utils))
-            ;; Remove binary blobs which do not contain source or proper license.
-            (for-each (lambda (file)
-                        (delete-file file))
-                      (find-files "." "\\.bin$"))))))
-    (build-system gnu-build-system)
-    (arguments
-     `(#:phases
-       (modify-phases %standard-phases
-         (delete 'configure) ; no configure script
-         (replace 'install
-           (lambda* (#:key outputs #:allow-other-keys)
-             (let ((out (assoc-ref outputs "out"))
-                   (bin (find-files "." "\\.(bin|elf)$")))
-               (for-each
-                 (lambda (file)
-                   (install-file file out))
-                 bin)))))
-       #:make-flags (list (string-append "PLAT=" ,platform)
-                          ,@(if (and (not (string-prefix? "aarch64"
-                                                          (%current-system)))
-                                     (string-prefix? "aarch64" arch))
-                              `("CROSS_COMPILE=aarch64-linux-gnu-")
-                              '())
-                          ,@(if (and (not (string-prefix? "armhf"
-                                                          (%current-system)))
-                                     (string-prefix? "armhf" arch))
-                              `("CROSS_COMPILE=arm-linux-gnueabihf-")
-                              '())
-                          "DEBUG=1")
-       #:tests? #f)) ; no tests
-    (native-inputs
-     (let ((system (%current-system)))
-       (cond
-        ((and (not (string-prefix? "aarch64" system))
-              (string-prefix? "aarch64" arch))
-         (list (cross-gcc "aarch64-linux-gnu")
-               (cross-binutils "aarch64-linux-gnu")))
-        ((and (not (string-prefix? "armhf" system))
-              (string-prefix? "armhf" arch))
-         (list (cross-gcc "arm-linux-gnueabihf")
-               (cross-binutils "arm-linux-gnueabihf")))
-        (else '()))))
-    (home-page "https://www.trustedfirmware.org/")
-    (synopsis "Implementation of \"secure world software\"")
-    (description
-     "ARM Trusted Firmware provides a reference implementation of secure world
+         (file-name (git-file-name "arm-trusted-firmware" version))
+         (sha256
+          (base32
+           "0grq3fgxi9xhcljnhwlxjvdghyz15gaq50raw41xy4lm8rkmnzp3"))
+         (snippet
+          #~(begin
+              (use-modules (guix build utils))
+              ;; Remove binary blobs which do not contain source or proper
+              ;; license.
+              (for-each (lambda (file)
+                          (delete-file file))
+                        (find-files "." "\\.bin$"))))))
+      (build-system gnu-build-system)
+      (arguments
+       (list
+        #:target (and (not (native-build?)) triplet)
+        #:phases
+        #~(modify-phases %standard-phases
+            (delete 'configure)         ;no configure script
+            (replace 'install
+              (lambda _
+                (for-each (lambda (file)
+                            (install-file file #$output))
+                          (find-files "." "\\.(bin|elf)$")))))
+        #:make-flags #~(list (string-append "PLAT=" #$platform)
+                             #$@(if (not (native-build?))
+                                    (list (string-append "CROSS_COMPILE=" triplet "-"))
+                                    '())
+                             "DEBUG=1")
+        #:tests? #f))                   ;no test suite
+      (home-page "https://www.trustedfirmware.org/")
+      (synopsis "Implementation of \"secure world software\"")
+      (description
+       "ARM Trusted Firmware provides a reference implementation of secure world
 software for ARMv7A and ARMv8-A, including a Secure Monitor executing at
 @dfn{Exception Level 3} (EL3).  It implements various ARM interface standards,
 such as:
@@ -1018,8 +1006,8 @@ such as:
 @item System Control and Management Interface
 @item Software Delegated Exception Interface (SDEI)
 @end enumerate\n")
-    (license (list license:bsd-3
-                   license:bsd-2)))) ; libfdt
+      (license (list license:bsd-3
+                     license:bsd-2))))) ; libfdt
 
 (define-public arm-trusted-firmware-sun50i-a64
   (let ((base (make-arm-trusted-firmware "sun50i_a64")))