bootloader: Fix u-boot installation.

This is a follow-up of f19cf27c2b. The
bootloader installation must be done on the final disk-image, hence using
"disk-image-installer" instead of "installer" callback.

* gnu/bootloader/u-boot.scm: Turn all installer callbacks into
disk-image-installer callbacks.
* gnu/build/bootloader.scm (write-file-on-device): Open the output file with
'no-truncate and 'no-create options.
* gnu/system/image.scm (with-imported-modules*): Add (gnu build bootloader)
module.
This commit is contained in:
Mathieu Othacehe 2020-10-05 10:58:55 +02:00
parent 525a351efa
commit b97b423e3f
No known key found for this signature in database
GPG key ID: 8354763531769CA6
3 changed files with 47 additions and 39 deletions

View file

@ -45,7 +45,7 @@ (define-module (gnu bootloader u-boot)
u-boot-wandboard-bootloader))
(define install-u-boot
#~(lambda (bootloader device mount-point)
#~(lambda (bootloader root-index image)
(if bootloader
(error "Failed to install U-Boot"))))
@ -56,74 +56,74 @@ (define install-beaglebone-black-u-boot
;; the MLO and is expected at 0x60000. Write both first stage ("MLO") and
;; second stage ("u-boot.img") images, read in BOOTLOADER directory, to the
;; specified DEVICE.
#~(lambda (bootloader device mount-point)
#~(lambda (bootloader root-index image)
(let ((mlo (string-append bootloader "/libexec/MLO"))
(u-boot (string-append bootloader "/libexec/u-boot.img")))
(write-file-on-device mlo (* 256 512)
device (* 256 512))
image (* 256 512))
(write-file-on-device u-boot (* 1024 512)
device (* 768 512)))))
image (* 768 512)))))
(define install-allwinner-u-boot
#~(lambda (bootloader device mount-point)
#~(lambda (bootloader root-index image)
(let ((u-boot (string-append bootloader
"/libexec/u-boot-sunxi-with-spl.bin")))
(write-file-on-device u-boot (stat:size (stat u-boot))
device (* 8 1024)))))
image (* 8 1024)))))
(define install-allwinner64-u-boot
#~(lambda (bootloader device mount-point)
#~(lambda (bootloader root-index image)
(let ((spl (string-append bootloader "/libexec/spl/sunxi-spl.bin"))
(u-boot (string-append bootloader "/libexec/u-boot.itb")))
(write-file-on-device spl (stat:size (stat spl))
device (* 8 1024))
image (* 8 1024))
(write-file-on-device u-boot (stat:size (stat u-boot))
device (* 40 1024)))))
image (* 40 1024)))))
(define install-imx-u-boot
#~(lambda (bootloader device mount-point)
#~(lambda (bootloader root-index image)
(let ((spl (string-append bootloader "/libexec/SPL"))
(u-boot (string-append bootloader "/libexec/u-boot.img")))
(write-file-on-device spl (stat:size (stat spl))
device (* 1 1024))
image (* 1 1024))
(write-file-on-device u-boot (stat:size (stat u-boot))
device (* 69 1024)))))
image (* 69 1024)))))
(define install-puma-rk3399-u-boot
#~(lambda (bootloader device mount-point)
#~(lambda (bootloader root-index image)
(let ((spl (string-append bootloader "/libexec/u-boot-spl.rksd"))
(u-boot (string-append bootloader "/libexec/u-boot.itb")))
(write-file-on-device spl (stat:size (stat spl))
device (* 64 512))
image (* 64 512))
(write-file-on-device u-boot (stat:size (stat u-boot))
device (* 512 512)))))
image (* 512 512)))))
(define install-firefly-rk3399-u-boot
#~(lambda (bootloader device mount-point)
#~(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))
device (* 64 512))
image (* 64 512))
(write-file-on-device u-boot (stat:size (stat u-boot))
device (* 16384 512)))))
image (* 16384 512)))))
(define install-rock64-rk3328-u-boot
#~(lambda (bootloader device mount-point)
#~(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))
device (* 64 512))
image (* 64 512))
(write-file-on-device u-boot (stat:size (stat u-boot))
device (* 16384 512)))))
image (* 16384 512)))))
(define install-rockpro64-rk3399-u-boot
#~(lambda (bootloader device mount-point)
#~(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))
device (* 64 512))
image (* 64 512))
(write-file-on-device u-boot (stat:size (stat u-boot))
device (* 16384 512)))))
image (* 16384 512)))))
(define install-pinebook-pro-rk3399-u-boot install-rockpro64-rk3399-u-boot)
@ -138,28 +138,29 @@ (define u-boot-bootloader
(inherit extlinux-bootloader)
(name 'u-boot)
(package #f)
(installer install-u-boot)))
(installer #f)
(disk-image-installer install-u-boot)))
(define u-boot-beaglebone-black-bootloader
(bootloader
(inherit u-boot-bootloader)
(package u-boot-am335x-boneblack)
(installer install-beaglebone-black-u-boot)))
(disk-image-installer install-beaglebone-black-u-boot)))
(define u-boot-allwinner-bootloader
(bootloader
(inherit u-boot-bootloader)
(installer install-allwinner-u-boot)))
(disk-image-installer install-allwinner-u-boot)))
(define u-boot-allwinner64-bootloader
(bootloader
(inherit u-boot-bootloader)
(installer install-allwinner64-u-boot)))
(disk-image-installer install-allwinner64-u-boot)))
(define u-boot-imx-bootloader
(bootloader
(inherit u-boot-bootloader)
(installer install-imx-u-boot)))
(disk-image-installer install-imx-u-boot)))
(define u-boot-nintendo-nes-classic-edition-bootloader
(bootloader
@ -196,7 +197,7 @@ (define u-boot-firefly-rk3399-bootloader
(bootloader
(inherit u-boot-bootloader)
(package u-boot-firefly-rk3399)
(installer install-firefly-rk3399-u-boot)))
(disk-image-installer install-firefly-rk3399-u-boot)))
(define u-boot-mx6cuboxi-bootloader
(bootloader
@ -232,25 +233,25 @@ (define u-boot-puma-rk3399-bootloader
(bootloader
(inherit u-boot-bootloader)
(package u-boot-puma-rk3399)
(installer install-puma-rk3399-u-boot)))
(disk-image-installer install-puma-rk3399-u-boot)))
(define u-boot-rock64-rk3328-bootloader
;; SD and eMMC use the same format
(bootloader
(inherit u-boot-bootloader)
(package u-boot-rock64-rk3328)
(installer install-rock64-rk3328-u-boot)))
(disk-image-installer install-rock64-rk3328-u-boot)))
(define u-boot-rockpro64-rk3399-bootloader
;; SD and eMMC use the same format
(bootloader
(inherit u-boot-bootloader)
(package u-boot-rockpro64-rk3399)
(installer install-rockpro64-rk3399-u-boot)))
(disk-image-installer install-rockpro64-rk3399-u-boot)))
(define u-boot-pinebook-pro-rk3399-bootloader
;; SD and eMMC use the same format
(bootloader
(inherit u-boot-bootloader)
(package u-boot-pinebook-pro-rk3399)
(installer install-pinebook-pro-rk3399-u-boot)))
(disk-image-installer install-pinebook-pro-rk3399-u-boot)))

