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