Commit | Line | Data |
---|---|---|
96c90474 TS |
1 | ;;; GNU Guix --- Functional package management for GNU |
2 | ;;; Copyright © 2019 Timothy Sample <samplet@ngyro.com> | |
3 | ;;; | |
4 | ;;; This file is part of GNU Guix. | |
5 | ;;; | |
6 | ;;; GNU Guix is free software; you can redistribute it and/or modify it | |
7 | ;;; under the terms of the GNU General Public License as published by | |
8 | ;;; the Free Software Foundation; either version 3 of the License, or (at | |
9 | ;;; your option) any later version. | |
10 | ;;; | |
11 | ;;; GNU Guix is distributed in the hope that it will be useful, but | |
12 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | ;;; GNU General Public License for more details. | |
15 | ;;; | |
16 | ;;; You should have received a copy of the GNU General Public License | |
17 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. | |
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 | ;; TODO: These files have to be writable, so we copy them. | |
38 | ;; This can probably be fixed by using a ".its" file, just | |
39 | ;; be careful not to break initrd loading. | |
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 | (match entries | |
87 | ((entry) | |
88 | (let ((kernel (menu-entry-linux entry)) | |
89 | (kernel-arguments (menu-entry-linux-arguments entry)) | |
90 | (initrd (menu-entry-initrd entry))) | |
91 | ;; XXX: Make this a symlink. | |
92 | (signed-kernel kernel kernel-arguments initrd))) | |
93 | (_ (error "Too many bootloader menu entries!")))) | |
94 | ||
95 | (define install-depthcharge | |
96 | #~(lambda (bootloader device mount-point) | |
97 | (let ((kpart (string-append mount-point | |
98 | "/boot/depthcharge/vmlinux.kpart"))) | |
99 | (write-file-on-device kpart (stat:size (stat kpart)) device 0)))) | |
100 | ||
101 | (define depthcharge-bootloader | |
102 | (bootloader | |
103 | (name 'depthcharge) | |
104 | (package #f) | |
105 | (installer install-depthcharge) | |
106 | (configuration-file "/boot/depthcharge/vmlinux.kpart") | |
107 | (configuration-file-generator depthcharge-configuration-file))) |