View file

@ -22,6 +22,8 @@ (define-module (gnu build bootloader)
#:use-module (guix utils)
#:use-module (ice-9 binary-ports)
#:use-module (ice-9 format)
#:use-module (rnrs io ports)
#:use-module (rnrs io simple)
#:export (write-file-on-device
install-efi-loader))
@ -35,11 +37,14 @@ (define (write-file-on-device file size device offset)
(call-with-input-file file
(lambda (input)
(let ((bv (get-bytevector-n input size)))
(call-with-output-file device
(lambda (output)
(seek output offset SEEK_SET)
(put-bytevector output bv))
#:binary #t)))))
(call-with-port
(open-file-output-port device
(file-options no-truncate no-create)
(buffer-mode block)
(native-transcoder))
(lambda (output)
(seek output offset SEEK_SET)
(put-bytevector output bv)))))))
;;;

View file

@ -202,6 +202,7 @@ (define-syntax-rule (with-imported-modules* gexp* ...)
(with-imported-modules `(,@(source-module-closure
'((gnu build vm)
(gnu build image)
(gnu build bootloader)
(gnu build hurd-boot)
(gnu build linux-boot)
(guix store database))
@ -210,6 +211,7 @@ (define-syntax-rule (with-imported-modules* gexp* ...)
#~(begin
(use-modules (gnu build vm)
(gnu build image)
(gnu build bootloader)
(gnu build hurd-boot)
(gnu build linux-boot)
(guix store database)