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