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