gnu: icecat: Update to 78.10.0-guix0-preview1 [security fixes].
[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, 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>
18 ;;;
19 ;;; This file is part of GNU Guix.
20 ;;;
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.
25 ;;;
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.
30 ;;;
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/>.
33
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))
76
77 (define unifont
78 ;; GNU Unifont, <http://gnu.org/s/unifont>.
79 ;; GRUB needs it for its graphical terminal, gfxterm.
80 (origin
81 (method url-fetch)
82 (uri
83 "http://unifoundry.com/pub/unifont-7.0.06/font-builds/unifont-7.0.06.bdf.gz")
84 (sha256
85 (base32
86 "0p2vhnc18cnbmb39vq4m7hzv4mhnm2l0a2s7gx3ar277fwng3hys"))))
87
88 (define-public grub
89 (package
90 (name "grub")
91 (version "2.04")
92 (source (origin
93 (method url-fetch)
94 (uri (string-append "mirror://gnu/grub/grub-" version ".tar.xz"))
95 (sha256
96 (base32
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)
104 (arguments
105 `(#:configure-flags
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.
109 (list "PYTHON=true")
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")))
115
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")
125 "/sbin/mdadm\""))))
126
127 ;; Make the font visible.
128 (copy-file (assoc-ref (or native-inputs inputs)
129 "unifont")
130 "unifont.bdf.gz")
131 (system* "gunzip" "unifont.bdf.gz")
132
133 ;; Give the absolute file name of 'ckbcomp'.
134 (substitute* "util/grub-kbdcomp.in"
135 (("^ckbcomp ")
136 (string-append (assoc-ref inputs "console-setup")
137 "/bin/ckbcomp ")))
138 #t))
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
148 "/lib -lfreetype"))
149 (setenv "BUILD_FREETYPE_CFLAGS"
150 (string-append "-I" freetype
151 "/include/freetype2"))))
152 #t))
153 (add-before 'check 'disable-flaky-test
154 (lambda _
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"))
160 #t))
161 (add-before 'check 'disable-pixel-perfect-test
162 (lambda _
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")
167 "test_unset"))
168 #t)))
169 ;; Disable tests on ARM and AARCH64 platforms or when cross-compiling.
170 #:tests? ,(not (or (any (cute string-prefix? <> (or (%current-target-system)
171 (%current-system)))
172 '("arm" "aarch64"))
173 (%current-target-system)))))
174 (inputs
175 `(("gettext" ,gettext-minimal)
176
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)
180 (%current-system))
181 (package-supported-systems lvm2))
182 `(("lvm2" ,lvm2))
183 '())
184
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)
188 (%current-system))
189 (package-supported-systems mdadm))
190 `(("mdadm" ,mdadm))
191 '())
192
193 ;; Console-setup's ckbcomp is invoked by grub-kbdcomp. It is required
194 ;; for generating alternative keyboard layouts.
195 ("console-setup" ,console-setup)
196
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)
200 (%current-system))
201 (package-supported-systems fuse))
202 `(("fuse" ,fuse))
203 '())
204
205 ("freetype" ,freetype)
206 ;; ("libusb" ,libusb)
207 ("ncurses" ,ncurses)))
208 (native-inputs
209 `(("pkg-config" ,pkg-config)
210 ("unifont" ,unifont)
211 ("bison" ,bison)
212 ("flex" ,flex)
213 ("texinfo" ,texinfo)
214 ("help2man" ,help2man)
215 ("freetype" ,freetype) ; native version needed for build-grub-mkfont
216
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
222 binutils
223 (name "binutils-i386")
224 (arguments
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)))
231 '())
232
233 ;; Dependencies for the test suite. The "real" QEMU is needed here,
234 ;; because several targets are used.
235 ("parted" ,parted)
236 ,@(if (member (%current-system) (package-supported-systems qemu-minimal))
237 `(("qemu" ,qemu-minimal))
238 '())
239 ("xorriso" ,xorriso)))
240 (home-page "https://www.gnu.org/software/grub/")
241 (synopsis "GRand Unified Boot loader")
242 (description
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")))))
251
252 (define-public grub-minimal
253 (package
254 (inherit grub)
255 (name "grub-minimal")
256 (inputs
257 (fold alist-delete (package-inputs grub)
258 '("lvm2" "mdadm" "fuse" "console-setup")))
259 (native-inputs
260 (fold alist-delete (package-native-inputs grub)
261 '("help2man" "texinfo" "parted" "qemu" "xorriso")))
262 (arguments
263 (substitute-keyword-arguments (package-arguments grub)
264 ((#:configure-flags _ ''())
265 '(list "PYTHON=true"))
266 ((#:tests? _ #t)
267 #f)
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")))
274
275 ;; Make the font visible.
276 (copy-file (assoc-ref (or native-inputs inputs)
277 "unifont")
278 "unifont.bdf.gz")
279 (system* "gunzip" "unifont.bdf.gz")
280
281 #t))))))))
282
283 (define-public grub-efi
284 (package
285 (inherit grub)
286 (name "grub-efi")
287 (synopsis "GRand Unified Boot loader (UEFI version)")
288 (inputs
289 `(("efibootmgr" ,efibootmgr)
290 ("mtools" ,mtools)
291 ,@(package-inputs grub)))
292 (arguments
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)
297 ((#:tests? _ #f) #f)
298 ((#:configure-flags flags ''())
299 `(cons "--with-platform=efi" ,flags))
300 ((#:phases phases)
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"
305 (("efibootmgr")
306 (string-append (assoc-ref inputs "efibootmgr")
307 "/sbin/efibootmgr")))
308 #t))
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"
313 (("\"mformat\"")
314 (string-append "\"" mtools
315 "/bin/mformat\"")))
316 (substitute* "util/grub-mkrescue.c"
317 (("\"mcopy\"")
318 (string-append "\"" mtools
319 "/bin/mcopy\"")))
320 #t))))))))))
321
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
328 (package
329 (inherit grub-efi)
330 (name "grub-hybrid")
331 (synopsis "GRand Unified Boot loader (hybrid version)")
332 (inputs
333 `(("grub" ,grub)
334 ,@(package-inputs grub-efi)))
335 (arguments
336 (substitute-keyword-arguments (package-arguments grub-efi)
337 ((#:modules modules `((guix build utils) (guix build gnu-build-system)))
338 `((ice-9 ftw) ,@modules))
339 ((#:phases phases)
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")
344 "/lib/grub"))
345 (output-dir (string-append (assoc-ref outputs "out")
346 "/lib/grub")))
347 (for-each
348 (lambda (basename)
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))))
353 (scandir input-dir))
354 #t)))))))))
355
356 (define-public syslinux
357 (let ((commit "bb41e935cc83c6242de24d2271e067d76af3585c"))
358 (package
359 (name "syslinux")
360 (version (git-version "6.04-pre" "1" commit))
361 (source (origin
362 (method git-fetch)
363 (uri (git-reference
364 (url "https://github.com/geneC/syslinux")
365 (commit commit)))
366 (file-name (git-file-name name version))
367 (sha256
368 (base32
369 "0k8dvafd6410kqxf3kyr4y8jzmpmrih6wbjqg6gklak7945yflrc"))))
370 (build-system gnu-build-system)
371 (native-inputs
372 `(("nasm" ,nasm)
373 ("perl" ,perl)
374 ("python-2" ,python-2)))
375 (inputs
376 `(("libuuid" ,util-linux "lib")
377 ("mtools" ,mtools)))
378 (arguments
379 `(#:parallel-build? #f
380 #:make-flags
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")
387 "PERL=perl"
388 "bios")
389 #:phases
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$")
399 (("mcopy")
400 (string-append mtools "/bin/mcopy"))
401 (("mattrib")
402 (string-append mtools "/bin/mattrib"))))
403 #t))
404 (delete 'configure)
405 (add-before 'build 'set-permissions
406 (lambda _
407 (invoke "chmod" "a+w" "utils/isohybrid.in")))
408 (replace 'check
409 (lambda _
410 (setenv "CC" "gcc")
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/*
423 ;; Also contains:
424 license:expat license:isc license:zlib)))))
425
426 (define-public dtc
427 (package
428 (name "dtc")
429 (version "1.6.0")
430 (source (origin
431 (method url-fetch)
432 (uri (string-append
433 "mirror://kernel.org/software/utils/dtc/"
434 "dtc-" version ".tar.xz"))
435 (sha256
436 (base32
437 "0bf8801z6fpd1gz9mxd5pqqj8nq101x393cyw8rpkc712w13nl0h"))))
438 (build-system gnu-build-system)
439 (native-inputs
440 `(("bison" ,bison)
441 ("flex" ,flex)
442 ("libyaml" ,libyaml)
443 ("pkg-config" ,pkg-config)
444 ("swig" ,swig)
445 ("valgrind" ,valgrind)))
446 (inputs
447 `(("python" ,python)))
448 (arguments
449 `(#:make-flags
450 (list (string-append "CC=" ,(cc-for-target))
451
452 ;; /bin/fdt{get,overlay,put} need help finding libfdt.so.1.
453 (string-append "LDFLAGS=-Wl,-rpath="
454 (assoc-ref %outputs "out") "/lib")
455
456 (string-append "PREFIX=" (assoc-ref %outputs "out"))
457 (string-append "SETUP_PREFIX=" (assoc-ref %outputs "out"))
458 "INSTALL=install")
459 #:phases
460 (modify-phases %standard-phases
461 (add-after 'unpack 'patch-pkg-config
462 (lambda _
463 (substitute* '("Makefile"
464 "tests/run_tests.sh")
465 (("pkg-config")
466 (or (which "pkg-config")
467 (string-append ,(%current-target-system)
468 "-pkg-config"))))
469 #t))
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+)))
477
478 (define u-boot
479 (package
480 (name "u-boot")
481 (version "2021.04")
482 (source (origin
483 (method url-fetch)
484 (uri (string-append
485 "https://ftp.denx.de/pub/u-boot/"
486 "u-boot-" version ".tar.bz2"))
487 (sha256
488 (base32
489 "06p1vymf0dl6jc2xy5w7p42mpgppa46lmpm2ishmgsycnldqnhqd"))))
490 (native-inputs
491 `(("bc" ,bc)
492 ("bison" ,bison)
493 ("dtc" ,dtc)
494 ("flex" ,flex)
495 ("lz4" ,lz4)
496 ("perl" ,perl)
497 ("python" ,python)
498 ("python-coverage" ,python-coverage)
499 ("python-pytest" ,python-pytest)
500 ("swig" ,swig)))
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+)))
507
508 (define-public u-boot-tools
509 (package
510 (inherit u-boot)
511 (name "u-boot-tools")
512 (native-inputs
513 `(("sdl2" ,sdl2)
514 ,@(package-native-inputs u-boot)))
515 (arguments
516 `(#:make-flags '("HOSTCC=gcc")
517 #:test-target "tcheck"
518 #:phases
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"
526 (("'cc'") "'gcc'"))
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"
542 (("def test_ctrl_c")
543 "@pytest.mark.skip(reason='Guix has problems with SIGINT')
544 def test_ctrl_c"))
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)
550 (substitute* file
551 ;; Disable features that require OpenSSL due
552 ;; to GPL/Openssl license incompatibilities.
553 ;; See https://bugs.gnu.org/34717 for
554 ;; details.
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
558 ;; in u-boot-tools.
559 (("CONFIG_SOUND=y") "CONFIG_SOUND=n")))
560 (find-files "configs" "sandbox_.*defconfig$|tools-only_defconfig"))
561 #t))
562 (replace 'configure
563 (lambda* (#:key make-flags #:allow-other-keys)
564 (apply invoke "make" "tools-only_defconfig" make-flags)))
565 (replace 'build
566 (lambda* (#:key inputs make-flags #:allow-other-keys)
567 (apply invoke "make" "tools-all" make-flags)))
568 (replace 'install
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))
574 '("tools/netconsole"
575 "tools/jtagconsole"
576 "tools/gen_eth_addr"
577 "tools/gen_ethaddr_crc"
578 "tools/img2srec"
579 "tools/mkenvimage"
580 "tools/dumpimage"
581 "tools/mkimage"
582 "tools/proftool"
583 "tools/fdtgrep"
584 "tools/env/fw_printenv"
585 "tools/sunxi-spl-image-builder"))
586 #t)))
587 (delete 'check)
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
592 ;; assume x86_64.
593 ,@(if (string-match "^x86_64-linux"
594 (or (%current-target-system)
595 (%current-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))))
602 '()))))
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.")))
606
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)))))
612 (package
613 (inherit u-boot)
614 (name (string-append "u-boot-"
615 (string-replace-substring (string-downcase board)
616 "_" "-")))
617 (native-inputs
618 `(,@(if (not (same-arch?))
619 `(("cross-gcc" ,(cross-gcc triplet))
620 ("cross-binutils" ,(cross-binutils triplet)))
621 `())
622 ,@(package-native-inputs u-boot)))
623 (arguments
624 `(#:modules ((ice-9 ftw)
625 (srfi srfi-1)
626 (guix build utils)
627 (guix build gnu-build-system))
628 #:test-target "test"
629 #:make-flags
630 (list "HOSTCC=gcc"
631 ,@(if (not (same-arch?))
632 `((string-append "CROSS_COMPILE=" ,triplet "-"))
633 '()))
634 #:phases
635 (modify-phases %standard-phases
636 (replace 'configure
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))
641 (begin
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)
649 "- ~A\n"
650 (string-drop-right file-name
651 suffix-len))))
652 (sort entries string-ci<)))
653 (error "Invalid boardname ~s." ,board))))))
654 (replace 'install
655 (lambda* (#:key outputs #:allow-other-keys)
656 (let* ((out (assoc-ref outputs "out"))
657 (libexec (string-append out "/libexec"))
658 (uboot-files (append
659 (remove
660 ;; Those would not be reproducible
661 ;; because of the randomness used
662 ;; to produce them.
663 ;; It's expected that the user will
664 ;; use u-boot-tools to generate them
665 ;; instead.
666 (lambda (name)
667 (string-suffix?
668 "sunxi-spl-with-ecc.bin"
669 name))
670 (find-files "." ".*\\.(bin|efi|img|spl|itb|dtb|rksd)$"))
671 (find-files "." "^(MLO|SPL)$"))))
672 (mkdir-p libexec)
673 (install-file ".config" libexec)
674 ;; Useful for "qemu -kernel".
675 (install-file "u-boot" libexec)
676 (for-each
677 (lambda (file)
678 (let ((target-file (string-append libexec "/" file)))
679 (mkdir-p (dirname target-file))
680 (copy-file file target-file)))
681 uboot-files)
682 #t)))))))))
683
684 (define-public u-boot-vexpress
685 (make-u-boot-package "vexpress_ca9x4" "arm-linux-gnueabihf"))
686
687 (define-public u-boot-malta
688 (make-u-boot-package "malta" "mips64el-linux-gnuabi64"))
689
690 (define-public u-boot-am335x-boneblack
691 (let ((base (make-u-boot-package "am335x_evm" "arm-linux-gnueabihf")))
692 (package
693 (inherit base)
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).
697
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.")
701 (arguments
702 (substitute-keyword-arguments (package-arguments base)
703 ((#:phases phases)
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.
709 (lambda _
710 (substitute* "configs/am335x_evm_defconfig"
711 (("CONFIG_OF_LIST=.*$") "CONFIG_OF_LIST=\"am335x-evm am335x-boneblack\"\n"))
712 #t)))))))))
713
714 (define-public u-boot-am335x-evm
715 (make-u-boot-package "am335x_evm" "arm-linux-gnueabihf"))
716
717 (define-public (make-u-boot-sunxi64-package board triplet)
718 (let ((base (make-u-boot-package board triplet)))
719 (package
720 (inherit base)
721 (arguments
722 (substitute-keyword-arguments (package-arguments base)
723 ((#:phases phases)
724 `(modify-phases ,phases
725 (add-after 'unpack 'set-environment
726 (lambda* (#:key native-inputs inputs #:allow-other-keys)
727 (let ((bl31
728 (string-append
729 (assoc-ref (or native-inputs inputs) "firmware")
730 "/bl31.bin")))
731 (setenv "BL31" bl31)
732 ;; This is necessary when we're using the bundled dtc.
733 ;(setenv "PATH" (string-append (getenv "PATH") ":"
734 ; "scripts/dtc"))
735 )
736 #t))))))
737 (native-inputs
738 `(("firmware" ,arm-trusted-firmware-sun50i-a64)
739 ,@(package-native-inputs base))))))
740
741 (define-public u-boot-pine64-plus
742 (make-u-boot-sunxi64-package "pine64_plus" "aarch64-linux-gnu"))
743
744 (define-public u-boot-pine64-lts
745 (make-u-boot-sunxi64-package "pine64-lts" "aarch64-linux-gnu"))
746
747 (define-public u-boot-pinebook
748 (let ((base (make-u-boot-sunxi64-package "pinebook" "aarch64-linux-gnu")))
749 (package
750 (inherit base)
751 (arguments
752 (substitute-keyword-arguments (package-arguments base)
753 ((#:phases phases)
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/
758 (lambda _
759 (substitute* "configs/pinebook_defconfig"
760 (("CONFIG_VIDEO_BRIDGE_ANALOGIX_ANX6345=y") "CONFIG_VIDEO_BRIDGE_ANALOGIX_ANX6345=y\nCONFIG_VIDEO_BPP32=y"))
761 #t)))))))))
762
763 (define-public u-boot-bananapi-m2-ultra
764 (make-u-boot-package "Bananapi_M2_Ultra" "arm-linux-gnueabihf"))
765
766 (define-public u-boot-a20-olinuxino-lime
767 (make-u-boot-package "A20-OLinuXino-Lime" "arm-linux-gnueabihf"))
768
769 (define-public u-boot-a20-olinuxino-lime2
770 (make-u-boot-package "A20-OLinuXino-Lime2" "arm-linux-gnueabihf"))
771
772 (define-public u-boot-a20-olinuxino-micro
773 (make-u-boot-package "A20-OLinuXino_MICRO" "arm-linux-gnueabihf"))
774
775 (define-public u-boot-nintendo-nes-classic-edition
776 (make-u-boot-package "Nintendo_NES_Classic_Edition" "arm-linux-gnueabihf"))
777
778 (define-public u-boot-wandboard
779 (make-u-boot-package "wandboard" "arm-linux-gnueabihf"))
780
781 (define-public u-boot-mx6cuboxi
782 (make-u-boot-package "mx6cuboxi" "arm-linux-gnueabihf"))
783
784 (define-public u-boot-novena
785 (let ((base (make-u-boot-package "novena" "arm-linux-gnueabihf")))
786 (package
787 (inherit base)
788 (description "U-Boot is a bootloader used mostly for ARM boards. It
789 also initializes the boards (RAM etc).
790
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.")
793 (arguments
794 (substitute-keyword-arguments (package-arguments base)
795 ((#:phases phases)
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.
800 (lambda _
801 (substitute* "configs/novena_defconfig"
802 (("CONFIG_SPL_FS_FAT=y") "# CONFIG_SPL_FS_FAT is not set"))
803 #t)))))))))
804
805 (define-public u-boot-cubieboard
806 (make-u-boot-package "Cubieboard" "arm-linux-gnueabihf"))
807
808 (define-public u-boot-cubietruck
809 (make-u-boot-package "Cubietruck" "arm-linux-gnueabihf"))
810
811 (define-public u-boot-puma-rk3399
812 (let ((base (make-u-boot-package "puma-rk3399" "aarch64-linux-gnu")))
813 (package
814 (inherit base)
815 (arguments
816 (substitute-keyword-arguments (package-arguments base)
817 ((#:phases phases)
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")
822 "/bl31.elf"))
823 #t))
824 ;; Phases do not succeed on the bl31 ELF.
825 (delete 'strip)
826 (delete 'validate-runpath)))))
827 (native-inputs
828 `(("firmware" ,arm-trusted-firmware-rk3399)
829 ,@(package-native-inputs base))))))
830
831 (define-public u-boot-qemu-riscv64
832 (make-u-boot-package "qemu-riscv64" "riscv64-linux-gnu"))
833
834 (define-public u-boot-qemu-riscv64-smode
835 (let ((base (make-u-boot-package "qemu-riscv64_smode" "riscv64-linux-gnu")))
836 (package
837 (inherit base)
838 (source (origin
839 (inherit (package-source u-boot))
840 (patches
841 (search-patches "u-boot-riscv64-fix-extlinux.patch")))))))
842
843 (define-public u-boot-sifive-fu540
844 (make-u-boot-package "sifive_fu540" "riscv64-linux-gnu"))
845
846 (define-public u-boot-rock64-rk3328
847 (let ((base (make-u-boot-package "rock64-rk3328" "aarch64-linux-gnu")))
848 (package
849 (inherit base)
850 (arguments
851 (substitute-keyword-arguments (package-arguments base)
852 ((#:phases phases)
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")
857 "/bl31.elf")))
858 (setenv "BL31" bl31))
859 #t))))))
860 (native-inputs
861 `(("firmware" ,arm-trusted-firmware-rk3328)
862 ,@(package-native-inputs base))))))
863
864 (define-public u-boot-firefly-rk3399
865 (let ((base (make-u-boot-package "firefly-rk3399" "aarch64-linux-gnu")))
866 (package
867 (inherit base)
868 (arguments
869 (substitute-keyword-arguments (package-arguments base)
870 ((#:phases phases)
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")
875 "/bl31.elf"))
876 #t))
877 ;; Phases do not succeed on the bl31 ELF.
878 (delete 'strip)
879 (delete 'validate-runpath)))))
880 (native-inputs
881 `(("firmware" ,arm-trusted-firmware-rk3399)
882 ,@(package-native-inputs base))))))
883
884 (define-public u-boot-rockpro64-rk3399
885 (let ((base (make-u-boot-package "rockpro64-rk3399" "aarch64-linux-gnu")))
886 (package
887 (inherit base)
888 (arguments
889 (substitute-keyword-arguments (package-arguments base)
890 ((#:phases phases)
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
895 (lambda _
896 (substitute* "configs/rockpro64-rk3399_defconfig"
897 (("CONFIG_USE_PREBOOT=y") "CONFIG_USE_PREBOOT=n"))
898 #t))
899 (add-after 'patch-rockpro64-config 'set-environment
900 (lambda* (#:key inputs #:allow-other-keys)
901 (setenv "BL31" (string-append (assoc-ref inputs "firmware")
902 "/bl31.elf"))
903 #t))
904 ;; Phases do not succeed on the bl31 ELF.
905 (delete 'strip)
906 (delete 'validate-runpath)))))
907 (native-inputs
908 `(("firmware" ,arm-trusted-firmware-rk3399)
909 ,@(package-native-inputs base))))))
910
911 (define-public u-boot-pinebook-pro-rk3399
912 (let ((base (make-u-boot-package "pinebook-pro-rk3399" "aarch64-linux-gnu")))
913 (package
914 (inherit base)
915 (arguments
916 (substitute-keyword-arguments (package-arguments base)
917 ((#:phases phases)
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
922 (lambda _
923 (substitute* "configs/pinebook-pro-rk3399_defconfig"
924 (("CONFIG_USE_PREBOOT=y") "CONFIG_USE_PREBOOT=n"))
925 #t))
926 (add-after 'unpack 'set-environment
927 (lambda* (#:key inputs #:allow-other-keys)
928 (setenv "BL31" (string-append (assoc-ref inputs "firmware")
929 "/bl31.elf"))
930 #t))
931 ;; Phases do not succeed on the bl31 ELF.
932 (delete 'strip)
933 (delete 'validate-runpath)))))
934 (native-inputs
935 `(("firmware" ,arm-trusted-firmware-rk3399)
936 ,@(package-native-inputs base))))))
937
938 (define-public vboot-utils
939 (package
940 (name "vboot-utils")
941 (version "R63-10032.B")
942 (source (origin
943 ;; XXX: Snapshots are available but changes timestamps every download.
944 (method git-fetch)
945 (uri (git-reference
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"))
950 (sha256
951 (base32
952 "0h0m3l69vp9dr6xrs1p6y7ilkq3jq8jraw2z20kqfv7lvc9l1lxj"))
953 (patches
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)
958 (arguments
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
965 ;; QEMU for testing.
966 ,@(if (string-prefix? "arm"
967 (or (%current-target-system)
968 (%current-system)))
969 '("HOST_ARCH=arm")
970 '())
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"
982 (("prefix=/usr")
983 (string-append "prefix=" (assoc-ref outputs "out"))))
984 #t)))
985 (delete 'configure)
986 (add-before 'check 'patch-tests
987 (lambda _
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
993 ".drv-0/source")))
994 ;; Tests require write permissions to many of these files.
995 (for-each make-file-writable (find-files "tests/futility"))
996 #t))
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"))
1003 #t))))
1004 #:test-target "runtests"))
1005 (native-inputs
1006 `(("pkg-config" ,pkg-config)
1007
1008 ;; For tests.
1009 ("diffutils" ,diffutils)
1010 ("python@2" ,python-2)))
1011 (inputs
1012 `(("coreutils" ,coreutils)
1013 ("libyaml" ,libyaml)
1014 ("openssl" ,openssl)
1015 ("openssl:static" ,openssl "static")
1016 ("util-linux" ,util-linux "lib")))
1017 (home-page
1018 "https://dev.chromium.org/chromium-os/chromiumos-design-docs/verified-boot")
1019 (synopsis "ChromiumOS verified boot utilities")
1020 (description
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
1024 tools, and more.")
1025 (license license:bsd-3)))
1026
1027 (define-public os-prober
1028 (package
1029 (name "os-prober")
1030 (version "1.78")
1031 (source
1032 (origin
1033 (method url-fetch)
1034 (uri (string-append "mirror://debian/pool/main/o/os-prober/os-prober_"
1035 version ".tar.xz"))
1036 (sha256
1037 (base32 "1sahk72blsrlirly4xlwa8jfxrpwagyn7b81p92q2s9m218rz43f"))))
1038 (build-system gnu-build-system)
1039 (arguments
1040 `(#:modules ((guix build gnu-build-system)
1041 (guix build utils)
1042 (ice-9 regex) ; for string-match
1043 (srfi srfi-26)) ; for cut
1044 #:make-flags
1045 (list ,(string-append "CC=" (cc-for-target)))
1046 #:tests? #f ; no tests
1047 #:phases
1048 (modify-phases %standard-phases
1049 (replace 'configure
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"))
1055 #t))
1056 (replace 'install
1057 (lambda* (#:key outputs #:allow-other-keys)
1058 (define (find-files-non-recursive directory)
1059 (find-files directory
1060 (lambda (file stat)
1061 (string-match (string-append "^" directory "/[^/]*$")
1062 file))
1063 #:directories? #t))
1064
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"))
1075 (for-each
1076 (lambda (directory)
1077 (for-each
1078 (lambda (file)
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"))
1087 #t))))))
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+)))
1095
1096 (define-public ipxe
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.
1099 ;;
1100 ;; TODO: Bump this timestamp at each modifications of the package (not only
1101 ;; for updates) by running: date +%s.
1102 (let ((timestamp "1591706427"))
1103 (package
1104 (name "ipxe")
1105 (version "1.21.1")
1106 (source (origin
1107 (method git-fetch)
1108 (uri (git-reference
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"))
1113 (sha256
1114 (base32
1115 "1pkf1n1c0rdlzfls8fvjvi1sd9xjd9ijqlyz3wigr70ijcv6x8i9"))))
1116 (build-system gnu-build-system)
1117 (arguments
1118 `(#:modules ((guix build utils)
1119 (guix build gnu-build-system)
1120 (guix base32)
1121 (ice-9 string-fun)
1122 (ice-9 regex)
1123 (rnrs bytevectors))
1124 #:imported-modules ((guix base32)
1125 ,@%gnu-build-system-modules)
1126 #:make-flags
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.
1132 (let ((build-id
1133 (lambda (out)
1134 (let* ((nix-store (string-append
1135 (or (getenv "NIX_STORE") "/gnu/store")
1136 "/"))
1137 (filename
1138 (string-replace-substring out nix-store ""))
1139 (hash (match:substring (string-match "[0-9a-z]{32}"
1140 filename)))
1141 (bv (nix-base32-string->bytevector hash)))
1142 (format #f "0x~x"
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"
1148
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")
1155
1156 ;; Build reproducibly.
1157 (string-append "BUILD_ID_CMD=echo -n " (build-id out))
1158 (string-append "BUILD_TIMESTAMP=" ,timestamp)
1159 "everything"))
1160 #:phases
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
1165 (lambda _
1166 (substitute* "config/general.h"
1167 (("^//(#define PING_CMD.*)" _ uncommented) uncommented)
1168 (("^//(#define IMAGE_TRUST_CMD.*)" _ uncommented)
1169 uncommented)
1170 (("^#undef.*(DOWNLOAD_PROTO_HTTPS.*)" _ option)
1171 (string-append "#define " option))
1172 (("^#undef.*(DOWNLOAD_PROTO_NFS.*)" _ option)
1173 (string-append "#define " option)))
1174 #t))
1175 (delete 'configure) ; no configure script
1176 (replace 'install
1177 (lambda* (#:key outputs #:allow-other-keys)
1178 (let* ((out (assoc-ref outputs "out"))
1179 (ipxe (string-append out "/lib/ipxe"))
1180 (exts-re
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
1185 (map (lambda (dir)
1186 (find-files dir exts-re)) dirs))))
1187 (for-each (lambda (file)
1188 (let* ((subdir (dirname file))
1189 (fn (basename file))
1190 (tgtsubdir (cond
1191 ((string=? "bin" subdir) "")
1192 ((string-prefix? "bin-" subdir)
1193 (string-drop subdir 4)))))
1194 (install-file file
1195 (string-append ipxe "/" tgtsubdir))))
1196 files))
1197 #t))
1198 (add-after 'install 'leave-source-directory
1199 (lambda _ (chdir "..") #t)))
1200 #:tests? #f)) ; no test suite
1201 (native-inputs
1202 `(("perl" ,perl)
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+))))
1215