summaryrefslogtreecommitdiff
path: root/gnu/bootloader/extlinux.scm
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/bootloader/extlinux.scm')
-rw-r--r--gnu/bootloader/extlinux.scm123
1 files changed, 123 insertions, 0 deletions
diff --git a/gnu/bootloader/extlinux.scm b/gnu/bootloader/extlinux.scm
new file mode 100644
index 00000000000..a0020010718
--- /dev/null
+++ b/gnu/bootloader/extlinux.scm
@@ -0,0 +1,123 @@
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)
23 #:use-module (gnu packages bootloaders)
24 #:use-module (guix gexp)
25 #:use-module (guix monads)
26 #:use-module (guix records)
27 #:use-module (guix utils)
28 #:export (extlinux-bootloader
29 syslinux-bootloader
30
31 extlinux-configuration
32 syslinux-configuration))
33
34(define* (extlinux-configuration-file config entries
35 #:key
36 (system (%current-system))
37 (old-entries '()))
38 "Return the U-Boot configuration file corresponding to CONFIG, a
39<u-boot-configuration> object, and where the store is available at STORE-FS, a
40<file-system> object. OLD-ENTRIES is taken to be a list of menu entries
41corresponding to old generations of the system."
42
43 (define all-entries
44 (append entries (bootloader-configuration-menu-entries config)))
45
46 (define (boot-parameters->gexp params)
47 (let ((label (boot-parameters-label params))
48 (kernel (boot-parameters-kernel params))
49 (kernel-arguments (boot-parameters-kernel-arguments params))
50 (initrd (boot-parameters-initrd params)))
51 #~(format port "LABEL ~a
52 MENU LABEL ~a
53 KERNEL ~a
54 FDTDIR ~a/lib/dtbs
55 INITRD ~a
56 APPEND ~a
57~%"
58 #$label #$label
59 #$kernel #$kernel #$initrd
60 (string-join (list #$@kernel-arguments)))))
61
62 (define builder
63 #~(call-with-output-file #$output
64 (lambda (port)
65 (let ((timeout #$(bootloader-configuration-timeout config)))
66 (format port "
67UI menu.c32
68PROMPT ~a
69TIMEOUT ~a~%"
70 (if (> timeout 0) 1 0)
71 ;; timeout is expressed in 1/10s of seconds.
72 (* 10 timeout))
73 #$@(map boot-parameters->gexp all-entries)
74
75 #$@(if (pair? old-entries)
76 #~((format port "~%")
77 #$@(map boot-parameters->gexp old-entries)
78 (format port "~%"))
79 #~())))))
80
81 (gexp->derivation "extlinux.conf" builder))
82
83
84
85
86;;;
87;;; Install procedures.
88;;;
89
90(define dd
91 #~(lambda (bs count if of)
92 (zero? (system* "dd"
93 (string-append "bs=" (number->string bs))
94 (string-append "count=" (number->string count))
95 (string-append "if=" if)
96 (string-append "of=" of)))))
97
98(define install-extlinux
99 #~(lambda (bootloader device mount-point)
100 (let ((extlinux (string-append bootloader "/sbin/extlinux"))
101 (install-dir (string-append mount-point "/boot/extlinux"))
102 (syslinux-dir (string-append bootloader "/share/syslinux")))
103 (for-each (lambda (file)
104 (install-file file install-dir))
105 (find-files syslinux-dir "\\.c32$"))
106
107 (unless (and (zero? (system* extlinux "--install" install-dir))
108 (#$dd 440 1 (string-append syslinux-dir "/mbr.bin") device))
109 (error "failed to install SYSLINUX")))))
110
111
112
113;;;
114;;; Bootloader definitions.
115;;;
116
117(define extlinux-bootloader
118 (bootloader
119 (name 'extlinux)
120 (package syslinux)
121 (installer install-extlinux)
122 (configuration-file "/boot/extlinux/extlinux.conf")
123 (configuration-file-generator extlinux-configuration-file)))