gnu: python-llvmlite: Remove obsolete patch.
[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")
336c4a4b 363 (version "2018.07")
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
336c4a4b 371 "1m7nw64mxflpc6sqvnz2kb5fxfkb4mrpy8b1wi15dcwipj4dy44z"))))
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
DC
383 (build-system gnu-build-system)
384 (home-page "http://www.denx.de/wiki/U-Boot/")
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'"))
406 (substitute* "test/run"
407 ;; Make it easier to find test failures.
408 (("#!/bin/bash") "#!/bin/bash -x")
409 ;; pytest doesn't find it otherwise.
410 (("test/py/tests/test_ofplatdata.py")
411 "tests/test_ofplatdata.py")
412 ;; This test would require git.
413 (("\\./tools/patman/patman") (which "true"))
414 ;; This test would require internet access.
415 (("\\./tools/buildman/buildman") (which "true")))
416 (substitute* "test/py/tests/test_sandbox_exit.py"
417 (("def test_ctrl_c")
418 "@pytest.mark.skip(reason='Guix has problems with SIGINT')
419def test_ctrl_c"))
420 (substitute* "tools/binman/binman.py"
421 (("100%") "99%")) ; TODO: Find out why that is needed.
422 #t))
2676628f
DM
423 (replace 'configure
424 (lambda* (#:key make-flags #:allow-other-keys)
425 (call-with-output-file "configs/tools_defconfig"
426 (lambda (port)
427 (display "CONFIG_SYS_TEXT_BASE=0\n" port)))
428 (apply invoke "make" "tools_defconfig" make-flags)))
429 (replace 'build
430 (lambda* (#:key inputs make-flags #:allow-other-keys)
9e84a4d6 431 (apply invoke "make" "tools-all" make-flags)))
2676628f
DM
432 (replace 'install
433 (lambda* (#:key outputs #:allow-other-keys)
434 (let* ((out (assoc-ref outputs "out"))
435 (bin (string-append out "/bin")))
436 (for-each (lambda (name)
437 (install-file name bin))
438 '("tools/netconsole"
439 "tools/jtagconsole"
440 "tools/gen_eth_addr"
441 "tools/gen_ethaddr_crc"
442 "tools/img2srec"
443 "tools/mkenvimage"
444 "tools/dumpimage"
445 "tools/mkimage"
446 "tools/proftool"
447 "tools/fdtgrep"
10186ee2
DM
448 "tools/env/fw_printenv"
449 "tools/sunxi-spl-image-builder"))
65212c42
DM
450 #t)))
451 (delete 'check)
452 (add-after 'install 'check
453 (lambda* (#:key make-flags test-target #:allow-other-keys)
454 (apply invoke "make" "mrproper" make-flags)
455 (setenv "SDL_VIDEODRIVER" "dummy")
456 (setenv "PAGER" "cat")
457 (apply invoke "make" test-target make-flags)
458 (symlink "build-sandbox_spl" "sandbox")
459 (invoke "test/image/test-imagetools.sh"))))))
2676628f
DM
460 (description "U-Boot is a bootloader used mostly for ARM boards. It
461also initializes the boards (RAM etc). This package provides its
462board-independent tools.")))
463
4ce4fc50 464(define-public (make-u-boot-package board triplet)
862e38d5 465 "Returns a u-boot package for BOARD cross-compiled for TRIPLET."
2ac42fe5
MO
466 (let ((same-arch? (if (string-prefix? (%current-system)
467 (gnu-triplet->nix-system triplet))
3bfee8ff
EF
468 `#t
469 `#f)))
470 (package
471 (inherit u-boot)
df8a9096
DM
472 (name (string-append "u-boot-"
473 (string-replace-substring (string-downcase board)
474 "_" "-")))
3bfee8ff
EF
475 (native-inputs
476 `(,@(if (not same-arch?)
f074f5e8 477 `(("cross-gcc" ,(cross-gcc triplet #:xgcc gcc-7))
3bfee8ff 478 ("cross-binutils" ,(cross-binutils triplet)))
a1f53127 479 `(("gcc-7" ,gcc-7)))
3bfee8ff
EF
480 ,@(package-native-inputs u-boot)))
481 (arguments
37297674
EF
482 `(#:modules ((ice-9 ftw)
483 (srfi srfi-1)
484 (guix build utils)
485 (guix build gnu-build-system))
3bfee8ff
EF
486 #:test-target "test"
487 #:make-flags
488 (list "HOSTCC=gcc"
489 ,@(if (not same-arch?)
490 `((string-append "CROSS_COMPILE=" ,triplet "-"))
491 '()))
492 #:phases
493 (modify-phases %standard-phases
494 (replace 'configure
495 (lambda* (#:key outputs make-flags #:allow-other-keys)
496 (let ((config-name (string-append ,board "_defconfig")))
497 (if (file-exists? (string-append "configs/" config-name))
498 (zero? (apply system* "make" `(,@make-flags ,config-name)))
499 (begin
ac30d18c
DM
500 (display "Invalid board name. Valid board names are:"
501 (current-error-port))
30ef146c
DM
502 (let ((suffix-len (string-length "_defconfig"))
503 (entries (scandir "configs")))
504 (for-each (lambda (file-name)
505 (when (string-suffix? "_defconfig" file-name)
ac30d18c 506 (format (current-error-port)
30ef146c
DM
507 "- ~A\n"
508 (string-drop-right file-name
509 suffix-len))))
ee3c8fbe 510 (sort entries string-ci<)))
bdd235b3 511 (error "Invalid boardname ~s." ,board))))))
3bfee8ff 512 (replace 'install
9b94ced4 513 (lambda* (#:key outputs #:allow-other-keys)
3bfee8ff
EF
514 (let* ((out (assoc-ref outputs "out"))
515 (libexec (string-append out "/libexec"))
dd208b93 516 (uboot-files (append
a9446dde
DM
517 (remove
518 ;; Those would not be reproducible
519 ;; because of the randomness used
520 ;; to produce them.
521 ;; It's expected that the user will
522 ;; use u-boot-tools to generate them
523 ;; instead.
524 (lambda (name)
525 (string-suffix?
526 "sunxi-spl-with-ecc.bin"
527 name))
528 (find-files "." ".*\\.(bin|efi|img|spl|itb|dtb|rksd)$"))
fd0b21d5 529 (find-files "." "^(MLO|SPL)$"))))
3bfee8ff 530 (mkdir-p libexec)
a32f9b59 531 (install-file ".config" libexec)
0fcfed39
DM
532 ;; Useful for "qemu -kernel".
533 (install-file "u-boot" libexec)
3bfee8ff
EF
534 (for-each
535 (lambda (file)
536 (let ((target-file (string-append libexec "/" file)))
537 (mkdir-p (dirname target-file))
538 (copy-file file target-file)))
d1af9a8c
DM
539 uboot-files)
540 #t)))))))))
862e38d5
DC
541
542(define-public u-boot-vexpress
543 (make-u-boot-package "vexpress_ca9x4" "arm-linux-gnueabihf"))
544
545(define-public u-boot-malta
546 (make-u-boot-package "malta" "mips64el-linux-gnuabi64"))
547
548(define-public u-boot-beagle-bone-black
549 (make-u-boot-package "am335x_boneblack" "arm-linux-gnueabihf"))
4adeb3f6 550
29be6cfb
EF
551(define-public u-boot-pine64-plus
552 (let ((base (make-u-boot-package "pine64_plus" "aarch64-linux-gnu")))
553 (package
554 (inherit base)
555 (arguments
556 (substitute-keyword-arguments (package-arguments base)
557 ((#:phases phases)
558 `(modify-phases ,phases
559 (add-after 'unpack 'set-environment
560 (lambda* (#:key inputs #:allow-other-keys)
561 (let ((bl31 (string-append (assoc-ref inputs "firmware")
562 "/bl31.bin")))
563 (setenv "BL31" bl31)
35e427d1
DM
564 ;; This is necessary when we're using the bundled dtc.
565 ;(setenv "PATH" (string-append (getenv "PATH") ":"
566 ; "scripts/dtc"))
567 )
29be6cfb
EF
568 #t))))))
569 (native-inputs
570 `(("firmware" ,arm-trusted-firmware-pine64-plus)
571 ,@(package-native-inputs base))))))
572
30aeb846
DM
573(define-public u-boot-banana-pi-m2-ultra
574 (make-u-boot-package "Bananapi_M2_Ultra" "arm-linux-gnueabihf"))
575
c55c6985
DM
576(define-public u-boot-a20-olinuxino-lime
577 (make-u-boot-package "A20-OLinuXino-Lime" "arm-linux-gnueabihf"))
578
4b9e9abb
DM
579(define-public u-boot-a20-olinuxino-lime2
580 (make-u-boot-package "A20-OLinuXino-Lime2" "arm-linux-gnueabihf"))
581
a7bb327e
DM
582(define-public u-boot-a20-olinuxino-micro
583 (make-u-boot-package "A20-OLinuXino_MICRO" "arm-linux-gnueabihf"))
584
84ee3378
DM
585(define-public u-boot-nintendo-nes-classic-edition
586 (make-u-boot-package "Nintendo_NES_Classic_Edition" "arm-linux-gnueabihf"))
587
95a3422e
VC
588(define-public u-boot-wandboard
589 (make-u-boot-package "wandboard" "arm-linux-gnueabihf"))
590
adc61d72
VC
591(define-public u-boot-mx6cuboxi
592 (make-u-boot-package "mx6cuboxi" "arm-linux-gnueabihf"))
593
1b960787
VC
594(define-public u-boot-novena
595 (make-u-boot-package "novena" "arm-linux-gnueabihf"))
596
dd4fe0c2
DM
597(define-public u-boot-cubieboard
598 (make-u-boot-package "Cubieboard" "arm-linux-gnueabihf"))
599
a7d5ce94
JL
600(define-public u-boot-cubietruck
601 (make-u-boot-package "Cubietruck" "arm-linux-gnueabihf"))
602
6fe16577
VC
603(define-public u-boot-puma-rk3399
604 (let ((base (make-u-boot-package "puma-rk3399" "aarch64-linux-gnu")))
605 (package
606 (inherit base)
607 (arguments
608 (substitute-keyword-arguments (package-arguments base)
609 ((#:phases phases)
610 `(modify-phases ,phases
611 (add-after 'unpack 'set-environment
612 (lambda* (#:key inputs #:allow-other-keys)
613 ;; Need to copy the firmware into u-boot build
614 ;; directory.
615 (copy-file (string-append (assoc-ref inputs "firmware")
616 "/bl31.bin") "bl31-rk3399.bin")
617 (copy-file (string-append (assoc-ref inputs "firmware-m0")
618 "/rk3399m0.bin") "rk3399m0.bin")
619 #t))
620 (add-after 'build 'build-itb
621 (lambda* (#:key make-flags #:allow-other-keys)
622 ;; The u-boot.itb is not built by default.
623 (apply invoke "make" `(,@make-flags ,"u-boot.itb"))))
624 (add-after 'build-itb 'build-rksd
625 (lambda* (#:key inputs #:allow-other-keys)
626 ;; Build Rockchip SD card images.
627 (invoke "./tools/mkimage" "-T" "rksd" "-n" "rk3399" "-d"
628 "spl/u-boot-spl.bin" "u-boot-spl.rksd")))))))
629 (native-inputs
630 `(("firmware" ,arm-trusted-firmware-puma-rk3399)
631 ("firmware-m0" ,rk3399-cortex-m0)
632 ,@(package-native-inputs base))))))
633
a60f1319
MB
634(define-public vboot-utils
635 (package
636 (name "vboot-utils")
637 (version "R63-10032.B")
638 (source (origin
639 ;; XXX: Snapshots are available but changes timestamps every download.
640 (method git-fetch)
641 (uri (git-reference
642 (url (string-append "https://chromium.googlesource.com"
643 "/chromiumos/platform/vboot_reference"))
644 (commit (string-append "release-" version))))
645 (file-name (string-append name "-" version "-checkout"))
646 (sha256
647 (base32
648 "0h0m3l69vp9dr6xrs1p6y7ilkq3jq8jraw2z20kqfv7lvc9l1lxj"))))
649 (build-system gnu-build-system)
650 (arguments
651 `(#:make-flags (list "CC=gcc"
652 (string-append "DESTDIR=" (assoc-ref %outputs "out")))
653 #:phases (modify-phases %standard-phases
654 (add-after 'unpack 'patch-hard-coded-paths
655 (lambda* (#:key inputs outputs #:allow-other-keys)
656 (let ((coreutils (assoc-ref inputs "coreutils"))
657 (diffutils (assoc-ref inputs "diffutils")))
658 (substitute* "futility/misc.c"
659 (("/bin/cp") (string-append coreutils "/bin/cp")))
660 (substitute* "tests/bitmaps/TestBmpBlock.py"
661 (("/usr/bin/cmp") (string-append diffutils "/bin/cmp")))
662 (substitute* "vboot_host.pc.in"
663 (("prefix=/usr")
664 (string-append "prefix=" (assoc-ref outputs "out"))))
665 #t)))
666 (delete 'configure)
667 (add-before 'check 'patch-tests
668 (lambda _
669 ;; These tests compare diffs against known-good values.
670 ;; Patch the paths to match those in the build container.
671 (substitute* (find-files "tests/futility/expect_output")
672 (("/mnt/host/source/src/platform/vboot_reference")
673 (string-append "/tmp/guix-build-" ,name "-" ,version
674 ".drv-0/source")))
675 ;; Tests require write permissions to many of these files.
676 (for-each make-file-writable (find-files "tests/futility"))
677 #t)))
678 #:test-target "runtests"))
679 (native-inputs
680 `(("pkg-config" ,pkg-config)
681
682 ;; For tests.
683 ("diffutils" ,diffutils)
684 ("python@2" ,python-2)))
685 (inputs
686 `(("coreutils" ,coreutils)
687 ("libyaml" ,libyaml)
688 ("openssl" ,openssl)
689 ("openssl:static" ,openssl "static")
690 ("util-linux" ,util-linux)))
691 (home-page
692 "https://dev.chromium.org/chromium-os/chromiumos-design-docs/verified-boot")
693 (synopsis "ChromiumOS verified boot utilities")
694 (description
695 "vboot-utils is a collection of tools to facilitate booting of
696Chrome-branded devices. This includes the @command{cgpt} partitioning
697program, the @command{futility} and @command{crossystem} firmware management
698tools, and more.")
699 (license license:bsd-3)))
700
aa90375a
AI
701(define-public os-prober
702 (package
703 (name "os-prober")
704 (version "1.76")
705 (source
706 (origin
707 (method url-fetch)
708 (uri (string-append "mirror://debian/pool/main/o/os-prober/os-prober_"
709 version ".tar.xz"))
710 (sha256
711 (base32
712 "1vb45i76bqivlghrq7m3n07qfmmq4wxrkplqx8gywj011rhq19fk"))))
713 (build-system gnu-build-system)
714 (arguments
715 `(#:modules ((guix build gnu-build-system)
716 (guix build utils)
717 (ice-9 regex) ; for string-match
718 (srfi srfi-26)) ; for cut
719 #:make-flags (list "CC=gcc")
720 #:tests? #f ; no tests
721 #:phases
722 (modify-phases %standard-phases
723 (replace 'configure
724 (lambda* (#:key outputs #:allow-other-keys)
725 (substitute* (find-files ".")
726 (("/usr") (assoc-ref outputs "out")))
727 (substitute* (find-files "." "50mounted-tests$")
728 (("mkdir") "mkdir -p"))
729 #t))
730 (replace 'install
731 (lambda* (#:key outputs #:allow-other-keys)
732 (define (find-files-non-recursive directory)
733 (find-files directory
734 (lambda (file stat)
735 (string-match (string-append "^" directory "/[^/]*$")
736 file))
737 #:directories? #t))
738
739 (let* ((out (assoc-ref outputs "out"))
740 (bin (string-append out "/bin"))
741 (lib (string-append out "/lib"))
742 (share (string-append out "/share")))
743 (for-each (cut install-file <> bin)
744 (list "linux-boot-prober" "os-prober"))
745 (install-file "newns" (string-append lib "/os-prober"))
746 (install-file "common.sh" (string-append share "/os-prober"))
747 (install-file "os-probes/mounted/powerpc/20macosx"
748 (string-append lib "/os-probes/mounted"))
749 (for-each
750 (lambda (directory)
751 (for-each
752 (lambda (file)
753 (let ((destination (string-append lib "/" directory
754 "/" (basename file))))
755 (mkdir-p (dirname destination))
756 (copy-recursively file destination)))
757 (append (find-files-non-recursive (string-append directory "/common"))
758 (find-files-non-recursive (string-append directory "/x86")))))
759 (list "os-probes" "os-probes/mounted" "os-probes/init"
760 "linux-boot-probes" "linux-boot-probes/mounted"))
761 #t))))))
762 (home-page "https://joeyh.name/code/os-prober")
763 (synopsis "Detect other operating systems")
764 (description "os-prober probes disks on the system for other operating
765systems so that they can be added to the bootloader. It also works out how to
766boot existing GNU/Linux systems and detects what distribution is installed in
767order to add a suitable bootloader menu entry.")
768 (license license:gpl2+)))