bootloaders.scm 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2021 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2015, 2018 Mark H Weaver <mhw@netris.org>
  4. ;;; Copyright © 2015 Leo Famulari <leo@famulari.name>
  5. ;;; Copyright © 2016, 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
  6. ;;; Copyright © 2016, 2017, 2018, 2021 Marius Bakke <marius@gnu.org>
  7. ;;; Copyright © 2016, 2017 Danny Milosavljevic <dannym@scratchpost.org>
  8. ;;; Copyright © 2016, 2017 David Craven <david@craven.ch>
  9. ;;; Copyright © 2017, 2018, 2020, 2021, 2022 Efraim Flashner <efraim@flashner.co.il>
  10. ;;; Copyright © 2018, 2019, 2020, 2021 Tobias Geerinckx-Rice <me@tobias.gr>
  11. ;;; Copyright © 2019 nee <nee@cock.li>
  12. ;;; Copyright © 2019 Mathieu Othacehe <m.othacehe@gmail.com>
  13. ;;; Copyright © 2020 Björn Höfling <bjoern.hoefling@bjoernhoefling.de>
  14. ;;; Copyright © 2018, 2019, 2020 Vagrant Cascadian <vagrant@debian.org>
  15. ;;; Copyright © 2020, 2021 Pierre Langlois <pierre.langlois@gmx.com>
  16. ;;; Copyright © 2021 Vincent Legoll <vincent.legoll@gmail.com>
  17. ;;; Copyright © 2021 Brice Waegeneire <brice@waegenei.re>
  18. ;;;
  19. ;;; This file is part of GNU Guix.
  20. ;;;
  21. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  22. ;;; under the terms of the GNU General Public License as published by
  23. ;;; the Free Software Foundation; either version 3 of the License, or (at
  24. ;;; your option) any later version.
  25. ;;;
  26. ;;; GNU Guix is distributed in the hope that it will be useful, but
  27. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  28. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  29. ;;; GNU General Public License for more details.
  30. ;;;
  31. ;;; You should have received a copy of the GNU General Public License
  32. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  33. (define-module (gnu packages bootloaders)
  34. #:use-module (gnu packages)
  35. #:use-module (gnu packages admin)
  36. #:use-module (gnu packages algebra)
  37. #:use-module (gnu packages assembly)
  38. #:use-module (gnu packages base)
  39. #:use-module (gnu packages disk)
  40. #:use-module (gnu packages bison)
  41. #:use-module (gnu packages cdrom)
  42. #:use-module (gnu packages check)
  43. #:use-module (gnu packages compression)
  44. #:use-module (gnu packages cross-base)
  45. #:use-module (gnu packages disk)
  46. #:use-module (gnu packages firmware)
  47. #:use-module (gnu packages flex)
  48. #:use-module (gnu packages fontutils)
  49. #:use-module (gnu packages gcc)
  50. #:use-module (gnu packages gettext)
  51. #:use-module (gnu packages linux)
  52. #:use-module (gnu packages man)
  53. #:use-module (gnu packages mtools)
  54. #:use-module (gnu packages ncurses)
  55. #:use-module (gnu packages perl)
  56. #:use-module (gnu packages pkg-config)
  57. #:use-module (gnu packages python)
  58. #:use-module (gnu packages python-crypto)
  59. #:use-module (gnu packages texinfo)
  60. #:use-module (gnu packages tls)
  61. #:use-module (gnu packages sdl)
  62. #:use-module (gnu packages serialization)
  63. #:use-module (gnu packages swig)
  64. #:use-module (gnu packages valgrind)
  65. #:use-module (gnu packages virtualization)
  66. #:use-module (gnu packages xorg)
  67. #:use-module (guix build-system gnu)
  68. #:use-module (guix download)
  69. #:use-module (guix git-download)
  70. #:use-module ((guix licenses) #:prefix license:)
  71. #:use-module (guix packages)
  72. #:use-module (guix utils)
  73. #:use-module (srfi srfi-1)
  74. #:use-module (srfi srfi-26)
  75. #:use-module (ice-9 regex))
  76. (define unifont
  77. ;; GNU Unifont, <http://gnu.org/s/unifont>.
  78. ;; GRUB needs it for its graphical terminal, gfxterm.
  79. (origin
  80. (method url-fetch)
  81. (uri
  82. "http://unifoundry.com/pub/unifont-7.0.06/font-builds/unifont-7.0.06.bdf.gz")
  83. (sha256
  84. (base32
  85. "0p2vhnc18cnbmb39vq4m7hzv4mhnm2l0a2s7gx3ar277fwng3hys"))))
  86. (define-public grub
  87. (package
  88. (name "grub")
  89. (version "2.06")
  90. (source (origin
  91. (method url-fetch)
  92. (uri (string-append "mirror://gnu/grub/grub-" version ".tar.xz"))
  93. (sha256
  94. (base32
  95. "1qbycnxkx07arj9f2nlsi9kp0dyldspbv07ysdyd34qvz55a97mp"))
  96. (patches (search-patches
  97. "grub-efi-fat-serial-number.patch"
  98. "grub-setup-root.patch"))
  99. (modules '((guix build utils)))
  100. (snippet
  101. '(begin
  102. ;; Adjust QEMU invocation to not use a deprecated device
  103. ;; name that was removed in QEMU 6.0. Remove for >2.06.
  104. (substitute* "tests/ahci_test.in"
  105. (("ide-drive")
  106. "ide-hd"))))))
  107. (build-system gnu-build-system)
  108. (arguments
  109. `(#:configure-flags
  110. ;; Counterintuitively, this *disables* a spurious Python dependency by
  111. ;; calling the ‘true’ binary instead. Python is only needed during
  112. ;; bootstrapping (for genptl.py), not when building from a release.
  113. (list "PYTHON=true")
  114. ;; Grub fails to load modules stripped with --strip-unneeded.
  115. #:strip-flags '("--strip-debug" "--enable-deterministic-archives")
  116. #:phases (modify-phases %standard-phases
  117. (add-after 'unpack 'patch-stuff
  118. (lambda* (#:key native-inputs inputs #:allow-other-keys)
  119. (substitute* "grub-core/Makefile.in"
  120. (("/bin/sh") (which "sh")))
  121. ;; Give the absolute file name of 'mdadm', used to
  122. ;; determine the root file system when it's a RAID
  123. ;; device. Failing to do that, 'grub-probe' silently
  124. ;; fails if 'mdadm' is not in $PATH.
  125. (when (assoc-ref inputs "mdadm")
  126. (substitute* "grub-core/osdep/linux/getroot.c"
  127. (("argv\\[0\\] = \"mdadm\"")
  128. (string-append "argv[0] = \""
  129. (assoc-ref inputs "mdadm")
  130. "/sbin/mdadm\""))))
  131. ;; Make the font visible.
  132. (copy-file (assoc-ref (or native-inputs inputs)
  133. "unifont")
  134. "unifont.bdf.gz")
  135. (system* "gunzip" "unifont.bdf.gz")
  136. ;; Give the absolute file name of 'ckbcomp'.
  137. (substitute* "util/grub-kbdcomp.in"
  138. (("^ckbcomp ")
  139. (string-append
  140. (search-input-file inputs "/bin/ckbcomp")
  141. " ")))))
  142. (add-after 'unpack 'set-freetype-variables
  143. ;; These variables need to be set to the native versions
  144. ;; of the dependencies because they are used to build
  145. ;; programs which are executed during build time.
  146. (lambda* (#:key native-inputs #:allow-other-keys)
  147. (when (assoc-ref native-inputs "freetype")
  148. (let ((freetype (assoc-ref native-inputs "freetype")))
  149. (setenv "BUILD_FREETYPE_LIBS"
  150. (string-append "-L" freetype
  151. "/lib -lfreetype"))
  152. (setenv "BUILD_FREETYPE_CFLAGS"
  153. (string-append "-I" freetype
  154. "/include/freetype2"))))
  155. #t))
  156. (add-before 'check 'disable-flaky-test
  157. (lambda _
  158. ;; This test is unreliable. For more information, see:
  159. ;; <https://bugs.gnu.org/26936>.
  160. (substitute* "Makefile.in"
  161. (("grub_cmd_date grub_cmd_set_date grub_cmd_sleep")
  162. "grub_cmd_date grub_cmd_sleep"))
  163. #t))
  164. (add-before 'check 'disable-pixel-perfect-test
  165. (lambda _
  166. ;; This test compares many screenshots rendered with an
  167. ;; older Unifont (9.0.06) than that packaged in Guix.
  168. (substitute* "Makefile.in"
  169. (("test_unset grub_func_test")
  170. "test_unset"))
  171. #t)))
  172. ;; Disable tests on ARM and AARCH64 platforms or when cross-compiling.
  173. #:tests? ,(not (or (any (cute string-prefix? <> (or (%current-target-system)
  174. (%current-system)))
  175. '("arm" "aarch64"))
  176. (%current-target-system)))))
  177. (inputs
  178. `(("gettext" ,gettext-minimal)
  179. ;; Depend on LVM2 for libdevmapper, used by 'grub-probe' and
  180. ;; 'grub-install' to recognize mapped devices (LUKS, etc.)
  181. ,@(if (member (or (%current-target-system)
  182. (%current-system))
  183. (package-supported-systems lvm2))
  184. `(("lvm2" ,lvm2))
  185. '())
  186. ;; Depend on mdadm, which is invoked by 'grub-probe' and 'grub-install'
  187. ;; to determine whether the root file system is RAID.
  188. ,@(if (member (or (%current-target-system)
  189. (%current-system))
  190. (package-supported-systems mdadm))
  191. `(("mdadm" ,mdadm))
  192. '())
  193. ;; Console-setup's ckbcomp is invoked by grub-kbdcomp. It is required
  194. ;; for generating alternative keyboard layouts.
  195. ("console-setup" ,console-setup)
  196. ;; Needed for ‘grub-mount’, the only reliable way to tell whether a given
  197. ;; file system will be readable by GRUB without rebooting.
  198. ,@(if (member (or (%current-target-system)
  199. (%current-system))
  200. (package-supported-systems fuse))
  201. `(("fuse" ,fuse))
  202. '())
  203. ("freetype" ,freetype)
  204. ;; ("libusb" ,libusb)
  205. ("ncurses" ,ncurses)))
  206. (native-inputs
  207. `(("pkg-config" ,pkg-config)
  208. ("unifont" ,unifont)
  209. ("bison" ,bison)
  210. ("flex" ,flex)
  211. ("texinfo" ,texinfo)
  212. ("help2man" ,help2man)
  213. ("freetype" ,freetype) ; native version needed for build-grub-mkfont
  214. ;; XXX: When building GRUB 2.02 on 32-bit x86, we need a binutils
  215. ;; capable of assembling 64-bit instructions. However, our default
  216. ;; binutils on 32-bit x86 is not 64-bit capable.
  217. ,@(if (string-match "^i[3456]86-" (%current-system))
  218. (let ((binutils (package/inherit
  219. binutils
  220. (name "binutils-i386")
  221. (arguments
  222. (substitute-keyword-arguments (package-arguments binutils)
  223. ((#:configure-flags flags ''())
  224. `(cons "--enable-64-bit-bfd" ,flags)))))))
  225. `(("ld-wrapper" ,(make-ld-wrapper "ld-wrapper-i386"
  226. #:binutils binutils))
  227. ("binutils" ,binutils)))
  228. '())
  229. ;; Dependencies for the test suite. The "real" QEMU is needed here,
  230. ;; because several targets are used.
  231. ("parted" ,parted)
  232. ,@(if (member (%current-system) (package-supported-systems qemu-minimal))
  233. `(("qemu" ,qemu-minimal))
  234. '())
  235. ("xorriso" ,xorriso)))
  236. (home-page "https://www.gnu.org/software/grub/")
  237. (synopsis "GRand Unified Boot loader")
  238. (description
  239. "GRUB is a multiboot bootloader. It is used for initially loading the
  240. kernel of an operating system and then transferring control to it. The kernel
  241. then goes on to load the rest of the operating system. As a multiboot
  242. bootloader, GRUB handles the presence of multiple operating systems installed
  243. on the same computer; upon booting the computer, the user is presented with a
  244. menu to select one of the installed operating systems.")
  245. (license license:gpl3+)
  246. (properties '((cpe-name . "grub2")))))
  247. (define-public grub-minimal
  248. (package
  249. (inherit grub)
  250. (name "grub-minimal")
  251. (inputs
  252. (modify-inputs (package-inputs grub)
  253. (delete "lvm2" "mdadm" "fuse" "console-setup")))
  254. (native-inputs
  255. (modify-inputs (package-native-inputs grub)
  256. (delete "help2man" "texinfo" "parted" "qemu" "xorriso")))
  257. (arguments
  258. (substitute-keyword-arguments (package-arguments grub)
  259. ((#:configure-flags _ ''())
  260. '(list "PYTHON=true"))
  261. ((#:tests? _ #t)
  262. #f)
  263. ((#:phases phases '%standard-phases)
  264. `(modify-phases ,phases
  265. (replace 'patch-stuff
  266. (lambda* (#:key native-inputs inputs #:allow-other-keys)
  267. (substitute* "grub-core/Makefile.in"
  268. (("/bin/sh") (which "sh")))
  269. ;; Make the font visible.
  270. (copy-file (assoc-ref (or native-inputs inputs)
  271. "unifont")
  272. "unifont.bdf.gz")
  273. (system* "gunzip" "unifont.bdf.gz")
  274. #t))))))))
  275. (define-public grub-efi
  276. (package
  277. (inherit grub)
  278. (name "grub-efi")
  279. (synopsis "GRand Unified Boot loader (UEFI version)")
  280. (inputs
  281. (modify-inputs (package-inputs grub)
  282. (prepend efibootmgr mtools)))
  283. (arguments
  284. `(;; TODO: Tests need a UEFI firmware for qemu. There is one at
  285. ;; https://github.com/tianocore/edk2/tree/master/OvmfPkg .
  286. ;; Search for 'OVMF' in "tests/util/grub-shell.in".
  287. ,@(substitute-keyword-arguments (package-arguments grub)
  288. ((#:tests? _ #f) #f)
  289. ((#:configure-flags flags ''())
  290. `(cons* "--with-platform=efi"
  291. ,@(if (string-prefix? "x86_64"
  292. (or (%current-target-system)
  293. (%current-system)))
  294. '("--enable-stack-protector") ; EFI-only for now
  295. '())
  296. ,flags))
  297. ((#:phases phases)
  298. `(modify-phases ,phases
  299. (add-after 'patch-stuff 'use-absolute-efibootmgr-path
  300. (lambda* (#:key inputs #:allow-other-keys)
  301. (substitute* "grub-core/osdep/unix/platform.c"
  302. (("efibootmgr")
  303. (search-input-file inputs
  304. "/sbin/efibootmgr")))))
  305. (add-after 'patch-stuff 'use-absolute-mtools-path
  306. (lambda* (#:key inputs #:allow-other-keys)
  307. (let ((mtools (assoc-ref inputs "mtools")))
  308. (substitute* "util/grub-mkrescue.c"
  309. (("\"mformat\"")
  310. (string-append "\"" mtools
  311. "/bin/mformat\"")))
  312. (substitute* "util/grub-mkrescue.c"
  313. (("\"mcopy\"")
  314. (string-append "\"" mtools
  315. "/bin/mcopy\"")))
  316. #t))))))))))
  317. ;; Because grub searches hardcoded paths it's easiest to just build grub
  318. ;; again to make it find both grub-pc and grub-efi. There is a command
  319. ;; line argument which allows you to specify ONE platform - but
  320. ;; grub-mkrescue will use multiple platforms if they are available
  321. ;; in the installation directory (without command line argument).
  322. (define-public grub-hybrid
  323. (package
  324. (inherit grub-efi)
  325. (name "grub-hybrid")
  326. (synopsis "GRand Unified Boot loader (hybrid version)")
  327. (inputs
  328. (modify-inputs (package-inputs grub-efi)
  329. (prepend grub)))
  330. (arguments
  331. (substitute-keyword-arguments (package-arguments grub-efi)
  332. ((#:modules modules `((guix build utils) (guix build gnu-build-system)))
  333. `((ice-9 ftw) ,@modules))
  334. ((#:phases phases)
  335. `(modify-phases ,phases
  336. (add-after 'install 'install-non-efi
  337. (lambda* (#:key inputs outputs #:allow-other-keys)
  338. (let ((input-dir (search-input-directory inputs
  339. "/lib/grub"))
  340. (output-dir (string-append (assoc-ref outputs "out")
  341. "/lib/grub")))
  342. (for-each
  343. (lambda (basename)
  344. (if (not (or (string-prefix? "." basename)
  345. (file-exists? (string-append output-dir "/" basename))))
  346. (symlink (string-append input-dir "/" basename)
  347. (string-append output-dir "/" basename))))
  348. (scandir input-dir))
  349. #t)))))))))
  350. (define-public syslinux
  351. (let ((commit "bb41e935cc83c6242de24d2271e067d76af3585c"))
  352. (package
  353. (name "syslinux")
  354. (version (git-version "6.04-pre" "1" commit))
  355. (source (origin
  356. (method git-fetch)
  357. (uri (git-reference
  358. (url "https://github.com/geneC/syslinux")
  359. (commit commit)))
  360. (file-name (git-file-name name version))
  361. (sha256
  362. (base32
  363. "0k8dvafd6410kqxf3kyr4y8jzmpmrih6wbjqg6gklak7945yflrc"))
  364. (patches
  365. (search-patches "syslinux-gcc10.patch"
  366. "syslinux-strip-gnu-property.patch"))))
  367. (build-system gnu-build-system)
  368. (native-inputs
  369. `(("nasm" ,nasm)
  370. ("perl" ,perl)
  371. ("python-2" ,python-2)))
  372. (inputs
  373. `(("libuuid" ,util-linux "lib")
  374. ("mtools" ,mtools)))
  375. (arguments
  376. `(#:parallel-build? #f
  377. #:make-flags
  378. (list (string-append "BINDIR=" %output "/bin")
  379. (string-append "SBINDIR=" %output "/sbin")
  380. (string-append "LIBDIR=" %output "/lib")
  381. (string-append "INCDIR=" %output "/include")
  382. (string-append "DATADIR=" %output "/share")
  383. (string-append "MANDIR=" %output "/share/man")
  384. "PERL=perl"
  385. "bios")
  386. #:strip-flags '("--strip-debug" "--enable-deterministic-archives")
  387. #:phases
  388. (modify-phases %standard-phases
  389. (add-after 'unpack 'patch-files
  390. (lambda* (#:key inputs #:allow-other-keys)
  391. (substitute* (find-files "." "Makefile.*|ppmtolss16")
  392. (("/bin/pwd") (which "pwd"))
  393. (("/bin/echo") (which "echo"))
  394. (("/usr/bin/perl") (which "perl")))
  395. (let ((mtools (assoc-ref inputs "mtools")))
  396. (substitute* (find-files "." "\\.c$")
  397. (("mcopy")
  398. (string-append mtools "/bin/mcopy"))
  399. (("mattrib")
  400. (string-append mtools "/bin/mattrib"))))
  401. #t))
  402. (delete 'configure)
  403. (add-before 'build 'set-permissions
  404. (lambda _
  405. (invoke "chmod" "a+w" "utils/isohybrid.in")))
  406. (replace 'check
  407. (lambda _
  408. (setenv "CC" "gcc")
  409. (substitute* "tests/unittest/include/unittest/unittest.h"
  410. ;; Don't look up headers under /usr.
  411. (("/usr/include/") ""))
  412. (invoke "make" "unittest"))))))
  413. (home-page "https://www.syslinux.org")
  414. (synopsis "Lightweight Linux bootloader")
  415. (description "Syslinux is a lightweight Linux bootloader.")
  416. ;; The Makefile specifically targets i386 and x86_64 using nasm.
  417. (supported-systems '("i686-linux" "x86_64-linux"))
  418. (license (list license:gpl2+
  419. license:bsd-3 ; gnu-efi/*
  420. license:bsd-4 ; gnu-efi/inc/* gnu-efi/lib/*
  421. ;; Also contains:
  422. license:expat license:isc license:zlib)))))
  423. (define-public dtc
  424. (package
  425. (name "dtc")
  426. (version "1.6.1")
  427. (source (origin
  428. (method url-fetch)
  429. (uri (string-append
  430. "mirror://kernel.org/software/utils/dtc/"
  431. "dtc-" version ".tar.gz"))
  432. (sha256
  433. (base32
  434. "0xm38h31jb29xfh2sfyk48d8wdfq4b8lmb412zx9vjr35izjb9iq"))))
  435. (build-system gnu-build-system)
  436. (native-inputs
  437. (append
  438. (list bison
  439. flex
  440. libyaml
  441. pkg-config
  442. swig)
  443. (if (member (%current-system) (package-supported-systems valgrind))
  444. (list valgrind)
  445. '())))
  446. (inputs
  447. (list python))
  448. (arguments
  449. `(#:make-flags
  450. (list (string-append "CC=" ,(cc-for-target))
  451. ;; /bin/fdt{get,overlay,put} need help finding libfdt.so.1.
  452. (string-append "LDFLAGS=-Wl,-rpath="
  453. (assoc-ref %outputs "out") "/lib")
  454. (string-append "PREFIX=" (assoc-ref %outputs "out"))
  455. (string-append "SETUP_PREFIX=" (assoc-ref %outputs "out"))
  456. "INSTALL=install")
  457. #:phases
  458. (modify-phases %standard-phases
  459. (add-after 'unpack 'patch-pkg-config
  460. (lambda _
  461. (substitute* '("Makefile"
  462. "tests/run_tests.sh")
  463. (("pkg-config")
  464. ,(pkg-config-for-target)))))
  465. (delete 'configure)))) ; no configure script
  466. (home-page "https://www.devicetree.org")
  467. (synopsis "Compiles device tree source files")
  468. (description "@command{dtc} compiles
  469. @uref{http://elinux.org/Device_Tree_Usage, device tree source files} to device
  470. tree binary files. These are board description files used by Linux and BSD.")
  471. (license license:gpl2+)))
  472. (define %u-boot-rockchip-inno-usb-patch
  473. ;; Fix regression in 2020.10 causing freezes on boot with USB boot enabled.
  474. ;; See https://gitlab.manjaro.org/manjaro-arm/packages/core/uboot-rockpro64/-/issues/4
  475. ;; and https://patchwork.ozlabs.org/project/uboot/patch/20210406151059.1187379-1-icenowy@aosc.io
  476. (search-patch "u-boot-rockchip-inno-usb.patch"))
  477. (define %u-boot-sifive-prevent-relocating-initrd-fdt
  478. ;; Fix boot in 2021.07 on Hifive unmatched, see
  479. ;; https://bugs.launchpad.net/ubuntu/+source/u-boot/+bug/1937246
  480. (search-patch "u-boot-sifive-prevent-reloc-initrd-fdt.patch"))
  481. (define %u-boot-allow-disabling-openssl-patch
  482. ;; Fixes build of u-boot 2021.10 without openssl
  483. ;; https://lists.denx.de/pipermail/u-boot/2021-October/462728.html
  484. (search-patch "u-boot-allow-disabling-openssl.patch"))
  485. (define %u-boot-rk3399-enable-emmc-phy-patch
  486. ;; Fix emmc boot on rockpro64 and pinebook-pro, this was a regression
  487. ;; therefore should hopefully be fixed when updating u-boot.
  488. ;; https://lists.denx.de/pipermail/u-boot/2021-November/466329.html
  489. (search-patch "u-boot-rk3399-enable-emmc-phy.patch"))
  490. (define u-boot
  491. (package
  492. (name "u-boot")
  493. (version "2021.10")
  494. (source (origin
  495. (patches
  496. (list %u-boot-rockchip-inno-usb-patch
  497. %u-boot-allow-disabling-openssl-patch
  498. %u-boot-sifive-prevent-relocating-initrd-fdt
  499. %u-boot-rk3399-enable-emmc-phy-patch))
  500. (method url-fetch)
  501. (uri (string-append
  502. "https://ftp.denx.de/pub/u-boot/"
  503. "u-boot-" version ".tar.bz2"))
  504. (sha256
  505. (base32
  506. "1m0bvwv8r62s4wk4w3cmvs888dhv9gnfa98dczr4drk2jbhj7ryd"))))
  507. (native-inputs
  508. `(("bc" ,bc)
  509. ("bison" ,bison)
  510. ("dtc" ,dtc)
  511. ("flex" ,flex)
  512. ("lz4" ,lz4)
  513. ("perl" ,perl)
  514. ("python" ,python)
  515. ("python-coverage" ,python-coverage)
  516. ("python-pycryptodomex" ,python-pycryptodomex)
  517. ("python-pytest" ,python-pytest)
  518. ("swig" ,swig)))
  519. (build-system gnu-build-system)
  520. (home-page "https://www.denx.de/wiki/U-Boot/")
  521. (synopsis "ARM bootloader")
  522. (description "U-Boot is a bootloader used mostly for ARM boards. It
  523. also initializes the boards (RAM etc).")
  524. (license license:gpl2+)))
  525. (define-public u-boot-tools
  526. (package
  527. (inherit u-boot)
  528. (name "u-boot-tools")
  529. (native-inputs
  530. (modify-inputs (package-native-inputs u-boot)
  531. (prepend sdl2)))
  532. (arguments
  533. `(#:make-flags '("HOSTCC=gcc")
  534. #:test-target "tcheck"
  535. #:phases
  536. (modify-phases %standard-phases
  537. (add-after 'unpack 'patch
  538. (lambda* (#:key inputs #:allow-other-keys)
  539. (substitute* "Makefile"
  540. (("/bin/pwd") (which "pwd"))
  541. (("/bin/false") (which "false")))
  542. (substitute* "tools/dtoc/fdt_util.py"
  543. (("'cc'") "'gcc'"))
  544. (substitute* "tools/patman/test_util.py"
  545. ;; python3-coverage is simply called coverage in guix.
  546. (("python3-coverage") "coverage"))
  547. (substitute* "test/run"
  548. ;; Make it easier to find test failures.
  549. (("#!/bin/bash") "#!/bin/bash -x")
  550. ;; This test would require git.
  551. (("\\./tools/patman/patman") (which "true"))
  552. ;; FIXME: test fails, needs further investiation
  553. (("run_test \"binman\"") "# run_test \"binman\"")
  554. ;; FIXME: test_spl fails, needs further investiation
  555. (("test_ofplatdata or test_handoff or test_spl")
  556. "test_ofplatdata or test_handoff")
  557. ;; FIXME: code coverage not working
  558. (("run_test \"binman code coverage\"")
  559. "# run_test \"binman code coverage\"")
  560. ;; This test would require internet access.
  561. (("\\./tools/buildman/buildman") (which "true")))
  562. (substitute* "test/py/tests/test_sandbox_exit.py"
  563. (("def test_ctrl_c")
  564. "@pytest.mark.skip(reason='Guix has problems with SIGINT')
  565. def test_ctrl_c"))
  566. ;; Test against the tools being installed rather than tools built
  567. ;; for "sandbox" target.
  568. (substitute* "test/image/test-imagetools.sh"
  569. (("BASEDIR=sandbox") "BASEDIR=."))
  570. (for-each (lambda (file)
  571. (substitute* file
  572. ;; Disable features that require OpenSSL due
  573. ;; to GPL/Openssl license incompatibilities.
  574. ;; See https://bugs.gnu.org/34717 for
  575. ;; details.
  576. (("CONFIG_FIT_SIGNATURE=y")
  577. "CONFIG_FIT_SIGNATURE=n\nCONFIG_UT_LIB_ASN1=n\nCONFIG_TOOLS_LIBCRYPTO=n")
  578. ;; This test requires a sound system, which is un-used
  579. ;; in u-boot-tools.
  580. (("CONFIG_SOUND=y") "CONFIG_SOUND=n")))
  581. (find-files "configs" "sandbox_.*defconfig$|tools-only_defconfig"))
  582. #t))
  583. (replace 'configure
  584. (lambda* (#:key make-flags #:allow-other-keys)
  585. (apply invoke "make" "tools-only_defconfig" make-flags)))
  586. (replace 'build
  587. (lambda* (#:key inputs make-flags #:allow-other-keys)
  588. (apply invoke "make" "tools-all" make-flags)))
  589. (replace 'install
  590. (lambda* (#:key outputs #:allow-other-keys)
  591. (let* ((out (assoc-ref outputs "out"))
  592. (bin (string-append out "/bin")))
  593. (for-each (lambda (name)
  594. (install-file name bin))
  595. '("tools/netconsole"
  596. "tools/jtagconsole"
  597. "tools/gen_eth_addr"
  598. "tools/gen_ethaddr_crc"
  599. "tools/img2srec"
  600. "tools/mkenvimage"
  601. "tools/dumpimage"
  602. "tools/mkimage"
  603. "tools/kwboot"
  604. "tools/proftool"
  605. "tools/fdtgrep"
  606. "tools/env/fw_printenv"
  607. "tools/sunxi-spl-image-builder"))
  608. #t)))
  609. (delete 'check)
  610. (add-after 'install 'check
  611. (lambda* (#:key make-flags test-target #:allow-other-keys)
  612. (invoke "test/image/test-imagetools.sh")))
  613. ;; Only run full test suite on x86_64 systems, as many tests
  614. ;; assume x86_64.
  615. ,@(if (string-match "^x86_64-linux"
  616. (or (%current-target-system)
  617. (%current-system)))
  618. '((add-after 'check 'check-x86
  619. (lambda* (#:key make-flags test-target #:allow-other-keys)
  620. (apply invoke "make" "mrproper" make-flags)
  621. (setenv "SDL_VIDEODRIVER" "dummy")
  622. (setenv "PAGER" "cat")
  623. (apply invoke "make" test-target make-flags))))
  624. '()))))
  625. (description "U-Boot is a bootloader used mostly for ARM boards. It
  626. also initializes the boards (RAM etc). This package provides its
  627. board-independent tools.")))
  628. (define-public (make-u-boot-package board triplet)
  629. "Returns a u-boot package for BOARD cross-compiled for TRIPLET."
  630. (let ((same-arch? (lambda ()
  631. (string=? (%current-system)
  632. (gnu-triplet->nix-system triplet)))))
  633. (package
  634. (inherit u-boot)
  635. (name (string-append "u-boot-"
  636. (string-replace-substring (string-downcase board)
  637. "_" "-")))
  638. (native-inputs
  639. `(,@(if (not (same-arch?))
  640. `(("cross-gcc" ,(cross-gcc triplet))
  641. ("cross-binutils" ,(cross-binutils triplet)))
  642. `())
  643. ,@(package-native-inputs u-boot)))
  644. (arguments
  645. `(#:modules ((ice-9 ftw)
  646. (srfi srfi-1)
  647. (guix build utils)
  648. (guix build gnu-build-system))
  649. #:test-target "test"
  650. #:make-flags
  651. (list "HOSTCC=gcc"
  652. ,@(if (not (same-arch?))
  653. `((string-append "CROSS_COMPILE=" ,triplet "-"))
  654. '()))
  655. #:phases
  656. (modify-phases %standard-phases
  657. (replace 'configure
  658. (lambda* (#:key outputs make-flags #:allow-other-keys)
  659. (let ((config-name (string-append ,board "_defconfig")))
  660. (if (file-exists? (string-append "configs/" config-name))
  661. (apply invoke "make" `(,@make-flags ,config-name))
  662. (begin
  663. (display "Invalid board name. Valid board names are:"
  664. (current-error-port))
  665. (let ((suffix-len (string-length "_defconfig"))
  666. (entries (scandir "configs")))
  667. (for-each (lambda (file-name)
  668. (when (string-suffix? "_defconfig" file-name)
  669. (format (current-error-port)
  670. "- ~A\n"
  671. (string-drop-right file-name
  672. suffix-len))))
  673. (sort entries string-ci<)))
  674. (error "Invalid boardname ~s." ,board))))))
  675. (add-after 'configure 'disable-tools-libcrypto
  676. ;; Disable libcrypto due to GPL and OpenSSL license
  677. ;; incompatibilities
  678. (lambda _
  679. (substitute* ".config"
  680. (("CONFIG_TOOLS_LIBCRYPTO=.*$") "CONFIG_TOOLS_LIBCRYPTO=n"))))
  681. (replace 'install
  682. (lambda* (#:key outputs #:allow-other-keys)
  683. (let* ((out (assoc-ref outputs "out"))
  684. (libexec (string-append out "/libexec"))
  685. (uboot-files (append
  686. (remove
  687. ;; Those would not be reproducible
  688. ;; because of the randomness used
  689. ;; to produce them.
  690. ;; It's expected that the user will
  691. ;; use u-boot-tools to generate them
  692. ;; instead.
  693. (lambda (name)
  694. (string-suffix?
  695. "sunxi-spl-with-ecc.bin"
  696. name))
  697. (find-files "." ".*\\.(bin|efi|img|spl|itb|dtb|rksd)$"))
  698. (find-files "." "^(MLO|SPL)$"))))
  699. (mkdir-p libexec)
  700. (install-file ".config" libexec)
  701. ;; Useful for "qemu -kernel".
  702. (install-file "u-boot" libexec)
  703. (for-each
  704. (lambda (file)
  705. (let ((target-file (string-append libexec "/" file)))
  706. (mkdir-p (dirname target-file))
  707. (copy-file file target-file)))
  708. uboot-files)
  709. #t)))))))))
  710. (define-public u-boot-malta
  711. (make-u-boot-package "malta" "mips64el-linux-gnuabi64"))
  712. (define-public u-boot-am335x-boneblack
  713. (let ((base (make-u-boot-package "am335x_evm" "arm-linux-gnueabihf")))
  714. (package
  715. (inherit base)
  716. (name "u-boot-am335x-boneblack")
  717. (description "U-Boot is a bootloader used mostly for ARM boards. It
  718. also initializes the boards (RAM etc).
  719. This U-Boot is built for the BeagleBone Black, which was removed upstream,
  720. adjusted from the am335x_evm build with several device trees removed so that
  721. it fits within common partitioning schemes.")
  722. (arguments
  723. (substitute-keyword-arguments (package-arguments base)
  724. ((#:phases phases)
  725. `(modify-phases ,phases
  726. (add-after 'unpack 'patch-defconfig
  727. ;; Patch out other devicetrees to build image small enough to
  728. ;; fit within typical partitioning schemes where the first
  729. ;; partition begins at sector 2048.
  730. (lambda _
  731. (substitute* "configs/am335x_evm_defconfig"
  732. (("CONFIG_OF_LIST=.*$") "CONFIG_OF_LIST=\"am335x-evm am335x-boneblack\"\n"))
  733. #t)))))))))
  734. (define-public u-boot-am335x-evm
  735. (make-u-boot-package "am335x_evm" "arm-linux-gnueabihf"))
  736. (define-public (make-u-boot-sunxi64-package board triplet)
  737. (let ((base (make-u-boot-package board triplet)))
  738. (package
  739. (inherit base)
  740. (arguments
  741. (substitute-keyword-arguments (package-arguments base)
  742. ((#:phases phases)
  743. `(modify-phases ,phases
  744. (add-after 'unpack 'set-environment
  745. (lambda* (#:key native-inputs inputs #:allow-other-keys)
  746. (let ((bl31
  747. (string-append
  748. (assoc-ref (or native-inputs inputs) "firmware")
  749. "/bl31.bin")))
  750. (setenv "BL31" bl31)
  751. ;; This is necessary when we're using the bundled dtc.
  752. ;(setenv "PATH" (string-append (getenv "PATH") ":"
  753. ; "scripts/dtc"))
  754. )
  755. #t))))))
  756. (native-inputs
  757. `(("firmware" ,arm-trusted-firmware-sun50i-a64)
  758. ,@(package-native-inputs base))))))
  759. (define-public u-boot-pine64-plus
  760. (make-u-boot-sunxi64-package "pine64_plus" "aarch64-linux-gnu"))
  761. (define-public u-boot-pine64-lts
  762. (make-u-boot-sunxi64-package "pine64-lts" "aarch64-linux-gnu"))
  763. (define-public u-boot-pinebook
  764. (let ((base (make-u-boot-sunxi64-package "pinebook" "aarch64-linux-gnu")))
  765. (package
  766. (inherit base)
  767. (arguments
  768. (substitute-keyword-arguments (package-arguments base)
  769. ((#:phases phases)
  770. `(modify-phases ,phases
  771. (add-after 'unpack 'patch-pinebook-config
  772. ;; Fix regression with LCD video output introduced in 2020.01
  773. ;; https://patchwork.ozlabs.org/patch/1225130/
  774. (lambda _
  775. (substitute* "configs/pinebook_defconfig"
  776. (("CONFIG_VIDEO_BRIDGE_ANALOGIX_ANX6345=y") "CONFIG_VIDEO_BRIDGE_ANALOGIX_ANX6345=y\nCONFIG_VIDEO_BPP32=y"))
  777. #t)))))))))
  778. (define-public u-boot-bananapi-m2-ultra
  779. (make-u-boot-package "Bananapi_M2_Ultra" "arm-linux-gnueabihf"))
  780. (define-public u-boot-a20-olinuxino-lime
  781. (make-u-boot-package "A20-OLinuXino-Lime" "arm-linux-gnueabihf"))
  782. (define-public u-boot-a20-olinuxino-lime2
  783. (make-u-boot-package "A20-OLinuXino-Lime2" "arm-linux-gnueabihf"))
  784. (define-public u-boot-a20-olinuxino-micro
  785. (make-u-boot-package "A20-OLinuXino_MICRO" "arm-linux-gnueabihf"))
  786. (define-public u-boot-nintendo-nes-classic-edition
  787. (let ((base (make-u-boot-package "Nintendo_NES_Classic_Edition"
  788. "arm-linux-gnueabihf")))
  789. (package
  790. (inherit base)
  791. ;; Starting with 2019.01, FEL doesn't work anymore on A33.
  792. (version "2018.11")
  793. (source (origin
  794. (method url-fetch)
  795. (uri (string-append
  796. "https://ftp.denx.de/pub/u-boot/"
  797. "u-boot-" version ".tar.bz2"))
  798. (sha256
  799. (base32
  800. "0znkwljfwwn4y7j20pzz4ilqw8znphrfxns0x1lwdzh3xbr96z3k"))
  801. (patches (search-patches
  802. "u-boot-nintendo-nes-serial.patch"))))
  803. (description "U-Boot is a bootloader used mostly for ARM boards. It
  804. also initializes the boards (RAM etc).
  805. This version is for the Nintendo NES Classic Edition. It is assumed that
  806. you have added a serial port to pins PB0 and PB1 as described on
  807. @url{https://linux-sunxi.org/Nintendo_NES_Classic_Edition}.
  808. In order to use FEL mode on the device, hold the Reset button on the
  809. device while it's being turned on (and a while longer).")
  810. (native-inputs
  811. `(("python" ,python-2)
  812. ,@(package-native-inputs base))))))
  813. (define-public u-boot-wandboard
  814. (make-u-boot-package "wandboard" "arm-linux-gnueabihf"))
  815. (define-public u-boot-mx6cuboxi
  816. (make-u-boot-package "mx6cuboxi" "arm-linux-gnueabihf"))
  817. (define-public u-boot-novena
  818. (let ((base (make-u-boot-package "novena" "arm-linux-gnueabihf")))
  819. (package
  820. (inherit base)
  821. (description "U-Boot is a bootloader used mostly for ARM boards. It
  822. also initializes the boards (RAM etc).
  823. This U-Boot is built for Novena. Be advised that this version, contrary
  824. to Novena upstream, does not load u-boot.img from the first partition.")
  825. (arguments
  826. (substitute-keyword-arguments (package-arguments base)
  827. ((#:phases phases)
  828. `(modify-phases ,phases
  829. (add-after 'unpack 'patch-novena-defconfig
  830. ;; Patch configuration to disable loading u-boot.img from FAT partition,
  831. ;; allowing it to be installed at a device offset.
  832. (lambda _
  833. (substitute* "configs/novena_defconfig"
  834. (("CONFIG_SPL_FS_FAT=y") "# CONFIG_SPL_FS_FAT is not set"))
  835. #t)))))))))
  836. (define-public u-boot-cubieboard
  837. (make-u-boot-package "Cubieboard" "arm-linux-gnueabihf"))
  838. (define-public u-boot-cubietruck
  839. (make-u-boot-package "Cubietruck" "arm-linux-gnueabihf"))
  840. (define-public u-boot-puma-rk3399
  841. (let ((base (make-u-boot-package "puma-rk3399" "aarch64-linux-gnu")))
  842. (package
  843. (inherit base)
  844. (arguments
  845. (substitute-keyword-arguments (package-arguments base)
  846. ((#:phases phases)
  847. `(modify-phases ,phases
  848. (add-after 'unpack 'set-environment
  849. (lambda* (#:key inputs #:allow-other-keys)
  850. (setenv "BL31"
  851. (search-input-file inputs "/bl31.elf"))))
  852. ;; Phases do not succeed on the bl31 ELF.
  853. (delete 'strip)
  854. (delete 'validate-runpath)))))
  855. (native-inputs
  856. `(("firmware" ,arm-trusted-firmware-rk3399)
  857. ,@(package-native-inputs base))))))
  858. (define-public u-boot-qemu-riscv64
  859. (make-u-boot-package "qemu-riscv64" "riscv64-linux-gnu"))
  860. (define-public u-boot-qemu-riscv64-smode
  861. (let ((base (make-u-boot-package "qemu-riscv64_smode" "riscv64-linux-gnu")))
  862. (package
  863. (inherit base)
  864. (source (origin
  865. (inherit (package-source u-boot))
  866. (patches
  867. (search-patches "u-boot-riscv64-fix-extlinux.patch"
  868. %u-boot-allow-disabling-openssl-patch)))))))
  869. (define-public u-boot-sifive-unleashed
  870. (make-u-boot-package "sifive_unleashed" "riscv64-linux-gnu"))
  871. (define-public u-boot-sifive-unmatched
  872. (let ((base (make-u-boot-package "sifive_unmatched" "riscv64-linux-gnu")))
  873. (package
  874. (inherit base)
  875. (arguments
  876. (substitute-keyword-arguments (package-arguments base)
  877. ((#:phases phases)
  878. `(modify-phases ,phases
  879. (add-after 'unpack 'set-environment
  880. (lambda* (#:key inputs #:allow-other-keys)
  881. (let ((opensbi (string-append (assoc-ref inputs "firmware")
  882. "/fw_dynamic.bin")))
  883. (setenv "OPENSBI" opensbi))))))))
  884. (inputs
  885. `(("firmware" ,opensbi-generic)
  886. ,@(package-inputs base))))))
  887. (define-public u-boot-rock64-rk3328
  888. (let ((base (make-u-boot-package "rock64-rk3328" "aarch64-linux-gnu")))
  889. (package
  890. (inherit base)
  891. (arguments
  892. (substitute-keyword-arguments (package-arguments base)
  893. ((#:phases phases)
  894. `(modify-phases ,phases
  895. (add-after 'unpack 'set-environment
  896. (lambda* (#:key inputs #:allow-other-keys)
  897. (let ((bl31 (search-input-file inputs "/bl31.elf")))
  898. (setenv "BL31" bl31))))))))
  899. (native-inputs
  900. `(("firmware" ,arm-trusted-firmware-rk3328)
  901. ,@(package-native-inputs base))))))
  902. (define-public u-boot-firefly-rk3399
  903. (let ((base (make-u-boot-package "firefly-rk3399" "aarch64-linux-gnu")))
  904. (package
  905. (inherit base)
  906. (arguments
  907. (substitute-keyword-arguments (package-arguments base)
  908. ((#:phases phases)
  909. `(modify-phases ,phases
  910. (add-after 'unpack 'set-environment
  911. (lambda* (#:key inputs #:allow-other-keys)
  912. (setenv "BL31" (search-input-file inputs "/bl31.elf"))))
  913. ;; Phases do not succeed on the bl31 ELF.
  914. (delete 'strip)
  915. (delete 'validate-runpath)))))
  916. (native-inputs
  917. `(("firmware" ,arm-trusted-firmware-rk3399)
  918. ,@(package-native-inputs base))))))
  919. (define-public u-boot-rockpro64-rk3399
  920. (let ((base (make-u-boot-package "rockpro64-rk3399" "aarch64-linux-gnu")))
  921. (package
  922. (inherit base)
  923. (arguments
  924. (substitute-keyword-arguments (package-arguments base)
  925. ((#:phases phases)
  926. `(modify-phases ,phases
  927. (add-after 'unpack 'set-environment
  928. (lambda* (#:key inputs #:allow-other-keys)
  929. (setenv "BL31"
  930. (search-input-file inputs "/bl31.elf"))))
  931. ;; Phases do not succeed on the bl31 ELF.
  932. (delete 'strip)
  933. (delete 'validate-runpath)))))
  934. (native-inputs
  935. `(("firmware" ,arm-trusted-firmware-rk3399)
  936. ,@(package-native-inputs base))))))
  937. (define-public u-boot-pinebook-pro-rk3399
  938. (let ((base (make-u-boot-package "pinebook-pro-rk3399" "aarch64-linux-gnu")))
  939. (package
  940. (inherit base)
  941. (arguments
  942. (substitute-keyword-arguments (package-arguments base)
  943. ((#:phases phases)
  944. `(modify-phases ,phases
  945. (add-after 'unpack 'set-environment
  946. (lambda* (#:key inputs #:allow-other-keys)
  947. (setenv "BL31"
  948. (search-input-file inputs "/bl31.elf"))))
  949. ;; Phases do not succeed on the bl31 ELF.
  950. (delete 'strip)
  951. (delete 'validate-runpath)))))
  952. (native-inputs
  953. `(("firmware" ,arm-trusted-firmware-rk3399)
  954. ,@(package-native-inputs base))))))
  955. (define-public vboot-utils
  956. (package
  957. (name "vboot-utils")
  958. (version "R63-10032.B")
  959. (source (origin
  960. ;; XXX: Snapshots are available but changes timestamps every download.
  961. (method git-fetch)
  962. (uri (git-reference
  963. (url (string-append "https://chromium.googlesource.com"
  964. "/chromiumos/platform/vboot_reference"))
  965. (commit (string-append "release-" version))))
  966. (file-name (string-append name "-" version "-checkout"))
  967. (sha256
  968. (base32
  969. "0h0m3l69vp9dr6xrs1p6y7ilkq3jq8jraw2z20kqfv7lvc9l1lxj"))
  970. (patches
  971. (search-patches "vboot-utils-skip-test-workbuf.patch"
  972. "vboot-utils-fix-tests-show-contents.patch"
  973. "vboot-utils-fix-format-load-address.patch"))))
  974. (build-system gnu-build-system)
  975. (arguments
  976. `(#:make-flags (list "CC=gcc"
  977. ;; On ARM, we must pass "HOST_ARCH=arm" so that the
  978. ;; ${HOST_ARCH} and ${ARCH} variables in the makefile
  979. ;; match. Otherwise, ${HOST_ARCH} will be assigned
  980. ;; "armv7l", the value of `uname -m`, and will not
  981. ;; match ${ARCH}, which will make the tests require
  982. ;; QEMU for testing.
  983. ,@(if (string-prefix? "arm"
  984. (or (%current-target-system)
  985. (%current-system)))
  986. '("HOST_ARCH=arm")
  987. '())
  988. (string-append "DESTDIR=" (assoc-ref %outputs "out")))
  989. #:phases (modify-phases %standard-phases
  990. (add-after 'unpack 'patch-hard-coded-paths
  991. (lambda* (#:key inputs outputs #:allow-other-keys)
  992. (let ((coreutils (assoc-ref inputs "coreutils"))
  993. (diffutils (assoc-ref inputs "diffutils")))
  994. (substitute* "futility/misc.c"
  995. (("/bin/cp") (string-append coreutils "/bin/cp")))
  996. (substitute* "tests/bitmaps/TestBmpBlock.py"
  997. (("/usr/bin/cmp") (string-append diffutils "/bin/cmp")))
  998. (substitute* "vboot_host.pc.in"
  999. (("prefix=/usr")
  1000. (string-append "prefix=" (assoc-ref outputs "out"))))
  1001. #t)))
  1002. (delete 'configure)
  1003. (add-before 'check 'patch-tests
  1004. (lambda _
  1005. ;; These tests compare diffs against known-good values.
  1006. ;; Patch the paths to match those in the build container.
  1007. (substitute* (find-files "tests/futility/expect_output")
  1008. (("/mnt/host/source/src/platform/vboot_reference")
  1009. (string-append "/tmp/guix-build-" ,name "-" ,version
  1010. ".drv-0/source")))
  1011. ;; Tests require write permissions to many of these files.
  1012. (for-each make-file-writable (find-files "tests/futility"))
  1013. #t))
  1014. (add-after 'install 'install-devkeys
  1015. (lambda* (#:key outputs #:allow-other-keys)
  1016. (let* ((out (assoc-ref outputs "out"))
  1017. (share (string-append out "/share/vboot-utils")))
  1018. (copy-recursively "tests/devkeys"
  1019. (string-append share "/devkeys"))
  1020. #t))))
  1021. #:test-target "runtests"))
  1022. (native-inputs
  1023. `(("pkg-config" ,pkg-config)
  1024. ;; For tests.
  1025. ("diffutils" ,diffutils)
  1026. ("python@2" ,python-2)))
  1027. (inputs
  1028. `(("coreutils" ,coreutils)
  1029. ("libyaml" ,libyaml)
  1030. ("openssl" ,openssl)
  1031. ("openssl:static" ,openssl "static")
  1032. ("util-linux" ,util-linux "lib")))
  1033. (home-page
  1034. "https://dev.chromium.org/chromium-os/chromiumos-design-docs/verified-boot")
  1035. (synopsis "ChromiumOS verified boot utilities")
  1036. (description
  1037. "vboot-utils is a collection of tools to facilitate booting of
  1038. Chrome-branded devices. This includes the @command{cgpt} partitioning
  1039. program, the @command{futility} and @command{crossystem} firmware management
  1040. tools, and more.")
  1041. (license license:bsd-3)))
  1042. (define-public os-prober
  1043. (package
  1044. (name "os-prober")
  1045. (version "1.79")
  1046. (source
  1047. (origin
  1048. (method url-fetch)
  1049. (uri (string-append "mirror://debian/pool/main/o/os-prober/os-prober_"
  1050. version ".tar.xz"))
  1051. (sha256
  1052. (base32 "1vhhk0bl2j4910513gn5h3z8nsaavyv3c8764bim2klc0xyk3rmb"))))
  1053. (build-system gnu-build-system)
  1054. (arguments
  1055. `(#:modules ((guix build gnu-build-system)
  1056. (guix build utils)
  1057. (ice-9 regex) ; for string-match
  1058. (srfi srfi-26)) ; for cut
  1059. #:make-flags
  1060. (list ,(string-append "CC=" (cc-for-target)))
  1061. #:tests? #f ; no tests
  1062. #:phases
  1063. (modify-phases %standard-phases
  1064. (replace 'configure
  1065. (lambda* (#:key outputs #:allow-other-keys)
  1066. (substitute* (find-files ".")
  1067. (("/usr") (assoc-ref outputs "out")))
  1068. (substitute* (find-files "." "50mounted-tests$")
  1069. (("mkdir") "mkdir -p"))
  1070. #t))
  1071. (replace 'install
  1072. (lambda* (#:key outputs #:allow-other-keys)
  1073. (define (find-files-non-recursive directory)
  1074. (find-files directory
  1075. (lambda (file stat)
  1076. (string-match (string-append "^" directory "/[^/]*$")
  1077. file))
  1078. #:directories? #t))
  1079. (let* ((out (assoc-ref outputs "out"))
  1080. (bin (string-append out "/bin"))
  1081. (lib (string-append out "/lib"))
  1082. (share (string-append out "/share")))
  1083. (for-each (cut install-file <> bin)
  1084. (list "linux-boot-prober" "os-prober"))
  1085. (install-file "newns" (string-append lib "/os-prober"))
  1086. (install-file "common.sh" (string-append share "/os-prober"))
  1087. (install-file "os-probes/mounted/powerpc/20macosx"
  1088. (string-append lib "/os-probes/mounted"))
  1089. (for-each
  1090. (lambda (directory)
  1091. (for-each
  1092. (lambda (file)
  1093. (let ((destination (string-append lib "/" directory
  1094. "/" (basename file))))
  1095. (mkdir-p (dirname destination))
  1096. (copy-recursively file destination)))
  1097. (append (find-files-non-recursive (string-append directory "/common"))
  1098. (find-files-non-recursive (string-append directory "/x86")))))
  1099. (list "os-probes" "os-probes/mounted" "os-probes/init"
  1100. "linux-boot-probes" "linux-boot-probes/mounted"))
  1101. #t))))))
  1102. (home-page "https://joeyh.name/code/os-prober")
  1103. (synopsis "Detect other operating systems")
  1104. (description "os-prober probes disks on the system for other operating
  1105. systems so that they can be added to the bootloader. It also works out how to
  1106. boot existing GNU/Linux systems and detects what distribution is installed in
  1107. order to add a suitable bootloader menu entry.")
  1108. (license license:gpl2+)))
  1109. (define-public ipxe
  1110. ;; XXX: 'BUILD_TIMESTAMP' is used to automatically select the newest version
  1111. ;; of iPXE if multiple iPXE drivers are loaded concurrently in a UEFI system.
  1112. ;;
  1113. ;; TODO: Bump this timestamp at each modifications of the package (not only
  1114. ;; for updates) by running: date +%s.
  1115. (let ((timestamp "1591706427"))
  1116. (package
  1117. (name "ipxe")
  1118. (version "1.21.1")
  1119. (source (origin
  1120. (method git-fetch)
  1121. (uri (git-reference
  1122. (url "https://github.com/ipxe/ipxe")
  1123. (commit (string-append "v" version))))
  1124. (file-name (git-file-name name version))
  1125. (patches (search-patches "ipxe-reproducible-geniso.patch"))
  1126. (sha256
  1127. (base32
  1128. "1pkf1n1c0rdlzfls8fvjvi1sd9xjd9ijqlyz3wigr70ijcv6x8i9"))))
  1129. (build-system gnu-build-system)
  1130. (arguments
  1131. `(#:modules ((guix build utils)
  1132. (guix build gnu-build-system)
  1133. (guix base32)
  1134. (ice-9 string-fun)
  1135. (ice-9 regex)
  1136. (rnrs bytevectors))
  1137. #:imported-modules ((guix base32)
  1138. ,@%gnu-build-system-modules)
  1139. #:make-flags
  1140. ;; XXX: 'BUILD_ID' is used to determine when another ROM in the
  1141. ;; system contains identical code in order to save space within the
  1142. ;; legacy BIOS option ROM area, which is extremely limited in size.
  1143. ;; It is supposed to be collision-free across all ROMs, to do so we
  1144. ;; use the truncated output hash of the package.
  1145. (let ((build-id
  1146. (lambda (out)
  1147. (let* ((nix-store (string-append
  1148. (or (getenv "NIX_STORE") "/gnu/store")
  1149. "/"))
  1150. (filename
  1151. (string-replace-substring out nix-store ""))
  1152. (hash (match:substring (string-match "[0-9a-z]{32}"
  1153. filename)))
  1154. (bv (nix-base32-string->bytevector hash)))
  1155. (format #f "0x~x"
  1156. (bytevector-u32-ref bv 0 (endianness big))))))
  1157. (out (assoc-ref %outputs "out"))
  1158. (syslinux (assoc-ref %build-inputs "syslinux")))
  1159. (list "ECHO_E_BIN_ECHO=echo"
  1160. "ECHO_E_BIN_ECHO_E=echo -e"
  1161. ;; cdrtools' mkisofs will silently ignore a missing isolinux.bin!
  1162. ;; Luckily xorriso is more strict.
  1163. (string-append "ISOLINUX_BIN=" syslinux
  1164. "/share/syslinux/isolinux.bin")
  1165. (string-append "SYSLINUX_MBR_DISK_PATH=" syslinux
  1166. "/share/syslinux/isohdpfx.bin")
  1167. ;; Build reproducibly.
  1168. (string-append "BUILD_ID_CMD=echo -n " (build-id out))
  1169. (string-append "BUILD_TIMESTAMP=" ,timestamp)
  1170. "everything"))
  1171. #:phases
  1172. (modify-phases %standard-phases
  1173. (add-after 'unpack 'enter-source-directory
  1174. (lambda _ (chdir "src") #t))
  1175. (add-after 'enter-source-directory 'set-options
  1176. (lambda _
  1177. (substitute* "config/general.h"
  1178. (("^//(#define PING_CMD.*)" _ uncommented) uncommented)
  1179. (("^//(#define IMAGE_TRUST_CMD.*)" _ uncommented)
  1180. uncommented)
  1181. (("^#undef.*(DOWNLOAD_PROTO_HTTPS.*)" _ option)
  1182. (string-append "#define " option))
  1183. (("^#undef.*(DOWNLOAD_PROTO_NFS.*)" _ option)
  1184. (string-append "#define " option)))
  1185. #t))
  1186. (delete 'configure) ; no configure script
  1187. (replace 'install
  1188. (lambda* (#:key outputs #:allow-other-keys)
  1189. (let* ((out (assoc-ref outputs "out"))
  1190. (ipxe (string-append out "/lib/ipxe"))
  1191. (exts-re
  1192. "\\.(efi|efirom|iso|kkpxe|kpxe|lkrn|mrom|pxe|rom|usb)$")
  1193. (dirs '("bin" "bin-i386-linux" "bin-x86_64-pcbios"
  1194. "bin-x86_64-efi" "bin-x86_64-linux" "bin-i386-efi"))
  1195. (files (apply append
  1196. (map (lambda (dir)
  1197. (find-files dir exts-re)) dirs))))
  1198. (for-each (lambda (file)
  1199. (let* ((subdir (dirname file))
  1200. (fn (basename file))
  1201. (tgtsubdir (cond
  1202. ((string=? "bin" subdir) "")
  1203. ((string-prefix? "bin-" subdir)
  1204. (string-drop subdir 4)))))
  1205. (install-file file
  1206. (string-append ipxe "/" tgtsubdir))))
  1207. files))
  1208. #t))
  1209. (add-after 'install 'leave-source-directory
  1210. (lambda _ (chdir "..") #t)))
  1211. #:tests? #f)) ; no test suite
  1212. (native-inputs
  1213. (list perl syslinux xorriso))
  1214. (home-page "https://ipxe.org")
  1215. (synopsis "PXE-compliant network boot firmware")
  1216. (description "iPXE is a network boot firmware. It provides a full PXE
  1217. implementation enhanced with additional features such as booting from: a web
  1218. server via HTTP, an iSCSI SAN, a Fibre Channel SAN via FCoE, an AoE SAN, a
  1219. wireless network, a wide-area network, an Infiniband network. It
  1220. controls the boot process with a script. You can use iPXE to replace the
  1221. existing PXE ROM on your network card, or you can chainload into iPXE to obtain
  1222. the features of iPXE without the hassle of reflashing.")
  1223. (license license:gpl2+))))