Merge branch 'master' into core-updates
[jackhill/guix/guix.git] / gnu / packages / bootloaders.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2013, 2014, 2015, 2016, 2017 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2015 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 Marius Bakke <mbakke@fastmail.com>
7 ;;; Copyright © 2016, 2017 Danny Milosavljevic <dannym@scratchpost.org>
8 ;;; Copyright © 2016, 2017 David Craven <david@craven.ch>
9 ;;;
10 ;;; This file is part of GNU Guix.
11 ;;;
12 ;;; GNU Guix is free software; you can redistribute it and/or modify it
13 ;;; under the terms of the GNU General Public License as published by
14 ;;; the Free Software Foundation; either version 3 of the License, or (at
15 ;;; your option) any later version.
16 ;;;
17 ;;; GNU Guix is distributed in the hope that it will be useful, but
18 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;;; GNU General Public License for more details.
21 ;;;
22 ;;; You should have received a copy of the GNU General Public License
23 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
24
25 (define-module (gnu packages bootloaders)
26 #:use-module (gnu packages)
27 #:use-module (gnu packages admin)
28 #:use-module ((gnu packages algebra) #:select (bc))
29 #:use-module (gnu packages assembly)
30 #:use-module (gnu packages disk)
31 #:use-module (gnu packages bison)
32 #:use-module (gnu packages cdrom)
33 #:use-module (gnu packages cross-base)
34 #:use-module (gnu packages disk)
35 #:use-module (gnu packages flex)
36 #:use-module (gnu packages fontutils)
37 #:use-module (gnu packages gettext)
38 #:use-module (gnu packages linux)
39 #:use-module (gnu packages man)
40 #:use-module (gnu packages ncurses)
41 #:use-module (gnu packages perl)
42 #:use-module (gnu packages python)
43 #:use-module (gnu packages qemu)
44 #:use-module (gnu packages texinfo)
45 #:use-module (guix build-system gnu)
46 #:use-module (guix download)
47 #:use-module (guix git-download)
48 #:use-module ((guix licenses) #:prefix license:)
49 #:use-module (guix packages)
50 #:use-module (guix utils))
51
52 (define unifont
53 ;; GNU Unifont, <http://gnu.org/s/unifont>.
54 ;; GRUB needs it for its graphical terminal, gfxterm.
55 (origin
56 (method url-fetch)
57 (uri
58 "http://unifoundry.com/pub/unifont-7.0.06/font-builds/unifont-7.0.06.bdf.gz")
59 (sha256
60 (base32
61 "0p2vhnc18cnbmb39vq4m7hzv4mhnm2l0a2s7gx3ar277fwng3hys"))))
62
63 (define-public grub
64 (package
65 (name "grub")
66 (version "2.02")
67 (source (origin
68 (method url-fetch)
69 (uri (string-append "mirror://gnu/grub/grub-" version ".tar.xz"))
70 (sha256
71 (base32
72 "03vvdfhdmf16121v7xs8is2krwnv15wpkhkf16a4yf8nsfc3f2w1"))))
73 (build-system gnu-build-system)
74 (arguments
75 '(#:phases (modify-phases %standard-phases
76 (add-after 'unpack 'patch-stuff
77 (lambda* (#:key inputs #:allow-other-keys)
78 (substitute* "grub-core/Makefile.in"
79 (("/bin/sh") (which "sh")))
80
81 ;; Give the absolute file name of 'mdadm', used to
82 ;; determine the root file system when it's a RAID
83 ;; device. Failing to do that, 'grub-probe' silently
84 ;; fails if 'mdadm' is not in $PATH.
85 (substitute* "grub-core/osdep/linux/getroot.c"
86 (("argv\\[0\\] = \"mdadm\"")
87 (string-append "argv[0] = \""
88 (assoc-ref inputs "mdadm")
89 "/sbin/mdadm\"")))
90
91 ;; Make the font visible.
92 (copy-file (assoc-ref inputs "unifont") "unifont.bdf.gz")
93 (system* "gunzip" "unifont.bdf.gz")
94 #t)))))
95 (inputs
96 `(("gettext" ,gettext-minimal)
97
98 ;; Depend on LVM2 for libdevmapper, used by 'grub-probe' and
99 ;; 'grub-install' to recognize mapped devices (LUKS, etc.)
100 ("lvm2" ,lvm2)
101
102 ;; Depend on mdadm, which is invoked by 'grub-probe' and 'grub-install'
103 ;; to determine whether the root file system is RAID.
104 ("mdadm" ,mdadm)
105
106 ("freetype" ,freetype)
107 ;; ("libusb" ,libusb)
108 ;; ("fuse" ,fuse)
109 ("ncurses" ,ncurses)))
110 (native-inputs
111 `(("unifont" ,unifont)
112 ("bison" ,bison)
113 ("flex" ,flex)
114 ("texinfo" ,texinfo)
115 ("help2man" ,help2man)
116
117 ;; Dependencies for the test suite. The "real" QEMU is needed here,
118 ;; because several targets are used.
119 ("parted" ,parted)
120 ("qemu" ,qemu-minimal)
121 ("xorriso" ,xorriso)))
122 (home-page "https://www.gnu.org/software/grub/")
123 (synopsis "GRand Unified Boot loader")
124 (description
125 "GRUB is a multiboot bootloader. It is used for initially loading the
126 kernel of an operating system and then transferring control to it. The kernel
127 then goes on to load the rest of the operating system. As a multiboot
128 bootloader, GRUB handles the presence of multiple operating systems installed
129 on the same computer; upon booting the computer, the user is presented with a
130 menu to select one of the installed operating systems.")
131 (license license:gpl3+)
132 (properties '((cpe-name . "grub2")))))
133
134 (define-public grub-efi
135 (package
136 (inherit grub)
137 (name "grub-efi")
138 (synopsis "GRand Unified Boot loader (UEFI version)")
139 (inputs
140 `(("efibootmgr" ,efibootmgr)
141 ,@(package-inputs grub)))
142 (arguments
143 `(;; TODO: Tests need a UEFI firmware for qemu. There is one at
144 ;; https://github.com/tianocore/edk2/tree/master/OvmfPkg .
145 ;; Search for 'OVMF' in "tests/util/grub-shell.in".
146 #:tests? #f
147 ,@(substitute-keyword-arguments (package-arguments grub)
148 ((#:configure-flags flags ''())
149 `(cons "--with-platform=efi" ,flags))
150 ((#:phases phases)
151 `(modify-phases ,phases
152 (add-after 'patch-stuff 'use-absolute-efibootmgr-path
153 (lambda* (#:key inputs #:allow-other-keys)
154 (substitute* "grub-core/osdep/unix/platform.c"
155 (("efibootmgr")
156 (string-append (assoc-ref inputs "efibootmgr")
157 "/sbin/efibootmgr")))
158 #t)))))))))
159
160 (define-public syslinux
161 (let ((commit "bb41e935cc83c6242de24d2271e067d76af3585c"))
162 (package
163 (name "syslinux")
164 (version (git-version "6.04-pre" "1" commit))
165 (source (origin
166 (method git-fetch)
167 (uri (git-reference
168 (url "https://github.com/geneC/syslinux")
169 (commit commit)))
170 (file-name (git-file-name name version))
171 (sha256
172 (base32
173 "0k8dvafd6410kqxf3kyr4y8jzmpmrih6wbjqg6gklak7945yflrc"))))
174 (build-system gnu-build-system)
175 (native-inputs
176 `(("nasm" ,nasm)
177 ("perl" ,perl)
178 ("python-2" ,python-2)))
179 (inputs
180 `(("libuuid" ,util-linux)))
181 (arguments
182 `(#:parallel-build? #f
183 #:make-flags
184 (list (string-append "BINDIR=" %output "/bin")
185 (string-append "SBINDIR=" %output "/sbin")
186 (string-append "LIBDIR=" %output "/lib")
187 (string-append "INCDIR=" %output "/include")
188 (string-append "DATADIR=" %output "/share")
189 (string-append "MANDIR=" %output "/share/man")
190 "PERL=perl"
191 "bios")
192 #:phases
193 (modify-phases %standard-phases
194 (add-after 'unpack 'patch-files
195 (lambda _
196 (substitute* (find-files "." "Makefile.*|ppmtolss16")
197 (("/bin/pwd") (which "pwd"))
198 (("/bin/echo") (which "echo"))
199 (("/usr/bin/perl") (which "perl")))
200 #t))
201 (delete 'configure)
202 (add-before 'build 'set-permissions
203 (lambda _
204 (zero? (system* "chmod" "a+w" "utils/isohybrid.in"))))
205 (replace 'check
206 (lambda _
207 (setenv "CC" "gcc")
208 (substitute* "tests/unittest/include/unittest/unittest.h"
209 ;; Don't look up headers under /usr.
210 (("/usr/include/") ""))
211 (zero? (system* "make" "unittest")))))))
212 (home-page "http://www.syslinux.org")
213 (synopsis "Lightweight Linux bootloader")
214 (description "Syslinux is a lightweight Linux bootloader.")
215 (license (list license:gpl2+
216 license:bsd-3 ; gnu-efi/*
217 license:bsd-4 ; gnu-efi/inc/* gnu-efi/lib/*
218 ;; Also contains:
219 license:expat license:isc license:zlib)))))
220
221 (define-public dtc
222 (package
223 (name "dtc")
224 (version "1.4.4")
225 (source (origin
226 (method url-fetch)
227 (uri (string-append
228 "mirror://kernel.org/software/utils/dtc/"
229 "dtc-" version ".tar.xz"))
230 (sha256
231 (base32
232 "1yygyvnnpdh241hl90n9p3kxcdvk3jxmsr4ndb961c8mq3ak21s7"))))
233 (build-system gnu-build-system)
234 (native-inputs
235 `(("bison" ,bison)
236 ("flex" ,flex)))
237 (arguments
238 `(#:make-flags
239 (list "CC=gcc"
240 (string-append "PREFIX=" (assoc-ref %outputs "out"))
241 "INSTALL=install")
242 #:phases
243 (modify-phases %standard-phases
244 (delete 'configure))))
245 (home-page "https://www.devicetree.org")
246 (synopsis "Compiles device tree source files")
247 (description "@command{dtc} compiles
248 @uref{http://elinux.org/Device_Tree_Usage, device tree source files} to device
249 tree binary files. These are board description files used by Linux and BSD.")
250 (license license:gpl2+)))
251
252 (define u-boot
253 (package
254 (name "u-boot")
255 (version "2017.03")
256 (source (origin
257 (method url-fetch)
258 (uri (string-append
259 "ftp://ftp.denx.de/pub/u-boot/"
260 "u-boot-" version ".tar.bz2"))
261 (sha256
262 (base32
263 "0gqihplap05dlpwdb971wsqyv01nz2vabwq5g5649gr5jczsyjzm"))))
264 (native-inputs
265 `(("bc" ,bc)
266 ("dtc" ,dtc)
267 ("python-2" ,python-2)))
268 (build-system gnu-build-system)
269 (home-page "http://www.denx.de/wiki/U-Boot/")
270 (synopsis "ARM bootloader")
271 (description "U-Boot is a bootloader used mostly for ARM boards. It
272 also initializes the boards (RAM etc).")
273 (license license:gpl2+)))
274
275 (define (make-u-boot-package board triplet)
276 "Returns a u-boot package for BOARD cross-compiled for TRIPLET."
277 (package
278 (inherit u-boot)
279 (name (string-append "u-boot-" (string-downcase board)))
280 (native-inputs
281 `(("cross-gcc" ,(cross-gcc triplet))
282 ("cross-binutils" ,(cross-binutils triplet))
283 ,@(package-native-inputs u-boot)))
284 (arguments
285 `(#:modules ((ice-9 ftw) (guix build utils) (guix build gnu-build-system))
286 #:test-target "test"
287 #:make-flags
288 (list "HOSTCC=gcc" (string-append "CROSS_COMPILE=" ,triplet "-"))
289 #:phases
290 (modify-phases %standard-phases
291 (replace 'configure
292 (lambda* (#:key outputs make-flags #:allow-other-keys)
293 (let ((config-name (string-append ,board "_defconfig")))
294 (if (file-exists? (string-append "configs/" config-name))
295 (zero? (apply system* "make" `(,@make-flags ,config-name)))
296 (begin
297 (display "Invalid board name. Valid board names are:")
298 (let ((suffix-len (string-length "_defconfig")))
299 (scandir "configs"
300 (lambda (file-name)
301 (when (string-suffix? "_defconfig" file-name)
302 (format #t
303 "- ~A\n"
304 (string-drop-right file-name
305 suffix-len))))))
306 #f)))))
307 (replace 'install
308 (lambda* (#:key outputs make-flags #:allow-other-keys)
309 (let* ((out (assoc-ref outputs "out"))
310 (libexec (string-append out "/libexec"))
311 (uboot-files (find-files "." ".*\\.(bin|efi|spl)$")))
312 (mkdir-p libexec)
313 (for-each
314 (lambda (file)
315 (let ((target-file (string-append libexec "/" file)))
316 (mkdir-p (dirname target-file))
317 (copy-file file target-file)))
318 uboot-files)))))))))
319
320 (define-public u-boot-vexpress
321 (make-u-boot-package "vexpress_ca9x4" "arm-linux-gnueabihf"))
322
323 (define-public u-boot-malta
324 (make-u-boot-package "malta" "mips64el-linux-gnuabi64"))
325
326 (define-public u-boot-beagle-bone-black
327 (make-u-boot-package "am335x_boneblack" "arm-linux-gnueabihf"))