| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 |
|
| 19 | (define-module (gnu bootloader depthcharge)
|
| 20 | #:use-module (gnu bootloader extlinux)
|
| 21 | #:use-module (gnu bootloader)
|
| 22 | #:use-module (gnu packages bootloaders)
|
| 23 | #:use-module (guix gexp)
|
| 24 | #:use-module (guix utils)
|
| 25 | #:use-module (ice-9 match)
|
| 26 | #:export (depthcharge-bootloader))
|
| 27 |
|
| 28 | (define (signed-kernel kernel kernel-arguments initrd)
|
| 29 | (define builder
|
| 30 | (with-imported-modules '((guix build utils))
|
| 31 | #~(begin
|
| 32 | (use-modules (guix build utils)
|
| 33 | (ice-9 binary-ports)
|
| 34 | (rnrs bytevectors))
|
| 35 | (set-path-environment-variable "PATH" '("bin") (list #$dtc))
|
| 36 |
|
| 37 | |
| 38 | |
| 39 | |
| 40 | (copy-file #$kernel "zImage")
|
| 41 | (chmod "zImage" #o755)
|
| 42 | (copy-file (string-append (dirname #$kernel) "/lib/dtbs/"
|
| 43 | "rk3288-veyron-speedy.dtb")
|
| 44 | "rk3288-veyron-speedy.dtb")
|
| 45 | (chmod "rk3288-veyron-speedy.dtb" #o644)
|
| 46 | (copy-file #$initrd "initrd")
|
| 47 | (chmod "initrd" #o644)
|
| 48 |
|
| 49 | (invoke (string-append #$u-boot-tools "/bin/mkimage")
|
| 50 | "-D" "-I dts -O dtb -p 2048"
|
| 51 | "-f" "auto"
|
| 52 | "-A" "arm"
|
| 53 | "-O" "linux"
|
| 54 | "-T" "kernel"
|
| 55 | "-C" "None"
|
| 56 | "-d" "zImage"
|
| 57 | "-a" "0"
|
| 58 | "-b" "rk3288-veyron-speedy.dtb"
|
| 59 | "-i" "initrd"
|
| 60 | "image.itb")
|
| 61 | (call-with-output-file "bootloader.bin"
|
| 62 | (lambda (port)
|
| 63 | (put-bytevector port (make-bytevector 512 0))))
|
| 64 | (with-output-to-file "kernel-arguments"
|
| 65 | (lambda ()
|
| 66 | (display (string-join (list #$@kernel-arguments)))))
|
| 67 | (invoke (string-append #$vboot-utils "/bin/vbutil_kernel")
|
| 68 | "--pack" #$output
|
| 69 | "--version" "1"
|
| 70 | "--vmlinuz" "image.itb"
|
| 71 | "--arch" "arm"
|
| 72 | "--keyblock" (string-append #$vboot-utils
|
| 73 | "/share/vboot-utils/devkeys/"
|
| 74 | "kernel.keyblock")
|
| 75 | "--signprivate" (string-append #$vboot-utils
|
| 76 | "/share/vboot-utils/devkeys/"
|
| 77 | "kernel_data_key.vbprivk")
|
| 78 | "--config" "kernel-arguments"
|
| 79 | "--bootloader" "bootloader.bin"))))
|
| 80 | (computed-file "vmlinux.kpart" builder))
|
| 81 |
|
| 82 | (define* (depthcharge-configuration-file config entries
|
| 83 | #:key
|
| 84 | (system (%current-system))
|
| 85 | (old-entries '())
|
| 86 | #:allow-other-keys)
|
| 87 | (match entries
|
| 88 | ((entry)
|
| 89 | (let ((kernel (menu-entry-linux entry))
|
| 90 | (kernel-arguments (menu-entry-linux-arguments entry))
|
| 91 | (initrd (menu-entry-initrd entry)))
|
| 92 | |
| 93 | (signed-kernel kernel kernel-arguments initrd)))
|
| 94 | (_ (error "Too many bootloader menu entries!"))))
|
| 95 |
|
| 96 | (define install-depthcharge
|
| 97 | #~(lambda (bootloader device mount-point)
|
| 98 | (let ((kpart (string-append mount-point
|
| 99 | "/boot/depthcharge/vmlinux.kpart")))
|
| 100 | (write-file-on-device kpart (stat:size (stat kpart)) device 0))))
|
| 101 |
|
| 102 | (define depthcharge-bootloader
|
| 103 | (bootloader
|
| 104 | (name 'depthcharge)
|
| 105 | (package #f)
|
| 106 | (installer install-depthcharge)
|
| 107 | (configuration-file "/boot/depthcharge/vmlinux.kpart")
|
| 108 | (configuration-file-generator depthcharge-configuration-file)))
|