me
/
guix
Archived
1
0
Fork 0

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>
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
1 changed files with 97 additions and 84 deletions

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,91 +881,102 @@ 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)
(srfi srfi-1) ((#:modules modules '())
(guix build gnu-build-system) `((ice-9 ftw)
(guix build kconfig) (srfi srfi-1)
(guix build utils)) (guix build gnu-build-system)
#:imported-modules (,@%gnu-build-system-modules (guix build kconfig)
(guix build kconfig)) (guix build utils)
#:test-target "test" ,@modules))
#:make-flags ((#:imported-modules imported-modules '())
(list "HOSTCC=gcc" `((guix build kconfig)
"KBUILD_VERBOSE=1" ,@%gnu-build-system-modules
,@(if (not (same-arch?)) ,@imported-modules))
`((string-append "CROSS_COMPILE=" ,triplet "-")) ((#:test-target _ "test")
'())) "test")
#:phases ((#:make-flags make-flags '())
(modify-phases %standard-phases #~(list "HOSTCC=gcc"
(replace 'configure "KBUILD_VERBOSE=1"
(lambda* (#:key outputs make-flags #:allow-other-keys) #$@(if (not (same-arch?))
(let* ((config-name (string-append ,board "_defconfig")) (list (string-append "CROSS_COMPILE=" triplet "-"))
(config-file (string-append "configs/" config-name)) '())
(defconfig ,defconfig) #$@make-flags))
(configs ',configs)) ((#:phases phases '%standard-phases)
(when defconfig #~(modify-phases #$phases
;; Replace the board-specific defconfig with the given one. (replace 'configure
(copy-file defconfig config-file)) (lambda* (#:key make-flags #:allow-other-keys)
(if (file-exists? config-file) (let* ((config-name (string-append #$board "_defconfig"))
(begin (config-file (string-append "configs/" config-name))
(when configs (defconfig #$defconfig)
(modify-defconfig config-file configs)) (configs '#$configs))
(apply invoke "make" `(,@make-flags ,config-name)) (when defconfig
(verify-config ".config" config-file)) ;; Replace the board-specific defconfig with the given
(begin ;; one.
(display "invalid board name; valid board names are:" (copy-file defconfig config-file))
(current-error-port)) (if (file-exists? config-file)
(let ((suffix-len (string-length "_defconfig")) (begin
(entries (scandir "configs"))) (when configs
(for-each (lambda (file-name) (modify-defconfig config-file configs))
(when (string-suffix? "_defconfig" file-name) (apply invoke "make" `(,@make-flags ,config-name))
(format (current-error-port) (verify-config ".config" config-file))
"- ~A\n" (begin
(string-drop-right file-name (display "invalid board name; valid board names are:"
suffix-len)))) (current-error-port))
(sort entries string-ci<))) (let ((suffix-len (string-length "_defconfig"))
(error "invalid boardname ~s" ,board)))))) (entries (scandir "configs")))
(add-after 'configure 'disable-tools-libcrypto (for-each (lambda (file-name)
;; Disable libcrypto due to GPL and OpenSSL license (when (string-suffix? "_defconfig"
;; incompatibilities file-name)
(lambda _ (format (current-error-port)
(substitute* ".config" "- ~A\n"
(("CONFIG_TOOLS_LIBCRYPTO=.*$") "CONFIG_TOOLS_LIBCRYPTO=n")))) (string-drop-right
(replace 'install file-name suffix-len))))
(lambda* (#:key outputs #:allow-other-keys) (sort entries string-ci<)))
(let* ((out (assoc-ref outputs "out")) (error "invalid boardname ~s" #$board))))))
(libexec (string-append out "/libexec")) (add-after 'configure 'disable-tools-libcrypto
(uboot-files (append ;; Disable libcrypto due to GPL and OpenSSL license
(remove ;; incompatibilities
;; Those would not be reproducible (lambda _
;; because of the randomness used (substitute* ".config"
;; to produce them. (("CONFIG_TOOLS_LIBCRYPTO=.*$")
;; It's expected that the user will "CONFIG_TOOLS_LIBCRYPTO=n"))))
;; use u-boot-tools to generate them (replace 'install
;; instead. (lambda _
(lambda (name) (let ((libexec (string-append #$output "/libexec"))
(string-suffix? (uboot-files
"sunxi-spl-with-ecc.bin" (append
name)) (remove
(find-files "." ".*\\.(bin|efi|img|spl|itb|dtb|rksd)$")) ;; Those would not be reproducible
(find-files "." "^(MLO|SPL)$")))) ;; because of the randomness used to
(mkdir-p libexec) ;; produce them. It's expected that the
(install-file ".config" libexec) ;; user will use u-boot-tools to generate
;; Useful for "qemu -kernel". ;; them instead.
(install-file "u-boot" libexec) (lambda (name)
(for-each (string-suffix?
(lambda (file) "sunxi-spl-with-ecc.bin"
(let ((target-file (string-append libexec "/" file))) name))
(mkdir-p (dirname target-file)) (find-files "."
(copy-file file target-file))) ".*\\.(bin|efi|img|spl|itb|dtb|rksd)$"))
uboot-files) (find-files "." "^(MLO|SPL)$"))))
#t))))))))) (mkdir-p libexec)
(install-file ".config" libexec)
;; Useful for "qemu -kernel".
(install-file "u-boot" libexec)
(for-each
(lambda (file)
(let ((target-file (string-append libexec "/" file)))
(mkdir-p (dirname target-file))
(copy-file file target-file)))
uboot-files)))))))))))
(define-public u-boot-am335x-boneblack (define-public u-boot-am335x-boneblack
(let ((base (make-u-boot-package (let ((base (make-u-boot-package