gnu: Update dtc to 1.5.0.
[jackhill/guix/guix.git] / gnu / packages / bootloaders.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019 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, 2019 Tobias Geerinckx-Rice <me@tobias.gr>
11 ;;; Copyright © 2019 nee <nee@cock.li>
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
28 (define-module (gnu packages bootloaders)
29 #:use-module (gnu packages)
30 #:use-module (gnu packages admin)
31 #:use-module ((gnu packages algebra) #:select (bc))
32 #:use-module (gnu packages assembly)
33 #:use-module (gnu packages base)
34 #:use-module (gnu packages disk)
35 #:use-module (gnu packages bison)
36 #:use-module (gnu packages cdrom)
37 #:use-module (gnu packages check)
38 #:use-module (gnu packages compression)
39 #:use-module (gnu packages cross-base)
40 #:use-module (gnu packages disk)
41 #:use-module (gnu packages firmware)
42 #:use-module (gnu packages flex)
43 #:use-module (gnu packages fontutils)
44 #:use-module (gnu packages gcc)
45 #:use-module (gnu packages gettext)
46 #:use-module (gnu packages linux)
47 #:use-module (gnu packages man)
48 #:use-module (gnu packages mtools)
49 #:use-module (gnu packages ncurses)
50 #:use-module (gnu packages perl)
51 #:use-module (gnu packages pkg-config)
52 #:use-module (gnu packages python)
53 #:use-module (gnu packages texinfo)
54 #:use-module (gnu packages tls)
55 #:use-module (gnu packages sdl)
56 #:use-module (gnu packages swig)
57 #:use-module (gnu packages valgrind)
58 #:use-module (gnu packages virtualization)
59 #:use-module (gnu packages xorg)
60 #:use-module (gnu packages web)
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)
66 #:use-module (guix utils)
67 #:use-module (srfi srfi-1)
68 #:use-module (srfi srfi-26)
69 #:use-module (ice-9 regex))
70
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
82 (define-public grub
83 (package
84 (name "grub")
85 (version "2.02")
86 (source (origin
87 (method url-fetch)
88 (uri (string-append "mirror://gnu/grub/grub-" version ".tar.xz"))
89 (sha256
90 (base32
91 "03vvdfhdmf16121v7xs8is2krwnv15wpkhkf16a4yf8nsfc3f2w1"))
92 (patches (search-patches "grub-check-error-efibootmgr.patch"
93 "grub-binutils-compat.patch"))))
94 (build-system gnu-build-system)
95 (arguments
96 `(#:phases (modify-phases %standard-phases
97 (add-after 'unpack 'patch-stuff
98 (lambda* (#:key inputs #:allow-other-keys)
99 (substitute* "grub-core/Makefile.in"
100 (("/bin/sh") (which "sh")))
101
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
112 ;; Make the font visible.
113 (copy-file (assoc-ref inputs "unifont") "unifont.bdf.gz")
114 (system* "gunzip" "unifont.bdf.gz")
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 ")))
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"))
129 #t)))
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")))))
134 (inputs
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.
143 ("mdadm" ,mdadm)
144
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
149 ("freetype" ,freetype)
150 ;; ("libusb" ,libusb)
151 ;; ("fuse" ,fuse)
152 ("ncurses" ,ncurses)))
153 (native-inputs
154 `(("pkg-config" ,pkg-config)
155 ("unifont" ,unifont)
156 ("bison" ,bison)
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)
161 ("texinfo" ,texinfo)
162 ("help2man" ,help2man)
163
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
180 ;; Dependencies for the test suite. The "real" QEMU is needed here,
181 ;; because several targets are used.
182 ("parted" ,parted)
183 ("qemu" ,qemu-minimal-2.10)
184 ("xorriso" ,xorriso)))
185 (home-page "https://www.gnu.org/software/grub/")
186 (synopsis "GRand Unified Boot loader")
187 (description
188 "GRUB is a multiboot bootloader. It is used for initially loading the
189 kernel of an operating system and then transferring control to it. The kernel
190 then goes on to load the rest of the operating system. As a multiboot
191 bootloader, GRUB handles the presence of multiple operating systems installed
192 on the same computer; upon booting the computer, the user is presented with a
193 menu to select one of the installed operating systems.")
194 (license license:gpl3+)
195 (properties '((cpe-name . "grub2")))))
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)
204 ("mtools" ,mtools)
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".
210 ,@(substitute-keyword-arguments (package-arguments grub)
211 ((#:tests? _ #f) #f)
212 ((#:configure-flags flags ''())
213 `(cons "--with-platform=efi" ,flags))
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")))
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))))))))))
235
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)
263 (if (not (or (string-prefix? "." basename)
264 (file-exists? (string-append output-dir "/" basename))))
265 (symlink (string-append input-dir "/" basename)
266 (string-append output-dir "/" basename))))
267 (scandir input-dir))
268 #t)))))))))
269
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
290 `(("libuuid" ,util-linux)
291 ("mtools" ,mtools)))
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
306 (lambda* (#:key inputs #:allow-other-keys)
307 (substitute* (find-files "." "Makefile.*|ppmtolss16")
308 (("/bin/pwd") (which "pwd"))
309 (("/bin/echo") (which "echo"))
310 (("/usr/bin/perl") (which "perl")))
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"))))
317 #t))
318 (delete 'configure)
319 (add-before 'build 'set-permissions
320 (lambda _
321 (invoke "chmod" "a+w" "utils/isohybrid.in")))
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/") ""))
328 (invoke "make" "unittest"))))))
329 (home-page "https://www.syslinux.org")
330 (synopsis "Lightweight Linux bootloader")
331 (description "Syslinux is a lightweight Linux bootloader.")
332 ;; The Makefile specifically targets i386 and x86_64 using nasm.
333 (supported-systems '("i686-linux" "x86_64-linux"))
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)))))
339
340 (define-public dtc
341 (package
342 (name "dtc")
343 (version "1.5.0")
344 (source (origin
345 (method url-fetch)
346 (uri (string-append
347 "mirror://kernel.org/software/utils/dtc/"
348 "dtc-" version ".tar.xz"))
349 (sha256
350 (base32
351 "0wh10p42hf5403ipvs0dsxddb6kzfyk2sq4fgid9zqzpr51y8wn6"))))
352 (build-system gnu-build-system)
353 (native-inputs
354 `(("bison" ,bison)
355 ("flex" ,flex)
356 ("libyaml" ,libyaml)
357 ("pkg-config" ,pkg-config)
358 ("swig" ,swig)
359 ("valgrind" ,valgrind)))
360 (inputs
361 `(("python-2" ,python-2)))
362 (arguments
363 `(#:make-flags
364 (list "CC=gcc"
365 (string-append "PREFIX=" (assoc-ref %outputs "out"))
366 (string-append "SETUP_PREFIX=" (assoc-ref %outputs "out"))
367 "INSTALL=install")
368 #:phases
369 (modify-phases %standard-phases
370 (delete 'configure)))) ; no configure script
371 (home-page "https://www.devicetree.org")
372 (synopsis "Compiles device tree source files")
373 (description "@command{dtc} compiles
374 @uref{http://elinux.org/Device_Tree_Usage, device tree source files} to device
375 tree binary files. These are board description files used by Linux and BSD.")
376 (license license:gpl2+)))
377
378 (define u-boot
379 (package
380 (name "u-boot")
381 (version "2019.01")
382 (source (origin
383 (method url-fetch)
384 (uri (string-append
385 "ftp://ftp.denx.de/pub/u-boot/"
386 "u-boot-" version ".tar.bz2"))
387 (sha256
388 (base32
389 "08hwsmh5xsb1gcxsv8gvx00bai938dm5y3889n8jif3a8rd7xgah"))))
390 (native-inputs
391 `(("bc" ,bc)
392 ("bison" ,bison)
393 ("dtc" ,dtc)
394 ("flex" ,flex)
395 ("lz4" ,lz4)
396 ("python-2" ,python-2)
397 ("python2-coverage" ,python2-coverage)
398 ("python2-pytest" ,python2-pytest)
399 ("sdl" ,sdl)
400 ("swig" ,swig)))
401 (build-system gnu-build-system)
402 (home-page "https://www.denx.de/wiki/U-Boot/")
403 (synopsis "ARM bootloader")
404 (description "U-Boot is a bootloader used mostly for ARM boards. It
405 also initializes the boards (RAM etc).")
406 (license license:gpl2+)))
407
408 (define-public u-boot-tools
409 (package
410 (inherit u-boot)
411 (name "u-boot-tools")
412 (arguments
413 `(#:make-flags '("HOSTCC=gcc")
414 #:test-target "tests"
415 #:phases
416 (modify-phases %standard-phases
417 (add-after 'unpack 'patch
418 (lambda* (#:key inputs #:allow-other-keys)
419 (substitute* "Makefile"
420 (("/bin/pwd") (which "pwd"))
421 (("/bin/false") (which "false")))
422 (substitute* "tools/dtoc/fdt_util.py"
423 (("'cc'") "'gcc'"))
424 (substitute* "tools/patman/test_util.py"
425 ;; python-coverage is simply called coverage in guix.
426 (("python-coverage") "coverage")
427 ;; XXX Allow for only 99% test coverage.
428 ;; TODO: Find out why that is needed.
429 (("if coverage != '100%':") "if not int(coverage.rstrip('%')) >= 99:"))
430 (substitute* "test/run"
431 ;; Make it easier to find test failures.
432 (("#!/bin/bash") "#!/bin/bash -x")
433 ;; pytest doesn't find it otherwise.
434 (("test/py/tests/test_ofplatdata.py")
435 "tests/test_ofplatdata.py")
436 ;; This test would require git.
437 (("\\./tools/patman/patman") (which "true"))
438 ;; This test would require internet access.
439 (("\\./tools/buildman/buildman") (which "true")))
440 (substitute* "test/py/tests/test_sandbox_exit.py"
441 (("def test_ctrl_c")
442 "@pytest.mark.skip(reason='Guix has problems with SIGINT')
443 def test_ctrl_c"))
444 (for-each (lambda (file)
445 (substitute* file
446 ;; Disable signatures, due to GPL/Openssl
447 ;; license incompatibilities. See
448 ;; https://bugs.gnu.org/34717 for details.
449 (("CONFIG_FIT_SIGNATURE=y") "CONFIG_FIT_SIGNATURE=n")
450 ;; This test requires a sound system, which is un-used
451 ;; in u-boot-tools.
452 (("CONFIG_SOUND=y") "CONFIG_SOUND=n")))
453 (find-files "configs" "sandbox_.*defconfig$"))
454 #t))
455 (replace 'configure
456 (lambda* (#:key make-flags #:allow-other-keys)
457 (call-with-output-file "configs/tools_defconfig"
458 (lambda (port)
459 (display "CONFIG_SYS_TEXT_BASE=0\n" port)))
460 (apply invoke "make" "tools_defconfig" make-flags)))
461 (replace 'build
462 (lambda* (#:key inputs make-flags #:allow-other-keys)
463 (apply invoke "make" "tools-all" make-flags)))
464 (replace 'install
465 (lambda* (#:key outputs #:allow-other-keys)
466 (let* ((out (assoc-ref outputs "out"))
467 (bin (string-append out "/bin")))
468 (for-each (lambda (name)
469 (install-file name bin))
470 '("tools/netconsole"
471 "tools/jtagconsole"
472 "tools/gen_eth_addr"
473 "tools/gen_ethaddr_crc"
474 "tools/img2srec"
475 "tools/mkenvimage"
476 "tools/dumpimage"
477 "tools/mkimage"
478 "tools/proftool"
479 "tools/fdtgrep"
480 "tools/env/fw_printenv"
481 "tools/sunxi-spl-image-builder"))
482 #t)))
483 (delete 'check)
484 (add-after 'install 'check
485 (lambda* (#:key make-flags test-target #:allow-other-keys)
486 (apply invoke "make" "mrproper" make-flags)
487 (setenv "SDL_VIDEODRIVER" "dummy")
488 (setenv "PAGER" "cat")
489 (apply invoke "make" test-target make-flags)
490 (symlink "build-sandbox_spl" "sandbox")
491 (invoke "test/image/test-imagetools.sh"))))))
492 (description "U-Boot is a bootloader used mostly for ARM boards. It
493 also initializes the boards (RAM etc). This package provides its
494 board-independent tools.")))
495
496 (define-public (make-u-boot-package board triplet)
497 "Returns a u-boot package for BOARD cross-compiled for TRIPLET."
498 (let ((same-arch? (if (string-prefix? (%current-system)
499 (gnu-triplet->nix-system triplet))
500 `#t
501 `#f)))
502 (package
503 (inherit u-boot)
504 (name (string-append "u-boot-"
505 (string-replace-substring (string-downcase board)
506 "_" "-")))
507 (native-inputs
508 `(,@(if (not same-arch?)
509 `(("cross-gcc" ,(cross-gcc triplet #:xgcc gcc-7))
510 ("cross-binutils" ,(cross-binutils triplet)))
511 `(("gcc-7" ,gcc-7)))
512 ,@(package-native-inputs u-boot)))
513 (arguments
514 `(#:modules ((ice-9 ftw)
515 (srfi srfi-1)
516 (guix build utils)
517 (guix build gnu-build-system))
518 #:test-target "test"
519 #:make-flags
520 (list "HOSTCC=gcc"
521 ,@(if (not same-arch?)
522 `((string-append "CROSS_COMPILE=" ,triplet "-"))
523 '()))
524 #:phases
525 (modify-phases %standard-phases
526 (replace 'configure
527 (lambda* (#:key outputs make-flags #:allow-other-keys)
528 (let ((config-name (string-append ,board "_defconfig")))
529 (if (file-exists? (string-append "configs/" config-name))
530 (apply invoke "make" `(,@make-flags ,config-name))
531 (begin
532 (display "Invalid board name. Valid board names are:"
533 (current-error-port))
534 (let ((suffix-len (string-length "_defconfig"))
535 (entries (scandir "configs")))
536 (for-each (lambda (file-name)
537 (when (string-suffix? "_defconfig" file-name)
538 (format (current-error-port)
539 "- ~A\n"
540 (string-drop-right file-name
541 suffix-len))))
542 (sort entries string-ci<)))
543 (error "Invalid boardname ~s." ,board))))))
544 (replace 'install
545 (lambda* (#:key outputs #:allow-other-keys)
546 (let* ((out (assoc-ref outputs "out"))
547 (libexec (string-append out "/libexec"))
548 (uboot-files (append
549 (remove
550 ;; Those would not be reproducible
551 ;; because of the randomness used
552 ;; to produce them.
553 ;; It's expected that the user will
554 ;; use u-boot-tools to generate them
555 ;; instead.
556 (lambda (name)
557 (string-suffix?
558 "sunxi-spl-with-ecc.bin"
559 name))
560 (find-files "." ".*\\.(bin|efi|img|spl|itb|dtb|rksd)$"))
561 (find-files "." "^(MLO|SPL)$"))))
562 (mkdir-p libexec)
563 (install-file ".config" libexec)
564 ;; Useful for "qemu -kernel".
565 (install-file "u-boot" libexec)
566 (for-each
567 (lambda (file)
568 (let ((target-file (string-append libexec "/" file)))
569 (mkdir-p (dirname target-file))
570 (copy-file file target-file)))
571 uboot-files)
572 #t)))))))))
573
574 (define-public u-boot-vexpress
575 (make-u-boot-package "vexpress_ca9x4" "arm-linux-gnueabihf"))
576
577 (define-public u-boot-malta
578 (make-u-boot-package "malta" "mips64el-linux-gnuabi64"))
579
580 (define-public u-boot-beagle-bone-black
581 (make-u-boot-package "am335x_boneblack" "arm-linux-gnueabihf"))
582
583 (define-public (make-u-boot-sunxi64-package board triplet)
584 (let ((base (make-u-boot-package board triplet)))
585 (package
586 (inherit base)
587 (arguments
588 (substitute-keyword-arguments (package-arguments base)
589 ((#:phases phases)
590 `(modify-phases ,phases
591 (add-after 'unpack 'set-environment
592 (lambda* (#:key inputs #:allow-other-keys)
593 (let ((bl31 (string-append (assoc-ref inputs "firmware")
594 "/bl31.bin")))
595 (setenv "BL31" bl31)
596 ;; This is necessary when we're using the bundled dtc.
597 ;(setenv "PATH" (string-append (getenv "PATH") ":"
598 ; "scripts/dtc"))
599 )
600 #t))))))
601 (native-inputs
602 `(("firmware" ,arm-trusted-firmware-sun50i-a64)
603 ,@(package-native-inputs base))))))
604
605 (define-public u-boot-pine64-plus
606 (make-u-boot-sunxi64-package "pine64_plus" "aarch64-linux-gnu"))
607
608 (define-public u-boot-pinebook
609 (make-u-boot-sunxi64-package "pinebook" "aarch64-linux-gnu"))
610
611 (define-public u-boot-bananapi-m2-ultra
612 (make-u-boot-package "Bananapi_M2_Ultra" "arm-linux-gnueabihf"))
613
614 (define-public u-boot-a20-olinuxino-lime
615 (make-u-boot-package "A20-OLinuXino-Lime" "arm-linux-gnueabihf"))
616
617 (define-public u-boot-a20-olinuxino-lime2
618 (make-u-boot-package "A20-OLinuXino-Lime2" "arm-linux-gnueabihf"))
619
620 (define-public u-boot-a20-olinuxino-micro
621 (make-u-boot-package "A20-OLinuXino_MICRO" "arm-linux-gnueabihf"))
622
623 (define-public u-boot-nintendo-nes-classic-edition
624 (make-u-boot-package "Nintendo_NES_Classic_Edition" "arm-linux-gnueabihf"))
625
626 (define-public u-boot-wandboard
627 (make-u-boot-package "wandboard" "arm-linux-gnueabihf"))
628
629 (define-public u-boot-mx6cuboxi
630 (make-u-boot-package "mx6cuboxi" "arm-linux-gnueabihf"))
631
632 (define-public u-boot-novena
633 (let ((base (make-u-boot-package "novena" "arm-linux-gnueabihf")))
634 (package
635 (inherit base)
636 (description "U-Boot is a bootloader used mostly for ARM boards. It
637 also initializes the boards (RAM etc).
638
639 This U-Boot is built for Novena. Be advised that this version, contrary
640 to Novena upstream, does not load u-boot.img from the first patition.")
641 (arguments
642 (substitute-keyword-arguments (package-arguments base)
643 ((#:phases phases)
644 `(modify-phases ,phases
645 (add-after 'unpack 'patch-novena-defconfig
646 ;; Patch configuration to disable loading u-boot.img from FAT partition,
647 ;; allowing it to be installed at a device offset.
648 (lambda _
649 (substitute* "configs/novena_defconfig"
650 (("CONFIG_SPL_FAT_SUPPORT=y") "# CONFIG_SPL_FAT_SUPPORT is not set"))
651 #t)))))))))
652
653 (define-public u-boot-cubieboard
654 (make-u-boot-package "Cubieboard" "arm-linux-gnueabihf"))
655
656 (define-public u-boot-cubietruck
657 (make-u-boot-package "Cubietruck" "arm-linux-gnueabihf"))
658
659 (define-public u-boot-puma-rk3399
660 (let ((base (make-u-boot-package "puma-rk3399" "aarch64-linux-gnu")))
661 (package
662 (inherit base)
663 (arguments
664 (substitute-keyword-arguments (package-arguments base)
665 ((#:phases phases)
666 `(modify-phases ,phases
667 (add-after 'unpack 'set-environment
668 (lambda* (#:key inputs #:allow-other-keys)
669 ;; Need to copy the firmware into u-boot build
670 ;; directory.
671 (copy-file (string-append (assoc-ref inputs "firmware")
672 "/bl31.bin") "bl31-rk3399.bin")
673 (copy-file (string-append (assoc-ref inputs "firmware-m0")
674 "/rk3399m0.bin") "rk3399m0.bin")
675 #t))
676 (add-after 'build 'build-itb
677 (lambda* (#:key make-flags #:allow-other-keys)
678 ;; The u-boot.itb is not built by default.
679 (apply invoke "make" `(,@make-flags ,"u-boot.itb"))))
680 (add-after 'build-itb 'build-rksd
681 (lambda* (#:key inputs #:allow-other-keys)
682 ;; Build Rockchip SD card images.
683 (invoke "./tools/mkimage" "-T" "rksd" "-n" "rk3399" "-d"
684 "spl/u-boot-spl.bin" "u-boot-spl.rksd")))))))
685 (native-inputs
686 `(("firmware" ,arm-trusted-firmware-puma-rk3399)
687 ("firmware-m0" ,rk3399-cortex-m0)
688 ,@(package-native-inputs base))))))
689
690 (define-public vboot-utils
691 (package
692 (name "vboot-utils")
693 (version "R63-10032.B")
694 (source (origin
695 ;; XXX: Snapshots are available but changes timestamps every download.
696 (method git-fetch)
697 (uri (git-reference
698 (url (string-append "https://chromium.googlesource.com"
699 "/chromiumos/platform/vboot_reference"))
700 (commit (string-append "release-" version))))
701 (file-name (string-append name "-" version "-checkout"))
702 (sha256
703 (base32
704 "0h0m3l69vp9dr6xrs1p6y7ilkq3jq8jraw2z20kqfv7lvc9l1lxj"))
705 (patches
706 (search-patches "vboot-utils-skip-test-workbuf.patch"
707 "vboot-utils-fix-tests-show-contents.patch"
708 "vboot-utils-fix-format-load-address.patch"))))
709 (build-system gnu-build-system)
710 (arguments
711 `(#:make-flags (list "CC=gcc"
712 ;; On ARM, we must pass "HOST_ARCH=arm" so that the
713 ;; ${HOST_ARCH} and ${ARCH} variables in the makefile
714 ;; match. Otherwise, ${HOST_ARCH} will be assigned
715 ;; "armv7l", the value of `uname -m`, and will not
716 ;; match ${ARCH}, which will make the tests require
717 ;; QEMU for testing.
718 ,@(if (string-prefix? "arm"
719 (or (%current-target-system)
720 (%current-system)))
721 '("HOST_ARCH=arm")
722 '())
723 (string-append "DESTDIR=" (assoc-ref %outputs "out")))
724 #:phases (modify-phases %standard-phases
725 (add-after 'unpack 'patch-hard-coded-paths
726 (lambda* (#:key inputs outputs #:allow-other-keys)
727 (let ((coreutils (assoc-ref inputs "coreutils"))
728 (diffutils (assoc-ref inputs "diffutils")))
729 (substitute* "futility/misc.c"
730 (("/bin/cp") (string-append coreutils "/bin/cp")))
731 (substitute* "tests/bitmaps/TestBmpBlock.py"
732 (("/usr/bin/cmp") (string-append diffutils "/bin/cmp")))
733 (substitute* "vboot_host.pc.in"
734 (("prefix=/usr")
735 (string-append "prefix=" (assoc-ref outputs "out"))))
736 #t)))
737 (delete 'configure)
738 (add-before 'check 'patch-tests
739 (lambda _
740 ;; These tests compare diffs against known-good values.
741 ;; Patch the paths to match those in the build container.
742 (substitute* (find-files "tests/futility/expect_output")
743 (("/mnt/host/source/src/platform/vboot_reference")
744 (string-append "/tmp/guix-build-" ,name "-" ,version
745 ".drv-0/source")))
746 ;; Tests require write permissions to many of these files.
747 (for-each make-file-writable (find-files "tests/futility"))
748 #t))
749 (add-after 'install 'install-devkeys
750 (lambda* (#:key outputs #:allow-other-keys)
751 (let* ((out (assoc-ref outputs "out"))
752 (share (string-append out "/share/vboot-utils")))
753 (copy-recursively "tests/devkeys"
754 (string-append share "/devkeys"))
755 #t))))
756 #:test-target "runtests"))
757 (native-inputs
758 `(("pkg-config" ,pkg-config)
759
760 ;; For tests.
761 ("diffutils" ,diffutils)
762 ("python@2" ,python-2)))
763 (inputs
764 `(("coreutils" ,coreutils)
765 ("libyaml" ,libyaml)
766 ("openssl" ,openssl)
767 ("openssl:static" ,openssl "static")
768 ("util-linux" ,util-linux)))
769 (home-page
770 "https://dev.chromium.org/chromium-os/chromiumos-design-docs/verified-boot")
771 (synopsis "ChromiumOS verified boot utilities")
772 (description
773 "vboot-utils is a collection of tools to facilitate booting of
774 Chrome-branded devices. This includes the @command{cgpt} partitioning
775 program, the @command{futility} and @command{crossystem} firmware management
776 tools, and more.")
777 (license license:bsd-3)))
778
779 (define-public os-prober
780 (package
781 (name "os-prober")
782 (version "1.77")
783 (source
784 (origin
785 (method url-fetch)
786 (uri (string-append "mirror://debian/pool/main/o/os-prober/os-prober_"
787 version ".tar.xz"))
788 (sha256
789 (base32
790 "0pvhrw4h05n21zw7ig3a3bi8aqdh6zxs0x1znz4g7vhspsps93ld"))))
791 (build-system gnu-build-system)
792 (arguments
793 `(#:modules ((guix build gnu-build-system)
794 (guix build utils)
795 (ice-9 regex) ; for string-match
796 (srfi srfi-26)) ; for cut
797 #:make-flags (list "CC=gcc")
798 #:tests? #f ; no tests
799 #:phases
800 (modify-phases %standard-phases
801 (replace 'configure
802 (lambda* (#:key outputs #:allow-other-keys)
803 (substitute* (find-files ".")
804 (("/usr") (assoc-ref outputs "out")))
805 (substitute* (find-files "." "50mounted-tests$")
806 (("mkdir") "mkdir -p"))
807 #t))
808 (replace 'install
809 (lambda* (#:key outputs #:allow-other-keys)
810 (define (find-files-non-recursive directory)
811 (find-files directory
812 (lambda (file stat)
813 (string-match (string-append "^" directory "/[^/]*$")
814 file))
815 #:directories? #t))
816
817 (let* ((out (assoc-ref outputs "out"))
818 (bin (string-append out "/bin"))
819 (lib (string-append out "/lib"))
820 (share (string-append out "/share")))
821 (for-each (cut install-file <> bin)
822 (list "linux-boot-prober" "os-prober"))
823 (install-file "newns" (string-append lib "/os-prober"))
824 (install-file "common.sh" (string-append share "/os-prober"))
825 (install-file "os-probes/mounted/powerpc/20macosx"
826 (string-append lib "/os-probes/mounted"))
827 (for-each
828 (lambda (directory)
829 (for-each
830 (lambda (file)
831 (let ((destination (string-append lib "/" directory
832 "/" (basename file))))
833 (mkdir-p (dirname destination))
834 (copy-recursively file destination)))
835 (append (find-files-non-recursive (string-append directory "/common"))
836 (find-files-non-recursive (string-append directory "/x86")))))
837 (list "os-probes" "os-probes/mounted" "os-probes/init"
838 "linux-boot-probes" "linux-boot-probes/mounted"))
839 #t))))))
840 (home-page "https://joeyh.name/code/os-prober")
841 (synopsis "Detect other operating systems")
842 (description "os-prober probes disks on the system for other operating
843 systems so that they can be added to the bootloader. It also works out how to
844 boot existing GNU/Linux systems and detects what distribution is installed in
845 order to add a suitable bootloader menu entry.")
846 (license license:gpl2+)))