gnu: make-u-boot-package: Add a u-boot argument and use gexps.

And have that u-boot argument used as the complete base of the template, so
that a user can override it.

* gnu/packages/bootloaders.scm (make-u-boot-package): New U-BOOT argument.
Document it.
[native-inputs]: Move the native-inputs of U-BOOT first, so that the
cross compilation tools can be overridden via U-BOOT.
[arguments]: Rewrite using substitute-keyword-arguments, extending rather than
overriding most arguments.  Use gexps.  Do not bind OUTPUTS.

Signed-off-by: Maxim Cournoyer <maxim.cournoyer@gmail.com>
This commit is contained in:
Maxim Cournoyer 2022-12-01 16:20:54 -05:00
parent 358ae8e12e
commit d970d6a04a
No known key found for this signature in database
GPG key ID: 1260E46482E63562

View file

@ -860,11 +860,13 @@ def test_ctrl_c"))
defconfig defconfig
configs configs
name-suffix name-suffix
append-description) append-description
(u-boot u-boot))
"Return a U-Boot package for BOARD cross-compiled for TRIPLET with the "Return a U-Boot package for BOARD cross-compiled for TRIPLET with the
optional DEFCONFIG file and optional configuration changes from CONFIGS. optional DEFCONFIG file and optional configuration changes from CONFIGS.
NAME-SUFFIX is appended to the package name, while APPEND-DESCRIPTION is NAME-SUFFIX is appended to the package name, while APPEND-DESCRIPTION is
appended to the package description." appended to the package description. U-BOOT can be used when a fork or a
different version of U-Boot must be used."
(let ((same-arch? (lambda () (let ((same-arch? (lambda ()
(string=? (%current-system) (string=? (%current-system)
(gnu-triplet->nix-system triplet))))) (gnu-triplet->nix-system triplet)))))
@ -879,36 +881,46 @@ appended to the package description."
"\n\n" append-description) "\n\n" append-description)
(package-description u-boot))) (package-description u-boot)))
(native-inputs (native-inputs
`(,@(if (not (same-arch?)) ;; Note: leave the native u-boot inputs first, so that a user can
;; override the cross-gcc and cross-binutils packages.
`(,@(package-native-inputs u-boot)
,@(if (not (same-arch?))
`(("cross-gcc" ,(cross-gcc triplet)) `(("cross-gcc" ,(cross-gcc triplet))
("cross-binutils" ,(cross-binutils triplet))) ("cross-binutils" ,(cross-binutils triplet)))
`()) `())))
,@(package-native-inputs u-boot)))
(arguments (arguments
`(#:modules ((ice-9 ftw) (substitute-keyword-arguments (package-arguments u-boot)
((#:modules modules '())
`((ice-9 ftw)
(srfi srfi-1) (srfi srfi-1)
(guix build gnu-build-system) (guix build gnu-build-system)
(guix build kconfig) (guix build kconfig)
(guix build utils)) (guix build utils)
#:imported-modules (,@%gnu-build-system-modules ,@modules))
(guix build kconfig)) ((#:imported-modules imported-modules '())
#:test-target "test" `((guix build kconfig)
#:make-flags ,@%gnu-build-system-modules
(list "HOSTCC=gcc" ,@imported-modules))
((#:test-target _ "test")
"test")
((#:make-flags make-flags '())
#~(list "HOSTCC=gcc"
"KBUILD_VERBOSE=1" "KBUILD_VERBOSE=1"
,@(if (not (same-arch?)) #$@(if (not (same-arch?))
`((string-append "CROSS_COMPILE=" ,triplet "-")) (list (string-append "CROSS_COMPILE=" triplet "-"))
'())) '())
#:phases #$@make-flags))
(modify-phases %standard-phases ((#:phases phases '%standard-phases)
#~(modify-phases #$phases
(replace 'configure (replace 'configure
(lambda* (#:key outputs make-flags #:allow-other-keys) (lambda* (#:key make-flags #:allow-other-keys)
(let* ((config-name (string-append ,board "_defconfig")) (let* ((config-name (string-append #$board "_defconfig"))
(config-file (string-append "configs/" config-name)) (config-file (string-append "configs/" config-name))
(defconfig ,defconfig) (defconfig #$defconfig)
(configs ',configs)) (configs '#$configs))
(when defconfig (when defconfig
;; Replace the board-specific defconfig with the given one. ;; Replace the board-specific defconfig with the given
;; one.
(copy-file defconfig config-file)) (copy-file defconfig config-file))
(if (file-exists? config-file) (if (file-exists? config-file)
(begin (begin
@ -922,36 +934,38 @@ appended to the package description."
(let ((suffix-len (string-length "_defconfig")) (let ((suffix-len (string-length "_defconfig"))
(entries (scandir "configs"))) (entries (scandir "configs")))
(for-each (lambda (file-name) (for-each (lambda (file-name)
(when (string-suffix? "_defconfig" file-name) (when (string-suffix? "_defconfig"
file-name)
(format (current-error-port) (format (current-error-port)
"- ~A\n" "- ~A\n"
(string-drop-right file-name (string-drop-right
suffix-len)))) file-name suffix-len))))
(sort entries string-ci<))) (sort entries string-ci<)))
(error "invalid boardname ~s" ,board)))))) (error "invalid boardname ~s" #$board))))))
(add-after 'configure 'disable-tools-libcrypto (add-after 'configure 'disable-tools-libcrypto
;; Disable libcrypto due to GPL and OpenSSL license ;; Disable libcrypto due to GPL and OpenSSL license
;; incompatibilities ;; incompatibilities
(lambda _ (lambda _
(substitute* ".config" (substitute* ".config"
(("CONFIG_TOOLS_LIBCRYPTO=.*$") "CONFIG_TOOLS_LIBCRYPTO=n")))) (("CONFIG_TOOLS_LIBCRYPTO=.*$")
"CONFIG_TOOLS_LIBCRYPTO=n"))))
(replace 'install (replace 'install
(lambda* (#:key outputs #:allow-other-keys) (lambda _
(let* ((out (assoc-ref outputs "out")) (let ((libexec (string-append #$output "/libexec"))
(libexec (string-append out "/libexec")) (uboot-files
(uboot-files (append (append
(remove (remove
;; Those would not be reproducible ;; Those would not be reproducible
;; because of the randomness used ;; because of the randomness used to
;; to produce them. ;; produce them. It's expected that the
;; It's expected that the user will ;; user will use u-boot-tools to generate
;; use u-boot-tools to generate them ;; them instead.
;; instead.
(lambda (name) (lambda (name)
(string-suffix? (string-suffix?
"sunxi-spl-with-ecc.bin" "sunxi-spl-with-ecc.bin"
name)) name))
(find-files "." ".*\\.(bin|efi|img|spl|itb|dtb|rksd)$")) (find-files "."
".*\\.(bin|efi|img|spl|itb|dtb|rksd)$"))
(find-files "." "^(MLO|SPL)$")))) (find-files "." "^(MLO|SPL)$"))))
(mkdir-p libexec) (mkdir-p libexec)
(install-file ".config" libexec) (install-file ".config" libexec)
@ -962,8 +976,7 @@ appended to the package description."
(let ((target-file (string-append libexec "/" file))) (let ((target-file (string-append libexec "/" file)))
(mkdir-p (dirname target-file)) (mkdir-p (dirname target-file))
(copy-file file target-file))) (copy-file file target-file)))
uboot-files) uboot-files)))))))))))
#t)))))))))
(define-public u-boot-am335x-boneblack (define-public u-boot-am335x-boneblack
(let ((base (make-u-boot-package (let ((base (make-u-boot-package