gnu: emacs-helm: Update to 3.8.7.
[jackhill/guix/guix.git] / gnu / packages / bootloaders.scm
CommitLineData
65d8b777 1;;; GNU Guix --- Functional package management for GNU
bc64d955 2;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2021 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>
d613991a 5;;; Copyright © 2016, 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
c87ebc1b 6;;; Copyright © 2016, 2017, 2018, 2021 Marius Bakke <marius@gnu.org>
862e38d5
DC
7;;; Copyright © 2016, 2017 Danny Milosavljevic <dannym@scratchpost.org>
8;;; Copyright © 2016, 2017 David Craven <david@craven.ch>
0dc99fd1 9;;; Copyright © 2017, 2018, 2020, 2021, 2022 Efraim Flashner <efraim@flashner.co.il>
aeed7218 10;;; Copyright © 2018, 2019, 2020, 2021 Tobias Geerinckx-Rice <me@tobias.gr>
ab100b90 11;;; Copyright © 2019 nee <nee@cock.li>
af58b275 12;;; Copyright © 2019 Mathieu Othacehe <m.othacehe@gmail.com>
5664a471 13;;; Copyright © 2020 Björn Höfling <bjoern.hoefling@bjoernhoefling.de>
5327b399 14;;; Copyright © 2018, 2019, 2020 Vagrant Cascadian <vagrant@debian.org>
adb84ae8 15;;; Copyright © 2020, 2021 Pierre Langlois <pierre.langlois@gmx.com>
aeed7218
VL
16;;; Copyright © 2021 Vincent Legoll <vincent.legoll@gmail.com>
17;;; Copyright © 2021 Brice Waegeneire <brice@waegenei.re>
62c86c83 18;;; Copyright © 2022 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
65d8b777
LC
19;;;
20;;; This file is part of GNU Guix.
21;;;
22;;; GNU Guix is free software; you can redistribute it and/or modify it
23;;; under the terms of the GNU General Public License as published by
24;;; the Free Software Foundation; either version 3 of the License, or (at
25;;; your option) any later version.
26;;;
27;;; GNU Guix is distributed in the hope that it will be useful, but
28;;; WITHOUT ANY WARRANTY; without even the implied warranty of
29;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30;;; GNU General Public License for more details.
31;;;
32;;; You should have received a copy of the GNU General Public License
33;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
34
862e38d5 35(define-module (gnu packages bootloaders)
65d8b777 36 #:use-module (gnu packages)
862e38d5 37 #:use-module (gnu packages admin)
178e5500 38 #:use-module (gnu packages algebra)
862e38d5 39 #:use-module (gnu packages assembly)
a60f1319 40 #:use-module (gnu packages base)
7febe3a2 41 #:use-module (gnu packages disk)
65d8b777 42 #:use-module (gnu packages bison)
862e38d5 43 #:use-module (gnu packages cdrom)
65212c42 44 #:use-module (gnu packages check)
0c7707d5 45 #:use-module (gnu packages compression)
862e38d5
DC
46 #:use-module (gnu packages cross-base)
47 #:use-module (gnu packages disk)
29be6cfb 48 #:use-module (gnu packages firmware)
862e38d5 49 #:use-module (gnu packages flex)
a86177d6 50 #:use-module (gnu packages fontutils)
f074f5e8 51 #:use-module (gnu packages gcc)
862e38d5 52 #:use-module (gnu packages gettext)
65d8b777 53 #:use-module (gnu packages linux)
862e38d5 54 #:use-module (gnu packages man)
444f9dcc 55 #:use-module (gnu packages mtools)
862e38d5 56 #:use-module (gnu packages ncurses)
96b714f5 57 #:use-module (gnu packages perl)
a60f1319 58 #:use-module (gnu packages pkg-config)
96b714f5 59 #:use-module (gnu packages python)
eb46c6c5 60 #:use-module (gnu packages python-crypto)
58301666 61 #:use-module (gnu packages texinfo)
a60f1319 62 #:use-module (gnu packages tls)
65212c42 63 #:use-module (gnu packages sdl)
e8122816 64 #:use-module (gnu packages serialization)
12c613b5 65 #:use-module (gnu packages swig)
5d706f18 66 #:use-module (gnu packages valgrind)
59132b80 67 #:use-module (gnu packages virtualization)
ab100b90 68 #:use-module (gnu packages xorg)
862e38d5
DC
69 #:use-module (guix build-system gnu)
70 #:use-module (guix download)
71 #:use-module (guix git-download)
72 #:use-module ((guix licenses) #:prefix license:)
73 #:use-module (guix packages)
63087721
EF
74 #:use-module (guix utils)
75 #:use-module (srfi srfi-1)
a7c87169
MW
76 #:use-module (srfi srfi-26)
77 #:use-module (ice-9 regex))
65d8b777 78
9b24c768
LC
79(define unifont
80 ;; GNU Unifont, <http://gnu.org/s/unifont>.
81 ;; GRUB needs it for its graphical terminal, gfxterm.
82 (origin
83 (method url-fetch)
84 (uri
85 "http://unifoundry.com/pub/unifont-7.0.06/font-builds/unifont-7.0.06.bdf.gz")
86 (sha256
87 (base32
88 "0p2vhnc18cnbmb39vq4m7hzv4mhnm2l0a2s7gx3ar277fwng3hys"))))
89
65d8b777
LC
90(define-public grub
91 (package
92 (name "grub")
2d115ea7 93 (version "2.06")
65d8b777
LC
94 (source (origin
95 (method url-fetch)
3586a3e9 96 (uri (string-append "mirror://gnu/grub/grub-" version ".tar.xz"))
65d8b777
LC
97 (sha256
98 (base32
2d115ea7 99 "1qbycnxkx07arj9f2nlsi9kp0dyldspbv07ysdyd34qvz55a97mp"))
654de94e
JN
100 (patches (search-patches
101 "grub-efi-fat-serial-number.patch"
c87ebc1b
MB
102 "grub-setup-root.patch"))
103 (modules '((guix build utils)))
104 (snippet
105 '(begin
106 ;; Adjust QEMU invocation to not use a deprecated device
107 ;; name that was removed in QEMU 6.0. Remove for >2.06.
108 (substitute* "tests/ahci_test.in"
109 (("ide-drive")
110 "ide-hd"))))))
65d8b777
LC
111 (build-system gnu-build-system)
112 (arguments
069ab3bb
TGR
113 `(#:configure-flags
114 ;; Counterintuitively, this *disables* a spurious Python dependency by
115 ;; calling the ‘true’ binary instead. Python is only needed during
116 ;; bootstrapping (for genptl.py), not when building from a release.
117 (list "PYTHON=true")
650e85d8
MO
118 ;; Grub fails to load modules stripped with --strip-unneeded.
119 #:strip-flags '("--strip-debug" "--enable-deterministic-archives")
069ab3bb 120 #:phases (modify-phases %standard-phases
358db004 121 (add-after 'unpack 'patch-stuff
7c353424 122 (lambda* (#:key native-inputs inputs #:allow-other-keys)
04e0eac1
MW
123 (substitute* "grub-core/Makefile.in"
124 (("/bin/sh") (which "sh")))
65d8b777 125
358db004
LC
126 ;; Give the absolute file name of 'mdadm', used to
127 ;; determine the root file system when it's a RAID
128 ;; device. Failing to do that, 'grub-probe' silently
129 ;; fails if 'mdadm' is not in $PATH.
149666df
EF
130 (when (assoc-ref inputs "mdadm")
131 (substitute* "grub-core/osdep/linux/getroot.c"
132 (("argv\\[0\\] = \"mdadm\"")
133 (string-append "argv[0] = \""
134 (assoc-ref inputs "mdadm")
135 "/sbin/mdadm\""))))
358db004 136
04e0eac1 137 ;; Make the font visible.
7c353424
MO
138 (copy-file (assoc-ref (or native-inputs inputs)
139 "unifont")
140 "unifont.bdf.gz")
04e0eac1 141 (system* "gunzip" "unifont.bdf.gz")
ab100b90 142
143 ;; Give the absolute file name of 'ckbcomp'.
144 (substitute* "util/grub-kbdcomp.in"
145 (("^ckbcomp ")
bc64d955
LC
146 (string-append
147 (search-input-file inputs "/bin/ckbcomp")
148 " ")))))
34a6f123
EF
149 (add-after 'unpack 'set-freetype-variables
150 ;; These variables need to be set to the native versions
151 ;; of the dependencies because they are used to build
152 ;; programs which are executed during build time.
77b7d990
EF
153 (lambda* (#:key native-inputs #:allow-other-keys)
154 (when (assoc-ref native-inputs "freetype")
155 (let ((freetype (assoc-ref native-inputs "freetype")))
156 (setenv "BUILD_FREETYPE_LIBS"
157 (string-append "-L" freetype
158 "/lib -lfreetype"))
159 (setenv "BUILD_FREETYPE_CFLAGS"
160 (string-append "-I" freetype
161 "/include/freetype2"))))
34a6f123 162 #t))
23a53a95
LF
163 (add-before 'check 'disable-flaky-test
164 (lambda _
165 ;; This test is unreliable. For more information, see:
166 ;; <https://bugs.gnu.org/26936>.
167 (substitute* "Makefile.in"
168 (("grub_cmd_date grub_cmd_set_date grub_cmd_sleep")
169 "grub_cmd_date grub_cmd_sleep"))
069ab3bb
TGR
170 #t))
171 (add-before 'check 'disable-pixel-perfect-test
172 (lambda _
173 ;; This test compares many screenshots rendered with an
174 ;; older Unifont (9.0.06) than that packaged in Guix.
175 (substitute* "Makefile.in"
176 (("test_unset grub_func_test")
177 "test_unset"))
56f0feb6 178 #t)))
66f76912
EF
179 ;; Disable tests on ARM and AARCH64 platforms or when cross-compiling.
180 #:tests? ,(not (or (any (cute string-prefix? <> (or (%current-target-system)
181 (%current-system)))
182 '("arm" "aarch64"))
183 (%current-target-system)))))
65d8b777 184 (inputs
10da75df
LC
185 `(("gettext" ,gettext-minimal)
186
187 ;; Depend on LVM2 for libdevmapper, used by 'grub-probe' and
188 ;; 'grub-install' to recognize mapped devices (LUKS, etc.)
654de94e
JN
189 ,@(if (member (or (%current-target-system)
190 (%current-system))
191 (package-supported-systems lvm2))
192 `(("lvm2" ,lvm2))
193 '())
10da75df
LC
194
195 ;; Depend on mdadm, which is invoked by 'grub-probe' and 'grub-install'
196 ;; to determine whether the root file system is RAID.
654de94e
JN
197 ,@(if (member (or (%current-target-system)
198 (%current-system))
199 (package-supported-systems mdadm))
200 `(("mdadm" ,mdadm))
201 '())
10da75df 202
ab100b90 203 ;; Console-setup's ckbcomp is invoked by grub-kbdcomp. It is required
204 ;; for generating alternative keyboard layouts.
205 ("console-setup" ,console-setup)
206
35014c40
TGR
207 ;; Needed for ‘grub-mount’, the only reliable way to tell whether a given
208 ;; file system will be readable by GRUB without rebooting.
654de94e
JN
209 ,@(if (member (or (%current-target-system)
210 (%current-system))
211 (package-supported-systems fuse))
212 `(("fuse" ,fuse))
213 '())
35014c40 214
65d8b777
LC
215 ("freetype" ,freetype)
216 ;; ("libusb" ,libusb)
01eafd38 217 ("ncurses" ,ncurses)))
65d8b777 218 (native-inputs
0a2a7053
MW
219 `(("pkg-config" ,pkg-config)
220 ("unifont" ,unifont)
9b24c768 221 ("bison" ,bison)
f142c077 222 ("flex" ,flex)
58301666
MW
223 ("texinfo" ,texinfo)
224 ("help2man" ,help2man)
34a6f123 225 ("freetype" ,freetype) ; native version needed for build-grub-mkfont
65d8b777 226
a7c87169
MW
227 ;; XXX: When building GRUB 2.02 on 32-bit x86, we need a binutils
228 ;; capable of assembling 64-bit instructions. However, our default
229 ;; binutils on 32-bit x86 is not 64-bit capable.
230 ,@(if (string-match "^i[3456]86-" (%current-system))
231 (let ((binutils (package/inherit
232 binutils
233 (name "binutils-i386")
234 (arguments
235 (substitute-keyword-arguments (package-arguments binutils)
236 ((#:configure-flags flags ''())
237 `(cons "--enable-64-bit-bfd" ,flags)))))))
238 `(("ld-wrapper" ,(make-ld-wrapper "ld-wrapper-i386"
239 #:binutils binutils))
240 ("binutils" ,binutils)))
241 '())
242
65d8b777
LC
243 ;; Dependencies for the test suite. The "real" QEMU is needed here,
244 ;; because several targets are used.
7febe3a2 245 ("parted" ,parted)
654de94e
JN
246 ,@(if (member (%current-system) (package-supported-systems qemu-minimal))
247 `(("qemu" ,qemu-minimal))
248 '())
65d8b777 249 ("xorriso" ,xorriso)))
175b259c 250 (home-page "https://www.gnu.org/software/grub/")
79c311b8 251 (synopsis "GRand Unified Boot loader")
65d8b777 252 (description
a22dc0c4 253 "GRUB is a multiboot bootloader. It is used for initially loading the
35b9e423 254kernel of an operating system and then transferring control to it. The kernel
c5779c93 255then goes on to load the rest of the operating system. As a multiboot
574e86f9
LC
256bootloader, GRUB handles the presence of multiple operating systems installed
257on the same computer; upon booting the computer, the user is presented with a
a22dc0c4 258menu to select one of the installed operating systems.")
3f73aa1a 259 (license license:gpl3+)
99effc8f 260 (properties '((cpe-name . "grub2")))))
acb5f7c3 261
0c962369
JN
262(define-public grub-minimal
263 (package
264 (inherit grub)
265 (name "grub-minimal")
266 (inputs
8394619b
LC
267 (modify-inputs (package-inputs grub)
268 (delete "lvm2" "mdadm" "fuse" "console-setup")))
0c962369 269 (native-inputs
8394619b
LC
270 (modify-inputs (package-native-inputs grub)
271 (delete "help2man" "texinfo" "parted" "qemu" "xorriso")))
0c962369 272 (arguments
097b7255
LC
273 (substitute-keyword-arguments (package-arguments grub)
274 ((#:configure-flags _ ''())
275 '(list "PYTHON=true"))
276 ((#:tests? _ #t)
277 #f)
278 ((#:phases phases '%standard-phases)
279 `(modify-phases ,phases
280 (replace 'patch-stuff
281 (lambda* (#:key native-inputs inputs #:allow-other-keys)
282 (substitute* "grub-core/Makefile.in"
283 (("/bin/sh") (which "sh")))
0c962369 284
097b7255
LC
285 ;; Make the font visible.
286 (copy-file (assoc-ref (or native-inputs inputs)
287 "unifont")
288 "unifont.bdf.gz")
289 (system* "gunzip" "unifont.bdf.gz")
0c962369 290
097b7255 291 #t))))))))
0c962369 292
acb5f7c3
MB
293(define-public grub-efi
294 (package
295 (inherit grub)
296 (name "grub-efi")
297 (synopsis "GRand Unified Boot loader (UEFI version)")
298 (inputs
8394619b
LC
299 (modify-inputs (package-inputs grub)
300 (prepend efibootmgr mtools)))
acb5f7c3
MB
301 (arguments
302 `(;; TODO: Tests need a UEFI firmware for qemu. There is one at
303 ;; https://github.com/tianocore/edk2/tree/master/OvmfPkg .
304 ;; Search for 'OVMF' in "tests/util/grub-shell.in".
acb5f7c3 305 ,@(substitute-keyword-arguments (package-arguments grub)
46ff2dbb 306 ((#:tests? _ #f) #f)
ef753a1a 307 ((#:configure-flags flags ''())
018f9509 308 `(cons* "--with-platform=efi"
fd549750
CB
309 ,@(if (string-prefix? "x86_64"
310 (or (%current-target-system)
311 (%current-system)))
312 '("--enable-stack-protector") ; EFI-only for now
313 '())
018f9509 314 ,flags))
acb5f7c3
MB
315 ((#:phases phases)
316 `(modify-phases ,phases
317 (add-after 'patch-stuff 'use-absolute-efibootmgr-path
318 (lambda* (#:key inputs #:allow-other-keys)
319 (substitute* "grub-core/osdep/unix/platform.c"
320 (("efibootmgr")
bc64d955
LC
321 (search-input-file inputs
322 "/sbin/efibootmgr")))))
444f9dcc
DM
323 (add-after 'patch-stuff 'use-absolute-mtools-path
324 (lambda* (#:key inputs #:allow-other-keys)
325 (let ((mtools (assoc-ref inputs "mtools")))
326 (substitute* "util/grub-mkrescue.c"
327 (("\"mformat\"")
328 (string-append "\"" mtools
329 "/bin/mformat\"")))
330 (substitute* "util/grub-mkrescue.c"
331 (("\"mcopy\"")
332 (string-append "\"" mtools
333 "/bin/mcopy\"")))
334 #t))))))))))
96b714f5 335
62c86c83
DGC
336(define-public grub-efi32
337 (package
338 (inherit grub-efi)
339 (name "grub-efi32")
340 (synopsis "GRand Unified Boot loader (UEFI 32bit version)")
341 (arguments
342 `(,@(substitute-keyword-arguments (package-arguments grub-efi)
343 ((#:configure-flags flags
344 ''()) `(cons* ,(cond ((target-x86?) "--target=i386")
345 ((target-arm?) "--target=arm"))
346 ,flags)))))))
347
dd4b7476
DM
348;; Because grub searches hardcoded paths it's easiest to just build grub
349;; again to make it find both grub-pc and grub-efi. There is a command
350;; line argument which allows you to specify ONE platform - but
351;; grub-mkrescue will use multiple platforms if they are available
352;; in the installation directory (without command line argument).
353(define-public grub-hybrid
354 (package
355 (inherit grub-efi)
356 (name "grub-hybrid")
357 (synopsis "GRand Unified Boot loader (hybrid version)")
358 (inputs
8394619b
LC
359 (modify-inputs (package-inputs grub-efi)
360 (prepend grub)))
dd4b7476
DM
361 (arguments
362 (substitute-keyword-arguments (package-arguments grub-efi)
363 ((#:modules modules `((guix build utils) (guix build gnu-build-system)))
364 `((ice-9 ftw) ,@modules))
365 ((#:phases phases)
366 `(modify-phases ,phases
367 (add-after 'install 'install-non-efi
368 (lambda* (#:key inputs outputs #:allow-other-keys)
d468a03a
LC
369 (let ((input-dir (search-input-directory inputs
370 "/lib/grub"))
dd4b7476
DM
371 (output-dir (string-append (assoc-ref outputs "out")
372 "/lib/grub")))
373 (for-each
374 (lambda (basename)
db34d4bb
EF
375 (if (not (or (string-prefix? "." basename)
376 (file-exists? (string-append output-dir "/" basename))))
dd4b7476
DM
377 (symlink (string-append input-dir "/" basename)
378 (string-append output-dir "/" basename))))
379 (scandir input-dir))
380 #t)))))))))
381
96b714f5
DC
382(define-public syslinux
383 (let ((commit "bb41e935cc83c6242de24d2271e067d76af3585c"))
384 (package
385 (name "syslinux")
386 (version (git-version "6.04-pre" "1" commit))
387 (source (origin
388 (method git-fetch)
389 (uri (git-reference
390 (url "https://github.com/geneC/syslinux")
391 (commit commit)))
392 (file-name (git-file-name name version))
393 (sha256
394 (base32
26cb0c39
MO
395 "0k8dvafd6410kqxf3kyr4y8jzmpmrih6wbjqg6gklak7945yflrc"))
396 (patches
397 (search-patches "syslinux-gcc10.patch"
398 "syslinux-strip-gnu-property.patch"))))
96b714f5
DC
399 (build-system gnu-build-system)
400 (native-inputs
401 `(("nasm" ,nasm)
402 ("perl" ,perl)
403 ("python-2" ,python-2)))
404 (inputs
bb93042c 405 `(("libuuid" ,util-linux "lib")
0b4dbb40 406 ("mtools" ,mtools)))
96b714f5
DC
407 (arguments
408 `(#:parallel-build? #f
409 #:make-flags
410 (list (string-append "BINDIR=" %output "/bin")
411 (string-append "SBINDIR=" %output "/sbin")
412 (string-append "LIBDIR=" %output "/lib")
413 (string-append "INCDIR=" %output "/include")
414 (string-append "DATADIR=" %output "/share")
415 (string-append "MANDIR=" %output "/share/man")
416 "PERL=perl"
417 "bios")
26cb0c39 418 #:strip-flags '("--strip-debug" "--enable-deterministic-archives")
96b714f5
DC
419 #:phases
420 (modify-phases %standard-phases
421 (add-after 'unpack 'patch-files
0b4dbb40 422 (lambda* (#:key inputs #:allow-other-keys)
96b714f5
DC
423 (substitute* (find-files "." "Makefile.*|ppmtolss16")
424 (("/bin/pwd") (which "pwd"))
425 (("/bin/echo") (which "echo"))
426 (("/usr/bin/perl") (which "perl")))
0b4dbb40
LC
427 (let ((mtools (assoc-ref inputs "mtools")))
428 (substitute* (find-files "." "\\.c$")
429 (("mcopy")
430 (string-append mtools "/bin/mcopy"))
431 (("mattrib")
432 (string-append mtools "/bin/mattrib"))))
96b714f5
DC
433 #t))
434 (delete 'configure)
435 (add-before 'build 'set-permissions
436 (lambda _
60d8db74 437 (invoke "chmod" "a+w" "utils/isohybrid.in")))
96b714f5
DC
438 (replace 'check
439 (lambda _
440 (setenv "CC" "gcc")
441 (substitute* "tests/unittest/include/unittest/unittest.h"
442 ;; Don't look up headers under /usr.
443 (("/usr/include/") ""))
60d8db74 444 (invoke "make" "unittest"))))))
0f304ba7 445 (home-page "https://www.syslinux.org")
96b714f5
DC
446 (synopsis "Lightweight Linux bootloader")
447 (description "Syslinux is a lightweight Linux bootloader.")
8d3f604d
EF
448 ;; The Makefile specifically targets i386 and x86_64 using nasm.
449 (supported-systems '("i686-linux" "x86_64-linux"))
96b714f5
DC
450 (license (list license:gpl2+
451 license:bsd-3 ; gnu-efi/*
452 license:bsd-4 ; gnu-efi/inc/* gnu-efi/lib/*
453 ;; Also contains:
454 license:expat license:isc license:zlib)))))
862e38d5
DC
455
456(define-public dtc
457 (package
458 (name "dtc")
402f544c 459 (version "1.6.1")
862e38d5
DC
460 (source (origin
461 (method url-fetch)
462 (uri (string-append
3b4efb1f 463 "mirror://kernel.org/software/utils/dtc/"
54933a40 464 "dtc-" version ".tar.gz"))
862e38d5
DC
465 (sha256
466 (base32
54933a40 467 "0xm38h31jb29xfh2sfyk48d8wdfq4b8lmb412zx9vjr35izjb9iq"))))
862e38d5
DC
468 (build-system gnu-build-system)
469 (native-inputs
0dc99fd1
EF
470 (append
471 (list bison
472 flex
473 libyaml
474 pkg-config
475 swig)
476 (if (member (%current-system) (package-supported-systems valgrind))
477 (list valgrind)
478 '())))
12c613b5 479 (inputs
8394619b 480 (list python))
862e38d5
DC
481 (arguments
482 `(#:make-flags
6cc86492 483 (list (string-append "CC=" ,(cc-for-target))
91af1031
TGR
484
485 ;; /bin/fdt{get,overlay,put} need help finding libfdt.so.1.
486 (string-append "LDFLAGS=-Wl,-rpath="
487 (assoc-ref %outputs "out") "/lib")
488
862e38d5 489 (string-append "PREFIX=" (assoc-ref %outputs "out"))
12c613b5 490 (string-append "SETUP_PREFIX=" (assoc-ref %outputs "out"))
862e38d5
DC
491 "INSTALL=install")
492 #:phases
493 (modify-phases %standard-phases
6cc86492
EF
494 (add-after 'unpack 'patch-pkg-config
495 (lambda _
496 (substitute* '("Makefile"
497 "tests/run_tests.sh")
498 (("pkg-config")
027ce789 499 ,(pkg-config-for-target)))))
d95bb295 500 (delete 'configure)))) ; no configure script
862e38d5
DC
501 (home-page "https://www.devicetree.org")
502 (synopsis "Compiles device tree source files")
503 (description "@command{dtc} compiles
504@uref{http://elinux.org/Device_Tree_Usage, device tree source files} to device
505tree binary files. These are board description files used by Linux and BSD.")
506 (license license:gpl2+)))
507
3a851d45
VC
508(define %u-boot-rockchip-inno-usb-patch
509 ;; Fix regression in 2020.10 causing freezes on boot with USB boot enabled.
510 ;; See https://gitlab.manjaro.org/manjaro-arm/packages/core/uboot-rockpro64/-/issues/4
511 ;; and https://patchwork.ozlabs.org/project/uboot/patch/20210406151059.1187379-1-icenowy@aosc.io
512 (search-patch "u-boot-rockchip-inno-usb.patch"))
513
eb46c6c5
PL
514(define %u-boot-sifive-prevent-relocating-initrd-fdt
515 ;; Fix boot in 2021.07 on Hifive unmatched, see
516 ;; https://bugs.launchpad.net/ubuntu/+source/u-boot/+bug/1937246
517 (search-patch "u-boot-sifive-prevent-reloc-initrd-fdt.patch"))
518
65be27dc
VC
519(define %u-boot-allow-disabling-openssl-patch
520 ;; Fixes build of u-boot 2021.10 without openssl
521 ;; https://lists.denx.de/pipermail/u-boot/2021-October/462728.html
522 (search-patch "u-boot-allow-disabling-openssl.patch"))
523
bf1e46e9
PL
524(define %u-boot-rk3399-enable-emmc-phy-patch
525 ;; Fix emmc boot on rockpro64 and pinebook-pro, this was a regression
526 ;; therefore should hopefully be fixed when updating u-boot.
527 ;; https://lists.denx.de/pipermail/u-boot/2021-November/466329.html
528 (search-patch "u-boot-rk3399-enable-emmc-phy.patch"))
529
862e38d5
DC
530(define u-boot
531 (package
532 (name "u-boot")
4a0d0459 533 (version "2022.04")
862e38d5 534 (source (origin
3a851d45 535 (patches
eb46c6c5 536 (list %u-boot-rockchip-inno-usb-patch
65be27dc 537 %u-boot-allow-disabling-openssl-patch
bf1e46e9
PL
538 %u-boot-sifive-prevent-relocating-initrd-fdt
539 %u-boot-rk3399-enable-emmc-phy-patch))
862e38d5
DC
540 (method url-fetch)
541 (uri (string-append
98067662 542 "https://ftp.denx.de/pub/u-boot/"
862e38d5
DC
543 "u-boot-" version ".tar.bz2"))
544 (sha256
545 (base32
4a0d0459 546 "1l5w13dznj0z1ibqv2d6ljx2ma1gnf5x5ay3dqkqwxr6750nbq38"))))
862e38d5
DC
547 (native-inputs
548 `(("bc" ,bc)
336c4a4b 549 ("bison" ,bison)
53e290df 550 ("dtc" ,dtc)
4a0d0459 551 ("gnutls" ,gnutls)
336c4a4b 552 ("flex" ,flex)
0c7707d5 553 ("lz4" ,lz4)
4a0d0459 554 ("tinfo" ,ncurses/tinfo)
634b0e28
VC
555 ("perl" ,perl)
556 ("python" ,python)
557 ("python-coverage" ,python-coverage)
eb46c6c5 558 ("python-pycryptodomex" ,python-pycryptodomex)
634b0e28 559 ("python-pytest" ,python-pytest)
4a0d0459
VC
560 ("swig" ,swig)
561 ("libuuid" ,util-linux "lib")))
862e38d5 562 (build-system gnu-build-system)
3e63a83c 563 (home-page "https://www.denx.de/wiki/U-Boot/")
862e38d5 564 (synopsis "ARM bootloader")
2ebcc538 565 (description "U-Boot is a bootloader used mostly for ARM boards. It
862e38d5
DC
566also initializes the boards (RAM etc).")
567 (license license:gpl2+)))
568
2676628f
DM
569(define-public u-boot-tools
570 (package
571 (inherit u-boot)
572 (name "u-boot-tools")
6b125371 573 (native-inputs
8394619b
LC
574 (modify-inputs (package-native-inputs u-boot)
575 (prepend sdl2)))
2676628f 576 (arguments
65212c42 577 `(#:make-flags '("HOSTCC=gcc")
e9545e6d 578 #:test-target "tcheck"
2676628f
DM
579 #:phases
580 (modify-phases %standard-phases
65212c42
DM
581 (add-after 'unpack 'patch
582 (lambda* (#:key inputs #:allow-other-keys)
583 (substitute* "Makefile"
584 (("/bin/pwd") (which "pwd"))
585 (("/bin/false") (which "false")))
586 (substitute* "tools/dtoc/fdt_util.py"
587 (("'cc'") "'gcc'"))
e1d1ec14 588 (substitute* "tools/patman/test_util.py"
e9545e6d
VC
589 ;; python3-coverage is simply called coverage in guix.
590 (("python3-coverage") "coverage"))
65212c42
DM
591 (substitute* "test/run"
592 ;; Make it easier to find test failures.
593 (("#!/bin/bash") "#!/bin/bash -x")
65212c42
DM
594 ;; This test would require git.
595 (("\\./tools/patman/patman") (which "true"))
634b0e28 596 ;; FIXME: test fails, needs further investiation
eb46c6c5
PL
597 (("run_test \"binman\"") "# run_test \"binman\"")
598 ;; FIXME: test_spl fails, needs further investiation
599 (("test_ofplatdata or test_handoff or test_spl")
600 "test_ofplatdata or test_handoff")
634b0e28 601 ;; FIXME: code coverage not working
eb46c6c5
PL
602 (("run_test \"binman code coverage\"")
603 "# run_test \"binman code coverage\"")
65212c42
DM
604 ;; This test would require internet access.
605 (("\\./tools/buildman/buildman") (which "true")))
606 (substitute* "test/py/tests/test_sandbox_exit.py"
607 (("def test_ctrl_c")
608 "@pytest.mark.skip(reason='Guix has problems with SIGINT')
609def test_ctrl_c"))
6f5be83c
VC
610 ;; Test against the tools being installed rather than tools built
611 ;; for "sandbox" target.
612 (substitute* "test/image/test-imagetools.sh"
613 (("BASEDIR=sandbox") "BASEDIR=."))
4da4e952
VC
614 (for-each (lambda (file)
615 (substitute* file
e9545e6d
VC
616 ;; Disable features that require OpenSSL due
617 ;; to GPL/Openssl license incompatibilities.
618 ;; See https://bugs.gnu.org/34717 for
619 ;; details.
620 (("CONFIG_FIT_SIGNATURE=y")
65be27dc 621 "CONFIG_FIT_SIGNATURE=n\nCONFIG_UT_LIB_ASN1=n\nCONFIG_TOOLS_LIBCRYPTO=n")
fb0aeaac
VC
622 ;; This test requires a sound system, which is un-used
623 ;; in u-boot-tools.
4da4e952 624 (("CONFIG_SOUND=y") "CONFIG_SOUND=n")))
634b0e28 625 (find-files "configs" "sandbox_.*defconfig$|tools-only_defconfig"))
65212c42 626 #t))
2676628f
DM
627 (replace 'configure
628 (lambda* (#:key make-flags #:allow-other-keys)
634b0e28 629 (apply invoke "make" "tools-only_defconfig" make-flags)))
2676628f
DM
630 (replace 'build
631 (lambda* (#:key inputs make-flags #:allow-other-keys)
9e84a4d6 632 (apply invoke "make" "tools-all" make-flags)))
2676628f
DM
633 (replace 'install
634 (lambda* (#:key outputs #:allow-other-keys)
635 (let* ((out (assoc-ref outputs "out"))
636 (bin (string-append out "/bin")))
637 (for-each (lambda (name)
638 (install-file name bin))
639 '("tools/netconsole"
640 "tools/jtagconsole"
641 "tools/gen_eth_addr"
642 "tools/gen_ethaddr_crc"
643 "tools/img2srec"
644 "tools/mkenvimage"
645 "tools/dumpimage"
646 "tools/mkimage"
06f47e02 647 "tools/kwboot"
2676628f
DM
648 "tools/proftool"
649 "tools/fdtgrep"
10186ee2
DM
650 "tools/env/fw_printenv"
651 "tools/sunxi-spl-image-builder"))
65212c42
DM
652 #t)))
653 (delete 'check)
654 (add-after 'install 'check
655 (lambda* (#:key make-flags test-target #:allow-other-keys)
6f5be83c
VC
656 (invoke "test/image/test-imagetools.sh")))
657 ;; Only run full test suite on x86_64 systems, as many tests
658 ;; assume x86_64.
659 ,@(if (string-match "^x86_64-linux"
660 (or (%current-target-system)
661 (%current-system)))
662 '((add-after 'check 'check-x86
663 (lambda* (#:key make-flags test-target #:allow-other-keys)
664 (apply invoke "make" "mrproper" make-flags)
665 (setenv "SDL_VIDEODRIVER" "dummy")
666 (setenv "PAGER" "cat")
667 (apply invoke "make" test-target make-flags))))
668 '()))))
2676628f
DM
669 (description "U-Boot is a bootloader used mostly for ARM boards. It
670also initializes the boards (RAM etc). This package provides its
671board-independent tools.")))
672
4ce4fc50 673(define-public (make-u-boot-package board triplet)
862e38d5 674 "Returns a u-boot package for BOARD cross-compiled for TRIPLET."
6bfcb729
LC
675 (let ((same-arch? (lambda ()
676 (string=? (%current-system)
677 (gnu-triplet->nix-system triplet)))))
3bfee8ff
EF
678 (package
679 (inherit u-boot)
df8a9096
DM
680 (name (string-append "u-boot-"
681 (string-replace-substring (string-downcase board)
682 "_" "-")))
3bfee8ff 683 (native-inputs
6bfcb729 684 `(,@(if (not (same-arch?))
b8806e13 685 `(("cross-gcc" ,(cross-gcc triplet))
3bfee8ff 686 ("cross-binutils" ,(cross-binutils triplet)))
b8806e13 687 `())
3bfee8ff
EF
688 ,@(package-native-inputs u-boot)))
689 (arguments
37297674
EF
690 `(#:modules ((ice-9 ftw)
691 (srfi srfi-1)
692 (guix build utils)
693 (guix build gnu-build-system))
3bfee8ff
EF
694 #:test-target "test"
695 #:make-flags
696 (list "HOSTCC=gcc"
6bfcb729 697 ,@(if (not (same-arch?))
3bfee8ff
EF
698 `((string-append "CROSS_COMPILE=" ,triplet "-"))
699 '()))
700 #:phases
701 (modify-phases %standard-phases
702 (replace 'configure
703 (lambda* (#:key outputs make-flags #:allow-other-keys)
704 (let ((config-name (string-append ,board "_defconfig")))
705 (if (file-exists? (string-append "configs/" config-name))
8f43bdd9 706 (apply invoke "make" `(,@make-flags ,config-name))
3bfee8ff 707 (begin
ac30d18c
DM
708 (display "Invalid board name. Valid board names are:"
709 (current-error-port))
30ef146c
DM
710 (let ((suffix-len (string-length "_defconfig"))
711 (entries (scandir "configs")))
712 (for-each (lambda (file-name)
713 (when (string-suffix? "_defconfig" file-name)
ac30d18c 714 (format (current-error-port)
30ef146c
DM
715 "- ~A\n"
716 (string-drop-right file-name
717 suffix-len))))
ee3c8fbe 718 (sort entries string-ci<)))
bdd235b3 719 (error "Invalid boardname ~s." ,board))))))
65be27dc
VC
720 (add-after 'configure 'disable-tools-libcrypto
721 ;; Disable libcrypto due to GPL and OpenSSL license
722 ;; incompatibilities
723 (lambda _
724 (substitute* ".config"
725 (("CONFIG_TOOLS_LIBCRYPTO=.*$") "CONFIG_TOOLS_LIBCRYPTO=n"))))
3bfee8ff 726 (replace 'install
9b94ced4 727 (lambda* (#:key outputs #:allow-other-keys)
3bfee8ff
EF
728 (let* ((out (assoc-ref outputs "out"))
729 (libexec (string-append out "/libexec"))
dd208b93 730 (uboot-files (append
a9446dde
DM
731 (remove
732 ;; Those would not be reproducible
733 ;; because of the randomness used
734 ;; to produce them.
735 ;; It's expected that the user will
736 ;; use u-boot-tools to generate them
737 ;; instead.
738 (lambda (name)
739 (string-suffix?
740 "sunxi-spl-with-ecc.bin"
741 name))
742 (find-files "." ".*\\.(bin|efi|img|spl|itb|dtb|rksd)$"))
fd0b21d5 743 (find-files "." "^(MLO|SPL)$"))))
3bfee8ff 744 (mkdir-p libexec)
a32f9b59 745 (install-file ".config" libexec)
0fcfed39
DM
746 ;; Useful for "qemu -kernel".
747 (install-file "u-boot" libexec)
3bfee8ff
EF
748 (for-each
749 (lambda (file)
750 (let ((target-file (string-append libexec "/" file)))
751 (mkdir-p (dirname target-file))
752 (copy-file file target-file)))
d1af9a8c
DM
753 uboot-files)
754 #t)))))))))
862e38d5 755
862e38d5
DC
756(define-public u-boot-malta
757 (make-u-boot-package "malta" "mips64el-linux-gnuabi64"))
758
6b99afee
VC
759(define-public u-boot-am335x-boneblack
760 (let ((base (make-u-boot-package "am335x_evm" "arm-linux-gnueabihf")))
761 (package
762 (inherit base)
763 (name "u-boot-am335x-boneblack")
2ebcc538 764 (description "U-Boot is a bootloader used mostly for ARM boards. It
6b99afee
VC
765also initializes the boards (RAM etc).
766
767This U-Boot is built for the BeagleBone Black, which was removed upstream,
768adjusted from the am335x_evm build with several device trees removed so that
769it fits within common partitioning schemes.")
770 (arguments
771 (substitute-keyword-arguments (package-arguments base)
772 ((#:phases phases)
773 `(modify-phases ,phases
774 (add-after 'unpack 'patch-defconfig
775 ;; Patch out other devicetrees to build image small enough to
776 ;; fit within typical partitioning schemes where the first
777 ;; partition begins at sector 2048.
778 (lambda _
779 (substitute* "configs/am335x_evm_defconfig"
780 (("CONFIG_OF_LIST=.*$") "CONFIG_OF_LIST=\"am335x-evm am335x-boneblack\"\n"))
781 #t)))))))))
782
783(define-public u-boot-am335x-evm
784 (make-u-boot-package "am335x_evm" "arm-linux-gnueabihf"))
4adeb3f6 785
0da3526d
VC
786(define-public (make-u-boot-sunxi64-package board triplet)
787 (let ((base (make-u-boot-package board triplet)))
29be6cfb
EF
788 (package
789 (inherit base)
790 (arguments
791 (substitute-keyword-arguments (package-arguments base)
792 ((#:phases phases)
793 `(modify-phases ,phases
794 (add-after 'unpack 'set-environment
db78fc06
MO
795 (lambda* (#:key native-inputs inputs #:allow-other-keys)
796 (let ((bl31
797 (string-append
798 (assoc-ref (or native-inputs inputs) "firmware")
799 "/bl31.bin")))
29be6cfb 800 (setenv "BL31" bl31)
35e427d1
DM
801 ;; This is necessary when we're using the bundled dtc.
802 ;(setenv "PATH" (string-append (getenv "PATH") ":"
803 ; "scripts/dtc"))
804 )
29be6cfb
EF
805 #t))))))
806 (native-inputs
95d91986 807 `(("firmware" ,arm-trusted-firmware-sun50i-a64)
29be6cfb
EF
808 ,@(package-native-inputs base))))))
809
0da3526d
VC
810(define-public u-boot-pine64-plus
811 (make-u-boot-sunxi64-package "pine64_plus" "aarch64-linux-gnu"))
812
af58b275
MO
813(define-public u-boot-pine64-lts
814 (make-u-boot-sunxi64-package "pine64-lts" "aarch64-linux-gnu"))
815
74e35e8c 816(define-public u-boot-pinebook
760dfc67
VC
817 (let ((base (make-u-boot-sunxi64-package "pinebook" "aarch64-linux-gnu")))
818 (package
819 (inherit base)
820 (arguments
821 (substitute-keyword-arguments (package-arguments base)
822 ((#:phases phases)
823 `(modify-phases ,phases
824 (add-after 'unpack 'patch-pinebook-config
825 ;; Fix regression with LCD video output introduced in 2020.01
826 ;; https://patchwork.ozlabs.org/patch/1225130/
827 (lambda _
828 (substitute* "configs/pinebook_defconfig"
829 (("CONFIG_VIDEO_BRIDGE_ANALOGIX_ANX6345=y") "CONFIG_VIDEO_BRIDGE_ANALOGIX_ANX6345=y\nCONFIG_VIDEO_BPP32=y"))
830 #t)))))))))
74e35e8c 831
e830c9d0 832(define-public u-boot-bananapi-m2-ultra
30aeb846
DM
833 (make-u-boot-package "Bananapi_M2_Ultra" "arm-linux-gnueabihf"))
834
c55c6985
DM
835(define-public u-boot-a20-olinuxino-lime
836 (make-u-boot-package "A20-OLinuXino-Lime" "arm-linux-gnueabihf"))
837
4b9e9abb
DM
838(define-public u-boot-a20-olinuxino-lime2
839 (make-u-boot-package "A20-OLinuXino-Lime2" "arm-linux-gnueabihf"))
840
a7bb327e
DM
841(define-public u-boot-a20-olinuxino-micro
842 (make-u-boot-package "A20-OLinuXino_MICRO" "arm-linux-gnueabihf"))
843
84ee3378 844(define-public u-boot-nintendo-nes-classic-edition
dd7df191
DM
845 (let ((base (make-u-boot-package "Nintendo_NES_Classic_Edition"
846 "arm-linux-gnueabihf")))
847 (package
848 (inherit base)
849 ;; Starting with 2019.01, FEL doesn't work anymore on A33.
850 (version "2018.11")
851 (source (origin
852 (method url-fetch)
853 (uri (string-append
854 "https://ftp.denx.de/pub/u-boot/"
855 "u-boot-" version ".tar.bz2"))
856 (sha256
857 (base32
858 "0znkwljfwwn4y7j20pzz4ilqw8znphrfxns0x1lwdzh3xbr96z3k"))
859 (patches (search-patches
860 "u-boot-nintendo-nes-serial.patch"))))
861 (description "U-Boot is a bootloader used mostly for ARM boards. It
862also initializes the boards (RAM etc).
863
864This version is for the Nintendo NES Classic Edition. It is assumed that
865you have added a serial port to pins PB0 and PB1 as described on
866@url{https://linux-sunxi.org/Nintendo_NES_Classic_Edition}.
867
868In order to use FEL mode on the device, hold the Reset button on the
869device while it's being turned on (and a while longer).")
870 (native-inputs
871 `(("python" ,python-2)
872 ,@(package-native-inputs base))))))
84ee3378 873
95a3422e
VC
874(define-public u-boot-wandboard
875 (make-u-boot-package "wandboard" "arm-linux-gnueabihf"))
876
adc61d72
VC
877(define-public u-boot-mx6cuboxi
878 (make-u-boot-package "mx6cuboxi" "arm-linux-gnueabihf"))
879
1b960787 880(define-public u-boot-novena
6e2bad00
VC
881 (let ((base (make-u-boot-package "novena" "arm-linux-gnueabihf")))
882 (package
883 (inherit base)
2ebcc538 884 (description "U-Boot is a bootloader used mostly for ARM boards. It
6e2bad00
VC
885also initializes the boards (RAM etc).
886
887This U-Boot is built for Novena. Be advised that this version, contrary
6b99afee 888to Novena upstream, does not load u-boot.img from the first partition.")
6e2bad00
VC
889 (arguments
890 (substitute-keyword-arguments (package-arguments base)
891 ((#:phases phases)
892 `(modify-phases ,phases
893 (add-after 'unpack 'patch-novena-defconfig
894 ;; Patch configuration to disable loading u-boot.img from FAT partition,
895 ;; allowing it to be installed at a device offset.
896 (lambda _
897 (substitute* "configs/novena_defconfig"
6b99afee 898 (("CONFIG_SPL_FS_FAT=y") "# CONFIG_SPL_FS_FAT is not set"))
6e2bad00 899 #t)))))))))
1b960787 900
dd4fe0c2
DM
901(define-public u-boot-cubieboard
902 (make-u-boot-package "Cubieboard" "arm-linux-gnueabihf"))
903
a7d5ce94
JL
904(define-public u-boot-cubietruck
905 (make-u-boot-package "Cubietruck" "arm-linux-gnueabihf"))
906
6fe16577
VC
907(define-public u-boot-puma-rk3399
908 (let ((base (make-u-boot-package "puma-rk3399" "aarch64-linux-gnu")))
909 (package
910 (inherit base)
911 (arguments
15990546
VC
912 (substitute-keyword-arguments (package-arguments base)
913 ((#:phases phases)
914 `(modify-phases ,phases
915 (add-after 'unpack 'set-environment
916 (lambda* (#:key inputs #:allow-other-keys)
d468a03a
LC
917 (setenv "BL31"
918 (search-input-file inputs "/bl31.elf"))))
15990546
VC
919 ;; Phases do not succeed on the bl31 ELF.
920 (delete 'strip)
921 (delete 'validate-runpath)))))
6fe16577 922 (native-inputs
15990546 923 `(("firmware" ,arm-trusted-firmware-rk3399)
6fe16577
VC
924 ,@(package-native-inputs base))))))
925
10f31af9
VC
926(define-public u-boot-qemu-riscv64
927 (make-u-boot-package "qemu-riscv64" "riscv64-linux-gnu"))
928
7e954f67 929(define-public u-boot-qemu-riscv64-smode
4a0d0459 930 (make-u-boot-package "qemu-riscv64_smode" "riscv64-linux-gnu"))
7e954f67 931
e914fc59
PL
932(define-public u-boot-sifive-unleashed
933 (make-u-boot-package "sifive_unleashed" "riscv64-linux-gnu"))
7d063645 934
df3a60d1 935(define-public u-boot-sifive-unmatched
1acd0bf8
EF
936 (let ((base (make-u-boot-package "sifive_unmatched" "riscv64-linux-gnu")))
937 (package
938 (inherit base)
939 (arguments
940 (substitute-keyword-arguments (package-arguments base)
941 ((#:phases phases)
942 `(modify-phases ,phases
943 (add-after 'unpack 'set-environment
944 (lambda* (#:key inputs #:allow-other-keys)
945 (let ((opensbi (string-append (assoc-ref inputs "firmware")
946 "/fw_dynamic.bin")))
947 (setenv "OPENSBI" opensbi))))))))
948 (inputs
949 `(("firmware" ,opensbi-generic)
950 ,@(package-inputs base))))))
df3a60d1 951
2fce14af
VC
952(define-public u-boot-rock64-rk3328
953 (let ((base (make-u-boot-package "rock64-rk3328" "aarch64-linux-gnu")))
954 (package
955 (inherit base)
2fce14af
VC
956 (arguments
957 (substitute-keyword-arguments (package-arguments base)
958 ((#:phases phases)
959 `(modify-phases ,phases
960 (add-after 'unpack 'set-environment
961 (lambda* (#:key inputs #:allow-other-keys)
d468a03a
LC
962 (let ((bl31 (search-input-file inputs "/bl31.elf")))
963 (setenv "BL31" bl31))))))))
2fce14af
VC
964 (native-inputs
965 `(("firmware" ,arm-trusted-firmware-rk3328)
966 ,@(package-native-inputs base))))))
967
545ff7b7
VC
968(define-public u-boot-firefly-rk3399
969 (let ((base (make-u-boot-package "firefly-rk3399" "aarch64-linux-gnu")))
970 (package
971 (inherit base)
545ff7b7
VC
972 (arguments
973 (substitute-keyword-arguments (package-arguments base)
974 ((#:phases phases)
975 `(modify-phases ,phases
7d440cdb 976 (add-after 'unpack 'set-environment
545ff7b7 977 (lambda* (#:key inputs #:allow-other-keys)
d468a03a 978 (setenv "BL31" (search-input-file inputs "/bl31.elf"))))
545ff7b7
VC
979 ;; Phases do not succeed on the bl31 ELF.
980 (delete 'strip)
981 (delete 'validate-runpath)))))
982 (native-inputs
983 `(("firmware" ,arm-trusted-firmware-rk3399)
984 ,@(package-native-inputs base))))))
985
fa747018
CN
986(define-public u-boot-rockpro64-rk3399
987 (let ((base (make-u-boot-package "rockpro64-rk3399" "aarch64-linux-gnu")))
988 (package
989 (inherit base)
5327b399
VC
990 (arguments
991 (substitute-keyword-arguments (package-arguments base)
992 ((#:phases phases)
993 `(modify-phases ,phases
adb84ae8 994 (add-after 'unpack 'set-environment
5327b399 995 (lambda* (#:key inputs #:allow-other-keys)
d468a03a
LC
996 (setenv "BL31"
997 (search-input-file inputs "/bl31.elf"))))
d643ef38
RW
998 (add-after 'unpack 'patch-config
999 (lambda _
1000 (substitute* "configs/rockpro64-rk3399_defconfig"
1001 (("CONFIG_USB=y") "\
1002CONFIG_USB=y
1003CONFIG_AHCI=y
1004CONFIG_AHCI_PCI=y
1005CONFIG_SATA=y
1006CONFIG_SATA_SIL=y
1007CONFIG_SCSI=y
1008CONFIG_SCSI_AHCI=y
1009CONFIG_DM_SCSI=y
1010"))
1011 (substitute* "include/config_distro_bootcmd.h"
1012 (("\"scsi_need_init=false")
1013 "\"setenv scsi_need_init false")
1014 (("#define BOOTENV_SET_SCSI_NEED_INIT \"scsi_need_init=;")
1015 "#define BOOTENV_SET_SCSI_NEED_INIT \"setenv scsi_need_init;"))
1016 (substitute* "include/configs/rockchip-common.h"
1017 (("#define BOOT_TARGET_DEVICES\\(func\\)")
1018 "
1019#if CONFIG_IS_ENABLED(CMD_SCSI)
1020 #define BOOT_TARGET_SCSI(func) func(SCSI, scsi, 0)
1021#else
1022 #define BOOT_TARGET_SCSI(func)
1023#endif
1024#define BOOT_TARGET_DEVICES(func)")
1025 (("BOOT_TARGET_NVME\\(func\\) \\\\")
1026 "\
1027BOOT_TARGET_NVME(func) \\
1028 BOOT_TARGET_SCSI(func) \\"))))
5327b399
VC
1029 ;; Phases do not succeed on the bl31 ELF.
1030 (delete 'strip)
1031 (delete 'validate-runpath)))))
1032 (native-inputs
1033 `(("firmware" ,arm-trusted-firmware-rk3399)
1034 ,@(package-native-inputs base))))))
1035
1036(define-public u-boot-pinebook-pro-rk3399
1037 (let ((base (make-u-boot-package "pinebook-pro-rk3399" "aarch64-linux-gnu")))
1038 (package
eb46c6c5 1039 (inherit base)
fa747018
CN
1040 (arguments
1041 (substitute-keyword-arguments (package-arguments base)
1042 ((#:phases phases)
1043 `(modify-phases ,phases
1044 (add-after 'unpack 'set-environment
1045 (lambda* (#:key inputs #:allow-other-keys)
d468a03a
LC
1046 (setenv "BL31"
1047 (search-input-file inputs "/bl31.elf"))))
fa747018
CN
1048 ;; Phases do not succeed on the bl31 ELF.
1049 (delete 'strip)
1050 (delete 'validate-runpath)))))
1051 (native-inputs
1052 `(("firmware" ,arm-trusted-firmware-rk3399)
1053 ,@(package-native-inputs base))))))
1054
a60f1319
MB
1055(define-public vboot-utils
1056 (package
1057 (name "vboot-utils")
1058 (version "R63-10032.B")
1059 (source (origin
1060 ;; XXX: Snapshots are available but changes timestamps every download.
1061 (method git-fetch)
1062 (uri (git-reference
1063 (url (string-append "https://chromium.googlesource.com"
1064 "/chromiumos/platform/vboot_reference"))
1065 (commit (string-append "release-" version))))
1066 (file-name (string-append name "-" version "-checkout"))
1067 (sha256
1068 (base32
b634b5c2
KK
1069 "0h0m3l69vp9dr6xrs1p6y7ilkq3jq8jraw2z20kqfv7lvc9l1lxj"))
1070 (patches
1071 (search-patches "vboot-utils-skip-test-workbuf.patch"
1072 "vboot-utils-fix-tests-show-contents.patch"
1073 "vboot-utils-fix-format-load-address.patch"))))
a60f1319
MB
1074 (build-system gnu-build-system)
1075 (arguments
1076 `(#:make-flags (list "CC=gcc"
b634b5c2
KK
1077 ;; On ARM, we must pass "HOST_ARCH=arm" so that the
1078 ;; ${HOST_ARCH} and ${ARCH} variables in the makefile
1079 ;; match. Otherwise, ${HOST_ARCH} will be assigned
1080 ;; "armv7l", the value of `uname -m`, and will not
1081 ;; match ${ARCH}, which will make the tests require
1082 ;; QEMU for testing.
1083 ,@(if (string-prefix? "arm"
1084 (or (%current-target-system)
1085 (%current-system)))
1086 '("HOST_ARCH=arm")
1087 '())
a60f1319
MB
1088 (string-append "DESTDIR=" (assoc-ref %outputs "out")))
1089 #:phases (modify-phases %standard-phases
1090 (add-after 'unpack 'patch-hard-coded-paths
1091 (lambda* (#:key inputs outputs #:allow-other-keys)
1092 (let ((coreutils (assoc-ref inputs "coreutils"))
1093 (diffutils (assoc-ref inputs "diffutils")))
1094 (substitute* "futility/misc.c"
1095 (("/bin/cp") (string-append coreutils "/bin/cp")))
1096 (substitute* "tests/bitmaps/TestBmpBlock.py"
1097 (("/usr/bin/cmp") (string-append diffutils "/bin/cmp")))
1098 (substitute* "vboot_host.pc.in"
1099 (("prefix=/usr")
1100 (string-append "prefix=" (assoc-ref outputs "out"))))
1101 #t)))
1102 (delete 'configure)
1103 (add-before 'check 'patch-tests
1104 (lambda _
1105 ;; These tests compare diffs against known-good values.
1106 ;; Patch the paths to match those in the build container.
1107 (substitute* (find-files "tests/futility/expect_output")
1108 (("/mnt/host/source/src/platform/vboot_reference")
1109 (string-append "/tmp/guix-build-" ,name "-" ,version
1110 ".drv-0/source")))
1111 ;; Tests require write permissions to many of these files.
1112 (for-each make-file-writable (find-files "tests/futility"))
71f2b4b8
KK
1113 #t))
1114 (add-after 'install 'install-devkeys
1115 (lambda* (#:key outputs #:allow-other-keys)
1116 (let* ((out (assoc-ref outputs "out"))
1117 (share (string-append out "/share/vboot-utils")))
1118 (copy-recursively "tests/devkeys"
1119 (string-append share "/devkeys"))
1120 #t))))
a60f1319
MB
1121 #:test-target "runtests"))
1122 (native-inputs
1123 `(("pkg-config" ,pkg-config)
1124
1125 ;; For tests.
1126 ("diffutils" ,diffutils)
1127 ("python@2" ,python-2)))
1128 (inputs
1129 `(("coreutils" ,coreutils)
1130 ("libyaml" ,libyaml)
1131 ("openssl" ,openssl)
1132 ("openssl:static" ,openssl "static")
bb93042c 1133 ("util-linux" ,util-linux "lib")))
a60f1319
MB
1134 (home-page
1135 "https://dev.chromium.org/chromium-os/chromiumos-design-docs/verified-boot")
1136 (synopsis "ChromiumOS verified boot utilities")
1137 (description
1138 "vboot-utils is a collection of tools to facilitate booting of
1139Chrome-branded devices. This includes the @command{cgpt} partitioning
1140program, the @command{futility} and @command{crossystem} firmware management
1141tools, and more.")
1142 (license license:bsd-3)))
1143
aa90375a
AI
1144(define-public os-prober
1145 (package
1146 (name "os-prober")
3666e5e4 1147 (version "1.80")
aa90375a
AI
1148 (source
1149 (origin
1150 (method url-fetch)
1151 (uri (string-append "mirror://debian/pool/main/o/os-prober/os-prober_"
1152 version ".tar.xz"))
1153 (sha256
3666e5e4 1154 (base32 "13z3rshgz5xj0328a80wavdimjw925yha9s1ks398sq0kn5w6qw0"))))
aa90375a
AI
1155 (build-system gnu-build-system)
1156 (arguments
1157 `(#:modules ((guix build gnu-build-system)
1158 (guix build utils)
e9bdef5f
TGR
1159 (ice-9 regex) ; for string-match
1160 (srfi srfi-26)) ; for cut
33430a45
TGR
1161 #:make-flags
1162 (list ,(string-append "CC=" (cc-for-target)))
e9bdef5f 1163 #:tests? #f ; no tests
aa90375a
AI
1164 #:phases
1165 (modify-phases %standard-phases
1166 (replace 'configure
1167 (lambda* (#:key outputs #:allow-other-keys)
1168 (substitute* (find-files ".")
1169 (("/usr") (assoc-ref outputs "out")))
1170 (substitute* (find-files "." "50mounted-tests$")
3666e5e4 1171 (("mkdir") "mkdir -p"))))
aa90375a
AI
1172 (replace 'install
1173 (lambda* (#:key outputs #:allow-other-keys)
1174 (define (find-files-non-recursive directory)
1175 (find-files directory
1176 (lambda (file stat)
1177 (string-match (string-append "^" directory "/[^/]*$")
1178 file))
1179 #:directories? #t))
1180
1181 (let* ((out (assoc-ref outputs "out"))
1182 (bin (string-append out "/bin"))
1183 (lib (string-append out "/lib"))
1184 (share (string-append out "/share")))
1185 (for-each (cut install-file <> bin)
1186 (list "linux-boot-prober" "os-prober"))
1187 (install-file "newns" (string-append lib "/os-prober"))
1188 (install-file "common.sh" (string-append share "/os-prober"))
1189 (install-file "os-probes/mounted/powerpc/20macosx"
1190 (string-append lib "/os-probes/mounted"))
1191 (for-each
1192 (lambda (directory)
1193 (for-each
1194 (lambda (file)
1195 (let ((destination (string-append lib "/" directory
1196 "/" (basename file))))
1197 (mkdir-p (dirname destination))
1198 (copy-recursively file destination)))
1199 (append (find-files-non-recursive (string-append directory "/common"))
1200 (find-files-non-recursive (string-append directory "/x86")))))
1201 (list "os-probes" "os-probes/mounted" "os-probes/init"
3666e5e4 1202 "linux-boot-probes" "linux-boot-probes/mounted"))))))))
aa90375a
AI
1203 (home-page "https://joeyh.name/code/os-prober")
1204 (synopsis "Detect other operating systems")
1205 (description "os-prober probes disks on the system for other operating
1206systems so that they can be added to the bootloader. It also works out how to
1207boot existing GNU/Linux systems and detects what distribution is installed in
1208order to add a suitable bootloader menu entry.")
1209 (license license:gpl2+)))
aeed7218
VL
1210
1211(define-public ipxe
1212 ;; XXX: 'BUILD_TIMESTAMP' is used to automatically select the newest version
1213 ;; of iPXE if multiple iPXE drivers are loaded concurrently in a UEFI system.
1214 ;;
1215 ;; TODO: Bump this timestamp at each modifications of the package (not only
1216 ;; for updates) by running: date +%s.
1217 (let ((timestamp "1591706427"))
1218 (package
1219 (name "ipxe")
ca34b6f0 1220 (version "1.21.1")
aeed7218
VL
1221 (source (origin
1222 (method git-fetch)
1223 (uri (git-reference
1224 (url "https://github.com/ipxe/ipxe")
1225 (commit (string-append "v" version))))
1226 (file-name (git-file-name name version))
1227 (patches (search-patches "ipxe-reproducible-geniso.patch"))
1228 (sha256
1229 (base32
ca34b6f0 1230 "1pkf1n1c0rdlzfls8fvjvi1sd9xjd9ijqlyz3wigr70ijcv6x8i9"))))
aeed7218
VL
1231 (build-system gnu-build-system)
1232 (arguments
1233 `(#:modules ((guix build utils)
1234 (guix build gnu-build-system)
1235 (guix base32)
1236 (ice-9 string-fun)
1237 (ice-9 regex)
1238 (rnrs bytevectors))
1239 #:imported-modules ((guix base32)
1240 ,@%gnu-build-system-modules)
1241 #:make-flags
1242 ;; XXX: 'BUILD_ID' is used to determine when another ROM in the
1243 ;; system contains identical code in order to save space within the
1244 ;; legacy BIOS option ROM area, which is extremely limited in size.
1245 ;; It is supposed to be collision-free across all ROMs, to do so we
1246 ;; use the truncated output hash of the package.
1247 (let ((build-id
1248 (lambda (out)
1249 (let* ((nix-store (string-append
1250 (or (getenv "NIX_STORE") "/gnu/store")
1251 "/"))
1252 (filename
1253 (string-replace-substring out nix-store ""))
1254 (hash (match:substring (string-match "[0-9a-z]{32}"
1255 filename)))
1256 (bv (nix-base32-string->bytevector hash)))
1257 (format #f "0x~x"
1258 (bytevector-u32-ref bv 0 (endianness big))))))
1259 (out (assoc-ref %outputs "out"))
1260 (syslinux (assoc-ref %build-inputs "syslinux")))
1261 (list "ECHO_E_BIN_ECHO=echo"
1262 "ECHO_E_BIN_ECHO_E=echo -e"
1263
1264 ;; cdrtools' mkisofs will silently ignore a missing isolinux.bin!
1265 ;; Luckily xorriso is more strict.
1266 (string-append "ISOLINUX_BIN=" syslinux
1267 "/share/syslinux/isolinux.bin")
1268 (string-append "SYSLINUX_MBR_DISK_PATH=" syslinux
1269 "/share/syslinux/isohdpfx.bin")
1270
1271 ;; Build reproducibly.
1272 (string-append "BUILD_ID_CMD=echo -n " (build-id out))
1273 (string-append "BUILD_TIMESTAMP=" ,timestamp)
1274 "everything"))
1275 #:phases
1276 (modify-phases %standard-phases
1277 (add-after 'unpack 'enter-source-directory
1278 (lambda _ (chdir "src") #t))
1279 (add-after 'enter-source-directory 'set-options
1280 (lambda _
1281 (substitute* "config/general.h"
1282 (("^//(#define PING_CMD.*)" _ uncommented) uncommented)
1283 (("^//(#define IMAGE_TRUST_CMD.*)" _ uncommented)
1284 uncommented)
1285 (("^#undef.*(DOWNLOAD_PROTO_HTTPS.*)" _ option)
1286 (string-append "#define " option))
1287 (("^#undef.*(DOWNLOAD_PROTO_NFS.*)" _ option)
1288 (string-append "#define " option)))
1289 #t))
1290 (delete 'configure) ; no configure script
1291 (replace 'install
1292 (lambda* (#:key outputs #:allow-other-keys)
1293 (let* ((out (assoc-ref outputs "out"))
1294 (ipxe (string-append out "/lib/ipxe"))
1295 (exts-re
1296 "\\.(efi|efirom|iso|kkpxe|kpxe|lkrn|mrom|pxe|rom|usb)$")
1297 (dirs '("bin" "bin-i386-linux" "bin-x86_64-pcbios"
1298 "bin-x86_64-efi" "bin-x86_64-linux" "bin-i386-efi"))
1299 (files (apply append
1300 (map (lambda (dir)
1301 (find-files dir exts-re)) dirs))))
1302 (for-each (lambda (file)
1303 (let* ((subdir (dirname file))
1304 (fn (basename file))
1305 (tgtsubdir (cond
1306 ((string=? "bin" subdir) "")
1307 ((string-prefix? "bin-" subdir)
1308 (string-drop subdir 4)))))
1309 (install-file file
1310 (string-append ipxe "/" tgtsubdir))))
1311 files))
1312 #t))
1313 (add-after 'install 'leave-source-directory
1314 (lambda _ (chdir "..") #t)))
1315 #:tests? #f)) ; no test suite
1316 (native-inputs
8394619b 1317 (list perl syslinux xorriso))
aeed7218
VL
1318 (home-page "https://ipxe.org")
1319 (synopsis "PXE-compliant network boot firmware")
1320 (description "iPXE is a network boot firmware. It provides a full PXE
1321implementation enhanced with additional features such as booting from: a web
1322server via HTTP, an iSCSI SAN, a Fibre Channel SAN via FCoE, an AoE SAN, a
084d3cac
VC
1323wireless network, a wide-area network, an Infiniband network. It
1324controls the boot process with a script. You can use iPXE to replace the
aeed7218
VL
1325existing PXE ROM on your network card, or you can chainload into iPXE to obtain
1326the features of iPXE without the hassle of reflashing.")
1327 (license license:gpl2+))))
1328