sys-kernel/linux-firmware: add USE=initramfs
authorThomas Deutschmann <whissi@gentoo.org>
Fri, 2 Aug 2019 23:46:36 +0000 (01:46 +0200)
committerThomas Deutschmann <whissi@gentoo.org>
Fri, 2 Aug 2019 23:59:05 +0000 (01:59 +0200)
USE=initramfs will create /boot/amd-uc.img.

Package-Manager: Portage-2.3.69, Repoman-2.3.16
Signed-off-by: Thomas Deutschmann <whissi@gentoo.org>
sys-kernel/linux-firmware/linux-firmware-99999999.ebuild
sys-kernel/linux-firmware/metadata.xml

index f439b40eab430654190d8c7d53c9febabad8ccff..c2afff9ee0c03f2bbdf4f37b2ba4edfc32a76989 100644 (file)
@@ -2,7 +2,7 @@
 # Distributed under the terms of the GNU General Public License v2
 
 EAPI=7
-inherit savedconfig
+inherit mount-boot savedconfig
 
 if [[ ${PV} == 99999999* ]]; then
        inherit git-r3
@@ -21,10 +21,12 @@ LICENSE="GPL-2 GPL-2+ GPL-3 BSD MIT || ( MPL-1.1 GPL-2 )
                linux-fw-redistributable ( BSD-2 BSD BSD-4 ISC MIT no-source-code ) )
        unknown-license? ( all-rights-reserved )"
 SLOT="0"
-IUSE="+redistributable savedconfig unknown-license"
+IUSE="initramfs +redistributable savedconfig unknown-license"
 RESTRICT="binchecks strip
        unknown-license? ( bindist )"
 
+BDEPEND="initramfs? ( app-arch/cpio )"
+
 RDEPEND="!savedconfig? (
                redistributable? (
                        !sys-firmware/alsa-firmware[alsa_cards_ca0132]
@@ -244,8 +246,35 @@ src_prepare() {
                IFS=$' \t\n'
        fi
 
+       if use initramfs; then
+               if [[ -d "${S}/amd-ucode" ]]; then
+                       local UCODETMP="${T}/ucode_tmp"
+                       local UCODEDIR="${UCODETMP}/kernel/x86/microcode"
+                       mkdir -p "${UCODEDIR}" || die
+                       echo 1 > "${UCODETMP}/early_cpio"
+
+                       local amd_ucode_file="${UCODEDIR}/AuthenticAMD.bin"
+                       cat "${S}"/amd-ucode/*.bin > "${amd_ucode_file}" || die "Failed to concat amd cpu ucode"
+
+                       if [[ ! -s "${amd_ucode_file}" ]]; then
+                               die "Sanity check failed: '${amd_ucode_file}' is empty!"
+                       fi
+
+                       pushd "${UCODETMP}" &>/dev/null || die
+                       find . -print0 | cpio --quiet --null -o -H newc -R 0:0 > "${S}"/amd-uc.img
+                       popd &>/dev/null || die
+                       if [[ ! -s "${S}/amd-uc.img" ]]; then
+                               die "Failed to create '${S}/amd-uc.img'!"
+                       fi
+               else
+                       # If this will ever happen something has changed which
+                       # must be reviewed
+                       die "'${S}/amd-ucode' not found!"
+               fi
+       fi
+
        echo "# Remove files that shall not be installed from this list." > ${PN}.conf
-       find * ! -type d ! -name ${PN}.conf >> ${PN}.conf
+       find * ! -type d \( ! -name ${PN}.conf -o -name amd-uc.img \) >> ${PN}.conf
 
        if use savedconfig; then
                restore_config ${PN}.conf
@@ -268,6 +297,11 @@ src_install() {
        fi
        rm ${PN}.conf || die
 
+       if use initramfs ; then
+               mkdir "${ED}/boot" || die
+               mv "${S}"/amd-uc.img "${ED}/boot" || die
+       fi
+
        if ! ( shopt -s failglob; : * ) 2>/dev/null; then
                eerror "No files to install. Check your USE flag settings"
                eerror "and the list of files in your saved configuration."
index 7370ea010ccdf024c0855c0a349765f6bd1cb403..b1cdaa4debb29df3ac2216e535e7c2160a44671b 100644 (file)
        <name>Gentoo Kernel Project</name>
 </maintainer>
 <use>
-       <flag name="redistributable">Install also non-free (but redistributable)
-       firmware files</flag>
+       <flag name="initramfs">Create and install initramfs for early microcode loading in /boot (only AMD for now)</flag>
+       <flag name="redistributable">Install also non-free (but redistributable) firmware files</flag>
        <flag name="savedconfig">Allows individual selection of firmware files</flag>
-       <flag name="unknown-license">Install firmware files whose license is
-       unknown</flag>
+       <flag name="unknown-license">Install firmware files whose license is unknown</flag>
 </use>
 </pkgmetadata>