gnu: Update r-mutationalpatterns to 1.4.1.
[jackhill/guix/guix.git] / gnu / packages / bootloaders.scm
CommitLineData
65d8b777 1;;; GNU Guix --- Functional package management for GNU
ef753a1a 2;;; Copyright © 2013, 2014, 2015, 2016, 2017 Ludovic Courtès <ludo@gnu.org>
04e0eac1 3;;; Copyright © 2015 Mark H Weaver <mhw@netris.org>
f0150f87 4;;; Copyright © 2015 Leo Famulari <leo@famulari.name>
4c726001 5;;; Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org>
d846834f 6;;; Copyright © 2016, 2017 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>
4adeb3f6 9;;; Copyright © 2017 Efraim Flashner <efraim@flashner.co.il>
65d8b777
LC
10;;;
11;;; This file is part of GNU Guix.
12;;;
13;;; GNU Guix is free software; you can redistribute it and/or modify it
14;;; under the terms of the GNU General Public License as published by
15;;; the Free Software Foundation; either version 3 of the License, or (at
16;;; your option) any later version.
17;;;
18;;; GNU Guix is distributed in the hope that it will be useful, but
19;;; WITHOUT ANY WARRANTY; without even the implied warranty of
20;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21;;; GNU General Public License for more details.
22;;;
23;;; You should have received a copy of the GNU General Public License
24;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
25
862e38d5 26(define-module (gnu packages bootloaders)
65d8b777 27 #:use-module (gnu packages)
862e38d5
DC
28 #:use-module (gnu packages admin)
29 #:use-module ((gnu packages algebra) #:select (bc))
30 #:use-module (gnu packages assembly)
7febe3a2 31 #:use-module (gnu packages disk)
65d8b777 32 #:use-module (gnu packages bison)
862e38d5
DC
33 #:use-module (gnu packages cdrom)
34 #:use-module (gnu packages cross-base)
35 #:use-module (gnu packages disk)
36 #:use-module (gnu packages flex)
a86177d6 37 #:use-module (gnu packages fontutils)
862e38d5 38 #:use-module (gnu packages gettext)
65d8b777 39 #:use-module (gnu packages linux)
862e38d5 40 #:use-module (gnu packages man)
444f9dcc 41 #:use-module (gnu packages mtools)
862e38d5 42 #:use-module (gnu packages ncurses)
96b714f5
DC
43 #:use-module (gnu packages perl)
44 #:use-module (gnu packages python)
58301666 45 #:use-module (gnu packages texinfo)
12c613b5 46 #:use-module (gnu packages swig)
59132b80 47 #:use-module (gnu packages virtualization)
862e38d5
DC
48 #:use-module (guix build-system gnu)
49 #:use-module (guix download)
50 #:use-module (guix git-download)
51 #:use-module ((guix licenses) #:prefix license:)
52 #:use-module (guix packages)
53 #:use-module (guix utils))
65d8b777 54
9b24c768
LC
55(define unifont
56 ;; GNU Unifont, <http://gnu.org/s/unifont>.
57 ;; GRUB needs it for its graphical terminal, gfxterm.
58 (origin
59 (method url-fetch)
60 (uri
61 "http://unifoundry.com/pub/unifont-7.0.06/font-builds/unifont-7.0.06.bdf.gz")
62 (sha256
63 (base32
64 "0p2vhnc18cnbmb39vq4m7hzv4mhnm2l0a2s7gx3ar277fwng3hys"))))
65
65d8b777
LC
66(define-public grub
67 (package
68 (name "grub")
3586a3e9 69 (version "2.02")
65d8b777
LC
70 (source (origin
71 (method url-fetch)
3586a3e9 72 (uri (string-append "mirror://gnu/grub/grub-" version ".tar.xz"))
65d8b777
LC
73 (sha256
74 (base32
3586a3e9 75 "03vvdfhdmf16121v7xs8is2krwnv15wpkhkf16a4yf8nsfc3f2w1"))))
65d8b777
LC
76 (build-system gnu-build-system)
77 (arguments
d846834f 78 '(#:phases (modify-phases %standard-phases
358db004 79 (add-after 'unpack 'patch-stuff
04e0eac1
MW
80 (lambda* (#:key inputs #:allow-other-keys)
81 (substitute* "grub-core/Makefile.in"
82 (("/bin/sh") (which "sh")))
65d8b777 83
358db004
LC
84 ;; Give the absolute file name of 'mdadm', used to
85 ;; determine the root file system when it's a RAID
86 ;; device. Failing to do that, 'grub-probe' silently
87 ;; fails if 'mdadm' is not in $PATH.
88 (substitute* "grub-core/osdep/linux/getroot.c"
89 (("argv\\[0\\] = \"mdadm\"")
90 (string-append "argv[0] = \""
91 (assoc-ref inputs "mdadm")
92 "/sbin/mdadm\"")))
93
04e0eac1
MW
94 ;; Make the font visible.
95 (copy-file (assoc-ref inputs "unifont") "unifont.bdf.gz")
96 (system* "gunzip" "unifont.bdf.gz")
23a53a95
LF
97 #t))
98 (add-before 'check 'disable-flaky-test
99 (lambda _
100 ;; This test is unreliable. For more information, see:
101 ;; <https://bugs.gnu.org/26936>.
102 (substitute* "Makefile.in"
103 (("grub_cmd_date grub_cmd_set_date grub_cmd_sleep")
104 "grub_cmd_date grub_cmd_sleep"))
105 #t)))))
65d8b777 106 (inputs
10da75df
LC
107 `(("gettext" ,gettext-minimal)
108
109 ;; Depend on LVM2 for libdevmapper, used by 'grub-probe' and
110 ;; 'grub-install' to recognize mapped devices (LUKS, etc.)
111 ("lvm2" ,lvm2)
112
113 ;; Depend on mdadm, which is invoked by 'grub-probe' and 'grub-install'
114 ;; to determine whether the root file system is RAID.
358db004 115 ("mdadm" ,mdadm)
10da75df 116
65d8b777
LC
117 ("freetype" ,freetype)
118 ;; ("libusb" ,libusb)
04e0eac1 119 ;; ("fuse" ,fuse)
01eafd38 120 ("ncurses" ,ncurses)))
65d8b777 121 (native-inputs
9b24c768
LC
122 `(("unifont" ,unifont)
123 ("bison" ,bison)
0a3aca47
LF
124 ;; Due to a bug in flex >= 2.6.2, GRUB must be built with an older flex:
125 ;; <http://lists.gnu.org/archive/html/grub-devel/2017-02/msg00133.html>
126 ;; TODO Try building with flex > 2.6.4.
127 ("flex" ,flex-2.6.1)
58301666
MW
128 ("texinfo" ,texinfo)
129 ("help2man" ,help2man)
65d8b777
LC
130
131 ;; Dependencies for the test suite. The "real" QEMU is needed here,
132 ;; because several targets are used.
7febe3a2 133 ("parted" ,parted)
7d8f7ab9 134 ("qemu" ,qemu-minimal)
65d8b777 135 ("xorriso" ,xorriso)))
175b259c 136 (home-page "https://www.gnu.org/software/grub/")
79c311b8 137 (synopsis "GRand Unified Boot loader")
65d8b777 138 (description
a22dc0c4 139 "GRUB is a multiboot bootloader. It is used for initially loading the
35b9e423 140kernel of an operating system and then transferring control to it. The kernel
c5779c93 141then goes on to load the rest of the operating system. As a multiboot
574e86f9
LC
142bootloader, GRUB handles the presence of multiple operating systems installed
143on the same computer; upon booting the computer, the user is presented with a
a22dc0c4 144menu to select one of the installed operating systems.")
3f73aa1a 145 (license license:gpl3+)
99effc8f 146 (properties '((cpe-name . "grub2")))))
acb5f7c3
MB
147
148(define-public grub-efi
149 (package
150 (inherit grub)
151 (name "grub-efi")
152 (synopsis "GRand Unified Boot loader (UEFI version)")
153 (inputs
154 `(("efibootmgr" ,efibootmgr)
444f9dcc 155 ("mtools", mtools)
acb5f7c3
MB
156 ,@(package-inputs grub)))
157 (arguments
158 `(;; TODO: Tests need a UEFI firmware for qemu. There is one at
159 ;; https://github.com/tianocore/edk2/tree/master/OvmfPkg .
160 ;; Search for 'OVMF' in "tests/util/grub-shell.in".
161 #:tests? #f
162 ,@(substitute-keyword-arguments (package-arguments grub)
ef753a1a
LC
163 ((#:configure-flags flags ''())
164 `(cons "--with-platform=efi" ,flags))
acb5f7c3
MB
165 ((#:phases phases)
166 `(modify-phases ,phases
167 (add-after 'patch-stuff 'use-absolute-efibootmgr-path
168 (lambda* (#:key inputs #:allow-other-keys)
169 (substitute* "grub-core/osdep/unix/platform.c"
170 (("efibootmgr")
171 (string-append (assoc-ref inputs "efibootmgr")
172 "/sbin/efibootmgr")))
444f9dcc
DM
173 #t))
174 (add-after 'patch-stuff 'use-absolute-mtools-path
175 (lambda* (#:key inputs #:allow-other-keys)
176 (let ((mtools (assoc-ref inputs "mtools")))
177 (substitute* "util/grub-mkrescue.c"
178 (("\"mformat\"")
179 (string-append "\"" mtools
180 "/bin/mformat\"")))
181 (substitute* "util/grub-mkrescue.c"
182 (("\"mcopy\"")
183 (string-append "\"" mtools
184 "/bin/mcopy\"")))
185 #t))))))))))
96b714f5 186
dd4b7476
DM
187;; Because grub searches hardcoded paths it's easiest to just build grub
188;; again to make it find both grub-pc and grub-efi. There is a command
189;; line argument which allows you to specify ONE platform - but
190;; grub-mkrescue will use multiple platforms if they are available
191;; in the installation directory (without command line argument).
192(define-public grub-hybrid
193 (package
194 (inherit grub-efi)
195 (name "grub-hybrid")
196 (synopsis "GRand Unified Boot loader (hybrid version)")
197 (inputs
198 `(("grub" ,grub)
199 ,@(package-inputs grub-efi)))
200 (arguments
201 (substitute-keyword-arguments (package-arguments grub-efi)
202 ((#:modules modules `((guix build utils) (guix build gnu-build-system)))
203 `((ice-9 ftw) ,@modules))
204 ((#:phases phases)
205 `(modify-phases ,phases
206 (add-after 'install 'install-non-efi
207 (lambda* (#:key inputs outputs #:allow-other-keys)
208 (let ((input-dir (string-append (assoc-ref inputs "grub")
209 "/lib/grub"))
210 (output-dir (string-append (assoc-ref outputs "out")
211 "/lib/grub")))
212 (for-each
213 (lambda (basename)
214 (if (not (string-prefix? "." basename))
215 (symlink (string-append input-dir "/" basename)
216 (string-append output-dir "/" basename))))
217 (scandir input-dir))
218 #t)))))))))
219
96b714f5
DC
220(define-public syslinux
221 (let ((commit "bb41e935cc83c6242de24d2271e067d76af3585c"))
222 (package
223 (name "syslinux")
224 (version (git-version "6.04-pre" "1" commit))
225 (source (origin
226 (method git-fetch)
227 (uri (git-reference
228 (url "https://github.com/geneC/syslinux")
229 (commit commit)))
230 (file-name (git-file-name name version))
231 (sha256
232 (base32
233 "0k8dvafd6410kqxf3kyr4y8jzmpmrih6wbjqg6gklak7945yflrc"))))
234 (build-system gnu-build-system)
235 (native-inputs
236 `(("nasm" ,nasm)
237 ("perl" ,perl)
238 ("python-2" ,python-2)))
239 (inputs
0b4dbb40
LC
240 `(("libuuid" ,util-linux)
241 ("mtools" ,mtools)))
96b714f5
DC
242 (arguments
243 `(#:parallel-build? #f
244 #:make-flags
245 (list (string-append "BINDIR=" %output "/bin")
246 (string-append "SBINDIR=" %output "/sbin")
247 (string-append "LIBDIR=" %output "/lib")
248 (string-append "INCDIR=" %output "/include")
249 (string-append "DATADIR=" %output "/share")
250 (string-append "MANDIR=" %output "/share/man")
251 "PERL=perl"
252 "bios")
253 #:phases
254 (modify-phases %standard-phases
255 (add-after 'unpack 'patch-files
0b4dbb40 256 (lambda* (#:key inputs #:allow-other-keys)
96b714f5
DC
257 (substitute* (find-files "." "Makefile.*|ppmtolss16")
258 (("/bin/pwd") (which "pwd"))
259 (("/bin/echo") (which "echo"))
260 (("/usr/bin/perl") (which "perl")))
0b4dbb40
LC
261 (let ((mtools (assoc-ref inputs "mtools")))
262 (substitute* (find-files "." "\\.c$")
263 (("mcopy")
264 (string-append mtools "/bin/mcopy"))
265 (("mattrib")
266 (string-append mtools "/bin/mattrib"))))
96b714f5
DC
267 #t))
268 (delete 'configure)
269 (add-before 'build 'set-permissions
270 (lambda _
271 (zero? (system* "chmod" "a+w" "utils/isohybrid.in"))))
272 (replace 'check
273 (lambda _
274 (setenv "CC" "gcc")
275 (substitute* "tests/unittest/include/unittest/unittest.h"
276 ;; Don't look up headers under /usr.
277 (("/usr/include/") ""))
278 (zero? (system* "make" "unittest")))))))
279 (home-page "http://www.syslinux.org")
280 (synopsis "Lightweight Linux bootloader")
281 (description "Syslinux is a lightweight Linux bootloader.")
282 (license (list license:gpl2+
283 license:bsd-3 ; gnu-efi/*
284 license:bsd-4 ; gnu-efi/inc/* gnu-efi/lib/*
285 ;; Also contains:
286 license:expat license:isc license:zlib)))))
862e38d5
DC
287
288(define-public dtc
289 (package
290 (name "dtc")
ab8757c5 291 (version "1.4.5")
862e38d5
DC
292 (source (origin
293 (method url-fetch)
294 (uri (string-append
3b4efb1f 295 "mirror://kernel.org/software/utils/dtc/"
862e38d5
DC
296 "dtc-" version ".tar.xz"))
297 (sha256
298 (base32
ab8757c5 299 "08gnl39i4xy3dm8iqwlz2ygx0ml1bgc5kpiys5ll1wvah1j72b04"))))
862e38d5
DC
300 (build-system gnu-build-system)
301 (native-inputs
302 `(("bison" ,bison)
12c613b5
EF
303 ("flex" ,flex)
304 ("swig" ,swig)))
305 (inputs
306 `(("python-2" ,python-2)))
862e38d5
DC
307 (arguments
308 `(#:make-flags
309 (list "CC=gcc"
310 (string-append "PREFIX=" (assoc-ref %outputs "out"))
12c613b5 311 (string-append "SETUP_PREFIX=" (assoc-ref %outputs "out"))
862e38d5
DC
312 "INSTALL=install")
313 #:phases
314 (modify-phases %standard-phases
315 (delete 'configure))))
316 (home-page "https://www.devicetree.org")
317 (synopsis "Compiles device tree source files")
318 (description "@command{dtc} compiles
319@uref{http://elinux.org/Device_Tree_Usage, device tree source files} to device
320tree binary files. These are board description files used by Linux and BSD.")
321 (license license:gpl2+)))
322
323(define u-boot
324 (package
325 (name "u-boot")
13136283 326 (version "2017.07")
862e38d5
DC
327 (source (origin
328 (method url-fetch)
329 (uri (string-append
330 "ftp://ftp.denx.de/pub/u-boot/"
331 "u-boot-" version ".tar.bz2"))
332 (sha256
333 (base32
13136283 334 "1zzywk0fgngm1mfnhkp8d0v57rs51zr1y6rp4p03i6nbibfbyx2k"))))
862e38d5
DC
335 (native-inputs
336 `(("bc" ,bc)
337 ("dtc" ,dtc)
338 ("python-2" ,python-2)))
339 (build-system gnu-build-system)
340 (home-page "http://www.denx.de/wiki/U-Boot/")
341 (synopsis "ARM bootloader")
342 (description "U-Boot is a bootloader used mostly for ARM boards. It
343also initializes the boards (RAM etc).")
344 (license license:gpl2+)))
345
346(define (make-u-boot-package board triplet)
347 "Returns a u-boot package for BOARD cross-compiled for TRIPLET."
2ac42fe5
MO
348 (let ((same-arch? (if (string-prefix? (%current-system)
349 (gnu-triplet->nix-system triplet))
3bfee8ff
EF
350 `#t
351 `#f)))
352 (package
353 (inherit u-boot)
354 (name (string-append "u-boot-" (string-downcase board)))
355 (native-inputs
356 `(,@(if (not same-arch?)
357 `(("cross-gcc" ,(cross-gcc triplet))
358 ("cross-binutils" ,(cross-binutils triplet)))
359 '())
360 ,@(package-native-inputs u-boot)))
361 (arguments
362 `(#:modules ((ice-9 ftw) (guix build utils) (guix build gnu-build-system))
363 #:test-target "test"
364 #:make-flags
365 (list "HOSTCC=gcc"
366 ,@(if (not same-arch?)
367 `((string-append "CROSS_COMPILE=" ,triplet "-"))
368 '()))
369 #:phases
370 (modify-phases %standard-phases
371 (replace 'configure
372 (lambda* (#:key outputs make-flags #:allow-other-keys)
373 (let ((config-name (string-append ,board "_defconfig")))
374 (if (file-exists? (string-append "configs/" config-name))
375 (zero? (apply system* "make" `(,@make-flags ,config-name)))
376 (begin
377 (display "Invalid board name. Valid board names are:")
378 (let ((suffix-len (string-length "_defconfig")))
379 (scandir "configs"
380 (lambda (file-name)
381 (when (string-suffix? "_defconfig" file-name)
382 (format #t
383 "- ~A\n"
384 (string-drop-right file-name
385 suffix-len))))))
386 #f)))))
387 (replace 'install
388 (lambda* (#:key outputs make-flags #:allow-other-keys)
389 (let* ((out (assoc-ref outputs "out"))
390 (libexec (string-append out "/libexec"))
dd208b93
MO
391 (uboot-files (append
392 (find-files "." ".*\\.(bin|efi|img|spl)$")
10b159a3 393 (find-files "." "^MLO$"))))
3bfee8ff
EF
394 (mkdir-p libexec)
395 (for-each
396 (lambda (file)
397 (let ((target-file (string-append libexec "/" file)))
398 (mkdir-p (dirname target-file))
399 (copy-file file target-file)))
400 uboot-files))))))))))
862e38d5
DC
401
402(define-public u-boot-vexpress
403 (make-u-boot-package "vexpress_ca9x4" "arm-linux-gnueabihf"))
404
405(define-public u-boot-malta
406 (make-u-boot-package "malta" "mips64el-linux-gnuabi64"))
407
408(define-public u-boot-beagle-bone-black
409 (make-u-boot-package "am335x_boneblack" "arm-linux-gnueabihf"))
4adeb3f6
EF
410
411(define-public u-boot-odroid-c2
412 (make-u-boot-package "odroid-c2" "aarch64-linux-gnu"))
aa90375a
AI
413
414(define-public os-prober
415 (package
416 (name "os-prober")
417 (version "1.76")
418 (source
419 (origin
420 (method url-fetch)
421 (uri (string-append "mirror://debian/pool/main/o/os-prober/os-prober_"
422 version ".tar.xz"))
423 (sha256
424 (base32
425 "1vb45i76bqivlghrq7m3n07qfmmq4wxrkplqx8gywj011rhq19fk"))))
426 (build-system gnu-build-system)
427 (arguments
428 `(#:modules ((guix build gnu-build-system)
429 (guix build utils)
430 (ice-9 regex) ; for string-match
431 (srfi srfi-26)) ; for cut
432 #:make-flags (list "CC=gcc")
433 #:tests? #f ; no tests
434 #:phases
435 (modify-phases %standard-phases
436 (replace 'configure
437 (lambda* (#:key outputs #:allow-other-keys)
438 (substitute* (find-files ".")
439 (("/usr") (assoc-ref outputs "out")))
440 (substitute* (find-files "." "50mounted-tests$")
441 (("mkdir") "mkdir -p"))
442 #t))
443 (replace 'install
444 (lambda* (#:key outputs #:allow-other-keys)
445 (define (find-files-non-recursive directory)
446 (find-files directory
447 (lambda (file stat)
448 (string-match (string-append "^" directory "/[^/]*$")
449 file))
450 #:directories? #t))
451
452 (let* ((out (assoc-ref outputs "out"))
453 (bin (string-append out "/bin"))
454 (lib (string-append out "/lib"))
455 (share (string-append out "/share")))
456 (for-each (cut install-file <> bin)
457 (list "linux-boot-prober" "os-prober"))
458 (install-file "newns" (string-append lib "/os-prober"))
459 (install-file "common.sh" (string-append share "/os-prober"))
460 (install-file "os-probes/mounted/powerpc/20macosx"
461 (string-append lib "/os-probes/mounted"))
462 (for-each
463 (lambda (directory)
464 (for-each
465 (lambda (file)
466 (let ((destination (string-append lib "/" directory
467 "/" (basename file))))
468 (mkdir-p (dirname destination))
469 (copy-recursively file destination)))
470 (append (find-files-non-recursive (string-append directory "/common"))
471 (find-files-non-recursive (string-append directory "/x86")))))
472 (list "os-probes" "os-probes/mounted" "os-probes/init"
473 "linux-boot-probes" "linux-boot-probes/mounted"))
474 #t))))))
475 (home-page "https://joeyh.name/code/os-prober")
476 (synopsis "Detect other operating systems")
477 (description "os-prober probes disks on the system for other operating
478systems so that they can be added to the bootloader. It also works out how to
479boot existing GNU/Linux systems and detects what distribution is installed in
480order to add a suitable bootloader menu entry.")
481 (license license:gpl2+)))