doc: Mention that ./pre-inst-env is generated.
[jackhill/guix/guix.git] / gnu / packages / bootloaders.scm
CommitLineData
65d8b777 1;;; GNU Guix --- Functional package management for GNU
a7c87169 2;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2018 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>
d95bb295 10;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
65d8b777
LC
11;;;
12;;; This file is part of GNU Guix.
13;;;
14;;; GNU Guix is free software; you can redistribute it and/or modify it
15;;; under the terms of the GNU General Public License as published by
16;;; the Free Software Foundation; either version 3 of the License, or (at
17;;; your option) any later version.
18;;;
19;;; GNU Guix is distributed in the hope that it will be useful, but
20;;; WITHOUT ANY WARRANTY; without even the implied warranty of
21;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22;;; GNU General Public License for more details.
23;;;
24;;; You should have received a copy of the GNU General Public License
25;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
26
862e38d5 27(define-module (gnu packages bootloaders)
65d8b777 28 #:use-module (gnu packages)
862e38d5
DC
29 #:use-module (gnu packages admin)
30 #:use-module ((gnu packages algebra) #:select (bc))
31 #:use-module (gnu packages assembly)
a60f1319 32 #:use-module (gnu packages base)
7febe3a2 33 #:use-module (gnu packages disk)
65d8b777 34 #:use-module (gnu packages bison)
862e38d5 35 #:use-module (gnu packages cdrom)
65212c42 36 #:use-module (gnu packages check)
862e38d5
DC
37 #:use-module (gnu packages cross-base)
38 #:use-module (gnu packages disk)
29be6cfb 39 #:use-module (gnu packages firmware)
862e38d5 40 #:use-module (gnu packages flex)
a86177d6 41 #:use-module (gnu packages fontutils)
f074f5e8 42 #:use-module (gnu packages gcc)
862e38d5 43 #:use-module (gnu packages gettext)
65d8b777 44 #:use-module (gnu packages linux)
862e38d5 45 #:use-module (gnu packages man)
444f9dcc 46 #:use-module (gnu packages mtools)
862e38d5 47 #:use-module (gnu packages ncurses)
96b714f5 48 #:use-module (gnu packages perl)
a60f1319 49 #:use-module (gnu packages pkg-config)
96b714f5 50 #:use-module (gnu packages python)
58301666 51 #:use-module (gnu packages texinfo)
a60f1319 52 #:use-module (gnu packages tls)
65212c42 53 #:use-module (gnu packages sdl)
12c613b5 54 #:use-module (gnu packages swig)
5d706f18 55 #:use-module (gnu packages valgrind)
59132b80 56 #:use-module (gnu packages virtualization)
a60f1319 57 #:use-module (gnu packages web)
862e38d5
DC
58 #:use-module (guix build-system gnu)
59 #:use-module (guix download)
60 #:use-module (guix git-download)
61 #:use-module ((guix licenses) #:prefix license:)
62 #:use-module (guix packages)
63087721
EF
63 #:use-module (guix utils)
64 #:use-module (srfi srfi-1)
a7c87169
MW
65 #:use-module (srfi srfi-26)
66 #:use-module (ice-9 regex))
65d8b777 67
9b24c768
LC
68(define unifont
69 ;; GNU Unifont, <http://gnu.org/s/unifont>.
70 ;; GRUB needs it for its graphical terminal, gfxterm.
71 (origin
72 (method url-fetch)
73 (uri
74 "http://unifoundry.com/pub/unifont-7.0.06/font-builds/unifont-7.0.06.bdf.gz")
75 (sha256
76 (base32
77 "0p2vhnc18cnbmb39vq4m7hzv4mhnm2l0a2s7gx3ar277fwng3hys"))))
78
65d8b777
LC
79(define-public grub
80 (package
81 (name "grub")
3586a3e9 82 (version "2.02")
65d8b777
LC
83 (source (origin
84 (method url-fetch)
3586a3e9 85 (uri (string-append "mirror://gnu/grub/grub-" version ".tar.xz"))
65d8b777
LC
86 (sha256
87 (base32
526ce419
MB
88 "03vvdfhdmf16121v7xs8is2krwnv15wpkhkf16a4yf8nsfc3f2w1"))
89 (patches (search-patches "grub-check-error-efibootmgr.patch"))))
65d8b777
LC
90 (build-system gnu-build-system)
91 (arguments
56f0feb6 92 `(#:phases (modify-phases %standard-phases
358db004 93 (add-after 'unpack 'patch-stuff
04e0eac1
MW
94 (lambda* (#:key inputs #:allow-other-keys)
95 (substitute* "grub-core/Makefile.in"
96 (("/bin/sh") (which "sh")))
65d8b777 97
358db004
LC
98 ;; Give the absolute file name of 'mdadm', used to
99 ;; determine the root file system when it's a RAID
100 ;; device. Failing to do that, 'grub-probe' silently
101 ;; fails if 'mdadm' is not in $PATH.
102 (substitute* "grub-core/osdep/linux/getroot.c"
103 (("argv\\[0\\] = \"mdadm\"")
104 (string-append "argv[0] = \""
105 (assoc-ref inputs "mdadm")
106 "/sbin/mdadm\"")))
107
04e0eac1
MW
108 ;; Make the font visible.
109 (copy-file (assoc-ref inputs "unifont") "unifont.bdf.gz")
110 (system* "gunzip" "unifont.bdf.gz")
23a53a95
LF
111 #t))
112 (add-before 'check 'disable-flaky-test
113 (lambda _
114 ;; This test is unreliable. For more information, see:
115 ;; <https://bugs.gnu.org/26936>.
116 (substitute* "Makefile.in"
117 (("grub_cmd_date grub_cmd_set_date grub_cmd_sleep")
118 "grub_cmd_date grub_cmd_sleep"))
56f0feb6 119 #t)))
63087721
EF
120 ;; Disable tests on ARM and AARCH64 platforms.
121 #:tests? ,(not (any (cute string-prefix? <> (or (%current-target-system)
122 (%current-system)))
123 '("arm" "aarch64")))))
65d8b777 124 (inputs
10da75df
LC
125 `(("gettext" ,gettext-minimal)
126
127 ;; Depend on LVM2 for libdevmapper, used by 'grub-probe' and
128 ;; 'grub-install' to recognize mapped devices (LUKS, etc.)
129 ("lvm2" ,lvm2)
130
131 ;; Depend on mdadm, which is invoked by 'grub-probe' and 'grub-install'
132 ;; to determine whether the root file system is RAID.
358db004 133 ("mdadm" ,mdadm)
10da75df 134
65d8b777
LC
135 ("freetype" ,freetype)
136 ;; ("libusb" ,libusb)
04e0eac1 137 ;; ("fuse" ,fuse)
01eafd38 138 ("ncurses" ,ncurses)))
65d8b777 139 (native-inputs
0a2a7053
MW
140 `(("pkg-config" ,pkg-config)
141 ("unifont" ,unifont)
9b24c768 142 ("bison" ,bison)
0a3aca47
LF
143 ;; Due to a bug in flex >= 2.6.2, GRUB must be built with an older flex:
144 ;; <http://lists.gnu.org/archive/html/grub-devel/2017-02/msg00133.html>
145 ;; TODO Try building with flex > 2.6.4.
146 ("flex" ,flex-2.6.1)
58301666
MW
147 ("texinfo" ,texinfo)
148 ("help2man" ,help2man)
65d8b777 149
a7c87169
MW
150 ;; XXX: When building GRUB 2.02 on 32-bit x86, we need a binutils
151 ;; capable of assembling 64-bit instructions. However, our default
152 ;; binutils on 32-bit x86 is not 64-bit capable.
153 ,@(if (string-match "^i[3456]86-" (%current-system))
154 (let ((binutils (package/inherit
155 binutils
156 (name "binutils-i386")
157 (arguments
158 (substitute-keyword-arguments (package-arguments binutils)
159 ((#:configure-flags flags ''())
160 `(cons "--enable-64-bit-bfd" ,flags)))))))
161 `(("ld-wrapper" ,(make-ld-wrapper "ld-wrapper-i386"
162 #:binutils binutils))
163 ("binutils" ,binutils)))
164 '())
165
65d8b777
LC
166 ;; Dependencies for the test suite. The "real" QEMU is needed here,
167 ;; because several targets are used.
7febe3a2 168 ("parted" ,parted)
d64bcccf 169 ("qemu" ,qemu-minimal-2.10)
65d8b777 170 ("xorriso" ,xorriso)))
175b259c 171 (home-page "https://www.gnu.org/software/grub/")
79c311b8 172 (synopsis "GRand Unified Boot loader")
65d8b777 173 (description
a22dc0c4 174 "GRUB is a multiboot bootloader. It is used for initially loading the
35b9e423 175kernel of an operating system and then transferring control to it. The kernel
c5779c93 176then goes on to load the rest of the operating system. As a multiboot
574e86f9
LC
177bootloader, GRUB handles the presence of multiple operating systems installed
178on the same computer; upon booting the computer, the user is presented with a
a22dc0c4 179menu to select one of the installed operating systems.")
3f73aa1a 180 (license license:gpl3+)
99effc8f 181 (properties '((cpe-name . "grub2")))))
acb5f7c3
MB
182
183(define-public grub-efi
184 (package
185 (inherit grub)
186 (name "grub-efi")
187 (synopsis "GRand Unified Boot loader (UEFI version)")
188 (inputs
189 `(("efibootmgr" ,efibootmgr)
c695fb76 190 ("mtools" ,mtools)
acb5f7c3
MB
191 ,@(package-inputs grub)))
192 (arguments
193 `(;; TODO: Tests need a UEFI firmware for qemu. There is one at
194 ;; https://github.com/tianocore/edk2/tree/master/OvmfPkg .
195 ;; Search for 'OVMF' in "tests/util/grub-shell.in".
acb5f7c3 196 ,@(substitute-keyword-arguments (package-arguments grub)
46ff2dbb 197 ((#:tests? _ #f) #f)
ef753a1a
LC
198 ((#:configure-flags flags ''())
199 `(cons "--with-platform=efi" ,flags))
acb5f7c3
MB
200 ((#:phases phases)
201 `(modify-phases ,phases
202 (add-after 'patch-stuff 'use-absolute-efibootmgr-path
203 (lambda* (#:key inputs #:allow-other-keys)
204 (substitute* "grub-core/osdep/unix/platform.c"
205 (("efibootmgr")
206 (string-append (assoc-ref inputs "efibootmgr")
207 "/sbin/efibootmgr")))
444f9dcc
DM
208 #t))
209 (add-after 'patch-stuff 'use-absolute-mtools-path
210 (lambda* (#:key inputs #:allow-other-keys)
211 (let ((mtools (assoc-ref inputs "mtools")))
212 (substitute* "util/grub-mkrescue.c"
213 (("\"mformat\"")
214 (string-append "\"" mtools
215 "/bin/mformat\"")))
216 (substitute* "util/grub-mkrescue.c"
217 (("\"mcopy\"")
218 (string-append "\"" mtools
219 "/bin/mcopy\"")))
220 #t))))))))))
96b714f5 221
dd4b7476
DM
222;; Because grub searches hardcoded paths it's easiest to just build grub
223;; again to make it find both grub-pc and grub-efi. There is a command
224;; line argument which allows you to specify ONE platform - but
225;; grub-mkrescue will use multiple platforms if they are available
226;; in the installation directory (without command line argument).
227(define-public grub-hybrid
228 (package
229 (inherit grub-efi)
230 (name "grub-hybrid")
231 (synopsis "GRand Unified Boot loader (hybrid version)")
232 (inputs
233 `(("grub" ,grub)
234 ,@(package-inputs grub-efi)))
235 (arguments
236 (substitute-keyword-arguments (package-arguments grub-efi)
237 ((#:modules modules `((guix build utils) (guix build gnu-build-system)))
238 `((ice-9 ftw) ,@modules))
239 ((#:phases phases)
240 `(modify-phases ,phases
241 (add-after 'install 'install-non-efi
242 (lambda* (#:key inputs outputs #:allow-other-keys)
243 (let ((input-dir (string-append (assoc-ref inputs "grub")
244 "/lib/grub"))
245 (output-dir (string-append (assoc-ref outputs "out")
246 "/lib/grub")))
247 (for-each
248 (lambda (basename)
db34d4bb
EF
249 (if (not (or (string-prefix? "." basename)
250 (file-exists? (string-append output-dir "/" basename))))
dd4b7476
DM
251 (symlink (string-append input-dir "/" basename)
252 (string-append output-dir "/" basename))))
253 (scandir input-dir))
254 #t)))))))))
255
96b714f5
DC
256(define-public syslinux
257 (let ((commit "bb41e935cc83c6242de24d2271e067d76af3585c"))
258 (package
259 (name "syslinux")
260 (version (git-version "6.04-pre" "1" commit))
261 (source (origin
262 (method git-fetch)
263 (uri (git-reference
264 (url "https://github.com/geneC/syslinux")
265 (commit commit)))
266 (file-name (git-file-name name version))
267 (sha256
268 (base32
269 "0k8dvafd6410kqxf3kyr4y8jzmpmrih6wbjqg6gklak7945yflrc"))))
270 (build-system gnu-build-system)
271 (native-inputs
272 `(("nasm" ,nasm)
273 ("perl" ,perl)
274 ("python-2" ,python-2)))
275 (inputs
0b4dbb40
LC
276 `(("libuuid" ,util-linux)
277 ("mtools" ,mtools)))
96b714f5
DC
278 (arguments
279 `(#:parallel-build? #f
280 #:make-flags
281 (list (string-append "BINDIR=" %output "/bin")
282 (string-append "SBINDIR=" %output "/sbin")
283 (string-append "LIBDIR=" %output "/lib")
284 (string-append "INCDIR=" %output "/include")
285 (string-append "DATADIR=" %output "/share")
286 (string-append "MANDIR=" %output "/share/man")
287 "PERL=perl"
288 "bios")
289 #:phases
290 (modify-phases %standard-phases
291 (add-after 'unpack 'patch-files
0b4dbb40 292 (lambda* (#:key inputs #:allow-other-keys)
96b714f5
DC
293 (substitute* (find-files "." "Makefile.*|ppmtolss16")
294 (("/bin/pwd") (which "pwd"))
295 (("/bin/echo") (which "echo"))
296 (("/usr/bin/perl") (which "perl")))
0b4dbb40
LC
297 (let ((mtools (assoc-ref inputs "mtools")))
298 (substitute* (find-files "." "\\.c$")
299 (("mcopy")
300 (string-append mtools "/bin/mcopy"))
301 (("mattrib")
302 (string-append mtools "/bin/mattrib"))))
96b714f5
DC
303 #t))
304 (delete 'configure)
305 (add-before 'build 'set-permissions
306 (lambda _
60d8db74 307 (invoke "chmod" "a+w" "utils/isohybrid.in")))
96b714f5
DC
308 (replace 'check
309 (lambda _
310 (setenv "CC" "gcc")
311 (substitute* "tests/unittest/include/unittest/unittest.h"
312 ;; Don't look up headers under /usr.
313 (("/usr/include/") ""))
60d8db74 314 (invoke "make" "unittest"))))))
0f304ba7 315 (home-page "https://www.syslinux.org")
96b714f5
DC
316 (synopsis "Lightweight Linux bootloader")
317 (description "Syslinux is a lightweight Linux bootloader.")
318 (license (list license:gpl2+
319 license:bsd-3 ; gnu-efi/*
320 license:bsd-4 ; gnu-efi/inc/* gnu-efi/lib/*
321 ;; Also contains:
322 license:expat license:isc license:zlib)))))
862e38d5
DC
323
324(define-public dtc
325 (package
326 (name "dtc")
5d706f18 327 (version "1.4.7")
862e38d5
DC
328 (source (origin
329 (method url-fetch)
330 (uri (string-append
3b4efb1f 331 "mirror://kernel.org/software/utils/dtc/"
862e38d5
DC
332 "dtc-" version ".tar.xz"))
333 (sha256
334 (base32
5d706f18 335 "1rydi5jvhlhsr110h6n0pavv3daqa0cb4m5vcps50qzq1zqfhhv6"))))
862e38d5
DC
336 (build-system gnu-build-system)
337 (native-inputs
338 `(("bison" ,bison)
12c613b5 339 ("flex" ,flex)
5d706f18
VC
340 ("swig" ,swig)
341 ("valgrind" ,valgrind)))
12c613b5
EF
342 (inputs
343 `(("python-2" ,python-2)))
862e38d5
DC
344 (arguments
345 `(#:make-flags
346 (list "CC=gcc"
347 (string-append "PREFIX=" (assoc-ref %outputs "out"))
12c613b5 348 (string-append "SETUP_PREFIX=" (assoc-ref %outputs "out"))
862e38d5
DC
349 "INSTALL=install")
350 #:phases
351 (modify-phases %standard-phases
d95bb295 352 (delete 'configure)))) ; no configure script
862e38d5
DC
353 (home-page "https://www.devicetree.org")
354 (synopsis "Compiles device tree source files")
355 (description "@command{dtc} compiles
356@uref{http://elinux.org/Device_Tree_Usage, device tree source files} to device
357tree binary files. These are board description files used by Linux and BSD.")
358 (license license:gpl2+)))
359
360(define u-boot
361 (package
362 (name "u-boot")
e1d1ec14 363 (version "2018.09")
862e38d5
DC
364 (source (origin
365 (method url-fetch)
366 (uri (string-append
367 "ftp://ftp.denx.de/pub/u-boot/"
368 "u-boot-" version ".tar.bz2"))
369 (sha256
370 (base32
e1d1ec14 371 "0s122kyz1svvs2yjzj4j9qravl3ra4vn0fjqgski7rlczqyg56w3"))))
862e38d5
DC
372 (native-inputs
373 `(("bc" ,bc)
336c4a4b 374 ("bison" ,bison)
53e290df 375 ("dtc" ,dtc)
336c4a4b 376 ("flex" ,flex)
65212c42 377 ("openssl" ,openssl)
f074f5e8 378 ("python-2" ,python-2)
65212c42
DM
379 ("python2-coverage" ,python2-coverage)
380 ("python2-pytest" ,python2-pytest)
381 ("sdl" ,sdl)
f074f5e8 382 ("swig" ,swig)))
862e38d5 383 (build-system gnu-build-system)
3e63a83c 384 (home-page "https://www.denx.de/wiki/U-Boot/")
862e38d5
DC
385 (synopsis "ARM bootloader")
386 (description "U-Boot is a bootloader used mostly for ARM boards. It
387also initializes the boards (RAM etc).")
388 (license license:gpl2+)))
389
2676628f
DM
390(define-public u-boot-tools
391 (package
392 (inherit u-boot)
393 (name "u-boot-tools")
394 (arguments
65212c42
DM
395 `(#:make-flags '("HOSTCC=gcc")
396 #:test-target "tests"
2676628f
DM
397 #:phases
398 (modify-phases %standard-phases
65212c42
DM
399 (add-after 'unpack 'patch
400 (lambda* (#:key inputs #:allow-other-keys)
401 (substitute* "Makefile"
402 (("/bin/pwd") (which "pwd"))
403 (("/bin/false") (which "false")))
404 (substitute* "tools/dtoc/fdt_util.py"
405 (("'cc'") "'gcc'"))
e1d1ec14
VC
406 (substitute* "tools/patman/test_util.py"
407 ;; python-coverage is simply called coverage in guix.
408 (("python-coverage") "coverage")
409 ;; XXX Allow for only 99% test coverage.
410 ;; TODO: Find out why that is needed.
411 (("if coverage != '100%':") "if not int(coverage.rstrip('%')) >= 99:"))
65212c42
DM
412 (substitute* "test/run"
413 ;; Make it easier to find test failures.
414 (("#!/bin/bash") "#!/bin/bash -x")
415 ;; pytest doesn't find it otherwise.
416 (("test/py/tests/test_ofplatdata.py")
417 "tests/test_ofplatdata.py")
418 ;; This test would require git.
419 (("\\./tools/patman/patman") (which "true"))
420 ;; This test would require internet access.
421 (("\\./tools/buildman/buildman") (which "true")))
422 (substitute* "test/py/tests/test_sandbox_exit.py"
423 (("def test_ctrl_c")
424 "@pytest.mark.skip(reason='Guix has problems with SIGINT')
425def test_ctrl_c"))
65212c42 426 #t))
2676628f
DM
427 (replace 'configure
428 (lambda* (#:key make-flags #:allow-other-keys)
429 (call-with-output-file "configs/tools_defconfig"
430 (lambda (port)
431 (display "CONFIG_SYS_TEXT_BASE=0\n" port)))
432 (apply invoke "make" "tools_defconfig" make-flags)))
433 (replace 'build
434 (lambda* (#:key inputs make-flags #:allow-other-keys)
9e84a4d6 435 (apply invoke "make" "tools-all" make-flags)))
2676628f
DM
436 (replace 'install
437 (lambda* (#:key outputs #:allow-other-keys)
438 (let* ((out (assoc-ref outputs "out"))
439 (bin (string-append out "/bin")))
440 (for-each (lambda (name)
441 (install-file name bin))
442 '("tools/netconsole"
443 "tools/jtagconsole"
444 "tools/gen_eth_addr"
445 "tools/gen_ethaddr_crc"
446 "tools/img2srec"
447 "tools/mkenvimage"
448 "tools/dumpimage"
449 "tools/mkimage"
450 "tools/proftool"
451 "tools/fdtgrep"
10186ee2
DM
452 "tools/env/fw_printenv"
453 "tools/sunxi-spl-image-builder"))
65212c42
DM
454 #t)))
455 (delete 'check)
456 (add-after 'install 'check
457 (lambda* (#:key make-flags test-target #:allow-other-keys)
458 (apply invoke "make" "mrproper" make-flags)
459 (setenv "SDL_VIDEODRIVER" "dummy")
460 (setenv "PAGER" "cat")
461 (apply invoke "make" test-target make-flags)
462 (symlink "build-sandbox_spl" "sandbox")
463 (invoke "test/image/test-imagetools.sh"))))))
2676628f
DM
464 (description "U-Boot is a bootloader used mostly for ARM boards. It
465also initializes the boards (RAM etc). This package provides its
466board-independent tools.")))
467
4ce4fc50 468(define-public (make-u-boot-package board triplet)
862e38d5 469 "Returns a u-boot package for BOARD cross-compiled for TRIPLET."
2ac42fe5
MO
470 (let ((same-arch? (if (string-prefix? (%current-system)
471 (gnu-triplet->nix-system triplet))
3bfee8ff
EF
472 `#t
473 `#f)))
474 (package
475 (inherit u-boot)
df8a9096
DM
476 (name (string-append "u-boot-"
477 (string-replace-substring (string-downcase board)
478 "_" "-")))
3bfee8ff
EF
479 (native-inputs
480 `(,@(if (not same-arch?)
f074f5e8 481 `(("cross-gcc" ,(cross-gcc triplet #:xgcc gcc-7))
3bfee8ff 482 ("cross-binutils" ,(cross-binutils triplet)))
a1f53127 483 `(("gcc-7" ,gcc-7)))
3bfee8ff
EF
484 ,@(package-native-inputs u-boot)))
485 (arguments
37297674
EF
486 `(#:modules ((ice-9 ftw)
487 (srfi srfi-1)
488 (guix build utils)
489 (guix build gnu-build-system))
3bfee8ff
EF
490 #:test-target "test"
491 #:make-flags
492 (list "HOSTCC=gcc"
493 ,@(if (not same-arch?)
494 `((string-append "CROSS_COMPILE=" ,triplet "-"))
495 '()))
496 #:phases
497 (modify-phases %standard-phases
498 (replace 'configure
499 (lambda* (#:key outputs make-flags #:allow-other-keys)
500 (let ((config-name (string-append ,board "_defconfig")))
501 (if (file-exists? (string-append "configs/" config-name))
502 (zero? (apply system* "make" `(,@make-flags ,config-name)))
503 (begin
ac30d18c
DM
504 (display "Invalid board name. Valid board names are:"
505 (current-error-port))
30ef146c
DM
506 (let ((suffix-len (string-length "_defconfig"))
507 (entries (scandir "configs")))
508 (for-each (lambda (file-name)
509 (when (string-suffix? "_defconfig" file-name)
ac30d18c 510 (format (current-error-port)
30ef146c
DM
511 "- ~A\n"
512 (string-drop-right file-name
513 suffix-len))))
ee3c8fbe 514 (sort entries string-ci<)))
bdd235b3 515 (error "Invalid boardname ~s." ,board))))))
3bfee8ff 516 (replace 'install
9b94ced4 517 (lambda* (#:key outputs #:allow-other-keys)
3bfee8ff
EF
518 (let* ((out (assoc-ref outputs "out"))
519 (libexec (string-append out "/libexec"))
dd208b93 520 (uboot-files (append
a9446dde
DM
521 (remove
522 ;; Those would not be reproducible
523 ;; because of the randomness used
524 ;; to produce them.
525 ;; It's expected that the user will
526 ;; use u-boot-tools to generate them
527 ;; instead.
528 (lambda (name)
529 (string-suffix?
530 "sunxi-spl-with-ecc.bin"
531 name))
532 (find-files "." ".*\\.(bin|efi|img|spl|itb|dtb|rksd)$"))
fd0b21d5 533 (find-files "." "^(MLO|SPL)$"))))
3bfee8ff 534 (mkdir-p libexec)
a32f9b59 535 (install-file ".config" libexec)
0fcfed39
DM
536 ;; Useful for "qemu -kernel".
537 (install-file "u-boot" libexec)
3bfee8ff
EF
538 (for-each
539 (lambda (file)
540 (let ((target-file (string-append libexec "/" file)))
541 (mkdir-p (dirname target-file))
542 (copy-file file target-file)))
d1af9a8c
DM
543 uboot-files)
544 #t)))))))))
862e38d5
DC
545
546(define-public u-boot-vexpress
547 (make-u-boot-package "vexpress_ca9x4" "arm-linux-gnueabihf"))
548
549(define-public u-boot-malta
550 (make-u-boot-package "malta" "mips64el-linux-gnuabi64"))
551
552(define-public u-boot-beagle-bone-black
553 (make-u-boot-package "am335x_boneblack" "arm-linux-gnueabihf"))
4adeb3f6 554
29be6cfb
EF
555(define-public u-boot-pine64-plus
556 (let ((base (make-u-boot-package "pine64_plus" "aarch64-linux-gnu")))
557 (package
558 (inherit base)
559 (arguments
560 (substitute-keyword-arguments (package-arguments base)
561 ((#:phases phases)
562 `(modify-phases ,phases
563 (add-after 'unpack 'set-environment
564 (lambda* (#:key inputs #:allow-other-keys)
565 (let ((bl31 (string-append (assoc-ref inputs "firmware")
566 "/bl31.bin")))
567 (setenv "BL31" bl31)
35e427d1
DM
568 ;; This is necessary when we're using the bundled dtc.
569 ;(setenv "PATH" (string-append (getenv "PATH") ":"
570 ; "scripts/dtc"))
571 )
29be6cfb
EF
572 #t))))))
573 (native-inputs
574 `(("firmware" ,arm-trusted-firmware-pine64-plus)
575 ,@(package-native-inputs base))))))
576
e830c9d0 577(define-public u-boot-bananapi-m2-ultra
30aeb846
DM
578 (make-u-boot-package "Bananapi_M2_Ultra" "arm-linux-gnueabihf"))
579
c55c6985
DM
580(define-public u-boot-a20-olinuxino-lime
581 (make-u-boot-package "A20-OLinuXino-Lime" "arm-linux-gnueabihf"))
582
4b9e9abb
DM
583(define-public u-boot-a20-olinuxino-lime2
584 (make-u-boot-package "A20-OLinuXino-Lime2" "arm-linux-gnueabihf"))
585
a7bb327e
DM
586(define-public u-boot-a20-olinuxino-micro
587 (make-u-boot-package "A20-OLinuXino_MICRO" "arm-linux-gnueabihf"))
588
84ee3378
DM
589(define-public u-boot-nintendo-nes-classic-edition
590 (make-u-boot-package "Nintendo_NES_Classic_Edition" "arm-linux-gnueabihf"))
591
95a3422e
VC
592(define-public u-boot-wandboard
593 (make-u-boot-package "wandboard" "arm-linux-gnueabihf"))
594
adc61d72
VC
595(define-public u-boot-mx6cuboxi
596 (make-u-boot-package "mx6cuboxi" "arm-linux-gnueabihf"))
597
1b960787
VC
598(define-public u-boot-novena
599 (make-u-boot-package "novena" "arm-linux-gnueabihf"))
600
dd4fe0c2
DM
601(define-public u-boot-cubieboard
602 (make-u-boot-package "Cubieboard" "arm-linux-gnueabihf"))
603
a7d5ce94
JL
604(define-public u-boot-cubietruck
605 (make-u-boot-package "Cubietruck" "arm-linux-gnueabihf"))
606
6fe16577
VC
607(define-public u-boot-puma-rk3399
608 (let ((base (make-u-boot-package "puma-rk3399" "aarch64-linux-gnu")))
609 (package
610 (inherit base)
611 (arguments
612 (substitute-keyword-arguments (package-arguments base)
613 ((#:phases phases)
614 `(modify-phases ,phases
615 (add-after 'unpack 'set-environment
616 (lambda* (#:key inputs #:allow-other-keys)
617 ;; Need to copy the firmware into u-boot build
618 ;; directory.
619 (copy-file (string-append (assoc-ref inputs "firmware")
620 "/bl31.bin") "bl31-rk3399.bin")
621 (copy-file (string-append (assoc-ref inputs "firmware-m0")
622 "/rk3399m0.bin") "rk3399m0.bin")
623 #t))
624 (add-after 'build 'build-itb
625 (lambda* (#:key make-flags #:allow-other-keys)
626 ;; The u-boot.itb is not built by default.
627 (apply invoke "make" `(,@make-flags ,"u-boot.itb"))))
628 (add-after 'build-itb 'build-rksd
629 (lambda* (#:key inputs #:allow-other-keys)
630 ;; Build Rockchip SD card images.
631 (invoke "./tools/mkimage" "-T" "rksd" "-n" "rk3399" "-d"
632 "spl/u-boot-spl.bin" "u-boot-spl.rksd")))))))
633 (native-inputs
634 `(("firmware" ,arm-trusted-firmware-puma-rk3399)
635 ("firmware-m0" ,rk3399-cortex-m0)
636 ,@(package-native-inputs base))))))
637
a60f1319
MB
638(define-public vboot-utils
639 (package
640 (name "vboot-utils")
641 (version "R63-10032.B")
642 (source (origin
643 ;; XXX: Snapshots are available but changes timestamps every download.
644 (method git-fetch)
645 (uri (git-reference
646 (url (string-append "https://chromium.googlesource.com"
647 "/chromiumos/platform/vboot_reference"))
648 (commit (string-append "release-" version))))
649 (file-name (string-append name "-" version "-checkout"))
650 (sha256
651 (base32
652 "0h0m3l69vp9dr6xrs1p6y7ilkq3jq8jraw2z20kqfv7lvc9l1lxj"))))
653 (build-system gnu-build-system)
654 (arguments
655 `(#:make-flags (list "CC=gcc"
656 (string-append "DESTDIR=" (assoc-ref %outputs "out")))
657 #:phases (modify-phases %standard-phases
658 (add-after 'unpack 'patch-hard-coded-paths
659 (lambda* (#:key inputs outputs #:allow-other-keys)
660 (let ((coreutils (assoc-ref inputs "coreutils"))
661 (diffutils (assoc-ref inputs "diffutils")))
662 (substitute* "futility/misc.c"
663 (("/bin/cp") (string-append coreutils "/bin/cp")))
664 (substitute* "tests/bitmaps/TestBmpBlock.py"
665 (("/usr/bin/cmp") (string-append diffutils "/bin/cmp")))
666 (substitute* "vboot_host.pc.in"
667 (("prefix=/usr")
668 (string-append "prefix=" (assoc-ref outputs "out"))))
669 #t)))
670 (delete 'configure)
671 (add-before 'check 'patch-tests
672 (lambda _
673 ;; These tests compare diffs against known-good values.
674 ;; Patch the paths to match those in the build container.
675 (substitute* (find-files "tests/futility/expect_output")
676 (("/mnt/host/source/src/platform/vboot_reference")
677 (string-append "/tmp/guix-build-" ,name "-" ,version
678 ".drv-0/source")))
679 ;; Tests require write permissions to many of these files.
680 (for-each make-file-writable (find-files "tests/futility"))
681 #t)))
682 #:test-target "runtests"))
683 (native-inputs
684 `(("pkg-config" ,pkg-config)
685
686 ;; For tests.
687 ("diffutils" ,diffutils)
688 ("python@2" ,python-2)))
689 (inputs
690 `(("coreutils" ,coreutils)
691 ("libyaml" ,libyaml)
692 ("openssl" ,openssl)
693 ("openssl:static" ,openssl "static")
694 ("util-linux" ,util-linux)))
695 (home-page
696 "https://dev.chromium.org/chromium-os/chromiumos-design-docs/verified-boot")
697 (synopsis "ChromiumOS verified boot utilities")
698 (description
699 "vboot-utils is a collection of tools to facilitate booting of
700Chrome-branded devices. This includes the @command{cgpt} partitioning
701program, the @command{futility} and @command{crossystem} firmware management
702tools, and more.")
703 (license license:bsd-3)))
704
aa90375a
AI
705(define-public os-prober
706 (package
707 (name "os-prober")
708 (version "1.76")
709 (source
710 (origin
711 (method url-fetch)
712 (uri (string-append "mirror://debian/pool/main/o/os-prober/os-prober_"
713 version ".tar.xz"))
714 (sha256
715 (base32
716 "1vb45i76bqivlghrq7m3n07qfmmq4wxrkplqx8gywj011rhq19fk"))))
717 (build-system gnu-build-system)
718 (arguments
719 `(#:modules ((guix build gnu-build-system)
720 (guix build utils)
721 (ice-9 regex) ; for string-match
722 (srfi srfi-26)) ; for cut
723 #:make-flags (list "CC=gcc")
724 #:tests? #f ; no tests
725 #:phases
726 (modify-phases %standard-phases
727 (replace 'configure
728 (lambda* (#:key outputs #:allow-other-keys)
729 (substitute* (find-files ".")
730 (("/usr") (assoc-ref outputs "out")))
731 (substitute* (find-files "." "50mounted-tests$")
732 (("mkdir") "mkdir -p"))
733 #t))
734 (replace 'install
735 (lambda* (#:key outputs #:allow-other-keys)
736 (define (find-files-non-recursive directory)
737 (find-files directory
738 (lambda (file stat)
739 (string-match (string-append "^" directory "/[^/]*$")
740 file))
741 #:directories? #t))
742
743 (let* ((out (assoc-ref outputs "out"))
744 (bin (string-append out "/bin"))
745 (lib (string-append out "/lib"))
746 (share (string-append out "/share")))
747 (for-each (cut install-file <> bin)
748 (list "linux-boot-prober" "os-prober"))
749 (install-file "newns" (string-append lib "/os-prober"))
750 (install-file "common.sh" (string-append share "/os-prober"))
751 (install-file "os-probes/mounted/powerpc/20macosx"
752 (string-append lib "/os-probes/mounted"))
753 (for-each
754 (lambda (directory)
755 (for-each
756 (lambda (file)
757 (let ((destination (string-append lib "/" directory
758 "/" (basename file))))
759 (mkdir-p (dirname destination))
760 (copy-recursively file destination)))
761 (append (find-files-non-recursive (string-append directory "/common"))
762 (find-files-non-recursive (string-append directory "/x86")))))
763 (list "os-probes" "os-probes/mounted" "os-probes/init"
764 "linux-boot-probes" "linux-boot-probes/mounted"))
765 #t))))))
766 (home-page "https://joeyh.name/code/os-prober")
767 (synopsis "Detect other operating systems")
768 (description "os-prober probes disks on the system for other operating
769systems so that they can be added to the bootloader. It also works out how to
770boot existing GNU/Linux systems and detects what distribution is installed in
771order to add a suitable bootloader menu entry.")
772 (license license:gpl2+)))