gnu: ovmf: Use gexps.

* gnu/packages/firmware.scm (edk2-commit, edk2-version)
(edk2-origin): Delete variables.
(ovmf)[source]: Define here; it's the only user of it so far.
[native-inputs]: Move below arguments.
[phases]: Use gexps.  Delete trailing #t.
{patch-source}: New phase.
{configure}: Use 'invoke' to execute the 'edksetup.sh' script; delete
associated FIXME comment.
(ovmf-aarch64, ovmf-arm): Adjust accordingly.
This commit is contained in:
Maxim Cournoyer 2022-06-15 21:58:34 -04:00
parent c8803d89fe
commit 1589debbd9
No known key found for this signature in database
GPG key ID: 1260E46482E63562

View file

@ -8,6 +8,7 @@
;;; Copyright © 2019 Mathieu Othacehe <m.othacehe@gmail.com> ;;; Copyright © 2019 Mathieu Othacehe <m.othacehe@gmail.com>
;;; Copyright © 2020, 2021, 2022 Marius Bakke <marius@gnu.org> ;;; Copyright © 2020, 2021, 2022 Marius Bakke <marius@gnu.org>
;;; Copyright © 2021 Petr Hodina <phodina@protonmail.com> ;;; Copyright © 2021 Petr Hodina <phodina@protonmail.com>
;;; Copyright © 2022 Maxim Cournoyer <maxim.cournoyer@gmail.com>
;;; ;;;
;;; This file is part of GNU Guix. ;;; This file is part of GNU Guix.
;;; ;;;
@ -366,39 +367,31 @@ (define-public seabios
;; cpl with a linking exception. ;; cpl with a linking exception.
license:cpl1.0)))) license:cpl1.0))))
;; OVMF is part of the edk2 source tree. (define-public ovmf
(define edk2-commit "13a50a6fe1dcfa6600c38456ee24e0f9ecf51b5f") (let ((commit "13a50a6fe1dcfa6600c38456ee24e0f9ecf51b5f")
(define edk2-version (git-version "20170116" "1" edk2-commit)) (revision "1"))
(define edk2-origin (package
(origin (name "ovmf")
(version (git-version "20170116" revision commit))
(source (origin
(method git-fetch) (method git-fetch)
(uri (git-reference (uri (git-reference
;; OVMF is part of the edk2 source tree.
(url "https://github.com/tianocore/edk2") (url "https://github.com/tianocore/edk2")
(commit edk2-commit))) (commit commit)))
(file-name (git-file-name "edk2" edk2-version)) (file-name (git-file-name name version))
(sha256 (sha256
(base32 (base32
"1gy2332kdqk8bjzpcsripx10896rbvgl0ic7r344kmpiwdgm948b")))) "1gy2332kdqk8bjzpcsripx10896rbvgl0ic7r344kmpiwdgm948b"))))
(define-public ovmf
(package
(name "ovmf")
(version edk2-version)
(source edk2-origin)
(build-system gnu-build-system) (build-system gnu-build-system)
(native-inputs
`(("acpica" ,acpica)
("gcc@5" ,gcc-5)
("nasm" ,nasm)
("python-2" ,python-2)
("util-linux" ,util-linux "lib")))
(arguments (arguments
`(#:tests? #f ; No check target. (list
#:tests? #f ; No check target.
#:phases #:phases
(modify-phases %standard-phases #~(modify-phases %standard-phases
;; Hide the default GCC from CPLUS_INCLUDE_PATH to prevent it from ;; Hide the default GCC from CPLUS_INCLUDE_PATH to prevent it from
;; shadowing the version of GCC provided in native-inputs. ;; shadowing the version of GCC provided in native-inputs.
(add-after 'set-paths 'hide-gcc7 (add-after 'set-paths 'hide-implicit-gcc
(lambda* (#:key inputs #:allow-other-keys) (lambda* (#:key inputs #:allow-other-keys)
(let ((gcc (assoc-ref inputs "gcc"))) (let ((gcc (assoc-ref inputs "gcc")))
(setenv "CPLUS_INCLUDE_PATH" (setenv "CPLUS_INCLUDE_PATH"
@ -406,8 +399,12 @@ (define-public ovmf
(delete (string-append gcc "/include/c++") (delete (string-append gcc "/include/c++")
(string-split (getenv "CPLUS_INCLUDE_PATH") (string-split (getenv "CPLUS_INCLUDE_PATH")
#\:)) #\:))
":")) ":")))))
#t))) (add-after 'unpack 'patch-source
(lambda _
(substitute* "edksetup.sh"
(("^return \\$\\?")
"exit $?"))))
(replace 'configure (replace 'configure
(lambda _ (lambda _
(let* ((cwd (getcwd)) (let* ((cwd (getcwd))
@ -416,9 +413,7 @@ (define-public ovmf
(setenv "WORKSPACE" cwd) (setenv "WORKSPACE" cwd)
(setenv "EDK_TOOLS_PATH" tools) (setenv "EDK_TOOLS_PATH" tools)
(setenv "PATH" (string-append (getenv "PATH") ":" bin)) (setenv "PATH" (string-append (getenv "PATH") ":" bin))
; FIXME: The below script errors out. When using 'invoke' instead (invoke "bash" "edksetup.sh")
; of 'system*' this causes the build to fail.
(system* "bash" "edksetup.sh")
(substitute* "Conf/target.txt" (substitute* "Conf/target.txt"
(("^TARGET[ ]*=.*$") "TARGET = RELEASE\n") (("^TARGET[ ]*=.*$") "TARGET = RELEASE\n")
(("^MAX_CONCURRENT_THREAD_NUMBER[ ]*=.*$") (("^MAX_CONCURRENT_THREAD_NUMBER[ ]*=.*$")
@ -426,71 +421,71 @@ (define-public ovmf
(number->string (parallel-job-count))))) (number->string (parallel-job-count)))))
;; Build build support. ;; Build build support.
(setenv "BUILD_CC" "gcc") (setenv "BUILD_CC" "gcc")
(invoke "make" "-C" tools) (invoke "make" "-C" tools))))
#t)))
(replace 'build (replace 'build
(lambda _ (lambda _
(invoke "build" "-a" "IA32" "-t" "GCC49" (invoke "build" "-a" "IA32" "-t" "GCC49"
"-p" "OvmfPkg/OvmfPkgIa32.dsc"))) "-p" "OvmfPkg/OvmfPkgIa32.dsc")))
,@(if (string=? "x86_64-linux" (%current-system)) #$@(if (string=? "x86_64-linux" (%current-system))
'((add-after 'build 'build-x64 #~((add-after 'build 'build-x64
(lambda _ (lambda _
(invoke "build" "-a" "X64" "-t" "GCC49" (invoke "build" "-a" "X64" "-t" "GCC49"
"-p" "OvmfPkg/OvmfPkgX64.dsc")))) "-p" "OvmfPkg/OvmfPkgX64.dsc"))))
'()) #~())
(replace 'install (replace 'install
(lambda* (#:key outputs #:allow-other-keys) (lambda _
(let* ((out (assoc-ref outputs "out")) (let ((fmw (string-append #$output "/share/firmware")))
(fmw (string-append out "/share/firmware")))
(mkdir-p fmw) (mkdir-p fmw)
(copy-file "Build/OvmfIa32/RELEASE_GCC49/FV/OVMF.fd" (copy-file "Build/OvmfIa32/RELEASE_GCC49/FV/OVMF.fd"
(string-append fmw "/ovmf_ia32.bin")) (string-append fmw "/ovmf_ia32.bin"))
,@(if (string=? "x86_64-linux" (%current-system)) #$@(if (string=? "x86_64-linux" (%current-system))
'((copy-file "Build/OvmfX64/RELEASE_GCC49/FV/OVMF.fd" '((copy-file "Build/OvmfX64/RELEASE_GCC49/FV/OVMF.fd"
(string-append fmw "/ovmf_x64.bin"))) (string-append fmw "/ovmf_x64.bin")))
'())) '())))))))
#t))))) (native-inputs
`(("acpica" ,acpica)
("gcc@5" ,gcc-5)
("nasm" ,nasm)
("python-2" ,python-2)
("util-linux" ,util-linux "lib")))
(supported-systems '("x86_64-linux" "i686-linux")) (supported-systems '("x86_64-linux" "i686-linux"))
(home-page "https://www.tianocore.org") (home-page "https://www.tianocore.org")
(synopsis "UEFI firmware for QEMU") (synopsis "UEFI firmware for QEMU")
(description "OVMF is an EDK II based project to enable UEFI support for (description "OVMF is an EDK II based project to enable UEFI support for
Virtual Machines. OVMF contains a sample UEFI firmware for QEMU and KVM.") Virtual Machines. OVMF contains a sample UEFI firmware for QEMU and KVM.")
(license (list license:expat (license (list license:expat
license:bsd-2 license:bsd-3 license:bsd-4)))) license:bsd-2 license:bsd-3 license:bsd-4)))))
(define-public ovmf-aarch64 (define-public ovmf-aarch64
(package (package
(inherit ovmf) (inherit ovmf)
(name "ovmf-aarch64") (name "ovmf-aarch64")
(native-inputs (native-inputs
`(,@(package-native-inputs ovmf) (append (package-native-inputs ovmf)
,@(if (not (string-prefix? "aarch64" (%current-system))) (if (not (string-prefix? "aarch64" (%current-system)))
`(("cross-gcc" ,(cross-gcc "aarch64-linux-gnu")) `(("cross-gcc" ,(cross-gcc "aarch64-linux-gnu"))
("cross-binutils" ,(cross-binutils "aarch64-linux-gnu"))) ("cross-binutils" ,(cross-binutils "aarch64-linux-gnu")))
'()))) '())))
(arguments (arguments
(substitute-keyword-arguments (package-arguments ovmf) (substitute-keyword-arguments (package-arguments ovmf)
((#:phases phases) ((#:phases phases)
`(modify-phases ,phases #~(modify-phases #$phases
(add-before 'configure 'set-env (add-before 'configure 'set-env
(lambda _ (lambda _
,@(if (not (string-prefix? "aarch64" (%current-system))) #$@(if (not (string-prefix? "aarch64" (%current-system)))
`((setenv "GCC49_AARCH64_PREFIX" "aarch64-linux-gnu-")) #~((setenv "GCC49_AARCH64_PREFIX" "aarch64-linux-gnu-"))
'()) #~())))
#t))
(replace 'build (replace 'build
(lambda _ (lambda _
(invoke "build" "-a" "AARCH64" "-t" "GCC49" (invoke "build" "-a" "AARCH64" "-t" "GCC49"
"-p" "ArmVirtPkg/ArmVirtQemu.dsc"))) "-p" "ArmVirtPkg/ArmVirtQemu.dsc")))
(delete 'build-x64) (delete 'build-x64)
(replace 'install (replace 'install
(lambda* (#:key outputs #:allow-other-keys) (lambda _
(let* ((out (assoc-ref outputs "out")) (let ((fmw (string-append #$output "/share/firmware")))
(fmw (string-append out "/share/firmware")))
(mkdir-p fmw) (mkdir-p fmw)
(copy-file "Build/ArmVirtQemu-AARCH64/RELEASE_GCC49/FV/QEMU_EFI.fd" (copy-file "Build/ArmVirtQemu-AARCH64/RELEASE_GCC49/FV/QEMU_EFI.fd"
(string-append fmw "/ovmf_aarch64.bin")) (string-append fmw "/ovmf_aarch64.bin")))))))))
#t)))))))
(supported-systems %supported-systems))) (supported-systems %supported-systems)))
(define-public ovmf-arm (define-public ovmf-arm
@ -498,34 +493,31 @@ (define-public ovmf-arm
(inherit ovmf) (inherit ovmf)
(name "ovmf-arm") (name "ovmf-arm")
(native-inputs (native-inputs
`(,@(package-native-inputs ovmf) (append (package-native-inputs ovmf)
,@(if (not (string-prefix? "armhf" (%current-system))) (if (not (string-prefix? "armhf" (%current-system)))
`(("cross-gcc" ,(cross-gcc "arm-linux-gnueabihf")) `(("cross-gcc" ,(cross-gcc "arm-linux-gnueabihf"))
("cross-binutils" ,(cross-binutils "arm-linux-gnueabihf"))) ("cross-binutils" ,(cross-binutils "arm-linux-gnueabihf")))
'()))) '())))
(arguments (arguments
(substitute-keyword-arguments (package-arguments ovmf) (substitute-keyword-arguments (package-arguments ovmf)
((#:phases phases) ((#:phases phases)
`(modify-phases ,phases #~(modify-phases #$phases
(add-before 'configure 'set-env (add-before 'configure 'set-env
(lambda _ (lambda _
,@(if (not (string-prefix? "armhf" (%current-system))) #$@(if (not (string-prefix? "armhf" (%current-system)))
`((setenv "GCC49_ARM_PREFIX" "arm-linux-gnueabihf-")) #~((setenv "GCC49_ARM_PREFIX" "arm-linux-gnueabihf-"))
'()) #~())))
#t))
(replace 'build (replace 'build
(lambda _ (lambda _
(invoke "build" "-a" "ARM" "-t" "GCC49" (invoke "build" "-a" "ARM" "-t" "GCC49"
"-p" "ArmVirtPkg/ArmVirtQemu.dsc"))) "-p" "ArmVirtPkg/ArmVirtQemu.dsc")))
(delete 'build-x64) (delete 'build-x64)
(replace 'install (replace 'install
(lambda* (#:key outputs #:allow-other-keys) (lambda _
(let* ((out (assoc-ref outputs "out")) (let ((fmw (string-append #$output "/share/firmware")))
(fmw (string-append out "/share/firmware")))
(mkdir-p fmw) (mkdir-p fmw)
(copy-file "Build/ArmVirtQemu-ARM/RELEASE_GCC49/FV/QEMU_EFI.fd" (copy-file "Build/ArmVirtQemu-ARM/RELEASE_GCC49/FV/QEMU_EFI.fd"
(string-append fmw "/ovmf_arm.bin")) (string-append fmw "/ovmf_arm.bin")))))))))
#t)))))))
(supported-systems %supported-systems))) (supported-systems %supported-systems)))
(define* (make-arm-trusted-firmware platform #:optional (arch "aarch64")) (define* (make-arm-trusted-firmware platform #:optional (arch "aarch64"))