system: Add BeagleBone Black installer.
[jackhill/guix/guix.git] / gnu / bootloader / extlinux.scm
CommitLineData
b09a8da4
MO
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2017 David Craven <david@craven.ch>
3;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
4;;;
5;;; This file is part of GNU Guix.
6;;;
7;;; GNU Guix is free software; you can redistribute it and/or modify it
8;;; under the terms of the GNU General Public License as published by
9;;; the Free Software Foundation; either version 3 of the License, or (at
10;;; your option) any later version.
11;;;
12;;; GNU Guix is distributed in the hope that it will be useful, but
13;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;;; GNU General Public License for more details.
16;;;
17;;; You should have received a copy of the GNU General Public License
18;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19
20(define-module (gnu bootloader extlinux)
21 #:use-module (gnu bootloader)
22 #:use-module (gnu system)
e2248203 23 #:use-module (gnu build bootloader)
b09a8da4
MO
24 #:use-module (gnu packages bootloaders)
25 #:use-module (guix gexp)
26 #:use-module (guix monads)
27 #:use-module (guix records)
28 #:use-module (guix utils)
dbaef95a
MO
29 #:export (extlinux-bootloader
30 extlinux-bootloader-gpt))
b09a8da4
MO
31
32(define* (extlinux-configuration-file config entries
33 #:key
34 (system (%current-system))
35 (old-entries '()))
36 "Return the U-Boot configuration file corresponding to CONFIG, a
37<u-boot-configuration> object, and where the store is available at STORE-FS, a
38<file-system> object. OLD-ENTRIES is taken to be a list of menu entries
39corresponding to old generations of the system."
40
41 (define all-entries
1975c754 42 (append entries (bootloader-configuration-menu-entries config)))
b09a8da4 43
1975c754
DM
44 (define (menu-entry->gexp entry)
45 (let ((label (menu-entry-label entry))
46 (kernel (menu-entry-linux entry))
47 (kernel-arguments (menu-entry-linux-arguments entry))
48 (initrd (menu-entry-initrd entry)))
b09a8da4
MO
49 #~(format port "LABEL ~a
50 MENU LABEL ~a
51 KERNEL ~a
52 FDTDIR ~a/lib/dtbs
53 INITRD ~a
54 APPEND ~a
55~%"
56 #$label #$label
be07cc45 57 #$kernel (dirname #$kernel) #$initrd
b09a8da4
MO
58 (string-join (list #$@kernel-arguments)))))
59
60 (define builder
61 #~(call-with-output-file #$output
62 (lambda (port)
63 (let ((timeout #$(bootloader-configuration-timeout config)))
65efb3c0
MO
64 (format port "# This file was generated from your GuixSD configuration. Any changes
65# will be lost upon reconfiguration.
b09a8da4
MO
66UI menu.c32
67PROMPT ~a
68TIMEOUT ~a~%"
69 (if (> timeout 0) 1 0)
70 ;; timeout is expressed in 1/10s of seconds.
71 (* 10 timeout))
1975c754 72 #$@(map menu-entry->gexp all-entries)
b09a8da4
MO
73
74 #$@(if (pair? old-entries)
75 #~((format port "~%")
1975c754 76 #$@(map menu-entry->gexp old-entries)
b09a8da4
MO
77 (format port "~%"))
78 #~())))))
79
80 (gexp->derivation "extlinux.conf" builder))
81
82
83\f
84
85;;;
86;;; Install procedures.
87;;;
88
dbaef95a 89(define (install-extlinux mbr)
b09a8da4
MO
90 #~(lambda (bootloader device mount-point)
91 (let ((extlinux (string-append bootloader "/sbin/extlinux"))
92 (install-dir (string-append mount-point "/boot/extlinux"))
93 (syslinux-dir (string-append bootloader "/share/syslinux")))
94 (for-each (lambda (file)
95 (install-file file install-dir))
96 (find-files syslinux-dir "\\.c32$"))
4307397b
MO
97 (unless
98 (and (zero? (system* extlinux "--install" install-dir))
e2248203
MO
99 (write-file-on-device
100 (string-append syslinux-dir "/" #$mbr) 440 device 0))
b09a8da4
MO
101 (error "failed to install SYSLINUX")))))
102
dbaef95a
MO
103(define install-extlinux-mbr
104 (install-extlinux "mbr.bin"))
105
106(define install-extlinux-gpt
107 (install-extlinux "gptmbr.bin"))
108
b09a8da4
MO
109\f
110
111;;;
112;;; Bootloader definitions.
113;;;
114
115(define extlinux-bootloader
116 (bootloader
117 (name 'extlinux)
118 (package syslinux)
dbaef95a 119 (installer install-extlinux-mbr)
b09a8da4
MO
120 (configuration-file "/boot/extlinux/extlinux.conf")
121 (configuration-file-generator extlinux-configuration-file)))
dbaef95a
MO
122
123(define extlinux-bootloader-gpt
124 (bootloader
125 (inherit extlinux-bootloader)
126 (installer install-extlinux-gpt)))