2022-12-19 17:17:39 +01:00
|
|
|
;;; SPDX-License-Identifier: GPL-3.0-or-later
|
2020-01-08 19:23:48 +01:00
|
|
|
;;; Copyright © 2020 Alex Griffin <a@ajgrf.com>
|
|
|
|
|
|
|
|
(define-module (nongnu system linux-initrd)
|
|
|
|
#:use-module (gnu system linux-initrd)
|
|
|
|
#:use-module (guix gexp)
|
|
|
|
#:use-module (guix modules)
|
|
|
|
#:use-module (guix utils)
|
|
|
|
#:use-module (nongnu packages linux)
|
2020-01-08 23:27:45 +01:00
|
|
|
#:use-module (nonguix modules)
|
2020-01-08 19:23:48 +01:00
|
|
|
#:export (microcode-initrd))
|
|
|
|
|
|
|
|
;; See https://www.kernel.org/doc/Documentation/x86/microcode.txt
|
|
|
|
|
|
|
|
(define* (microcode-initrd file-systems
|
|
|
|
#:key
|
|
|
|
(initrd base-initrd)
|
|
|
|
(microcode-packages (list amd-microcode
|
|
|
|
intel-microcode))
|
|
|
|
#:allow-other-keys
|
|
|
|
#:rest rest)
|
|
|
|
"Build INITRD, extended to include x86 processor microcode from
|
|
|
|
MICROCODE-PACKAGES."
|
|
|
|
(let ((args (strip-keyword-arguments '(#:initrd #:microcode-packages) rest)))
|
|
|
|
(combined-initrd (microcode-initrd* microcode-packages)
|
|
|
|
(apply initrd file-systems
|
|
|
|
args))))
|
|
|
|
|
|
|
|
(define (microcode-initrd* microcode-packages)
|
|
|
|
"Build an uncompressed initrd containing x86 processor microcode from
|
|
|
|
MICROCODE-PACKAGES, in the format expected by the kernel."
|
|
|
|
(define builder
|
|
|
|
(with-imported-modules (source-module-closure
|
|
|
|
'((gnu build linux-initrd)
|
|
|
|
(guix build utils)
|
|
|
|
(nonguix build utils))
|
2020-12-18 22:20:23 +01:00
|
|
|
#:select? import-nonguix-module?)
|
2020-01-08 19:23:48 +01:00
|
|
|
#~(begin
|
|
|
|
(use-modules (gnu build linux-initrd)
|
|
|
|
(guix build utils)
|
|
|
|
(nonguix build utils))
|
|
|
|
|
|
|
|
(let* ((initrd (string-append #$output "/initrd.cpio"))
|
|
|
|
(dest-dir "kernel/x86/microcode")
|
|
|
|
(amd-bin (string-append dest-dir "/AuthenticAMD.bin"))
|
|
|
|
(intel-bin (string-append dest-dir "/GenuineIntel.bin")))
|
|
|
|
(mkdir-p dest-dir)
|
|
|
|
(for-each
|
|
|
|
(lambda (package)
|
|
|
|
(let ((intel-ucode (string-append package
|
|
|
|
"/lib/firmware/intel-ucode"))
|
|
|
|
(amd-ucode (string-append package
|
|
|
|
"/lib/firmware/amd-ucode")))
|
|
|
|
(when (directory-exists? intel-ucode)
|
|
|
|
(concatenate-files (find-files intel-ucode ".*")
|
|
|
|
intel-bin))
|
|
|
|
(when (directory-exists? amd-ucode)
|
|
|
|
(concatenate-files (find-files amd-ucode
|
|
|
|
"^microcode_amd.*\\.bin$")
|
|
|
|
amd-bin))))
|
|
|
|
'#$microcode-packages)
|
|
|
|
|
|
|
|
(mkdir-p #$output)
|
|
|
|
(write-cpio-archive initrd "kernel" #:compress? #f)))))
|
|
|
|
|
|
|
|
(file-append (computed-file "microcode-initrd" builder)
|
|
|
|
"/initrd.cpio"))
|
|
|
|
|
|
|
|
(define (combined-initrd . initrds)
|
2022-12-25 13:19:53 +01:00
|
|
|
"Return a combined initrd, the result of concatenating INITRDS. This relies
|
|
|
|
on the kernel ability to detect and load multiple initrds archives from a
|
|
|
|
single file."
|
2020-01-08 19:23:48 +01:00
|
|
|
(define builder
|
|
|
|
(with-imported-modules (source-module-closure
|
|
|
|
'((guix build utils)
|
|
|
|
(nonguix build utils))
|
2020-12-18 22:20:23 +01:00
|
|
|
#:select? import-nonguix-module?)
|
2020-01-08 19:23:48 +01:00
|
|
|
#~(begin
|
|
|
|
(use-modules (guix build utils)
|
2022-12-25 13:19:53 +01:00
|
|
|
(nonguix build utils)
|
|
|
|
(srfi srfi-1))
|
2020-01-08 19:23:48 +01:00
|
|
|
|
|
|
|
;; Use .img suffix since the result is no longer easily inspected by
|
|
|
|
;; standard tools like cpio and gzip.
|
2022-12-25 13:19:53 +01:00
|
|
|
;;
|
|
|
|
;; The initrds may contain "references" files to keep some items
|
|
|
|
;; such as the static guile alive. Concatenate them in a single,
|
|
|
|
;; top-level references file.
|
|
|
|
(let ((initrd (string-append #$output "/initrd.img"))
|
|
|
|
(references
|
|
|
|
(filter-map
|
|
|
|
(lambda (initrd)
|
|
|
|
(let ((ref (string-append (dirname initrd)
|
|
|
|
"/references")))
|
|
|
|
(and (file-exists? ref) ref)))
|
|
|
|
'#$initrds))
|
|
|
|
(new-references
|
|
|
|
(string-append #$output "/references")))
|
2020-01-08 19:23:48 +01:00
|
|
|
(mkdir-p #$output)
|
2022-12-25 13:19:53 +01:00
|
|
|
(concatenate-files '#$initrds initrd)
|
|
|
|
(concatenate-files references new-references)))))
|
2020-01-08 19:23:48 +01:00
|
|
|
|
|
|
|
(file-append (computed-file "combined-initrd" builder)
|
|
|
|
"/initrd.img"))
|