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