gnu: gnupg: Update to 2.2.25.
[jackhill/guix/guix.git] / gnu / packages / bootloaders.scm
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 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 ;;;
17 ;;; This file is part of GNU Guix.
18 ;;;
19 ;;; GNU Guix is free software; you can redistribute it and/or modify it
20 ;;; under the terms of the GNU General Public License as published by
21 ;;; the Free Software Foundation; either version 3 of the License, or (at
22 ;;; your option) any later version.
23 ;;;
24 ;;; GNU Guix is distributed in the hope that it will be useful, but
25 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
26 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 ;;; GNU General Public License for more details.
28 ;;;
29 ;;; You should have received a copy of the GNU General Public License
30 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
31
32 (define-module (gnu packages bootloaders)
33 #:use-module (gnu packages)
34 #:use-module (gnu packages admin)
35 #:use-module (gnu packages algebra)
36 #:use-module (gnu packages assembly)
37 #:use-module (gnu packages base)
38 #:use-module (gnu packages disk)
39 #:use-module (gnu packages bison)
40 #:use-module (gnu packages cdrom)
41 #:use-module (gnu packages check)
42 #:use-module (gnu packages compression)
43 #:use-module (gnu packages cross-base)
44 #:use-module (gnu packages disk)
45 #:use-module (gnu packages firmware)
46 #:use-module (gnu packages flex)
47 #:use-module (gnu packages fontutils)
48 #:use-module (gnu packages gcc)
49 #:use-module (gnu packages gettext)
50 #:use-module (gnu packages linux)
51 #:use-module (gnu packages man)
52 #:use-module (gnu packages mtools)
53 #:use-module (gnu packages ncurses)
54 #:use-module (gnu packages perl)
55 #:use-module (gnu packages pkg-config)
56 #:use-module (gnu packages python)
57 #:use-module (gnu packages texinfo)
58 #:use-module (gnu packages tls)
59 #:use-module (gnu packages sdl)
60 #:use-module (gnu packages swig)
61 #:use-module (gnu packages valgrind)
62 #:use-module (gnu packages virtualization)
63 #:use-module (gnu packages xorg)
64 #:use-module (gnu packages web)
65 #:use-module (guix build-system gnu)
66 #:use-module (guix download)
67 #:use-module (guix git-download)
68 #:use-module ((guix licenses) #:prefix license:)
69 #:use-module (guix packages)
70 #:use-module (guix utils)
71 #:use-module (srfi srfi-1)
72 #:use-module (srfi srfi-26)
73 #:use-module (ice-9 regex))
74
75 (define unifont
76 ;; GNU Unifont, <http://gnu.org/s/unifont>.
77 ;; GRUB needs it for its graphical terminal, gfxterm.
78 (origin
79 (method url-fetch)
80 (uri
81 "http://unifoundry.com/pub/unifont-7.0.06/font-builds/unifont-7.0.06.bdf.gz")
82 (sha256
83 (base32
84 "0p2vhnc18cnbmb39vq4m7hzv4mhnm2l0a2s7gx3ar277fwng3hys"))))
85
86 (define-public grub
87 (package
88 (name "grub")
89 (version "2.04")
90 (source (origin
91 (method url-fetch)
92 (uri (string-append "mirror://gnu/grub/grub-" version ".tar.xz"))
93 (sha256
94 (base32
95 "0zgp5m3hmc9jh8wpjx6czzkh5id2y8n1k823x2mjvm2sk6b28ag5"))
96 (patches (search-patches
97 "grub-efi-fat-serial-number.patch"
98 "grub-setup-root.patch"
99 "grub-verifiers-Blocklist-fallout-cleanup.patch"
100 "grub-cross-system-i686.patch"))))
101 (build-system gnu-build-system)
102 (arguments
103 `(#:configure-flags
104 ;; Counterintuitively, this *disables* a spurious Python dependency by
105 ;; calling the ‘true’ binary instead. Python is only needed during
106 ;; bootstrapping (for genptl.py), not when building from a release.
107 (list "PYTHON=true")
108 #:phases (modify-phases %standard-phases
109 (add-after 'unpack 'patch-stuff
110 (lambda* (#:key native-inputs inputs #:allow-other-keys)
111 (substitute* "grub-core/Makefile.in"
112 (("/bin/sh") (which "sh")))
113
114 ;; Give the absolute file name of 'mdadm', used to
115 ;; determine the root file system when it's a RAID
116 ;; device. Failing to do that, 'grub-probe' silently
117 ;; fails if 'mdadm' is not in $PATH.
118 (when (assoc-ref inputs "mdadm")
119 (substitute* "grub-core/osdep/linux/getroot.c"
120 (("argv\\[0\\] = \"mdadm\"")
121 (string-append "argv[0] = \""
122 (assoc-ref inputs "mdadm")
123 "/sbin/mdadm\""))))
124
125 ;; Make the font visible.
126 (copy-file (assoc-ref (or native-inputs inputs)
127 "unifont")
128 "unifont.bdf.gz")
129 (system* "gunzip" "unifont.bdf.gz")
130
131 ;; Give the absolute file name of 'ckbcomp'.
132 (substitute* "util/grub-kbdcomp.in"
133 (("^ckbcomp ")
134 (string-append (assoc-ref inputs "console-setup")
135 "/bin/ckbcomp ")))
136 #t))
137 (add-after 'unpack 'set-freetype-variables
138 ;; These variables need to be set to the native versions
139 ;; of the dependencies because they are used to build
140 ;; programs which are executed during build time.
141 (lambda* (#:key native-inputs #:allow-other-keys)
142 (when (assoc-ref native-inputs "freetype")
143 (let ((freetype (assoc-ref native-inputs "freetype")))
144 (setenv "BUILD_FREETYPE_LIBS"
145 (string-append "-L" freetype
146 "/lib -lfreetype"))
147 (setenv "BUILD_FREETYPE_CFLAGS"
148 (string-append "-I" freetype
149 "/include/freetype2"))))
150 #t))
151 (add-before 'check 'disable-flaky-test
152 (lambda _
153 ;; This test is unreliable. For more information, see:
154 ;; <https://bugs.gnu.org/26936>.
155 (substitute* "Makefile.in"
156 (("grub_cmd_date grub_cmd_set_date grub_cmd_sleep")
157 "grub_cmd_date grub_cmd_sleep"))
158 #t))
159 (add-before 'check 'disable-pixel-perfect-test
160 (lambda _
161 ;; This test compares many screenshots rendered with an
162 ;; older Unifont (9.0.06) than that packaged in Guix.
163 (substitute* "Makefile.in"
164 (("test_unset grub_func_test")
165 "test_unset"))
166 #t)))
167 ;; Disable tests on ARM and AARCH64 platforms or when cross-compiling.
168 #:tests? ,(not (or (any (cute string-prefix? <> (or (%current-target-system)
169 (%current-system)))
170 '("arm" "aarch64"))
171 (%current-target-system)))))
172 (inputs
173 `(("gettext" ,gettext-minimal)
174
175 ;; Depend on LVM2 for libdevmapper, used by 'grub-probe' and
176 ;; 'grub-install' to recognize mapped devices (LUKS, etc.)
177 ,@(if (member (or (%current-target-system)
178 (%current-system))
179 (package-supported-systems lvm2))
180 `(("lvm2" ,lvm2))
181 '())
182
183 ;; Depend on mdadm, which is invoked by 'grub-probe' and 'grub-install'
184 ;; to determine whether the root file system is RAID.
185 ,@(if (member (or (%current-target-system)
186 (%current-system))
187 (package-supported-systems mdadm))
188 `(("mdadm" ,mdadm))
189 '())
190
191 ;; Console-setup's ckbcomp is invoked by grub-kbdcomp. It is required
192 ;; for generating alternative keyboard layouts.
193 ("console-setup" ,console-setup)
194
195 ;; Needed for ‘grub-mount’, the only reliable way to tell whether a given
196 ;; file system will be readable by GRUB without rebooting.
197 ,@(if (member (or (%current-target-system)
198 (%current-system))
199 (package-supported-systems fuse))
200 `(("fuse" ,fuse))
201 '())
202
203 ("freetype" ,freetype)
204 ;; ("libusb" ,libusb)
205 ("ncurses" ,ncurses)))
206 (native-inputs
207 `(("pkg-config" ,pkg-config)
208 ("unifont" ,unifont)
209 ("bison" ,bison)
210 ("flex" ,flex)
211 ("texinfo" ,texinfo)
212 ("help2man" ,help2man)
213 ("freetype" ,freetype) ; native version needed for build-grub-mkfont
214
215 ;; XXX: When building GRUB 2.02 on 32-bit x86, we need a binutils
216 ;; capable of assembling 64-bit instructions. However, our default
217 ;; binutils on 32-bit x86 is not 64-bit capable.
218 ,@(if (string-match "^i[3456]86-" (%current-system))
219 (let ((binutils (package/inherit
220 binutils
221 (name "binutils-i386")
222 (arguments
223 (substitute-keyword-arguments (package-arguments binutils)
224 ((#:configure-flags flags ''())
225 `(cons "--enable-64-bit-bfd" ,flags)))))))
226 `(("ld-wrapper" ,(make-ld-wrapper "ld-wrapper-i386"
227 #:binutils binutils))
228 ("binutils" ,binutils)))
229 '())
230
231 ;; Dependencies for the test suite. The "real" QEMU is needed here,
232 ;; because several targets are used.
233 ("parted" ,parted)
234 ,@(if (member (%current-system) (package-supported-systems qemu-minimal))
235 `(("qemu" ,qemu-minimal))
236 '())
237 ("xorriso" ,xorriso)))
238 (home-page "https://www.gnu.org/software/grub/")
239 (synopsis "GRand Unified Boot loader")
240 (description
241 "GRUB is a multiboot bootloader. It is used for initially loading the
242 kernel of an operating system and then transferring control to it. The kernel
243 then goes on to load the rest of the operating system. As a multiboot
244 bootloader, GRUB handles the presence of multiple operating systems installed
245 on the same computer; upon booting the computer, the user is presented with a
246 menu to select one of the installed operating systems.")
247 (license license:gpl3+)
248 (properties '((cpe-name . "grub2")))))
249
250 (define-public grub-minimal
251 (package
252 (inherit grub)
253 (name "grub-minimal")
254 (inputs
255 (fold alist-delete (package-inputs grub)
256 '("lvm2" "mdadm" "fuse" "console-setup")))
257 (native-inputs
258 (fold alist-delete (package-native-inputs grub)
259 '("help2man" "texinfo" "parted" "qemu" "xorriso")))
260 (arguments
261 `(#:configure-flags (list "PYTHON=true")
262 #:phases (modify-phases %standard-phases
263 (add-after 'unpack 'patch-stuff
264 (lambda* (#:key native-inputs inputs #:allow-other-keys)
265 (substitute* "grub-core/Makefile.in"
266 (("/bin/sh") (which "sh")))
267
268 ;; Make the font visible.
269 (copy-file (assoc-ref (or native-inputs inputs)
270 "unifont")
271 "unifont.bdf.gz")
272 (system* "gunzip" "unifont.bdf.gz")
273
274 #t)))
275 #:tests? #f))))
276
277 (define-public grub-efi
278 (package
279 (inherit grub)
280 (name "grub-efi")
281 (synopsis "GRand Unified Boot loader (UEFI version)")
282 (inputs
283 `(("efibootmgr" ,efibootmgr)
284 ("mtools" ,mtools)
285 ,@(package-inputs grub)))
286 (arguments
287 `(;; TODO: Tests need a UEFI firmware for qemu. There is one at
288 ;; https://github.com/tianocore/edk2/tree/master/OvmfPkg .
289 ;; Search for 'OVMF' in "tests/util/grub-shell.in".
290 ,@(substitute-keyword-arguments (package-arguments grub)
291 ((#:tests? _ #f) #f)
292 ((#:configure-flags flags ''())
293 `(cons "--with-platform=efi" ,flags))
294 ((#:phases phases)
295 `(modify-phases ,phases
296 (add-after 'patch-stuff 'use-absolute-efibootmgr-path
297 (lambda* (#:key inputs #:allow-other-keys)
298 (substitute* "grub-core/osdep/unix/platform.c"
299 (("efibootmgr")
300 (string-append (assoc-ref inputs "efibootmgr")
301 "/sbin/efibootmgr")))
302 #t))
303 (add-after 'patch-stuff 'use-absolute-mtools-path
304 (lambda* (#:key inputs #:allow-other-keys)
305 (let ((mtools (assoc-ref inputs "mtools")))
306 (substitute* "util/grub-mkrescue.c"
307 (("\"mformat\"")
308 (string-append "\"" mtools
309 "/bin/mformat\"")))
310 (substitute* "util/grub-mkrescue.c"
311 (("\"mcopy\"")
312 (string-append "\"" mtools
313 "/bin/mcopy\"")))
314 #t))))))))))
315
316 ;; Because grub searches hardcoded paths it's easiest to just build grub
317 ;; again to make it find both grub-pc and grub-efi. There is a command
318 ;; line argument which allows you to specify ONE platform - but
319 ;; grub-mkrescue will use multiple platforms if they are available
320 ;; in the installation directory (without command line argument).
321 (define-public grub-hybrid
322 (package
323 (inherit grub-efi)
324 (name "grub-hybrid")
325 (synopsis "GRand Unified Boot loader (hybrid version)")
326 (inputs
327 `(("grub" ,grub)
328 ,@(package-inputs grub-efi)))
329 (arguments
330 (substitute-keyword-arguments (package-arguments grub-efi)
331 ((#:modules modules `((guix build utils) (guix build gnu-build-system)))
332 `((ice-9 ftw) ,@modules))
333 ((#:phases phases)
334 `(modify-phases ,phases
335 (add-after 'install 'install-non-efi
336 (lambda* (#:key inputs outputs #:allow-other-keys)
337 (let ((input-dir (string-append (assoc-ref inputs "grub")
338 "/lib/grub"))
339 (output-dir (string-append (assoc-ref outputs "out")
340 "/lib/grub")))
341 (for-each
342 (lambda (basename)
343 (if (not (or (string-prefix? "." basename)
344 (file-exists? (string-append output-dir "/" basename))))
345 (symlink (string-append input-dir "/" basename)
346 (string-append output-dir "/" basename))))
347 (scandir input-dir))
348 #t)))))))))
349
350 (define-public syslinux
351 (let ((commit "bb41e935cc83c6242de24d2271e067d76af3585c"))
352 (package
353 (name "syslinux")
354 (version (git-version "6.04-pre" "1" commit))
355 (source (origin
356 (method git-fetch)
357 (uri (git-reference
358 (url "https://github.com/geneC/syslinux")
359 (commit commit)))
360 (file-name (git-file-name name version))
361 (sha256
362 (base32
363 "0k8dvafd6410kqxf3kyr4y8jzmpmrih6wbjqg6gklak7945yflrc"))))
364 (build-system gnu-build-system)
365 (native-inputs
366 `(("nasm" ,nasm)
367 ("perl" ,perl)
368 ("python-2" ,python-2)))
369 (inputs
370 `(("libuuid" ,util-linux "lib")
371 ("mtools" ,mtools)))
372 (arguments
373 `(#:parallel-build? #f
374 #:make-flags
375 (list (string-append "BINDIR=" %output "/bin")
376 (string-append "SBINDIR=" %output "/sbin")
377 (string-append "LIBDIR=" %output "/lib")
378 (string-append "INCDIR=" %output "/include")
379 (string-append "DATADIR=" %output "/share")
380 (string-append "MANDIR=" %output "/share/man")
381 "PERL=perl"
382 "bios")
383 #:phases
384 (modify-phases %standard-phases
385 (add-after 'unpack 'patch-files
386 (lambda* (#:key inputs #:allow-other-keys)
387 (substitute* (find-files "." "Makefile.*|ppmtolss16")
388 (("/bin/pwd") (which "pwd"))
389 (("/bin/echo") (which "echo"))
390 (("/usr/bin/perl") (which "perl")))
391 (let ((mtools (assoc-ref inputs "mtools")))
392 (substitute* (find-files "." "\\.c$")
393 (("mcopy")
394 (string-append mtools "/bin/mcopy"))
395 (("mattrib")
396 (string-append mtools "/bin/mattrib"))))
397 #t))
398 (delete 'configure)
399 (add-before 'build 'set-permissions
400 (lambda _
401 (invoke "chmod" "a+w" "utils/isohybrid.in")))
402 (replace 'check
403 (lambda _
404 (setenv "CC" "gcc")
405 (substitute* "tests/unittest/include/unittest/unittest.h"
406 ;; Don't look up headers under /usr.
407 (("/usr/include/") ""))
408 (invoke "make" "unittest"))))))
409 (home-page "https://www.syslinux.org")
410 (synopsis "Lightweight Linux bootloader")
411 (description "Syslinux is a lightweight Linux bootloader.")
412 ;; The Makefile specifically targets i386 and x86_64 using nasm.
413 (supported-systems '("i686-linux" "x86_64-linux"))
414 (license (list license:gpl2+
415 license:bsd-3 ; gnu-efi/*
416 license:bsd-4 ; gnu-efi/inc/* gnu-efi/lib/*
417 ;; Also contains:
418 license:expat license:isc license:zlib)))))
419
420 (define-public dtc
421 (package
422 (name "dtc")
423 (version "1.5.1")
424 (source (origin
425 (method url-fetch)
426 (uri (string-append
427 "mirror://kernel.org/software/utils/dtc/"
428 "dtc-" version ".tar.xz"))
429 (sha256
430 (base32
431 "07q3mdsvl4smbiakriq3hnsyyd0q344lsm306q0kgz4hjq1p82v6"))))
432 (build-system gnu-build-system)
433 (native-inputs
434 `(("bison" ,bison)
435 ("flex" ,flex)
436 ("libyaml" ,libyaml)
437 ("pkg-config" ,pkg-config)
438 ("swig" ,swig)
439 ("valgrind" ,valgrind)))
440 (inputs
441 `(("python" ,python)))
442 (arguments
443 `(#:make-flags
444 (list (string-append "CC=" ,(cc-for-target))
445
446 ;; /bin/fdt{get,overlay,put} need help finding libfdt.so.1.
447 (string-append "LDFLAGS=-Wl,-rpath="
448 (assoc-ref %outputs "out") "/lib")
449
450 (string-append "PREFIX=" (assoc-ref %outputs "out"))
451 (string-append "SETUP_PREFIX=" (assoc-ref %outputs "out"))
452 "INSTALL=install")
453 #:phases
454 (modify-phases %standard-phases
455 (add-after 'unpack 'patch-pkg-config
456 (lambda _
457 (substitute* '("Makefile"
458 "tests/run_tests.sh")
459 (("pkg-config")
460 (or (which "pkg-config")
461 (string-append ,(%current-target-system)
462 "-pkg-config"))))
463 #t))
464 (delete 'configure)))) ; no configure script
465 (home-page "https://www.devicetree.org")
466 (synopsis "Compiles device tree source files")
467 (description "@command{dtc} compiles
468 @uref{http://elinux.org/Device_Tree_Usage, device tree source files} to device
469 tree binary files. These are board description files used by Linux and BSD.")
470 (license license:gpl2+)))
471
472 (define u-boot
473 (package
474 (name "u-boot")
475 (version "2020.10")
476 (source (origin
477 (method url-fetch)
478 (uri (string-append
479 "ftp://ftp.denx.de/pub/u-boot/"
480 "u-boot-" version ".tar.bz2"))
481 (sha256
482 (base32
483 "08m6f1bh4pdcqbxf983qdb66ccd5vak5cbzc114yf3jwq2yinj0d"))))
484 (native-inputs
485 `(("bc" ,bc)
486 ("bison" ,bison)
487 ("dtc" ,dtc)
488 ("flex" ,flex)
489 ("lz4" ,lz4)
490 ("perl" ,perl)
491 ("python" ,python)
492 ("python-coverage" ,python-coverage)
493 ("python-pytest" ,python-pytest)
494 ("swig" ,swig)))
495 (build-system gnu-build-system)
496 (home-page "https://www.denx.de/wiki/U-Boot/")
497 (synopsis "ARM bootloader")
498 (description "U-Boot is a bootloader used mostly for ARM boards. It
499 also initializes the boards (RAM etc).")
500 (license license:gpl2+)))
501
502 (define-public u-boot-tools
503 (package
504 (inherit u-boot)
505 (name "u-boot-tools")
506 (native-inputs
507 `(("sdl2" ,sdl2)
508 ,@(package-native-inputs u-boot)))
509 (arguments
510 `(#:make-flags '("HOSTCC=gcc")
511 #:test-target "tcheck"
512 #:phases
513 (modify-phases %standard-phases
514 (add-after 'unpack 'patch
515 (lambda* (#:key inputs #:allow-other-keys)
516 (substitute* "Makefile"
517 (("/bin/pwd") (which "pwd"))
518 (("/bin/false") (which "false")))
519 (substitute* "tools/dtoc/fdt_util.py"
520 (("'cc'") "'gcc'"))
521 (substitute* "tools/patman/test_util.py"
522 ;; python3-coverage is simply called coverage in guix.
523 (("python3-coverage") "coverage"))
524 (substitute* "test/run"
525 ;; Make it easier to find test failures.
526 (("#!/bin/bash") "#!/bin/bash -x")
527 ;; This test would require git.
528 (("\\./tools/patman/patman") (which "true"))
529 ;; FIXME: test fails, needs further investiation
530 (("run_test \"binman\"") ": run_test \"binman\"")
531 ;; FIXME: code coverage not working
532 (("run_test \"binman code coverage\"") ": run_test \"binman code coverage\"")
533 ;; This test would require internet access.
534 (("\\./tools/buildman/buildman") (which "true")))
535 (substitute* "test/py/tests/test_sandbox_exit.py"
536 (("def test_ctrl_c")
537 "@pytest.mark.skip(reason='Guix has problems with SIGINT')
538 def test_ctrl_c"))
539 ;; Test against the tools being installed rather than tools built
540 ;; for "sandbox" target.
541 (substitute* "test/image/test-imagetools.sh"
542 (("BASEDIR=sandbox") "BASEDIR=."))
543 (for-each (lambda (file)
544 (substitute* file
545 ;; Disable features that require OpenSSL due
546 ;; to GPL/Openssl license incompatibilities.
547 ;; See https://bugs.gnu.org/34717 for
548 ;; details.
549 (("CONFIG_FIT_SIGNATURE=y")
550 "CONFIG_FIT_SIGNATURE=n\nCONFIG_UT_LIB_ASN1=n")
551 ;; This test requires a sound system, which is un-used
552 ;; in u-boot-tools.
553 (("CONFIG_SOUND=y") "CONFIG_SOUND=n")))
554 (find-files "configs" "sandbox_.*defconfig$|tools-only_defconfig"))
555 #t))
556 (replace 'configure
557 (lambda* (#:key make-flags #:allow-other-keys)
558 (apply invoke "make" "tools-only_defconfig" make-flags)))
559 (replace 'build
560 (lambda* (#:key inputs make-flags #:allow-other-keys)
561 (apply invoke "make" "tools-all" make-flags)))
562 (replace 'install
563 (lambda* (#:key outputs #:allow-other-keys)
564 (let* ((out (assoc-ref outputs "out"))
565 (bin (string-append out "/bin")))
566 (for-each (lambda (name)
567 (install-file name bin))
568 '("tools/netconsole"
569 "tools/jtagconsole"
570 "tools/gen_eth_addr"
571 "tools/gen_ethaddr_crc"
572 "tools/img2srec"
573 "tools/mkenvimage"
574 "tools/dumpimage"
575 "tools/mkimage"
576 "tools/proftool"
577 "tools/fdtgrep"
578 "tools/env/fw_printenv"
579 "tools/sunxi-spl-image-builder"))
580 #t)))
581 (delete 'check)
582 (add-after 'install 'check
583 (lambda* (#:key make-flags test-target #:allow-other-keys)
584 (invoke "test/image/test-imagetools.sh")))
585 ;; Only run full test suite on x86_64 systems, as many tests
586 ;; assume x86_64.
587 ,@(if (string-match "^x86_64-linux"
588 (or (%current-target-system)
589 (%current-system)))
590 '((add-after 'check 'check-x86
591 (lambda* (#:key make-flags test-target #:allow-other-keys)
592 (apply invoke "make" "mrproper" make-flags)
593 (setenv "SDL_VIDEODRIVER" "dummy")
594 (setenv "PAGER" "cat")
595 (apply invoke "make" test-target make-flags))))
596 '()))))
597 (description "U-Boot is a bootloader used mostly for ARM boards. It
598 also initializes the boards (RAM etc). This package provides its
599 board-independent tools.")))
600
601 (define-public (make-u-boot-package board triplet)
602 "Returns a u-boot package for BOARD cross-compiled for TRIPLET."
603 (let ((same-arch? (lambda ()
604 (string=? (%current-system)
605 (gnu-triplet->nix-system triplet)))))
606 (package
607 (inherit u-boot)
608 (name (string-append "u-boot-"
609 (string-replace-substring (string-downcase board)
610 "_" "-")))
611 (native-inputs
612 `(,@(if (not (same-arch?))
613 `(("cross-gcc" ,(cross-gcc triplet))
614 ("cross-binutils" ,(cross-binutils triplet)))
615 `())
616 ,@(package-native-inputs u-boot)))
617 (arguments
618 `(#:modules ((ice-9 ftw)
619 (srfi srfi-1)
620 (guix build utils)
621 (guix build gnu-build-system))
622 #:test-target "test"
623 #:make-flags
624 (list "HOSTCC=gcc"
625 ,@(if (not (same-arch?))
626 `((string-append "CROSS_COMPILE=" ,triplet "-"))
627 '()))
628 #:phases
629 (modify-phases %standard-phases
630 (replace 'configure
631 (lambda* (#:key outputs make-flags #:allow-other-keys)
632 (let ((config-name (string-append ,board "_defconfig")))
633 (if (file-exists? (string-append "configs/" config-name))
634 (apply invoke "make" `(,@make-flags ,config-name))
635 (begin
636 (display "Invalid board name. Valid board names are:"
637 (current-error-port))
638 (let ((suffix-len (string-length "_defconfig"))
639 (entries (scandir "configs")))
640 (for-each (lambda (file-name)
641 (when (string-suffix? "_defconfig" file-name)
642 (format (current-error-port)
643 "- ~A\n"
644 (string-drop-right file-name
645 suffix-len))))
646 (sort entries string-ci<)))
647 (error "Invalid boardname ~s." ,board))))))
648 (replace 'install
649 (lambda* (#:key outputs #:allow-other-keys)
650 (let* ((out (assoc-ref outputs "out"))
651 (libexec (string-append out "/libexec"))
652 (uboot-files (append
653 (remove
654 ;; Those would not be reproducible
655 ;; because of the randomness used
656 ;; to produce them.
657 ;; It's expected that the user will
658 ;; use u-boot-tools to generate them
659 ;; instead.
660 (lambda (name)
661 (string-suffix?
662 "sunxi-spl-with-ecc.bin"
663 name))
664 (find-files "." ".*\\.(bin|efi|img|spl|itb|dtb|rksd)$"))
665 (find-files "." "^(MLO|SPL)$"))))
666 (mkdir-p libexec)
667 (install-file ".config" libexec)
668 ;; Useful for "qemu -kernel".
669 (install-file "u-boot" libexec)
670 (for-each
671 (lambda (file)
672 (let ((target-file (string-append libexec "/" file)))
673 (mkdir-p (dirname target-file))
674 (copy-file file target-file)))
675 uboot-files)
676 #t)))))))))
677
678 (define-public u-boot-vexpress
679 (make-u-boot-package "vexpress_ca9x4" "arm-linux-gnueabihf"))
680
681 (define-public u-boot-malta
682 (make-u-boot-package "malta" "mips64el-linux-gnuabi64"))
683
684 (define-public u-boot-am335x-boneblack
685 (let ((base (make-u-boot-package "am335x_evm" "arm-linux-gnueabihf")))
686 (package
687 (inherit base)
688 (name "u-boot-am335x-boneblack")
689 (description "U-Boot is a bootloader used mostly for ARM boards. It
690 also initializes the boards (RAM etc).
691
692 This U-Boot is built for the BeagleBone Black, which was removed upstream,
693 adjusted from the am335x_evm build with several device trees removed so that
694 it fits within common partitioning schemes.")
695 (arguments
696 (substitute-keyword-arguments (package-arguments base)
697 ((#:phases phases)
698 `(modify-phases ,phases
699 (add-after 'unpack 'patch-defconfig
700 ;; Patch out other devicetrees to build image small enough to
701 ;; fit within typical partitioning schemes where the first
702 ;; partition begins at sector 2048.
703 (lambda _
704 (substitute* "configs/am335x_evm_defconfig"
705 (("CONFIG_OF_LIST=.*$") "CONFIG_OF_LIST=\"am335x-evm am335x-boneblack\"\n"))
706 #t)))))))))
707
708 (define-public u-boot-am335x-evm
709 (make-u-boot-package "am335x_evm" "arm-linux-gnueabihf"))
710
711 (define-public (make-u-boot-sunxi64-package board triplet)
712 (let ((base (make-u-boot-package board triplet)))
713 (package
714 (inherit base)
715 (arguments
716 (substitute-keyword-arguments (package-arguments base)
717 ((#:phases phases)
718 `(modify-phases ,phases
719 (add-after 'unpack 'set-environment
720 (lambda* (#:key native-inputs inputs #:allow-other-keys)
721 (let ((bl31
722 (string-append
723 (assoc-ref (or native-inputs inputs) "firmware")
724 "/bl31.bin")))
725 (setenv "BL31" bl31)
726 ;; This is necessary when we're using the bundled dtc.
727 ;(setenv "PATH" (string-append (getenv "PATH") ":"
728 ; "scripts/dtc"))
729 )
730 #t))))))
731 (native-inputs
732 `(("firmware" ,arm-trusted-firmware-sun50i-a64)
733 ,@(package-native-inputs base))))))
734
735 (define-public u-boot-pine64-plus
736 (make-u-boot-sunxi64-package "pine64_plus" "aarch64-linux-gnu"))
737
738 (define-public u-boot-pine64-lts
739 (make-u-boot-sunxi64-package "pine64-lts" "aarch64-linux-gnu"))
740
741 (define-public u-boot-pinebook
742 (let ((base (make-u-boot-sunxi64-package "pinebook" "aarch64-linux-gnu")))
743 (package
744 (inherit base)
745 (arguments
746 (substitute-keyword-arguments (package-arguments base)
747 ((#:phases phases)
748 `(modify-phases ,phases
749 (add-after 'unpack 'patch-pinebook-config
750 ;; Fix regression with LCD video output introduced in 2020.01
751 ;; https://patchwork.ozlabs.org/patch/1225130/
752 (lambda _
753 (substitute* "configs/pinebook_defconfig"
754 (("CONFIG_VIDEO_BRIDGE_ANALOGIX_ANX6345=y") "CONFIG_VIDEO_BRIDGE_ANALOGIX_ANX6345=y\nCONFIG_VIDEO_BPP32=y"))
755 #t)))))))))
756
757 (define-public u-boot-bananapi-m2-ultra
758 (make-u-boot-package "Bananapi_M2_Ultra" "arm-linux-gnueabihf"))
759
760 (define-public u-boot-a20-olinuxino-lime
761 (make-u-boot-package "A20-OLinuXino-Lime" "arm-linux-gnueabihf"))
762
763 (define-public u-boot-a20-olinuxino-lime2
764 (make-u-boot-package "A20-OLinuXino-Lime2" "arm-linux-gnueabihf"))
765
766 (define-public u-boot-a20-olinuxino-micro
767 (make-u-boot-package "A20-OLinuXino_MICRO" "arm-linux-gnueabihf"))
768
769 (define-public u-boot-nintendo-nes-classic-edition
770 (make-u-boot-package "Nintendo_NES_Classic_Edition" "arm-linux-gnueabihf"))
771
772 (define-public u-boot-wandboard
773 (make-u-boot-package "wandboard" "arm-linux-gnueabihf"))
774
775 (define-public u-boot-mx6cuboxi
776 (make-u-boot-package "mx6cuboxi" "arm-linux-gnueabihf"))
777
778 (define-public u-boot-novena
779 (let ((base (make-u-boot-package "novena" "arm-linux-gnueabihf")))
780 (package
781 (inherit base)
782 (description "U-Boot is a bootloader used mostly for ARM boards. It
783 also initializes the boards (RAM etc).
784
785 This U-Boot is built for Novena. Be advised that this version, contrary
786 to Novena upstream, does not load u-boot.img from the first partition.")
787 (arguments
788 (substitute-keyword-arguments (package-arguments base)
789 ((#:phases phases)
790 `(modify-phases ,phases
791 (add-after 'unpack 'patch-novena-defconfig
792 ;; Patch configuration to disable loading u-boot.img from FAT partition,
793 ;; allowing it to be installed at a device offset.
794 (lambda _
795 (substitute* "configs/novena_defconfig"
796 (("CONFIG_SPL_FS_FAT=y") "# CONFIG_SPL_FS_FAT is not set"))
797 #t)))))))))
798
799 (define-public u-boot-cubieboard
800 (make-u-boot-package "Cubieboard" "arm-linux-gnueabihf"))
801
802 (define-public u-boot-cubietruck
803 (make-u-boot-package "Cubietruck" "arm-linux-gnueabihf"))
804
805 (define-public u-boot-puma-rk3399
806 (let ((base (make-u-boot-package "puma-rk3399" "aarch64-linux-gnu")))
807 (package
808 (inherit base)
809 (arguments
810 (substitute-keyword-arguments (package-arguments base)
811 ((#:phases phases)
812 `(modify-phases ,phases
813 (add-after 'unpack 'set-environment
814 (lambda* (#:key inputs #:allow-other-keys)
815 ;; Need to copy the firmware into u-boot build
816 ;; directory.
817 (copy-file (string-append (assoc-ref inputs "firmware")
818 "/bl31.bin") "bl31-rk3399.bin")
819 (copy-file (string-append (assoc-ref inputs "firmware-m0")
820 "/rk3399m0.bin") "rk3399m0.bin")
821 #t))
822 (add-after 'build 'build-itb
823 (lambda* (#:key make-flags #:allow-other-keys)
824 ;; The u-boot.itb is not built by default.
825 (apply invoke "make" `(,@make-flags ,"u-boot.itb"))))
826 (add-after 'build-itb 'build-rksd
827 (lambda* (#:key inputs #:allow-other-keys)
828 ;; Build Rockchip SD card images.
829 (invoke "./tools/mkimage" "-T" "rksd" "-n" "rk3399" "-d"
830 "spl/u-boot-spl.bin" "u-boot-spl.rksd")))))))
831 (native-inputs
832 `(("firmware" ,arm-trusted-firmware-puma-rk3399)
833 ("firmware-m0" ,rk3399-cortex-m0)
834 ,@(package-native-inputs base))))))
835
836 (define-public u-boot-qemu-riscv64
837 (make-u-boot-package "qemu-riscv64" "riscv64-linux-gnu"))
838
839 (define-public u-boot-qemu-riscv64-smode
840 (let ((base (make-u-boot-package "qemu-riscv64_smode" "riscv64-linux-gnu")))
841 (package
842 (inherit base)
843 (source (origin
844 (inherit (package-source u-boot))
845 (patches
846 (search-patches "u-boot-riscv64-fix-extlinux.patch")))))))
847
848 (define-public u-boot-sifive-fu540
849 (make-u-boot-package "sifive_fu540" "riscv64-linux-gnu"))
850
851 (define-public u-boot-rock64-rk3328
852 (let ((base (make-u-boot-package "rock64-rk3328" "aarch64-linux-gnu")))
853 (package
854 (inherit base)
855 (arguments
856 (substitute-keyword-arguments (package-arguments base)
857 ((#:phases phases)
858 `(modify-phases ,phases
859 (add-after 'unpack 'set-environment
860 (lambda* (#:key inputs #:allow-other-keys)
861 (let ((bl31 (string-append (assoc-ref inputs "firmware")
862 "/bl31.elf")))
863 (setenv "BL31" bl31))
864 #t))))))
865 (native-inputs
866 `(("firmware" ,arm-trusted-firmware-rk3328)
867 ,@(package-native-inputs base))))))
868
869 (define-public u-boot-firefly-rk3399
870 (let ((base (make-u-boot-package "firefly-rk3399" "aarch64-linux-gnu")))
871 (package
872 (inherit base)
873 (arguments
874 (substitute-keyword-arguments (package-arguments base)
875 ((#:phases phases)
876 `(modify-phases ,phases
877 (add-after 'unpack 'set-environment
878 (lambda* (#:key inputs #:allow-other-keys)
879 (setenv "BL31" (string-append (assoc-ref inputs "firmware")
880 "/bl31.elf"))
881 #t))
882 ;; Phases do not succeed on the bl31 ELF.
883 (delete 'strip)
884 (delete 'validate-runpath)))))
885 (native-inputs
886 `(("firmware" ,arm-trusted-firmware-rk3399)
887 ,@(package-native-inputs base))))))
888
889 (define-public u-boot-rockpro64-rk3399
890 (let ((base (make-u-boot-package "rockpro64-rk3399" "aarch64-linux-gnu")))
891 (package
892 (inherit base)
893 (arguments
894 (substitute-keyword-arguments (package-arguments base)
895 ((#:phases phases)
896 `(modify-phases ,phases
897 (add-after 'unpack 'set-environment
898 (lambda* (#:key inputs #:allow-other-keys)
899 (setenv "BL31" (string-append (assoc-ref inputs "firmware")
900 "/bl31.elf"))
901 #t))
902 ;; Phases do not succeed on the bl31 ELF.
903 (delete 'strip)
904 (delete 'validate-runpath)))))
905 (native-inputs
906 `(("firmware" ,arm-trusted-firmware-rk3399)
907 ,@(package-native-inputs base))))))
908
909 (define-public u-boot-pinebook-pro-rk3399
910 (let ((base (make-u-boot-package "pinebook-pro-rk3399" "aarch64-linux-gnu")))
911 (package
912 (inherit base)
913 (arguments
914 (substitute-keyword-arguments (package-arguments base)
915 ((#:phases phases)
916 `(modify-phases ,phases
917 (add-after 'unpack 'set-environment
918 (lambda* (#:key inputs #:allow-other-keys)
919 (setenv "BL31" (string-append (assoc-ref inputs "firmware")
920 "/bl31.elf"))
921 #t))
922 ;; Phases do not succeed on the bl31 ELF.
923 (delete 'strip)
924 (delete 'validate-runpath)))))
925 (native-inputs
926 `(("firmware" ,arm-trusted-firmware-rk3399)
927 ,@(package-native-inputs base))))))
928
929 (define-public vboot-utils
930 (package
931 (name "vboot-utils")
932 (version "R63-10032.B")
933 (source (origin
934 ;; XXX: Snapshots are available but changes timestamps every download.
935 (method git-fetch)
936 (uri (git-reference
937 (url (string-append "https://chromium.googlesource.com"
938 "/chromiumos/platform/vboot_reference"))
939 (commit (string-append "release-" version))))
940 (file-name (string-append name "-" version "-checkout"))
941 (sha256
942 (base32
943 "0h0m3l69vp9dr6xrs1p6y7ilkq3jq8jraw2z20kqfv7lvc9l1lxj"))
944 (patches
945 (search-patches "vboot-utils-skip-test-workbuf.patch"
946 "vboot-utils-fix-tests-show-contents.patch"
947 "vboot-utils-fix-format-load-address.patch"))))
948 (build-system gnu-build-system)
949 (arguments
950 `(#:make-flags (list "CC=gcc"
951 ;; On ARM, we must pass "HOST_ARCH=arm" so that the
952 ;; ${HOST_ARCH} and ${ARCH} variables in the makefile
953 ;; match. Otherwise, ${HOST_ARCH} will be assigned
954 ;; "armv7l", the value of `uname -m`, and will not
955 ;; match ${ARCH}, which will make the tests require
956 ;; QEMU for testing.
957 ,@(if (string-prefix? "arm"
958 (or (%current-target-system)
959 (%current-system)))
960 '("HOST_ARCH=arm")
961 '())
962 (string-append "DESTDIR=" (assoc-ref %outputs "out")))
963 #:phases (modify-phases %standard-phases
964 (add-after 'unpack 'patch-hard-coded-paths
965 (lambda* (#:key inputs outputs #:allow-other-keys)
966 (let ((coreutils (assoc-ref inputs "coreutils"))
967 (diffutils (assoc-ref inputs "diffutils")))
968 (substitute* "futility/misc.c"
969 (("/bin/cp") (string-append coreutils "/bin/cp")))
970 (substitute* "tests/bitmaps/TestBmpBlock.py"
971 (("/usr/bin/cmp") (string-append diffutils "/bin/cmp")))
972 (substitute* "vboot_host.pc.in"
973 (("prefix=/usr")
974 (string-append "prefix=" (assoc-ref outputs "out"))))
975 #t)))
976 (delete 'configure)
977 (add-before 'check 'patch-tests
978 (lambda _
979 ;; These tests compare diffs against known-good values.
980 ;; Patch the paths to match those in the build container.
981 (substitute* (find-files "tests/futility/expect_output")
982 (("/mnt/host/source/src/platform/vboot_reference")
983 (string-append "/tmp/guix-build-" ,name "-" ,version
984 ".drv-0/source")))
985 ;; Tests require write permissions to many of these files.
986 (for-each make-file-writable (find-files "tests/futility"))
987 #t))
988 (add-after 'install 'install-devkeys
989 (lambda* (#:key outputs #:allow-other-keys)
990 (let* ((out (assoc-ref outputs "out"))
991 (share (string-append out "/share/vboot-utils")))
992 (copy-recursively "tests/devkeys"
993 (string-append share "/devkeys"))
994 #t))))
995 #:test-target "runtests"))
996 (native-inputs
997 `(("pkg-config" ,pkg-config)
998
999 ;; For tests.
1000 ("diffutils" ,diffutils)
1001 ("python@2" ,python-2)))
1002 (inputs
1003 `(("coreutils" ,coreutils)
1004 ("libyaml" ,libyaml)
1005 ("openssl" ,openssl)
1006 ("openssl:static" ,openssl "static")
1007 ("util-linux" ,util-linux "lib")))
1008 (home-page
1009 "https://dev.chromium.org/chromium-os/chromiumos-design-docs/verified-boot")
1010 (synopsis "ChromiumOS verified boot utilities")
1011 (description
1012 "vboot-utils is a collection of tools to facilitate booting of
1013 Chrome-branded devices. This includes the @command{cgpt} partitioning
1014 program, the @command{futility} and @command{crossystem} firmware management
1015 tools, and more.")
1016 (license license:bsd-3)))
1017
1018 (define-public os-prober
1019 (package
1020 (name "os-prober")
1021 (version "1.77")
1022 (source
1023 (origin
1024 (method url-fetch)
1025 (uri (string-append "mirror://debian/pool/main/o/os-prober/os-prober_"
1026 version ".tar.xz"))
1027 (sha256
1028 (base32
1029 "0pvhrw4h05n21zw7ig3a3bi8aqdh6zxs0x1znz4g7vhspsps93ld"))))
1030 (build-system gnu-build-system)
1031 (arguments
1032 `(#:modules ((guix build gnu-build-system)
1033 (guix build utils)
1034 (ice-9 regex) ; for string-match
1035 (srfi srfi-26)) ; for cut
1036 #:make-flags
1037 (list ,(string-append "CC=" (cc-for-target)))
1038 #:tests? #f ; no tests
1039 #:phases
1040 (modify-phases %standard-phases
1041 (replace 'configure
1042 (lambda* (#:key outputs #:allow-other-keys)
1043 (substitute* (find-files ".")
1044 (("/usr") (assoc-ref outputs "out")))
1045 (substitute* (find-files "." "50mounted-tests$")
1046 (("mkdir") "mkdir -p"))
1047 #t))
1048 (replace 'install
1049 (lambda* (#:key outputs #:allow-other-keys)
1050 (define (find-files-non-recursive directory)
1051 (find-files directory
1052 (lambda (file stat)
1053 (string-match (string-append "^" directory "/[^/]*$")
1054 file))
1055 #:directories? #t))
1056
1057 (let* ((out (assoc-ref outputs "out"))
1058 (bin (string-append out "/bin"))
1059 (lib (string-append out "/lib"))
1060 (share (string-append out "/share")))
1061 (for-each (cut install-file <> bin)
1062 (list "linux-boot-prober" "os-prober"))
1063 (install-file "newns" (string-append lib "/os-prober"))
1064 (install-file "common.sh" (string-append share "/os-prober"))
1065 (install-file "os-probes/mounted/powerpc/20macosx"
1066 (string-append lib "/os-probes/mounted"))
1067 (for-each
1068 (lambda (directory)
1069 (for-each
1070 (lambda (file)
1071 (let ((destination (string-append lib "/" directory
1072 "/" (basename file))))
1073 (mkdir-p (dirname destination))
1074 (copy-recursively file destination)))
1075 (append (find-files-non-recursive (string-append directory "/common"))
1076 (find-files-non-recursive (string-append directory "/x86")))))
1077 (list "os-probes" "os-probes/mounted" "os-probes/init"
1078 "linux-boot-probes" "linux-boot-probes/mounted"))
1079 #t))))))
1080 (home-page "https://joeyh.name/code/os-prober")
1081 (synopsis "Detect other operating systems")
1082 (description "os-prober probes disks on the system for other operating
1083 systems so that they can be added to the bootloader. It also works out how to
1084 boot existing GNU/Linux systems and detects what distribution is installed in
1085 order to add a suitable bootloader menu entry.")
1086 (license license:gpl2+)))