Commit | Line | Data |
---|---|---|
65d8b777 | 1 | ;;; GNU Guix --- Functional package management for GNU |
bc64d955 | 2 | ;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2021 Ludovic Courtès <ludo@gnu.org> |
0a2a7053 | 3 | ;;; Copyright © 2015, 2018 Mark H Weaver <mhw@netris.org> |
f0150f87 | 4 | ;;; Copyright © 2015 Leo Famulari <leo@famulari.name> |
d613991a | 5 | ;;; Copyright © 2016, 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> |
b435f631 | 6 | ;;; Copyright © 2016-2018, 2021-2023 Marius Bakke <marius@gnu.org> |
862e38d5 DC |
7 | ;;; Copyright © 2016, 2017 Danny Milosavljevic <dannym@scratchpost.org> |
8 | ;;; Copyright © 2016, 2017 David Craven <david@craven.ch> | |
0dc99fd1 | 9 | ;;; Copyright © 2017, 2018, 2020, 2021, 2022 Efraim Flashner <efraim@flashner.co.il> |
25e9bb05 | 10 | ;;; Copyright © 2018–2022 Tobias Geerinckx-Rice <me@tobias.gr> |
ab100b90 | 11 | ;;; Copyright © 2019 nee <nee@cock.li> |
af58b275 | 12 | ;;; Copyright © 2019 Mathieu Othacehe <m.othacehe@gmail.com> |
5664a471 | 13 | ;;; Copyright © 2020 Björn Höfling <bjoern.hoefling@bjoernhoefling.de> |
5327b399 | 14 | ;;; Copyright © 2018, 2019, 2020 Vagrant Cascadian <vagrant@debian.org> |
adb84ae8 | 15 | ;;; Copyright © 2020, 2021 Pierre Langlois <pierre.langlois@gmx.com> |
aeed7218 VL |
16 | ;;; Copyright © 2021 Vincent Legoll <vincent.legoll@gmail.com> |
17 | ;;; Copyright © 2021 Brice Waegeneire <brice@waegenei.re> | |
62c86c83 | 18 | ;;; Copyright © 2022 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> |
a9acbf91 | 19 | ;;; Copyright © 2021 Stefan <stefan-guix@vodafonemail.de> |
0d4587d6 | 20 | ;;; Copyright © 2022 Maxim Cournoyer <maxim.cournoyer@gmail.com> |
65d8b777 LC |
21 | ;;; |
22 | ;;; This file is part of GNU Guix. | |
23 | ;;; | |
24 | ;;; GNU Guix is free software; you can redistribute it and/or modify it | |
25 | ;;; under the terms of the GNU General Public License as published by | |
26 | ;;; the Free Software Foundation; either version 3 of the License, or (at | |
27 | ;;; your option) any later version. | |
28 | ;;; | |
29 | ;;; GNU Guix is distributed in the hope that it will be useful, but | |
30 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
31 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
32 | ;;; GNU General Public License for more details. | |
33 | ;;; | |
34 | ;;; You should have received a copy of the GNU General Public License | |
35 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. | |
36 | ||
862e38d5 | 37 | (define-module (gnu packages bootloaders) |
65d8b777 | 38 | #:use-module (gnu packages) |
862e38d5 | 39 | #:use-module (gnu packages admin) |
178e5500 | 40 | #:use-module (gnu packages algebra) |
862e38d5 | 41 | #:use-module (gnu packages assembly) |
a60f1319 | 42 | #:use-module (gnu packages base) |
7febe3a2 | 43 | #:use-module (gnu packages disk) |
65d8b777 | 44 | #:use-module (gnu packages bison) |
862e38d5 | 45 | #:use-module (gnu packages cdrom) |
65212c42 | 46 | #:use-module (gnu packages check) |
0c7707d5 | 47 | #:use-module (gnu packages compression) |
862e38d5 DC |
48 | #:use-module (gnu packages cross-base) |
49 | #:use-module (gnu packages disk) | |
29be6cfb | 50 | #:use-module (gnu packages firmware) |
862e38d5 | 51 | #:use-module (gnu packages flex) |
a86177d6 | 52 | #:use-module (gnu packages fontutils) |
f074f5e8 | 53 | #:use-module (gnu packages gcc) |
862e38d5 | 54 | #:use-module (gnu packages gettext) |
65d8b777 | 55 | #:use-module (gnu packages linux) |
862e38d5 | 56 | #:use-module (gnu packages man) |
444f9dcc | 57 | #:use-module (gnu packages mtools) |
862e38d5 | 58 | #:use-module (gnu packages ncurses) |
96b714f5 | 59 | #:use-module (gnu packages perl) |
a60f1319 | 60 | #:use-module (gnu packages pkg-config) |
96b714f5 | 61 | #:use-module (gnu packages python) |
eb46c6c5 | 62 | #:use-module (gnu packages python-crypto) |
58301666 | 63 | #:use-module (gnu packages texinfo) |
a60f1319 | 64 | #:use-module (gnu packages tls) |
65212c42 | 65 | #:use-module (gnu packages sdl) |
0d4587d6 | 66 | #:use-module (gnu packages sphinx) |
e8122816 | 67 | #:use-module (gnu packages serialization) |
12c613b5 | 68 | #:use-module (gnu packages swig) |
5d706f18 | 69 | #:use-module (gnu packages valgrind) |
59132b80 | 70 | #:use-module (gnu packages virtualization) |
ab100b90 | 71 | #:use-module (gnu packages xorg) |
bcd131da MC |
72 | #:use-module (gnu packages python-web) |
73 | #:use-module (gnu packages python-xyz) | |
862e38d5 | 74 | #:use-module (guix build-system gnu) |
bcd131da | 75 | #:use-module (guix build-system pyproject) |
a9acbf91 | 76 | #:use-module (guix build-system trivial) |
862e38d5 | 77 | #:use-module (guix download) |
a9acbf91 | 78 | #:use-module (guix gexp) |
862e38d5 DC |
79 | #:use-module (guix git-download) |
80 | #:use-module ((guix licenses) #:prefix license:) | |
81 | #:use-module (guix packages) | |
63087721 EF |
82 | #:use-module (guix utils) |
83 | #:use-module (srfi srfi-1) | |
a7c87169 | 84 | #:use-module (srfi srfi-26) |
a3f638e7 | 85 | #:use-module (ice-9 optargs) |
a9acbf91 | 86 | #:use-module (ice-9 match) |
a7c87169 | 87 | #:use-module (ice-9 regex)) |
65d8b777 | 88 | |
9b24c768 LC |
89 | (define unifont |
90 | ;; GNU Unifont, <http://gnu.org/s/unifont>. | |
91 | ;; GRUB needs it for its graphical terminal, gfxterm. | |
92 | (origin | |
93 | (method url-fetch) | |
94 | (uri | |
95 | "http://unifoundry.com/pub/unifont-7.0.06/font-builds/unifont-7.0.06.bdf.gz") | |
96 | (sha256 | |
97 | (base32 | |
98 | "0p2vhnc18cnbmb39vq4m7hzv4mhnm2l0a2s7gx3ar277fwng3hys")))) | |
99 | ||
65d8b777 LC |
100 | (define-public grub |
101 | (package | |
102 | (name "grub") | |
2d115ea7 | 103 | (version "2.06") |
65d8b777 | 104 | (source (origin |
1a1a5aad MC |
105 | (method url-fetch) |
106 | (uri (string-append "mirror://gnu/grub/grub-" version ".tar.xz")) | |
107 | (sha256 | |
108 | (base32 | |
109 | "1qbycnxkx07arj9f2nlsi9kp0dyldspbv07ysdyd34qvz55a97mp")) | |
110 | (patches (search-patches | |
111 | "grub-efi-fat-serial-number.patch" | |
112 | "grub-setup-root.patch")) | |
113 | (modules '((guix build utils))) | |
114 | (snippet | |
115 | '(begin | |
116 | ;; Adjust QEMU invocation to not use a deprecated device | |
117 | ;; name that was removed in QEMU 6.0. Remove for >2.06. | |
118 | (substitute* "tests/ahci_test.in" | |
119 | (("ide-drive") | |
120 | "ide-hd")))))) | |
65d8b777 LC |
121 | (build-system gnu-build-system) |
122 | (arguments | |
069ab3bb TGR |
123 | `(#:configure-flags |
124 | ;; Counterintuitively, this *disables* a spurious Python dependency by | |
125 | ;; calling the ‘true’ binary instead. Python is only needed during | |
126 | ;; bootstrapping (for genptl.py), not when building from a release. | |
127 | (list "PYTHON=true") | |
650e85d8 MO |
128 | ;; Grub fails to load modules stripped with --strip-unneeded. |
129 | #:strip-flags '("--strip-debug" "--enable-deterministic-archives") | |
1a1a5aad MC |
130 | #:phases |
131 | (modify-phases %standard-phases | |
132 | (add-after 'unpack 'patch-stuff | |
133 | (lambda* (#:key native-inputs inputs #:allow-other-keys) | |
134 | (substitute* "grub-core/Makefile.in" | |
135 | (("/bin/sh") (which "sh"))) | |
65d8b777 | 136 | |
1a1a5aad MC |
137 | ;; Give the absolute file name of 'mdadm', used to determine the |
138 | ;; root file system when it's a RAID device. Failing to do that, | |
139 | ;; 'grub-probe' silently fails if 'mdadm' is not in $PATH. | |
140 | (when (assoc-ref inputs "mdadm") | |
141 | (substitute* "grub-core/osdep/linux/getroot.c" | |
142 | (("argv\\[0\\] = \"mdadm\"") | |
143 | (string-append "argv[0] = \"" | |
144 | (assoc-ref inputs "mdadm") | |
145 | "/sbin/mdadm\"")))) | |
358db004 | 146 | |
1a1a5aad MC |
147 | ;; Make the font visible. |
148 | (copy-file (assoc-ref (or native-inputs inputs) | |
149 | "unifont") | |
150 | "unifont.bdf.gz") | |
151 | (system* "gunzip" "unifont.bdf.gz") | |
ab100b90 | 152 | |
1a1a5aad MC |
153 | ;; Give the absolute file name of 'ckbcomp'. |
154 | (substitute* "util/grub-kbdcomp.in" | |
155 | (("^ckbcomp ") | |
156 | (string-append | |
157 | (search-input-file inputs "/bin/ckbcomp") | |
158 | " "))))) | |
159 | (add-after 'unpack 'set-freetype-variables | |
160 | ;; These variables need to be set to the native versions of the | |
161 | ;; dependencies because they are used to build programs which are | |
162 | ;; executed during build time. | |
163 | (lambda* (#:key native-inputs #:allow-other-keys) | |
164 | (when (assoc-ref native-inputs "freetype") | |
165 | (let ((freetype (assoc-ref native-inputs "freetype"))) | |
166 | (setenv "BUILD_FREETYPE_LIBS" | |
167 | (string-append "-L" freetype | |
168 | "/lib -lfreetype")) | |
169 | (setenv "BUILD_FREETYPE_CFLAGS" | |
170 | (string-append "-I" freetype | |
171 | "/include/freetype2")))))) | |
172 | (add-before 'check 'disable-flaky-test | |
173 | (lambda _ | |
174 | ;; This test is unreliable. For more information, see: | |
175 | ;; <https://bugs.gnu.org/26936>. | |
176 | (substitute* "Makefile.in" | |
177 | (("grub_cmd_date grub_cmd_set_date grub_cmd_sleep") | |
178 | "grub_cmd_date grub_cmd_sleep")))) | |
179 | (add-before 'check 'disable-pixel-perfect-test | |
180 | (lambda _ | |
181 | ;; This test compares many screenshots rendered with an older | |
182 | ;; Unifont (9.0.06) than that packaged in Guix. | |
183 | (substitute* "Makefile.in" | |
184 | (("test_unset grub_func_test") | |
185 | "test_unset"))))) | |
66f76912 EF |
186 | ;; Disable tests on ARM and AARCH64 platforms or when cross-compiling. |
187 | #:tests? ,(not (or (any (cute string-prefix? <> (or (%current-target-system) | |
188 | (%current-system))) | |
189 | '("arm" "aarch64")) | |
190 | (%current-target-system))))) | |
65d8b777 | 191 | (inputs |
10da75df LC |
192 | `(("gettext" ,gettext-minimal) |
193 | ||
194 | ;; Depend on LVM2 for libdevmapper, used by 'grub-probe' and | |
195 | ;; 'grub-install' to recognize mapped devices (LUKS, etc.) | |
654de94e JN |
196 | ,@(if (member (or (%current-target-system) |
197 | (%current-system)) | |
198 | (package-supported-systems lvm2)) | |
199 | `(("lvm2" ,lvm2)) | |
200 | '()) | |
10da75df LC |
201 | |
202 | ;; Depend on mdadm, which is invoked by 'grub-probe' and 'grub-install' | |
203 | ;; to determine whether the root file system is RAID. | |
654de94e JN |
204 | ,@(if (member (or (%current-target-system) |
205 | (%current-system)) | |
206 | (package-supported-systems mdadm)) | |
207 | `(("mdadm" ,mdadm)) | |
208 | '()) | |
10da75df | 209 | |
ab100b90 | 210 | ;; Console-setup's ckbcomp is invoked by grub-kbdcomp. It is required |
211 | ;; for generating alternative keyboard layouts. | |
212 | ("console-setup" ,console-setup) | |
213 | ||
35014c40 TGR |
214 | ;; Needed for ‘grub-mount’, the only reliable way to tell whether a given |
215 | ;; file system will be readable by GRUB without rebooting. | |
654de94e JN |
216 | ,@(if (member (or (%current-target-system) |
217 | (%current-system)) | |
218 | (package-supported-systems fuse)) | |
219 | `(("fuse" ,fuse)) | |
220 | '()) | |
35014c40 | 221 | |
65d8b777 LC |
222 | ("freetype" ,freetype) |
223 | ;; ("libusb" ,libusb) | |
01eafd38 | 224 | ("ncurses" ,ncurses))) |
65d8b777 | 225 | (native-inputs |
0a2a7053 MW |
226 | `(("pkg-config" ,pkg-config) |
227 | ("unifont" ,unifont) | |
9b24c768 | 228 | ("bison" ,bison) |
f142c077 | 229 | ("flex" ,flex) |
58301666 MW |
230 | ("texinfo" ,texinfo) |
231 | ("help2man" ,help2man) | |
1a1a5aad | 232 | ("freetype" ,freetype) ;native version needed for build-grub-mkfont |
65d8b777 | 233 | |
a7c87169 MW |
234 | ;; XXX: When building GRUB 2.02 on 32-bit x86, we need a binutils |
235 | ;; capable of assembling 64-bit instructions. However, our default | |
236 | ;; binutils on 32-bit x86 is not 64-bit capable. | |
237 | ,@(if (string-match "^i[3456]86-" (%current-system)) | |
238 | (let ((binutils (package/inherit | |
1a1a5aad MC |
239 | binutils |
240 | (name "binutils-i386") | |
241 | (arguments | |
242 | (substitute-keyword-arguments (package-arguments binutils) | |
243 | ((#:configure-flags flags ''()) | |
244 | `(cons "--enable-64-bit-bfd" ,flags))))))) | |
a7c87169 MW |
245 | `(("ld-wrapper" ,(make-ld-wrapper "ld-wrapper-i386" |
246 | #:binutils binutils)) | |
247 | ("binutils" ,binutils))) | |
248 | '()) | |
249 | ||
65d8b777 LC |
250 | ;; Dependencies for the test suite. The "real" QEMU is needed here, |
251 | ;; because several targets are used. | |
7febe3a2 | 252 | ("parted" ,parted) |
654de94e JN |
253 | ,@(if (member (%current-system) (package-supported-systems qemu-minimal)) |
254 | `(("qemu" ,qemu-minimal)) | |
255 | '()) | |
65d8b777 | 256 | ("xorriso" ,xorriso))) |
175b259c | 257 | (home-page "https://www.gnu.org/software/grub/") |
79c311b8 | 258 | (synopsis "GRand Unified Boot loader") |
65d8b777 | 259 | (description |
a22dc0c4 | 260 | "GRUB is a multiboot bootloader. It is used for initially loading the |
35b9e423 | 261 | kernel of an operating system and then transferring control to it. The kernel |
c5779c93 | 262 | then goes on to load the rest of the operating system. As a multiboot |
574e86f9 LC |
263 | bootloader, GRUB handles the presence of multiple operating systems installed |
264 | on the same computer; upon booting the computer, the user is presented with a | |
a22dc0c4 | 265 | menu to select one of the installed operating systems.") |
3f73aa1a | 266 | (license license:gpl3+) |
99effc8f | 267 | (properties '((cpe-name . "grub2"))))) |
acb5f7c3 | 268 | |
0c962369 JN |
269 | (define-public grub-minimal |
270 | (package | |
271 | (inherit grub) | |
272 | (name "grub-minimal") | |
273 | (inputs | |
8394619b LC |
274 | (modify-inputs (package-inputs grub) |
275 | (delete "lvm2" "mdadm" "fuse" "console-setup"))) | |
0c962369 | 276 | (native-inputs |
8394619b LC |
277 | (modify-inputs (package-native-inputs grub) |
278 | (delete "help2man" "texinfo" "parted" "qemu" "xorriso"))) | |
0c962369 | 279 | (arguments |
097b7255 LC |
280 | (substitute-keyword-arguments (package-arguments grub) |
281 | ((#:configure-flags _ ''()) | |
282 | '(list "PYTHON=true")) | |
283 | ((#:tests? _ #t) | |
284 | #f) | |
285 | ((#:phases phases '%standard-phases) | |
286 | `(modify-phases ,phases | |
287 | (replace 'patch-stuff | |
288 | (lambda* (#:key native-inputs inputs #:allow-other-keys) | |
289 | (substitute* "grub-core/Makefile.in" | |
290 | (("/bin/sh") (which "sh"))) | |
0c962369 | 291 | |
097b7255 LC |
292 | ;; Make the font visible. |
293 | (copy-file (assoc-ref (or native-inputs inputs) | |
294 | "unifont") | |
295 | "unifont.bdf.gz") | |
296 | (system* "gunzip" "unifont.bdf.gz") | |
0c962369 | 297 | |
097b7255 | 298 | #t)))))))) |
0c962369 | 299 | |
acb5f7c3 MB |
300 | (define-public grub-efi |
301 | (package | |
302 | (inherit grub) | |
303 | (name "grub-efi") | |
304 | (synopsis "GRand Unified Boot loader (UEFI version)") | |
305 | (inputs | |
8394619b LC |
306 | (modify-inputs (package-inputs grub) |
307 | (prepend efibootmgr mtools))) | |
acb5f7c3 MB |
308 | (arguments |
309 | `(;; TODO: Tests need a UEFI firmware for qemu. There is one at | |
310 | ;; https://github.com/tianocore/edk2/tree/master/OvmfPkg . | |
311 | ;; Search for 'OVMF' in "tests/util/grub-shell.in". | |
acb5f7c3 | 312 | ,@(substitute-keyword-arguments (package-arguments grub) |
46ff2dbb | 313 | ((#:tests? _ #f) #f) |
ef753a1a | 314 | ((#:configure-flags flags ''()) |
018f9509 | 315 | `(cons* "--with-platform=efi" |
fd549750 CB |
316 | ,@(if (string-prefix? "x86_64" |
317 | (or (%current-target-system) | |
318 | (%current-system))) | |
319 | '("--enable-stack-protector") ; EFI-only for now | |
320 | '()) | |
018f9509 | 321 | ,flags)) |
acb5f7c3 MB |
322 | ((#:phases phases) |
323 | `(modify-phases ,phases | |
324 | (add-after 'patch-stuff 'use-absolute-efibootmgr-path | |
325 | (lambda* (#:key inputs #:allow-other-keys) | |
326 | (substitute* "grub-core/osdep/unix/platform.c" | |
327 | (("efibootmgr") | |
bc64d955 LC |
328 | (search-input-file inputs |
329 | "/sbin/efibootmgr"))))) | |
444f9dcc DM |
330 | (add-after 'patch-stuff 'use-absolute-mtools-path |
331 | (lambda* (#:key inputs #:allow-other-keys) | |
332 | (let ((mtools (assoc-ref inputs "mtools"))) | |
333 | (substitute* "util/grub-mkrescue.c" | |
334 | (("\"mformat\"") | |
335 | (string-append "\"" mtools | |
336 | "/bin/mformat\""))) | |
337 | (substitute* "util/grub-mkrescue.c" | |
338 | (("\"mcopy\"") | |
339 | (string-append "\"" mtools | |
340 | "/bin/mcopy\""))) | |
341 | #t)))))))))) | |
96b714f5 | 342 | |
62c86c83 DGC |
343 | (define-public grub-efi32 |
344 | (package | |
345 | (inherit grub-efi) | |
346 | (name "grub-efi32") | |
347 | (synopsis "GRand Unified Boot loader (UEFI 32bit version)") | |
348 | (arguments | |
349 | `(,@(substitute-keyword-arguments (package-arguments grub-efi) | |
116c0268 EF |
350 | ((#:configure-flags flags ''()) |
351 | `(cons* | |
76259d73 MC |
352 | ,@(cond ((target-x86?) '("--target=i386")) |
353 | ((target-aarch64?) | |
354 | (list "--target=arm" | |
355 | (string-append "TARGET_CC=" | |
356 | (cc-for-target "arm-linux-gnueabihf")))) | |
357 | ((target-arm?) '("--target=arm")) | |
358 | (else '())) | |
359 | ,flags))))) | |
116c0268 EF |
360 | (native-inputs |
361 | (if (target-aarch64?) | |
76259d73 MC |
362 | (modify-inputs (package-native-inputs grub-efi) |
363 | (prepend | |
364 | (cross-gcc "arm-linux-gnueabihf") | |
365 | (cross-binutils "arm-linux-gnueabihf"))) | |
366 | (package-native-inputs grub-efi))))) | |
62c86c83 | 367 | |
dd4b7476 DM |
368 | ;; Because grub searches hardcoded paths it's easiest to just build grub |
369 | ;; again to make it find both grub-pc and grub-efi. There is a command | |
370 | ;; line argument which allows you to specify ONE platform - but | |
371 | ;; grub-mkrescue will use multiple platforms if they are available | |
372 | ;; in the installation directory (without command line argument). | |
373 | (define-public grub-hybrid | |
374 | (package | |
375 | (inherit grub-efi) | |
376 | (name "grub-hybrid") | |
377 | (synopsis "GRand Unified Boot loader (hybrid version)") | |
378 | (inputs | |
8394619b LC |
379 | (modify-inputs (package-inputs grub-efi) |
380 | (prepend grub))) | |
dd4b7476 DM |
381 | (arguments |
382 | (substitute-keyword-arguments (package-arguments grub-efi) | |
383 | ((#:modules modules `((guix build utils) (guix build gnu-build-system))) | |
384 | `((ice-9 ftw) ,@modules)) | |
385 | ((#:phases phases) | |
386 | `(modify-phases ,phases | |
387 | (add-after 'install 'install-non-efi | |
388 | (lambda* (#:key inputs outputs #:allow-other-keys) | |
d468a03a LC |
389 | (let ((input-dir (search-input-directory inputs |
390 | "/lib/grub")) | |
dd4b7476 DM |
391 | (output-dir (string-append (assoc-ref outputs "out") |
392 | "/lib/grub"))) | |
393 | (for-each | |
394 | (lambda (basename) | |
db34d4bb EF |
395 | (if (not (or (string-prefix? "." basename) |
396 | (file-exists? (string-append output-dir "/" basename)))) | |
dd4b7476 DM |
397 | (symlink (string-append input-dir "/" basename) |
398 | (string-append output-dir "/" basename)))) | |
399 | (scandir input-dir)) | |
400 | #t))))))))) | |
401 | ||
a9acbf91 S |
402 | (define-public (make-grub-efi-netboot name subdir) |
403 | "Make a grub-efi-netboot package named NAME, which will be able to boot over | |
404 | network via TFTP by accessing its files in the SUBDIR of a TFTP root directory. | |
405 | This package is also able to boot from local storage devices. | |
406 | ||
407 | A bootloader-installer basically needs to copy the package content into the | |
408 | bootloader-target directory, which will usually be the TFTP root, as | |
409 | 'grub-mknetdir' will be invoked already during the package creation. | |
410 | ||
411 | Alternatively the bootloader-target directory can be a mounted EFI System | |
412 | Partition (ESP), or a similar partition with a FAT file system, for booting | |
413 | from local storage devices. | |
414 | ||
415 | The name of the GRUB EFI binary will conform to the UEFI specification for | |
416 | removable media. Depending on the system it will be e.g. bootx64.efi or | |
417 | bootaa64.efi below SUBDIR. | |
418 | ||
419 | The SUBDIR argument needs to be set to \"efi/boot\" to create a package which | |
420 | conforms to the UEFI specification for removable media. | |
421 | ||
422 | The SUBDIR argument defaults to \"efi/Guix\", as it is also the case for | |
423 | 'grub-efi-bootloader'." | |
424 | (package | |
425 | (name name) | |
426 | (version (package-version grub-efi)) | |
427 | ;; Source is not needed, but it cannot be omitted. | |
428 | (source #f) | |
429 | (build-system trivial-build-system) | |
430 | (arguments | |
431 | (let* ((system (string-split (nix-system->gnu-triplet | |
432 | (or (%current-target-system) | |
433 | (%current-system))) | |
434 | #\-)) | |
435 | (arch (first system)) | |
436 | (boot-efi | |
437 | (match system | |
438 | ;; These are the supportend systems and the names defined by | |
439 | ;; the UEFI standard for removable media. | |
440 | (("i686" _ ...) "/bootia32.efi") | |
441 | (("x86_64" _ ...) "/bootx64.efi") | |
442 | (("arm" _ ...) "/bootarm.efi") | |
443 | (("aarch64" _ ...) "/bootaa64.efi") | |
444 | (("riscv" _ ...) "/bootriscv32.efi") | |
445 | (("riscv64" _ ...) "/bootriscv64.efi") | |
446 | ;; Other systems are not supported, although defined. | |
447 | ;; (("riscv128" _ ...) "/bootriscv128.efi") | |
448 | ;; (("ia64" _ ...) "/bootia64.efi") | |
449 | ((_ ...) #f))) | |
450 | (core-efi (string-append | |
451 | ;; This is the arch dependent file name of GRUB, e.g. | |
452 | ;; i368-efi/core.efi or arm64-efi/core.efi. | |
453 | (match arch | |
454 | ("i686" "i386") | |
455 | ("aarch64" "arm64") | |
456 | ("riscv" "riscv32") | |
457 | (_ arch)) | |
458 | "-efi/core.efi"))) | |
459 | (list | |
460 | #:modules '((guix build utils)) | |
461 | #:builder | |
462 | #~(begin | |
463 | (use-modules (guix build utils)) | |
464 | (let* ((bootloader #$(this-package-input "grub-efi")) | |
465 | (net-dir #$output) | |
466 | (sub-dir (string-append net-dir "/" #$subdir "/")) | |
467 | (boot-efi (string-append sub-dir #$boot-efi)) | |
468 | (core-efi (string-append sub-dir #$core-efi))) | |
469 | ;; Install GRUB, which refers to the grub.cfg, with support for | |
470 | ;; encrypted partitions, | |
471 | (setenv "GRUB_ENABLE_CRYPTODISK" "y") | |
472 | (invoke/quiet (string-append bootloader "/bin/grub-mknetdir") | |
473 | (string-append "--net-directory=" net-dir) | |
474 | (string-append "--subdir=" #$subdir) | |
475 | ;; These modules must be pre-loaded to allow booting | |
476 | ;; from an ESP or a similar partition with a FAT | |
477 | ;; file system. | |
478 | (string-append "--modules=part_msdos part_gpt fat")) | |
479 | ;; Move GRUB's core.efi to the removable media name. | |
480 | (false-if-exception (delete-file boot-efi)) | |
481 | (rename-file core-efi boot-efi)))))) | |
482 | (inputs (list grub-efi)) | |
483 | (synopsis (package-synopsis grub-efi)) | |
484 | (description (package-description grub-efi)) | |
485 | (home-page (package-home-page grub-efi)) | |
486 | (license (package-license grub-efi)))) | |
487 | ||
96b714f5 DC |
488 | (define-public syslinux |
489 | (let ((commit "bb41e935cc83c6242de24d2271e067d76af3585c")) | |
490 | (package | |
491 | (name "syslinux") | |
492 | (version (git-version "6.04-pre" "1" commit)) | |
493 | (source (origin | |
494 | (method git-fetch) | |
495 | (uri (git-reference | |
496 | (url "https://github.com/geneC/syslinux") | |
497 | (commit commit))) | |
498 | (file-name (git-file-name name version)) | |
499 | (sha256 | |
500 | (base32 | |
26cb0c39 MO |
501 | "0k8dvafd6410kqxf3kyr4y8jzmpmrih6wbjqg6gklak7945yflrc")) |
502 | (patches | |
503 | (search-patches "syslinux-gcc10.patch" | |
504 | "syslinux-strip-gnu-property.patch")))) | |
96b714f5 DC |
505 | (build-system gnu-build-system) |
506 | (native-inputs | |
507 | `(("nasm" ,nasm) | |
508 | ("perl" ,perl) | |
509 | ("python-2" ,python-2))) | |
510 | (inputs | |
bb93042c | 511 | `(("libuuid" ,util-linux "lib") |
0b4dbb40 | 512 | ("mtools" ,mtools))) |
96b714f5 DC |
513 | (arguments |
514 | `(#:parallel-build? #f | |
515 | #:make-flags | |
516 | (list (string-append "BINDIR=" %output "/bin") | |
517 | (string-append "SBINDIR=" %output "/sbin") | |
518 | (string-append "LIBDIR=" %output "/lib") | |
519 | (string-append "INCDIR=" %output "/include") | |
520 | (string-append "DATADIR=" %output "/share") | |
521 | (string-append "MANDIR=" %output "/share/man") | |
522 | "PERL=perl" | |
523 | "bios") | |
26cb0c39 | 524 | #:strip-flags '("--strip-debug" "--enable-deterministic-archives") |
96b714f5 DC |
525 | #:phases |
526 | (modify-phases %standard-phases | |
527 | (add-after 'unpack 'patch-files | |
0b4dbb40 | 528 | (lambda* (#:key inputs #:allow-other-keys) |
96b714f5 DC |
529 | (substitute* (find-files "." "Makefile.*|ppmtolss16") |
530 | (("/bin/pwd") (which "pwd")) | |
531 | (("/bin/echo") (which "echo")) | |
532 | (("/usr/bin/perl") (which "perl"))) | |
0b4dbb40 LC |
533 | (let ((mtools (assoc-ref inputs "mtools"))) |
534 | (substitute* (find-files "." "\\.c$") | |
535 | (("mcopy") | |
536 | (string-append mtools "/bin/mcopy")) | |
537 | (("mattrib") | |
538 | (string-append mtools "/bin/mattrib")))) | |
96b714f5 DC |
539 | #t)) |
540 | (delete 'configure) | |
541 | (add-before 'build 'set-permissions | |
542 | (lambda _ | |
60d8db74 | 543 | (invoke "chmod" "a+w" "utils/isohybrid.in"))) |
96b714f5 | 544 | (replace 'check |
10a661c8 EF |
545 | (lambda* (#:key tests? #:allow-other-keys) |
546 | (when tests? | |
547 | (setenv "CC" "gcc") | |
548 | (substitute* "tests/unittest/include/unittest/unittest.h" | |
549 | ;; Don't look up headers under /usr. | |
550 | (("/usr/include/") "")) | |
551 | (invoke "make" "unittest"))))))) | |
0f304ba7 | 552 | (home-page "https://www.syslinux.org") |
96b714f5 DC |
553 | (synopsis "Lightweight Linux bootloader") |
554 | (description "Syslinux is a lightweight Linux bootloader.") | |
8d3f604d EF |
555 | ;; The Makefile specifically targets i386 and x86_64 using nasm. |
556 | (supported-systems '("i686-linux" "x86_64-linux")) | |
96b714f5 DC |
557 | (license (list license:gpl2+ |
558 | license:bsd-3 ; gnu-efi/* | |
559 | license:bsd-4 ; gnu-efi/inc/* gnu-efi/lib/* | |
560 | ;; Also contains: | |
561 | license:expat license:isc license:zlib))))) | |
862e38d5 DC |
562 | |
563 | (define-public dtc | |
564 | (package | |
565 | (name "dtc") | |
402f544c | 566 | (version "1.6.1") |
862e38d5 DC |
567 | (source (origin |
568 | (method url-fetch) | |
569 | (uri (string-append | |
3b4efb1f | 570 | "mirror://kernel.org/software/utils/dtc/" |
54933a40 | 571 | "dtc-" version ".tar.gz")) |
862e38d5 DC |
572 | (sha256 |
573 | (base32 | |
54933a40 | 574 | "0xm38h31jb29xfh2sfyk48d8wdfq4b8lmb412zx9vjr35izjb9iq")))) |
862e38d5 | 575 | (build-system gnu-build-system) |
862e38d5 | 576 | (arguments |
a5b00d27 | 577 | (list |
5dc8cf84 | 578 | #:modules `(,@%gnu-build-system-modules (srfi srfi-26)) |
a5b00d27 MC |
579 | #:make-flags |
580 | #~(list (string-append "CC=" #$(cc-for-target)) | |
581 | ;; /bin/fdt{get,overlay,put} need help finding libfdt.so.1. | |
582 | (string-append "LDFLAGS=-Wl,-rpath=" #$output "/lib") | |
583 | (string-append "PREFIX=" #$output) | |
584 | (string-append "SETUP_PREFIX=" #$output) | |
585 | "INSTALL=install") | |
586 | #:phases | |
587 | #~(modify-phases %standard-phases | |
588 | (add-after 'unpack 'patch-pkg-config | |
589 | (lambda _ | |
590 | (substitute* '("Makefile" | |
591 | "tests/run_tests.sh") | |
592 | (("pkg-config") | |
593 | #$(pkg-config-for-target))))) | |
5dc8cf84 MC |
594 | (delete 'configure) ;no configure script |
595 | (add-before 'build 'install-doc | |
596 | (lambda _ | |
597 | (with-directory-excursion "Documentation" | |
598 | (for-each (cut install-file <> (string-append | |
599 | #$output "/share/doc/dtc/")) | |
600 | '("dts-format.txt" | |
601 | "dt-object-internal.txt" | |
602 | "manual.txt")))))))) | |
ec3c37d7 MC |
603 | (native-inputs |
604 | (append | |
605 | (list bison | |
606 | flex | |
607 | libyaml | |
608 | pkg-config | |
609 | swig) | |
610 | (if (member (%current-system) (package-supported-systems valgrind)) | |
611 | (list valgrind) | |
612 | '()))) | |
613 | (inputs | |
614 | (list python)) | |
862e38d5 DC |
615 | (home-page "https://www.devicetree.org") |
616 | (synopsis "Compiles device tree source files") | |
617 | (description "@command{dtc} compiles | |
618 | @uref{http://elinux.org/Device_Tree_Usage, device tree source files} to device | |
619 | tree binary files. These are board description files used by Linux and BSD.") | |
620 | (license license:gpl2+))) | |
621 | ||
3a851d45 VC |
622 | (define %u-boot-rockchip-inno-usb-patch |
623 | ;; Fix regression in 2020.10 causing freezes on boot with USB boot enabled. | |
624 | ;; See https://gitlab.manjaro.org/manjaro-arm/packages/core/uboot-rockpro64/-/issues/4 | |
625 | ;; and https://patchwork.ozlabs.org/project/uboot/patch/20210406151059.1187379-1-icenowy@aosc.io | |
626 | (search-patch "u-boot-rockchip-inno-usb.patch")) | |
627 | ||
eb46c6c5 PL |
628 | (define %u-boot-sifive-prevent-relocating-initrd-fdt |
629 | ;; Fix boot in 2021.07 on Hifive unmatched, see | |
630 | ;; https://bugs.launchpad.net/ubuntu/+source/u-boot/+bug/1937246 | |
631 | (search-patch "u-boot-sifive-prevent-reloc-initrd-fdt.patch")) | |
632 | ||
65be27dc VC |
633 | (define %u-boot-allow-disabling-openssl-patch |
634 | ;; Fixes build of u-boot 2021.10 without openssl | |
635 | ;; https://lists.denx.de/pipermail/u-boot/2021-October/462728.html | |
636 | (search-patch "u-boot-allow-disabling-openssl.patch")) | |
637 | ||
bf1e46e9 PL |
638 | (define %u-boot-rk3399-enable-emmc-phy-patch |
639 | ;; Fix emmc boot on rockpro64 and pinebook-pro, this was a regression | |
640 | ;; therefore should hopefully be fixed when updating u-boot. | |
641 | ;; https://lists.denx.de/pipermail/u-boot/2021-November/466329.html | |
642 | (search-patch "u-boot-rk3399-enable-emmc-phy.patch")) | |
643 | ||
862e38d5 DC |
644 | (define u-boot |
645 | (package | |
646 | (name "u-boot") | |
5b0e656e | 647 | (version "2022.10") |
862e38d5 | 648 | (source (origin |
c2c1dfdf | 649 | (patches |
eb46c6c5 | 650 | (list %u-boot-rockchip-inno-usb-patch |
65be27dc | 651 | %u-boot-allow-disabling-openssl-patch |
bf1e46e9 | 652 | %u-boot-sifive-prevent-relocating-initrd-fdt |
0d4587d6 | 653 | %u-boot-rk3399-enable-emmc-phy-patch |
bcd131da | 654 | (search-patch "u-boot-infodocs-target.patch") |
c42ae60a | 655 | (search-patch "u-boot-patman-guix-integration.patch"))) |
862e38d5 DC |
656 | (method url-fetch) |
657 | (uri (string-append | |
98067662 | 658 | "https://ftp.denx.de/pub/u-boot/" |
862e38d5 DC |
659 | "u-boot-" version ".tar.bz2")) |
660 | (sha256 | |
661 | (base32 | |
5b0e656e RW |
662 | "1y5x8vxdgsqdqlsvq01mn8lmw53fqairkhvhhjx83hjva0m4id2h")))) |
663 | (build-system gnu-build-system) | |
862e38d5 | 664 | (native-inputs |
680a7683 | 665 | (list bison |
7c8832e1 RW |
666 | dtc |
667 | gnutls | |
668 | flex | |
669 | lz4 | |
670 | ncurses/tinfo | |
671 | perl | |
57abc2b7 | 672 | pkg-config ;for 'make menuconfig' |
7c8832e1 | 673 | python |
7c8832e1 RW |
674 | swig |
675 | (list util-linux "lib"))) | |
3e63a83c | 676 | (home-page "https://www.denx.de/wiki/U-Boot/") |
862e38d5 | 677 | (synopsis "ARM bootloader") |
2ebcc538 | 678 | (description "U-Boot is a bootloader used mostly for ARM boards. It |
862e38d5 DC |
679 | also initializes the boards (RAM etc).") |
680 | (license license:gpl2+))) | |
681 | ||
0d4587d6 MC |
682 | ;;; This is very similar to the linux-libre-documentation package, since it |
683 | ;;; reuses the same Makefile-based build system. | |
684 | (define-public u-boot-documentation | |
685 | (package | |
686 | (inherit u-boot) | |
687 | (name "u-boot-documentation") | |
688 | (arguments | |
689 | (list | |
690 | #:make-flags #~(list "HOSTCC=gcc" | |
691 | ;; Avoid treating Sphinx warnings as errors. | |
692 | "SPHINXOPTS=") | |
693 | #:tests? #f | |
694 | #:phases #~(modify-phases %standard-phases | |
695 | (delete 'configure) | |
696 | (replace 'build | |
697 | (lambda* (#:key make-flags #:allow-other-keys) | |
698 | (apply invoke "make" "infodocs" make-flags))) | |
699 | (replace 'install | |
700 | (lambda* (#:key make-flags #:allow-other-keys) | |
701 | (let* ((info-dir (string-append #$output "/share/info")) | |
702 | (info (string-append info-dir | |
703 | "/DasUBoot.info.gz"))) | |
704 | (with-directory-excursion "doc/output" | |
705 | (apply invoke "make" "-C" "texinfo" "install-info" | |
706 | (string-append "infodir=" info-dir) | |
707 | make-flags)))))))) | |
708 | (native-inputs | |
709 | (modify-inputs (package-native-inputs u-boot) | |
710 | (append fontconfig | |
711 | python-sphinx | |
712 | texinfo | |
713 | which))) | |
714 | (synopsis "U-Boot documentation") | |
715 | (description "This package provides the documentation for U-Boot, as an | |
716 | Info manual."))) | |
717 | ||
2676628f DM |
718 | (define-public u-boot-tools |
719 | (package | |
720 | (inherit u-boot) | |
721 | (name "u-boot-tools") | |
6b125371 | 722 | (native-inputs |
8394619b | 723 | (modify-inputs (package-native-inputs u-boot) |
680a7683 | 724 | (prepend python-coverage python-pycryptodomex python-pytest sdl2))) |
2676628f | 725 | (arguments |
65212c42 | 726 | `(#:make-flags '("HOSTCC=gcc") |
e9545e6d | 727 | #:test-target "tcheck" |
2676628f DM |
728 | #:phases |
729 | (modify-phases %standard-phases | |
65212c42 DM |
730 | (add-after 'unpack 'patch |
731 | (lambda* (#:key inputs #:allow-other-keys) | |
732 | (substitute* "Makefile" | |
8d1d209f MC |
733 | (("/bin/pwd") (which "pwd")) |
734 | (("/bin/false") (which "false"))) | |
65212c42 | 735 | (substitute* "tools/dtoc/fdt_util.py" |
8d1d209f | 736 | (("'cc'") "'gcc'")) |
e1d1ec14 | 737 | (substitute* "tools/patman/test_util.py" |
8d1d209f | 738 | ;; python3-coverage is simply called coverage in guix. |
b0bd3ef9 MB |
739 | (("python3-coverage") "coverage") |
740 | ||
741 | ;; Don't require 100% coverage since it's brittle and can | |
742 | ;; fail with newer versions of coverage or dependencies. | |
743 | (("raise ValueError\\('Test coverage failure'\\)") | |
744 | "print('Continuing anyway since Guix does not care :O')")) | |
65212c42 | 745 | (substitute* "test/run" |
8d1d209f MC |
746 | ;; Make it easier to find test failures. |
747 | (("#!/bin/bash") "#!/bin/bash -x") | |
748 | ;; This test would require git. | |
749 | (("\\./tools/patman/patman") (which "true")) | |
750 | ;; FIXME: test fails, needs further investiation | |
751 | (("run_test \"binman\"") "# run_test \"binman\"") | |
752 | ;; FIXME: test_spl fails, needs further investiation | |
753 | (("test_ofplatdata or test_handoff or test_spl") | |
eb46c6c5 | 754 | "test_ofplatdata or test_handoff") |
8d1d209f MC |
755 | ;; FIXME: code coverage not working |
756 | (("run_test \"binman code coverage\"") | |
757 | "# run_test \"binman code coverage\"") | |
758 | ;; This test would require internet access. | |
759 | (("\\./tools/buildman/buildman") (which "true"))) | |
65212c42 | 760 | (substitute* "test/py/tests/test_sandbox_exit.py" |
8d1d209f MC |
761 | (("def test_ctrl_c") |
762 | "@pytest.mark.skip(reason='Guix has problems with SIGINT') | |
65212c42 | 763 | def test_ctrl_c")) |
6f5be83c VC |
764 | ;; Test against the tools being installed rather than tools built |
765 | ;; for "sandbox" target. | |
766 | (substitute* "test/image/test-imagetools.sh" | |
767 | (("BASEDIR=sandbox") "BASEDIR=.")) | |
4da4e952 | 768 | (for-each (lambda (file) |
8d1d209f MC |
769 | (substitute* file |
770 | ;; Disable features that require OpenSSL due | |
771 | ;; to GPL/Openssl license incompatibilities. | |
772 | ;; See https://bugs.gnu.org/34717 for | |
773 | ;; details. | |
774 | (("CONFIG_FIT_SIGNATURE=y") | |
775 | "CONFIG_FIT_SIGNATURE=n\nCONFIG_UT_LIB_ASN1=n\nCONFIG_TOOLS_LIBCRYPTO=n") | |
776 | ;; This test requires a sound system, which is un-used | |
777 | ;; in u-boot-tools. | |
778 | (("CONFIG_SOUND=y") "CONFIG_SOUND=n"))) | |
4a4f2d22 | 779 | (find-files "configs" "sandbox_.*defconfig$|tools-only_defconfig")))) |
2676628f DM |
780 | (replace 'configure |
781 | (lambda* (#:key make-flags #:allow-other-keys) | |
634b0e28 | 782 | (apply invoke "make" "tools-only_defconfig" make-flags))) |
2676628f DM |
783 | (replace 'build |
784 | (lambda* (#:key inputs make-flags #:allow-other-keys) | |
9e84a4d6 | 785 | (apply invoke "make" "tools-all" make-flags))) |
2676628f DM |
786 | (replace 'install |
787 | (lambda* (#:key outputs #:allow-other-keys) | |
788 | (let* ((out (assoc-ref outputs "out")) | |
789 | (bin (string-append out "/bin"))) | |
790 | (for-each (lambda (name) | |
791 | (install-file name bin)) | |
792 | '("tools/netconsole" | |
793 | "tools/jtagconsole" | |
794 | "tools/gen_eth_addr" | |
795 | "tools/gen_ethaddr_crc" | |
796 | "tools/img2srec" | |
797 | "tools/mkenvimage" | |
798 | "tools/dumpimage" | |
799 | "tools/mkimage" | |
06f47e02 | 800 | "tools/kwboot" |
2676628f DM |
801 | "tools/proftool" |
802 | "tools/fdtgrep" | |
10186ee2 | 803 | "tools/env/fw_printenv" |
4a4f2d22 | 804 | "tools/sunxi-spl-image-builder"))))) |
8d1d209f MC |
805 | (delete 'check) |
806 | (add-after 'install 'check | |
807 | (lambda* (#:key make-flags test-target #:allow-other-keys) | |
808 | (invoke "test/image/test-imagetools.sh"))) | |
809 | ;; Only run full test suite on x86_64 systems, as many tests | |
810 | ;; assume x86_64. | |
811 | ,@(if (string-match "^x86_64-linux" | |
812 | (or (%current-target-system) | |
813 | (%current-system))) | |
814 | '((add-after 'check 'check-x86 | |
815 | (lambda* (#:key make-flags test-target #:allow-other-keys) | |
816 | (apply invoke "make" "mrproper" make-flags) | |
817 | (setenv "SDL_VIDEODRIVER" "dummy") | |
818 | (setenv "PAGER" "cat") | |
819 | (apply invoke "make" test-target make-flags)))) | |
820 | '())))) | |
c2c1dfdf S |
821 | (description (string-append |
822 | (package-description u-boot) | |
823 | " This package provides board-independent tools " | |
824 | "of U-Boot.")))) | |
825 | ||
bcd131da MC |
826 | ;;; This is packaged separately, as it can be used in other contexts than for |
827 | ;;; U-Boot development. | |
828 | (define-public patman | |
829 | (package | |
830 | (inherit u-boot) | |
831 | (name "patman") | |
832 | (build-system pyproject-build-system) | |
833 | (arguments | |
834 | ;; The test suite strongly relies on the git metadata being available (23 | |
835 | ;; failed, 14 passed). | |
836 | (list | |
837 | #:tests? #f | |
838 | #:phases | |
839 | #~(modify-phases %standard-phases | |
840 | (add-after 'unpack 'chdir | |
841 | (lambda _ | |
842 | (chdir "tools/patman")))))) | |
843 | (inputs (list python-pygit2 python-requests)) | |
844 | (synopsis "Patch automation tool") | |
845 | (description "Patman is a patch automation script which: | |
846 | @itemize | |
847 | @item Creates patches directly from your branch | |
848 | @item Cleans them up by removing unwanted tags | |
849 | @item Inserts a cover letter with change lists | |
850 | @item Runs the patches through automated checks | |
851 | @item Optionally emails them out to selected people. | |
852 | @end itemize"))) | |
853 | ||
c2c1dfdf S |
854 | (define*-public (make-u-boot-package board triplet |
855 | #:key | |
856 | defconfig | |
857 | configs | |
858 | name-suffix | |
d970d6a0 MC |
859 | append-description |
860 | (u-boot u-boot)) | |
c2c1dfdf S |
861 | "Return a U-Boot package for BOARD cross-compiled for TRIPLET with the |
862 | optional DEFCONFIG file and optional configuration changes from CONFIGS. | |
980abad2 MC |
863 | TRIPLET may also be set to #f to disable cross-compilation. NAME-SUFFIX is |
864 | appended to the package name, while APPEND-DESCRIPTION is appended to the | |
865 | package description. U-BOOT can be used when a fork or a different version of | |
866 | U-Boot must be used." | |
c6a8b138 | 867 | (let ((native-build? (lambda () |
980abad2 MC |
868 | (or (not triplet) ;disable cross-compilation |
869 | (string=? (%current-system) | |
870 | (gnu-triplet->nix-system triplet)))))) | |
3bfee8ff EF |
871 | (package |
872 | (inherit u-boot) | |
df8a9096 DM |
873 | (name (string-append "u-boot-" |
874 | (string-replace-substring (string-downcase board) | |
c2c1dfdf S |
875 | "_" "-") |
876 | (or name-suffix ""))) | |
877 | (description (if append-description | |
878 | (string-append (package-description u-boot) | |
879 | "\n\n" append-description) | |
880 | (package-description u-boot))) | |
c6a8b138 | 881 | (build-system gnu-build-system) |
3bfee8ff | 882 | (arguments |
d970d6a0 | 883 | (substitute-keyword-arguments (package-arguments u-boot) |
c6a8b138 MC |
884 | ((#:target _ #f) |
885 | (and (not (native-build?)) triplet)) | |
d970d6a0 MC |
886 | ((#:modules modules '()) |
887 | `((ice-9 ftw) | |
888 | (srfi srfi-1) | |
889 | (guix build gnu-build-system) | |
890 | (guix build kconfig) | |
891 | (guix build utils) | |
892 | ,@modules)) | |
893 | ((#:imported-modules imported-modules '()) | |
894 | `((guix build kconfig) | |
895 | ,@%gnu-build-system-modules | |
896 | ,@imported-modules)) | |
897 | ((#:test-target _ "test") | |
898 | "test") | |
899 | ((#:make-flags make-flags '()) | |
900 | #~(list "HOSTCC=gcc" | |
901 | "KBUILD_VERBOSE=1" | |
c6a8b138 | 902 | #$@(if (not (native-build?)) |
d970d6a0 MC |
903 | (list (string-append "CROSS_COMPILE=" triplet "-")) |
904 | '()) | |
905 | #$@make-flags)) | |
906 | ((#:phases phases '%standard-phases) | |
907 | #~(modify-phases #$phases | |
908 | (replace 'configure | |
909 | (lambda* (#:key make-flags #:allow-other-keys) | |
910 | (let* ((config-name (string-append #$board "_defconfig")) | |
911 | (config-file (string-append "configs/" config-name)) | |
912 | (defconfig #$defconfig) | |
913 | (configs '#$configs)) | |
914 | (when defconfig | |
915 | ;; Replace the board-specific defconfig with the given | |
916 | ;; one. | |
917 | (copy-file defconfig config-file)) | |
918 | (if (file-exists? config-file) | |
919 | (begin | |
920 | (when configs | |
921 | (modify-defconfig config-file configs)) | |
922 | (apply invoke "make" `(,@make-flags ,config-name)) | |
923 | (verify-config ".config" config-file)) | |
924 | (begin | |
925 | (display "invalid board name; valid board names are:" | |
926 | (current-error-port)) | |
927 | (let ((suffix-len (string-length "_defconfig")) | |
928 | (entries (scandir "configs"))) | |
929 | (for-each (lambda (file-name) | |
930 | (when (string-suffix? "_defconfig" | |
931 | file-name) | |
932 | (format (current-error-port) | |
933 | "- ~A\n" | |
934 | (string-drop-right | |
935 | file-name suffix-len)))) | |
936 | (sort entries string-ci<))) | |
937 | (error "invalid boardname ~s" #$board)))))) | |
938 | (add-after 'configure 'disable-tools-libcrypto | |
939 | ;; Disable libcrypto due to GPL and OpenSSL license | |
940 | ;; incompatibilities | |
941 | (lambda _ | |
942 | (substitute* ".config" | |
943 | (("CONFIG_TOOLS_LIBCRYPTO=.*$") | |
944 | "CONFIG_TOOLS_LIBCRYPTO=n")))) | |
945 | (replace 'install | |
946 | (lambda _ | |
947 | (let ((libexec (string-append #$output "/libexec")) | |
948 | (uboot-files | |
949 | (append | |
950 | (remove | |
951 | ;; Those would not be reproducible | |
952 | ;; because of the randomness used to | |
953 | ;; produce them. It's expected that the | |
954 | ;; user will use u-boot-tools to generate | |
955 | ;; them instead. | |
956 | (lambda (name) | |
957 | (string-suffix? | |
958 | "sunxi-spl-with-ecc.bin" | |
959 | name)) | |
960 | (find-files "." | |
64e526c3 | 961 | ".*\\.(bin|efi|img|imx|spl|itb|dtb|rksd)$")) |
d970d6a0 MC |
962 | (find-files "." "^(MLO|SPL)$")))) |
963 | (mkdir-p libexec) | |
964 | (install-file ".config" libexec) | |
965 | ;; Useful for "qemu -kernel". | |
966 | (install-file "u-boot" libexec) | |
967 | (for-each | |
968 | (lambda (file) | |
969 | (let ((target-file (string-append libexec "/" file))) | |
970 | (mkdir-p (dirname target-file)) | |
971 | (copy-file file target-file))) | |
972 | uboot-files))))))))))) | |
862e38d5 | 973 | |
d6ea9f8b MC |
974 | (define-public u-boot-am335x-boneblack |
975 | (let ((base (make-u-boot-package | |
976 | "am335x_evm" "arm-linux-gnueabihf" | |
977 | ;; Patch out other device trees to build an image small enough | |
978 | ;; to fit within typical partitioning schemes where the first | |
979 | ;; partition begins at sector 2048. | |
980 | #:configs '("CONFIG_OF_LIST=\"am335x-evm am335x-boneblack\"") | |
981 | #:append-description | |
982 | "This U-Boot is built for the BeagleBone Black, which was | |
983 | removed upstream, adjusted from the am335x_evm build with several device trees | |
984 | removed so that it fits within common partitioning schemes."))) | |
985 | (package | |
986 | (inherit base) | |
987 | ;; The name is not derived from the board name on purpose, as the config | |
988 | ;; is modified per the comment above, parting from the default | |
989 | ;; am335x_evm configuration. | |
990 | (name "u-boot-am335x-boneblack")))) | |
6b99afee VC |
991 | |
992 | (define-public u-boot-am335x-evm | |
993 | (make-u-boot-package "am335x_evm" "arm-linux-gnueabihf")) | |
4adeb3f6 | 994 | |
a3f638e7 S |
995 | (define*-public (make-u-boot-sunxi64-package board triplet |
996 | #:key defconfig configs) | |
997 | (let ((base (make-u-boot-package | |
998 | board triplet #:defconfig defconfig #:configs configs))) | |
29be6cfb EF |
999 | (package |
1000 | (inherit base) | |
1001 | (arguments | |
a3f638e7 S |
1002 | (substitute-keyword-arguments (package-arguments base) |
1003 | ((#:phases phases) | |
126e07a2 MC |
1004 | #~(modify-phases #$phases |
1005 | (add-after 'unpack 'set-environment | |
1006 | (lambda* (#:key native-inputs inputs #:allow-other-keys) | |
1007 | (setenv "BL31" (search-input-file inputs "bl31.bin")))))))) | |
1008 | (inputs | |
1009 | (modify-inputs (package-inputs base) | |
1010 | (append arm-trusted-firmware-sun50i-a64)))))) | |
29be6cfb | 1011 | |
0da3526d VC |
1012 | (define-public u-boot-pine64-plus |
1013 | (make-u-boot-sunxi64-package "pine64_plus" "aarch64-linux-gnu")) | |
1014 | ||
af58b275 MO |
1015 | (define-public u-boot-pine64-lts |
1016 | (make-u-boot-sunxi64-package "pine64-lts" "aarch64-linux-gnu")) | |
1017 | ||
74e35e8c | 1018 | (define-public u-boot-pinebook |
a3f638e7 S |
1019 | (make-u-boot-sunxi64-package |
1020 | "pinebook" "aarch64-linux-gnu" | |
1021 | ;; Fix regression with LCD video output introduced in 2020.01 | |
1022 | ;; https://patchwork.ozlabs.org/patch/1225130/ | |
1023 | #:configs '("CONFIG_VIDEO_BPP32=y"))) | |
74e35e8c | 1024 | |
e830c9d0 | 1025 | (define-public u-boot-bananapi-m2-ultra |
30aeb846 DM |
1026 | (make-u-boot-package "Bananapi_M2_Ultra" "arm-linux-gnueabihf")) |
1027 | ||
c55c6985 DM |
1028 | (define-public u-boot-a20-olinuxino-lime |
1029 | (make-u-boot-package "A20-OLinuXino-Lime" "arm-linux-gnueabihf")) | |
1030 | ||
4b9e9abb DM |
1031 | (define-public u-boot-a20-olinuxino-lime2 |
1032 | (make-u-boot-package "A20-OLinuXino-Lime2" "arm-linux-gnueabihf")) | |
1033 | ||
a7bb327e DM |
1034 | (define-public u-boot-a20-olinuxino-micro |
1035 | (make-u-boot-package "A20-OLinuXino_MICRO" "arm-linux-gnueabihf")) | |
1036 | ||
84ee3378 | 1037 | (define-public u-boot-nintendo-nes-classic-edition |
dd7df191 | 1038 | (let ((base (make-u-boot-package "Nintendo_NES_Classic_Edition" |
c2c1dfdf S |
1039 | "arm-linux-gnueabihf" |
1040 | #:append-description "This version is for | |
1041 | the Nintendo NES Classic Edition. It is assumed that you have added a serial | |
1042 | port to pins PB0 and PB1 as described on | |
1043 | @url{https://linux-sunxi.org/Nintendo_NES_Classic_Edition}. | |
1044 | ||
1045 | In order to use FEL mode on the device, hold the Reset button on the | |
1046 | device while it's being turned on (and a while longer)."))) | |
dd7df191 DM |
1047 | (package |
1048 | (inherit base) | |
1049 | ;; Starting with 2019.01, FEL doesn't work anymore on A33. | |
1050 | (version "2018.11") | |
1051 | (source (origin | |
1052 | (method url-fetch) | |
1053 | (uri (string-append | |
1054 | "https://ftp.denx.de/pub/u-boot/" | |
1055 | "u-boot-" version ".tar.bz2")) | |
1056 | (sha256 | |
1057 | (base32 | |
1058 | "0znkwljfwwn4y7j20pzz4ilqw8znphrfxns0x1lwdzh3xbr96z3k")) | |
1059 | (patches (search-patches | |
8cac149e | 1060 | "u-boot-nintendo-nes-serial.patch")))) |
dd7df191 DM |
1061 | (native-inputs |
1062 | `(("python" ,python-2) | |
1063 | ,@(package-native-inputs base)))))) | |
84ee3378 | 1064 | |
95a3422e VC |
1065 | (define-public u-boot-wandboard |
1066 | (make-u-boot-package "wandboard" "arm-linux-gnueabihf")) | |
1067 | ||
adc61d72 VC |
1068 | (define-public u-boot-mx6cuboxi |
1069 | (make-u-boot-package "mx6cuboxi" "arm-linux-gnueabihf")) | |
1070 | ||
1b960787 | 1071 | (define-public u-boot-novena |
c2c1dfdf S |
1072 | (make-u-boot-package |
1073 | "novena" "arm-linux-gnueabihf" | |
1074 | ;; Patch configuration to disable loading u-boot.img from FAT partition, | |
1075 | ;; allowing it to be installed at a device offset. | |
1076 | #:configs '("# CONFIG_SPL_FS_FAT is not set") | |
1077 | #:append-description "This U-Boot is built for Novena. Be advised that this | |
1078 | version, contrary to Novena upstream, does not load u-boot.img from the first | |
1079 | partition.")) | |
1b960787 | 1080 | |
dd4fe0c2 DM |
1081 | (define-public u-boot-cubieboard |
1082 | (make-u-boot-package "Cubieboard" "arm-linux-gnueabihf")) | |
1083 | ||
a7d5ce94 JL |
1084 | (define-public u-boot-cubietruck |
1085 | (make-u-boot-package "Cubietruck" "arm-linux-gnueabihf")) | |
1086 | ||
6fe16577 VC |
1087 | (define-public u-boot-puma-rk3399 |
1088 | (let ((base (make-u-boot-package "puma-rk3399" "aarch64-linux-gnu"))) | |
1089 | (package | |
1090 | (inherit base) | |
1091 | (arguments | |
d1ef19e7 MC |
1092 | (substitute-keyword-arguments (package-arguments base) |
1093 | ((#:phases phases) | |
12f1b5fe MC |
1094 | #~(modify-phases #$phases |
1095 | (add-after 'unpack 'set-environment | |
1096 | (lambda* (#:key inputs #:allow-other-keys) | |
1097 | (setenv "BL31" (search-input-file inputs "/bl31.elf")))) | |
1098 | ;; Phases do not succeed on the bl31 ELF. | |
1099 | (delete 'strip) | |
1100 | (delete 'validate-runpath))))) | |
1101 | (inputs | |
1102 | (modify-inputs (package-native-inputs base) | |
1103 | (append arm-trusted-firmware-rk3399)))))) | |
6fe16577 | 1104 | |
36f7b1f0 DGC |
1105 | (define-public u-boot-qemu-arm |
1106 | (make-u-boot-package "qemu_arm" "arm-linux-gnueabihf" | |
1107 | ;; Disable features that require OpenSSL due | |
8a68407a DGC |
1108 | ;; to GPL/Openssl license incompatibilities. |
1109 | ;; See https://bugs.gnu.org/34717 for | |
1110 | ;; details. | |
1111 | #:configs '("# CONFIG_FIT_SIGNATURE is not set"))) | |
1112 | ||
1113 | (define-public u-boot-qemu-arm64 | |
1114 | (make-u-boot-package "qemu_arm64" "aarch64-linux-gnu" | |
1115 | ;; Disable features that require OpenSSL due | |
36f7b1f0 DGC |
1116 | ;; to GPL/Openssl license incompatibilities. |
1117 | ;; See https://bugs.gnu.org/34717 for | |
1118 | ;; details. | |
1119 | #:configs '("# CONFIG_FIT_SIGNATURE is not set"))) | |
1120 | ||
10f31af9 VC |
1121 | (define-public u-boot-qemu-riscv64 |
1122 | (make-u-boot-package "qemu-riscv64" "riscv64-linux-gnu")) | |
1123 | ||
7e954f67 | 1124 | (define-public u-boot-qemu-riscv64-smode |
4a0d0459 | 1125 | (make-u-boot-package "qemu-riscv64_smode" "riscv64-linux-gnu")) |
7e954f67 | 1126 | |
6433d49a MC |
1127 | (define-public u-boot-sandbox |
1128 | (let ((base (make-u-boot-package | |
1129 | "sandbox" #f ;build for the native system | |
1130 | ;; Disable CONFIG_TOOLS_LIBCRYPTO, CONFIG_FIT_SIGNATURE and | |
1131 | ;; CONFIG_FIT_CIPHER and their selectors as these features | |
1132 | ;; require OpenSSL, which is incompatible with the GPLv2-only | |
1133 | ;; parts of U-boot. The options below replicate the changes | |
1134 | ;; that disabling the above features in 'make menuconfig' then | |
1135 | ;; refreshing the defconfig with 'make savedefconfig' would do. | |
1136 | #:configs (list "# CONFIG_FIT_RSASSA_PSS is not set" | |
1137 | "# CONFIG_FIT_CIPHER is not set" | |
1138 | "# CONFIG_LEGACY_IMAGE_FORMAT is not set" | |
1139 | "# CONFIG_IMAGE_PRE_LOAD is not set" | |
1140 | "# CONFIG_IMAGE_PRE_LOAD_SIG is not set" | |
1141 | "# CONFIG_CMD_BOOTM_PRE_LOAD is not set" | |
1142 | "CONFIG_RSA=y" | |
1143 | "# CONFIG_EFI_SECURE_BOOT is not set" | |
1144 | "# CONFIG_TOOLS_LIBCRYPTO is not set") | |
1145 | #:append-description | |
1146 | "The sandbox configuration of U-Boot provides a | |
1147 | @command{u-boot} command that runs as a normal user space application. It can | |
1148 | be used to test the functionality of U-Boot interactively without having to | |
1149 | deploy to an actual target device. @xref{Sandbox<6>,,,u-boot, The U-Boot | |
1150 | Documentation} for more information (for example by running @samp{info | |
1151 | \"(u-boot) Sandbox<6>\"})."))) | |
1152 | (package | |
1153 | (inherit base) | |
1154 | (arguments | |
1155 | (substitute-keyword-arguments (package-arguments base) | |
1156 | ((#:phases phases '%standard-phases) | |
1157 | #~(modify-phases #$phases | |
1158 | (add-after 'install 'symlink-u-boot-command | |
1159 | (lambda* (#:key outputs #:allow-other-keys) | |
1160 | ;; For ease of discovery. | |
1161 | (mkdir (string-append #$output "/bin")) | |
1162 | (symlink (search-input-file outputs "libexec/u-boot") | |
1163 | (string-append #$output "/bin/u-boot")))))))) | |
1164 | (inputs (modify-inputs (package-inputs base) | |
1165 | (append sdl2)))))) | |
1166 | ||
e914fc59 PL |
1167 | (define-public u-boot-sifive-unleashed |
1168 | (make-u-boot-package "sifive_unleashed" "riscv64-linux-gnu")) | |
7d063645 | 1169 | |
df3a60d1 | 1170 | (define-public u-boot-sifive-unmatched |
1acd0bf8 EF |
1171 | (let ((base (make-u-boot-package "sifive_unmatched" "riscv64-linux-gnu"))) |
1172 | (package | |
1173 | (inherit base) | |
1174 | (arguments | |
1175 | (substitute-keyword-arguments (package-arguments base) | |
1176 | ((#:phases phases) | |
4dd0378d MC |
1177 | #~(modify-phases #$phases |
1178 | (add-after 'unpack 'set-environment | |
1179 | (lambda* (#:key inputs #:allow-other-keys) | |
1180 | (setenv "OPENSBI" (search-input-file inputs | |
1181 | "fw_dynamic.bin")))))))) | |
1acd0bf8 | 1182 | (inputs |
4dd0378d MC |
1183 | (modify-inputs (package-inputs base) |
1184 | (append opensbi-generic)))))) | |
df3a60d1 | 1185 | |
2fce14af VC |
1186 | (define-public u-boot-rock64-rk3328 |
1187 | (let ((base (make-u-boot-package "rock64-rk3328" "aarch64-linux-gnu"))) | |
1188 | (package | |
1189 | (inherit base) | |
2fce14af VC |
1190 | (arguments |
1191 | (substitute-keyword-arguments (package-arguments base) | |
1192 | ((#:phases phases) | |
e7d82f47 MC |
1193 | #~(modify-phases #$phases |
1194 | (add-after 'unpack 'set-environment | |
1195 | (lambda* (#:key native-inputs inputs #:allow-other-keys) | |
df8b8f0c | 1196 | (setenv "BL31" (search-input-file inputs "bl31.elf")))))))) |
e7d82f47 MC |
1197 | (inputs |
1198 | (modify-inputs (package-inputs base) | |
1199 | (append arm-trusted-firmware-rk3328)))))) | |
2fce14af | 1200 | |
545ff7b7 VC |
1201 | (define-public u-boot-firefly-rk3399 |
1202 | (let ((base (make-u-boot-package "firefly-rk3399" "aarch64-linux-gnu"))) | |
1203 | (package | |
1204 | (inherit base) | |
545ff7b7 | 1205 | (arguments |
a18aaa26 MC |
1206 | (substitute-keyword-arguments (package-arguments base) |
1207 | ((#:phases phases) | |
3f398ea9 MC |
1208 | #~(modify-phases #$phases |
1209 | (add-after 'unpack 'set-environment | |
1210 | (lambda* (#:key native-inputs inputs #:allow-other-keys) | |
1211 | (setenv "BL31" (search-input-file inputs "bl31.elf")))) | |
1212 | ;; Phases do not succeed on the bl31 ELF. | |
1213 | (delete 'strip) | |
1214 | (delete 'validate-runpath))))) | |
1215 | (inputs | |
1216 | (modify-inputs (package-inputs base) | |
1217 | (append arm-trusted-firmware-rk3399)))))) | |
545ff7b7 | 1218 | |
fa747018 | 1219 | (define-public u-boot-rockpro64-rk3399 |
a3f638e7 S |
1220 | (let ((base (make-u-boot-package "rockpro64-rk3399" "aarch64-linux-gnu" |
1221 | #:configs '("CONFIG_USB=y" | |
1222 | "CONFIG_AHCI=y" | |
1223 | "CONFIG_AHCI_PCI=y" | |
1224 | "CONFIG_SATA=y" | |
1225 | "CONFIG_SATA_SIL=y" | |
1226 | "CONFIG_SCSI=y" | |
1227 | "CONFIG_SCSI_AHCI=y" | |
1228 | "CONFIG_DM_SCSI=y")))) | |
fa747018 CN |
1229 | (package |
1230 | (inherit base) | |
5327b399 | 1231 | (arguments |
24b0fe34 MC |
1232 | (substitute-keyword-arguments (package-arguments base) |
1233 | ((#:phases phases) | |
ea0d3e1e MC |
1234 | #~(modify-phases #$phases |
1235 | (add-after 'unpack 'set-environment | |
1236 | (lambda* (#:key inputs #:allow-other-keys) | |
1237 | (setenv "BL31" (search-input-file inputs "/bl31.elf")))) | |
1238 | (add-after 'unpack 'patch-header | |
1239 | (lambda _ | |
1240 | (substitute* "include/config_distro_bootcmd.h" | |
1241 | (("\"scsi_need_init=false") | |
1242 | "\"setenv scsi_need_init false") | |
1243 | (("#define BOOTENV_SET_SCSI_NEED_INIT \"scsi_need_init=;") | |
1244 | "#define BOOTENV_SET_SCSI_NEED_INIT \"setenv scsi_need_init;")) | |
1245 | (substitute* "include/configs/rockchip-common.h" | |
1246 | (("#define BOOT_TARGET_DEVICES\\(func\\)") | |
1247 | " | |
d643ef38 RW |
1248 | #if CONFIG_IS_ENABLED(CMD_SCSI) |
1249 | #define BOOT_TARGET_SCSI(func) func(SCSI, scsi, 0) | |
1250 | #else | |
1251 | #define BOOT_TARGET_SCSI(func) | |
1252 | #endif | |
1253 | #define BOOT_TARGET_DEVICES(func)") | |
ea0d3e1e MC |
1254 | (("BOOT_TARGET_NVME\\(func\\) \\\\") |
1255 | "\ | |
d643ef38 RW |
1256 | BOOT_TARGET_NVME(func) \\ |
1257 | BOOT_TARGET_SCSI(func) \\")))) | |
ea0d3e1e MC |
1258 | ;; Phases do not succeed on the bl31 ELF. |
1259 | (delete 'strip) | |
1260 | (delete 'validate-runpath))))) | |
1261 | (inputs | |
1262 | (modify-inputs (package-inputs base) | |
1263 | (append arm-trusted-firmware-rk3399)))))) | |
5327b399 VC |
1264 | |
1265 | (define-public u-boot-pinebook-pro-rk3399 | |
1266 | (let ((base (make-u-boot-package "pinebook-pro-rk3399" "aarch64-linux-gnu"))) | |
1267 | (package | |
eb46c6c5 | 1268 | (inherit base) |
fa747018 | 1269 | (arguments |
df251655 MC |
1270 | (substitute-keyword-arguments (package-arguments base) |
1271 | ((#:phases phases) | |
c9c19593 MC |
1272 | #~(modify-phases #$phases |
1273 | (add-after 'unpack 'set-environment | |
1274 | (lambda* (#:key native-inputs inputs #:allow-other-keys) | |
1275 | (setenv "BL31" (search-input-file inputs "bl31.elf")))) | |
1276 | ;; Phases do not succeed on the bl31 ELF. | |
1277 | (delete 'strip) | |
1278 | (delete 'validate-runpath))))) | |
1279 | (inputs | |
1280 | (modify-inputs (package-inputs base) | |
1281 | (append arm-trusted-firmware-rk3399)))))) | |
fa747018 | 1282 | |
c2c1dfdf S |
1283 | (define*-public (make-u-boot-bin-package u-boot-package |
1284 | #:key | |
1285 | (u-boot-bin "u-boot.bin")) | |
1286 | "Return a package with a single U-BOOT-BIN file from the U-BOOT-PACKAGE. | |
1287 | The package name will be that of the U-BOOT package suffixed with \"-bin\"." | |
1288 | (package | |
1289 | (name (string-append (package-name u-boot-package) "-bin")) | |
1290 | (version (package-version u-boot-package)) | |
1291 | (source #f) | |
1292 | (build-system trivial-build-system) | |
1293 | (arguments | |
1294 | (list | |
1295 | #:builder | |
1296 | (with-imported-modules '((guix build utils)) | |
1297 | #~(begin | |
1298 | (use-modules (guix build utils)) | |
1299 | (mkdir #$output) | |
1300 | (symlink (search-input-file %build-inputs | |
1301 | (string-append "libexec/" #$u-boot-bin)) | |
1302 | (string-append #$output "/" #$u-boot-bin)))))) | |
1303 | (inputs (list u-boot-package)) | |
1304 | (home-page (package-home-page u-boot-package)) | |
1305 | (synopsis (package-synopsis u-boot-package)) | |
1306 | (description (string-append | |
1307 | (package-description u-boot-package) | |
1308 | "\n\n" | |
1309 | (format #f | |
1310 | "This package only contains the file ~a." | |
1311 | u-boot-bin))) | |
1312 | (license (package-license u-boot-package)))) | |
1313 | ||
1314 | (define-public %u-boot-rpi-efi-configs | |
1315 | '("CONFIG_OF_EMBED" | |
1316 | "CONFIG_OF_BOARD=y")) | |
1317 | ||
1318 | (define %u-boot-rpi-description-32-bit | |
1319 | "This is a 32-bit build of U-Boot.") | |
1320 | ||
1321 | (define %u-boot-rpi-description-64-bit | |
1322 | "This is a common 64-bit build of U-Boot for all 64-bit capable Raspberry Pi | |
1323 | variants.") | |
1324 | ||
1325 | (define %u-boot-rpi-efi-description | |
1326 | "It allows network booting and uses the device-tree from the firmware, | |
1327 | allowing the usage of overlays. It can act as an EFI firmware for the | |
1328 | grub-efi-netboot-removable-bootloader.") | |
1329 | ||
1330 | (define %u-boot-rpi-efi-description-32-bit | |
1331 | (string-append %u-boot-rpi-efi-description " " | |
1332 | %u-boot-rpi-description-32-bit)) | |
1333 | ||
1334 | (define-public u-boot-rpi-2 | |
1335 | (make-u-boot-package "rpi_2" "arm-linux-gnueabihf" | |
1336 | #:append-description %u-boot-rpi-description-32-bit)) | |
1337 | ||
1338 | (define-public u-boot-rpi-3-32b | |
1339 | (make-u-boot-package "rpi_3_32b" "arm-linux-gnueabihf" | |
1340 | #:append-description %u-boot-rpi-description-32-bit)) | |
1341 | ||
1342 | (define-public u-boot-rpi-4-32b | |
1343 | (make-u-boot-package "rpi_4_32b" "arm-linux-gnueabihf" | |
1344 | #:append-description %u-boot-rpi-description-32-bit)) | |
1345 | ||
1346 | (define-public u-boot-rpi-arm64 | |
1347 | (make-u-boot-package "rpi_arm64" "aarch64-linux-gnu" | |
1348 | #:append-description %u-boot-rpi-description-64-bit)) | |
1349 | ||
1350 | (define-public u-boot-rpi-2-efi | |
1351 | (make-u-boot-package "rpi_2" "arm-linux-gnueabihf" | |
1352 | #:name-suffix "-efi" | |
1353 | #:configs %u-boot-rpi-efi-configs | |
1354 | #:append-description %u-boot-rpi-efi-description-32-bit)) | |
1355 | ||
1356 | (define-public u-boot-rpi-3-32b-efi | |
1357 | (make-u-boot-package "rpi_3_32b" "arm-linux-gnueabihf" | |
1358 | #:name-suffix "-efi" | |
1359 | #:configs %u-boot-rpi-efi-configs | |
1360 | #:append-description %u-boot-rpi-efi-description-32-bit)) | |
1361 | ||
1362 | (define-public u-boot-rpi-4-32b-efi | |
1363 | (make-u-boot-package "rpi_4_32b" "arm-linux-gnueabihf" | |
1364 | #:name-suffix "-efi" | |
1365 | #:configs %u-boot-rpi-efi-configs | |
1366 | #:append-description %u-boot-rpi-efi-description-32-bit)) | |
1367 | ||
1368 | (define-public u-boot-rpi-arm64-efi | |
1369 | (make-u-boot-package "rpi_arm64""aarch64-linux-gnu" | |
1370 | #:name-suffix "-efi" | |
1371 | #:configs %u-boot-rpi-efi-configs | |
1372 | #:append-description (string-append | |
1373 | %u-boot-rpi-efi-description " " | |
1374 | %u-boot-rpi-description-64-bit))) | |
1375 | ||
1376 | (define-public u-boot-rpi-2-bin (make-u-boot-bin-package u-boot-rpi-2)) | |
1377 | ||
1378 | (define-public u-boot-rpi-3_32b-bin (make-u-boot-bin-package u-boot-rpi-3-32b)) | |
1379 | ||
1380 | (define-public u-boot-rpi-4_32b-bin (make-u-boot-bin-package u-boot-rpi-4-32b)) | |
1381 | ||
1382 | (define-public u-boot-rpi-arm64-bin (make-u-boot-bin-package u-boot-rpi-arm64)) | |
1383 | ||
1384 | (define-public u-boot-rpi-2-efi-bin (make-u-boot-bin-package u-boot-rpi-2-efi)) | |
1385 | ||
1386 | (define-public u-boot-rpi-3-32b-efi-bin | |
1387 | (make-u-boot-bin-package u-boot-rpi-3-32b-efi)) | |
1388 | ||
1389 | (define-public u-boot-rpi-4-32b-efi-bin | |
1390 | (make-u-boot-bin-package u-boot-rpi-4-32b-efi)) | |
1391 | ||
1392 | (define-public u-boot-rpi-arm64-efi-bin | |
1393 | (make-u-boot-bin-package u-boot-rpi-arm64-efi)) | |
1394 | ||
d393e89d MC |
1395 | (define u-boot-ts-mx6 |
1396 | ;; There is no release; use the latest commit of the | |
1397 | ;; 'imx_v2015.04_3.14.52_1.1.0_ga' branch. | |
1398 | (let ((revision "0") | |
1399 | (commit "08809160fbc60d6e949fa9d37d9a41aab8fef742")) | |
1400 | (package | |
1401 | (inherit u-boot) | |
1402 | (name "u-boot-ts-mx6") | |
1403 | (version (git-version "2015.04_3" revision commit)) | |
1404 | (source (origin | |
1405 | (method git-fetch) | |
1406 | (uri (git-reference | |
1407 | (url "https://github.com/embeddedTS/u-boot-imx") | |
1408 | (commit commit))) | |
1409 | (file-name (git-file-name "u-boot-imx-ts" version)) | |
1410 | (sha256 | |
1411 | (base32 | |
1412 | "01mja33351hkcs59rmfvppqlxqw4rh9gng7a7hx2cfspqwh2y6kr")))) | |
1413 | (arguments | |
1414 | (substitute-keyword-arguments (package-arguments u-boot) | |
1415 | ((#:phases phases '%standard-phases) | |
1416 | #~(modify-phases #$phases | |
1417 | (add-after 'unpack 'patch-u-boot | |
1418 | (lambda _ | |
1419 | (substitute* (find-files "include/configs" "^ts[0-9]{4}\\.h$") | |
1420 | ;; Default to boot a standard zImage instead of a uImage. | |
1421 | (("/boot/uImage") | |
1422 | "/boot/zImage") | |
1423 | (("uimage") | |
1424 | "zimage") | |
1425 | (("bootm \\$\\{loadaddr}") | |
1426 | "bootz ${loadaddr}") | |
1427 | ;; This reference DTB is not available in mainline. | |
1428 | (("ts7970-revf.dtb") | |
1429 | "ts7970.dtb") | |
1430 | ;; Enable support for DISTRO_DEFAULTS, which enables to | |
1431 | ;; use 'sysboot' to boot Guix System. Also enable | |
1432 | ;; "standard" boot commands for dealing with discovery and | |
1433 | ;; booting of syslinux configurations (extlinux.conf). | |
1434 | ||
1435 | ;; Disable the stock CONFIG_BOOTCOMMAND to avoid a | |
1436 | ;; redefinition error. | |
1437 | (("CONFIG_BOOTCOMMAND") | |
1438 | "CONFIG_BOOTCOMMAND_DISABLED") | |
1439 | (("CONFIG_BOOTDELAY") | |
1440 | "CONFIG_BOOTDELAY_DISABLED") | |
1441 | ;; Inspired by include/configs/embestmx6boards.h | |
1442 | (("#define CONFIG_EXTRA_ENV_SETTINGS.*" anchor) | |
1443 | (string-append "\ | |
1444 | #include <config_distro_defaults.h> | |
1445 | ||
1446 | #define MEM_LAYOUT_ENV_SETTINGS \\ | |
1447 | \t\"bootm_size=0x10000000\\0\" \\ | |
1448 | \t\"kernel_addr_r=0x10800000\\0\" \\ | |
1449 | \t\"fdt_addr_r=0x18000000\\0\" \\ | |
1450 | \t\"scriptaddr=0x18100000\\0\" \\ | |
1451 | \t\"pxefile_addr_r=0x18200000\\0\" \\ | |
1452 | \t\"ramdisk_addr_r=0x18300000\\0\" | |
1453 | ||
1454 | #define BOOT_TARGET_DEVICES(func) \\ | |
1455 | \tfunc(MMC, mmc, 0) \\ | |
1456 | \tfunc(MMC, mmc, 1) \\ | |
1457 | \tfunc(SATA, sata, 0) \\ | |
1458 | \tfunc(USB, usb, 0) \\ | |
1459 | \tfunc(PXE, pxe, na) \\ | |
1460 | \tfunc(DHCP, dhcp, na) | |
1461 | ||
1462 | #include <config_distro_bootcmd.h> | |
1463 | ||
1464 | " anchor | |
1465 | ||
1466 | ;; Sadly, the user config CONFIG_DEFAULT_FDT_FILE did not exist in that older | |
1467 | ;; U-Boot. A placeholder is added here, to be substituted in each TS U-Boot | |
1468 | ;; board package. | |
1469 | "\ | |
1470 | \t\"fdtfile=DEFAULT_FDT_FILE\\0\" \\ | |
1471 | \tMEM_LAYOUT_ENV_SETTINGS \\ | |
1472 | \tBOOTENV \\\n"))))) | |
1473 | (add-after 'unpack 'patch-for-reproducibility | |
1474 | (lambda _ | |
1475 | ;; Substitute dynamically computed timestamps with static | |
1476 | ;; ones. | |
1477 | (substitute* "Makefile" | |
1478 | (("U_BOOT_DATE \"%b %d %C%y\"") | |
1479 | "U_BOOT_DATE \"Jan 01 1969\"") | |
1480 | (("U_BOOT_TIME \"%T\"") | |
1481 | "U_BOOT_TIME \"00:00:00\"")))) | |
1482 | (add-before 'build 'adjust-for-gcc10 | |
1483 | (lambda _ | |
1484 | (copy-file "include/linux/compiler-gcc6.h" | |
1485 | "include/linux/compiler-gcc10.h") | |
1486 | (substitute* "arch/arm/Makefile" | |
1487 | (("march=armv5") | |
1488 | "march=armv5te")))) | |
1489 | (add-after 'install 'build+install-tools | |
1490 | (lambda* (#:key make-flags #:allow-other-keys) | |
1491 | (apply invoke "make" "tools-all" make-flags) | |
1492 | (install-file "tools/env/fw_printenv" | |
1493 | (string-append #$output "/bin")) | |
1494 | (symlink (string-append #$output "/bin/fw_printenv") | |
1495 | (string-append #$output "/bin/fw_setenv")))))))) | |
1496 | (native-inputs | |
1497 | (modify-inputs (package-native-inputs u-boot) | |
1498 | (delete "dtc")))))) ;otherwise the build fails | |
1499 | ||
1500 | ;;; Note: the default cross-build of this package is currently broken on | |
1501 | ;;; master; the fix exists as commit 6454208222d6e7760daa964b590f35ea75ffe0e5 | |
1502 | ;;; ("build: gnu-build-system: Remove source from native inputs.") on | |
1503 | ;;; core-updates. | |
1504 | (define-public u-boot-ts7970-q-2g-1000mhz-c | |
1505 | (let ((base | |
1506 | (make-u-boot-package "ts7970-q-2g-1000mhz-c" "arm-linux-gnueabihf" | |
1507 | #:u-boot u-boot-ts-mx6 | |
1508 | #:append-description | |
1509 | "This U-Boot variant is for the Technologic | |
1510 | Systems TS-7970 revision C board, which includes a quad core Freescale i.MX6 | |
1511 | CPU and 2 GiB of RAM clocked at 1000MHz. The binary U-Boot image to flash is | |
1512 | the @file{libexec/u-boot.imx} file. It can be used with the @file{zImage} and | |
1513 | the @file{imx6q-ts7970.dtb} files provided by the | |
1514 | @code{linux-libre-arm-generic} image. | |
1515 | ||
1516 | To flash this bootloader, write it to an SD card, then using the U-Boot serial | |
1517 | console: | |
1518 | @example | |
1519 | mmc dev 0 | |
01fd830f | 1520 | load mmc 0:1 ${loadaddr} /boot/u-boot.imx |
d393e89d MC |
1521 | sf probe |
1522 | sf erase 0 0x80000 | |
1523 | sf write ${loadaddr} 0x400 $filesize | |
1524 | @end example | |
1525 | ||
1526 | The factory values of U-Boot must also be reset so that it boots using a | |
1527 | zImage instead of the default uImage: | |
1528 | @example | |
1529 | run clearenv | |
1530 | reset | |
1531 | @end example | |
1532 | ||
1533 | For more information, refer to | |
1534 | @url{https://docs.embeddedts.com/TS-7970#Update_U-Boot}."))) | |
1535 | (package | |
1536 | (inherit base) | |
1537 | (arguments | |
1538 | (substitute-keyword-arguments (package-arguments base) | |
1539 | ((#:phases phases '%standard-phases) | |
1540 | #~(modify-phases #$phases | |
1541 | (add-after 'patch-u-boot 'set-default-fdt-file | |
1542 | (lambda _ | |
1543 | (substitute* "include/configs/ts7970.h" | |
1544 | (("DEFAULT_FDT_FILE") | |
1545 | "imx6q-ts7970.dtb"))))))))))) | |
1546 | ||
a60f1319 MB |
1547 | (define-public vboot-utils |
1548 | (package | |
1549 | (name "vboot-utils") | |
1550 | (version "R63-10032.B") | |
1551 | (source (origin | |
1552 | ;; XXX: Snapshots are available but changes timestamps every download. | |
1553 | (method git-fetch) | |
1554 | (uri (git-reference | |
1555 | (url (string-append "https://chromium.googlesource.com" | |
1556 | "/chromiumos/platform/vboot_reference")) | |
1557 | (commit (string-append "release-" version)))) | |
1558 | (file-name (string-append name "-" version "-checkout")) | |
1559 | (sha256 | |
1560 | (base32 | |
b634b5c2 KK |
1561 | "0h0m3l69vp9dr6xrs1p6y7ilkq3jq8jraw2z20kqfv7lvc9l1lxj")) |
1562 | (patches | |
1563 | (search-patches "vboot-utils-skip-test-workbuf.patch" | |
1564 | "vboot-utils-fix-tests-show-contents.patch" | |
1565 | "vboot-utils-fix-format-load-address.patch")))) | |
a60f1319 MB |
1566 | (build-system gnu-build-system) |
1567 | (arguments | |
1568 | `(#:make-flags (list "CC=gcc" | |
b634b5c2 KK |
1569 | ;; On ARM, we must pass "HOST_ARCH=arm" so that the |
1570 | ;; ${HOST_ARCH} and ${ARCH} variables in the makefile | |
1571 | ;; match. Otherwise, ${HOST_ARCH} will be assigned | |
1572 | ;; "armv7l", the value of `uname -m`, and will not | |
1573 | ;; match ${ARCH}, which will make the tests require | |
1574 | ;; QEMU for testing. | |
1575 | ,@(if (string-prefix? "arm" | |
1576 | (or (%current-target-system) | |
1577 | (%current-system))) | |
1578 | '("HOST_ARCH=arm") | |
1579 | '()) | |
a60f1319 MB |
1580 | (string-append "DESTDIR=" (assoc-ref %outputs "out"))) |
1581 | #:phases (modify-phases %standard-phases | |
1582 | (add-after 'unpack 'patch-hard-coded-paths | |
1583 | (lambda* (#:key inputs outputs #:allow-other-keys) | |
1584 | (let ((coreutils (assoc-ref inputs "coreutils")) | |
1585 | (diffutils (assoc-ref inputs "diffutils"))) | |
1586 | (substitute* "futility/misc.c" | |
1587 | (("/bin/cp") (string-append coreutils "/bin/cp"))) | |
1588 | (substitute* "tests/bitmaps/TestBmpBlock.py" | |
1589 | (("/usr/bin/cmp") (string-append diffutils "/bin/cmp"))) | |
1590 | (substitute* "vboot_host.pc.in" | |
1591 | (("prefix=/usr") | |
1592 | (string-append "prefix=" (assoc-ref outputs "out")))) | |
1593 | #t))) | |
1594 | (delete 'configure) | |
1595 | (add-before 'check 'patch-tests | |
1596 | (lambda _ | |
1597 | ;; These tests compare diffs against known-good values. | |
1598 | ;; Patch the paths to match those in the build container. | |
1599 | (substitute* (find-files "tests/futility/expect_output") | |
1600 | (("/mnt/host/source/src/platform/vboot_reference") | |
1601 | (string-append "/tmp/guix-build-" ,name "-" ,version | |
1602 | ".drv-0/source"))) | |
1603 | ;; Tests require write permissions to many of these files. | |
1604 | (for-each make-file-writable (find-files "tests/futility")) | |
71f2b4b8 KK |
1605 | #t)) |
1606 | (add-after 'install 'install-devkeys | |
1607 | (lambda* (#:key outputs #:allow-other-keys) | |
1608 | (let* ((out (assoc-ref outputs "out")) | |
1609 | (share (string-append out "/share/vboot-utils"))) | |
1610 | (copy-recursively "tests/devkeys" | |
1611 | (string-append share "/devkeys")) | |
1612 | #t)))) | |
a60f1319 MB |
1613 | #:test-target "runtests")) |
1614 | (native-inputs | |
1615 | `(("pkg-config" ,pkg-config) | |
1616 | ||
1617 | ;; For tests. | |
1618 | ("diffutils" ,diffutils) | |
1619 | ("python@2" ,python-2))) | |
1620 | (inputs | |
1621 | `(("coreutils" ,coreutils) | |
1622 | ("libyaml" ,libyaml) | |
1623 | ("openssl" ,openssl) | |
1624 | ("openssl:static" ,openssl "static") | |
bb93042c | 1625 | ("util-linux" ,util-linux "lib"))) |
a60f1319 MB |
1626 | (home-page |
1627 | "https://dev.chromium.org/chromium-os/chromiumos-design-docs/verified-boot") | |
1628 | (synopsis "ChromiumOS verified boot utilities") | |
1629 | (description | |
1630 | "vboot-utils is a collection of tools to facilitate booting of | |
1631 | Chrome-branded devices. This includes the @command{cgpt} partitioning | |
1632 | program, the @command{futility} and @command{crossystem} firmware management | |
1633 | tools, and more.") | |
1634 | (license license:bsd-3))) | |
1635 | ||
aa90375a AI |
1636 | (define-public os-prober |
1637 | (package | |
1638 | (name "os-prober") | |
25e9bb05 | 1639 | (version "1.81") |
aa90375a AI |
1640 | (source |
1641 | (origin | |
1642 | (method url-fetch) | |
1643 | (uri (string-append "mirror://debian/pool/main/o/os-prober/os-prober_" | |
1644 | version ".tar.xz")) | |
1645 | (sha256 | |
25e9bb05 | 1646 | (base32 "10w8jz6mqhp0skdcam9mpgv79vx1sv7lkpra3rqjg0jkhvn2in9g")))) |
aa90375a AI |
1647 | (build-system gnu-build-system) |
1648 | (arguments | |
1649 | `(#:modules ((guix build gnu-build-system) | |
1650 | (guix build utils) | |
e9bdef5f TGR |
1651 | (ice-9 regex) ; for string-match |
1652 | (srfi srfi-26)) ; for cut | |
33430a45 TGR |
1653 | #:make-flags |
1654 | (list ,(string-append "CC=" (cc-for-target))) | |
e9bdef5f | 1655 | #:tests? #f ; no tests |
aa90375a AI |
1656 | #:phases |
1657 | (modify-phases %standard-phases | |
1658 | (replace 'configure | |
1659 | (lambda* (#:key outputs #:allow-other-keys) | |
1660 | (substitute* (find-files ".") | |
1661 | (("/usr") (assoc-ref outputs "out"))) | |
1662 | (substitute* (find-files "." "50mounted-tests$") | |
3666e5e4 | 1663 | (("mkdir") "mkdir -p")))) |
aa90375a AI |
1664 | (replace 'install |
1665 | (lambda* (#:key outputs #:allow-other-keys) | |
1666 | (define (find-files-non-recursive directory) | |
1667 | (find-files directory | |
1668 | (lambda (file stat) | |
1669 | (string-match (string-append "^" directory "/[^/]*$") | |
1670 | file)) | |
1671 | #:directories? #t)) | |
1672 | ||
1673 | (let* ((out (assoc-ref outputs "out")) | |
1674 | (bin (string-append out "/bin")) | |
1675 | (lib (string-append out "/lib")) | |
1676 | (share (string-append out "/share"))) | |
1677 | (for-each (cut install-file <> bin) | |
1678 | (list "linux-boot-prober" "os-prober")) | |
1679 | (install-file "newns" (string-append lib "/os-prober")) | |
1680 | (install-file "common.sh" (string-append share "/os-prober")) | |
1681 | (install-file "os-probes/mounted/powerpc/20macosx" | |
1682 | (string-append lib "/os-probes/mounted")) | |
1683 | (for-each | |
1684 | (lambda (directory) | |
1685 | (for-each | |
1686 | (lambda (file) | |
1687 | (let ((destination (string-append lib "/" directory | |
1688 | "/" (basename file)))) | |
1689 | (mkdir-p (dirname destination)) | |
1690 | (copy-recursively file destination))) | |
1691 | (append (find-files-non-recursive (string-append directory "/common")) | |
1692 | (find-files-non-recursive (string-append directory "/x86"))))) | |
1693 | (list "os-probes" "os-probes/mounted" "os-probes/init" | |
3666e5e4 | 1694 | "linux-boot-probes" "linux-boot-probes/mounted")))))))) |
aa90375a AI |
1695 | (home-page "https://joeyh.name/code/os-prober") |
1696 | (synopsis "Detect other operating systems") | |
1697 | (description "os-prober probes disks on the system for other operating | |
1698 | systems so that they can be added to the bootloader. It also works out how to | |
1699 | boot existing GNU/Linux systems and detects what distribution is installed in | |
1700 | order to add a suitable bootloader menu entry.") | |
1701 | (license license:gpl2+))) | |
aeed7218 VL |
1702 | |
1703 | (define-public ipxe | |
1704 | ;; XXX: 'BUILD_TIMESTAMP' is used to automatically select the newest version | |
1705 | ;; of iPXE if multiple iPXE drivers are loaded concurrently in a UEFI system. | |
1706 | ;; | |
1707 | ;; TODO: Bump this timestamp at each modifications of the package (not only | |
1708 | ;; for updates) by running: date +%s. | |
9279775d | 1709 | (let ((timestamp "1671715380")) |
aeed7218 VL |
1710 | (package |
1711 | (name "ipxe") | |
ca34b6f0 | 1712 | (version "1.21.1") |
aeed7218 VL |
1713 | (source (origin |
1714 | (method git-fetch) | |
1715 | (uri (git-reference | |
1716 | (url "https://github.com/ipxe/ipxe") | |
1717 | (commit (string-append "v" version)))) | |
1718 | (file-name (git-file-name name version)) | |
1719 | (patches (search-patches "ipxe-reproducible-geniso.patch")) | |
1720 | (sha256 | |
1721 | (base32 | |
ca34b6f0 | 1722 | "1pkf1n1c0rdlzfls8fvjvi1sd9xjd9ijqlyz3wigr70ijcv6x8i9")))) |
aeed7218 VL |
1723 | (build-system gnu-build-system) |
1724 | (arguments | |
b435f631 MB |
1725 | (list |
1726 | #:modules `((guix build utils) | |
aeed7218 VL |
1727 | (guix build gnu-build-system) |
1728 | (guix base32) | |
1729 | (ice-9 string-fun) | |
1730 | (ice-9 regex) | |
1731 | (rnrs bytevectors)) | |
b435f631 | 1732 | #:imported-modules `((guix base32) |
aeed7218 | 1733 | ,@%gnu-build-system-modules) |
b435f631 MB |
1734 | #:make-flags |
1735 | ;; XXX: 'BUILD_ID' is used to determine when another ROM in the | |
1736 | ;; system contains identical code in order to save space within the | |
1737 | ;; legacy BIOS option ROM area, which is extremely limited in size. | |
1738 | ;; It is supposed to be collision-free across all ROMs, to do so we | |
1739 | ;; use the truncated output hash of the package. | |
1740 | #~(let ((build-id | |
1741 | (lambda (out) | |
1742 | (let* ((nix-store (string-append | |
1743 | (or (getenv "NIX_STORE") "/gnu/store") | |
1744 | "/")) | |
1745 | (filename | |
1746 | (string-replace-substring out nix-store "")) | |
1747 | (hash (match:substring (string-match "[0-9a-z]{32}" | |
1748 | filename))) | |
1749 | (bv (nix-base32-string->bytevector hash))) | |
1750 | (format #f "0x~x" | |
1751 | (bytevector-u32-ref bv 0 (endianness big)))))) | |
1752 | (syslinux #$(this-package-native-input "syslinux"))) | |
1753 | (list "ECHO_E_BIN_ECHO=echo" | |
1754 | "ECHO_E_BIN_ECHO_E=echo -e" | |
1755 | ||
1756 | ;; cdrtools' mkisofs will silently ignore a missing isolinux.bin! | |
1757 | ;; Luckily xorriso is more strict. | |
d1597219 MB |
1758 | #$@(if (or (target-x86-64?) (target-x86?)) |
1759 | '((string-append "ISOLINUX_BIN=" syslinux | |
1760 | "/share/syslinux/isolinux.bin") | |
1761 | (string-append "SYSLINUX_MBR_DISK_PATH=" syslinux | |
1762 | "/share/syslinux/isohdpfx.bin")) | |
1763 | '()) | |
b435f631 MB |
1764 | |
1765 | ;; Build reproducibly. | |
1766 | (string-append "BUILD_ID_CMD=echo -n " (build-id #$output)) | |
1767 | (string-append "BUILD_TIMESTAMP=" #$timestamp) | |
1768 | "everything")) | |
1769 | #:phases | |
1770 | #~(modify-phases %standard-phases | |
1771 | (add-after 'unpack 'enter-source-directory | |
1772 | (lambda _ (chdir "src"))) | |
1773 | (add-after 'enter-source-directory 'set-version | |
1774 | (lambda _ | |
1775 | ;; When not building from a git checkout, iPXE encodes the | |
1776 | ;; version as "1.0.0+". Use the package version instead. | |
1777 | (substitute* "Makefile" | |
1778 | (("^VERSION[[:blank:]]+=.*") | |
1779 | (string-append "VERSION = " #$(package-version this-package) | |
1780 | "-guix\n"))))) | |
1781 | (add-after 'enter-source-directory 'set-options | |
1782 | (lambda _ | |
1783 | (substitute* "config/general.h" | |
1784 | (("^//(#define PING_CMD.*)" _ uncommented) uncommented) | |
1785 | (("^//(#define IMAGE_TRUST_CMD.*)" _ uncommented) | |
1786 | uncommented) | |
1787 | (("^#undef.*(DOWNLOAD_PROTO_HTTPS.*)" _ option) | |
1788 | (string-append "#define " option)) | |
1789 | (("^#undef.*(DOWNLOAD_PROTO_NFS.*)" _ option) | |
1790 | (string-append "#define " option))))) | |
1791 | (delete 'configure) ; no configure script | |
1792 | (replace 'install | |
1793 | (lambda _ | |
1794 | (let* ((ipxe (string-append #$output "/lib/ipxe")) | |
1795 | (exts-re | |
1796 | "\\.(efi|efirom|iso|kkpxe|kpxe|lkrn|mrom|pxe|rom|usb)$") | |
1797 | (dirs '("bin" "bin-i386-linux" "bin-x86_64-pcbios" | |
1798 | "bin-x86_64-efi" "bin-x86_64-linux" "bin-i386-efi")) | |
1799 | (files (apply append | |
1800 | (map (lambda (dir) | |
1801 | (find-files dir exts-re)) dirs)))) | |
1802 | (for-each (lambda (file) | |
1803 | (let* ((subdir (dirname file)) | |
1804 | (fn (basename file)) | |
1805 | (tgtsubdir (cond | |
1806 | ((string=? "bin" subdir) "") | |
1807 | ((string-prefix? "bin-" subdir) | |
1808 | (string-drop subdir 4))))) | |
1809 | (install-file file | |
1810 | (string-append ipxe "/" tgtsubdir)))) | |
1811 | files)))) | |
1812 | (add-after 'install 'leave-source-directory | |
1813 | (lambda _ (chdir "..")))) | |
1814 | #:tests? #f)) ; no test suite | |
aeed7218 | 1815 | (native-inputs |
d1597219 MB |
1816 | (append (if (or (target-x86-64?) (target-x86?)) |
1817 | ;; Syslinux only supports i686 and x86_64. | |
1818 | (list syslinux) | |
1819 | '()) | |
1820 | (list perl xorriso))) | |
aeed7218 VL |
1821 | (home-page "https://ipxe.org") |
1822 | (synopsis "PXE-compliant network boot firmware") | |
1823 | (description "iPXE is a network boot firmware. It provides a full PXE | |
1824 | implementation enhanced with additional features such as booting from: a web | |
1825 | server via HTTP, an iSCSI SAN, a Fibre Channel SAN via FCoE, an AoE SAN, a | |
084d3cac VC |
1826 | wireless network, a wide-area network, an Infiniband network. It |
1827 | controls the boot process with a script. You can use iPXE to replace the | |
aeed7218 VL |
1828 | existing PXE ROM on your network card, or you can chainload into iPXE to obtain |
1829 | the features of iPXE without the hassle of reflashing.") | |
1830 | (license license:gpl2+)))) | |
1831 | ||
2f2a9aca MB |
1832 | (define-public ipxe-qemu |
1833 | (package/inherit ipxe | |
1834 | (name "ipxe-qemu") | |
1835 | (native-inputs | |
a5dbe84a MB |
1836 | ;; QEMU uses a 64-bit UEFI firmware. |
1837 | (if (target-x86-64?) | |
1838 | (modify-inputs (package-native-inputs ipxe) | |
1839 | (prepend edk2-tools)) | |
6ce7904a EF |
1840 | (if (target-64bit?) |
1841 | (modify-inputs (package-native-inputs ipxe) | |
1842 | (prepend edk2-tools | |
1843 | (cross-gcc "x86_64-linux-gnu") | |
1844 | (cross-binutils "x86_64-linux-gnu"))) | |
1845 | ;; Our default 32-bit binutils is not 64-bit capable. | |
1846 | (let ((binutils-64-bit-bfd | |
1847 | (package/inherit | |
1848 | binutils | |
1849 | (name "binutils-64-bit-bfd") | |
1850 | (arguments | |
1851 | (substitute-keyword-arguments (package-arguments binutils) | |
1852 | ((#:configure-flags flags ''()) | |
1853 | `(cons "--enable-64-bit-bfd" ,flags))))))) | |
1854 | (modify-inputs (package-native-inputs ipxe) | |
1855 | (prepend edk2-tools | |
1856 | (make-ld-wrapper "ld-wrapper-64-bit-bfd" | |
1857 | #:binutils binutils) | |
1858 | binutils-64-bit-bfd | |
1859 | (cross-gcc "x86_64-linux-gnu") | |
1860 | (cross-binutils "x86_64-linux-gnu"))))))) | |
2f2a9aca MB |
1861 | (arguments |
1862 | (let ((roms | |
1863 | ;; Alist of ROM -> (VID . DID) entries. This list and below | |
1864 | ;; build steps are taken from QEMUs roms/Makefile. | |
1865 | '(("e1000" . ("8086" . "100e")) | |
1866 | ("e1000e" . ("8086" . "10d3")) | |
1867 | ("eepro100" . ("8086" . "1209")) | |
1868 | ("ne2k_pci" . ("1050" . "0940")) | |
1869 | ("pcnet" . ("1022" . "2000")) | |
1870 | ("rtl8139" . ("10ec" . "8139")) | |
1871 | ("virtio" . ("1af4" . "1000")) | |
1872 | ("vmxnet3" . ("15ad" . "07b0"))))) | |
1873 | (substitute-keyword-arguments (package-arguments ipxe) | |
1874 | ((#:modules modules) | |
1875 | `((ice-9 match) ,@modules)) | |
1876 | ((#:make-flags flags) | |
1877 | #~(append (delete "everything" #$flags) | |
a5dbe84a MB |
1878 | '("CONFIG=qemu" |
1879 | #$@(if (target-x86-64?) | |
1880 | '() | |
1881 | '("CROSS_COMPILE=x86_64-linux-gnu-"))) | |
2f2a9aca MB |
1882 | (map (match-lambda |
1883 | ((_ . (vid . did)) | |
1884 | (string-append "bin/" vid did ".rom"))) | |
1885 | '#$roms) | |
1886 | (map (match-lambda | |
1887 | ((_ . (vid . did)) | |
a5dbe84a | 1888 | (string-append "bin-x86_64-efi/" |
2f2a9aca MB |
1889 | vid did ".efidrv"))) |
1890 | '#$roms))) | |
1891 | ((#:phases phases) | |
1892 | #~(modify-phases #$phases | |
1893 | (replace 'install | |
1894 | (lambda _ | |
209aed95 | 1895 | (let ((firmware (string-append #$output "/share/qemu"))) |
2f2a9aca MB |
1896 | (mkdir-p firmware) |
1897 | (for-each | |
1898 | (match-lambda | |
1899 | ((name . (vid . did)) | |
1900 | (let ((rom (string-append "bin/" vid did ".rom"))) | |
1901 | (copy-file rom | |
1902 | (string-append firmware | |
1903 | "/pxe-" name ".rom")) | |
1904 | (invoke "EfiRom" | |
1905 | "-b" rom | |
1906 | "-l" "0x02" | |
1907 | "-f" (string-append "0x" vid) | |
1908 | "-i" (string-append "0x" did) | |
a5dbe84a | 1909 | "-ec" (string-append "bin-x86_64-efi/" |
2f2a9aca MB |
1910 | vid did ".efidrv") |
1911 | "-o" (string-append firmware | |
1912 | "/efi-" name ".rom"))))) | |
1913 | '#$roms))))))))))) |