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