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