gnu: Add fflas-ffpack.
[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 "grub-efi-fat-serial-number.patch"))))
95 (build-system gnu-build-system)
96 (arguments
97 `(#:phases (modify-phases %standard-phases
98 (add-after 'unpack 'patch-stuff
99 (lambda* (#:key inputs #:allow-other-keys)
100 (substitute* "grub-core/Makefile.in"
101 (("/bin/sh") (which "sh")))
102
103 ;; Give the absolute file name of 'mdadm', used to
104 ;; determine the root file system when it's a RAID
105 ;; device. Failing to do that, 'grub-probe' silently
106 ;; fails if 'mdadm' is not in $PATH.
107 (substitute* "grub-core/osdep/linux/getroot.c"
108 (("argv\\[0\\] = \"mdadm\"")
109 (string-append "argv[0] = \""
110 (assoc-ref inputs "mdadm")
111 "/sbin/mdadm\"")))
112
113 ;; Make the font visible.
114 (copy-file (assoc-ref inputs "unifont") "unifont.bdf.gz")
115 (system* "gunzip" "unifont.bdf.gz")
116
117 ;; Give the absolute file name of 'ckbcomp'.
118 (substitute* "util/grub-kbdcomp.in"
119 (("^ckbcomp ")
120 (string-append (assoc-ref inputs "console-setup")
121 "/bin/ckbcomp ")))
122 #t))
123 (add-before 'check 'disable-flaky-test
124 (lambda _
125 ;; This test is unreliable. For more information, see:
126 ;; <https://bugs.gnu.org/26936>.
127 (substitute* "Makefile.in"
128 (("grub_cmd_date grub_cmd_set_date grub_cmd_sleep")
129 "grub_cmd_date grub_cmd_sleep"))
130 #t)))
131 ;; Disable tests on ARM and AARCH64 platforms.
132 #:tests? ,(not (any (cute string-prefix? <> (or (%current-target-system)
133 (%current-system)))
134 '("arm" "aarch64")))))
135 (inputs
136 `(("gettext" ,gettext-minimal)
137
138 ;; Depend on LVM2 for libdevmapper, used by 'grub-probe' and
139 ;; 'grub-install' to recognize mapped devices (LUKS, etc.)
140 ("lvm2" ,lvm2)
141
142 ;; Depend on mdadm, which is invoked by 'grub-probe' and 'grub-install'
143 ;; to determine whether the root file system is RAID.
144 ("mdadm" ,mdadm)
145
146 ;; Console-setup's ckbcomp is invoked by grub-kbdcomp. It is required
147 ;; for generating alternative keyboard layouts.
148 ("console-setup" ,console-setup)
149
150 ("freetype" ,freetype)
151 ;; ("libusb" ,libusb)
152 ;; ("fuse" ,fuse)
153 ("ncurses" ,ncurses)))
154 (native-inputs
155 `(("pkg-config" ,pkg-config)
156 ("unifont" ,unifont)
157 ("bison" ,bison)
158 ;; Due to a bug in flex >= 2.6.2, GRUB must be built with an older flex:
159 ;; <http://lists.gnu.org/archive/html/grub-devel/2017-02/msg00133.html>
160 ;; TODO Try building with flex > 2.6.4.
161 ("flex" ,flex-2.6.1)
162 ("texinfo" ,texinfo)
163 ("help2man" ,help2man)
164
165 ;; XXX: When building GRUB 2.02 on 32-bit x86, we need a binutils
166 ;; capable of assembling 64-bit instructions. However, our default
167 ;; binutils on 32-bit x86 is not 64-bit capable.
168 ,@(if (string-match "^i[3456]86-" (%current-system))
169 (let ((binutils (package/inherit
170 binutils
171 (name "binutils-i386")
172 (arguments
173 (substitute-keyword-arguments (package-arguments binutils)
174 ((#:configure-flags flags ''())
175 `(cons "--enable-64-bit-bfd" ,flags)))))))
176 `(("ld-wrapper" ,(make-ld-wrapper "ld-wrapper-i386"
177 #:binutils binutils))
178 ("binutils" ,binutils)))
179 '())
180
181 ;; Dependencies for the test suite. The "real" QEMU is needed here,
182 ;; because several targets are used.
183 ("parted" ,parted)
184 ("qemu" ,qemu-minimal-2.10)
185 ("xorriso" ,xorriso)))
186 (home-page "https://www.gnu.org/software/grub/")
187 (synopsis "GRand Unified Boot loader")
188 (description
189 "GRUB is a multiboot bootloader. It is used for initially loading the
190 kernel of an operating system and then transferring control to it. The kernel
191 then goes on to load the rest of the operating system. As a multiboot
192 bootloader, GRUB handles the presence of multiple operating systems installed
193 on the same computer; upon booting the computer, the user is presented with a
194 menu to select one of the installed operating systems.")
195 (license license:gpl3+)
196 (properties '((cpe-name . "grub2")))))
197
198 (define-public grub-efi
199 (package
200 (inherit grub)
201 (name "grub-efi")
202 (synopsis "GRand Unified Boot loader (UEFI version)")
203 (inputs
204 `(("efibootmgr" ,efibootmgr)
205 ("mtools" ,mtools)
206 ,@(package-inputs grub)))
207 (arguments
208 `(;; TODO: Tests need a UEFI firmware for qemu. There is one at
209 ;; https://github.com/tianocore/edk2/tree/master/OvmfPkg .
210 ;; Search for 'OVMF' in "tests/util/grub-shell.in".
211 ,@(substitute-keyword-arguments (package-arguments grub)
212 ((#:tests? _ #f) #f)
213 ((#:configure-flags flags ''())
214 `(cons "--with-platform=efi" ,flags))
215 ((#:phases phases)
216 `(modify-phases ,phases
217 (add-after 'patch-stuff 'use-absolute-efibootmgr-path
218 (lambda* (#:key inputs #:allow-other-keys)
219 (substitute* "grub-core/osdep/unix/platform.c"
220 (("efibootmgr")
221 (string-append (assoc-ref inputs "efibootmgr")
222 "/sbin/efibootmgr")))
223 #t))
224 (add-after 'patch-stuff 'use-absolute-mtools-path
225 (lambda* (#:key inputs #:allow-other-keys)
226 (let ((mtools (assoc-ref inputs "mtools")))
227 (substitute* "util/grub-mkrescue.c"
228 (("\"mformat\"")
229 (string-append "\"" mtools
230 "/bin/mformat\"")))
231 (substitute* "util/grub-mkrescue.c"
232 (("\"mcopy\"")
233 (string-append "\"" mtools
234 "/bin/mcopy\"")))
235 #t))))))))))
236
237 ;; Because grub searches hardcoded paths it's easiest to just build grub
238 ;; again to make it find both grub-pc and grub-efi. There is a command
239 ;; line argument which allows you to specify ONE platform - but
240 ;; grub-mkrescue will use multiple platforms if they are available
241 ;; in the installation directory (without command line argument).
242 (define-public grub-hybrid
243 (package
244 (inherit grub-efi)
245 (name "grub-hybrid")
246 (synopsis "GRand Unified Boot loader (hybrid version)")
247 (inputs
248 `(("grub" ,grub)
249 ,@(package-inputs grub-efi)))
250 (arguments
251 (substitute-keyword-arguments (package-arguments grub-efi)
252 ((#:modules modules `((guix build utils) (guix build gnu-build-system)))
253 `((ice-9 ftw) ,@modules))
254 ((#:phases phases)
255 `(modify-phases ,phases
256 (add-after 'install 'install-non-efi
257 (lambda* (#:key inputs outputs #:allow-other-keys)
258 (let ((input-dir (string-append (assoc-ref inputs "grub")
259 "/lib/grub"))
260 (output-dir (string-append (assoc-ref outputs "out")
261 "/lib/grub")))
262 (for-each
263 (lambda (basename)
264 (if (not (or (string-prefix? "." basename)
265 (file-exists? (string-append output-dir "/" basename))))
266 (symlink (string-append input-dir "/" basename)
267 (string-append output-dir "/" basename))))
268 (scandir input-dir))
269 #t)))))))))
270
271 (define-public syslinux
272 (let ((commit "bb41e935cc83c6242de24d2271e067d76af3585c"))
273 (package
274 (name "syslinux")
275 (version (git-version "6.04-pre" "1" commit))
276 (source (origin
277 (method git-fetch)
278 (uri (git-reference
279 (url "https://github.com/geneC/syslinux")
280 (commit commit)))
281 (file-name (git-file-name name version))
282 (sha256
283 (base32
284 "0k8dvafd6410kqxf3kyr4y8jzmpmrih6wbjqg6gklak7945yflrc"))))
285 (build-system gnu-build-system)
286 (native-inputs
287 `(("nasm" ,nasm)
288 ("perl" ,perl)
289 ("python-2" ,python-2)))
290 (inputs
291 `(("libuuid" ,util-linux)
292 ("mtools" ,mtools)))
293 (arguments
294 `(#:parallel-build? #f
295 #:make-flags
296 (list (string-append "BINDIR=" %output "/bin")
297 (string-append "SBINDIR=" %output "/sbin")
298 (string-append "LIBDIR=" %output "/lib")
299 (string-append "INCDIR=" %output "/include")
300 (string-append "DATADIR=" %output "/share")
301 (string-append "MANDIR=" %output "/share/man")
302 "PERL=perl"
303 "bios")
304 #:phases
305 (modify-phases %standard-phases
306 (add-after 'unpack 'patch-files
307 (lambda* (#:key inputs #:allow-other-keys)
308 (substitute* (find-files "." "Makefile.*|ppmtolss16")
309 (("/bin/pwd") (which "pwd"))
310 (("/bin/echo") (which "echo"))
311 (("/usr/bin/perl") (which "perl")))
312 (let ((mtools (assoc-ref inputs "mtools")))
313 (substitute* (find-files "." "\\.c$")
314 (("mcopy")
315 (string-append mtools "/bin/mcopy"))
316 (("mattrib")
317 (string-append mtools "/bin/mattrib"))))
318 #t))
319 (delete 'configure)
320 (add-before 'build 'set-permissions
321 (lambda _
322 (invoke "chmod" "a+w" "utils/isohybrid.in")))
323 (replace 'check
324 (lambda _
325 (setenv "CC" "gcc")
326 (substitute* "tests/unittest/include/unittest/unittest.h"
327 ;; Don't look up headers under /usr.
328 (("/usr/include/") ""))
329 (invoke "make" "unittest"))))))
330 (home-page "https://www.syslinux.org")
331 (synopsis "Lightweight Linux bootloader")
332 (description "Syslinux is a lightweight Linux bootloader.")
333 ;; The Makefile specifically targets i386 and x86_64 using nasm.
334 (supported-systems '("i686-linux" "x86_64-linux"))
335 (license (list license:gpl2+
336 license:bsd-3 ; gnu-efi/*
337 license:bsd-4 ; gnu-efi/inc/* gnu-efi/lib/*
338 ;; Also contains:
339 license:expat license:isc license:zlib)))))
340
341 (define-public dtc
342 (package
343 (name "dtc")
344 (version "1.5.0")
345 (source (origin
346 (method url-fetch)
347 (uri (string-append
348 "mirror://kernel.org/software/utils/dtc/"
349 "dtc-" version ".tar.xz"))
350 (sha256
351 (base32
352 "0wh10p42hf5403ipvs0dsxddb6kzfyk2sq4fgid9zqzpr51y8wn6"))))
353 (build-system gnu-build-system)
354 (native-inputs
355 `(("bison" ,bison)
356 ("flex" ,flex)
357 ("libyaml" ,libyaml)
358 ("pkg-config" ,pkg-config)
359 ("swig" ,swig)
360 ("valgrind" ,valgrind)))
361 (inputs
362 `(("python-2" ,python-2)))
363 (arguments
364 `(#:make-flags
365 (list "CC=gcc"
366 (string-append "PREFIX=" (assoc-ref %outputs "out"))
367 (string-append "SETUP_PREFIX=" (assoc-ref %outputs "out"))
368 "INSTALL=install")
369 #:phases
370 (modify-phases %standard-phases
371 (delete 'configure)))) ; no configure script
372 (home-page "https://www.devicetree.org")
373 (synopsis "Compiles device tree source files")
374 (description "@command{dtc} compiles
375 @uref{http://elinux.org/Device_Tree_Usage, device tree source files} to device
376 tree binary files. These are board description files used by Linux and BSD.")
377 (license license:gpl2+)))
378
379 (define u-boot
380 (package
381 (name "u-boot")
382 (version "2019.04")
383 (source (origin
384 (method url-fetch)
385 (uri (string-append
386 "ftp://ftp.denx.de/pub/u-boot/"
387 "u-boot-" version ".tar.bz2"))
388 (sha256
389 (base32
390 "1vwv4bgbl7fjcm073zrphn17hnz5h5h778f88ivdsgbb2lnpgdvn"))
391 (patches
392 (search-patches
393 "u-boot-fix-mkimage-header-verification.patch"))))
394 (native-inputs
395 `(("bc" ,bc)
396 ("bison" ,bison)
397 ("dtc" ,dtc)
398 ("flex" ,flex)
399 ("lz4" ,lz4)
400 ("python-2" ,python-2)
401 ("python2-coverage" ,python2-coverage)
402 ("python2-pytest" ,python2-pytest)
403 ("sdl" ,sdl)
404 ("swig" ,swig)))
405 (build-system gnu-build-system)
406 (home-page "https://www.denx.de/wiki/U-Boot/")
407 (synopsis "ARM bootloader")
408 (description "U-Boot is a bootloader used mostly for ARM boards. It
409 also initializes the boards (RAM etc).")
410 (license license:gpl2+)))
411
412 (define-public u-boot-tools
413 (package
414 (inherit u-boot)
415 (name "u-boot-tools")
416 (arguments
417 `(#:make-flags '("HOSTCC=gcc")
418 #:test-target "tests"
419 #:phases
420 (modify-phases %standard-phases
421 (add-after 'unpack 'patch
422 (lambda* (#:key inputs #:allow-other-keys)
423 (substitute* "Makefile"
424 (("/bin/pwd") (which "pwd"))
425 (("/bin/false") (which "false")))
426 (substitute* "tools/dtoc/fdt_util.py"
427 (("'cc'") "'gcc'"))
428 (substitute* "tools/patman/test_util.py"
429 ;; python-coverage is simply called coverage in guix.
430 (("python-coverage") "coverage")
431 ;; XXX Allow for only 99% test coverage.
432 ;; TODO: Find out why that is needed.
433 (("if coverage != '100%':") "if not int(coverage.rstrip('%')) >= 99:"))
434 (substitute* "test/run"
435 ;; Make it easier to find test failures.
436 (("#!/bin/bash") "#!/bin/bash -x")
437 ;; pytest doesn't find it otherwise.
438 (("test/py/tests/test_ofplatdata.py")
439 "tests/test_ofplatdata.py")
440 ;; This test would require git.
441 (("\\./tools/patman/patman") (which "true"))
442 ;; This test would require internet access.
443 (("\\./tools/buildman/buildman") (which "true")))
444 (substitute* "test/py/tests/test_sandbox_exit.py"
445 (("def test_ctrl_c")
446 "@pytest.mark.skip(reason='Guix has problems with SIGINT')
447 def test_ctrl_c"))
448 ;; Test against the tools being installed rather than tools built
449 ;; for "sandbox" target.
450 (substitute* "test/image/test-imagetools.sh"
451 (("BASEDIR=sandbox") "BASEDIR=."))
452 (for-each (lambda (file)
453 (substitute* file
454 ;; Disable signatures, due to GPL/Openssl
455 ;; license incompatibilities. See
456 ;; https://bugs.gnu.org/34717 for details.
457 (("CONFIG_FIT_SIGNATURE=y") "CONFIG_FIT_SIGNATURE=n")
458 ;; This test requires a sound system, which is un-used
459 ;; in u-boot-tools.
460 (("CONFIG_SOUND=y") "CONFIG_SOUND=n")))
461 (find-files "configs" "sandbox_.*defconfig$"))
462 #t))
463 (replace 'configure
464 (lambda* (#:key make-flags #:allow-other-keys)
465 (call-with-output-file "configs/tools_defconfig"
466 (lambda (port)
467 (display "CONFIG_SYS_TEXT_BASE=0\n" port)))
468 (apply invoke "make" "tools_defconfig" make-flags)))
469 (replace 'build
470 (lambda* (#:key inputs make-flags #:allow-other-keys)
471 (apply invoke "make" "tools-all" make-flags)))
472 (replace 'install
473 (lambda* (#:key outputs #:allow-other-keys)
474 (let* ((out (assoc-ref outputs "out"))
475 (bin (string-append out "/bin")))
476 (for-each (lambda (name)
477 (install-file name bin))
478 '("tools/netconsole"
479 "tools/jtagconsole"
480 "tools/gen_eth_addr"
481 "tools/gen_ethaddr_crc"
482 "tools/img2srec"
483 "tools/mkenvimage"
484 "tools/dumpimage"
485 "tools/mkimage"
486 "tools/proftool"
487 "tools/fdtgrep"
488 "tools/env/fw_printenv"
489 "tools/sunxi-spl-image-builder"))
490 #t)))
491 (delete 'check)
492 (add-after 'install 'check
493 (lambda* (#:key make-flags test-target #:allow-other-keys)
494 (invoke "test/image/test-imagetools.sh")))
495 ;; Only run full test suite on x86_64 systems, as many tests
496 ;; assume x86_64.
497 ,@(if (string-match "^x86_64-linux"
498 (or (%current-target-system)
499 (%current-system)))
500 '((add-after 'check 'check-x86
501 (lambda* (#:key make-flags test-target #:allow-other-keys)
502 (apply invoke "make" "mrproper" make-flags)
503 (setenv "SDL_VIDEODRIVER" "dummy")
504 (setenv "PAGER" "cat")
505 (apply invoke "make" test-target make-flags))))
506 '()))))
507 (description "U-Boot is a bootloader used mostly for ARM boards. It
508 also initializes the boards (RAM etc). This package provides its
509 board-independent tools.")))
510
511 (define-public (make-u-boot-package board triplet)
512 "Returns a u-boot package for BOARD cross-compiled for TRIPLET."
513 (let ((same-arch? (if (string-prefix? (%current-system)
514 (gnu-triplet->nix-system triplet))
515 `#t
516 `#f)))
517 (package
518 (inherit u-boot)
519 (name (string-append "u-boot-"
520 (string-replace-substring (string-downcase board)
521 "_" "-")))
522 (native-inputs
523 `(,@(if (not same-arch?)
524 `(("cross-gcc" ,(cross-gcc triplet #:xgcc gcc-7))
525 ("cross-binutils" ,(cross-binutils triplet)))
526 `(("gcc-7" ,gcc-7)))
527 ,@(package-native-inputs u-boot)))
528 (arguments
529 `(#:modules ((ice-9 ftw)
530 (srfi srfi-1)
531 (guix build utils)
532 (guix build gnu-build-system))
533 #:test-target "test"
534 #:make-flags
535 (list "HOSTCC=gcc"
536 ,@(if (not same-arch?)
537 `((string-append "CROSS_COMPILE=" ,triplet "-"))
538 '()))
539 #:phases
540 (modify-phases %standard-phases
541 (replace 'configure
542 (lambda* (#:key outputs make-flags #:allow-other-keys)
543 (let ((config-name (string-append ,board "_defconfig")))
544 (if (file-exists? (string-append "configs/" config-name))
545 (apply invoke "make" `(,@make-flags ,config-name))
546 (begin
547 (display "Invalid board name. Valid board names are:"
548 (current-error-port))
549 (let ((suffix-len (string-length "_defconfig"))
550 (entries (scandir "configs")))
551 (for-each (lambda (file-name)
552 (when (string-suffix? "_defconfig" file-name)
553 (format (current-error-port)
554 "- ~A\n"
555 (string-drop-right file-name
556 suffix-len))))
557 (sort entries string-ci<)))
558 (error "Invalid boardname ~s." ,board))))))
559 (replace 'install
560 (lambda* (#:key outputs #:allow-other-keys)
561 (let* ((out (assoc-ref outputs "out"))
562 (libexec (string-append out "/libexec"))
563 (uboot-files (append
564 (remove
565 ;; Those would not be reproducible
566 ;; because of the randomness used
567 ;; to produce them.
568 ;; It's expected that the user will
569 ;; use u-boot-tools to generate them
570 ;; instead.
571 (lambda (name)
572 (string-suffix?
573 "sunxi-spl-with-ecc.bin"
574 name))
575 (find-files "." ".*\\.(bin|efi|img|spl|itb|dtb|rksd)$"))
576 (find-files "." "^(MLO|SPL)$"))))
577 (mkdir-p libexec)
578 (install-file ".config" libexec)
579 ;; Useful for "qemu -kernel".
580 (install-file "u-boot" libexec)
581 (for-each
582 (lambda (file)
583 (let ((target-file (string-append libexec "/" file)))
584 (mkdir-p (dirname target-file))
585 (copy-file file target-file)))
586 uboot-files)
587 #t)))))))))
588
589 (define-public u-boot-vexpress
590 (make-u-boot-package "vexpress_ca9x4" "arm-linux-gnueabihf"))
591
592 (define-public u-boot-malta
593 (make-u-boot-package "malta" "mips64el-linux-gnuabi64"))
594
595 (define-public u-boot-am335x-boneblack
596 (let ((base (make-u-boot-package "am335x_evm" "arm-linux-gnueabihf")))
597 (package
598 (inherit base)
599 (name "u-boot-am335x-boneblack")
600 (description "U-Boot is a bootloader used mostly for ARM boards. It
601 also initializes the boards (RAM etc).
602
603 This U-Boot is built for the BeagleBone Black, which was removed upstream,
604 adjusted from the am335x_evm build with several device trees removed so that
605 it fits within common partitioning schemes.")
606 (arguments
607 (substitute-keyword-arguments (package-arguments base)
608 ((#:phases phases)
609 `(modify-phases ,phases
610 (add-after 'unpack 'patch-defconfig
611 ;; Patch out other devicetrees to build image small enough to
612 ;; fit within typical partitioning schemes where the first
613 ;; partition begins at sector 2048.
614 (lambda _
615 (substitute* "configs/am335x_evm_defconfig"
616 (("CONFIG_OF_LIST=.*$") "CONFIG_OF_LIST=\"am335x-evm am335x-boneblack\"\n"))
617 #t)))))))))
618
619 (define-public u-boot-am335x-evm
620 (make-u-boot-package "am335x_evm" "arm-linux-gnueabihf"))
621
622 (define-public (make-u-boot-sunxi64-package board triplet)
623 (let ((base (make-u-boot-package board triplet)))
624 (package
625 (inherit base)
626 (arguments
627 (substitute-keyword-arguments (package-arguments base)
628 ((#:phases phases)
629 `(modify-phases ,phases
630 (add-after 'unpack 'set-environment
631 (lambda* (#:key inputs #:allow-other-keys)
632 (let ((bl31 (string-append (assoc-ref inputs "firmware")
633 "/bl31.bin")))
634 (setenv "BL31" bl31)
635 ;; This is necessary when we're using the bundled dtc.
636 ;(setenv "PATH" (string-append (getenv "PATH") ":"
637 ; "scripts/dtc"))
638 )
639 #t))))))
640 (native-inputs
641 `(("firmware" ,arm-trusted-firmware-sun50i-a64)
642 ,@(package-native-inputs base))))))
643
644 (define-public u-boot-pine64-plus
645 (make-u-boot-sunxi64-package "pine64_plus" "aarch64-linux-gnu"))
646
647 (define-public u-boot-pinebook
648 (make-u-boot-sunxi64-package "pinebook" "aarch64-linux-gnu"))
649
650 (define-public u-boot-bananapi-m2-ultra
651 (make-u-boot-package "Bananapi_M2_Ultra" "arm-linux-gnueabihf"))
652
653 (define-public u-boot-a20-olinuxino-lime
654 (make-u-boot-package "A20-OLinuXino-Lime" "arm-linux-gnueabihf"))
655
656 (define-public u-boot-a20-olinuxino-lime2
657 (make-u-boot-package "A20-OLinuXino-Lime2" "arm-linux-gnueabihf"))
658
659 (define-public u-boot-a20-olinuxino-micro
660 (make-u-boot-package "A20-OLinuXino_MICRO" "arm-linux-gnueabihf"))
661
662 (define-public u-boot-nintendo-nes-classic-edition
663 (make-u-boot-package "Nintendo_NES_Classic_Edition" "arm-linux-gnueabihf"))
664
665 (define-public u-boot-wandboard
666 (make-u-boot-package "wandboard" "arm-linux-gnueabihf"))
667
668 (define-public u-boot-mx6cuboxi
669 (make-u-boot-package "mx6cuboxi" "arm-linux-gnueabihf"))
670
671 (define-public u-boot-novena
672 (let ((base (make-u-boot-package "novena" "arm-linux-gnueabihf")))
673 (package
674 (inherit base)
675 (description "U-Boot is a bootloader used mostly for ARM boards. It
676 also initializes the boards (RAM etc).
677
678 This U-Boot is built for Novena. Be advised that this version, contrary
679 to Novena upstream, does not load u-boot.img from the first partition.")
680 (arguments
681 (substitute-keyword-arguments (package-arguments base)
682 ((#:phases phases)
683 `(modify-phases ,phases
684 (add-after 'unpack 'patch-novena-defconfig
685 ;; Patch configuration to disable loading u-boot.img from FAT partition,
686 ;; allowing it to be installed at a device offset.
687 (lambda _
688 (substitute* "configs/novena_defconfig"
689 (("CONFIG_SPL_FS_FAT=y") "# CONFIG_SPL_FS_FAT is not set"))
690 #t)))))))))
691
692 (define-public u-boot-cubieboard
693 (make-u-boot-package "Cubieboard" "arm-linux-gnueabihf"))
694
695 (define-public u-boot-cubietruck
696 (make-u-boot-package "Cubietruck" "arm-linux-gnueabihf"))
697
698 (define-public u-boot-puma-rk3399
699 (let ((base (make-u-boot-package "puma-rk3399" "aarch64-linux-gnu")))
700 (package
701 (inherit base)
702 (arguments
703 (substitute-keyword-arguments (package-arguments base)
704 ((#:phases phases)
705 `(modify-phases ,phases
706 (add-after 'unpack 'set-environment
707 (lambda* (#:key inputs #:allow-other-keys)
708 ;; Need to copy the firmware into u-boot build
709 ;; directory.
710 (copy-file (string-append (assoc-ref inputs "firmware")
711 "/bl31.bin") "bl31-rk3399.bin")
712 (copy-file (string-append (assoc-ref inputs "firmware-m0")
713 "/rk3399m0.bin") "rk3399m0.bin")
714 #t))
715 (add-after 'build 'build-itb
716 (lambda* (#:key make-flags #:allow-other-keys)
717 ;; The u-boot.itb is not built by default.
718 (apply invoke "make" `(,@make-flags ,"u-boot.itb"))))
719 (add-after 'build-itb 'build-rksd
720 (lambda* (#:key inputs #:allow-other-keys)
721 ;; Build Rockchip SD card images.
722 (invoke "./tools/mkimage" "-T" "rksd" "-n" "rk3399" "-d"
723 "spl/u-boot-spl.bin" "u-boot-spl.rksd")))))))
724 (native-inputs
725 `(("firmware" ,arm-trusted-firmware-puma-rk3399)
726 ("firmware-m0" ,rk3399-cortex-m0)
727 ,@(package-native-inputs base))))))
728
729 (define-public vboot-utils
730 (package
731 (name "vboot-utils")
732 (version "R63-10032.B")
733 (source (origin
734 ;; XXX: Snapshots are available but changes timestamps every download.
735 (method git-fetch)
736 (uri (git-reference
737 (url (string-append "https://chromium.googlesource.com"
738 "/chromiumos/platform/vboot_reference"))
739 (commit (string-append "release-" version))))
740 (file-name (string-append name "-" version "-checkout"))
741 (sha256
742 (base32
743 "0h0m3l69vp9dr6xrs1p6y7ilkq3jq8jraw2z20kqfv7lvc9l1lxj"))
744 (patches
745 (search-patches "vboot-utils-skip-test-workbuf.patch"
746 "vboot-utils-fix-tests-show-contents.patch"
747 "vboot-utils-fix-format-load-address.patch"))))
748 (build-system gnu-build-system)
749 (arguments
750 `(#:make-flags (list "CC=gcc"
751 ;; On ARM, we must pass "HOST_ARCH=arm" so that the
752 ;; ${HOST_ARCH} and ${ARCH} variables in the makefile
753 ;; match. Otherwise, ${HOST_ARCH} will be assigned
754 ;; "armv7l", the value of `uname -m`, and will not
755 ;; match ${ARCH}, which will make the tests require
756 ;; QEMU for testing.
757 ,@(if (string-prefix? "arm"
758 (or (%current-target-system)
759 (%current-system)))
760 '("HOST_ARCH=arm")
761 '())
762 (string-append "DESTDIR=" (assoc-ref %outputs "out")))
763 #:phases (modify-phases %standard-phases
764 (add-after 'unpack 'patch-hard-coded-paths
765 (lambda* (#:key inputs outputs #:allow-other-keys)
766 (let ((coreutils (assoc-ref inputs "coreutils"))
767 (diffutils (assoc-ref inputs "diffutils")))
768 (substitute* "futility/misc.c"
769 (("/bin/cp") (string-append coreutils "/bin/cp")))
770 (substitute* "tests/bitmaps/TestBmpBlock.py"
771 (("/usr/bin/cmp") (string-append diffutils "/bin/cmp")))
772 (substitute* "vboot_host.pc.in"
773 (("prefix=/usr")
774 (string-append "prefix=" (assoc-ref outputs "out"))))
775 #t)))
776 (delete 'configure)
777 (add-before 'check 'patch-tests
778 (lambda _
779 ;; These tests compare diffs against known-good values.
780 ;; Patch the paths to match those in the build container.
781 (substitute* (find-files "tests/futility/expect_output")
782 (("/mnt/host/source/src/platform/vboot_reference")
783 (string-append "/tmp/guix-build-" ,name "-" ,version
784 ".drv-0/source")))
785 ;; Tests require write permissions to many of these files.
786 (for-each make-file-writable (find-files "tests/futility"))
787 #t))
788 (add-after 'install 'install-devkeys
789 (lambda* (#:key outputs #:allow-other-keys)
790 (let* ((out (assoc-ref outputs "out"))
791 (share (string-append out "/share/vboot-utils")))
792 (copy-recursively "tests/devkeys"
793 (string-append share "/devkeys"))
794 #t))))
795 #:test-target "runtests"))
796 (native-inputs
797 `(("pkg-config" ,pkg-config)
798
799 ;; For tests.
800 ("diffutils" ,diffutils)
801 ("python@2" ,python-2)))
802 (inputs
803 `(("coreutils" ,coreutils)
804 ("libyaml" ,libyaml)
805 ("openssl" ,openssl)
806 ("openssl:static" ,openssl "static")
807 ("util-linux" ,util-linux)))
808 (home-page
809 "https://dev.chromium.org/chromium-os/chromiumos-design-docs/verified-boot")
810 (synopsis "ChromiumOS verified boot utilities")
811 (description
812 "vboot-utils is a collection of tools to facilitate booting of
813 Chrome-branded devices. This includes the @command{cgpt} partitioning
814 program, the @command{futility} and @command{crossystem} firmware management
815 tools, and more.")
816 (license license:bsd-3)))
817
818 (define-public os-prober
819 (package
820 (name "os-prober")
821 (version "1.77")
822 (source
823 (origin
824 (method url-fetch)
825 (uri (string-append "mirror://debian/pool/main/o/os-prober/os-prober_"
826 version ".tar.xz"))
827 (sha256
828 (base32
829 "0pvhrw4h05n21zw7ig3a3bi8aqdh6zxs0x1znz4g7vhspsps93ld"))))
830 (build-system gnu-build-system)
831 (arguments
832 `(#:modules ((guix build gnu-build-system)
833 (guix build utils)
834 (ice-9 regex) ; for string-match
835 (srfi srfi-26)) ; for cut
836 #:make-flags (list "CC=gcc")
837 #:tests? #f ; no tests
838 #:phases
839 (modify-phases %standard-phases
840 (replace 'configure
841 (lambda* (#:key outputs #:allow-other-keys)
842 (substitute* (find-files ".")
843 (("/usr") (assoc-ref outputs "out")))
844 (substitute* (find-files "." "50mounted-tests$")
845 (("mkdir") "mkdir -p"))
846 #t))
847 (replace 'install
848 (lambda* (#:key outputs #:allow-other-keys)
849 (define (find-files-non-recursive directory)
850 (find-files directory
851 (lambda (file stat)
852 (string-match (string-append "^" directory "/[^/]*$")
853 file))
854 #:directories? #t))
855
856 (let* ((out (assoc-ref outputs "out"))
857 (bin (string-append out "/bin"))
858 (lib (string-append out "/lib"))
859 (share (string-append out "/share")))
860 (for-each (cut install-file <> bin)
861 (list "linux-boot-prober" "os-prober"))
862 (install-file "newns" (string-append lib "/os-prober"))
863 (install-file "common.sh" (string-append share "/os-prober"))
864 (install-file "os-probes/mounted/powerpc/20macosx"
865 (string-append lib "/os-probes/mounted"))
866 (for-each
867 (lambda (directory)
868 (for-each
869 (lambda (file)
870 (let ((destination (string-append lib "/" directory
871 "/" (basename file))))
872 (mkdir-p (dirname destination))
873 (copy-recursively file destination)))
874 (append (find-files-non-recursive (string-append directory "/common"))
875 (find-files-non-recursive (string-append directory "/x86")))))
876 (list "os-probes" "os-probes/mounted" "os-probes/init"
877 "linux-boot-probes" "linux-boot-probes/mounted"))
878 #t))))))
879 (home-page "https://joeyh.name/code/os-prober")
880 (synopsis "Detect other operating systems")
881 (description "os-prober probes disks on the system for other operating
882 systems so that they can be added to the bootloader. It also works out how to
883 boot existing GNU/Linux systems and detects what distribution is installed in
884 order to add a suitable bootloader menu entry.")
885 (license license:gpl2+)))