extlinux.scm 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. ;;; Copyright © 2022 Reza Alizadeh Majd <r.majd@pantherx.org>
  5. ;;;
  6. ;;; This file is part of GNU Guix.
  7. ;;;
  8. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  9. ;;; under the terms of the GNU General Public License as published by
  10. ;;; the Free Software Foundation; either version 3 of the License, or (at
  11. ;;; your option) any later version.
  12. ;;;
  13. ;;; GNU Guix is distributed in the hope that it will be useful, but
  14. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;;; GNU General Public License for more details.
  17. ;;;
  18. ;;; You should have received a copy of the GNU General Public License
  19. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  20. (define-module (gnu bootloader extlinux)
  21. #:use-module (gnu bootloader)
  22. #:use-module (gnu packages bootloaders)
  23. #:use-module (guix gexp)
  24. #:use-module (guix utils)
  25. #:export (extlinux-bootloader
  26. extlinux-bootloader-gpt))
  27. (define* (extlinux-configuration-file config entries
  28. #:key
  29. (system (%current-system))
  30. (old-entries '())
  31. #:allow-other-keys)
  32. "Return the U-Boot configuration file corresponding to CONFIG, a
  33. <u-boot-configuration> object, and where the store is available at STORE-FS, a
  34. <file-system> object. OLD-ENTRIES is taken to be a list of menu entries
  35. corresponding to old generations of the system."
  36. (define all-entries
  37. (append entries (bootloader-configuration-menu-entries config)))
  38. (define with-fdtdir?
  39. (bootloader-configuration-device-tree-support? config))
  40. (define (menu-entry->gexp entry)
  41. (let ((label (menu-entry-label entry))
  42. (kernel (menu-entry-linux entry))
  43. (kernel-arguments (menu-entry-linux-arguments entry))
  44. (initrd (menu-entry-initrd entry)))
  45. #~(format port "LABEL ~a
  46. MENU LABEL ~a
  47. KERNEL ~a
  48. ~a
  49. INITRD ~a
  50. APPEND ~a
  51. ~%"
  52. #$label #$label
  53. #$kernel
  54. (if #$with-fdtdir?
  55. (string-append "FDTDIR " (dirname #$kernel) "/lib/dtbs")
  56. "")
  57. #$initrd
  58. (string-join (list #$@kernel-arguments)))))
  59. (define builder
  60. #~(call-with-output-file #$output
  61. (lambda (port)
  62. (let ((timeout #$(bootloader-configuration-timeout config)))
  63. (format port "# This file was generated from your Guix configuration. Any changes
  64. # will be lost upon reconfiguration.
  65. UI menu.c32
  66. MENU TITLE GNU Guix Boot Options
  67. PROMPT ~a
  68. TIMEOUT ~a~%"
  69. (if (> timeout 0) 1 0)
  70. ;; timeout is expressed in 1/10s of seconds.
  71. (* 10 timeout))
  72. #$@(map menu-entry->gexp all-entries)
  73. #$@(if (pair? old-entries)
  74. #~((format port "~%")
  75. #$@(map menu-entry->gexp old-entries)
  76. (format port "~%"))
  77. #~())))))
  78. (computed-file "extlinux.conf" builder
  79. #:options '(#:local-build? #t
  80. #:substitutable? #f)))
  81. ;;;
  82. ;;; Install procedures.
  83. ;;;
  84. (define (install-extlinux mbr)
  85. #~(lambda (bootloader device mount-point)
  86. (let ((extlinux (string-append bootloader "/sbin/extlinux"))
  87. (install-dir (string-append mount-point "/boot/extlinux"))
  88. (syslinux-dir (string-append bootloader "/share/syslinux")))
  89. (for-each (lambda (file)
  90. (install-file file install-dir))
  91. (find-files syslinux-dir "\\.c32$"))
  92. (invoke/quiet extlinux "--install" install-dir)
  93. (write-file-on-device (string-append syslinux-dir "/" #$mbr)
  94. 440 device 0))))
  95. (define install-extlinux-mbr
  96. (install-extlinux "mbr.bin"))
  97. (define install-extlinux-gpt
  98. (install-extlinux "gptmbr.bin"))
  99. ;;;
  100. ;;; Bootloader definitions.
  101. ;;;
  102. (define extlinux-bootloader
  103. (bootloader
  104. (name 'extlinux)
  105. (package syslinux)
  106. (installer install-extlinux-mbr)
  107. (configuration-file "/boot/extlinux/extlinux.conf")
  108. (configuration-file-generator extlinux-configuration-file)))
  109. (define extlinux-bootloader-gpt
  110. (bootloader
  111. (inherit extlinux-bootloader)
  112. (installer install-extlinux-gpt)))