1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2013, 2014, 2015, 2016, 2017 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2015, 2018 Mark H Weaver <mhw@netris.org>
4 ;;; Copyright © 2015 Leo Famulari <leo@famulari.name>
5 ;;; Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;; Copyright © 2016, 2017, 2018 Marius Bakke <mbakke@fastmail.com>
7 ;;; Copyright © 2016, 2017 Danny Milosavljevic <dannym@scratchpost.org>
8 ;;; Copyright © 2016, 2017 David Craven <david@craven.ch>
9 ;;; Copyright © 2017, 2018 Efraim Flashner <efraim@flashner.co.il>
10 ;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
12 ;;; This file is part of GNU Guix.
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.
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.
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/>.
27 (define-module (gnu packages bootloaders)
28 #:use-module (gnu packages)
29 #:use-module (gnu packages admin)
30 #:use-module ((gnu packages algebra) #:select (bc))
31 #:use-module (gnu packages assembly)
32 #:use-module (gnu packages base)
33 #:use-module (gnu packages disk)
34 #:use-module (gnu packages bison)
35 #:use-module (gnu packages cdrom)
36 #:use-module (gnu packages cross-base)
37 #:use-module (gnu packages disk)
38 #:use-module (gnu packages firmware)
39 #:use-module (gnu packages flex)
40 #:use-module (gnu packages fontutils)
41 #:use-module (gnu packages gcc)
42 #:use-module (gnu packages gettext)
43 #:use-module (gnu packages linux)
44 #:use-module (gnu packages man)
45 #:use-module (gnu packages mtools)
46 #:use-module (gnu packages ncurses)
47 #:use-module (gnu packages perl)
48 #:use-module (gnu packages pkg-config)
49 #:use-module (gnu packages python)
50 #:use-module (gnu packages texinfo)
51 #:use-module (gnu packages tls)
52 #:use-module (gnu packages swig)
53 #:use-module (gnu packages virtualization)
54 #:use-module (gnu packages web)
55 #:use-module (guix build-system gnu)
56 #:use-module (guix download)
57 #:use-module (guix git-download)
58 #:use-module ((guix licenses) #:prefix license:)
59 #:use-module (guix packages)
60 #:use-module (guix utils)
61 #:use-module (srfi srfi-1)
62 #:use-module (srfi srfi-26))
65 ;; GNU Unifont, <http://gnu.org/s/unifont>.
66 ;; GRUB needs it for its graphical terminal, gfxterm.
70 "http://unifoundry.com/pub/unifont-7.0.06/font-builds/unifont-7.0.06.bdf.gz")
73 "0p2vhnc18cnbmb39vq4m7hzv4mhnm2l0a2s7gx3ar277fwng3hys"))))
75 ;; The GRUB test suite fails with later versions of Qemu, so we
76 ;; keep it at 2.10 for now. See
77 ;; <https://lists.gnu.org/archive/html/bug-grub/2018-02/msg00004.html>.
78 ;; TODO: When grub no longer needs this version, move to gnu/packages/debug.scm.
79 (define qemu-minimal-2.10
81 (inherit qemu-minimal)
85 (uri (string-append "https://download.qemu.org/qemu-"
89 "17w21spvaxaidi2am5lpsln8yjpyp2zi3s3gc6nsxj5arlgamzgw"))))))
97 (uri (string-append "mirror://gnu/grub/grub-" version ".tar.xz"))
100 "03vvdfhdmf16121v7xs8is2krwnv15wpkhkf16a4yf8nsfc3f2w1"))))
101 (build-system gnu-build-system)
103 `(#:phases (modify-phases %standard-phases
104 (add-after 'unpack 'patch-stuff
105 (lambda* (#:key inputs #:allow-other-keys)
106 (substitute* "grub-core/Makefile.in"
107 (("/bin/sh") (which "sh")))
109 ;; Give the absolute file name of 'mdadm', used to
110 ;; determine the root file system when it's a RAID
111 ;; device. Failing to do that, 'grub-probe' silently
112 ;; fails if 'mdadm' is not in $PATH.
113 (substitute* "grub-core/osdep/linux/getroot.c"
114 (("argv\\[0\\] = \"mdadm\"")
115 (string-append "argv[0] = \""
116 (assoc-ref inputs "mdadm")
119 ;; Make the font visible.
120 (copy-file (assoc-ref inputs "unifont") "unifont.bdf.gz")
121 (system* "gunzip" "unifont.bdf.gz")
123 (add-before 'check 'disable-flaky-test
125 ;; This test is unreliable. For more information, see:
126 ;; <https://bugs.gnu.org/26936>.
127 (substitute* "Makefile.in"
128 (("grub_cmd_date grub_cmd_set_date grub_cmd_sleep")
129 "grub_cmd_date grub_cmd_sleep"))
131 ;; Disable tests on ARM and AARCH64 platforms.
132 #:tests? ,(not (any (cute string-prefix? <> (or (%current-target-system)
134 '("arm" "aarch64")))))
136 `(("gettext" ,gettext-minimal)
138 ;; Depend on LVM2 for libdevmapper, used by 'grub-probe' and
139 ;; 'grub-install' to recognize mapped devices (LUKS, etc.)
142 ;; Depend on mdadm, which is invoked by 'grub-probe' and 'grub-install'
143 ;; to determine whether the root file system is RAID.
146 ("freetype" ,freetype)
147 ;; ("libusb" ,libusb)
149 ("ncurses" ,ncurses)))
151 `(("pkg-config" ,pkg-config)
154 ;; Due to a bug in flex >= 2.6.2, GRUB must be built with an older flex:
155 ;; <http://lists.gnu.org/archive/html/grub-devel/2017-02/msg00133.html>
156 ;; TODO Try building with flex > 2.6.4.
159 ("help2man" ,help2man)
161 ;; Dependencies for the test suite. The "real" QEMU is needed here,
162 ;; because several targets are used.
164 ("qemu" ,qemu-minimal-2.10)
165 ("xorriso" ,xorriso)))
166 (home-page "https://www.gnu.org/software/grub/")
167 (synopsis "GRand Unified Boot loader")
169 "GRUB is a multiboot bootloader. It is used for initially loading the
170 kernel of an operating system and then transferring control to it. The kernel
171 then goes on to load the rest of the operating system. As a multiboot
172 bootloader, GRUB handles the presence of multiple operating systems installed
173 on the same computer; upon booting the computer, the user is presented with a
174 menu to select one of the installed operating systems.")
175 (license license:gpl3+)
176 (properties '((cpe-name . "grub2")))))
178 (define-public grub-efi
182 (synopsis "GRand Unified Boot loader (UEFI version)")
184 `(("efibootmgr" ,efibootmgr)
186 ,@(package-inputs grub)))
188 `(;; TODO: Tests need a UEFI firmware for qemu. There is one at
189 ;; https://github.com/tianocore/edk2/tree/master/OvmfPkg .
190 ;; Search for 'OVMF' in "tests/util/grub-shell.in".
191 ,@(substitute-keyword-arguments (package-arguments grub)
193 ((#:configure-flags flags ''())
194 `(cons "--with-platform=efi" ,flags))
196 `(modify-phases ,phases
197 (add-after 'patch-stuff 'use-absolute-efibootmgr-path
198 (lambda* (#:key inputs #:allow-other-keys)
199 (substitute* "grub-core/osdep/unix/platform.c"
201 (string-append (assoc-ref inputs "efibootmgr")
202 "/sbin/efibootmgr")))
204 (add-after 'patch-stuff 'use-absolute-mtools-path
205 (lambda* (#:key inputs #:allow-other-keys)
206 (let ((mtools (assoc-ref inputs "mtools")))
207 (substitute* "util/grub-mkrescue.c"
209 (string-append "\"" mtools
211 (substitute* "util/grub-mkrescue.c"
213 (string-append "\"" mtools
217 ;; Because grub searches hardcoded paths it's easiest to just build grub
218 ;; again to make it find both grub-pc and grub-efi. There is a command
219 ;; line argument which allows you to specify ONE platform - but
220 ;; grub-mkrescue will use multiple platforms if they are available
221 ;; in the installation directory (without command line argument).
222 (define-public grub-hybrid
226 (synopsis "GRand Unified Boot loader (hybrid version)")
229 ,@(package-inputs grub-efi)))
231 (substitute-keyword-arguments (package-arguments grub-efi)
232 ((#:modules modules `((guix build utils) (guix build gnu-build-system)))
233 `((ice-9 ftw) ,@modules))
235 `(modify-phases ,phases
236 (add-after 'install 'install-non-efi
237 (lambda* (#:key inputs outputs #:allow-other-keys)
238 (let ((input-dir (string-append (assoc-ref inputs "grub")
240 (output-dir (string-append (assoc-ref outputs "out")
244 (if (not (or (string-prefix? "." basename)
245 (file-exists? (string-append output-dir "/" basename))))
246 (symlink (string-append input-dir "/" basename)
247 (string-append output-dir "/" basename))))
251 (define-public syslinux
252 (let ((commit "bb41e935cc83c6242de24d2271e067d76af3585c"))
255 (version (git-version "6.04-pre" "1" commit))
259 (url "https://github.com/geneC/syslinux")
261 (file-name (git-file-name name version))
264 "0k8dvafd6410kqxf3kyr4y8jzmpmrih6wbjqg6gklak7945yflrc"))))
265 (build-system gnu-build-system)
269 ("python-2" ,python-2)))
271 `(("libuuid" ,util-linux)
274 `(#:parallel-build? #f
276 (list (string-append "BINDIR=" %output "/bin")
277 (string-append "SBINDIR=" %output "/sbin")
278 (string-append "LIBDIR=" %output "/lib")
279 (string-append "INCDIR=" %output "/include")
280 (string-append "DATADIR=" %output "/share")
281 (string-append "MANDIR=" %output "/share/man")
285 (modify-phases %standard-phases
286 (add-after 'unpack 'patch-files
287 (lambda* (#:key inputs #:allow-other-keys)
288 (substitute* (find-files "." "Makefile.*|ppmtolss16")
289 (("/bin/pwd") (which "pwd"))
290 (("/bin/echo") (which "echo"))
291 (("/usr/bin/perl") (which "perl")))
292 (let ((mtools (assoc-ref inputs "mtools")))
293 (substitute* (find-files "." "\\.c$")
295 (string-append mtools "/bin/mcopy"))
297 (string-append mtools "/bin/mattrib"))))
300 (add-before 'build 'set-permissions
302 (zero? (system* "chmod" "a+w" "utils/isohybrid.in"))))
306 (substitute* "tests/unittest/include/unittest/unittest.h"
307 ;; Don't look up headers under /usr.
308 (("/usr/include/") ""))
309 (zero? (system* "make" "unittest")))))))
310 (home-page "http://www.syslinux.org")
311 (synopsis "Lightweight Linux bootloader")
312 (description "Syslinux is a lightweight Linux bootloader.")
313 (license (list license:gpl2+
314 license:bsd-3 ; gnu-efi/*
315 license:bsd-4 ; gnu-efi/inc/* gnu-efi/lib/*
317 license:expat license:isc license:zlib)))))
326 "mirror://kernel.org/software/utils/dtc/"
327 "dtc-" version ".tar.xz"))
330 "0zkvih0fpwvk31aqyyfy9kn13nbi76c21ihax15p6h1wrjzh48rq"))))
331 (build-system gnu-build-system)
337 `(("python-2" ,python-2)))
341 (string-append "PREFIX=" (assoc-ref %outputs "out"))
342 (string-append "SETUP_PREFIX=" (assoc-ref %outputs "out"))
345 (modify-phases %standard-phases
346 (delete 'configure)))) ; no configure script
347 (home-page "https://www.devicetree.org")
348 (synopsis "Compiles device tree source files")
349 (description "@command{dtc} compiles
350 @uref{http://elinux.org/Device_Tree_Usage, device tree source files} to device
351 tree binary files. These are board description files used by Linux and BSD.")
352 (license license:gpl2+)))
361 "ftp://ftp.denx.de/pub/u-boot/"
362 "u-boot-" version ".tar.bz2"))
365 "1nidnnjprgxdhiiz7gmaj8cgcf52l5gbv64cmzjq4gmkjirmk3wk"))))
368 ;("dtc" ,dtc) ; they have their own incompatible copy.
369 ("python-2" ,python-2)
371 (build-system gnu-build-system)
372 (home-page "http://www.denx.de/wiki/U-Boot/")
373 (synopsis "ARM bootloader")
374 (description "U-Boot is a bootloader used mostly for ARM boards. It
375 also initializes the boards (RAM etc).")
376 (license license:gpl2+)))
378 (define (make-u-boot-package board triplet)
379 "Returns a u-boot package for BOARD cross-compiled for TRIPLET."
380 (let ((same-arch? (if (string-prefix? (%current-system)
381 (gnu-triplet->nix-system triplet))
386 (name (string-append "u-boot-"
387 (string-replace-substring (string-downcase board)
390 `(,@(if (not same-arch?)
391 `(("cross-gcc" ,(cross-gcc triplet #:xgcc gcc-7))
392 ("cross-binutils" ,(cross-binutils triplet)))
394 ,@(package-native-inputs u-boot)))
396 `(#:modules ((ice-9 ftw) (guix build utils) (guix build gnu-build-system))
400 ,@(if (not same-arch?)
401 `((string-append "CROSS_COMPILE=" ,triplet "-"))
404 (modify-phases %standard-phases
406 (lambda* (#:key outputs make-flags #:allow-other-keys)
407 (let ((config-name (string-append ,board "_defconfig")))
408 (if (file-exists? (string-append "configs/" config-name))
409 (zero? (apply system* "make" `(,@make-flags ,config-name)))
411 (display "Invalid board name. Valid board names are:")
412 (let ((suffix-len (string-length "_defconfig")))
415 (when (string-suffix? "_defconfig" file-name)
418 (string-drop-right file-name
422 (lambda* (#:key outputs #:allow-other-keys)
423 (let* ((out (assoc-ref outputs "out"))
424 (libexec (string-append out "/libexec"))
426 (find-files "." ".*\\.(bin|efi|img|spl|itb|dtb)$")
427 (find-files "." "^MLO$"))))
429 (install-file ".config" libexec)
432 (let ((target-file (string-append libexec "/" file)))
433 (mkdir-p (dirname target-file))
434 (copy-file file target-file)))
435 uboot-files))))))))))
437 (define-public u-boot-vexpress
438 (make-u-boot-package "vexpress_ca9x4" "arm-linux-gnueabihf"))
440 (define-public u-boot-malta
441 (make-u-boot-package "malta" "mips64el-linux-gnuabi64"))
443 (define-public u-boot-beagle-bone-black
444 (make-u-boot-package "am335x_boneblack" "arm-linux-gnueabihf"))
446 (define-public u-boot-odroid-c2
447 (make-u-boot-package "odroid-c2" "aarch64-linux-gnu"))
449 (define-public u-boot-pine64-plus
450 (let ((base (make-u-boot-package "pine64_plus" "aarch64-linux-gnu")))
454 (substitute-keyword-arguments (package-arguments base)
456 `(modify-phases ,phases
457 (add-after 'unpack 'set-environment
458 (lambda* (#:key inputs #:allow-other-keys)
459 (let ((bl31 (string-append (assoc-ref inputs "firmware")
462 ;; This is necessary while we're using the bundled dtc.
463 (setenv "PATH" (string-append (getenv "PATH") ":"
467 `(("firmware" ,arm-trusted-firmware-pine64-plus)
468 ,@(package-native-inputs base))))))
470 (define-public u-boot-banana-pi-m2-ultra
471 (make-u-boot-package "Bananapi_M2_Ultra" "arm-linux-gnueabihf"))
473 (define-public u-boot-a20-olinuxino-lime
474 (make-u-boot-package "A20-OLinuXino-Lime" "arm-linux-gnueabihf"))
476 (define-public u-boot-a20-olinuxino-lime2
477 (make-u-boot-package "A20-OLinuXino-Lime2" "arm-linux-gnueabihf"))
479 (define-public u-boot-a20-olinuxino-micro
480 (make-u-boot-package "A20-OLinuXino_MICRO" "arm-linux-gnueabihf"))
482 (define-public u-boot-nintendo-nes-classic-edition
483 (make-u-boot-package "Nintendo_NES_Classic_Edition" "arm-linux-gnueabihf"))
485 (define-public vboot-utils
488 (version "R63-10032.B")
490 ;; XXX: Snapshots are available but changes timestamps every download.
493 (url (string-append "https://chromium.googlesource.com"
494 "/chromiumos/platform/vboot_reference"))
495 (commit (string-append "release-" version))))
496 (file-name (string-append name "-" version "-checkout"))
499 "0h0m3l69vp9dr6xrs1p6y7ilkq3jq8jraw2z20kqfv7lvc9l1lxj"))))
500 (build-system gnu-build-system)
502 `(#:make-flags (list "CC=gcc"
503 (string-append "DESTDIR=" (assoc-ref %outputs "out")))
504 #:phases (modify-phases %standard-phases
505 (add-after 'unpack 'patch-hard-coded-paths
506 (lambda* (#:key inputs outputs #:allow-other-keys)
507 (let ((coreutils (assoc-ref inputs "coreutils"))
508 (diffutils (assoc-ref inputs "diffutils")))
509 (substitute* "futility/misc.c"
510 (("/bin/cp") (string-append coreutils "/bin/cp")))
511 (substitute* "tests/bitmaps/TestBmpBlock.py"
512 (("/usr/bin/cmp") (string-append diffutils "/bin/cmp")))
513 (substitute* "vboot_host.pc.in"
515 (string-append "prefix=" (assoc-ref outputs "out"))))
518 (add-before 'check 'patch-tests
520 ;; These tests compare diffs against known-good values.
521 ;; Patch the paths to match those in the build container.
522 (substitute* (find-files "tests/futility/expect_output")
523 (("/mnt/host/source/src/platform/vboot_reference")
524 (string-append "/tmp/guix-build-" ,name "-" ,version
526 ;; Tests require write permissions to many of these files.
527 (for-each make-file-writable (find-files "tests/futility"))
529 #:test-target "runtests"))
531 `(("pkg-config" ,pkg-config)
534 ("diffutils" ,diffutils)
535 ("python@2" ,python-2)))
537 `(("coreutils" ,coreutils)
540 ("openssl:static" ,openssl "static")
541 ("util-linux" ,util-linux)))
543 "https://dev.chromium.org/chromium-os/chromiumos-design-docs/verified-boot")
544 (synopsis "ChromiumOS verified boot utilities")
546 "vboot-utils is a collection of tools to facilitate booting of
547 Chrome-branded devices. This includes the @command{cgpt} partitioning
548 program, the @command{futility} and @command{crossystem} firmware management
550 (license license:bsd-3)))
552 (define-public os-prober
559 (uri (string-append "mirror://debian/pool/main/o/os-prober/os-prober_"
563 "1vb45i76bqivlghrq7m3n07qfmmq4wxrkplqx8gywj011rhq19fk"))))
564 (build-system gnu-build-system)
566 `(#:modules ((guix build gnu-build-system)
568 (ice-9 regex) ; for string-match
569 (srfi srfi-26)) ; for cut
570 #:make-flags (list "CC=gcc")
571 #:tests? #f ; no tests
573 (modify-phases %standard-phases
575 (lambda* (#:key outputs #:allow-other-keys)
576 (substitute* (find-files ".")
577 (("/usr") (assoc-ref outputs "out")))
578 (substitute* (find-files "." "50mounted-tests$")
579 (("mkdir") "mkdir -p"))
582 (lambda* (#:key outputs #:allow-other-keys)
583 (define (find-files-non-recursive directory)
584 (find-files directory
586 (string-match (string-append "^" directory "/[^/]*$")
590 (let* ((out (assoc-ref outputs "out"))
591 (bin (string-append out "/bin"))
592 (lib (string-append out "/lib"))
593 (share (string-append out "/share")))
594 (for-each (cut install-file <> bin)
595 (list "linux-boot-prober" "os-prober"))
596 (install-file "newns" (string-append lib "/os-prober"))
597 (install-file "common.sh" (string-append share "/os-prober"))
598 (install-file "os-probes/mounted/powerpc/20macosx"
599 (string-append lib "/os-probes/mounted"))
604 (let ((destination (string-append lib "/" directory
605 "/" (basename file))))
606 (mkdir-p (dirname destination))
607 (copy-recursively file destination)))
608 (append (find-files-non-recursive (string-append directory "/common"))
609 (find-files-non-recursive (string-append directory "/x86")))))
610 (list "os-probes" "os-probes/mounted" "os-probes/init"
611 "linux-boot-probes" "linux-boot-probes/mounted"))
613 (home-page "https://joeyh.name/code/os-prober")
614 (synopsis "Detect other operating systems")
615 (description "os-prober probes disks on the system for other operating
616 systems so that they can be added to the bootloader. It also works out how to
617 boot existing GNU/Linux systems and detects what distribution is installed in
618 order to add a suitable bootloader menu entry.")
619 (license license:gpl2+)))