1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2015, 2018 Mark H Weaver <mhw@netris.org>
4 ;;; Copyright © 2015 Leo Famulari <leo@famulari.name>
5 ;;; Copyright © 2016, 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
6 ;;; Copyright © 2016, 2017, 2018 Marius Bakke <mbakke@fastmail.com>
7 ;;; Copyright © 2016, 2017 Danny Milosavljevic <dannym@scratchpost.org>
8 ;;; Copyright © 2016, 2017 David Craven <david@craven.ch>
9 ;;; Copyright © 2017, 2018, 2020 Efraim Flashner <efraim@flashner.co.il>
10 ;;; Copyright © 2018, 2019, 2020, 2021 Tobias Geerinckx-Rice <me@tobias.gr>
11 ;;; Copyright © 2019 nee <nee@cock.li>
12 ;;; Copyright © 2019 Mathieu Othacehe <m.othacehe@gmail.com>
13 ;;; Copyright © 2020 Björn Höfling <bjoern.hoefling@bjoernhoefling.de>
14 ;;; Copyright © 2018, 2019, 2020 Vagrant Cascadian <vagrant@debian.org>
15 ;;; Copyright © 2020 Pierre Langlois <pierre.langlois@gmx.com>
16 ;;; Copyright © 2021 Vincent Legoll <vincent.legoll@gmail.com>
17 ;;; Copyright © 2021 Brice Waegeneire <brice@waegenei.re>
19 ;;; This file is part of GNU Guix.
21 ;;; GNU Guix is free software; you can redistribute it and/or modify it
22 ;;; under the terms of the GNU General Public License as published by
23 ;;; the Free Software Foundation; either version 3 of the License, or (at
24 ;;; your option) any later version.
26 ;;; GNU Guix is distributed in the hope that it will be useful, but
27 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
28 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 ;;; GNU General Public License for more details.
31 ;;; You should have received a copy of the GNU General Public License
32 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
34 (define-module (gnu packages bootloaders)
35 #:use-module (gnu packages)
36 #:use-module (gnu packages admin)
37 #:use-module (gnu packages algebra)
38 #:use-module (gnu packages assembly)
39 #:use-module (gnu packages base)
40 #:use-module (gnu packages disk)
41 #:use-module (gnu packages bison)
42 #:use-module (gnu packages cdrom)
43 #:use-module (gnu packages check)
44 #:use-module (gnu packages compression)
45 #:use-module (gnu packages cross-base)
46 #:use-module (gnu packages disk)
47 #:use-module (gnu packages firmware)
48 #:use-module (gnu packages flex)
49 #:use-module (gnu packages fontutils)
50 #:use-module (gnu packages gcc)
51 #:use-module (gnu packages gettext)
52 #:use-module (gnu packages linux)
53 #:use-module (gnu packages man)
54 #:use-module (gnu packages mtools)
55 #:use-module (gnu packages ncurses)
56 #:use-module (gnu packages perl)
57 #:use-module (gnu packages pkg-config)
58 #:use-module (gnu packages python)
59 #:use-module (gnu packages texinfo)
60 #:use-module (gnu packages tls)
61 #:use-module (gnu packages sdl)
62 #:use-module (gnu packages swig)
63 #:use-module (gnu packages valgrind)
64 #:use-module (gnu packages virtualization)
65 #:use-module (gnu packages xorg)
66 #:use-module (gnu packages web)
67 #:use-module (guix build-system gnu)
68 #:use-module (guix download)
69 #:use-module (guix git-download)
70 #:use-module ((guix licenses) #:prefix license:)
71 #:use-module (guix packages)
72 #:use-module (guix utils)
73 #:use-module (srfi srfi-1)
74 #:use-module (srfi srfi-26)
75 #:use-module (ice-9 regex))
78 ;; GNU Unifont, <http://gnu.org/s/unifont>.
79 ;; GRUB needs it for its graphical terminal, gfxterm.
83 "http://unifoundry.com/pub/unifont-7.0.06/font-builds/unifont-7.0.06.bdf.gz")
86 "0p2vhnc18cnbmb39vq4m7hzv4mhnm2l0a2s7gx3ar277fwng3hys"))))
94 (uri (string-append "mirror://gnu/grub/grub-" version ".tar.xz"))
97 "0zgp5m3hmc9jh8wpjx6czzkh5id2y8n1k823x2mjvm2sk6b28ag5"))
98 (patches (search-patches
99 "grub-efi-fat-serial-number.patch"
100 "grub-setup-root.patch"
101 "grub-verifiers-Blocklist-fallout-cleanup.patch"
102 "grub-cross-system-i686.patch"))))
103 (build-system gnu-build-system)
106 ;; Counterintuitively, this *disables* a spurious Python dependency by
107 ;; calling the ‘true’ binary instead. Python is only needed during
108 ;; bootstrapping (for genptl.py), not when building from a release.
110 #:phases (modify-phases %standard-phases
111 (add-after 'unpack 'patch-stuff
112 (lambda* (#:key native-inputs inputs #:allow-other-keys)
113 (substitute* "grub-core/Makefile.in"
114 (("/bin/sh") (which "sh")))
116 ;; Give the absolute file name of 'mdadm', used to
117 ;; determine the root file system when it's a RAID
118 ;; device. Failing to do that, 'grub-probe' silently
119 ;; fails if 'mdadm' is not in $PATH.
120 (when (assoc-ref inputs "mdadm")
121 (substitute* "grub-core/osdep/linux/getroot.c"
122 (("argv\\[0\\] = \"mdadm\"")
123 (string-append "argv[0] = \""
124 (assoc-ref inputs "mdadm")
127 ;; Make the font visible.
128 (copy-file (assoc-ref (or native-inputs inputs)
131 (system* "gunzip" "unifont.bdf.gz")
133 ;; Give the absolute file name of 'ckbcomp'.
134 (substitute* "util/grub-kbdcomp.in"
136 (string-append (assoc-ref inputs "console-setup")
139 (add-after 'unpack 'set-freetype-variables
140 ;; These variables need to be set to the native versions
141 ;; of the dependencies because they are used to build
142 ;; programs which are executed during build time.
143 (lambda* (#:key native-inputs #:allow-other-keys)
144 (when (assoc-ref native-inputs "freetype")
145 (let ((freetype (assoc-ref native-inputs "freetype")))
146 (setenv "BUILD_FREETYPE_LIBS"
147 (string-append "-L" freetype
149 (setenv "BUILD_FREETYPE_CFLAGS"
150 (string-append "-I" freetype
151 "/include/freetype2"))))
153 (add-before 'check 'disable-flaky-test
155 ;; This test is unreliable. For more information, see:
156 ;; <https://bugs.gnu.org/26936>.
157 (substitute* "Makefile.in"
158 (("grub_cmd_date grub_cmd_set_date grub_cmd_sleep")
159 "grub_cmd_date grub_cmd_sleep"))
161 (add-before 'check 'disable-pixel-perfect-test
163 ;; This test compares many screenshots rendered with an
164 ;; older Unifont (9.0.06) than that packaged in Guix.
165 (substitute* "Makefile.in"
166 (("test_unset grub_func_test")
169 ;; Disable tests on ARM and AARCH64 platforms or when cross-compiling.
170 #:tests? ,(not (or (any (cute string-prefix? <> (or (%current-target-system)
173 (%current-target-system)))))
175 `(("gettext" ,gettext-minimal)
177 ;; Depend on LVM2 for libdevmapper, used by 'grub-probe' and
178 ;; 'grub-install' to recognize mapped devices (LUKS, etc.)
179 ,@(if (member (or (%current-target-system)
181 (package-supported-systems lvm2))
185 ;; Depend on mdadm, which is invoked by 'grub-probe' and 'grub-install'
186 ;; to determine whether the root file system is RAID.
187 ,@(if (member (or (%current-target-system)
189 (package-supported-systems mdadm))
193 ;; Console-setup's ckbcomp is invoked by grub-kbdcomp. It is required
194 ;; for generating alternative keyboard layouts.
195 ("console-setup" ,console-setup)
197 ;; Needed for ‘grub-mount’, the only reliable way to tell whether a given
198 ;; file system will be readable by GRUB without rebooting.
199 ,@(if (member (or (%current-target-system)
201 (package-supported-systems fuse))
205 ("freetype" ,freetype)
206 ;; ("libusb" ,libusb)
207 ("ncurses" ,ncurses)))
209 `(("pkg-config" ,pkg-config)
214 ("help2man" ,help2man)
215 ("freetype" ,freetype) ; native version needed for build-grub-mkfont
217 ;; XXX: When building GRUB 2.02 on 32-bit x86, we need a binutils
218 ;; capable of assembling 64-bit instructions. However, our default
219 ;; binutils on 32-bit x86 is not 64-bit capable.
220 ,@(if (string-match "^i[3456]86-" (%current-system))
221 (let ((binutils (package/inherit
223 (name "binutils-i386")
225 (substitute-keyword-arguments (package-arguments binutils)
226 ((#:configure-flags flags ''())
227 `(cons "--enable-64-bit-bfd" ,flags)))))))
228 `(("ld-wrapper" ,(make-ld-wrapper "ld-wrapper-i386"
229 #:binutils binutils))
230 ("binutils" ,binutils)))
233 ;; Dependencies for the test suite. The "real" QEMU is needed here,
234 ;; because several targets are used.
236 ,@(if (member (%current-system) (package-supported-systems qemu-minimal))
237 `(("qemu" ,qemu-minimal))
239 ("xorriso" ,xorriso)))
240 (home-page "https://www.gnu.org/software/grub/")
241 (synopsis "GRand Unified Boot loader")
243 "GRUB is a multiboot bootloader. It is used for initially loading the
244 kernel of an operating system and then transferring control to it. The kernel
245 then goes on to load the rest of the operating system. As a multiboot
246 bootloader, GRUB handles the presence of multiple operating systems installed
247 on the same computer; upon booting the computer, the user is presented with a
248 menu to select one of the installed operating systems.")
249 (license license:gpl3+)
250 (properties '((cpe-name . "grub2")))))
252 (define-public grub-minimal
255 (name "grub-minimal")
257 (fold alist-delete (package-inputs grub)
258 '("lvm2" "mdadm" "fuse" "console-setup")))
260 (fold alist-delete (package-native-inputs grub)
261 '("help2man" "texinfo" "parted" "qemu" "xorriso")))
263 (substitute-keyword-arguments (package-arguments grub)
264 ((#:configure-flags _ ''())
265 '(list "PYTHON=true"))
268 ((#:phases phases '%standard-phases)
269 `(modify-phases ,phases
270 (replace 'patch-stuff
271 (lambda* (#:key native-inputs inputs #:allow-other-keys)
272 (substitute* "grub-core/Makefile.in"
273 (("/bin/sh") (which "sh")))
275 ;; Make the font visible.
276 (copy-file (assoc-ref (or native-inputs inputs)
279 (system* "gunzip" "unifont.bdf.gz")
283 (define-public grub-efi
287 (synopsis "GRand Unified Boot loader (UEFI version)")
289 `(("efibootmgr" ,efibootmgr)
291 ,@(package-inputs grub)))
293 `(;; TODO: Tests need a UEFI firmware for qemu. There is one at
294 ;; https://github.com/tianocore/edk2/tree/master/OvmfPkg .
295 ;; Search for 'OVMF' in "tests/util/grub-shell.in".
296 ,@(substitute-keyword-arguments (package-arguments grub)
298 ((#:configure-flags flags ''())
299 `(cons "--with-platform=efi" ,flags))
301 `(modify-phases ,phases
302 (add-after 'patch-stuff 'use-absolute-efibootmgr-path
303 (lambda* (#:key inputs #:allow-other-keys)
304 (substitute* "grub-core/osdep/unix/platform.c"
306 (string-append (assoc-ref inputs "efibootmgr")
307 "/sbin/efibootmgr")))
309 (add-after 'patch-stuff 'use-absolute-mtools-path
310 (lambda* (#:key inputs #:allow-other-keys)
311 (let ((mtools (assoc-ref inputs "mtools")))
312 (substitute* "util/grub-mkrescue.c"
314 (string-append "\"" mtools
316 (substitute* "util/grub-mkrescue.c"
318 (string-append "\"" mtools
322 ;; Because grub searches hardcoded paths it's easiest to just build grub
323 ;; again to make it find both grub-pc and grub-efi. There is a command
324 ;; line argument which allows you to specify ONE platform - but
325 ;; grub-mkrescue will use multiple platforms if they are available
326 ;; in the installation directory (without command line argument).
327 (define-public grub-hybrid
331 (synopsis "GRand Unified Boot loader (hybrid version)")
334 ,@(package-inputs grub-efi)))
336 (substitute-keyword-arguments (package-arguments grub-efi)
337 ((#:modules modules `((guix build utils) (guix build gnu-build-system)))
338 `((ice-9 ftw) ,@modules))
340 `(modify-phases ,phases
341 (add-after 'install 'install-non-efi
342 (lambda* (#:key inputs outputs #:allow-other-keys)
343 (let ((input-dir (string-append (assoc-ref inputs "grub")
345 (output-dir (string-append (assoc-ref outputs "out")
349 (if (not (or (string-prefix? "." basename)
350 (file-exists? (string-append output-dir "/" basename))))
351 (symlink (string-append input-dir "/" basename)
352 (string-append output-dir "/" basename))))
356 (define-public syslinux
357 (let ((commit "bb41e935cc83c6242de24d2271e067d76af3585c"))
360 (version (git-version "6.04-pre" "1" commit))
364 (url "https://github.com/geneC/syslinux")
366 (file-name (git-file-name name version))
369 "0k8dvafd6410kqxf3kyr4y8jzmpmrih6wbjqg6gklak7945yflrc"))))
370 (build-system gnu-build-system)
374 ("python-2" ,python-2)))
376 `(("libuuid" ,util-linux "lib")
379 `(#:parallel-build? #f
381 (list (string-append "BINDIR=" %output "/bin")
382 (string-append "SBINDIR=" %output "/sbin")
383 (string-append "LIBDIR=" %output "/lib")
384 (string-append "INCDIR=" %output "/include")
385 (string-append "DATADIR=" %output "/share")
386 (string-append "MANDIR=" %output "/share/man")
390 (modify-phases %standard-phases
391 (add-after 'unpack 'patch-files
392 (lambda* (#:key inputs #:allow-other-keys)
393 (substitute* (find-files "." "Makefile.*|ppmtolss16")
394 (("/bin/pwd") (which "pwd"))
395 (("/bin/echo") (which "echo"))
396 (("/usr/bin/perl") (which "perl")))
397 (let ((mtools (assoc-ref inputs "mtools")))
398 (substitute* (find-files "." "\\.c$")
400 (string-append mtools "/bin/mcopy"))
402 (string-append mtools "/bin/mattrib"))))
405 (add-before 'build 'set-permissions
407 (invoke "chmod" "a+w" "utils/isohybrid.in")))
411 (substitute* "tests/unittest/include/unittest/unittest.h"
412 ;; Don't look up headers under /usr.
413 (("/usr/include/") ""))
414 (invoke "make" "unittest"))))))
415 (home-page "https://www.syslinux.org")
416 (synopsis "Lightweight Linux bootloader")
417 (description "Syslinux is a lightweight Linux bootloader.")
418 ;; The Makefile specifically targets i386 and x86_64 using nasm.
419 (supported-systems '("i686-linux" "x86_64-linux"))
420 (license (list license:gpl2+
421 license:bsd-3 ; gnu-efi/*
422 license:bsd-4 ; gnu-efi/inc/* gnu-efi/lib/*
424 license:expat license:isc license:zlib)))))
433 "mirror://kernel.org/software/utils/dtc/"
434 "dtc-" version ".tar.xz"))
437 "0bf8801z6fpd1gz9mxd5pqqj8nq101x393cyw8rpkc712w13nl0h"))))
438 (build-system gnu-build-system)
443 ("pkg-config" ,pkg-config)
445 ("valgrind" ,valgrind)))
447 `(("python" ,python)))
450 (list (string-append "CC=" ,(cc-for-target))
452 ;; /bin/fdt{get,overlay,put} need help finding libfdt.so.1.
453 (string-append "LDFLAGS=-Wl,-rpath="
454 (assoc-ref %outputs "out") "/lib")
456 (string-append "PREFIX=" (assoc-ref %outputs "out"))
457 (string-append "SETUP_PREFIX=" (assoc-ref %outputs "out"))
460 (modify-phases %standard-phases
461 (add-after 'unpack 'patch-pkg-config
463 (substitute* '("Makefile"
464 "tests/run_tests.sh")
466 (or (which "pkg-config")
467 (string-append ,(%current-target-system)
470 (delete 'configure)))) ; no configure script
471 (home-page "https://www.devicetree.org")
472 (synopsis "Compiles device tree source files")
473 (description "@command{dtc} compiles
474 @uref{http://elinux.org/Device_Tree_Usage, device tree source files} to device
475 tree binary files. These are board description files used by Linux and BSD.")
476 (license license:gpl2+)))
485 "https://ftp.denx.de/pub/u-boot/"
486 "u-boot-" version ".tar.bz2"))
489 "06p1vymf0dl6jc2xy5w7p42mpgppa46lmpm2ishmgsycnldqnhqd"))))
498 ("python-coverage" ,python-coverage)
499 ("python-pytest" ,python-pytest)
501 (build-system gnu-build-system)
502 (home-page "https://www.denx.de/wiki/U-Boot/")
503 (synopsis "ARM bootloader")
504 (description "U-Boot is a bootloader used mostly for ARM boards. It
505 also initializes the boards (RAM etc).")
506 (license license:gpl2+)))
508 (define-public u-boot-tools
511 (name "u-boot-tools")
514 ,@(package-native-inputs u-boot)))
516 `(#:make-flags '("HOSTCC=gcc")
517 #:test-target "tcheck"
519 (modify-phases %standard-phases
520 (add-after 'unpack 'patch
521 (lambda* (#:key inputs #:allow-other-keys)
522 (substitute* "Makefile"
523 (("/bin/pwd") (which "pwd"))
524 (("/bin/false") (which "false")))
525 (substitute* "tools/dtoc/fdt_util.py"
527 (substitute* "tools/patman/test_util.py"
528 ;; python3-coverage is simply called coverage in guix.
529 (("python3-coverage") "coverage"))
530 (substitute* "test/run"
531 ;; Make it easier to find test failures.
532 (("#!/bin/bash") "#!/bin/bash -x")
533 ;; This test would require git.
534 (("\\./tools/patman/patman") (which "true"))
535 ;; FIXME: test fails, needs further investiation
536 (("run_test \"binman\"") ": run_test \"binman\"")
537 ;; FIXME: code coverage not working
538 (("run_test \"binman code coverage\"") ": run_test \"binman code coverage\"")
539 ;; This test would require internet access.
540 (("\\./tools/buildman/buildman") (which "true")))
541 (substitute* "test/py/tests/test_sandbox_exit.py"
543 "@pytest.mark.skip(reason='Guix has problems with SIGINT')
545 ;; Test against the tools being installed rather than tools built
546 ;; for "sandbox" target.
547 (substitute* "test/image/test-imagetools.sh"
548 (("BASEDIR=sandbox") "BASEDIR=."))
549 (for-each (lambda (file)
551 ;; Disable features that require OpenSSL due
552 ;; to GPL/Openssl license incompatibilities.
553 ;; See https://bugs.gnu.org/34717 for
555 (("CONFIG_FIT_SIGNATURE=y")
556 "CONFIG_FIT_SIGNATURE=n\nCONFIG_UT_LIB_ASN1=n")
557 ;; This test requires a sound system, which is un-used
559 (("CONFIG_SOUND=y") "CONFIG_SOUND=n")))
560 (find-files "configs" "sandbox_.*defconfig$|tools-only_defconfig"))
563 (lambda* (#:key make-flags #:allow-other-keys)
564 (apply invoke "make" "tools-only_defconfig" make-flags)))
566 (lambda* (#:key inputs make-flags #:allow-other-keys)
567 (apply invoke "make" "tools-all" make-flags)))
569 (lambda* (#:key outputs #:allow-other-keys)
570 (let* ((out (assoc-ref outputs "out"))
571 (bin (string-append out "/bin")))
572 (for-each (lambda (name)
573 (install-file name bin))
577 "tools/gen_ethaddr_crc"
584 "tools/env/fw_printenv"
585 "tools/sunxi-spl-image-builder"))
588 (add-after 'install 'check
589 (lambda* (#:key make-flags test-target #:allow-other-keys)
590 (invoke "test/image/test-imagetools.sh")))
591 ;; Only run full test suite on x86_64 systems, as many tests
593 ,@(if (string-match "^x86_64-linux"
594 (or (%current-target-system)
596 '((add-after 'check 'check-x86
597 (lambda* (#:key make-flags test-target #:allow-other-keys)
598 (apply invoke "make" "mrproper" make-flags)
599 (setenv "SDL_VIDEODRIVER" "dummy")
600 (setenv "PAGER" "cat")
601 (apply invoke "make" test-target make-flags))))
603 (description "U-Boot is a bootloader used mostly for ARM boards. It
604 also initializes the boards (RAM etc). This package provides its
605 board-independent tools.")))
607 (define-public (make-u-boot-package board triplet)
608 "Returns a u-boot package for BOARD cross-compiled for TRIPLET."
609 (let ((same-arch? (lambda ()
610 (string=? (%current-system)
611 (gnu-triplet->nix-system triplet)))))
614 (name (string-append "u-boot-"
615 (string-replace-substring (string-downcase board)
618 `(,@(if (not (same-arch?))
619 `(("cross-gcc" ,(cross-gcc triplet))
620 ("cross-binutils" ,(cross-binutils triplet)))
622 ,@(package-native-inputs u-boot)))
624 `(#:modules ((ice-9 ftw)
627 (guix build gnu-build-system))
631 ,@(if (not (same-arch?))
632 `((string-append "CROSS_COMPILE=" ,triplet "-"))
635 (modify-phases %standard-phases
637 (lambda* (#:key outputs make-flags #:allow-other-keys)
638 (let ((config-name (string-append ,board "_defconfig")))
639 (if (file-exists? (string-append "configs/" config-name))
640 (apply invoke "make" `(,@make-flags ,config-name))
642 (display "Invalid board name. Valid board names are:"
643 (current-error-port))
644 (let ((suffix-len (string-length "_defconfig"))
645 (entries (scandir "configs")))
646 (for-each (lambda (file-name)
647 (when (string-suffix? "_defconfig" file-name)
648 (format (current-error-port)
650 (string-drop-right file-name
652 (sort entries string-ci<)))
653 (error "Invalid boardname ~s." ,board))))))
655 (lambda* (#:key outputs #:allow-other-keys)
656 (let* ((out (assoc-ref outputs "out"))
657 (libexec (string-append out "/libexec"))
660 ;; Those would not be reproducible
661 ;; because of the randomness used
663 ;; It's expected that the user will
664 ;; use u-boot-tools to generate them
668 "sunxi-spl-with-ecc.bin"
670 (find-files "." ".*\\.(bin|efi|img|spl|itb|dtb|rksd)$"))
671 (find-files "." "^(MLO|SPL)$"))))
673 (install-file ".config" libexec)
674 ;; Useful for "qemu -kernel".
675 (install-file "u-boot" libexec)
678 (let ((target-file (string-append libexec "/" file)))
679 (mkdir-p (dirname target-file))
680 (copy-file file target-file)))
684 (define-public u-boot-vexpress
685 (make-u-boot-package "vexpress_ca9x4" "arm-linux-gnueabihf"))
687 (define-public u-boot-malta
688 (make-u-boot-package "malta" "mips64el-linux-gnuabi64"))
690 (define-public u-boot-am335x-boneblack
691 (let ((base (make-u-boot-package "am335x_evm" "arm-linux-gnueabihf")))
694 (name "u-boot-am335x-boneblack")
695 (description "U-Boot is a bootloader used mostly for ARM boards. It
696 also initializes the boards (RAM etc).
698 This U-Boot is built for the BeagleBone Black, which was removed upstream,
699 adjusted from the am335x_evm build with several device trees removed so that
700 it fits within common partitioning schemes.")
702 (substitute-keyword-arguments (package-arguments base)
704 `(modify-phases ,phases
705 (add-after 'unpack 'patch-defconfig
706 ;; Patch out other devicetrees to build image small enough to
707 ;; fit within typical partitioning schemes where the first
708 ;; partition begins at sector 2048.
710 (substitute* "configs/am335x_evm_defconfig"
711 (("CONFIG_OF_LIST=.*$") "CONFIG_OF_LIST=\"am335x-evm am335x-boneblack\"\n"))
714 (define-public u-boot-am335x-evm
715 (make-u-boot-package "am335x_evm" "arm-linux-gnueabihf"))
717 (define-public (make-u-boot-sunxi64-package board triplet)
718 (let ((base (make-u-boot-package board triplet)))
722 (substitute-keyword-arguments (package-arguments base)
724 `(modify-phases ,phases
725 (add-after 'unpack 'set-environment
726 (lambda* (#:key native-inputs inputs #:allow-other-keys)
729 (assoc-ref (or native-inputs inputs) "firmware")
732 ;; This is necessary when we're using the bundled dtc.
733 ;(setenv "PATH" (string-append (getenv "PATH") ":"
738 `(("firmware" ,arm-trusted-firmware-sun50i-a64)
739 ,@(package-native-inputs base))))))
741 (define-public u-boot-pine64-plus
742 (make-u-boot-sunxi64-package "pine64_plus" "aarch64-linux-gnu"))
744 (define-public u-boot-pine64-lts
745 (make-u-boot-sunxi64-package "pine64-lts" "aarch64-linux-gnu"))
747 (define-public u-boot-pinebook
748 (let ((base (make-u-boot-sunxi64-package "pinebook" "aarch64-linux-gnu")))
752 (substitute-keyword-arguments (package-arguments base)
754 `(modify-phases ,phases
755 (add-after 'unpack 'patch-pinebook-config
756 ;; Fix regression with LCD video output introduced in 2020.01
757 ;; https://patchwork.ozlabs.org/patch/1225130/
759 (substitute* "configs/pinebook_defconfig"
760 (("CONFIG_VIDEO_BRIDGE_ANALOGIX_ANX6345=y") "CONFIG_VIDEO_BRIDGE_ANALOGIX_ANX6345=y\nCONFIG_VIDEO_BPP32=y"))
763 (define-public u-boot-bananapi-m2-ultra
764 (make-u-boot-package "Bananapi_M2_Ultra" "arm-linux-gnueabihf"))
766 (define-public u-boot-a20-olinuxino-lime
767 (make-u-boot-package "A20-OLinuXino-Lime" "arm-linux-gnueabihf"))
769 (define-public u-boot-a20-olinuxino-lime2
770 (make-u-boot-package "A20-OLinuXino-Lime2" "arm-linux-gnueabihf"))
772 (define-public u-boot-a20-olinuxino-micro
773 (make-u-boot-package "A20-OLinuXino_MICRO" "arm-linux-gnueabihf"))
775 (define-public u-boot-nintendo-nes-classic-edition
776 (make-u-boot-package "Nintendo_NES_Classic_Edition" "arm-linux-gnueabihf"))
778 (define-public u-boot-wandboard
779 (make-u-boot-package "wandboard" "arm-linux-gnueabihf"))
781 (define-public u-boot-mx6cuboxi
782 (make-u-boot-package "mx6cuboxi" "arm-linux-gnueabihf"))
784 (define-public u-boot-novena
785 (let ((base (make-u-boot-package "novena" "arm-linux-gnueabihf")))
788 (description "U-Boot is a bootloader used mostly for ARM boards. It
789 also initializes the boards (RAM etc).
791 This U-Boot is built for Novena. Be advised that this version, contrary
792 to Novena upstream, does not load u-boot.img from the first partition.")
794 (substitute-keyword-arguments (package-arguments base)
796 `(modify-phases ,phases
797 (add-after 'unpack 'patch-novena-defconfig
798 ;; Patch configuration to disable loading u-boot.img from FAT partition,
799 ;; allowing it to be installed at a device offset.
801 (substitute* "configs/novena_defconfig"
802 (("CONFIG_SPL_FS_FAT=y") "# CONFIG_SPL_FS_FAT is not set"))
805 (define-public u-boot-cubieboard
806 (make-u-boot-package "Cubieboard" "arm-linux-gnueabihf"))
808 (define-public u-boot-cubietruck
809 (make-u-boot-package "Cubietruck" "arm-linux-gnueabihf"))
811 (define-public u-boot-puma-rk3399
812 (let ((base (make-u-boot-package "puma-rk3399" "aarch64-linux-gnu")))
816 (substitute-keyword-arguments (package-arguments base)
818 `(modify-phases ,phases
819 (add-after 'unpack 'set-environment
820 (lambda* (#:key inputs #:allow-other-keys)
821 (setenv "BL31" (string-append (assoc-ref inputs "firmware")
824 ;; Phases do not succeed on the bl31 ELF.
826 (delete 'validate-runpath)))))
828 `(("firmware" ,arm-trusted-firmware-rk3399)
829 ,@(package-native-inputs base))))))
831 (define-public u-boot-qemu-riscv64
832 (make-u-boot-package "qemu-riscv64" "riscv64-linux-gnu"))
834 (define-public u-boot-qemu-riscv64-smode
835 (let ((base (make-u-boot-package "qemu-riscv64_smode" "riscv64-linux-gnu")))
839 (inherit (package-source u-boot))
841 (search-patches "u-boot-riscv64-fix-extlinux.patch")))))))
843 (define-public u-boot-sifive-fu540
844 (make-u-boot-package "sifive_fu540" "riscv64-linux-gnu"))
846 (define-public u-boot-rock64-rk3328
847 (let ((base (make-u-boot-package "rock64-rk3328" "aarch64-linux-gnu")))
851 (substitute-keyword-arguments (package-arguments base)
853 `(modify-phases ,phases
854 (add-after 'unpack 'set-environment
855 (lambda* (#:key inputs #:allow-other-keys)
856 (let ((bl31 (string-append (assoc-ref inputs "firmware")
858 (setenv "BL31" bl31))
861 `(("firmware" ,arm-trusted-firmware-rk3328)
862 ,@(package-native-inputs base))))))
864 (define-public u-boot-firefly-rk3399
865 (let ((base (make-u-boot-package "firefly-rk3399" "aarch64-linux-gnu")))
869 (substitute-keyword-arguments (package-arguments base)
871 `(modify-phases ,phases
872 (add-after 'unpack 'set-environment
873 (lambda* (#:key inputs #:allow-other-keys)
874 (setenv "BL31" (string-append (assoc-ref inputs "firmware")
877 ;; Phases do not succeed on the bl31 ELF.
879 (delete 'validate-runpath)))))
881 `(("firmware" ,arm-trusted-firmware-rk3399)
882 ,@(package-native-inputs base))))))
884 (define-public u-boot-rockpro64-rk3399
885 (let ((base (make-u-boot-package "rockpro64-rk3399" "aarch64-linux-gnu")))
889 (substitute-keyword-arguments (package-arguments base)
891 `(modify-phases ,phases
892 (add-after 'unpack 'patch-rockpro64-config
893 ;; Fix regression in 2020.10 causing freezes on boot with USB boot enabled.
894 ;; See https://gitlab.manjaro.org/manjaro-arm/packages/core/uboot-rockpro64/-/issues/4
896 (substitute* "configs/rockpro64-rk3399_defconfig"
897 (("CONFIG_USE_PREBOOT=y") "CONFIG_USE_PREBOOT=n"))
899 (add-after 'patch-rockpro64-config 'set-environment
900 (lambda* (#:key inputs #:allow-other-keys)
901 (setenv "BL31" (string-append (assoc-ref inputs "firmware")
904 ;; Phases do not succeed on the bl31 ELF.
906 (delete 'validate-runpath)))))
908 `(("firmware" ,arm-trusted-firmware-rk3399)
909 ,@(package-native-inputs base))))))
911 (define-public u-boot-pinebook-pro-rk3399
912 (let ((base (make-u-boot-package "pinebook-pro-rk3399" "aarch64-linux-gnu")))
916 (substitute-keyword-arguments (package-arguments base)
918 `(modify-phases ,phases
919 (add-after 'unpack 'patch-pinebook-pro-config
920 ;; Fix regression in 2020.10 causing freezes on boot with USB boot enabled.
921 ;; See https://gitlab.manjaro.org/manjaro-arm/packages/core/uboot-rockpro64/-/issues/4
923 (substitute* "configs/pinebook-pro-rk3399_defconfig"
924 (("CONFIG_USE_PREBOOT=y") "CONFIG_USE_PREBOOT=n"))
926 (add-after 'unpack 'set-environment
927 (lambda* (#:key inputs #:allow-other-keys)
928 (setenv "BL31" (string-append (assoc-ref inputs "firmware")
931 ;; Phases do not succeed on the bl31 ELF.
933 (delete 'validate-runpath)))))
935 `(("firmware" ,arm-trusted-firmware-rk3399)
936 ,@(package-native-inputs base))))))
938 (define-public vboot-utils
941 (version "R63-10032.B")
943 ;; XXX: Snapshots are available but changes timestamps every download.
946 (url (string-append "https://chromium.googlesource.com"
947 "/chromiumos/platform/vboot_reference"))
948 (commit (string-append "release-" version))))
949 (file-name (string-append name "-" version "-checkout"))
952 "0h0m3l69vp9dr6xrs1p6y7ilkq3jq8jraw2z20kqfv7lvc9l1lxj"))
954 (search-patches "vboot-utils-skip-test-workbuf.patch"
955 "vboot-utils-fix-tests-show-contents.patch"
956 "vboot-utils-fix-format-load-address.patch"))))
957 (build-system gnu-build-system)
959 `(#:make-flags (list "CC=gcc"
960 ;; On ARM, we must pass "HOST_ARCH=arm" so that the
961 ;; ${HOST_ARCH} and ${ARCH} variables in the makefile
962 ;; match. Otherwise, ${HOST_ARCH} will be assigned
963 ;; "armv7l", the value of `uname -m`, and will not
964 ;; match ${ARCH}, which will make the tests require
966 ,@(if (string-prefix? "arm"
967 (or (%current-target-system)
971 (string-append "DESTDIR=" (assoc-ref %outputs "out")))
972 #:phases (modify-phases %standard-phases
973 (add-after 'unpack 'patch-hard-coded-paths
974 (lambda* (#:key inputs outputs #:allow-other-keys)
975 (let ((coreutils (assoc-ref inputs "coreutils"))
976 (diffutils (assoc-ref inputs "diffutils")))
977 (substitute* "futility/misc.c"
978 (("/bin/cp") (string-append coreutils "/bin/cp")))
979 (substitute* "tests/bitmaps/TestBmpBlock.py"
980 (("/usr/bin/cmp") (string-append diffutils "/bin/cmp")))
981 (substitute* "vboot_host.pc.in"
983 (string-append "prefix=" (assoc-ref outputs "out"))))
986 (add-before 'check 'patch-tests
988 ;; These tests compare diffs against known-good values.
989 ;; Patch the paths to match those in the build container.
990 (substitute* (find-files "tests/futility/expect_output")
991 (("/mnt/host/source/src/platform/vboot_reference")
992 (string-append "/tmp/guix-build-" ,name "-" ,version
994 ;; Tests require write permissions to many of these files.
995 (for-each make-file-writable (find-files "tests/futility"))
997 (add-after 'install 'install-devkeys
998 (lambda* (#:key outputs #:allow-other-keys)
999 (let* ((out (assoc-ref outputs "out"))
1000 (share (string-append out "/share/vboot-utils")))
1001 (copy-recursively "tests/devkeys"
1002 (string-append share "/devkeys"))
1004 #:test-target "runtests"))
1006 `(("pkg-config" ,pkg-config)
1009 ("diffutils" ,diffutils)
1010 ("python@2" ,python-2)))
1012 `(("coreutils" ,coreutils)
1013 ("libyaml" ,libyaml)
1014 ("openssl" ,openssl)
1015 ("openssl:static" ,openssl "static")
1016 ("util-linux" ,util-linux "lib")))
1018 "https://dev.chromium.org/chromium-os/chromiumos-design-docs/verified-boot")
1019 (synopsis "ChromiumOS verified boot utilities")
1021 "vboot-utils is a collection of tools to facilitate booting of
1022 Chrome-branded devices. This includes the @command{cgpt} partitioning
1023 program, the @command{futility} and @command{crossystem} firmware management
1025 (license license:bsd-3)))
1027 (define-public os-prober
1034 (uri (string-append "mirror://debian/pool/main/o/os-prober/os-prober_"
1037 (base32 "1sahk72blsrlirly4xlwa8jfxrpwagyn7b81p92q2s9m218rz43f"))))
1038 (build-system gnu-build-system)
1040 `(#:modules ((guix build gnu-build-system)
1042 (ice-9 regex) ; for string-match
1043 (srfi srfi-26)) ; for cut
1045 (list ,(string-append "CC=" (cc-for-target)))
1046 #:tests? #f ; no tests
1048 (modify-phases %standard-phases
1050 (lambda* (#:key outputs #:allow-other-keys)
1051 (substitute* (find-files ".")
1052 (("/usr") (assoc-ref outputs "out")))
1053 (substitute* (find-files "." "50mounted-tests$")
1054 (("mkdir") "mkdir -p"))
1057 (lambda* (#:key outputs #:allow-other-keys)
1058 (define (find-files-non-recursive directory)
1059 (find-files directory
1061 (string-match (string-append "^" directory "/[^/]*$")
1065 (let* ((out (assoc-ref outputs "out"))
1066 (bin (string-append out "/bin"))
1067 (lib (string-append out "/lib"))
1068 (share (string-append out "/share")))
1069 (for-each (cut install-file <> bin)
1070 (list "linux-boot-prober" "os-prober"))
1071 (install-file "newns" (string-append lib "/os-prober"))
1072 (install-file "common.sh" (string-append share "/os-prober"))
1073 (install-file "os-probes/mounted/powerpc/20macosx"
1074 (string-append lib "/os-probes/mounted"))
1079 (let ((destination (string-append lib "/" directory
1080 "/" (basename file))))
1081 (mkdir-p (dirname destination))
1082 (copy-recursively file destination)))
1083 (append (find-files-non-recursive (string-append directory "/common"))
1084 (find-files-non-recursive (string-append directory "/x86")))))
1085 (list "os-probes" "os-probes/mounted" "os-probes/init"
1086 "linux-boot-probes" "linux-boot-probes/mounted"))
1088 (home-page "https://joeyh.name/code/os-prober")
1089 (synopsis "Detect other operating systems")
1090 (description "os-prober probes disks on the system for other operating
1091 systems so that they can be added to the bootloader. It also works out how to
1092 boot existing GNU/Linux systems and detects what distribution is installed in
1093 order to add a suitable bootloader menu entry.")
1094 (license license:gpl2+)))
1097 ;; XXX: 'BUILD_TIMESTAMP' is used to automatically select the newest version
1098 ;; of iPXE if multiple iPXE drivers are loaded concurrently in a UEFI system.
1100 ;; TODO: Bump this timestamp at each modifications of the package (not only
1101 ;; for updates) by running: date +%s.
1102 (let ((timestamp "1591706427"))
1109 (url "https://github.com/ipxe/ipxe")
1110 (commit (string-append "v" version))))
1111 (file-name (git-file-name name version))
1112 (patches (search-patches "ipxe-reproducible-geniso.patch"))
1115 "1pkf1n1c0rdlzfls8fvjvi1sd9xjd9ijqlyz3wigr70ijcv6x8i9"))))
1116 (build-system gnu-build-system)
1118 `(#:modules ((guix build utils)
1119 (guix build gnu-build-system)
1124 #:imported-modules ((guix base32)
1125 ,@%gnu-build-system-modules)
1127 ;; XXX: 'BUILD_ID' is used to determine when another ROM in the
1128 ;; system contains identical code in order to save space within the
1129 ;; legacy BIOS option ROM area, which is extremely limited in size.
1130 ;; It is supposed to be collision-free across all ROMs, to do so we
1131 ;; use the truncated output hash of the package.
1134 (let* ((nix-store (string-append
1135 (or (getenv "NIX_STORE") "/gnu/store")
1138 (string-replace-substring out nix-store ""))
1139 (hash (match:substring (string-match "[0-9a-z]{32}"
1141 (bv (nix-base32-string->bytevector hash)))
1143 (bytevector-u32-ref bv 0 (endianness big))))))
1144 (out (assoc-ref %outputs "out"))
1145 (syslinux (assoc-ref %build-inputs "syslinux")))
1146 (list "ECHO_E_BIN_ECHO=echo"
1147 "ECHO_E_BIN_ECHO_E=echo -e"
1149 ;; cdrtools' mkisofs will silently ignore a missing isolinux.bin!
1150 ;; Luckily xorriso is more strict.
1151 (string-append "ISOLINUX_BIN=" syslinux
1152 "/share/syslinux/isolinux.bin")
1153 (string-append "SYSLINUX_MBR_DISK_PATH=" syslinux
1154 "/share/syslinux/isohdpfx.bin")
1156 ;; Build reproducibly.
1157 (string-append "BUILD_ID_CMD=echo -n " (build-id out))
1158 (string-append "BUILD_TIMESTAMP=" ,timestamp)
1161 (modify-phases %standard-phases
1162 (add-after 'unpack 'enter-source-directory
1163 (lambda _ (chdir "src") #t))
1164 (add-after 'enter-source-directory 'set-options
1166 (substitute* "config/general.h"
1167 (("^//(#define PING_CMD.*)" _ uncommented) uncommented)
1168 (("^//(#define IMAGE_TRUST_CMD.*)" _ uncommented)
1170 (("^#undef.*(DOWNLOAD_PROTO_HTTPS.*)" _ option)
1171 (string-append "#define " option))
1172 (("^#undef.*(DOWNLOAD_PROTO_NFS.*)" _ option)
1173 (string-append "#define " option)))
1175 (delete 'configure) ; no configure script
1177 (lambda* (#:key outputs #:allow-other-keys)
1178 (let* ((out (assoc-ref outputs "out"))
1179 (ipxe (string-append out "/lib/ipxe"))
1181 "\\.(efi|efirom|iso|kkpxe|kpxe|lkrn|mrom|pxe|rom|usb)$")
1182 (dirs '("bin" "bin-i386-linux" "bin-x86_64-pcbios"
1183 "bin-x86_64-efi" "bin-x86_64-linux" "bin-i386-efi"))
1184 (files (apply append
1186 (find-files dir exts-re)) dirs))))
1187 (for-each (lambda (file)
1188 (let* ((subdir (dirname file))
1189 (fn (basename file))
1191 ((string=? "bin" subdir) "")
1192 ((string-prefix? "bin-" subdir)
1193 (string-drop subdir 4)))))
1195 (string-append ipxe "/" tgtsubdir))))
1198 (add-after 'install 'leave-source-directory
1199 (lambda _ (chdir "..") #t)))
1200 #:tests? #f)) ; no test suite
1203 ("syslinux" ,syslinux)
1204 ("xorriso" ,xorriso)))
1205 (home-page "https://ipxe.org")
1206 (synopsis "PXE-compliant network boot firmware")
1207 (description "iPXE is a network boot firmware. It provides a full PXE
1208 implementation enhanced with additional features such as booting from: a web
1209 server via HTTP, an iSCSI SAN, a Fibre Channel SAN via FCoE, an AoE SAN, a
1210 wireless network, a wide-area network, an Infiniband network. It allows to
1211 control the boot process with a script. You can use iPXE to replace the
1212 existing PXE ROM on your network card, or you can chainload into iPXE to obtain
1213 the features of iPXE without the hassle of reflashing.")
1214 (license license:gpl2+))))