firmware.scm 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2016 Eric Bavier <bavier@member.fsf.org>
  4. ;;; Copyright © 2017 David Craven <david@craven.ch>
  5. ;;; Copyright © 2017, 2018 Efraim Flashner <efraim@flashner.co.il>
  6. ;;; Copyright © 2018, 2020 Tobias Geerinckx-Rice <me@tobias.gr>
  7. ;;; Copyright © 2018 Vagrant Cascadian <vagrant@debian.org>
  8. ;;; Copyright © 2019 Mathieu Othacehe <m.othacehe@gmail.com>
  9. ;;; Copyright © 2020, 2021, 2022 Marius Bakke <marius@gnu.org>
  10. ;;; Copyright © 2021 Petr Hodina <phodina@protonmail.com>
  11. ;;;
  12. ;;; This file is part of GNU Guix.
  13. ;;;
  14. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  15. ;;; under the terms of the GNU General Public License as published by
  16. ;;; the Free Software Foundation; either version 3 of the License, or (at
  17. ;;; your option) any later version.
  18. ;;;
  19. ;;; GNU Guix is distributed in the hope that it will be useful, but
  20. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  21. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. ;;; GNU General Public License for more details.
  23. ;;;
  24. ;;; You should have received a copy of the GNU General Public License
  25. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  26. (define-module (gnu packages firmware)
  27. #:use-module ((guix licenses) #:prefix license:)
  28. #:use-module (guix packages)
  29. #:use-module (guix download)
  30. #:use-module (guix gexp)
  31. #:use-module (guix utils)
  32. #:use-module (guix git-download)
  33. #:use-module (guix build-system gnu)
  34. #:use-module (guix build-system meson)
  35. #:use-module (gnu packages)
  36. #:use-module (gnu packages admin)
  37. #:use-module (gnu packages assembly)
  38. #:use-module (gnu packages base)
  39. #:use-module (gnu packages bison)
  40. #:use-module (gnu packages cmake)
  41. #:use-module (gnu packages curl)
  42. #:use-module (gnu packages cross-base)
  43. #:use-module (gnu packages flex)
  44. #:use-module (gnu packages gcc)
  45. #:use-module (gnu packages glib)
  46. #:use-module (gnu packages gnome)
  47. #:use-module (gnu packages libusb)
  48. #:use-module (gnu packages linux)
  49. #:use-module (gnu packages perl)
  50. #:use-module (gnu packages python)
  51. #:use-module (gnu packages pkg-config))
  52. (define-public ath9k-htc-firmware
  53. (package
  54. (name "ath9k-htc-firmware")
  55. (version "1.4.0")
  56. (source (origin
  57. (method git-fetch)
  58. (uri (git-reference
  59. (url "https://github.com/qca/open-ath9k-htc-firmware")
  60. (commit version)))
  61. (sha256
  62. (base32
  63. "16jbj8avg5jkgvq5lxm0hdxxn4c3zn7fx8b4nxllvr024apk9w23"))
  64. (file-name (git-file-name name version))
  65. (patches (search-patches "ath9k-htc-firmware-objcopy.patch"
  66. "ath9k-htc-firmware-gcc-compat.patch"))))
  67. (build-system gnu-build-system)
  68. (arguments
  69. '(#:phases
  70. (modify-phases %standard-phases
  71. (add-before 'configure 'pre-configure
  72. (lambda* (#:key inputs native-inputs #:allow-other-keys)
  73. (chdir "target_firmware")
  74. ;; 'configure' is a simple script that runs 'cmake' with
  75. ;; the right flags.
  76. (substitute* "configure"
  77. (("^TOOLCHAIN=.*$")
  78. (string-append "TOOLCHAIN="
  79. (assoc-ref (or native-inputs inputs) "cross-gcc")
  80. "\n")))
  81. #t))
  82. (replace 'install
  83. (lambda* (#:key outputs #:allow-other-keys)
  84. (let* ((out (assoc-ref outputs "out"))
  85. (fw-dir (string-append out "/lib/firmware")))
  86. (for-each (lambda (file)
  87. (install-file file fw-dir))
  88. (find-files "." "\\.fw$"))
  89. #t))))
  90. #:tests? #f))
  91. ;; The firmware is cross-compiled using a "bare bones" compiler (no libc.)
  92. ;; Use our own tool chain for that.
  93. (native-inputs `(("cross-gcc" ,(cross-gcc
  94. "xtensa-elf"
  95. #:xbinutils (cross-binutils "xtensa-elf"
  96. binutils-2.33)))
  97. ("cross-binutils" ,(cross-binutils "xtensa-elf" binutils-2.33))
  98. ("cmake" ,cmake-minimal)
  99. ("perl" ,perl)))
  100. (home-page "https://wireless.wiki.kernel.org/en/users/Drivers/ath9k_htc")
  101. (synopsis "Firmware for the Atheros AR7010 and AR9271 USB 802.11n NICs")
  102. (description
  103. "This is the firmware for the Qualcomm Atheros AR7010 and AR9271 USB
  104. 802.11n NICs (aka Wi-Fi USB dongles). It is used by the ath9k driver of
  105. Linux-libre.")
  106. (license (license:non-copyleft "http://directory.fsf.org/wiki/License:ClearBSD"))))
  107. (define-public b43-tools
  108. (let ((commit "27892ef741e7f1d08cb939744f8b8f5dac7b04ae")
  109. (revision "1"))
  110. (package
  111. (name "b43-tools")
  112. (version (git-version "0.0.0" revision commit))
  113. (source
  114. (origin
  115. (method git-fetch)
  116. (uri (git-reference
  117. (url "http://git.bues.ch/git/b43-tools.git")
  118. (commit commit)))
  119. (file-name (git-file-name name version))
  120. (sha256
  121. (base32
  122. "1wgmj4d65izbhprwb5bcwimc2ryv19b9066lqzy4sa5m6wncm9cn"))))
  123. (build-system gnu-build-system)
  124. (native-inputs
  125. (list flex bison))
  126. (arguments
  127. `(#:modules ((srfi srfi-1)
  128. (guix build gnu-build-system)
  129. (guix build utils))
  130. #:tests? #f ; no tests
  131. #:phases
  132. (let ((subdirs '("assembler" "disassembler")))
  133. (modify-phases %standard-phases
  134. (delete 'configure) ; no configure script
  135. (add-before 'build 'patch-/bin/true
  136. (lambda _
  137. (substitute* (find-files "." "Makefile")
  138. (("/bin/true") ":"))
  139. #t))
  140. (replace 'build
  141. (lambda _
  142. (for-each (lambda (dir)
  143. (invoke "make" "-C" dir "CC=gcc"))
  144. subdirs)
  145. #t))
  146. (replace 'install
  147. (lambda* (#:key outputs #:allow-other-keys)
  148. (let ((out (assoc-ref outputs "out")))
  149. (mkdir-p (string-append out "/bin"))
  150. (for-each (lambda (dir)
  151. (invoke "make" "-C" dir
  152. (string-append "PREFIX=" out)
  153. "install"))
  154. subdirs)
  155. #t)))))))
  156. (home-page
  157. "https://bues.ch/cms/hacking/misc.html#linux_b43_driver_firmware_tools")
  158. (synopsis "Collection of tools for the b43 wireless driver")
  159. (description
  160. "The b43 firmware tools is a collection of firmware extractor,
  161. assembler, disassembler, and debugging tools for the Linux kernel b43 wireless
  162. driver.")
  163. (license license:gpl2))))
  164. (define-public openfwwf-firmware
  165. (package
  166. (name "openfwwf-firmware")
  167. (version "5.2")
  168. (source
  169. (origin
  170. (method url-fetch)
  171. (uri (string-append "http://netweb.ing.unibs.it/~openfwwf/firmware/"
  172. "openfwwf-" version ".tar.gz"))
  173. (sha256
  174. (base32
  175. "1p60gdi7w88s7qw82d3g9v7mk887mhvidf4l5q5hh09j10h37q4x"))))
  176. (build-system gnu-build-system)
  177. (native-inputs
  178. (list b43-tools))
  179. (arguments
  180. `(#:make-flags (list (string-append "PREFIX="
  181. (assoc-ref %outputs "out")
  182. "/lib/firmware/b43-open"))
  183. #:tests? #f ;no tests
  184. #:phases (modify-phases %standard-phases
  185. (delete 'configure))))
  186. (home-page "http://netweb.ing.unibs.it/~openfwwf/")
  187. (synopsis "Firmware for BCM43xx devices")
  188. (description
  189. "This is firmware from Open FirmWare for WiFi networks (OpenFWWF) for the
  190. Broadcom/AirForce chipset BCM43xx with Wireless-Core Revision 5. It is used
  191. by the b43-open driver of Linux-libre.")
  192. (license license:gpl2)))
  193. (define-public eg25-manager
  194. (package
  195. (name "eg25-manager")
  196. (version "0.4.2")
  197. (source (origin
  198. (method git-fetch)
  199. (uri (git-reference
  200. (url "https://gitlab.com/mobian1/devices/eg25-manager")
  201. (commit version)))
  202. (file-name (git-file-name name version))
  203. (sha256
  204. (base32
  205. "1czq2yi852aqkdnrxdifzcq669bdvlm7j40xivxq77jq04fggpmf"))))
  206. (build-system meson-build-system)
  207. (native-inputs (list curl
  208. `(,glib "bin") pkg-config))
  209. (inputs (list libgpiod libgudev libusb))
  210. (synopsis "Manager daemon for the Quectel EG25 mobile broadband modem")
  211. (description
  212. "This package provides a manager daemon for the Quectel EG25 mobile
  213. broadband modem as found, for example, on PinePhone.")
  214. (home-page "https://gitlab.com/mobian1/devices/eg25-manager")
  215. (license license:gpl3+)))
  216. (define* (make-opensbi-package platform name #:optional (arch "riscv64"))
  217. (package
  218. (name name)
  219. (version "1.0")
  220. (source
  221. (origin
  222. (method git-fetch)
  223. (uri (git-reference
  224. (url "https://github.com/riscv-software-src/opensbi")
  225. (commit (string-append "v" version))))
  226. (file-name (git-file-name name version))
  227. (sha256
  228. (base32 "0srqkhd9b1mq4qkqk31dlrzy4mhljr49bzjxm0saylsbwhgxq31s"))))
  229. (build-system gnu-build-system)
  230. (native-inputs
  231. `(,@(if (and (not (string-prefix? "riscv64" (%current-system)))
  232. (string-prefix? "riscv64" arch))
  233. `(("cross-gcc" ,(cross-gcc "riscv64-linux-gnu" #:xgcc gcc-7))
  234. ("cross-binutils" ,(cross-binutils "riscv64-linux-gnu")))
  235. '())))
  236. (arguments
  237. `(#:tests? #f ; no check target
  238. #:make-flags (list (string-append "PLATFORM=" ,platform)
  239. ,@(if (and (not (string-prefix? "riscv64"
  240. (%current-system)))
  241. (string-prefix? "riscv64" arch))
  242. `("CROSS_COMPILE=riscv64-linux-gnu-")
  243. `("CC=gcc"))
  244. "FW_PAYLOAD=n"
  245. "V=1")
  246. #:phases
  247. (modify-phases %standard-phases
  248. (delete 'configure)
  249. (replace 'install
  250. (lambda* (#:key outputs #:allow-other-keys)
  251. (let ((out (assoc-ref outputs "out"))
  252. (bin (find-files "." "fw_.*\\.(elf|bin)$")))
  253. (for-each
  254. (lambda (file)
  255. (install-file file out))
  256. bin))
  257. #t)))))
  258. (home-page "https://github.com/riscv-software-src/opensbi")
  259. (synopsis "RISC-V Open Source Supervisor Binary Interface")
  260. (description "A reference implementation of the RISC-V SBI specifications
  261. for platform-specific firmwares executing in M-mode.")
  262. (license (list license:bsd-2
  263. ;; lib/utils/libfdt/* is dual licensed under bsd-2 and gpl2+.
  264. license:gpl2+
  265. ;; platform/ariane-fpga/* is gpl2.
  266. license:gpl2))))
  267. (define-public opensbi-generic
  268. (make-opensbi-package "generic" "opensbi-generic"))
  269. (define-public seabios
  270. (package
  271. (name "seabios")
  272. (version "1.15.0")
  273. (source
  274. (origin
  275. (method git-fetch)
  276. (uri (git-reference
  277. (url "https://review.coreboot.org/seabios.git")
  278. (commit (string-append "rel-" version))))
  279. (file-name (git-file-name name version))
  280. (sha256
  281. (base32 "0gnsfmbgcvihsap8sz8c2n3qs439q44i3pwrms2nv3xcnf1sclj9"))))
  282. (build-system gnu-build-system)
  283. (native-inputs (list python-wrapper))
  284. (arguments
  285. `(#:tests? #f ; no check target
  286. #:make-flags '("EXTRAVERSION=-guix") ;upstream wants distros to set this
  287. #:modules (,@%gnu-build-system-modules
  288. (ice-9 match))
  289. #:phases
  290. (modify-phases %standard-phases
  291. (replace 'configure
  292. (lambda _
  293. ;; Create the ".version" file that is present in release tarballs.
  294. ;; Otherwise this will be regarded as an "unclean" build, and the
  295. ;; build system ends up encoding the build date in the binaries.
  296. (call-with-output-file ".version"
  297. (lambda (port)
  298. (format port ,(package-version this-package))))
  299. (setenv "CC" "gcc")))
  300. (add-after 'build 'build-vgabios
  301. (lambda* (#:key (make-flags ''()) #:allow-other-keys)
  302. (for-each
  303. (match-lambda
  304. ((target . config)
  305. (let* ((dot-config (string-append (getcwd) "/" target "/.config"))
  306. (flags (append make-flags
  307. (list (string-append "KCONFIG_CONFIG="
  308. dot-config)
  309. (string-append "OUT=" target "/")))))
  310. (mkdir target)
  311. (call-with-output-file dot-config
  312. (lambda (port)
  313. (for-each (lambda (entry)
  314. (if (string-suffix? "=n" entry)
  315. (format port "# CONFIG_~a is not set~%"
  316. (string-drop-right entry 2))
  317. (format port "CONFIG_~a~%" entry)))
  318. (cons "BUILD_VGABIOS=y" config))))
  319. (apply invoke "make" (append flags '("oldnoconfig")))
  320. (apply invoke "make" flags)
  321. (link (string-append target "/bios.bin")
  322. (string-append "out/" target ".bin")))))
  323. ;; These tuples are modelled after Debians packaging:
  324. ;; https://salsa.debian.org/qemu-team/seabios/-/blob/master/debian/rules
  325. '(("ati" . ("VGA_ATI=y" "VGA_PCI=y"))
  326. ("bochs-display" . ("DISPLAY_BOCHS=y" "VGA_PCI=y"))
  327. ("cirrus" . ("VGA_CIRRUS=y" "VGA_PCI=y"))
  328. ("stdvga" . ("VGA_BOCHS=y" "VGA_PCI=y"))
  329. ("virtio" . ("VGA_BOCHS_VIRTIO=y" "VGA_PCI=y"))
  330. ("vmware" . ("VGA_BOCHS_VMWARE=y" "VGA_PCI=y"))
  331. ("qxl" . ("VGA_BOCHS_QXL=y" "VGA_PCI=y"))
  332. ("isavga" . ("VGA_BOCHS=y" "VGA_PCI=n"))
  333. ("ramfb" . ("VGA_RAMFB=y" "VGA_PCI=n"))))))
  334. (replace 'install
  335. (lambda* (#:key outputs #:allow-other-keys)
  336. (let* ((out (assoc-ref outputs "out"))
  337. (fmw (string-append out "/share/firmware")))
  338. (mkdir-p fmw)
  339. (copy-file "out/bios.bin" (string-append fmw "/bios.bin"))
  340. (for-each (lambda (bios)
  341. (install-file bios fmw))
  342. (find-files "out" "\\.bin$"))
  343. (with-directory-excursion fmw
  344. ;; QEMU 1.7 and later looks only for the latter.
  345. (symlink "bios.bin" "bios-256k.bin"))))))))
  346. (home-page "https://www.seabios.org/SeaBIOS")
  347. (synopsis "x86 BIOS implementation")
  348. (description "SeaBIOS is an implementation of a 16bit x86 BIOS. SeaBIOS
  349. can run in an emulator or it can run natively on X86 hardware with the use of
  350. coreboot.")
  351. ;; Dual licensed.
  352. (license (list license:gpl3+ license:lgpl3+
  353. ;; src/fw/acpi-dsdt.dsl is lgpl2
  354. license:lgpl2.1
  355. ;; src/fw/lzmadecode.c and src/fw/lzmadecode.h are lgpl3+ and
  356. ;; cpl with a linking exception.
  357. license:cpl1.0))))
  358. ;; OVMF is part of the edk2 source tree.
  359. (define edk2-commit "13a50a6fe1dcfa6600c38456ee24e0f9ecf51b5f")
  360. (define edk2-version (git-version "20170116" "1" edk2-commit))
  361. (define edk2-origin
  362. (origin
  363. (method git-fetch)
  364. (uri (git-reference
  365. (url "https://github.com/tianocore/edk2")
  366. (commit edk2-commit)))
  367. (file-name (git-file-name "edk2" edk2-version))
  368. (sha256
  369. (base32
  370. "1gy2332kdqk8bjzpcsripx10896rbvgl0ic7r344kmpiwdgm948b"))))
  371. (define-public ovmf
  372. (package
  373. (name "ovmf")
  374. (version edk2-version)
  375. (source edk2-origin)
  376. (build-system gnu-build-system)
  377. (native-inputs
  378. `(("acpica" ,acpica)
  379. ("gcc@5" ,gcc-5)
  380. ("nasm" ,nasm)
  381. ("python-2" ,python-2)
  382. ("util-linux" ,util-linux "lib")))
  383. (arguments
  384. `(#:tests? #f ; No check target.
  385. #:phases
  386. (modify-phases %standard-phases
  387. ;; Hide the default GCC from CPLUS_INCLUDE_PATH to prevent it from
  388. ;; shadowing the version of GCC provided in native-inputs.
  389. (add-after 'set-paths 'hide-gcc7
  390. (lambda* (#:key inputs #:allow-other-keys)
  391. (let ((gcc (assoc-ref inputs "gcc")))
  392. (setenv "CPLUS_INCLUDE_PATH"
  393. (string-join
  394. (delete (string-append gcc "/include/c++")
  395. (string-split (getenv "CPLUS_INCLUDE_PATH")
  396. #\:))
  397. ":"))
  398. #t)))
  399. (replace 'configure
  400. (lambda _
  401. (let* ((cwd (getcwd))
  402. (tools (string-append cwd "/BaseTools"))
  403. (bin (string-append tools "/BinWrappers/PosixLike")))
  404. (setenv "WORKSPACE" cwd)
  405. (setenv "EDK_TOOLS_PATH" tools)
  406. (setenv "PATH" (string-append (getenv "PATH") ":" bin))
  407. ; FIXME: The below script errors out. When using 'invoke' instead
  408. ; of 'system*' this causes the build to fail.
  409. (system* "bash" "edksetup.sh")
  410. (substitute* "Conf/target.txt"
  411. (("^TARGET[ ]*=.*$") "TARGET = RELEASE\n")
  412. (("^MAX_CONCURRENT_THREAD_NUMBER[ ]*=.*$")
  413. (format #f "MAX_CONCURRENT_THREAD_NUMBER = ~a~%"
  414. (number->string (parallel-job-count)))))
  415. ;; Build build support.
  416. (setenv "BUILD_CC" "gcc")
  417. (invoke "make" "-C" tools)
  418. #t)))
  419. (replace 'build
  420. (lambda _
  421. (invoke "build" "-a" "IA32" "-t" "GCC49"
  422. "-p" "OvmfPkg/OvmfPkgIa32.dsc")))
  423. ,@(if (string=? "x86_64-linux" (%current-system))
  424. '((add-after 'build 'build-x64
  425. (lambda _
  426. (invoke "build" "-a" "X64" "-t" "GCC49"
  427. "-p" "OvmfPkg/OvmfPkgX64.dsc"))))
  428. '())
  429. (replace 'install
  430. (lambda* (#:key outputs #:allow-other-keys)
  431. (let* ((out (assoc-ref outputs "out"))
  432. (fmw (string-append out "/share/firmware")))
  433. (mkdir-p fmw)
  434. (copy-file "Build/OvmfIa32/RELEASE_GCC49/FV/OVMF.fd"
  435. (string-append fmw "/ovmf_ia32.bin"))
  436. ,@(if (string=? "x86_64-linux" (%current-system))
  437. '((copy-file "Build/OvmfX64/RELEASE_GCC49/FV/OVMF.fd"
  438. (string-append fmw "/ovmf_x64.bin")))
  439. '()))
  440. #t)))))
  441. (supported-systems '("x86_64-linux" "i686-linux"))
  442. (home-page "https://www.tianocore.org")
  443. (synopsis "UEFI firmware for QEMU")
  444. (description "OVMF is an EDK II based project to enable UEFI support for
  445. Virtual Machines. OVMF contains a sample UEFI firmware for QEMU and KVM.")
  446. (license (list license:expat
  447. license:bsd-2 license:bsd-3 license:bsd-4))))
  448. (define-public ovmf-aarch64
  449. (package
  450. (inherit ovmf)
  451. (name "ovmf-aarch64")
  452. (native-inputs
  453. `(,@(package-native-inputs ovmf)
  454. ,@(if (not (string-prefix? "aarch64" (%current-system)))
  455. `(("cross-gcc" ,(cross-gcc "aarch64-linux-gnu"))
  456. ("cross-binutils" ,(cross-binutils "aarch64-linux-gnu")))
  457. '())))
  458. (arguments
  459. (substitute-keyword-arguments (package-arguments ovmf)
  460. ((#:phases phases)
  461. `(modify-phases ,phases
  462. (add-before 'configure 'set-env
  463. (lambda _
  464. ,@(if (not (string-prefix? "aarch64" (%current-system)))
  465. `((setenv "GCC49_AARCH64_PREFIX" "aarch64-linux-gnu-"))
  466. '())
  467. #t))
  468. (replace 'build
  469. (lambda _
  470. (invoke "build" "-a" "AARCH64" "-t" "GCC49"
  471. "-p" "ArmVirtPkg/ArmVirtQemu.dsc")))
  472. (delete 'build-x64)
  473. (replace 'install
  474. (lambda* (#:key outputs #:allow-other-keys)
  475. (let* ((out (assoc-ref outputs "out"))
  476. (fmw (string-append out "/share/firmware")))
  477. (mkdir-p fmw)
  478. (copy-file "Build/ArmVirtQemu-AARCH64/RELEASE_GCC49/FV/QEMU_EFI.fd"
  479. (string-append fmw "/ovmf_aarch64.bin"))
  480. #t)))))))
  481. (supported-systems %supported-systems)))
  482. (define-public ovmf-arm
  483. (package
  484. (inherit ovmf)
  485. (name "ovmf-arm")
  486. (native-inputs
  487. `(,@(package-native-inputs ovmf)
  488. ,@(if (not (string-prefix? "armhf" (%current-system)))
  489. `(("cross-gcc" ,(cross-gcc "arm-linux-gnueabihf"))
  490. ("cross-binutils" ,(cross-binutils "arm-linux-gnueabihf")))
  491. '())))
  492. (arguments
  493. (substitute-keyword-arguments (package-arguments ovmf)
  494. ((#:phases phases)
  495. `(modify-phases ,phases
  496. (add-before 'configure 'set-env
  497. (lambda _
  498. ,@(if (not (string-prefix? "armhf" (%current-system)))
  499. `((setenv "GCC49_ARM_PREFIX" "arm-linux-gnueabihf-"))
  500. '())
  501. #t))
  502. (replace 'build
  503. (lambda _
  504. (invoke "build" "-a" "ARM" "-t" "GCC49"
  505. "-p" "ArmVirtPkg/ArmVirtQemu.dsc")))
  506. (delete 'build-x64)
  507. (replace 'install
  508. (lambda* (#:key outputs #:allow-other-keys)
  509. (let* ((out (assoc-ref outputs "out"))
  510. (fmw (string-append out "/share/firmware")))
  511. (mkdir-p fmw)
  512. (copy-file "Build/ArmVirtQemu-ARM/RELEASE_GCC49/FV/QEMU_EFI.fd"
  513. (string-append fmw "/ovmf_arm.bin"))
  514. #t)))))))
  515. (supported-systems %supported-systems)))
  516. (define* (make-arm-trusted-firmware platform #:optional (arch "aarch64"))
  517. (package
  518. (name (string-append "arm-trusted-firmware-" platform))
  519. (version "2.6")
  520. (source
  521. (origin
  522. (method git-fetch)
  523. (uri (git-reference
  524. ;; There are only GitHub generated release snapshots.
  525. (url "https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/")
  526. (commit (string-append "v" version))))
  527. (file-name (git-file-name "arm-trusted-firmware" version))
  528. (sha256
  529. (base32
  530. "1j0rn33pwgmksqliwf2npm2px84qmbyma9iq8zpllwfc7dsl6gx9"))))
  531. (build-system gnu-build-system)
  532. (arguments
  533. `(#:phases
  534. (modify-phases %standard-phases
  535. (delete 'configure) ; no configure script
  536. ;; Remove binary blobs which do not contain source or proper license.
  537. (add-after 'unpack 'remove-binary-blobs
  538. (lambda _
  539. (for-each (lambda (file)
  540. (delete-file file))
  541. (find-files "." ".*\\.bin$"))))
  542. (replace 'install
  543. (lambda* (#:key outputs #:allow-other-keys)
  544. (let ((out (assoc-ref outputs "out"))
  545. (bin (find-files "." ".*\\.(bin|elf)$")))
  546. (for-each
  547. (lambda (file)
  548. (install-file file out))
  549. bin))
  550. #t)))
  551. #:make-flags (list (string-append "PLAT=" ,platform)
  552. ,@(if (and (not (string-prefix? "aarch64"
  553. (%current-system)))
  554. (string-prefix? "aarch64" arch))
  555. `("CROSS_COMPILE=aarch64-linux-gnu-")
  556. '())
  557. ,@(if (and (not (string-prefix? "armhf"
  558. (%current-system)))
  559. (string-prefix? "armhf" arch))
  560. `("CROSS_COMPILE=arm-linux-gnueabihf-")
  561. '())
  562. "DEBUG=1")
  563. #:tests? #f)) ; no tests
  564. (native-inputs
  565. (let ((system (%current-system)))
  566. (cond
  567. ((and (not (string-prefix? "aarch64" system))
  568. (string-prefix? "aarch64" arch))
  569. (list (cross-gcc "aarch64-linux-gnu")
  570. (cross-binutils "aarch64-linux-gnu")))
  571. ((and (not (string-prefix? "armhf" system))
  572. (string-prefix? "armhf" arch))
  573. (list (cross-gcc "arm-linux-gnueabihf")
  574. (cross-binutils "arm-linux-gnueabihf")))
  575. (else '()))))
  576. (home-page "https://www.trustedfirmware.org/")
  577. (synopsis "Implementation of \"secure world software\"")
  578. (description
  579. "ARM Trusted Firmware provides a reference implementation of secure world
  580. software for ARMv7A and ARMv8-A, including a Secure Monitor executing at
  581. @dfn{Exception Level 3} (EL3). It implements various ARM interface standards,
  582. such as:
  583. @enumerate
  584. @item The Power State Coordination Interface (PSCI)
  585. @item Trusted Board Boot Requirements (TBBR, ARM DEN0006C-1)
  586. @item SMC Calling Convention
  587. @item System Control and Management Interface
  588. @item Software Delegated Exception Interface (SDEI)
  589. @end enumerate\n")
  590. (license (list license:bsd-3
  591. license:bsd-2)))) ; libfdt
  592. (define-public arm-trusted-firmware-sun50i-a64
  593. (let ((base (make-arm-trusted-firmware "sun50i_a64")))
  594. (package
  595. (inherit base)
  596. (name "arm-trusted-firmware-sun50i-a64"))))
  597. (define-public arm-trusted-firmware-rk3328
  598. (make-arm-trusted-firmware "rk3328"))
  599. (define-public arm-trusted-firmware-rk3399
  600. (let ((base (make-arm-trusted-firmware "rk3399")))
  601. (package
  602. (inherit base)
  603. (name "arm-trusted-firmware-rk3399")
  604. (native-inputs
  605. (modify-inputs (package-native-inputs base)
  606. (prepend
  607. (cross-gcc "arm-none-eabi")
  608. (cross-binutils "arm-none-eabi")))))))
  609. (define-public arm-trusted-firmware-imx8mq
  610. (let ((base (make-arm-trusted-firmware "imx8mq")))
  611. (package
  612. (inherit base)
  613. (arguments
  614. (substitute-keyword-arguments (package-arguments base)
  615. ((#:make-flags flags ''())
  616. ;; Adding debug symbols causes the size to exceed limits.
  617. #~(delete "DEBUG=1" #$flags)))))))