u-boot.scm 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2017 David Craven <david@craven.ch>
  3. ;;; Copyright © 2017, 2019 Mathieu Othacehe <m.othacehe@gmail.com>
  4. ;;; Copyright © 2020 Julien Lepiller <julien@lepiller.eu>
  5. ;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
  6. ;;; Copyright © 2022 Maxim Cournoyer <maxim.cournoyer@gmail.com>
  7. ;;; Copyright © 2023 Efraim Flashner <efraim@flashner.co.il>
  8. ;;;
  9. ;;; This file is part of GNU Guix.
  10. ;;;
  11. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  12. ;;; under the terms of the GNU General Public License as published by
  13. ;;; the Free Software Foundation; either version 3 of the License, or (at
  14. ;;; your option) any later version.
  15. ;;;
  16. ;;; GNU Guix is distributed in the hope that it will be useful, but
  17. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. ;;; GNU General Public License for more details.
  20. ;;;
  21. ;;; You should have received a copy of the GNU General Public License
  22. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  23. (define-module (gnu bootloader u-boot)
  24. #:use-module (gnu bootloader extlinux)
  25. #:use-module (gnu bootloader)
  26. #:use-module (gnu packages bootloaders)
  27. #:use-module (guix gexp)
  28. #:export (u-boot-bootloader
  29. u-boot-a20-olinuxino-lime-bootloader
  30. u-boot-a20-olinuxino-lime2-bootloader
  31. u-boot-a20-olinuxino-micro-bootloader
  32. u-boot-bananapi-m2-ultra-bootloader
  33. u-boot-beaglebone-black-bootloader
  34. u-boot-cubietruck-bootloader
  35. u-boot-firefly-rk3399-bootloader
  36. u-boot-mx6cuboxi-bootloader
  37. u-boot-nintendo-nes-classic-edition-bootloader
  38. u-boot-novena-bootloader
  39. u-boot-pine64-plus-bootloader
  40. u-boot-pine64-lts-bootloader
  41. u-boot-pinebook-bootloader
  42. u-boot-pinebook-pro-rk3399-bootloader
  43. u-boot-puma-rk3399-bootloader
  44. u-boot-rock64-rk3328-bootloader
  45. u-boot-rockpro64-rk3399-bootloader
  46. u-boot-sifive-unmatched-bootloader
  47. u-boot-ts7970-q-2g-1000mhz-c-bootloader
  48. u-boot-wandboard-bootloader))
  49. (define install-u-boot
  50. #~(lambda (bootloader root-index image)
  51. (if bootloader
  52. (error "Failed to install U-Boot"))))
  53. (define install-beaglebone-black-u-boot
  54. ;; http://wiki.beyondlogic.org/index.php?title=BeagleBoneBlack_Upgrading_uBoot
  55. ;; This first stage bootloader called MLO (U-Boot SPL) is expected at
  56. ;; 0x20000 by BBB ROM code. The second stage bootloader will be loaded by
  57. ;; the MLO and is expected at 0x60000. Write both first stage ("MLO") and
  58. ;; second stage ("u-boot.img") images, read in BOOTLOADER directory, to the
  59. ;; specified DEVICE.
  60. #~(lambda (bootloader root-index image)
  61. (let ((mlo (string-append bootloader "/libexec/MLO"))
  62. (u-boot (string-append bootloader "/libexec/u-boot.img")))
  63. (write-file-on-device mlo (* 256 512)
  64. image (* 256 512))
  65. (write-file-on-device u-boot (* 1024 512)
  66. image (* 768 512)))))
  67. (define install-allwinner-u-boot
  68. #~(lambda (bootloader root-index image)
  69. (let ((u-boot (string-append bootloader
  70. "/libexec/u-boot-sunxi-with-spl.bin")))
  71. (write-file-on-device u-boot (stat:size (stat u-boot))
  72. image (* 8 1024)))))
  73. (define install-allwinner64-u-boot
  74. #~(lambda (bootloader root-index image)
  75. (let ((spl (string-append bootloader "/libexec/u-boot-sunxi-with-spl.bin"))
  76. (u-boot (string-append bootloader "/libexec/u-boot-sunxi-with-spl.fit.itb")))
  77. (write-file-on-device spl (stat:size (stat spl))
  78. image (* 8 1024))
  79. (write-file-on-device u-boot (stat:size (stat u-boot))
  80. image (* 40 1024)))))
  81. (define install-imx-u-boot
  82. #~(lambda (bootloader root-index image)
  83. (let ((spl (string-append bootloader "/libexec/SPL"))
  84. (u-boot (string-append bootloader "/libexec/u-boot.img")))
  85. (write-file-on-device spl (stat:size (stat spl))
  86. image (* 1 1024))
  87. (write-file-on-device u-boot (stat:size (stat u-boot))
  88. image (* 69 1024)))))
  89. (define install-puma-rk3399-u-boot
  90. #~(lambda (bootloader root-index image)
  91. (let ((spl (string-append bootloader "/libexec/idbloader.img"))
  92. (u-boot (string-append bootloader "/libexec/u-boot.itb")))
  93. (write-file-on-device spl (stat:size (stat spl))
  94. image (* 64 512))
  95. (write-file-on-device u-boot (stat:size (stat u-boot))
  96. image (* 512 512)))))
  97. (define install-firefly-rk3399-u-boot
  98. #~(lambda (bootloader root-index image)
  99. (let ((idb (string-append bootloader "/libexec/idbloader.img"))
  100. (u-boot (string-append bootloader "/libexec/u-boot.itb")))
  101. (write-file-on-device idb (stat:size (stat idb))
  102. image (* 64 512))
  103. (write-file-on-device u-boot (stat:size (stat u-boot))
  104. image (* 16384 512)))))
  105. (define install-rock64-rk3328-u-boot
  106. #~(lambda (bootloader root-index image)
  107. (let ((idb (string-append bootloader "/libexec/idbloader.img"))
  108. (u-boot (string-append bootloader "/libexec/u-boot.itb")))
  109. (write-file-on-device idb (stat:size (stat idb))
  110. image (* 64 512))
  111. (write-file-on-device u-boot (stat:size (stat u-boot))
  112. image (* 16384 512)))))
  113. (define install-rockpro64-rk3399-u-boot
  114. #~(lambda (bootloader root-index image)
  115. (let ((idb (string-append bootloader "/libexec/idbloader.img"))
  116. (u-boot (string-append bootloader "/libexec/u-boot.itb")))
  117. (write-file-on-device idb (stat:size (stat idb))
  118. image (* 64 512))
  119. (write-file-on-device u-boot (stat:size (stat u-boot))
  120. image (* 16384 512)))))
  121. (define install-pinebook-pro-rk3399-u-boot install-rockpro64-rk3399-u-boot)
  122. (define install-u-boot-ts7970-q-2g-1000mhz-c-u-boot
  123. #~(lambda (bootloader device mount-point)
  124. (let ((u-boot.imx (string-append bootloader "/libexec/u-boot.imx"))
  125. (install-dir (string-append mount-point "/boot")))
  126. (install-file u-boot.imx install-dir))))
  127. (define install-sifive-unmatched-u-boot
  128. #~(lambda (bootloader root-index image)
  129. (let ((spl (string-append bootloader "/libexec/spl/u-boot-spl.bin"))
  130. (u-boot (string-append bootloader "/libexec/u-boot.itb")))
  131. (write-file-on-device spl (stat:size (stat spl))
  132. image (* 34 512))
  133. (write-file-on-device u-boot (stat:size (stat u-boot))
  134. image (* 2082 512)))))
  135. ;;;
  136. ;;; Bootloader definitions.
  137. ;;;
  138. (define u-boot-bootloader
  139. (bootloader
  140. (inherit extlinux-bootloader)
  141. (name 'u-boot)
  142. (package #f)
  143. (installer #f)
  144. (disk-image-installer install-u-boot)))
  145. (define u-boot-beaglebone-black-bootloader
  146. (bootloader
  147. (inherit u-boot-bootloader)
  148. (package u-boot-am335x-boneblack)
  149. (disk-image-installer install-beaglebone-black-u-boot)))
  150. (define u-boot-allwinner-bootloader
  151. (bootloader
  152. (inherit u-boot-bootloader)
  153. (disk-image-installer install-allwinner-u-boot)))
  154. (define u-boot-allwinner64-bootloader
  155. (bootloader
  156. (inherit u-boot-bootloader)
  157. (disk-image-installer install-allwinner64-u-boot)))
  158. (define u-boot-imx-bootloader
  159. (bootloader
  160. (inherit u-boot-bootloader)
  161. (disk-image-installer install-imx-u-boot)))
  162. (define u-boot-nintendo-nes-classic-edition-bootloader
  163. (bootloader
  164. (inherit u-boot-allwinner-bootloader)
  165. (package u-boot-nintendo-nes-classic-edition)))
  166. (define u-boot-a20-olinuxino-lime-bootloader
  167. (bootloader
  168. (inherit u-boot-allwinner-bootloader)
  169. (package u-boot-a20-olinuxino-lime)))
  170. (define u-boot-a20-olinuxino-lime2-bootloader
  171. (bootloader
  172. (inherit u-boot-allwinner-bootloader)
  173. (package u-boot-a20-olinuxino-lime2)))
  174. (define u-boot-a20-olinuxino-micro-bootloader
  175. (bootloader
  176. (inherit u-boot-allwinner-bootloader)
  177. (package u-boot-a20-olinuxino-micro)))
  178. (define u-boot-bananapi-m2-ultra-bootloader
  179. (bootloader
  180. (inherit u-boot-allwinner-bootloader)
  181. (package u-boot-bananapi-m2-ultra)))
  182. (define u-boot-cubietruck-bootloader
  183. (bootloader
  184. (inherit u-boot-allwinner-bootloader)
  185. (package u-boot-cubietruck)))
  186. (define u-boot-firefly-rk3399-bootloader
  187. ;; SD and eMMC use the same format
  188. (bootloader
  189. (inherit u-boot-bootloader)
  190. (package u-boot-firefly-rk3399)
  191. (disk-image-installer install-firefly-rk3399-u-boot)))
  192. (define u-boot-mx6cuboxi-bootloader
  193. (bootloader
  194. (inherit u-boot-imx-bootloader)
  195. (package u-boot-mx6cuboxi)))
  196. (define u-boot-wandboard-bootloader
  197. (bootloader
  198. (inherit u-boot-imx-bootloader)
  199. (package u-boot-wandboard)))
  200. (define u-boot-novena-bootloader
  201. (bootloader
  202. (inherit u-boot-imx-bootloader)
  203. (package u-boot-novena)))
  204. (define u-boot-pine64-plus-bootloader
  205. (bootloader
  206. (inherit u-boot-allwinner64-bootloader)
  207. (package u-boot-pine64-plus)))
  208. (define u-boot-pine64-lts-bootloader
  209. (bootloader
  210. (inherit u-boot-allwinner-bootloader)
  211. (package u-boot-pine64-lts)))
  212. (define u-boot-pinebook-bootloader
  213. (bootloader
  214. (inherit u-boot-allwinner64-bootloader)
  215. (package u-boot-pinebook)))
  216. (define u-boot-puma-rk3399-bootloader
  217. (bootloader
  218. (inherit u-boot-bootloader)
  219. (package u-boot-puma-rk3399)
  220. (disk-image-installer install-puma-rk3399-u-boot)))
  221. (define u-boot-rock64-rk3328-bootloader
  222. ;; SD and eMMC use the same format
  223. (bootloader
  224. (inherit u-boot-bootloader)
  225. (package u-boot-rock64-rk3328)
  226. (disk-image-installer install-rock64-rk3328-u-boot)))
  227. (define u-boot-rockpro64-rk3399-bootloader
  228. ;; SD and eMMC use the same format
  229. (bootloader
  230. (inherit u-boot-bootloader)
  231. (package u-boot-rockpro64-rk3399)
  232. (disk-image-installer install-rockpro64-rk3399-u-boot)))
  233. (define u-boot-pinebook-pro-rk3399-bootloader
  234. ;; SD and eMMC use the same format
  235. (bootloader
  236. (inherit u-boot-bootloader)
  237. (package u-boot-pinebook-pro-rk3399)
  238. (disk-image-installer install-pinebook-pro-rk3399-u-boot)))
  239. (define u-boot-ts7970-q-2g-1000mhz-c-bootloader
  240. ;; This bootloader doesn't really need to be installed, as it is read from
  241. ;; an SPI memory chip, not the SD card. It is copied to /boot/u-boot.imx
  242. ;; for convenience and should be manually flashed at the U-Boot prompt.
  243. (bootloader
  244. (inherit u-boot-bootloader)
  245. (package u-boot-ts7970-q-2g-1000mhz-c)
  246. (installer install-u-boot-ts7970-q-2g-1000mhz-c-u-boot)
  247. (disk-image-installer #f)))
  248. (define u-boot-sifive-unmatched-bootloader
  249. (bootloader
  250. (inherit u-boot-bootloader)
  251. (package u-boot-sifive-unmatched)
  252. (disk-image-installer install-sifive-unmatched-u-boot)))