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