gnu: emacs-consult: Fix grammar.
[jackhill/guix/guix.git] / gnu / packages / bootloaders.scm
CommitLineData
65d8b777 1;;; GNU Guix --- Functional package management for GNU
ab100b90 2;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
0a2a7053 3;;; Copyright © 2015, 2018 Mark H Weaver <mhw@netris.org>
f0150f87 4;;; Copyright © 2015 Leo Famulari <leo@famulari.name>
d613991a 5;;; Copyright © 2016, 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
a60f1319 6;;; Copyright © 2016, 2017, 2018 Marius Bakke <mbakke@fastmail.com>
862e38d5
DC
7;;; Copyright © 2016, 2017 Danny Milosavljevic <dannym@scratchpost.org>
8;;; Copyright © 2016, 2017 David Craven <david@craven.ch>
149666df 9;;; Copyright © 2017, 2018, 2020 Efraim Flashner <efraim@flashner.co.il>
aeed7218 10;;; Copyright © 2018, 2019, 2020, 2021 Tobias Geerinckx-Rice <me@tobias.gr>
ab100b90 11;;; Copyright © 2019 nee <nee@cock.li>
af58b275 12;;; Copyright © 2019 Mathieu Othacehe <m.othacehe@gmail.com>
5664a471 13;;; Copyright © 2020 Björn Höfling <bjoern.hoefling@bjoernhoefling.de>
5327b399 14;;; Copyright © 2018, 2019, 2020 Vagrant Cascadian <vagrant@debian.org>
c10e8cf7 15;;; Copyright © 2020 Pierre Langlois <pierre.langlois@gmx.com>
aeed7218
VL
16;;; Copyright © 2021 Vincent Legoll <vincent.legoll@gmail.com>
17;;; Copyright © 2021 Brice Waegeneire <brice@waegenei.re>
65d8b777
LC
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
862e38d5 34(define-module (gnu packages bootloaders)
65d8b777 35 #:use-module (gnu packages)
862e38d5 36 #:use-module (gnu packages admin)
178e5500 37 #:use-module (gnu packages algebra)
862e38d5 38 #:use-module (gnu packages assembly)
a60f1319 39 #:use-module (gnu packages base)
7febe3a2 40 #:use-module (gnu packages disk)
65d8b777 41 #:use-module (gnu packages bison)
862e38d5 42 #:use-module (gnu packages cdrom)
65212c42 43 #:use-module (gnu packages check)
0c7707d5 44 #:use-module (gnu packages compression)
862e38d5
DC
45 #:use-module (gnu packages cross-base)
46 #:use-module (gnu packages disk)
29be6cfb 47 #:use-module (gnu packages firmware)
862e38d5 48 #:use-module (gnu packages flex)
a86177d6 49 #:use-module (gnu packages fontutils)
f074f5e8 50 #:use-module (gnu packages gcc)
862e38d5 51 #:use-module (gnu packages gettext)
65d8b777 52 #:use-module (gnu packages linux)
862e38d5 53 #:use-module (gnu packages man)
444f9dcc 54 #:use-module (gnu packages mtools)
862e38d5 55 #:use-module (gnu packages ncurses)
96b714f5 56 #:use-module (gnu packages perl)
a60f1319 57 #:use-module (gnu packages pkg-config)
96b714f5 58 #:use-module (gnu packages python)
58301666 59 #:use-module (gnu packages texinfo)
a60f1319 60 #:use-module (gnu packages tls)
65212c42 61 #:use-module (gnu packages sdl)
12c613b5 62 #:use-module (gnu packages swig)
5d706f18 63 #:use-module (gnu packages valgrind)
59132b80 64 #:use-module (gnu packages virtualization)
ab100b90 65 #:use-module (gnu packages xorg)
a60f1319 66 #:use-module (gnu packages web)
862e38d5
DC
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)
63087721
EF
72 #:use-module (guix utils)
73 #:use-module (srfi srfi-1)
a7c87169
MW
74 #:use-module (srfi srfi-26)
75 #:use-module (ice-9 regex))
65d8b777 76
9b24c768
LC
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
65d8b777
LC
88(define-public grub
89 (package
90 (name "grub")
069ab3bb 91 (version "2.04")
65d8b777
LC
92 (source (origin
93 (method url-fetch)
3586a3e9 94 (uri (string-append "mirror://gnu/grub/grub-" version ".tar.xz"))
65d8b777
LC
95 (sha256
96 (base32
069ab3bb 97 "0zgp5m3hmc9jh8wpjx6czzkh5id2y8n1k823x2mjvm2sk6b28ag5"))
654de94e
JN
98 (patches (search-patches
99 "grub-efi-fat-serial-number.patch"
15135a5e 100 "grub-setup-root.patch"
d613991a
JN
101 "grub-verifiers-Blocklist-fallout-cleanup.patch"
102 "grub-cross-system-i686.patch"))))
65d8b777
LC
103 (build-system gnu-build-system)
104 (arguments
069ab3bb
TGR
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
358db004 111 (add-after 'unpack 'patch-stuff
7c353424 112 (lambda* (#:key native-inputs inputs #:allow-other-keys)
04e0eac1
MW
113 (substitute* "grub-core/Makefile.in"
114 (("/bin/sh") (which "sh")))
65d8b777 115
358db004
LC
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.
149666df
EF
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\""))))
358db004 126
04e0eac1 127 ;; Make the font visible.
7c353424
MO
128 (copy-file (assoc-ref (or native-inputs inputs)
129 "unifont")
130 "unifont.bdf.gz")
04e0eac1 131 (system* "gunzip" "unifont.bdf.gz")
ab100b90 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 ")))
23a53a95 138 #t))
34a6f123
EF
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.
77b7d990
EF
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"))))
34a6f123 152 #t))
23a53a95
LF
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"))
069ab3bb
TGR
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"))
56f0feb6 168 #t)))
66f76912
EF
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)))))
65d8b777 174 (inputs
10da75df
LC
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.)
654de94e
JN
179 ,@(if (member (or (%current-target-system)
180 (%current-system))
181 (package-supported-systems lvm2))
182 `(("lvm2" ,lvm2))
183 '())
10da75df
LC
184
185 ;; Depend on mdadm, which is invoked by 'grub-probe' and 'grub-install'
186 ;; to determine whether the root file system is RAID.
654de94e
JN
187 ,@(if (member (or (%current-target-system)
188 (%current-system))
189 (package-supported-systems mdadm))
190 `(("mdadm" ,mdadm))
191 '())
10da75df 192
ab100b90 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
35014c40
TGR
197 ;; Needed for ‘grub-mount’, the only reliable way to tell whether a given
198 ;; file system will be readable by GRUB without rebooting.
654de94e
JN
199 ,@(if (member (or (%current-target-system)
200 (%current-system))
201 (package-supported-systems fuse))
202 `(("fuse" ,fuse))
203 '())
35014c40 204
65d8b777
LC
205 ("freetype" ,freetype)
206 ;; ("libusb" ,libusb)
01eafd38 207 ("ncurses" ,ncurses)))
65d8b777 208 (native-inputs
0a2a7053
MW
209 `(("pkg-config" ,pkg-config)
210 ("unifont" ,unifont)
9b24c768 211 ("bison" ,bison)
f142c077 212 ("flex" ,flex)
58301666
MW
213 ("texinfo" ,texinfo)
214 ("help2man" ,help2man)
34a6f123 215 ("freetype" ,freetype) ; native version needed for build-grub-mkfont
65d8b777 216
a7c87169
MW
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
65d8b777
LC
233 ;; Dependencies for the test suite. The "real" QEMU is needed here,
234 ;; because several targets are used.
7febe3a2 235 ("parted" ,parted)
654de94e
JN
236 ,@(if (member (%current-system) (package-supported-systems qemu-minimal))
237 `(("qemu" ,qemu-minimal))
238 '())
65d8b777 239 ("xorriso" ,xorriso)))
175b259c 240 (home-page "https://www.gnu.org/software/grub/")
79c311b8 241 (synopsis "GRand Unified Boot loader")
65d8b777 242 (description
a22dc0c4 243 "GRUB is a multiboot bootloader. It is used for initially loading the
35b9e423 244kernel of an operating system and then transferring control to it. The kernel
c5779c93 245then goes on to load the rest of the operating system. As a multiboot
574e86f9
LC
246bootloader, GRUB handles the presence of multiple operating systems installed
247on the same computer; upon booting the computer, the user is presented with a
a22dc0c4 248menu to select one of the installed operating systems.")
3f73aa1a 249 (license license:gpl3+)
99effc8f 250 (properties '((cpe-name . "grub2")))))
acb5f7c3 251
0c962369
JN
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
097b7255
LC
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")))
0c962369 274
097b7255
LC
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")
0c962369 280
097b7255 281 #t))))))))
0c962369 282
acb5f7c3
MB
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)
c695fb76 290 ("mtools" ,mtools)
acb5f7c3
MB
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".
acb5f7c3 296 ,@(substitute-keyword-arguments (package-arguments grub)
46ff2dbb 297 ((#:tests? _ #f) #f)
ef753a1a
LC
298 ((#:configure-flags flags ''())
299 `(cons "--with-platform=efi" ,flags))
acb5f7c3
MB
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")))
444f9dcc
DM
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))))))))))
96b714f5 321
dd4b7476
DM
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)
db34d4bb
EF
349 (if (not (or (string-prefix? "." basename)
350 (file-exists? (string-append output-dir "/" basename))))
dd4b7476
DM
351 (symlink (string-append input-dir "/" basename)
352 (string-append output-dir "/" basename))))
353 (scandir input-dir))
354 #t)))))))))
355
96b714f5
DC
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
bb93042c 376 `(("libuuid" ,util-linux "lib")
0b4dbb40 377 ("mtools" ,mtools)))
96b714f5
DC
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
0b4dbb40 392 (lambda* (#:key inputs #:allow-other-keys)
96b714f5
DC
393 (substitute* (find-files "." "Makefile.*|ppmtolss16")
394 (("/bin/pwd") (which "pwd"))
395 (("/bin/echo") (which "echo"))
396 (("/usr/bin/perl") (which "perl")))
0b4dbb40
LC
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"))))
96b714f5
DC
403 #t))
404 (delete 'configure)
405 (add-before 'build 'set-permissions
406 (lambda _
60d8db74 407 (invoke "chmod" "a+w" "utils/isohybrid.in")))
96b714f5
DC
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/") ""))
60d8db74 414 (invoke "make" "unittest"))))))
0f304ba7 415 (home-page "https://www.syslinux.org")
96b714f5
DC
416 (synopsis "Lightweight Linux bootloader")
417 (description "Syslinux is a lightweight Linux bootloader.")
8d3f604d
EF
418 ;; The Makefile specifically targets i386 and x86_64 using nasm.
419 (supported-systems '("i686-linux" "x86_64-linux"))
96b714f5
DC
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)))))
862e38d5
DC
425
426(define-public dtc
427 (package
428 (name "dtc")
4ed96d68 429 (version "1.6.0")
862e38d5
DC
430 (source (origin
431 (method url-fetch)
432 (uri (string-append
3b4efb1f 433 "mirror://kernel.org/software/utils/dtc/"
862e38d5
DC
434 "dtc-" version ".tar.xz"))
435 (sha256
436 (base32
4ed96d68 437 "0bf8801z6fpd1gz9mxd5pqqj8nq101x393cyw8rpkc712w13nl0h"))))
862e38d5
DC
438 (build-system gnu-build-system)
439 (native-inputs
440 `(("bison" ,bison)
12c613b5 441 ("flex" ,flex)
8cd10b22
VC
442 ("libyaml" ,libyaml)
443 ("pkg-config" ,pkg-config)
5d706f18
VC
444 ("swig" ,swig)
445 ("valgrind" ,valgrind)))
12c613b5 446 (inputs
5664a471 447 `(("python" ,python)))
862e38d5
DC
448 (arguments
449 `(#:make-flags
6cc86492 450 (list (string-append "CC=" ,(cc-for-target))
91af1031
TGR
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
862e38d5 456 (string-append "PREFIX=" (assoc-ref %outputs "out"))
12c613b5 457 (string-append "SETUP_PREFIX=" (assoc-ref %outputs "out"))
862e38d5
DC
458 "INSTALL=install")
459 #:phases
460 (modify-phases %standard-phases
6cc86492
EF
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))
d95bb295 470 (delete 'configure)))) ; no configure script
862e38d5
DC
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
475tree 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")
98067662 481 (version "2021.04")
862e38d5
DC
482 (source (origin
483 (method url-fetch)
484 (uri (string-append
98067662 485 "https://ftp.denx.de/pub/u-boot/"
862e38d5
DC
486 "u-boot-" version ".tar.bz2"))
487 (sha256
488 (base32
98067662 489 "06p1vymf0dl6jc2xy5w7p42mpgppa46lmpm2ishmgsycnldqnhqd"))))
862e38d5
DC
490 (native-inputs
491 `(("bc" ,bc)
336c4a4b 492 ("bison" ,bison)
53e290df 493 ("dtc" ,dtc)
336c4a4b 494 ("flex" ,flex)
0c7707d5 495 ("lz4" ,lz4)
634b0e28
VC
496 ("perl" ,perl)
497 ("python" ,python)
498 ("python-coverage" ,python-coverage)
499 ("python-pytest" ,python-pytest)
f074f5e8 500 ("swig" ,swig)))
862e38d5 501 (build-system gnu-build-system)
3e63a83c 502 (home-page "https://www.denx.de/wiki/U-Boot/")
862e38d5
DC
503 (synopsis "ARM bootloader")
504 (description "U-Boot is a bootloader used mostly for ARM boards. It
505also initializes the boards (RAM etc).")
506 (license license:gpl2+)))
507
2676628f
DM
508(define-public u-boot-tools
509 (package
510 (inherit u-boot)
511 (name "u-boot-tools")
6b125371
DM
512 (native-inputs
513 `(("sdl2" ,sdl2)
514 ,@(package-native-inputs u-boot)))
2676628f 515 (arguments
65212c42 516 `(#:make-flags '("HOSTCC=gcc")
e9545e6d 517 #:test-target "tcheck"
2676628f
DM
518 #:phases
519 (modify-phases %standard-phases
65212c42
DM
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'"))
e1d1ec14 527 (substitute* "tools/patman/test_util.py"
e9545e6d
VC
528 ;; python3-coverage is simply called coverage in guix.
529 (("python3-coverage") "coverage"))
65212c42
DM
530 (substitute* "test/run"
531 ;; Make it easier to find test failures.
532 (("#!/bin/bash") "#!/bin/bash -x")
65212c42
DM
533 ;; This test would require git.
534 (("\\./tools/patman/patman") (which "true"))
634b0e28
VC
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\"")
65212c42
DM
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')
544def test_ctrl_c"))
6f5be83c
VC
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=."))
4da4e952
VC
549 (for-each (lambda (file)
550 (substitute* file
e9545e6d
VC
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")
fb0aeaac
VC
557 ;; This test requires a sound system, which is un-used
558 ;; in u-boot-tools.
4da4e952 559 (("CONFIG_SOUND=y") "CONFIG_SOUND=n")))
634b0e28 560 (find-files "configs" "sandbox_.*defconfig$|tools-only_defconfig"))
65212c42 561 #t))
2676628f
DM
562 (replace 'configure
563 (lambda* (#:key make-flags #:allow-other-keys)
634b0e28 564 (apply invoke "make" "tools-only_defconfig" make-flags)))
2676628f
DM
565 (replace 'build
566 (lambda* (#:key inputs make-flags #:allow-other-keys)
9e84a4d6 567 (apply invoke "make" "tools-all" make-flags)))
2676628f
DM
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"
10186ee2
DM
584 "tools/env/fw_printenv"
585 "tools/sunxi-spl-image-builder"))
65212c42
DM
586 #t)))
587 (delete 'check)
588 (add-after 'install 'check
589 (lambda* (#:key make-flags test-target #:allow-other-keys)
6f5be83c
VC
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 '()))))
2676628f
DM
603 (description "U-Boot is a bootloader used mostly for ARM boards. It
604also initializes the boards (RAM etc). This package provides its
605board-independent tools.")))
606
4ce4fc50 607(define-public (make-u-boot-package board triplet)
862e38d5 608 "Returns a u-boot package for BOARD cross-compiled for TRIPLET."
6bfcb729
LC
609 (let ((same-arch? (lambda ()
610 (string=? (%current-system)
611 (gnu-triplet->nix-system triplet)))))
3bfee8ff
EF
612 (package
613 (inherit u-boot)
df8a9096
DM
614 (name (string-append "u-boot-"
615 (string-replace-substring (string-downcase board)
616 "_" "-")))
3bfee8ff 617 (native-inputs
6bfcb729 618 `(,@(if (not (same-arch?))
b8806e13 619 `(("cross-gcc" ,(cross-gcc triplet))
3bfee8ff 620 ("cross-binutils" ,(cross-binutils triplet)))
b8806e13 621 `())
3bfee8ff
EF
622 ,@(package-native-inputs u-boot)))
623 (arguments
37297674
EF
624 `(#:modules ((ice-9 ftw)
625 (srfi srfi-1)
626 (guix build utils)
627 (guix build gnu-build-system))
3bfee8ff
EF
628 #:test-target "test"
629 #:make-flags
630 (list "HOSTCC=gcc"
6bfcb729 631 ,@(if (not (same-arch?))
3bfee8ff
EF
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))
8f43bdd9 640 (apply invoke "make" `(,@make-flags ,config-name))
3bfee8ff 641 (begin
ac30d18c
DM
642 (display "Invalid board name. Valid board names are:"
643 (current-error-port))
30ef146c
DM
644 (let ((suffix-len (string-length "_defconfig"))
645 (entries (scandir "configs")))
646 (for-each (lambda (file-name)
647 (when (string-suffix? "_defconfig" file-name)
ac30d18c 648 (format (current-error-port)
30ef146c
DM
649 "- ~A\n"
650 (string-drop-right file-name
651 suffix-len))))
ee3c8fbe 652 (sort entries string-ci<)))
bdd235b3 653 (error "Invalid boardname ~s." ,board))))))
3bfee8ff 654 (replace 'install
9b94ced4 655 (lambda* (#:key outputs #:allow-other-keys)
3bfee8ff
EF
656 (let* ((out (assoc-ref outputs "out"))
657 (libexec (string-append out "/libexec"))
dd208b93 658 (uboot-files (append
a9446dde
DM
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)$"))
fd0b21d5 671 (find-files "." "^(MLO|SPL)$"))))
3bfee8ff 672 (mkdir-p libexec)
a32f9b59 673 (install-file ".config" libexec)
0fcfed39
DM
674 ;; Useful for "qemu -kernel".
675 (install-file "u-boot" libexec)
3bfee8ff
EF
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)))
d1af9a8c
DM
681 uboot-files)
682 #t)))))))))
862e38d5
DC
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
6b99afee
VC
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
696also initializes the boards (RAM etc).
697
698This U-Boot is built for the BeagleBone Black, which was removed upstream,
699adjusted from the am335x_evm build with several device trees removed so that
700it 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"))
4adeb3f6 716
0da3526d
VC
717(define-public (make-u-boot-sunxi64-package board triplet)
718 (let ((base (make-u-boot-package board triplet)))
29be6cfb
EF
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
db78fc06
MO
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")))
29be6cfb 731 (setenv "BL31" bl31)
35e427d1
DM
732 ;; This is necessary when we're using the bundled dtc.
733 ;(setenv "PATH" (string-append (getenv "PATH") ":"
734 ; "scripts/dtc"))
735 )
29be6cfb
EF
736 #t))))))
737 (native-inputs
95d91986 738 `(("firmware" ,arm-trusted-firmware-sun50i-a64)
29be6cfb
EF
739 ,@(package-native-inputs base))))))
740
0da3526d
VC
741(define-public u-boot-pine64-plus
742 (make-u-boot-sunxi64-package "pine64_plus" "aarch64-linux-gnu"))
743
af58b275
MO
744(define-public u-boot-pine64-lts
745 (make-u-boot-sunxi64-package "pine64-lts" "aarch64-linux-gnu"))
746
74e35e8c 747(define-public u-boot-pinebook
760dfc67
VC
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)))))))))
74e35e8c 762
e830c9d0 763(define-public u-boot-bananapi-m2-ultra
30aeb846
DM
764 (make-u-boot-package "Bananapi_M2_Ultra" "arm-linux-gnueabihf"))
765
c55c6985
DM
766(define-public u-boot-a20-olinuxino-lime
767 (make-u-boot-package "A20-OLinuXino-Lime" "arm-linux-gnueabihf"))
768
4b9e9abb
DM
769(define-public u-boot-a20-olinuxino-lime2
770 (make-u-boot-package "A20-OLinuXino-Lime2" "arm-linux-gnueabihf"))
771
a7bb327e
DM
772(define-public u-boot-a20-olinuxino-micro
773 (make-u-boot-package "A20-OLinuXino_MICRO" "arm-linux-gnueabihf"))
774
84ee3378
DM
775(define-public u-boot-nintendo-nes-classic-edition
776 (make-u-boot-package "Nintendo_NES_Classic_Edition" "arm-linux-gnueabihf"))
777
95a3422e
VC
778(define-public u-boot-wandboard
779 (make-u-boot-package "wandboard" "arm-linux-gnueabihf"))
780
adc61d72
VC
781(define-public u-boot-mx6cuboxi
782 (make-u-boot-package "mx6cuboxi" "arm-linux-gnueabihf"))
783
1b960787 784(define-public u-boot-novena
6e2bad00
VC
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
789also initializes the boards (RAM etc).
790
791This U-Boot is built for Novena. Be advised that this version, contrary
6b99afee 792to Novena upstream, does not load u-boot.img from the first partition.")
6e2bad00
VC
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"
6b99afee 802 (("CONFIG_SPL_FS_FAT=y") "# CONFIG_SPL_FS_FAT is not set"))
6e2bad00 803 #t)))))))))
1b960787 804
dd4fe0c2
DM
805(define-public u-boot-cubieboard
806 (make-u-boot-package "Cubieboard" "arm-linux-gnueabihf"))
807
a7d5ce94
JL
808(define-public u-boot-cubietruck
809 (make-u-boot-package "Cubietruck" "arm-linux-gnueabihf"))
810
6fe16577
VC
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
15990546
VC
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)))))
6fe16577 827 (native-inputs
15990546 828 `(("firmware" ,arm-trusted-firmware-rk3399)
6fe16577
VC
829 ,@(package-native-inputs base))))))
830
10f31af9
VC
831(define-public u-boot-qemu-riscv64
832 (make-u-boot-package "qemu-riscv64" "riscv64-linux-gnu"))
833
7e954f67 834(define-public u-boot-qemu-riscv64-smode
1f9fae00
VC
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")))))))
7e954f67 842
7d063645
VC
843(define-public u-boot-sifive-fu540
844 (make-u-boot-package "sifive_fu540" "riscv64-linux-gnu"))
845
2fce14af
VC
846(define-public u-boot-rock64-rk3328
847 (let ((base (make-u-boot-package "rock64-rk3328" "aarch64-linux-gnu")))
848 (package
849 (inherit base)
2fce14af
VC
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))
2fce14af
VC
859 #t))))))
860 (native-inputs
861 `(("firmware" ,arm-trusted-firmware-rk3328)
862 ,@(package-native-inputs base))))))
863
545ff7b7
VC
864(define-public u-boot-firefly-rk3399
865 (let ((base (make-u-boot-package "firefly-rk3399" "aarch64-linux-gnu")))
866 (package
867 (inherit base)
545ff7b7
VC
868 (arguments
869 (substitute-keyword-arguments (package-arguments base)
870 ((#:phases phases)
871 `(modify-phases ,phases
7d440cdb 872 (add-after 'unpack 'set-environment
545ff7b7
VC
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
fa747018
CN
884(define-public u-boot-rockpro64-rk3399
885 (let ((base (make-u-boot-package "rockpro64-rk3399" "aarch64-linux-gnu")))
886 (package
887 (inherit base)
5327b399
VC
888 (arguments
889 (substitute-keyword-arguments (package-arguments base)
890 ((#:phases phases)
891 `(modify-phases ,phases
21961290
CN
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
5327b399
VC
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)
fa747018
CN
915 (arguments
916 (substitute-keyword-arguments (package-arguments base)
917 ((#:phases phases)
918 `(modify-phases ,phases
0424d1ff
VC
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))
fa747018
CN
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
a60f1319
MB
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
b634b5c2
KK
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"))))
a60f1319
MB
957 (build-system gnu-build-system)
958 (arguments
959 `(#:make-flags (list "CC=gcc"
b634b5c2
KK
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 '())
a60f1319
MB
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"))
71f2b4b8
KK
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))))
a60f1319
MB
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")
bb93042c 1016 ("util-linux" ,util-linux "lib")))
a60f1319
MB
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
1022Chrome-branded devices. This includes the @command{cgpt} partitioning
1023program, the @command{futility} and @command{crossystem} firmware management
1024tools, and more.")
1025 (license license:bsd-3)))
1026
aa90375a
AI
1027(define-public os-prober
1028 (package
1029 (name "os-prober")
69001053 1030 (version "1.78")
aa90375a
AI
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
69001053 1037 (base32 "1sahk72blsrlirly4xlwa8jfxrpwagyn7b81p92q2s9m218rz43f"))))
aa90375a
AI
1038 (build-system gnu-build-system)
1039 (arguments
1040 `(#:modules ((guix build gnu-build-system)
1041 (guix build utils)
e9bdef5f
TGR
1042 (ice-9 regex) ; for string-match
1043 (srfi srfi-26)) ; for cut
33430a45
TGR
1044 #:make-flags
1045 (list ,(string-append "CC=" (cc-for-target)))
e9bdef5f 1046 #:tests? #f ; no tests
aa90375a
AI
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
1091systems so that they can be added to the bootloader. It also works out how to
1092boot existing GNU/Linux systems and detects what distribution is installed in
1093order to add a suitable bootloader menu entry.")
1094 (license license:gpl2+)))
aeed7218
VL
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")
ca34b6f0 1105 (version "1.21.1")
aeed7218
VL
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
ca34b6f0 1115 "1pkf1n1c0rdlzfls8fvjvi1sd9xjd9ijqlyz3wigr70ijcv6x8i9"))))
aeed7218
VL
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
1208implementation enhanced with additional features such as booting from: a web
1209server via HTTP, an iSCSI SAN, a Fibre Channel SAN via FCoE, an AoE SAN, a
084d3cac
VC
1210wireless network, a wide-area network, an Infiniband network. It
1211controls the boot process with a script. You can use iPXE to replace the
aeed7218
VL
1212existing PXE ROM on your network card, or you can chainload into iPXE to obtain
1213the features of iPXE without the hassle of reflashing.")
1214 (license license:gpl2+))))
1215