projects/guix·blob java-team · refs

2293 lines · 99.3 KiB

1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2013-2019, 2021, 2023-2025 Ludovic Courtès <[email protected]>
3;;; Copyright © 2015, 2018 Mark H Weaver <[email protected]>
4;;; Copyright © 2015 Leo Famulari <[email protected]>
5;;; Copyright © 2016, 2020, 2024 Janneke Nieuwenhuizen <[email protected]>
6;;; Copyright © 2016-2018, 2021-2023 Marius Bakke <[email protected]>
7;;; Copyright © 2016, 2017 Danny Milosavljevic <[email protected]>
8;;; Copyright © 2016, 2017 David Craven <[email protected]>
9;;; Copyright © 2017, 2018, 2020-2025 Efraim Flashner <[email protected]>
10;;; Copyright © 2018–2022 Tobias Geerinckx-Rice <[email protected]>
11;;; Copyright © 2019 nee <[email protected]>
12;;; Copyright © 2019 Mathieu Othacehe <[email protected]>
13;;; Copyright © 2020 Björn Höfling <[email protected]>
14;;; Copyright © 2018, 2019, 2020 Vagrant Cascadian <[email protected]>
15;;; Copyright © 2020, 2021 Pierre Langlois <[email protected]>
16;;; Copyright © 2021 Vincent Legoll <[email protected]>
17;;; Copyright © 2021 Brice Waegeneire <[email protected]>
18;;; Copyright © 2022, 2023 Denis 'GNUtoo' Carikli <[email protected]>
19;;; Copyright © 2021 Stefan <[email protected]>
20;;; Copyright © 2022-2024, 2026 Maxim Cournoyer <[email protected]>
21;;; Copyright © 2023-2024 Herman Rimm <[email protected]>
22;;; Copyright © 2023 Simon Tournier <[email protected]>
23;;; Copyright © 2024 Zheng Junjie <[email protected]>
24;;; Copyright © 2025 Esther Flashner <[email protected]>
25;;; Copyright © 2025 André Batista <[email protected]>
26;;; Copyright © 2025 dan <[email protected]>
27;;; Copyright © 2025 Jiyu Software <[email protected]>
28;;;
29;;; This file is part of GNU Guix.
30;;;
31;;; GNU Guix is free software; you can redistribute it and/or modify it
32;;; under the terms of the GNU General Public License as published by
33;;; the Free Software Foundation; either version 3 of the License, or (at
34;;; your option) any later version.
35;;;
36;;; GNU Guix is distributed in the hope that it will be useful, but
37;;; WITHOUT ANY WARRANTY; without even the implied warranty of
38;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39;;; GNU General Public License for more details.
40;;;
41;;; You should have received a copy of the GNU General Public License
42;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
43
44(define-module (gnu packages bootloaders)
45 #:use-module (gnu packages)
46 #:use-module (gnu packages assembly)
47 #:use-module (gnu packages autotools)
48 #:use-module (gnu packages base)
49 #:use-module (gnu packages disk)
50 #:use-module (gnu packages bison)
51 #:use-module (gnu packages build-tools)
52 #:use-module (gnu packages cdrom)
53 #:use-module (gnu packages check)
54 #:use-module (gnu packages compression)
55 #:use-module (gnu packages cross-base)
56 #:use-module (gnu packages disk)
57 #:use-module (gnu packages firmware)
58 #:use-module (gnu packages compiler-tools)
59 #:use-module (gnu packages fontutils)
60 #:use-module (gnu packages gcc)
61 #:use-module (gnu packages gettext)
62 #:use-module (gnu packages guile)
63 #:use-module (gnu packages efi)
64 #:use-module (gnu packages linux)
65 #:use-module (gnu packages llvm)
66 #:use-module (gnu packages man)
67 #:use-module (gnu packages mtools)
68 #:use-module (gnu packages ncurses)
69 #:use-module (gnu packages package-management)
70 #:use-module (gnu packages perl)
71 #:use-module (gnu packages pkg-config)
72 #:use-module (gnu packages python)
73 #:use-module (gnu packages python-build)
74 #:use-module (gnu packages python-crypto)
75 #:use-module (gnu packages texinfo)
76 #:use-module (gnu packages tls)
77 #:use-module (gnu packages sdl)
78 #:use-module (gnu packages sphinx)
79 #:use-module (gnu packages serialization)
80 #:use-module (gnu packages swig)
81 #:use-module (gnu packages valgrind)
82 #:use-module (gnu packages version-control)
83 #:use-module (gnu packages virtualization)
84 #:use-module (gnu packages xorg)
85 #:use-module (gnu packages python-build)
86 #:use-module (gnu packages python-web)
87 #:use-module (gnu packages python-xyz)
88 #:use-module (guix build-system gnu)
89 #:use-module (guix build-system meson)
90 #:use-module (guix build-system pyproject)
91 #:use-module (guix build-system trivial)
92 #:use-module (guix download)
93 #:use-module (guix gexp)
94 #:use-module (guix git-download)
95 #:use-module ((guix licenses) #:prefix license:)
96 #:use-module (guix packages)
97 #:use-module (guix utils)
98 #:use-module (srfi srfi-1)
99 #:use-module (srfi srfi-26)
100 #:use-module (ice-9 optargs)
101 #:use-module (ice-9 match)
102 #:use-module (ice-9 regex))
103
104(define unifont
105 ;; GNU Unifont, <http://gnu.org/s/unifont>.
106 ;; GRUB needs it for its graphical terminal, gfxterm.
107 (origin
108 (method url-fetch)
109 (uri
110 "http://unifoundry.com/pub/unifont-7.0.06/font-builds/unifont-7.0.06.bdf.gz")
111 (sha256
112 (base32
113 "0p2vhnc18cnbmb39vq4m7hzv4mhnm2l0a2s7gx3ar277fwng3hys"))))
114
115(define*-public (make-grub platform)
116 (package
117 (name (string-append "grub-" platform))
118 (version "2.14")
119 (source (origin
120 (method url-fetch)
121 (uri (string-append "mirror://gnu/grub/grub-" version ".tar.xz"))
122 (sha256
123 (base32
124 "0hvd8i3ib6nwymfmvd6dia6axrn4xmrlsrg2r3c3i22vadrkr3dw"))
125 (patches (search-patches
126 "grub-efi-fat-serial-number.patch"
127 "grub-setup-root.patch"))
128 (modules '((guix build utils)))
129 (snippet
130 #~(begin
131 ;; Add file missing from the release tarball.
132 (call-with-output-file "grub-core/extra_deps.lst"
133 (lambda (port)
134 (display "depends bli part_gpt\n" port)))
135
136 ;; Use exit code 77, not 99, to tell Automake that a test
137 ;; is skipped.
138 (substitute* (find-files "tests" "\\.in$")
139 (("exit 99") "exit 77"))))))
140 (build-system gnu-build-system)
141 (arguments
142 (list #:configure-flags
143 ;; Counterintuitively, this *disables* a spurious Python dependency by
144 ;; calling the ‘true’ binary instead. Python is only needed during
145 ;; bootstrapping (for genptl.py), not when building from a release.
146 #~(append
147 (list "PYTHON=true"
148 (string-append "--with-platform=" #$platform))
149 ;; This needs to be compiled with clang for powerpc64le.
150 (if #$(and=> (%current-target-system)
151 target-ppc64le?)
152 (list "TARGET_CC=powerpc64le-linux-gnu-clang"
153 "CFLAGS=-Wno-error")
154 '())
155 (if #$(and (target-ppc64le? (%current-system))
156 (not (%current-target-system)))
157 (list "CC=clang" "CFLAGS=-Wno-error")
158 '()))
159
160 ;; The 'configure' script detects --image-base support and uses it,
161 ;; but that shifts the i386-pc kernel.img start address from 0x9000
162 ;; to 0x9074, breaking grub-install. Override with -Ttext.
163 ;; See <https://lists.gnu.org/archive/html/grub-devel/2026-01/msg00041.html>.
164 #:make-flags
165 #~(list "TARGET_IMG_BASE_LDOPT=-Wl,-Ttext")
166
167 ;; GRUB fails to load modules stripped with --strip-unneeded.
168 #:strip-flags
169 #~(list "--strip-debug" "--enable-deterministic-archives")
170
171 #:phases
172 #~(modify-phases %standard-phases
173 (add-after 'unpack 'patch-stuff
174 (lambda* (#:key native-inputs inputs #:allow-other-keys)
175 (substitute* "grub-core/Makefile.in"
176 (("/bin/sh") (which "sh")))
177
178 ;; Give the absolute file name of 'mdadm', used to determine the
179 ;; root file system when it's a RAID device. Failing to do that,
180 ;; 'grub-probe' silently fails if 'mdadm' is not in $PATH.
181 (let ((mdadm (false-if-exception
182 (search-input-file inputs "/sbin/mdadm"))))
183 (when mdadm
184 (substitute* "grub-core/osdep/linux/getroot.c"
185 (("argv\\[0\\] = \"mdadm\"")
186 (string-append "argv[0] = \"" mdadm "\"")))))
187
188 ;; Make the font visible.
189 (copy-file #+unifont "unifont.bdf.gz")
190 (system* "gunzip" "unifont.bdf.gz")
191
192 ;; Give the absolute file name of 'ckbcomp'.
193 (substitute* "util/grub-kbdcomp.in"
194 (("^ckbcomp ")
195 (string-append
196 (search-input-file inputs "/bin/ckbcomp")
197 " ")))))
198 (add-after 'unpack 'set-freetype-variables
199 ;; These variables need to be set to the native versions of the
200 ;; dependencies because they are used to build programs which are
201 ;; executed during build time.
202 (lambda* (#:key native-inputs #:allow-other-keys)
203 (when (assoc-ref native-inputs "freetype")
204 (let ((freetype (assoc-ref native-inputs "freetype")))
205 (setenv "BUILD_FREETYPE_LIBS"
206 (string-append "-L" freetype
207 "/lib -lfreetype"))
208 (setenv "BUILD_FREETYPE_CFLAGS"
209 (string-append "-I" freetype
210 "/include/freetype2"))))))
211 (add-before 'check 'disable-flaky-test
212 (lambda _
213 ;; This test is unreliable. For more information, see:
214 ;; <https://bugs.gnu.org/26936>.
215 (substitute* "Makefile.in"
216 (("grub_cmd_date grub_cmd_set_date grub_cmd_sleep")
217 "grub_cmd_date grub_cmd_sleep"))))
218 (add-before 'check 'skip-tests
219 (lambda _
220 (substitute* "Makefile.in"
221 ;; The grub_cmd_date sometimes fail (see:
222 ;; <https://savannah.gnu.org/bugs/index.php?67471>).
223 ((" grub_cmd_date ") " ")
224 ((" pseries_test ") " "))))
225 (add-before 'check 'disable-pixel-perfect-test
226 (lambda _
227 ;; This test compares many screenshots rendered with an older
228 ;; Unifont (9.0.06) than that packaged in Guix.
229 (substitute* "Makefile.in"
230 (("test_unset grub_func_test")
231 "test_unset")))))))
232 (inputs
233 (append (list gettext-minimal freetype ncurses libtasn1
234
235 ;; Console-setup's ckbcomp is invoked by grub-kbdcomp. It
236 ;; is required for generating alternative keyboard layouts.
237 console-setup)
238
239 ;; 64-bit PowerPC hardware boots in big-endian mode and then for
240 ;; powerpc64le it switches to little-endian mode. Therefore we
241 ;; need a compiler which can generate both big-endian and
242 ;; little-endian binaries for the bootloader and the utilities
243 ;; and building with clang is the easiest option.
244 (if (target-ppc64le?)
245 (list clang-13)
246 '())
247
248 ;; Depend on LVM2 for libdevmapper, used by 'grub-probe' and
249 ;; 'grub-install' to recognize mapped devices (LUKS, etc.)
250 (if (member (or (%current-target-system)
251 (%current-system))
252 (package-supported-systems lvm2))
253 (list lvm2)
254 '())
255
256 ;; Depend on mdadm, which is invoked by 'grub-probe' and
257 ;; 'grub-install' to determine whether the root file system is
258 ;; RAID.
259 (if (member (or (%current-target-system)
260 (%current-system))
261 (package-supported-systems mdadm))
262 (list mdadm)
263 '())
264
265 ;; Needed for ‘grub-mount’, the only reliable way to tell whether
266 ;; a given file system will be readable by GRUB without
267 ;; rebooting.
268 (if (member (or (%current-target-system)
269 (%current-system))
270 (package-supported-systems fuse))
271 (list fuse)
272 '())))
273 (native-inputs
274 (append (list pkg-config
275 bison
276 flex
277 texinfo
278 help2man
279 freetype ;native version needed for build-grub-mkfont
280
281 ;; Dependencies of the test suite.
282 parted
283 xorriso)
284
285 ;; For the test suite, the "real" QEMU is needed because several
286 ;; targets are used.
287 (if (member (%current-system) (package-supported-systems qemu-minimal))
288 (list qemu-minimal)
289 '())))
290 (home-page "https://www.gnu.org/software/grub/")
291 (synopsis "GRand Unified Boot loader")
292 (description
293 "GRUB is a multiboot bootloader. It is used for initially loading the
294kernel of an operating system and then transferring control to it. The kernel
295then goes on to load the rest of the operating system. As a multiboot
296bootloader, GRUB handles the presence of multiple operating systems installed
297on the same computer; upon booting the computer, the user is presented with a
298menu to select one of the installed operating systems.")
299 (license license:gpl3+)
300 (properties '((cpe-name . "grub2")))))
301
302(define-public grub-pc
303 (package
304 (inherit (make-grub "pc"))
305 (supported-systems '("i686-linux" "x86_64-linux"
306 "i586-gnu" "x86_64-gnu"))))
307
308(define-public grub grub-pc)
309
310(define-public grub-minimal
311 (package
312 (inherit grub-pc)
313 (name "grub-minimal")
314 (inputs
315 (modify-inputs inputs
316 (delete "lvm2" "mdadm" "fuse" "console-setup")))
317 (native-inputs
318 (modify-inputs native-inputs
319 (delete "help2man" "texinfo" "parted" "qemu" "qemu-minimal" "xorriso")))
320 (arguments
321 (substitute-keyword-arguments arguments
322 ((#:tests? _ #t) #f)
323 ((#:phases phases #~%standard-phases)
324 #~(modify-phases #$phases
325 (replace 'patch-stuff
326 (lambda* (#:key native-inputs inputs #:allow-other-keys)
327 (substitute* "grub-core/Makefile.in"
328 (("/bin/sh")
329 (which "sh")))
330
331 ;; Make the font visible.
332 (copy-file #+unifont "unifont.bdf.gz")
333 (system* "gunzip" "unifont.bdf.gz")))))))))
334
335(define-public grub-coreboot
336 (let ((base (make-grub "coreboot")))
337 (package
338 (inherit base)
339 (synopsis "GRand Unified Boot loader (Coreboot payload version)")
340 (arguments
341 (substitute-keyword-arguments arguments
342 ((#:phases phases #~%standard-phases)
343 #~(modify-phases #$phases
344 (add-before 'check 'disable-broken-tests
345 (lambda _
346 (setenv "DISABLE_HARD_ERRORS" "1")
347 (setenv "XFAIL_TESTS"
348 (string-join
349 ;; TODO: All the tests below use grub shell
350 ;; (tests/util/grub-shell.in), and here grub-shell uses
351 ;; QEMU and a Coreboot image to run the tests. Since we
352 ;; don't have a Coreboot package in Guix yet these tests
353 ;; are disabled. See the Guix bug #64667 for more details
354 ;; (https://debbugs.gnu.org/cgi/bugreport.cgi?bug=64667).
355 (list "pata_test"
356 "ahci_test"
357 "uhci_test"
358 "ehci_test"
359 "example_grub_script_test"
360 "ohci_test"
361 "grub_script_eval"
362 "grub_script_echo1"
363 "grub_script_test"
364 "grub_script_leading_whitespace"
365 "grub_script_echo_keywords"
366 "grub_script_vars1"
367 "grub_script_for1"
368 "grub_script_while1"
369 "grub_script_if"
370 "grub_script_comments"
371 "grub_script_functions"
372 "grub_script_continue"
373 "grub_script_break"
374 "grub_script_shift"
375 "grub_script_blockarg"
376 "grub_script_return"
377 "grub_script_setparams"
378 "grub_cmd_date"
379 "grub_cmd_set_date"
380 "grub_cmd_sleep"
381 "grub_cmd_regexp"
382 "grub_cmd_test"
383 "grub_script_not"
384 "grub_cmd_echo"
385 "grub_script_expansion"
386 "grub_script_gettext"
387 "grub_script_escape_comma"
388 "help_test"
389 "grub_script_strcmp"
390 "test_sha512sum"
391 "grub_cmd_tr"
392 "test_unset"
393 "file_filter_test"
394 "asn1_test")
395 " "))))))))
396 (supported-systems '("i686-linux" "x86_64-linux")))))
397
398(define-public grub-efi
399 (let ((base (make-grub "efi")))
400 (package
401 (inherit base)
402 (synopsis "GRand Unified Boot loader (UEFI version)")
403 (inputs
404 (modify-inputs inputs
405 (prepend efibootmgr mtools)))
406 (native-inputs
407 (cond ((or (target-x86-64?)
408 (target-x86-32?)
409 (target-aarch64?)
410 (target-arm32?))
411 ;; We add the firmware needed to run the tests.
412 (modify-inputs native-inputs
413 (prepend
414 (cond ((target-x86-64?) ovmf-x86-64)
415 ((target-x86-32?) ovmf-i686)
416 ((target-aarch64?) ovmf-aarch64)
417 ((target-arm32?) ovmf-arm)
418 (else pkg-config)))))
419 (else
420 ;; The tests are skipped in this package so we remove some
421 ;; test dependencies.
422 (modify-inputs native-inputs
423 (delete "parted" "qemu-minimal" "xorriso")))))
424 (arguments
425 (substitute-keyword-arguments arguments
426 ((#:tests? _ #f) (and (not (%current-target-system))
427 (this-package-native-input "qemu-minimal")))
428 ((#:configure-flags flags #~'())
429 #~(cons* #$@(if (string-prefix? "x86_64"
430 (or (%current-target-system)
431 (%current-system)))
432 #~("--enable-stack-protector") ;EFI-only for now
433 #~())
434 #$flags))
435 ((#:phases phases)
436 #~(modify-phases #$phases
437 #$@(if (this-package-native-input "qemu-minimal")
438 #~((add-after 'patch-stuff 'patch-ovmf-path
439 (lambda* (#:key native-inputs inputs #:allow-other-keys)
440 (let ((arch #$(cond ((target-x86-64?) "x64")
441 ((target-x86-32?) "ia32")
442 ((target-aarch64?) "aarch64")
443 ((target-arm32?) "arm")
444 (else ""))))
445 (substitute* "tests/util/grub-shell.in"
446 (("\\$\\{srcdir\\}/OVMF(32)?\\.fd")
447 (search-input-file
448 (or native-inputs inputs)
449 (string-append
450 "/share/firmware/ovmf_" arch ".bin")))
451 (("/usr/share/qemu/OVMF(32)?\\.fd")
452 (search-input-file
453 (or native-inputs inputs)
454 (string-append
455 "/share/firmware/ovmf_" arch ".bin")))
456 (("\\$\\{srcdir\\}/AAVMF(32)?\\.fd")
457 (search-input-file
458 (or native-inputs inputs)
459 (string-append
460 "/share/firmware/ovmf_" arch ".bin")))
461 (("/usr/share/qemu-efi-aarch64/QEMU_EFI\\.fd")
462 (search-input-file
463 (or native-inputs inputs)
464 (string-append
465 "/share/firmware/ovmf_" arch ".bin")))
466 (("/usr/share/AAVMF/AAVMF(32)?\\.fd")
467 (search-input-file
468 (or native-inputs inputs)
469 (string-append
470 "/share/firmware/ovmf_" arch ".bin"))))))))
471 #~())
472 (add-after 'patch-stuff 'use-absolute-efibootmgr-path
473 (lambda* (#:key inputs #:allow-other-keys)
474 (substitute* "grub-core/osdep/unix/platform.c"
475 (("efibootmgr")
476 (search-input-file inputs "/sbin/efibootmgr")))))
477 (add-after 'patch-stuff 'use-absolute-mtools-path
478 (lambda* (#:key inputs #:allow-other-keys)
479 (substitute* "util/grub-mkrescue.c"
480 (("\"mformat\"")
481 (string-append "\""
482 (search-input-file inputs "/bin/mformat")
483 "\"")))
484 (substitute* "util/grub-mkrescue.c"
485 (("\"mcopy\"")
486 (string-append "\""
487 (search-input-file inputs "/bin/mcopy")
488 "\"")))))))))
489 ;; Check configure.ac for the list of supported EFI platforms.
490 (supported-systems '("i686-linux" "x86_64-linux"
491 "i586-gnu" "x86_64-gnu"
492 "armhf-linux" "aarch64-linux" "riscv64-linux")))))
493
494(define-public grub-efi32
495 (package
496 (inherit grub-efi)
497 (name "grub-efi32")
498 (synopsis "GRand Unified Boot loader (UEFI 32bit version)")
499 (arguments
500 (substitute-keyword-arguments arguments
501 ((#:configure-flags flags #~'())
502 #~(cons* #$@(cond ((target-x86?)
503 #~("--target=i386"))
504 ((target-aarch64?)
505 #~("--target=arm"
506 (string-append "TARGET_CC="
507 #$(cc-for-target
508 "arm-linux-gnueabihf"))))
509 ((target-arm?)
510 #~("--target=arm"))
511 (else #~()))
512 #$flags))
513 ((#:phases phases)
514 #~(modify-phases #$phases
515 #$@(if (or (target-x86?)
516 (target-arm?))
517 #~((replace 'patch-ovmf-path
518 (lambda* (#:key native-inputs inputs #:allow-other-keys)
519 (let ((arch #$(cond ((target-x86?) "ia32")
520 ((target-arm?) "arm")
521 (else ""))))
522 (substitute* "tests/util/grub-shell.in"
523 (("\\$\\{srcdir\\}/OVMF(32)?\\.fd")
524 (search-input-file
525 (or native-inputs inputs)
526 (string-append
527 "/share/firmware/ovmf_" arch ".bin")))
528 (("/usr/share/qemu/OVMF(32)?\\.fd")
529 (search-input-file
530 (or native-inputs inputs)
531 (string-append
532 "/share/firmware/ovmf_" arch ".bin")))
533 (("\\$\\{srcdir\\}/AAVMF(32)?\\.fd")
534 (search-input-file
535 (or native-inputs inputs)
536 (string-append
537 "/share/firmware/ovmf_" arch ".bin")))
538 (("/usr/share/qemu-efi-aarch64/QEMU_EFI\\.fd")
539 (search-input-file
540 (or native-inputs inputs)
541 (string-append
542 "/share/firmware/ovmf_" arch ".bin")))
543 (("/usr/share/AAVMF/AAVMF(32)?\\.fd")
544 (search-input-file
545 (or native-inputs inputs)
546 (string-append
547 "/share/firmware/ovmf_" arch ".bin")))
548 (("/usr/share/ovmf-arm/QEMU_EFI\\.fd")
549 (search-input-file
550 (or native-inputs inputs)
551 (string-append
552 "/share/firmware/ovmf_" arch ".bin"))))))))
553 #~())))))
554 (native-inputs
555 (cond
556 ((target-x86-64?)
557 (modify-inputs native-inputs
558 (replace "ovmf-x86-64" ovmf-i686)))
559 ((target-aarch64?)
560 (modify-inputs native-inputs
561 (prepend
562 (cross-gcc "arm-linux-gnueabihf")
563 (cross-binutils "arm-linux-gnueabihf"))
564 (replace "ovmf-aarch64" ovmf-arm)))
565 (else (package-native-inputs grub-efi))))))
566
567(define-public grub-emu
568 (package
569 (inherit (make-grub "emu"))
570 (synopsis "GRand Unified Boot loader (Emu version)")))
571
572(define-public grub-ieee1275
573 (package
574 (inherit (make-grub "ieee1275"))
575 (synopsis "GRand Unified Boot loader (ieee1275 version)")
576 (supported-systems '("powerpc-linux" "powerpc64le-linux"))))
577
578(define-public grub-qemu
579 (package
580 (inherit (make-grub "qemu"))
581 (synopsis "GRand Unified Boot loader (qemu version)")
582 (supported-systems '("i686-linux" "x86_64-linux"
583 "i586-gnu" "x86_64-gnu"))))
584
585(define-public grub-uboot
586 (let ((base (make-grub "uboot")))
587 (package
588 (inherit base)
589 (arguments
590 (substitute-keyword-arguments arguments
591 ;; Running the tests isn't supported for this grub platform.
592 ((#:tests? _ #t) #f)))
593 (synopsis "GRand Unified Boot loader (u-boot version)")
594 (supported-systems '("armhf-linux")))))
595
596;; Because grub searches hardcoded paths it's easiest to just build grub
597;; again to make it find both grub-pc and grub-efi. There is a command
598;; line argument which allows you to specify ONE platform - but
599;; grub-mkrescue will use multiple platforms if they are available
600;; in the installation directory (without command line argument).
601(define-public grub-hybrid
602 (package
603 (inherit grub-efi)
604 (name "grub-hybrid")
605 (synopsis "GRand Unified Boot loader (hybrid version)")
606 (inputs
607 (modify-inputs inputs
608 (prepend grub)))
609 (arguments
610 (substitute-keyword-arguments arguments
611 ((#:modules modules `((guix build utils)
612 (guix build gnu-build-system)))
613 `((ice-9 ftw) ,@modules))
614 ((#:phases phases)
615 #~(modify-phases #$phases
616 (add-after 'install 'install-non-efi
617 (lambda* (#:key inputs outputs #:allow-other-keys)
618 (let ((input-dir (search-input-directory inputs "/lib/grub"))
619 (output-dir (string-append (assoc-ref outputs "out")
620 "/lib/grub")))
621 (for-each (lambda (basename)
622 (unless (or (string-prefix? "." basename)
623 (file-exists? (string-append
624 output-dir "/"
625 basename)))
626 (symlink (string-append input-dir "/"
627 basename)
628 (string-append output-dir "/"
629 basename))))
630 (scandir input-dir)))))))))))
631
632(define-public (make-grub-efi-netboot name subdir)
633 "Make a grub-efi-netboot package named NAME, which will be able to boot over
634network via TFTP by accessing its files in the SUBDIR of a TFTP root directory.
635This package is also able to boot from local storage devices.
636
637A bootloader-installer basically needs to copy the package content into the
638bootloader-target directory, which will usually be the TFTP root, as
639'grub-mknetdir' will be invoked already during the package creation.
640
641Alternatively the bootloader-target directory can be a mounted EFI System
642Partition (ESP), or a similar partition with a FAT file system, for booting
643from local storage devices.
644
645The name of the GRUB EFI binary will conform to the UEFI specification for
646removable media. Depending on the system it will be e.g. bootx64.efi or
647bootaa64.efi below SUBDIR.
648
649The SUBDIR argument needs to be set to \"efi/boot\" to create a package which
650conforms to the UEFI specification for removable media.
651
652The SUBDIR argument defaults to \"efi/Guix\", as it is also the case for
653'grub-efi-bootloader'."
654 (package
655 (name name)
656 (version (package-version grub-efi))
657 ;; Source is not needed, but it cannot be omitted.
658 (source #f)
659 (build-system trivial-build-system)
660 (arguments
661 (let* ((system (string-split (nix-system->gnu-triplet
662 (or (%current-target-system)
663 (%current-system)))
664 #\-))
665 (arch (first system))
666 (boot-efi
667 (match system
668 ;; These are the supportend systems and the names defined by
669 ;; the UEFI standard for removable media.
670 (("i686" _ ...) "/bootia32.efi")
671 (("x86_64" _ ...) "/bootx64.efi")
672 (("arm" _ ...) "/bootarm.efi")
673 (("aarch64" _ ...) "/bootaa64.efi")
674 (("riscv" _ ...) "/bootriscv32.efi")
675 (("riscv64" _ ...) "/bootriscv64.efi")
676 ;; Other systems are not supported, although defined.
677 ;; (("riscv128" _ ...) "/bootriscv128.efi")
678 ;; (("ia64" _ ...) "/bootia64.efi")
679 ((_ ...) #f)))
680 (core-efi (string-append
681 ;; This is the arch dependent file name of GRUB, e.g.
682 ;; i368-efi/core.efi or arm64-efi/core.efi.
683 (match arch
684 ("i686" "i386")
685 ("aarch64" "arm64")
686 ("riscv" "riscv32")
687 (_ arch))
688 "-efi/core.efi")))
689 (list
690 #:modules '((guix build utils))
691 #:builder
692 #~(begin
693 (use-modules (guix build utils))
694 (let* ((bootloader #$(this-package-input "grub-efi"))
695 (net-dir #$output)
696 (sub-dir (string-append net-dir "/" #$subdir "/"))
697 (boot-efi (string-append sub-dir #$boot-efi))
698 (core-efi (string-append sub-dir #$core-efi)))
699 ;; Install GRUB, which refers to the grub.cfg, with support for
700 ;; encrypted partitions,
701 (setenv "GRUB_ENABLE_CRYPTODISK" "y")
702 (invoke/quiet (string-append bootloader "/bin/grub-mknetdir")
703 (string-append "--net-directory=" net-dir)
704 (string-append "--subdir=" #$subdir)
705 ;; These modules must be pre-loaded to allow booting
706 ;; from an ESP or a similar partition with a FAT
707 ;; file system.
708 (string-append "--modules=part_msdos part_gpt fat"))
709 ;; Move GRUB's core.efi to the removable media name.
710 (false-if-exception (delete-file boot-efi))
711 (rename-file core-efi boot-efi))))))
712 (inputs (list grub-efi))
713 (synopsis (package-synopsis grub-efi))
714 (description (package-description grub-efi))
715 (home-page (package-home-page grub-efi))
716 (license (package-license grub-efi))))
717
718(define-public syslinux
719 (let ((commit "b4cc12b9db2c6f5df7aa90bb2b8b4d62b22e01ee")
720 (revision "21")) ; As in git describe
721 (package
722 (name "syslinux")
723 (version (git-version "6.04-pre1" revision commit))
724 (source
725 (origin
726 (method git-fetch)
727 (uri (git-reference
728 (url "https://git.zytor.com/syslinux/syslinux")
729 (commit commit)))
730 (file-name (git-file-name name version))
731 (sha256
732 (base32
733 "1vdqbipmx6bqhb7lsq6fwfv6hbdwyx29w43pfcgcrqc45l4hl22c"))
734 (patches
735 (search-patches "syslinux-gcc10.patch"
736 "syslinux-strip-gnu-property.patch"))))
737 (build-system gnu-build-system)
738 (native-inputs
739 (list coreutils
740 nasm
741 perl
742 python))
743 (inputs
744 (list `(,util-linux "lib")
745 mtools))
746 (arguments
747 (list
748 #:make-flags
749 #~(list (string-append "BINDIR=" #$output "/bin")
750 (string-append "SBINDIR=" #$output "/sbin")
751 (string-append "LIBDIR=" #$output "/lib")
752 (string-append "INCDIR=" #$output "/include")
753 (string-append "DATADIR=" #$output "/share")
754 (string-append "MANDIR=" #$output "/share/man")
755 "PERL=perl"
756 "PYTHON=python3"
757 "bios")
758 #:strip-flags
759 #~(list "--enable-deterministic-archives"
760 "--strip-debug")
761 #:phases
762 #~(modify-phases %standard-phases
763 (add-after 'unpack 'patch-files
764 (lambda* (#:key inputs native-inputs #:allow-other-keys)
765 (substitute* "tests/unittest/include/unittest/unittest.h"
766 ;; Don't look up headers under /usr.
767 (("^(#include <)/usr/include/" all keep) keep))
768 (substitute* "Makefile"
769 (("/bin/pwd") "pwd"))
770 (substitute* (find-files "." "\\.c$")
771 (("mcopy")
772 (search-input-file inputs "bin/mcopy"))
773 (("mattrib")
774 (search-input-file inputs "bin/mattrib")))))
775 (delete 'configure)
776 (replace 'check
777 (lambda* (#:key tests? parallel-tests? #:allow-other-keys)
778 (when tests?
779 ;; INFO: The Makefile has a test target, but it requires
780 ;; sudo.
781 (apply invoke "make" "unittest"
782 (append (if parallel-tests?
783 (list "-j" (number->string (parallel-job-count)))
784 (list))
785 (list (string-append "CC=" #$(cc-for-target)))))))))))
786 (home-page "https://wiki.syslinux.org/wiki/index.php?title=The_Syslinux_Project")
787 (synopsis "Lightweight Linux bootloader")
788 (description "Syslinux is a lightweight Linux bootloader.")
789 (license (list license:gpl2+
790 license:bsd-3 ; gnu-efi/*
791 license:bsd-4 ; gnu-efi/inc/* gnu-efi/lib/*
792 license:expat
793 license:isc
794 license:zlib))
795 ;; The Makefile specifically targets i386 and x86_64 using nasm.
796 (supported-systems (list "i686-linux" "x86_64-linux")))))
797
798(define-public dtc
799 (package
800 (name "dtc")
801 (version "1.8.1")
802 (source (origin
803 (method url-fetch)
804 (uri (string-append
805 "mirror://kernel.org/software/utils/dtc/"
806 "dtc-" version ".tar.gz"))
807 (sha256
808 (base32
809 "1c5wy7mcnhwwj1x5s5ajvc6i1xfgl9nycibz3v4mgsccfk75qkj5"))))
810 (build-system meson-build-system)
811 (arguments
812 (list
813 #:modules '((guix build meson-build-system)
814 (guix build utils)
815 (srfi srfi-26))
816 #:phases
817 #~(modify-phases %standard-phases
818 (add-after 'unpack 'preparations
819 (lambda _
820 ;; Needed by setup.py.
821 (setenv "DESTDIR" "/")
822
823 ;; Native gcc needed by run_test.sh.
824 (setenv "CC" "gcc")
825
826 ;; /bin/fdt{get,overlay,put} need help finding libfdt.so.1.
827 (setenv "LDFLAGS"
828 (string-append "-Wl,-rpath=" #$output "/lib"))))
829 (add-after 'unpack 'install-doc
830 (lambda _
831 (with-directory-excursion "Documentation"
832 (for-each (cut install-file <> (string-append
833 #$output "/share/doc/dtc/"))
834 '("dts-format.txt"
835 "dt-object-internal.txt"
836 "manual.txt")))))
837 (add-after 'unpack 'patch-pkg-config
838 (lambda _
839 (substitute* '("tests/run_tests.sh")
840 (("pkg-config")
841 #$(pkg-config-for-target))))))))
842 (native-inputs
843 (append
844 (list bison
845 flex
846 libyaml
847 ninja
848 pkg-config
849 python
850 python-setuptools-scm
851 swig-4.0
852 which)
853 (if (member (%current-system) (package-supported-systems valgrind/pinned))
854 (list valgrind/pinned)
855 '())))
856 (inputs
857 (list python))
858 (home-page "https://www.devicetree.org")
859 (synopsis "Compiles device tree source files")
860 (description "@command{dtc} compiles
861@uref{http://elinux.org/Device_Tree_Usage, device tree source files} to device
862tree binary files. These are board description files used by Linux and BSD.")
863 (license license:gpl2+)))
864
865(define-public python-libfdt
866 (package
867 (name "python-libfdt")
868 (version (package-version dtc))
869 (source (package-source dtc))
870 (build-system pyproject-build-system)
871 (arguments
872 ;; Requires entire dtc tools to be built.
873 (list
874 #:tests? #f))
875 (native-inputs
876 (list dtc
877 python-meson
878 python-setuptools
879 python-setuptools-scm
880 swig))
881 (home-page "https://www.devicetree.org/")
882 (synopsis "python bindings for libfdt")
883 (description
884 "This package provides python bindings for @{libfdt}, a utility
885library for reading and manipulating the Linux Kernel Device Tree binary format.")
886 (license (list license:gpl2+ license:bsd-2))))
887
888(define-public dtschema
889 (package
890 (name "dtschema")
891 (version "2026.06")
892 (source
893 (origin
894 (method git-fetch)
895 (uri (git-reference
896 (url "https://github.com/devicetree-org/dt-schema")
897 (commit (string-append "v" version))))
898 (file-name (git-file-name name version))
899 (sha256
900 (base32 "0ikklbdpwpz7g3y7x9602gp4y3crqxb62n38r9cpi3w3dm8r2i0p"))))
901 (build-system pyproject-build-system)
902 (arguments
903 (list
904 #:test-backend
905 #~'custom
906 #:test-flags
907 #~(list "test/test-dt-validate.py")
908 #:phases
909 #~(modify-phases %standard-phases
910 (add-before 'build 'patch-requirements
911 (lambda _
912 (substitute* "pyproject.toml"
913 (("pylibfdt")
914 "libfdt")))))))
915 (inputs
916 (list python-jsonschema
917 python-libfdt
918 python-rfc3987
919 python-ruamel.yaml))
920 (native-inputs
921 (list dtc
922 python-pytest
923 python-setuptools
924 python-setuptools-scm))
925 (home-page "https://www.devicetree.org/")
926 (synopsis "Tooling for devicetree validation using YAML and jsonschema")
927 (description
928 "This package contains tools and schema data for Devicetree schema validation
929using the json-schema vocabulary.")
930 (license license:bsd-2)))
931
932;;; Note: this package is not intended to be (and does not) build; it is a
933;;; template used by target-specific u-boot packages that make use of
934;;; `make-u-boot-package' and friends.
935;;;
936;;; To update:
937;;; ./pre-inst-env guix refresh -u '(@@ (gnu packages bootloaders u-boot))'
938;;;
939;;; To build most u-boot packages:
940;;; ./pre-inst-env guix search '^u-boot-' | recsel -Pname | xargs ./pre-inst-env guix build
941(define u-boot
942 (package
943 (name "u-boot")
944 (version "2026.07")
945 (source
946 (origin
947 (method git-fetch)
948 (uri (git-reference
949 (url "https://source.denx.de/u-boot/u-boot.git")
950 (commit (string-append "v" version))))
951 (file-name (git-file-name name version))
952 (sha256
953 (base32 "1y7syd9j6mp6pn16n3d9wzrh4aksip4r0rnkzkdqy3hpz29apsj7"))
954 (patches (search-patches "u-boot-allow-disabling-openssl.patch"))
955 (snippet
956 ;; Remove non-free binary licenses, blobs and microcode.
957 #~(begin
958 (use-modules (guix build utils))
959 (for-each delete-file
960 '("Licenses/r8a779x_usb3.txt"
961 "drivers/usb/host/xhci-rcar-r8a779x_usb3_v3.h"
962 "arch/mips/mach-octeon/include/mach/cvmx-pki-cluster.h"))
963 (for-each delete-file
964 (find-files "arch/x86/dts/microcode/" "\\.dtsi$"))))))
965 (build-system gnu-build-system)
966 (native-inputs
967 (list bison
968 dtc
969 gnutls
970 flex
971 lz4
972 ncurses/tinfo
973 perl
974 pkg-config ;for 'make menuconfig'
975 python
976 python-pyelftools
977 python-setuptools
978 python-wheel
979 swig-4.0
980 (list util-linux "lib")))
981 (home-page "https://www.denx.de/wiki/U-Boot/")
982 (synopsis "ARM bootloader")
983 (description "U-Boot is a bootloader used mostly for ARM boards. It
984also initializes the boards (RAM etc).")
985 (license license:gpl2+)))
986
987;;; This is very similar to the linux-libre-documentation package, since it
988;;; reuses the same Makefile-based build system.
989(define-public u-boot-documentation
990 (package
991 (inherit u-boot)
992 (name "u-boot-documentation")
993 (arguments
994 (list
995 #:make-flags #~(list "HOSTCC=gcc"
996 ;; Avoid treating Sphinx warnings as errors.
997 "SPHINXOPTS=")
998 #:tests? #f
999 #:phases #~(modify-phases %standard-phases
1000 (delete 'configure)
1001 (replace 'build
1002 (lambda* (#:key make-flags #:allow-other-keys)
1003 (apply invoke "make" "infodocs" make-flags)))
1004 (replace 'install
1005 (lambda* (#:key make-flags #:allow-other-keys)
1006 (let* ((info-dir (string-append #$output "/share/info"))
1007 (info (string-append info-dir
1008 "/DasUBoot.info.gz")))
1009 (with-directory-excursion "doc/output"
1010 (apply invoke "make" "-C" "texinfo" "install-info"
1011 (string-append "infodir=" info-dir)
1012 make-flags))))))))
1013 (native-inputs
1014 (modify-inputs native-inputs
1015 (append fontconfig
1016 python-six
1017 python-sphinx
1018 python-sphinx-prompt
1019 ; python-sphinx-rtd-theme ; optional
1020 python-sphinx-reredirects
1021 texinfo
1022 which)))
1023 (synopsis "U-Boot documentation")
1024 (description "This package provides the documentation for U-Boot, as an
1025Info manual.")))
1026
1027(define-public u-boot-tools
1028 (package
1029 (inherit u-boot)
1030 (name "u-boot-tools")
1031 (native-inputs
1032 (if (string-match "^x86_64-linux" (%current-system))
1033 (modify-inputs native-inputs
1034 (prepend python-filelock
1035 python-pycryptodomex
1036 python-pytest
1037 python-pytest-xdist))
1038 (modify-inputs native-inputs
1039 (prepend python-filelock
1040 python-pycryptodomex))))
1041 (inputs (list gnutls ncurses/tinfo))
1042 (arguments
1043 `(#:make-flags '("HOSTCC=gcc"
1044 ,@(if (%current-target-system)
1045 (list "CROSS_BUILD_TOOLS=y"
1046 (string-append
1047 "CROSS_COMPILE="
1048 (%current-target-system)
1049 "-"))
1050 '()))
1051 #:test-target "tcheck"
1052 #:phases
1053 (modify-phases %standard-phases
1054 (add-after 'unpack 'patch
1055 (lambda* (#:key inputs #:allow-other-keys)
1056 (substitute* "Makefile"
1057 (("/bin/pwd") (which "pwd"))
1058 (("/bin/false") (which "false")))
1059 (substitute* "tools/dtoc/fdt_util.py"
1060 (("'cc'") "'gcc'"))
1061 (substitute* "test/run"
1062 ;; Make it easier to find test failures.
1063 (("#!/bin/bash") "#!/bin/bash -x")
1064 ;; This test would require git.
1065 (("\\./tools/patman/patman") (which "true"))
1066 ;; FIXME: test fails, needs further investiation
1067 (("run_test \"binman\"") "# run_test \"binman\"")
1068 ;; FIXME: tests fail without kwbimage, i.e. openssl.
1069 (("run_test \"sandbox_noinst\"")
1070 "# run_test \"sandbox_noinst\"")
1071 (("run_test \"sandbox_vpl\"")
1072 "# run_test \"sandbox_vpl\"")
1073 ;; Disable code coverage tests.
1074 (("run_test \"(\\w+) code coverage\"" all)
1075 (string-append "# " all))
1076 ;; This test would require internet access.
1077 (("\\./tools/buildman/buildman") (which "true")))
1078 (substitute* "test/py/tests/test_sandbox_exit.py"
1079 (("def test_ctrl_c")
1080 "@pytest.mark.skip(reason='Guix has problems with SIGINT')
1081def test_ctrl_c"))
1082 ;; Test against the tools being installed rather than tools built
1083 ;; for "sandbox" target.
1084 (substitute* "test/image/test-imagetools.sh"
1085 (("BASEDIR=sandbox") "BASEDIR=."))
1086 (for-each (lambda (file)
1087 (substitute* file
1088 ;; Disable features that require OpenSSL due
1089 ;; to GPL/Openssl license incompatibilities.
1090 ;; See https://bugs.gnu.org/34717 for
1091 ;; details.
1092 (("CONFIG_FIT=y")
1093 "CONFIG_FIT=y
1094CONFIG_FIT_SIGNATURE=n
1095CONFIG_UT_LIB_ASN1=n
1096CONFIG_TOOLS_LIBCRYPTO=n
1097CONFIG_TOOLS_KWBIMAGE=n")
1098 ;; Catch instances of implied CONFIG_FIG_SIGNATURE
1099 ;; with VPL targets
1100 (("CONFIG_SANDBOX_VPL=y")
1101 "CONFIG_SANDBOX_VPL=y
1102CONFIG_FIT_SIGNATURE=n
1103CONFIG_VPL_FIT_SIGNATURE=n
1104CONFIG_TOOLS_LIBCRYPTO=n
1105CONFIG_TOOLS_KWBIMAGE=n")
1106 ;; This test requires a sound system, which is un-used
1107 ;; in u-boot-tools.
1108 (("CONFIG_SOUND=y") "CONFIG_SOUND=n")))
1109 (find-files "configs" "sandbox_.*defconfig$|tools-only_defconfig"))))
1110 (replace 'configure
1111 (lambda* (#:key make-flags #:allow-other-keys)
1112 (apply invoke "make" "tools-only_defconfig" make-flags)))
1113 (replace 'build
1114 (lambda* (#:key inputs make-flags #:allow-other-keys)
1115 (apply invoke "make" "tools-all" make-flags)))
1116 (replace 'install
1117 (lambda* (#:key outputs #:allow-other-keys)
1118 (let* ((out (assoc-ref outputs "out"))
1119 (bin (string-append out "/bin")))
1120 (for-each (lambda (name)
1121 (install-file name bin))
1122 '("tools/netconsole"
1123 "tools/jtagconsole"
1124 "tools/gen_eth_addr"
1125 "tools/gen_ethaddr_crc"
1126 "tools/img2srec"
1127 "tools/mkenvimage"
1128 "tools/dumpimage"
1129 "tools/mkimage"
1130 "tools/kwboot"
1131 "tools/proftool"
1132 "tools/fdtgrep"
1133 "tools/env/fw_printenv"
1134 "tools/sunxi-spl-image-builder")))))
1135 (delete 'check)
1136 (add-after 'install 'check
1137 (lambda* (#:key make-flags test-target tests? #:allow-other-keys)
1138 (when tests?
1139 (invoke "test/image/test-imagetools.sh"))))
1140 ;; Only run full test suite on x86_64 systems, as many tests
1141 ;; assume x86_64.
1142 ,@(if (string-match "^x86_64-linux" (%current-system))
1143 '((add-after 'check 'check-x86
1144 (lambda* (#:key make-flags test-target tests? #:allow-other-keys)
1145 (when tests?
1146 (begin
1147 (apply invoke "make" "mrproper" make-flags)
1148 (setenv "SDL_VIDEODRIVER" "dummy")
1149 (setenv "PAGER" "cat")
1150 (apply invoke "make" test-target make-flags))))))
1151 '()))))
1152 (description (string-append
1153 (package-description u-boot)
1154 " This package provides board-independent tools "
1155 "of U-Boot."))))
1156
1157(define-public python-u-boot-pylib
1158 (package
1159 (inherit u-boot)
1160 (name "python-u-boot-pylib")
1161 (build-system pyproject-build-system)
1162 (arguments
1163 (list
1164 #:phases
1165 #~(modify-phases %standard-phases
1166 (add-after 'unpack 'chdir
1167 (lambda _
1168 (chdir "tools/u_boot_pylib")))
1169 (replace 'check
1170 (lambda* (#:key tests? #:allow-other-keys)
1171 (when tests?
1172 (invoke "./u_boot_pylib")))))))
1173 (native-inputs (list python-setuptools))
1174 (synopsis "U-Boot Python library")
1175 (description "This package provides common Python code used by some of the
1176commands part of the U-Boot project, such as Patman.")))
1177
1178;;; This is packaged separately, as it can be used in other contexts than for
1179;;; U-Boot development.
1180(define-public patman
1181 (package
1182 (inherit u-boot)
1183 (name "patman")
1184 (build-system pyproject-build-system)
1185 (arguments
1186 ;; The test suite strongly relies on the git metadata being available (23
1187 ;; failed, 14 passed).
1188 (list
1189 #:tests? #f
1190 #:phases
1191 #~(modify-phases %standard-phases
1192 ;; Patman fails to run during 'sanity-check phase, as it needs to be
1193 ;; run within a git directory.
1194 (delete 'sanity-check)
1195 (add-after 'unpack 'chdir
1196 (lambda _
1197 (chdir "tools/patman")))
1198 (add-after 'install 'wrap-script
1199 (lambda* (#:key inputs #:allow-other-keys)
1200 (wrap-script (string-append #$output "/bin/patman")
1201 `("PATH" ":" prefix
1202 (,(string-append #$(this-package-input "git") "/bin")))
1203 `("GIT_EXEC_PATH" ":" prefix
1204 (,(dirname (search-input-file
1205 inputs "libexec/git-core/git-commit"))
1206 ,(dirname (search-input-file
1207 inputs
1208 "libexec/git-core/git-send-email"))))))))))
1209 (native-inputs (list python-setuptools))
1210 (inputs
1211 (list git
1212 `(,git "send-email")
1213 guile-3.0/pinned ;for wrap-script
1214 python-pygit2
1215 python-requests
1216 python-u-boot-pylib))
1217 (synopsis "Patch automation tool")
1218 (description "Patman is a patch automation script which:
1219@itemize
1220@item Creates patches directly from your branch
1221@item Cleans them up by removing unwanted tags
1222@item Inserts a cover letter with change lists
1223@item Runs the patches through automated checks
1224@item Optionally emails them out to selected people.
1225@end itemize")))
1226
1227(define*-public (make-u-boot-package board triplet
1228 #:key
1229 defconfig
1230 configs
1231 name-suffix
1232 append-description
1233 (u-boot u-boot))
1234 "Return a U-Boot package for BOARD cross-compiled for TRIPLET with the
1235optional DEFCONFIG file and optional configuration changes from CONFIGS.
1236TRIPLET may also be set to #f to disable cross-compilation. NAME-SUFFIX is
1237appended to the package name, while APPEND-DESCRIPTION is appended to the
1238package description. U-BOOT can be used when a fork or a different version of
1239U-Boot must be used."
1240 (let ((native-build? (lambda ()
1241 (or (not triplet) ;disable cross-compilation
1242 (string=? (%current-system)
1243 (gnu-triplet->nix-system triplet))))))
1244 (package
1245 (inherit u-boot)
1246 (name (string-append (downstream-package-name "u-boot-" board)
1247 (or name-suffix "")))
1248 (description (if append-description
1249 (string-append (package-description u-boot)
1250 "\n\n" append-description)
1251 (package-description u-boot)))
1252 (build-system gnu-build-system)
1253 (arguments
1254 (substitute-keyword-arguments arguments
1255 ((#:target _ #f)
1256 (and (not (native-build?)) triplet))
1257 ((#:modules modules '())
1258 `((ice-9 ftw)
1259 (srfi srfi-1)
1260 (guix build gnu-build-system)
1261 (guix build kconfig)
1262 (guix build utils)
1263 ,@modules))
1264 ((#:imported-modules imported-modules '())
1265 `((guix build kconfig)
1266 ,@%default-gnu-imported-modules
1267 ,@imported-modules))
1268 ((#:test-target _ "test")
1269 "test")
1270 ((#:make-flags make-flags '())
1271 #~(list "HOSTCC=gcc"
1272 "KBUILD_VERBOSE=1"
1273 #$@(if (not (native-build?))
1274 (list (string-append "CROSS_COMPILE=" triplet "-"))
1275 '())
1276 #$@make-flags))
1277 ((#:phases phases '%standard-phases)
1278 #~(modify-phases #$phases
1279 (replace 'configure
1280 (lambda* (#:key make-flags #:allow-other-keys)
1281 (let* ((config-name (string-append #$board "_defconfig"))
1282 (config-file (string-append "configs/" config-name))
1283 (defconfig #$defconfig)
1284 (configs '#$configs))
1285 (when defconfig
1286 ;; Replace the board-specific defconfig with the given
1287 ;; one.
1288 (copy-file defconfig config-file))
1289 (if (file-exists? config-file)
1290 (begin
1291 (when configs
1292 (modify-defconfig config-file configs))
1293 (apply invoke "make" `(,@make-flags ,config-name))
1294 (verify-config ".config" config-file))
1295 (begin
1296 (display "invalid board name; valid board names are:"
1297 (current-error-port))
1298 (let ((suffix-len (string-length "_defconfig"))
1299 (entries (scandir "configs")))
1300 (for-each (lambda (file-name)
1301 (when (string-suffix? "_defconfig"
1302 file-name)
1303 (format (current-error-port)
1304 "- ~A\n"
1305 (string-drop-right
1306 file-name suffix-len))))
1307 (sort entries string-ci<)))
1308 (error "invalid boardname ~s" #$board))))))
1309 (add-after 'configure 'disable-tools-libcrypto
1310 ;; Disable libcrypto due to GPL and OpenSSL license
1311 ;; incompatibilities
1312 (lambda _
1313 (substitute* ".config"
1314 (("CONFIG_TOOLS_LIBCRYPTO=.*$")
1315 "CONFIG_TOOLS_LIBCRYPTO=n
1316CONFIG_TOOLS_KWBIMAGE=n"))))
1317 (replace 'install
1318 (lambda _
1319 (let ((libexec (string-append #$output "/libexec"))
1320 (uboot-files
1321 (append
1322 (remove
1323 ;; Those would not be reproducible
1324 ;; because of the randomness used to
1325 ;; produce them. It's expected that the
1326 ;; user will use u-boot-tools to generate
1327 ;; them instead.
1328 (lambda (name)
1329 (string-suffix?
1330 "sunxi-spl-with-ecc.bin"
1331 name))
1332 (find-files "."
1333 ".*\\.(bin|efi|img|imx|spl|itb|dtb|rksd)$"))
1334 (find-files "." "^(MLO|SPL)$"))))
1335 (mkdir-p libexec)
1336 (install-file ".config" libexec)
1337 ;; Useful for "qemu -kernel".
1338 (install-file "u-boot" libexec)
1339 (for-each
1340 (lambda (file)
1341 (let ((target-file (string-append libexec "/" file)))
1342 (mkdir-p (dirname target-file))
1343 (copy-file file target-file)))
1344 uboot-files)))))))))))
1345
1346(define* (make-u-boot-rockchip-package board soc #:optional configs)
1347 "Return the U-Boot package for BOARD with AAarch64 Rockchip SOC
1348(System on Chip)."
1349 (let* ((board (string-append board "-" (symbol->string soc)))
1350 (base (make-u-boot-package board "aarch64-linux-gnu"
1351 #:configs configs)))
1352 (package
1353 (inherit base)
1354 (arguments
1355 (substitute-keyword-arguments arguments
1356 ((#:phases phases)
1357 #~(modify-phases #$phases
1358 (add-after 'unpack 'set-environment
1359 (lambda* (#:key inputs #:allow-other-keys)
1360 (setenv "BL31" (search-input-file inputs "/bl31.elf"))))))))
1361 (inputs (modify-inputs inputs
1362 (append (match soc
1363 ('rk3588 arm-trusted-firmware-rk3588)
1364 ('rk3399 arm-trusted-firmware-rk3399)
1365 ('rk3328 arm-trusted-firmware-rk3328))))))))
1366
1367(define-public u-boot-am335x-boneblack
1368 (let ((base (make-u-boot-package
1369 "am335x_evm" "arm-linux-gnueabihf"
1370 ;; Patch out other device trees to build an image small enough
1371 ;; to fit within typical partitioning schemes where the first
1372 ;; partition begins at sector 2048.
1373 #:configs '("CONFIG_OF_LIST=\"am335x-evm am335x-boneblack\"")
1374 #:append-description
1375 "This U-Boot is built for the BeagleBone Black, which was
1376removed upstream, adjusted from the am335x_evm build with several device trees
1377removed so that it fits within common partitioning schemes.")))
1378 (package
1379 (inherit base)
1380 ;; The name is not derived from the board name on purpose, as the config
1381 ;; is modified per the comment above, parting from the default
1382 ;; am335x_evm configuration.
1383 (name "u-boot-am335x-boneblack"))))
1384
1385(define-public u-boot-am335x-evm
1386 (make-u-boot-package "am335x_evm" "arm-linux-gnueabihf"))
1387
1388(define*-public (make-u-boot-sunxi64-package board triplet scp-firmware
1389 #:key defconfig configs)
1390 (let ((base (make-u-boot-package
1391 board triplet #:defconfig defconfig #:configs configs)))
1392 (package
1393 (inherit base)
1394 (arguments
1395 (substitute-keyword-arguments arguments
1396 ((#:phases phases)
1397 #~(modify-phases #$phases
1398 (add-after 'unpack 'set-environment
1399 (lambda* (#:key native-inputs inputs #:allow-other-keys)
1400 (setenv "SCP" (search-input-file
1401 (or native-inputs inputs) "libexec/scp.bin"))
1402 (setenv "BL31" (search-input-file inputs "bl31.bin"))))))))
1403 (native-inputs
1404 (modify-inputs native-inputs
1405 (append (force scp-firmware))))
1406 (inputs
1407 (modify-inputs inputs
1408 (append arm-trusted-firmware-sun50i-a64))))))
1409
1410(define-public u-boot-orangepi-zero2w
1411 (let ((base (make-u-boot-package
1412 "orangepi_zero2w" "aarch64-linux-gnu")))
1413 (package
1414 (inherit base)
1415 (arguments
1416 (substitute-keyword-arguments arguments
1417 ((#:phases phases)
1418 #~(modify-phases #$phases
1419 (add-after 'unpack 'set-environment
1420 (lambda* (#:key native-inputs inputs #:allow-other-keys)
1421 (setenv "SCP" "/dev/null")
1422 (setenv "BL31" (search-input-file inputs "bl31.bin"))))))))
1423 (inputs
1424 (modify-inputs inputs
1425 ;; The Zero 2W uses the slightly revised Allwinner H618.
1426 (append arm-trusted-firmware-sun50i-h616))))))
1427
1428(define-public u-boot-pine64-plus
1429 (make-u-boot-sunxi64-package "pine64_plus" "aarch64-linux-gnu"
1430 (delay crust-pine64-plus)))
1431
1432(define-public u-boot-pine64-lts
1433 (make-u-boot-sunxi64-package "pine64-lts" "aarch64-linux-gnu"
1434 (delay crust-pine64-plus)))
1435
1436(define-public u-boot-pinebook
1437 (make-u-boot-sunxi64-package
1438 "pinebook" "aarch64-linux-gnu" (delay crust-pinebook)
1439 ;; Fix regression with LCD video output introduced in 2020.01
1440 ;; https://patchwork.ozlabs.org/patch/1225130/
1441 #:configs '("CONFIG_VIDEO_BPP32=y")))
1442
1443(define-public u-boot-bananapi-m2-ultra
1444 (make-u-boot-package "Bananapi_M2_Ultra" "arm-linux-gnueabihf"))
1445
1446(define-public u-boot-a20-olinuxino-lime
1447 (make-u-boot-package "A20-OLinuXino-Lime" "arm-linux-gnueabihf"))
1448
1449(define-public u-boot-a20-olinuxino-lime2
1450 (make-u-boot-package "A20-OLinuXino-Lime2" "arm-linux-gnueabihf"))
1451
1452(define-public u-boot-a20-olinuxino-micro
1453 (make-u-boot-package "A20-OLinuXino_MICRO" "arm-linux-gnueabihf"))
1454
1455(define-public u-boot-wandboard
1456 (make-u-boot-package "wandboard" "arm-linux-gnueabihf"))
1457
1458(define-public u-boot-mx6cuboxi
1459 (make-u-boot-package "mx6cuboxi" "arm-linux-gnueabihf"))
1460
1461(define-public u-boot-novena
1462 (make-u-boot-package
1463 "novena" "arm-linux-gnueabihf"
1464 ;; Patch configuration to disable loading u-boot.img from FAT partition,
1465 ;; allowing it to be installed at a device offset.
1466 #:configs '("# CONFIG_SPL_FS_FAT is not set")
1467 #:append-description "This U-Boot is built for Novena. Be advised that this
1468version, contrary to Novena upstream, does not load u-boot.img from the first
1469partition."))
1470
1471(define-public u-boot-orangepi-r1-plus-lts-rk3328
1472 (make-u-boot-rockchip-package "orangepi-r1-plus-lts" 'rk3328))
1473
1474(define-public u-boot-cubieboard
1475 (make-u-boot-package "Cubieboard" "arm-linux-gnueabihf"))
1476
1477(define-public u-boot-cubietruck
1478 (make-u-boot-package "Cubietruck" "arm-linux-gnueabihf"))
1479
1480(define-public u-boot-puma-rk3399
1481 (make-u-boot-rockchip-package "puma" 'rk3399))
1482
1483(define-public u-boot-qemu-arm
1484 (make-u-boot-package "qemu_arm" "arm-linux-gnueabihf"
1485 ;; Disable features that require OpenSSL due
1486 ;; to GPL/Openssl license incompatibilities.
1487 ;; See https://bugs.gnu.org/34717 for
1488 ;; details.
1489 #:configs '("# CONFIG_FIT_SIGNATURE is not set")))
1490
1491(define-public u-boot-qemu-arm64
1492 (make-u-boot-package "qemu_arm64" "aarch64-linux-gnu"
1493 ;; Disable features that require OpenSSL due
1494 ;; to GPL/Openssl license incompatibilities.
1495 ;; See https://bugs.gnu.org/34717 for
1496 ;; details.
1497 #:configs '("# CONFIG_FIT_SIGNATURE is not set")))
1498
1499(define-public u-boot-qemu-riscv64
1500 (make-u-boot-package "qemu-riscv64" "riscv64-linux-gnu"))
1501
1502(define-public u-boot-qemu-riscv64-smode
1503 (make-u-boot-package "qemu-riscv64_smode" "riscv64-linux-gnu"))
1504
1505(define-public u-boot-sandbox
1506 (define base
1507 (make-u-boot-package
1508 "sandbox" #f ;build for the native system
1509 ;; These disabled features require OpenSSL, which is
1510 ;; incompatible with the GPLv2-only parts of U-boot.
1511 #:configs (map (cut string-append "# CONFIG_" <> " is not set")
1512 '("FIT_CIPHER" "MBEDTLS_LIB" "HKDF_MBEDTLS"))
1513 #:append-description
1514 "The sandbox configuration of U-Boot provides a @command{u-boot}
1515command that runs as a normal user space application. It can be used to
1516test the functionality of U-Boot interactively without having to deploy
1517to an actual target device. @xref{Sandbox<6>,,,u-boot, The U-Boot
1518Documentation} for more information (for example by running @samp{info
1519\"(u-boot) Sandbox<6>\"})."))
1520 (package
1521 (inherit base)
1522 (arguments
1523 (substitute-keyword-arguments arguments
1524 ((#:phases phases '%standard-phases)
1525 #~(modify-phases #$phases
1526 (add-after 'install 'symlink-u-boot-command
1527 (lambda* (#:key outputs #:allow-other-keys)
1528 ;; For ease of discovery.
1529 (mkdir (string-append #$output "/bin"))
1530 (symlink (search-input-file outputs "libexec/u-boot")
1531 (string-append #$output "/bin/u-boot"))))))))
1532 ;; cert-to-efi-sig-list from efitools creates the EFI capsule ESL.
1533 (inputs (modify-inputs inputs
1534 (append efitools sdl2)))))
1535
1536(define-public u-boot-sifive-unleashed
1537 (let ((base (make-u-boot-package "sifive_unleashed" "riscv64-linux-gnu")))
1538 (package
1539 (inherit base)
1540 (arguments
1541 (substitute-keyword-arguments arguments
1542 ((#:phases phases)
1543 #~(modify-phases #$phases
1544 (add-after 'unpack 'set-environment
1545 (lambda* (#:key inputs #:allow-other-keys)
1546 (setenv "OPENSBI" (search-input-file inputs
1547 "fw_dynamic.bin"))))))))
1548 (inputs
1549 (modify-inputs inputs
1550 (append opensbi-generic))))))
1551
1552(define-public u-boot-sifive-unmatched
1553 (let ((base (make-u-boot-package "sifive_unmatched" "riscv64-linux-gnu")))
1554 (package
1555 (inherit base)
1556 (arguments
1557 (substitute-keyword-arguments arguments
1558 ((#:phases phases)
1559 #~(modify-phases #$phases
1560 (add-after 'unpack 'set-environment
1561 (lambda* (#:key inputs #:allow-other-keys)
1562 (setenv "OPENSBI" (search-input-file inputs
1563 "fw_dynamic.bin"))))))))
1564 (inputs
1565 (modify-inputs inputs
1566 (append opensbi-generic))))))
1567
1568(define-public u-boot-starfive-visionfive2
1569 (let ((base (make-u-boot-package
1570 "starfive_visionfive2" "riscv64-linux-gnu"
1571 ;; Allow kernel-arguments pass more content.
1572 ;; If out of range, boot will fail.
1573 #:configs '("CONFIG_SYS_CBSIZE=1024"
1574 "CONFIG_WGET_HTTPS")))) ;avoid openssl
1575 (package
1576 (inherit base)
1577 (arguments
1578 (substitute-keyword-arguments arguments
1579 ((#:phases phases)
1580 #~(modify-phases #$phases
1581 (add-after 'unpack 'set-environment
1582 (lambda* (#:key inputs #:allow-other-keys)
1583 (setenv "OPENSBI" (search-input-file inputs
1584 "fw_dynamic.bin"))))
1585 (add-after 'install 'install-u-boot-spl.bin.normal.out
1586 (lambda _
1587 (install-file "spl/u-boot-spl.bin.normal.out"
1588 (string-append #$output
1589 "/libexec/spl"))))))))
1590 (inputs
1591 (modify-inputs inputs
1592 (append opensbi-for-visionfive2))))))
1593
1594(define-public u-boot-rock64-rk3328
1595 (make-u-boot-rockchip-package "rock64" 'rk3328))
1596
1597(define-public u-boot-firefly-rk3399
1598 (make-u-boot-rockchip-package "firefly" 'rk3399))
1599
1600(define-public u-boot-rock-4c-plus-rk3399
1601 (make-u-boot-rockchip-package "rock-4c-plus" 'rk3399))
1602
1603(define-public u-boot-rockpro64-rk3399
1604 (let ((base (make-u-boot-rockchip-package
1605 "rockpro64" 'rk3399
1606 '("CONFIG_USB=y"
1607 "CONFIG_AHCI=y"
1608 "CONFIG_AHCI_PCI=y"
1609 "CONFIG_SATA=y"
1610 "CONFIG_SATA_SIL=y"
1611 "CONFIG_SCSI=y"
1612 "CONFIG_SCSI_AHCI=y"
1613 ;; Disable SPL FIT signatures, due to GPLv2 and
1614 ;; OpenSSL license incompatibilities.
1615 "# CONFIG_SPL_FIT_SIGNATURE is not set"))))
1616 (package
1617 (inherit base))))
1618
1619(define-public u-boot-pinebook-pro-rk3399
1620 (make-u-boot-rockchip-package "pinebook-pro" 'rk3399))
1621
1622(define-public u-boot-nanopi-r4s-rk3399
1623 (make-u-boot-rockchip-package "nanopi-r4s" 'rk3399))
1624
1625(define*-public (make-u-boot-bin-package u-boot-package
1626 #:key
1627 (u-boot-bin "u-boot.bin"))
1628 "Return a package with a single U-BOOT-BIN file from the U-BOOT-PACKAGE.
1629The package name will be that of the U-BOOT package suffixed with \"-bin\"."
1630 (package
1631 (name (string-append (package-name u-boot-package) "-bin"))
1632 (version (package-version u-boot-package))
1633 (source #f)
1634 (build-system trivial-build-system)
1635 (arguments
1636 (list
1637 #:builder
1638 (with-imported-modules '((guix build utils))
1639 #~(begin
1640 (use-modules (guix build utils))
1641 (mkdir #$output)
1642 (symlink (search-input-file %build-inputs
1643 (string-append "libexec/" #$u-boot-bin))
1644 (string-append #$output "/" #$u-boot-bin))))))
1645 (inputs (list u-boot-package))
1646 (home-page (package-home-page u-boot-package))
1647 (synopsis (package-synopsis u-boot-package))
1648 (description (string-append
1649 (package-description u-boot-package)
1650 "\n\n"
1651 (format #f
1652 "This package only contains the file ~a."
1653 u-boot-bin)))
1654 (license (package-license u-boot-package))))
1655
1656(define-public %u-boot-rpi-efi-configs
1657 '("CONFIG_OF_EMBED"
1658 "CONFIG_OF_BOARD=y"))
1659
1660(define %u-boot-rpi-description-32-bit
1661 "This is a 32-bit build of U-Boot.")
1662
1663(define %u-boot-rpi-description-64-bit
1664 "This is a common 64-bit build of U-Boot for all 64-bit capable Raspberry Pi
1665variants.")
1666
1667(define %u-boot-rpi-efi-description
1668 "It allows network booting and uses the device-tree from the firmware,
1669allowing the usage of overlays. It can act as an EFI firmware for the
1670grub-efi-netboot-removable-bootloader.")
1671
1672(define %u-boot-rpi-efi-description-32-bit
1673 (string-append %u-boot-rpi-efi-description " "
1674 %u-boot-rpi-description-32-bit))
1675
1676(define-public u-boot-rpi-2
1677 (make-u-boot-package "rpi_2" "arm-linux-gnueabihf"
1678 #:append-description %u-boot-rpi-description-32-bit))
1679
1680(define-public u-boot-rpi-3-32b
1681 (make-u-boot-package "rpi_3_32b" "arm-linux-gnueabihf"
1682 #:append-description %u-boot-rpi-description-32-bit))
1683
1684(define-public u-boot-rpi-4-32b
1685 (make-u-boot-package "rpi_4_32b" "arm-linux-gnueabihf"
1686 #:append-description %u-boot-rpi-description-32-bit))
1687
1688(define-public u-boot-rpi-arm64
1689 (make-u-boot-package "rpi_arm64" "aarch64-linux-gnu"
1690 #:configs '("CONFIG_WGET_HTTPS") ;requires openssl
1691 #:append-description %u-boot-rpi-description-64-bit))
1692
1693(define-public u-boot-rpi-2-efi
1694 (make-u-boot-package "rpi_2" "arm-linux-gnueabihf"
1695 #:name-suffix "-efi"
1696 #:configs %u-boot-rpi-efi-configs
1697 #:append-description %u-boot-rpi-efi-description-32-bit))
1698
1699(define-public u-boot-rpi-3-32b-efi
1700 (make-u-boot-package "rpi_3_32b" "arm-linux-gnueabihf"
1701 #:name-suffix "-efi"
1702 #:configs %u-boot-rpi-efi-configs
1703 #:append-description %u-boot-rpi-efi-description-32-bit))
1704
1705(define-public u-boot-rpi-4-32b-efi
1706 (make-u-boot-package "rpi_4_32b" "arm-linux-gnueabihf"
1707 #:name-suffix "-efi"
1708 #:configs %u-boot-rpi-efi-configs
1709 #:append-description %u-boot-rpi-efi-description-32-bit))
1710
1711(define-public u-boot-rpi-arm64-efi
1712 (make-u-boot-package "rpi_arm64" "aarch64-linux-gnu"
1713 #:name-suffix "-efi"
1714 #:configs (cons "CONFIG_WGET_HTTPS" ;requires openssl
1715 %u-boot-rpi-efi-configs)
1716 #:append-description (string-append
1717 %u-boot-rpi-efi-description " "
1718 %u-boot-rpi-description-64-bit)))
1719
1720(define-public u-boot-rpi-2-bin (make-u-boot-bin-package u-boot-rpi-2))
1721
1722(define-public u-boot-rpi-3_32b-bin (make-u-boot-bin-package u-boot-rpi-3-32b))
1723
1724(define-public u-boot-rpi-4_32b-bin (make-u-boot-bin-package u-boot-rpi-4-32b))
1725
1726(define-public u-boot-rpi-arm64-bin (make-u-boot-bin-package u-boot-rpi-arm64))
1727
1728(define-public u-boot-rpi-2-efi-bin (make-u-boot-bin-package u-boot-rpi-2-efi))
1729
1730(define-public u-boot-rpi-3-32b-efi-bin
1731 (make-u-boot-bin-package u-boot-rpi-3-32b-efi))
1732
1733(define-public u-boot-rpi-4-32b-efi-bin
1734 (make-u-boot-bin-package u-boot-rpi-4-32b-efi))
1735
1736(define-public u-boot-rpi-arm64-efi-bin
1737 (make-u-boot-bin-package u-boot-rpi-arm64-efi))
1738
1739(define u-boot-ts-mx6
1740 ;; There is no release; use the latest commit of the
1741 ;; 'imx_v2015.04_3.14.52_1.1.0_ga' branch.
1742 (let ((revision "0")
1743 (commit "08809160fbc60d6e949fa9d37d9a41aab8fef742"))
1744 (package
1745 (inherit u-boot)
1746 (name "u-boot-ts-mx6")
1747 (version (git-version "2015.04_3" revision commit))
1748 (source (origin
1749 (method git-fetch)
1750 (uri (git-reference
1751 (url "https://github.com/embeddedTS/u-boot-imx")
1752 (commit commit)))
1753 (file-name (git-file-name "u-boot-imx-ts" version))
1754 (sha256
1755 (base32
1756 "01mja33351hkcs59rmfvppqlxqw4rh9gng7a7hx2cfspqwh2y6kr"))))
1757 (arguments
1758 (substitute-keyword-arguments arguments
1759 ((#:phases phases '%standard-phases)
1760 #~(modify-phases #$phases
1761 (add-after 'unpack 'patch-u-boot
1762 (lambda _
1763 (substitute* (find-files "include/configs" "^ts[0-9]{4}\\.h$")
1764 ;; Default to boot a standard zImage instead of a uImage.
1765 (("/boot/uImage")
1766 "/boot/zImage")
1767 (("uimage")
1768 "zimage")
1769 (("bootm \\$\\{loadaddr}")
1770 "bootz ${loadaddr}")
1771 ;; This reference DTB is not available in mainline.
1772 (("ts7970-revf.dtb")
1773 "ts7970.dtb")
1774 ;; Enable support for DISTRO_DEFAULTS, which enables to
1775 ;; use 'sysboot' to boot Guix System. Also enable
1776 ;; "standard" boot commands for dealing with discovery and
1777 ;; booting of syslinux configurations (extlinux.conf).
1778
1779 ;; Disable the stock CONFIG_BOOTCOMMAND to avoid a
1780 ;; redefinition error.
1781 (("CONFIG_BOOTCOMMAND")
1782 "CONFIG_BOOTCOMMAND_DISABLED")
1783 (("CONFIG_BOOTDELAY")
1784 "CONFIG_BOOTDELAY_DISABLED")
1785 ;; Inspired by include/configs/embestmx6boards.h
1786 (("#define CONFIG_EXTRA_ENV_SETTINGS.*" anchor)
1787 (string-append "\
1788#include <config_distro_defaults.h>
1789
1790#define MEM_LAYOUT_ENV_SETTINGS \\
1791\t\"bootm_size=0x10000000\\0\" \\
1792\t\"kernel_addr_r=0x10800000\\0\" \\
1793\t\"fdt_addr_r=0x18000000\\0\" \\
1794\t\"scriptaddr=0x18100000\\0\" \\
1795\t\"pxefile_addr_r=0x18200000\\0\" \\
1796\t\"ramdisk_addr_r=0x18300000\\0\"
1797
1798#define BOOT_TARGET_DEVICES(func) \\
1799\tfunc(MMC, mmc, 0) \\
1800\tfunc(MMC, mmc, 1) \\
1801\tfunc(SATA, sata, 0) \\
1802\tfunc(USB, usb, 0) \\
1803\tfunc(PXE, pxe, na) \\
1804\tfunc(DHCP, dhcp, na)
1805
1806#include <config_distro_bootcmd.h>
1807
1808" anchor
1809
1810;; Sadly, the user config CONFIG_DEFAULT_FDT_FILE did not exist in that older
1811;; U-Boot. A placeholder is added here, to be substituted in each TS U-Boot
1812;; board package.
1813"\
1814\t\"fdtfile=DEFAULT_FDT_FILE\\0\" \\
1815\tMEM_LAYOUT_ENV_SETTINGS \\
1816\tBOOTENV \\\n")))))
1817 (add-after 'unpack 'patch-for-reproducibility
1818 (lambda _
1819 ;; Substitute dynamically computed timestamps with static
1820 ;; ones.
1821 (substitute* "Makefile"
1822 (("U_BOOT_DATE \"%b %d %C%y\"")
1823 "U_BOOT_DATE \"Jan 01 1969\"")
1824 (("U_BOOT_TIME \"%T\"")
1825 "U_BOOT_TIME \"00:00:00\""))))
1826 (add-before 'build 'adjust-for-current-gcc
1827 (lambda _
1828 (let ((gcc-major-version #$(version-major
1829 (package-version gcc))))
1830 (copy-file "include/linux/compiler-gcc6.h"
1831 (string-append "include/linux/compiler-gcc"
1832 gcc-major-version ".h")))
1833 (substitute* "arch/arm/Makefile"
1834 (("march=armv5")
1835 "march=armv5te"))))
1836 (add-after 'install 'build+install-tools
1837 (lambda* (#:key make-flags #:allow-other-keys)
1838 (apply invoke "make" "tools-all" make-flags)
1839 (install-file "tools/env/fw_printenv"
1840 (string-append #$output "/bin"))
1841 (symlink (string-append #$output "/bin/fw_printenv")
1842 (string-append #$output "/bin/fw_setenv"))))))))
1843 (native-inputs
1844 (modify-inputs native-inputs
1845 (delete "dtc")))))) ;otherwise the build fails
1846
1847;;; Note: the default cross-build of this package is currently broken on
1848;;; master; the fix exists as commit 6454208222d6e7760daa964b590f35ea75ffe0e5
1849;;; ("build: gnu-build-system: Remove source from native inputs.") on
1850;;; core-updates.
1851(define-public u-boot-ts7970-q-2g-1000mhz-c
1852 (let ((base
1853 (make-u-boot-package "ts7970-q-2g-1000mhz-c" "arm-linux-gnueabihf"
1854 #:u-boot u-boot-ts-mx6
1855 #:append-description
1856 "This U-Boot variant is for the Technologic
1857Systems TS-7970 revision C board, which includes a quad core Freescale i.MX6
1858CPU and 2 GiB of RAM clocked at 1000MHz. The binary U-Boot image to flash is
1859the @file{libexec/u-boot.imx} file. It can be used with the @file{zImage} and
1860the @file{imx6q-ts7970.dtb} files provided by the
1861@code{linux-libre-arm-generic} image.
1862
1863To flash this bootloader, write it to an SD card, then using the U-Boot serial
1864console:
1865@example
1866mmc dev 0
1867load mmc 0:1 ${loadaddr} /boot/u-boot.imx
1868sf probe
1869sf erase 0 0x80000
1870sf write ${loadaddr} 0x400 $filesize
1871@end example
1872
1873The factory values of U-Boot must also be reset so that it boots using a
1874zImage instead of the default uImage:
1875@example
1876run clearenv
1877reset
1878@end example
1879
1880For more information, refer to
1881@url{https://docs.embeddedts.com/TS-7970#Update_U-Boot}.")))
1882 (package
1883 (inherit base)
1884 (arguments
1885 (substitute-keyword-arguments arguments
1886 ((#:phases phases '%standard-phases)
1887 #~(modify-phases #$phases
1888 (add-after 'patch-u-boot 'set-default-fdt-file
1889 (lambda _
1890 (substitute* "include/configs/ts7970.h"
1891 (("DEFAULT_FDT_FILE")
1892 "imx6q-ts7970.dtb")))))))))))
1893
1894(define-public os-prober
1895 (package
1896 (name "os-prober")
1897 (version "1.84")
1898 (source
1899 (origin
1900 (method git-fetch)
1901 (uri (git-reference
1902 (url "https://salsa.debian.org/installer-team/os-prober.git")
1903 (commit version)))
1904 (file-name (git-file-name name version))
1905 (sha256
1906 (base32 "1bji3w6nbqaz8zqrbmy8b1j5dph9xn7bdh1cd2z8ia1q125i6mgp"))))
1907 (build-system gnu-build-system)
1908 (arguments
1909 (list
1910 #:tests? #f ; No tests.
1911 #:modules '((guix build gnu-build-system)
1912 (guix build utils)
1913 (ice-9 regex) ; string-match
1914 (srfi srfi-26)) ; cut
1915 #:make-flags
1916 #~(list (string-append "CC=" #$(cc-for-target)))
1917 #:phases
1918 #~(modify-phases %standard-phases
1919 (replace 'configure
1920 (lambda _
1921 (substitute* (find-files ".")
1922 (("/usr") #$output))
1923 (substitute* (find-files "." "50mounted-tests$")
1924 (("mkdir") "mkdir -p -v"))))
1925 (replace 'install
1926 (lambda _
1927 (define (find-files-non-recursive directory)
1928 (find-files directory
1929 (lambda (file stat)
1930 (string-match (string-append "^" directory "/[^/]*$")
1931 file))
1932 #:directories? #t))
1933
1934 (let ((bin (string-append #$output "/bin"))
1935 (lib (string-append #$output "/lib"))
1936 (share (string-append #$output "/share")))
1937 (for-each (cut install-file <> bin)
1938 (list "linux-boot-prober" "os-prober"))
1939 (install-file "newns" (string-append lib "/os-prober"))
1940 (install-file "common.sh" (string-append share "/os-prober"))
1941 (install-file "os-probes/mounted/powerpc/20macosx"
1942 (string-append lib "/os-probes/mounted"))
1943 (for-each
1944 (lambda (directory)
1945 (for-each
1946 (lambda (file)
1947 (let ((destination (string-append lib "/" directory
1948 "/" (basename file))))
1949 (mkdir-p (dirname destination))
1950 (copy-recursively file destination)))
1951 (append (find-files-non-recursive (string-append directory "/common"))
1952 (find-files-non-recursive (string-append directory "/x86")))))
1953 (list "linux-boot-probes"
1954 "linux-boot-probes/mounted"
1955 "os-probes"
1956 "os-probes/init"
1957 "os-probes/mounted"))))))))
1958 (home-page "https://joeyh.name/code/os-prober/")
1959 (synopsis "Detect other operating systems")
1960 (description "os-prober probes disks on the system for other operating
1961systems so that they can be added to the bootloader. It also works out how to
1962boot existing GNU/Linux systems and detects what distribution is installed in
1963order to add a suitable bootloader menu entry.")
1964 (license license:gpl2+)))
1965
1966(define-public ipxe
1967 ;; XXX: 'BUILD_TIMESTAMP' is used to automatically select the newest version
1968 ;; of iPXE if multiple iPXE drivers are loaded concurrently in a UEFI system.
1969 ;;
1970 ;; TODO: Bump this timestamp at each modifications of the package (not only
1971 ;; for updates) by running: date +%s.
1972 (let ((timestamp "1756877872")
1973 (commit "969ce2c559a6841a949a1b73a3967b1889e0c999")
1974 (revision "4"))
1975 (package
1976 (name "ipxe")
1977 (version (git-version "1.21.1" revision commit))
1978 (source (origin
1979 (method git-fetch)
1980 (uri (git-reference
1981 (url "https://github.com/ipxe/ipxe")
1982 (commit commit)))
1983 (file-name (git-file-name name version))
1984 (sha256
1985 (base32
1986 "0ijgc9w0az2zb5w5zlzfxjqizhx8fxc2rgq47wgbpka0ssindlvb"))))
1987 (build-system gnu-build-system)
1988 (arguments
1989 (list
1990 #:modules `((guix build utils)
1991 (guix build gnu-build-system)
1992 (guix base32)
1993 (ice-9 string-fun)
1994 (ice-9 regex)
1995 (rnrs bytevectors))
1996 #:imported-modules `((guix base32)
1997 ,@%default-gnu-imported-modules)
1998 #:make-flags
1999 ;; XXX: 'BUILD_ID' is used to determine when another ROM in the
2000 ;; system contains identical code in order to save space within the
2001 ;; legacy BIOS option ROM area, which is extremely limited in size.
2002 ;; It is supposed to be collision-free across all ROMs, to do so we
2003 ;; use the truncated output hash of the package.
2004 #~(let ((build-id
2005 (lambda (out)
2006 (let* ((nix-store (string-append
2007 (or (getenv "NIX_STORE") "/gnu/store")
2008 "/"))
2009 (filename
2010 (string-replace-substring out nix-store ""))
2011 (hash (match:substring (string-match "[0-9a-z]{32}"
2012 filename)))
2013 (bv (nix-base32-string->bytevector hash)))
2014 (format #f "0x~x"
2015 (bytevector-u32-ref bv 0 (endianness big))))))
2016 (syslinux #$(this-package-native-input "syslinux")))
2017 (list "ECHO_E_BIN_ECHO=echo"
2018 "ECHO_E_BIN_ECHO_E=echo -e"
2019
2020 ;; Build reproducibly.
2021 (string-append "BUILD_ID_CMD=echo -n " (build-id #$output))
2022 (string-append "BUILD_TIMESTAMP=" #$timestamp)
2023 "everything"))
2024 #:phases
2025 #~(modify-phases %standard-phases
2026 (add-after 'unpack 'enter-source-directory
2027 (lambda _ (chdir "src")))
2028 (add-after 'enter-source-directory 'set-version
2029 (lambda _
2030 ;; When not building from a git checkout, iPXE encodes the
2031 ;; version as "1.0.0+". Use the package version instead.
2032 (substitute* "Makefile"
2033 (("^VERSION[[:blank:]]+=.*")
2034 (string-append "VERSION = " #$(package-version this-package)
2035 "-guix\n")))))
2036 (add-after 'enter-source-directory 'set-options
2037 (lambda _
2038 (substitute* "config/general.h"
2039 (("^//(#define PING_CMD.*)" _ uncommented) uncommented)
2040 (("^//(#define IMAGE_TRUST_CMD.*)" _ uncommented)
2041 uncommented)
2042 (("^#undef.*(DOWNLOAD_PROTO_HTTPS.*)" _ option)
2043 (string-append "#define " option))
2044 (("^#undef.*(DOWNLOAD_PROTO_NFS.*)" _ option)
2045 (string-append "#define " option)))))
2046 ;; It is not entirely clear why these fail to compile.
2047 (add-after 'enter-source-directory 'skip-i386-tap-linux
2048 (lambda _
2049 (substitute* "Makefile"
2050 (("bin-i386-linux/tap.linux") "")
2051 (("bin-i386-linux/tests.linux") ""))))
2052 #$@(if (target-x86?)
2053 #~((add-after 'enter-source-directory 'set-syslinux-path
2054 ;; cdrtools' mkisofs will silently ignore a missing isolinux.bin!
2055 ;; Luckily xorriso is more strict.
2056 (lambda* (#:key inputs #:allow-other-keys)
2057 (substitute* "util/genfsimg"
2058 (("\t/usr/lib/syslinux " all)
2059 (string-append
2060 "\t" #$(this-package-native-input "syslinux")
2061 "/share/syslinux \\\n"
2062 all))))))
2063 #~())
2064 #$@(if (target-x86-32?)
2065 ;; Otherwise (u)int64 assertion failure on this arch.
2066 ;; See <https://github.com/ipxe/ipxe/issues/1506>
2067 #~((add-after 'enter-source-directory 'fix-x86-align
2068 (lambda _
2069 (setenv "HOST_EFI_CFLAGS" "-malign-double"))))
2070 #~())
2071 (delete 'configure) ; no configure script
2072 (replace 'install
2073 (lambda _
2074 (let* ((ipxe (string-append #$output "/lib/ipxe"))
2075 (exts-re
2076 "\\.(efi|efirom|iso|kkpxe|kpxe|lkrn|mrom|pxe|rom|usb)$")
2077 (dirs '("bin" "bin-i386-linux" "bin-x86_64-pcbios"
2078 "bin-x86_64-efi" "bin-x86_64-linux" "bin-i386-efi"))
2079 (files (apply append
2080 (map (lambda (dir)
2081 (find-files dir exts-re)) dirs))))
2082 (for-each (lambda (file)
2083 (let* ((subdir (dirname file))
2084 (fn (basename file))
2085 (tgtsubdir (cond
2086 ((string=? "bin" subdir) "")
2087 ((string-prefix? "bin-" subdir)
2088 (string-drop subdir 4)))))
2089 (install-file file
2090 (string-append ipxe "/" tgtsubdir))))
2091 files))))
2092 (add-after 'install 'leave-source-directory
2093 (lambda _ (chdir ".."))))
2094 #:tests? #f)) ; no test suite
2095 (native-inputs
2096 (append (if (target-x86?)
2097 ;; Syslinux only supports i686 and x86_64.
2098 (list syslinux)
2099 '())
2100 (list perl xorriso)))
2101 (home-page "https://ipxe.org")
2102 (synopsis "PXE-compliant network boot firmware")
2103 (description "iPXE is a network boot firmware. It provides a full PXE
2104implementation enhanced with additional features such as booting from: a web
2105server via HTTP, an iSCSI SAN, a Fibre Channel SAN via FCoE, an AoE SAN, a
2106wireless network, a wide-area network, an Infiniband network. It
2107controls the boot process with a script. You can use iPXE to replace the
2108existing PXE ROM on your network card, or you can chainload into iPXE to obtain
2109the features of iPXE without the hassle of reflashing.")
2110 (license license:gpl2+))))
2111
2112(define-public ipxe-qemu
2113 (package/inherit ipxe
2114 (name "ipxe-qemu")
2115 (native-inputs
2116 ;; QEMU uses a 64-bit UEFI firmware.
2117 (if (target-x86-64?)
2118 (modify-inputs native-inputs
2119 (prepend edk2-tools))
2120 (if (target-64bit?)
2121 (modify-inputs native-inputs
2122 (prepend edk2-tools
2123 (cross-gcc "x86_64-linux-gnu")
2124 (cross-binutils "x86_64-linux-gnu")))
2125 ;; Our default 32-bit binutils is not 64-bit capable.
2126 (let ((binutils-64-bit-bfd
2127 (package/inherit
2128 binutils
2129 (name "binutils-64-bit-bfd")
2130 (arguments
2131 (substitute-keyword-arguments arguments
2132 ((#:configure-flags flags ''())
2133 #~(cons* "--enable-64-bit-bfd" #$flags)))))))
2134 (modify-inputs native-inputs
2135 (prepend edk2-tools
2136 (make-ld-wrapper "ld-wrapper-64-bit-bfd"
2137 #:binutils binutils)
2138 binutils-64-bit-bfd
2139 (cross-gcc "x86_64-linux-gnu")
2140 (cross-binutils "x86_64-linux-gnu")))))))
2141 (arguments
2142 (let ((roms
2143 ;; Alist of ROM -> (VID . DID) entries. This list and below
2144 ;; build steps are taken from QEMUs roms/Makefile.
2145 '(("e1000" . ("8086" . "100e"))
2146 ("e1000e" . ("8086" . "10d3"))
2147 ("eepro100" . ("8086" . "1209"))
2148 ("ne2k_pci" . ("1050" . "0940"))
2149 ("pcnet" . ("1022" . "2000"))
2150 ("rtl8139" . ("10ec" . "8139"))
2151 ("virtio" . ("1af4" . "1000"))
2152 ("vmxnet3" . ("15ad" . "07b0")))))
2153 (substitute-keyword-arguments arguments
2154 ((#:modules modules)
2155 `((ice-9 match) ,@modules))
2156 ((#:make-flags flags)
2157 #~(append (delete "everything" #$flags)
2158 '("CONFIG=qemu"
2159 #$@(if (target-x86-64?)
2160 '()
2161 '("CROSS_COMPILE=x86_64-linux-gnu-")))
2162 (map (match-lambda
2163 ((_ . (vid . did))
2164 (string-append "bin/" vid did ".rom")))
2165 '#$roms)
2166 (map (match-lambda
2167 ((_ . (vid . did))
2168 (string-append "bin-x86_64-efi/"
2169 vid did ".efidrv")))
2170 '#$roms)))
2171 ((#:phases phases)
2172 #~(modify-phases #$phases
2173 (replace 'install
2174 (lambda _
2175 (let ((firmware (string-append #$output "/share/qemu")))
2176 (mkdir-p firmware)
2177 (for-each
2178 (match-lambda
2179 ((name . (vid . did))
2180 (let ((rom (string-append "bin/" vid did ".rom")))
2181 (copy-file rom
2182 (string-append firmware
2183 "/pxe-" name ".rom"))
2184 (invoke "EfiRom"
2185 "-b" rom
2186 "-l" "0x02"
2187 "-f" (string-append "0x" vid)
2188 "-i" (string-append "0x" did)
2189 "-ec" (string-append "bin-x86_64-efi/"
2190 vid did ".efidrv")
2191 "-o" (string-append firmware
2192 "/efi-" name ".rom")))))
2193 '#$roms)))))))))))
2194
2195(define-public refind
2196 (package
2197 (name "refind")
2198 (version "0.14.2")
2199 (source (origin
2200 (method url-fetch)
2201 (uri (string-append "mirror://sourceforge/refind/" version
2202 "/refind-src-" version ".tar.gz"))
2203 (sha256
2204 (base32
2205 "1w682p0j59apjcy26xzzhv70fyd8nqjs47i8cz2qcsx71pl3rngp"))
2206 (snippet
2207 #~(begin
2208 (use-modules (guix build utils))
2209 (delete-file-recursively
2210 "refind/tools_x64/gptsync_x64.efi")))))
2211 (build-system gnu-build-system)
2212 (outputs '("out" "doc"))
2213 (native-inputs
2214 (list binutils))
2215 (inputs
2216 (list gnu-efi-3))
2217 (arguments
2218 (list #:tests? #f ; no tests
2219 #:make-flags
2220 #~(list ;; Make build reproducible.
2221 ;; Also disables secure boot anti-rollback protection.
2222 ;; Otherwise, "objcopy --add-section" would change the
2223 ;; timestamp inside the EFI file.
2224 "OMIT_SBAT=1"
2225 (string-append "AR=" #$(ar-for-target))
2226 (string-append "CC=" #$(cc-for-target))
2227 (string-append "LD=" #$(ld-for-target))
2228 (string-append "EFIINC=" (assoc-ref %build-inputs "gnu-efi")
2229 "/include/efi")
2230 (string-append "GNUEFILIB=" (assoc-ref %build-inputs "gnu-efi")
2231 "/lib")
2232 (string-append "EFILIB=" (assoc-ref %build-inputs "gnu-efi")
2233 "/lib")
2234 (string-append "EFICRT0=" (assoc-ref %build-inputs "gnu-efi")
2235 "/lib")
2236 (string-append "OBJCOPY=" (assoc-ref %build-inputs "binutils")
2237 "/bin/objcopy"))
2238 #:phases
2239 #~(modify-phases %standard-phases
2240 (delete 'configure)
2241 (add-after 'build 'build-fs
2242 (lambda* (#:key inputs make-flags #:allow-other-keys)
2243 (apply invoke "make" "fs" make-flags)))
2244 (replace 'install
2245 (lambda* (#:key outputs #:allow-other-keys)
2246 (let* ((out-sbin (string-append #$output "/sbin"))
2247 (out-share
2248 (string-append #$output "/share/refind-"
2249 #$version))
2250 (out-share-refind
2251 (string-append out-share "/refind")))
2252 (mkdir-p out-share)
2253 (copy-recursively "banners"
2254 (string-append out-share "/banners"))
2255 (copy-recursively "fonts"
2256 (string-append out-share "/fonts"))
2257 (for-each (lambda (name)
2258 (copy-recursively name
2259 (string-append
2260 out-share-refind "/"
2261 name)))
2262 (find-files "." "^drivers_" #:directories? #t))
2263 (copy-recursively "icons"
2264 (string-append out-share-refind "/icons"))
2265 ;(copy-recursively "keys" "/etc/refind.d")
2266 (install-file "mkrlconf" out-sbin)
2267 (install-file "mvrefind" out-sbin)
2268 (install-file "refind-sb-healthcheck" out-sbin)
2269 (install-file "refind-install" out-share)
2270 (install-file "refind-mkdefault" out-sbin)
2271 (install-file "refind.conf-sample" out-share-refind)
2272 (for-each
2273 (lambda (name)
2274 (install-file name
2275 (string-append #$output "/share/man/man8")))
2276 (find-files "docs/man" "[.]8$"))
2277 (for-each (lambda (f)
2278 (install-file f out-share-refind))
2279 (find-files "refind" "refind.*\\.efi$")))))
2280 (add-after 'install 'install-doc
2281 (lambda* (#:key outputs #:allow-other-keys)
2282 (let* ((out-doc
2283 (string-append #$output:doc "/share/doc/refind-"
2284 #$version)))
2285 (copy-recursively "docs/refind"
2286 (string-append out-doc "/refind"))
2287 (copy-recursively "docs/Styles"
2288 (string-append out-doc "/Styles"))))))))
2289 (synopsis "rEFInd boot manager")
2290 (description "This package provides a boot manager that is an EFI
2291program.")
2292 (home-page "https://www.rodsbooks.com/refind/")
2293 (license license:gpl3+)))