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