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