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