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 flex)
39 #:use-module (gnu packages fontutils)
40 #:use-module (gnu packages gcc)
41 #:use-module (gnu packages gettext)
42 #:use-module (gnu packages linux)
43 #:use-module (gnu packages man)
44 #:use-module (gnu packages mtools)
45 #:use-module (gnu packages ncurses)
46 #:use-module (gnu packages perl)
47 #:use-module (gnu packages pkg-config)
48 #:use-module (gnu packages python)
49 #:use-module (gnu packages texinfo)
50 #:use-module (gnu packages tls)
51 #:use-module (gnu packages swig)
52 #:use-module (gnu packages virtualization)
53 #:use-module (gnu packages web)
54 #:use-module (guix build-system gnu)
55 #:use-module (guix download)
56 #:use-module (guix git-download)
57 #:use-module ((guix licenses) #:prefix license:)
58 #:use-module (guix packages)
59 #:use-module (guix utils)
60 #:use-module (srfi srfi-1)
61 #:use-module (srfi srfi-26))
64 ;; GNU Unifont, <http://gnu.org/s/unifont>.
65 ;; GRUB needs it for its graphical terminal, gfxterm.
69 "http://unifoundry.com/pub/unifont-7.0.06/font-builds/unifont-7.0.06.bdf.gz")
72 "0p2vhnc18cnbmb39vq4m7hzv4mhnm2l0a2s7gx3ar277fwng3hys"))))
80 (uri (string-append "mirror://gnu/grub/grub-" version ".tar.xz"))
83 "03vvdfhdmf16121v7xs8is2krwnv15wpkhkf16a4yf8nsfc3f2w1"))))
84 (build-system gnu-build-system)
86 `(#:phases (modify-phases %standard-phases
87 (add-after 'unpack 'patch-stuff
88 (lambda* (#:key inputs #:allow-other-keys)
89 (substitute* "grub-core/Makefile.in"
90 (("/bin/sh") (which "sh")))
92 ;; Give the absolute file name of 'mdadm', used to
93 ;; determine the root file system when it's a RAID
94 ;; device. Failing to do that, 'grub-probe' silently
95 ;; fails if 'mdadm' is not in $PATH.
96 (substitute* "grub-core/osdep/linux/getroot.c"
97 (("argv\\[0\\] = \"mdadm\"")
98 (string-append "argv[0] = \""
99 (assoc-ref inputs "mdadm")
102 ;; Make the font visible.
103 (copy-file (assoc-ref inputs "unifont") "unifont.bdf.gz")
104 (system* "gunzip" "unifont.bdf.gz")
106 (add-before 'check 'disable-flaky-test
108 ;; This test is unreliable. For more information, see:
109 ;; <https://bugs.gnu.org/26936>.
110 (substitute* "Makefile.in"
111 (("grub_cmd_date grub_cmd_set_date grub_cmd_sleep")
112 "grub_cmd_date grub_cmd_sleep"))
114 ;; Disable tests on ARM and AARCH64 platforms.
115 #:tests? ,(not (any (cute string-prefix? <> (or (%current-target-system)
117 '("arm" "aarch64")))))
119 `(("gettext" ,gettext-minimal)
121 ;; Depend on LVM2 for libdevmapper, used by 'grub-probe' and
122 ;; 'grub-install' to recognize mapped devices (LUKS, etc.)
125 ;; Depend on mdadm, which is invoked by 'grub-probe' and 'grub-install'
126 ;; to determine whether the root file system is RAID.
129 ("freetype" ,freetype)
130 ;; ("libusb" ,libusb)
132 ("ncurses" ,ncurses)))
134 `(("pkg-config" ,pkg-config)
137 ;; Due to a bug in flex >= 2.6.2, GRUB must be built with an older flex:
138 ;; <http://lists.gnu.org/archive/html/grub-devel/2017-02/msg00133.html>
139 ;; TODO Try building with flex > 2.6.4.
142 ("help2man" ,help2man)
144 ;; Dependencies for the test suite. The "real" QEMU is needed here,
145 ;; because several targets are used.
147 ("qemu" ,qemu-minimal)
148 ("xorriso" ,xorriso)))
149 (home-page "https://www.gnu.org/software/grub/")
150 (synopsis "GRand Unified Boot loader")
152 "GRUB is a multiboot bootloader. It is used for initially loading the
153 kernel of an operating system and then transferring control to it. The kernel
154 then goes on to load the rest of the operating system. As a multiboot
155 bootloader, GRUB handles the presence of multiple operating systems installed
156 on the same computer; upon booting the computer, the user is presented with a
157 menu to select one of the installed operating systems.")
158 (license license:gpl3+)
159 (properties '((cpe-name . "grub2")))))
161 (define-public grub-efi
165 (synopsis "GRand Unified Boot loader (UEFI version)")
167 `(("efibootmgr" ,efibootmgr)
169 ,@(package-inputs grub)))
171 `(;; TODO: Tests need a UEFI firmware for qemu. There is one at
172 ;; https://github.com/tianocore/edk2/tree/master/OvmfPkg .
173 ;; Search for 'OVMF' in "tests/util/grub-shell.in".
174 ,@(substitute-keyword-arguments (package-arguments grub)
176 ((#:configure-flags flags ''())
177 `(cons "--with-platform=efi" ,flags))
179 `(modify-phases ,phases
180 (add-after 'patch-stuff 'use-absolute-efibootmgr-path
181 (lambda* (#:key inputs #:allow-other-keys)
182 (substitute* "grub-core/osdep/unix/platform.c"
184 (string-append (assoc-ref inputs "efibootmgr")
185 "/sbin/efibootmgr")))
187 (add-after 'patch-stuff 'use-absolute-mtools-path
188 (lambda* (#:key inputs #:allow-other-keys)
189 (let ((mtools (assoc-ref inputs "mtools")))
190 (substitute* "util/grub-mkrescue.c"
192 (string-append "\"" mtools
194 (substitute* "util/grub-mkrescue.c"
196 (string-append "\"" mtools
200 ;; Because grub searches hardcoded paths it's easiest to just build grub
201 ;; again to make it find both grub-pc and grub-efi. There is a command
202 ;; line argument which allows you to specify ONE platform - but
203 ;; grub-mkrescue will use multiple platforms if they are available
204 ;; in the installation directory (without command line argument).
205 (define-public grub-hybrid
209 (synopsis "GRand Unified Boot loader (hybrid version)")
212 ,@(package-inputs grub-efi)))
214 (substitute-keyword-arguments (package-arguments grub-efi)
215 ((#:modules modules `((guix build utils) (guix build gnu-build-system)))
216 `((ice-9 ftw) ,@modules))
218 `(modify-phases ,phases
219 (add-after 'install 'install-non-efi
220 (lambda* (#:key inputs outputs #:allow-other-keys)
221 (let ((input-dir (string-append (assoc-ref inputs "grub")
223 (output-dir (string-append (assoc-ref outputs "out")
227 (if (not (or (string-prefix? "." basename)
228 (file-exists? (string-append output-dir "/" basename))))
229 (symlink (string-append input-dir "/" basename)
230 (string-append output-dir "/" basename))))
234 (define-public syslinux
235 (let ((commit "bb41e935cc83c6242de24d2271e067d76af3585c"))
238 (version (git-version "6.04-pre" "1" commit))
242 (url "https://github.com/geneC/syslinux")
244 (file-name (git-file-name name version))
247 "0k8dvafd6410kqxf3kyr4y8jzmpmrih6wbjqg6gklak7945yflrc"))))
248 (build-system gnu-build-system)
252 ("python-2" ,python-2)))
254 `(("libuuid" ,util-linux)
257 `(#:parallel-build? #f
259 (list (string-append "BINDIR=" %output "/bin")
260 (string-append "SBINDIR=" %output "/sbin")
261 (string-append "LIBDIR=" %output "/lib")
262 (string-append "INCDIR=" %output "/include")
263 (string-append "DATADIR=" %output "/share")
264 (string-append "MANDIR=" %output "/share/man")
268 (modify-phases %standard-phases
269 (add-after 'unpack 'patch-files
270 (lambda* (#:key inputs #:allow-other-keys)
271 (substitute* (find-files "." "Makefile.*|ppmtolss16")
272 (("/bin/pwd") (which "pwd"))
273 (("/bin/echo") (which "echo"))
274 (("/usr/bin/perl") (which "perl")))
275 (let ((mtools (assoc-ref inputs "mtools")))
276 (substitute* (find-files "." "\\.c$")
278 (string-append mtools "/bin/mcopy"))
280 (string-append mtools "/bin/mattrib"))))
283 (add-before 'build 'set-permissions
285 (zero? (system* "chmod" "a+w" "utils/isohybrid.in"))))
289 (substitute* "tests/unittest/include/unittest/unittest.h"
290 ;; Don't look up headers under /usr.
291 (("/usr/include/") ""))
292 (zero? (system* "make" "unittest")))))))
293 (home-page "http://www.syslinux.org")
294 (synopsis "Lightweight Linux bootloader")
295 (description "Syslinux is a lightweight Linux bootloader.")
296 (license (list license:gpl2+
297 license:bsd-3 ; gnu-efi/*
298 license:bsd-4 ; gnu-efi/inc/* gnu-efi/lib/*
300 license:expat license:isc license:zlib)))))
309 "mirror://kernel.org/software/utils/dtc/"
310 "dtc-" version ".tar.xz"))
313 "0zkvih0fpwvk31aqyyfy9kn13nbi76c21ihax15p6h1wrjzh48rq"))))
314 (build-system gnu-build-system)
320 `(("python-2" ,python-2)))
324 (string-append "PREFIX=" (assoc-ref %outputs "out"))
325 (string-append "SETUP_PREFIX=" (assoc-ref %outputs "out"))
328 (modify-phases %standard-phases
329 (delete 'configure)))) ; no configure script
330 (home-page "https://www.devicetree.org")
331 (synopsis "Compiles device tree source files")
332 (description "@command{dtc} compiles
333 @uref{http://elinux.org/Device_Tree_Usage, device tree source files} to device
334 tree binary files. These are board description files used by Linux and BSD.")
335 (license license:gpl2+)))
344 "ftp://ftp.denx.de/pub/u-boot/"
345 "u-boot-" version ".tar.bz2"))
348 "1nidnnjprgxdhiiz7gmaj8cgcf52l5gbv64cmzjq4gmkjirmk3wk"))))
351 ;("dtc" ,dtc) ; they have their own incompatible copy.
352 ("python-2" ,python-2)
354 (build-system gnu-build-system)
355 (home-page "http://www.denx.de/wiki/U-Boot/")
356 (synopsis "ARM bootloader")
357 (description "U-Boot is a bootloader used mostly for ARM boards. It
358 also initializes the boards (RAM etc).")
359 (license license:gpl2+)))
361 (define (make-u-boot-package board triplet)
362 "Returns a u-boot package for BOARD cross-compiled for TRIPLET."
363 (let ((same-arch? (if (string-prefix? (%current-system)
364 (gnu-triplet->nix-system triplet))
369 (name (string-append "u-boot-"
370 (string-replace-substring (string-downcase board)
373 `(,@(if (not same-arch?)
374 `(("cross-gcc" ,(cross-gcc triplet #:xgcc gcc-7))
375 ("cross-binutils" ,(cross-binutils triplet)))
377 ,@(package-native-inputs u-boot)))
379 `(#:modules ((ice-9 ftw) (guix build utils) (guix build gnu-build-system))
383 ,@(if (not same-arch?)
384 `((string-append "CROSS_COMPILE=" ,triplet "-"))
387 (modify-phases %standard-phases
389 (lambda* (#:key outputs make-flags #:allow-other-keys)
390 (let ((config-name (string-append ,board "_defconfig")))
391 (if (file-exists? (string-append "configs/" config-name))
392 (zero? (apply system* "make" `(,@make-flags ,config-name)))
394 (display "Invalid board name. Valid board names are:")
395 (let ((suffix-len (string-length "_defconfig")))
398 (when (string-suffix? "_defconfig" file-name)
401 (string-drop-right file-name
405 (lambda* (#:key outputs #:allow-other-keys)
406 (let* ((out (assoc-ref outputs "out"))
407 (libexec (string-append out "/libexec"))
409 (find-files "." ".*\\.(bin|efi|img|spl)$")
410 (find-files "." "^MLO$"))))
414 (let ((target-file (string-append libexec "/" file)))
415 (mkdir-p (dirname target-file))
416 (copy-file file target-file)))
417 uboot-files))))))))))
419 (define-public u-boot-vexpress
420 (make-u-boot-package "vexpress_ca9x4" "arm-linux-gnueabihf"))
422 (define-public u-boot-malta
423 (make-u-boot-package "malta" "mips64el-linux-gnuabi64"))
425 (define-public u-boot-beagle-bone-black
426 (make-u-boot-package "am335x_boneblack" "arm-linux-gnueabihf"))
428 (define-public u-boot-odroid-c2
429 (make-u-boot-package "odroid-c2" "aarch64-linux-gnu"))
431 (define-public u-boot-banana-pi-m2-ultra
432 (make-u-boot-package "Bananapi_M2_Ultra" "arm-linux-gnueabihf"))
434 (define-public u-boot-a20-olinuxino-lime
435 (make-u-boot-package "A20-OLinuXino-Lime" "arm-linux-gnueabihf"))
437 (define-public u-boot-a20-olinuxino-lime2
438 (make-u-boot-package "A20-OLinuXino-Lime2" "arm-linux-gnueabihf"))
440 (define-public u-boot-a20-olinuxino-micro
441 (make-u-boot-package "A20-OLinuXino_MICRO" "arm-linux-gnueabihf"))
443 (define-public u-boot-nintendo-nes-classic-edition
444 (make-u-boot-package "Nintendo_NES_Classic_Edition" "arm-linux-gnueabihf"))
446 (define-public vboot-utils
449 (version "R63-10032.B")
451 ;; XXX: Snapshots are available but changes timestamps every download.
454 (url (string-append "https://chromium.googlesource.com"
455 "/chromiumos/platform/vboot_reference"))
456 (commit (string-append "release-" version))))
457 (file-name (string-append name "-" version "-checkout"))
460 "0h0m3l69vp9dr6xrs1p6y7ilkq3jq8jraw2z20kqfv7lvc9l1lxj"))))
461 (build-system gnu-build-system)
463 `(#:make-flags (list "CC=gcc"
464 (string-append "DESTDIR=" (assoc-ref %outputs "out")))
465 #:phases (modify-phases %standard-phases
466 (add-after 'unpack 'patch-hard-coded-paths
467 (lambda* (#:key inputs outputs #:allow-other-keys)
468 (let ((coreutils (assoc-ref inputs "coreutils"))
469 (diffutils (assoc-ref inputs "diffutils")))
470 (substitute* "futility/misc.c"
471 (("/bin/cp") (string-append coreutils "/bin/cp")))
472 (substitute* "tests/bitmaps/TestBmpBlock.py"
473 (("/usr/bin/cmp") (string-append diffutils "/bin/cmp")))
474 (substitute* "vboot_host.pc.in"
476 (string-append "prefix=" (assoc-ref outputs "out"))))
479 (add-before 'check 'patch-tests
481 ;; These tests compare diffs against known-good values.
482 ;; Patch the paths to match those in the build container.
483 (substitute* (find-files "tests/futility/expect_output")
484 (("/mnt/host/source/src/platform/vboot_reference")
485 (string-append "/tmp/guix-build-" ,name "-" ,version
487 ;; Tests require write permissions to many of these files.
488 (for-each make-file-writable (find-files "tests/futility"))
490 #:test-target "runtests"))
492 `(("pkg-config" ,pkg-config)
495 ("diffutils" ,diffutils)
496 ("python@2" ,python-2)))
498 `(("coreutils" ,coreutils)
501 ("openssl:static" ,openssl "static")
502 ("util-linux" ,util-linux)))
504 "https://dev.chromium.org/chromium-os/chromiumos-design-docs/verified-boot")
505 (synopsis "ChromiumOS verified boot utilities")
507 "vboot-utils is a collection of tools to facilitate booting of
508 Chrome-branded devices. This includes the @command{cgpt} partitioning
509 program, the @command{futility} and @command{crossystem} firmware management
511 (license license:bsd-3)))
513 (define-public os-prober
520 (uri (string-append "mirror://debian/pool/main/o/os-prober/os-prober_"
524 "1vb45i76bqivlghrq7m3n07qfmmq4wxrkplqx8gywj011rhq19fk"))))
525 (build-system gnu-build-system)
527 `(#:modules ((guix build gnu-build-system)
529 (ice-9 regex) ; for string-match
530 (srfi srfi-26)) ; for cut
531 #:make-flags (list "CC=gcc")
532 #:tests? #f ; no tests
534 (modify-phases %standard-phases
536 (lambda* (#:key outputs #:allow-other-keys)
537 (substitute* (find-files ".")
538 (("/usr") (assoc-ref outputs "out")))
539 (substitute* (find-files "." "50mounted-tests$")
540 (("mkdir") "mkdir -p"))
543 (lambda* (#:key outputs #:allow-other-keys)
544 (define (find-files-non-recursive directory)
545 (find-files directory
547 (string-match (string-append "^" directory "/[^/]*$")
551 (let* ((out (assoc-ref outputs "out"))
552 (bin (string-append out "/bin"))
553 (lib (string-append out "/lib"))
554 (share (string-append out "/share")))
555 (for-each (cut install-file <> bin)
556 (list "linux-boot-prober" "os-prober"))
557 (install-file "newns" (string-append lib "/os-prober"))
558 (install-file "common.sh" (string-append share "/os-prober"))
559 (install-file "os-probes/mounted/powerpc/20macosx"
560 (string-append lib "/os-probes/mounted"))
565 (let ((destination (string-append lib "/" directory
566 "/" (basename file))))
567 (mkdir-p (dirname destination))
568 (copy-recursively file destination)))
569 (append (find-files-non-recursive (string-append directory "/common"))
570 (find-files-non-recursive (string-append directory "/x86")))))
571 (list "os-probes" "os-probes/mounted" "os-probes/init"
572 "linux-boot-probes" "linux-boot-probes/mounted"))
574 (home-page "https://joeyh.name/code/os-prober")
575 (synopsis "Detect other operating systems")
576 (description "os-prober probes disks on the system for other operating
577 systems so that they can be added to the bootloader. It also works out how to
578 boot existing GNU/Linux systems and detects what distribution is installed in
579 order to add a suitable bootloader menu entry.")
580 (license license:gpl2+)))