Merge branch 'master' into core-updates
[jackhill/guix/guix.git] / gnu / packages / firmware.scm
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 Tobias Geerinckx-Rice <me@tobias.gr>
7 ;;; Copyright © 2018 Vagrant Cascadian <vagrant@debian.org>
8 ;;; Copyright © 2019 Mathieu Othacehe <m.othacehe@gmail.com>
9 ;;;
10 ;;; This file is part of GNU Guix.
11 ;;;
12 ;;; GNU Guix is free software; you can redistribute it and/or modify it
13 ;;; under the terms of the GNU General Public License as published by
14 ;;; the Free Software Foundation; either version 3 of the License, or (at
15 ;;; your option) any later version.
16 ;;;
17 ;;; GNU Guix is distributed in the hope that it will be useful, but
18 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;;; GNU General Public License for more details.
21 ;;;
22 ;;; You should have received a copy of the GNU General Public License
23 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
24
25 (define-module (gnu packages firmware)
26 #:use-module ((guix licenses) #:prefix license:)
27 #:use-module (guix packages)
28 #:use-module (guix download)
29 #:use-module (guix utils)
30 #:use-module (guix git-download)
31 #:use-module (guix build-system gnu)
32 #:use-module (gnu packages)
33 #:use-module (gnu packages admin)
34 #:use-module (gnu packages assembly)
35 #:use-module (gnu packages bison)
36 #:use-module (gnu packages cmake)
37 #:use-module (gnu packages cross-base)
38 #:use-module (gnu packages flex)
39 #:use-module (gnu packages gcc)
40 #:use-module (gnu packages linux)
41 #:use-module (gnu packages perl)
42 #:use-module (gnu packages python))
43
44 (define-public ath9k-htc-firmware
45 (package
46 (name "ath9k-htc-firmware")
47 (version "1.4.0")
48 (source (origin
49 (method git-fetch)
50 (uri (git-reference
51 (url "https://github.com/qca/open-ath9k-htc-firmware.git")
52 (commit version)))
53 (sha256
54 (base32
55 "16jbj8avg5jkgvq5lxm0hdxxn4c3zn7fx8b4nxllvr024apk9w23"))
56 (file-name (string-append name "-" version "-checkout"))
57 (patches (search-patches "ath9k-htc-firmware-objcopy.patch"))))
58 (build-system gnu-build-system)
59 (arguments
60 '(#:phases
61 (modify-phases %standard-phases
62 (add-before 'configure 'pre-configure
63 (lambda* (#:key inputs native-inputs #:allow-other-keys)
64 (chdir "target_firmware")
65
66 ;; 'configure' is a simple script that runs 'cmake' with
67 ;; the right flags.
68 (substitute* "configure"
69 (("^TOOLCHAIN=.*$")
70 (string-append "TOOLCHAIN="
71 (assoc-ref (or native-inputs inputs) "cross-gcc")
72 "\n")))
73 #t))
74 (replace 'install
75 (lambda* (#:key outputs #:allow-other-keys)
76 (let* ((out (assoc-ref outputs "out"))
77 (fw-dir (string-append out "/lib/firmware")))
78 (for-each (lambda (file)
79 (install-file file fw-dir))
80 (find-files "." "\\.fw$"))
81 #t))))
82 #:tests? #f))
83
84 ;; The firmware is cross-compiled using a "bare bones" compiler (no libc.)
85 ;; Use our own tool chain for that.
86 (native-inputs `(("cross-gcc" ,(cross-gcc "xtensa-elf"))
87 ("cross-binutils" ,(cross-binutils "xtensa-elf"))
88 ("cmake" ,cmake-minimal)
89 ("perl" ,perl)))
90 (home-page "http://wireless.kernel.org/en/users/Drivers/ath9k_htc")
91 (synopsis "Firmware for the Atheros AR7010 and AR9271 USB 802.11n NICs")
92 (description
93 "This is the firmware for the Qualcomm Atheros AR7010 and AR9271 USB
94 802.11n NICs (aka Wi-Fi USB dongles). It is used by the ath9k driver of
95 Linux-libre.")
96 (license (license:non-copyleft "http://directory.fsf.org/wiki/License:ClearBSD"))))
97
98 (define-public b43-tools
99 (let ((commit "27892ef741e7f1d08cb939744f8b8f5dac7b04ae")
100 (revision "1"))
101 (package
102 (name "b43-tools")
103 (version (git-version "0.0.0" revision commit))
104 (source
105 (origin
106 (method git-fetch)
107 (uri (git-reference
108 (url "http://git.bues.ch/git/b43-tools.git")
109 (commit commit)))
110 (file-name (string-append name "-" version "-checkout"))
111 (sha256
112 (base32
113 "1wgmj4d65izbhprwb5bcwimc2ryv19b9066lqzy4sa5m6wncm9cn"))))
114 (build-system gnu-build-system)
115 (native-inputs
116 `(("flex" ,flex)
117 ("bison" ,bison)))
118 (arguments
119 `(#:modules ((srfi srfi-1)
120 (guix build gnu-build-system)
121 (guix build utils))
122 #:tests? #f ; no tests
123 #:phases
124 (let ((subdirs '("assembler" "disassembler")))
125 (modify-phases %standard-phases
126 (delete 'configure) ; no configure script
127 (add-before 'build 'patch-/bin/true
128 (lambda _
129 (substitute* (find-files "." "Makefile")
130 (("/bin/true") ":"))
131 #t))
132 (replace 'build
133 (lambda _
134 (for-each (lambda (dir)
135 (invoke "make" "-C" dir "CC=gcc"))
136 subdirs)
137 #t))
138 (replace 'install
139 (lambda* (#:key outputs #:allow-other-keys)
140 (let ((out (assoc-ref outputs "out")))
141 (mkdir-p (string-append out "/bin"))
142 (for-each (lambda (dir)
143 (invoke "make" "-C" dir
144 (string-append "PREFIX=" out)
145 "install"))
146 subdirs)
147 #t)))))))
148 (home-page
149 "https://bues.ch/cms/hacking/misc.html#linux_b43_driver_firmware_tools")
150 (synopsis "Collection of tools for the b43 wireless driver")
151 (description
152 "The b43 firmware tools is a collection of firmware extractor,
153 assembler, disassembler, and debugging tools for the Linux kernel b43 wireless
154 driver.")
155 (license license:gpl2))))
156
157 (define-public openfwwf-firmware
158 (package
159 (name "openfwwf-firmware")
160 (version "5.2")
161 (source
162 (origin
163 (method url-fetch)
164 (uri (string-append "http://netweb.ing.unibs.it/~openfwwf/firmware/"
165 "openfwwf-" version ".tar.gz"))
166 (sha256
167 (base32
168 "1p60gdi7w88s7qw82d3g9v7mk887mhvidf4l5q5hh09j10h37q4x"))))
169 (build-system gnu-build-system)
170 (native-inputs
171 `(("b43-tools" ,b43-tools)))
172 (arguments
173 `(#:make-flags (list (string-append "PREFIX="
174 (assoc-ref %outputs "out")
175 "/lib/firmware/b43-open"))
176 #:tests? #f ;no tests
177 #:phases (modify-phases %standard-phases
178 (delete 'configure))))
179 (home-page "http://netweb.ing.unibs.it/~openfwwf/")
180 (synopsis "Firmware for BCM43xx devices")
181 (description
182 "This is firmware from Open FirmWare for WiFi networks (OpenFWWF) for the
183 Broadcom/AirForce chipset BCM43xx with Wireless-Core Revision 5. It is used
184 by the b43-open driver of Linux-libre.")
185 (license license:gpl2)))
186
187 (define-public seabios
188 (package
189 (name "seabios")
190 (version "1.12.1")
191 (source
192 (origin
193 (method git-fetch)
194 (uri (git-reference
195 (url "https://review.coreboot.org/seabios.git")
196 (commit (string-append "rel-" version))))
197 (file-name (git-file-name name version))
198 (sha256
199 (base32 "1g9y03r5ky58q2g9rhbwfhs42z0zb9f59wfxpwh6zjqa6fyv1r80"))))
200 (build-system gnu-build-system)
201 (native-inputs
202 `(("python-2" ,python-2)))
203 (arguments
204 `(#:tests? #f ; no check target
205 #:phases
206 (modify-phases %standard-phases
207 (replace 'configure
208 (lambda _
209 (setenv "CC" "gcc")
210 #t))
211 (replace 'install
212 (lambda* (#:key outputs #:allow-other-keys)
213 (let* ((out (assoc-ref outputs "out"))
214 (fmw (string-append out "/share/firmware")))
215 (mkdir-p fmw)
216 (copy-file "out/bios.bin" (string-append fmw "/bios.bin"))
217 #t))))))
218 (home-page "https://www.seabios.org/SeaBIOS")
219 (synopsis "x86 BIOS implementation")
220 (description "SeaBIOS is an implementation of a 16bit x86 BIOS. SeaBIOS
221 can run in an emulator or it can run natively on X86 hardware with the use of
222 coreboot.")
223 ;; Dual licensed.
224 (license (list license:gpl3+ license:lgpl3+
225 ;; src/fw/acpi-dsdt.dsl is lgpl2
226 license:lgpl2.1
227 ;; src/fw/lzmadecode.c and src/fw/lzmadecode.h are lgpl3+ and
228 ;; cpl with a linking exception.
229 license:cpl1.0))))
230
231 ;; OVMF is part of the edk2 source tree.
232 (define edk2-commit "13a50a6fe1dcfa6600c38456ee24e0f9ecf51b5f")
233 (define edk2-version (git-version "20170116" "1" edk2-commit))
234 (define edk2-origin
235 (origin
236 (method git-fetch)
237 (uri (git-reference
238 (url "https://github.com/tianocore/edk2")
239 (commit edk2-commit)))
240 (file-name (git-file-name "edk2" edk2-version))
241 (sha256
242 (base32
243 "1gy2332kdqk8bjzpcsripx10896rbvgl0ic7r344kmpiwdgm948b"))))
244
245 (define-public ovmf
246 (package
247 (name "ovmf")
248 (version edk2-version)
249 (source edk2-origin)
250 (build-system gnu-build-system)
251 (native-inputs
252 `(("acpica" ,acpica)
253 ("gcc" ,gcc-5)
254 ("nasm" ,nasm)
255 ("python-2" ,python-2)
256 ("util-linux" ,util-linux)))
257 (arguments
258 `(#:tests? #f ; No check target.
259 #:phases
260 (modify-phases %standard-phases
261 (replace 'configure
262 (lambda _
263 (let* ((cwd (getcwd))
264 (tools (string-append cwd "/BaseTools"))
265 (bin (string-append tools "/BinWrappers/PosixLike")))
266 (setenv "WORKSPACE" cwd)
267 (setenv "EDK_TOOLS_PATH" tools)
268 (setenv "PATH" (string-append (getenv "PATH") ":" bin))
269 ; FIXME: The below script errors out. When using 'invoke' instead
270 ; of 'system*' this causes the build to fail.
271 (system* "bash" "edksetup.sh")
272 (substitute* "Conf/target.txt"
273 (("^TARGET[ ]*=.*$") "TARGET = RELEASE\n")
274 (("^MAX_CONCURRENT_THREAD_NUMBER[ ]*=.*$")
275 (format #f "MAX_CONCURRENT_THREAD_NUMBER = ~a~%"
276 (number->string (parallel-job-count)))))
277 ;; Build build support.
278 (setenv "BUILD_CC" "gcc")
279 (invoke "make" "-C" tools)
280 #t)))
281 (replace 'build
282 (lambda _
283 (invoke "build" "-a" "IA32" "-t" "GCC49"
284 "-p" "OvmfPkg/OvmfPkgIa32.dsc")))
285 ,@(if (string=? "x86_64-linux" (%current-system))
286 '((add-after 'build 'build-x64
287 (lambda _
288 (invoke "build" "-a" "X64" "-t" "GCC49"
289 "-p" "OvmfPkg/OvmfPkgX64.dsc"))))
290 '())
291 (replace 'install
292 (lambda* (#:key outputs #:allow-other-keys)
293 (let* ((out (assoc-ref outputs "out"))
294 (fmw (string-append out "/share/firmware")))
295 (mkdir-p fmw)
296 (copy-file "Build/OvmfIa32/RELEASE_GCC49/FV/OVMF.fd"
297 (string-append fmw "/ovmf_ia32.bin"))
298 ,@(if (string=? "x86_64-linux" (%current-system))
299 '((copy-file "Build/OvmfX64/RELEASE_GCC49/FV/OVMF.fd"
300 (string-append fmw "/ovmf_x64.bin")))
301 '()))
302 #t)))))
303 (supported-systems '("x86_64-linux" "i686-linux"))
304 (home-page "https://www.tianocore.org")
305 (synopsis "UEFI firmware for QEMU")
306 (description "OVMF is an EDK II based project to enable UEFI support for
307 Virtual Machines. OVMF contains a sample UEFI firmware for QEMU and KVM.")
308 (license (list license:expat
309 license:bsd-2 license:bsd-3 license:bsd-4))))
310
311 (define-public ovmf-aarch64
312 (package
313 (inherit ovmf)
314 (name "ovmf-aarch64")
315 (native-inputs
316 `(,@(package-native-inputs ovmf)
317 ,@(if (not (string-prefix? "aarch64" (%current-system)))
318 `(("cross-gcc" ,(cross-gcc "aarch64-linux-gnu"))
319 ("cross-binutils" ,(cross-binutils "aarch64-linux-gnu")))
320 '())))
321 (arguments
322 (substitute-keyword-arguments (package-arguments ovmf)
323 ((#:phases phases)
324 `(modify-phases ,phases
325 (add-before 'configure 'set-env
326 (lambda _
327 ,@(if (not (string-prefix? "aarch64" (%current-system)))
328 `((setenv "GCC49_AARCH64_PREFIX" "aarch64-linux-gnu-"))
329 '())
330 #t))
331 (replace 'build
332 (lambda _
333 (invoke "build" "-a" "AARCH64" "-t" "GCC49"
334 "-p" "ArmVirtPkg/ArmVirtQemu.dsc")))
335 (delete 'build-x64)
336 (replace 'install
337 (lambda* (#:key outputs #:allow-other-keys)
338 (let* ((out (assoc-ref outputs "out"))
339 (fmw (string-append out "/share/firmware")))
340 (mkdir-p fmw)
341 (copy-file "Build/ArmVirtQemu-AARCH64/RELEASE_GCC49/FV/QEMU_EFI.fd"
342 (string-append fmw "/ovmf_aarch64.bin"))
343 #t)))))))
344 (supported-systems %supported-systems)))
345
346 (define-public ovmf-arm
347 (package
348 (inherit ovmf)
349 (name "ovmf-arm")
350 (native-inputs
351 `(,@(package-native-inputs ovmf)
352 ,@(if (not (string-prefix? "armhf" (%current-system)))
353 `(("cross-gcc" ,(cross-gcc "arm-linux-gnueabihf"))
354 ("cross-binutils" ,(cross-binutils "arm-linux-gnueabihf")))
355 '())))
356 (arguments
357 (substitute-keyword-arguments (package-arguments ovmf)
358 ((#:phases phases)
359 `(modify-phases ,phases
360 (add-before 'configure 'set-env
361 (lambda _
362 ,@(if (not (string-prefix? "armhf" (%current-system)))
363 `((setenv "GCC49_ARM_PREFIX" "arm-linux-gnueabihf-"))
364 '())
365 #t))
366 (replace 'build
367 (lambda _
368 (invoke "build" "-a" "ARM" "-t" "GCC49"
369 "-p" "ArmVirtPkg/ArmVirtQemu.dsc")))
370 (delete 'build-x64)
371 (replace 'install
372 (lambda* (#:key outputs #:allow-other-keys)
373 (let* ((out (assoc-ref outputs "out"))
374 (fmw (string-append out "/share/firmware")))
375 (mkdir-p fmw)
376 (copy-file "Build/ArmVirtQemu-ARM/RELEASE_GCC49/FV/QEMU_EFI.fd"
377 (string-append fmw "/ovmf_arm.bin"))
378 #t)))))))
379 (supported-systems %supported-systems)))
380
381 (define* (make-arm-trusted-firmware platform #:optional (arch "aarch64"))
382 (package
383 (name (string-append "arm-trusted-firmware-" platform))
384 (version "2.1")
385 (source
386 (origin
387 (method git-fetch)
388 (uri (git-reference
389 ;; There are only GitHub generated release snapshots.
390 (url "https://github.com/ARM-software/arm-trusted-firmware.git")
391 (commit (string-append "v" version))))
392 (file-name (git-file-name "arm-trusted-firmware" version))
393 (patches (search-patches
394 "arm-trusted-firmware-optional-bin-generation.patch"
395 "arm-trusted-firmware-rockchip-disable-binary.patch"
396 "arm-trusted-firmware-disable-hdcp.patch"))
397 (sha256
398 (base32
399 "1gy5qskrjy8n3kxdcm1dx8b45l5b75n0pm8pq80wl6xic1ycy24r"))))
400 (build-system gnu-build-system)
401 (arguments
402 `(#:phases
403 (modify-phases %standard-phases
404 (delete 'configure) ; no configure script
405 ;; Remove binary blobs which do not contain source or proper license.
406 (add-after 'unpack 'remove-binary-blobs
407 (lambda _
408 (for-each (lambda (file)
409 (delete-file file))
410 (find-files "." ".*\\.bin$"))))
411 (replace 'install
412 (lambda* (#:key outputs #:allow-other-keys)
413 (let ((out (assoc-ref outputs "out"))
414 (bin (find-files "." ".*\\.(bin|elf)$")))
415 (for-each
416 (lambda (file)
417 (install-file file out))
418 bin))
419 #t)))
420 #:make-flags (list (string-append "PLAT=" ,platform)
421 ,@(if (and (not (string-prefix? "aarch64"
422 (%current-system)))
423 (string-prefix? "aarch64" arch))
424 `("CROSS_COMPILE=aarch64-linux-gnu-")
425 '())
426 ,@(if (and (not (string-prefix? "armhf"
427 (%current-system)))
428 (string-prefix? "armhf" arch))
429 `("CROSS_COMPILE=arm-linux-gnueabihf-")
430 '())
431 "DEBUG=1")
432 #:tests? #f)) ; no tests
433 (native-inputs
434 `(,@(if (and (not (string-prefix? "aarch64" (%current-system)))
435 (string-prefix? "aarch64" arch))
436 ;; gcc-7 since it is used for u-boot, which needs gcc-7.
437 `(("cross-gcc" ,(cross-gcc "aarch64-linux-gnu" #:xgcc gcc-7))
438 ("cross-binutils" ,(cross-binutils "aarch64-linux-gnu")))
439 '())
440 ,@(if (and (not (string-prefix? "armhf" (%current-system)))
441 (string-prefix? "armhf" arch))
442 ;; gcc-7 since it is used for u-boot, which needs gcc-7.
443 `(("cross-gcc" ,(cross-gcc "arm-linux-gnueabihf" #:xgcc gcc-7))
444 ("cross-binutils" ,(cross-binutils "arm-linux-gnueabihf")))
445 '())
446 ))
447 (home-page "https://github.com/ARM-software/arm-trusted-firmware")
448 (synopsis "Implementation of \"secure world software\"")
449 (description
450 "ARM Trusted Firmware provides a reference implementation of secure world
451 software for ARMv7A and ARMv8-A, including a Secure Monitor executing at
452 @dfn{Exception Level 3} (EL3). It implements various ARM interface standards,
453 such as:
454 @enumerate
455 @item The Power State Coordination Interface (PSCI)
456 @item Trusted Board Boot Requirements (TBBR, ARM DEN0006C-1)
457 @item SMC Calling Convention
458 @item System Control and Management Interface
459 @item Software Delegated Exception Interface (SDEI)
460 @end enumerate\n")
461 (license (list license:bsd-3
462 license:bsd-2)))) ; libfdt
463
464 (define-public arm-trusted-firmware-sun50i-a64
465 (let ((base (make-arm-trusted-firmware "sun50i_a64")))
466 (package
467 (inherit base)
468 (name "arm-trusted-firmware-sun50i-a64"))))
469
470 (define-public arm-trusted-firmware-rk3328
471 (make-arm-trusted-firmware "rk3328"))
472
473 (define-public arm-trusted-firmware-puma-rk3399
474 (let ((base (make-arm-trusted-firmware "rk3399"))
475 ;; Vendor's arm trusted firmware branch hasn't been upstreamed yet.
476 (commit "d71e6d83612df896774ec4c03d49500312d2c324")
477 (revision "1"))
478 (package
479 (inherit base)
480 (name "arm-trusted-firmware-puma-rk3399")
481 (version (git-version "1.3" revision commit))
482 (source
483 (origin
484 (method git-fetch)
485 (uri (git-reference
486 (url "https://git.theobroma-systems.com/arm-trusted-firmware.git")
487 (commit commit)))
488 (file-name (git-file-name name version))
489 (sha256
490 (base32
491 "0vqhwqqh8h9qlkpybg2v94911091c1418bc4pnzq5fd7zf0fjkf8")))))))
492
493 (define-public arm-trusted-firmware-rk3399
494 (let ((base (make-arm-trusted-firmware "rk3399")))
495 (package
496 (inherit base)
497 (name "arm-trusted-firmware-rk3399")
498 (native-inputs
499 `(("cross32-gcc" ,(cross-gcc "arm-none-eabi"))
500 ("cross32-binutils", (cross-binutils "arm-none-eabi"))
501 ,@(package-native-inputs base))))))
502
503 (define-public rk3399-cortex-m0
504 (package
505 (name "rk3399-cortex-m0")
506 (version "1")
507 (source
508 (origin
509 (method git-fetch)
510 (uri (git-reference
511 (url "https://git.theobroma-systems.com/rk3399-cortex-m0.git")
512 (commit (string-append "v" version))))
513 (file-name (git-file-name "rk3399-cortex-m0" version))
514 (sha256
515 (base32
516 "02wz1vkf4j3zc8rx289z76xhrf71jhb2p05lvmygky393a9gjh9w"))))
517 (home-page "https://git.theobroma-systems.com/rk3399-cortex-m0.git/about/")
518 (synopsis "PMU Cortex M0 firmware for RK3399 Q7 (Puma)")
519 (description
520 "Cortex-M0 firmware used with the RK3399 to implement
521 power-management functionality and helpers (e.g. DRAM frequency
522 switching support).\n")
523 (license license:bsd-3)
524 (build-system gnu-build-system)
525 (arguments
526 `(#:phases
527 (modify-phases %standard-phases
528 (delete 'configure)
529 (delete 'check)
530 (replace 'install
531 (lambda* (#:key outputs #:allow-other-keys)
532 (let ((out (assoc-ref outputs "out"))
533 (mzerofiles (find-files "." "rk3399m0.(elf|bin)$")))
534 (for-each
535 (lambda (file)
536 (install-file file out))
537 mzerofiles))
538 #t))
539 (add-before 'build 'setenv
540 (lambda* (#:key inputs #:allow-other-keys)
541 (setenv "CROSS_COMPILE" "arm-none-eabi-")
542 #t)))))
543 (native-inputs `(("cross-gcc" ,(cross-gcc "arm-none-eabi" #:xgcc gcc-7))
544 ("cross-binutils" ,(cross-binutils "arm-none-eabi"))))))