The /boot/intel-uc.img is useless when we use a dist-kernel since dracut is
responsible for generating the initramfs, and it (by default) includes the
microcode.

Instead add USE=dist-kernel and enable USE=initramfs by default. The
initramfs flag toggles the early_microcode setting of dracut, and if both flags
are enabled we trigger initramfs re-installation. This ensures that when we
update this package, we also get the latest microcode in our dist-kernel
initramfs or UKI.

Signed-off-by: Andrew Ammerlaan <andrewammerl...@gentoo.org>
---
 .../intel-microcode-20221108_p20221102.ebuild | 43 ++++++++++++++-----
 .../intel-microcode-20230214_p20230212.ebuild | 41 ++++++++++++++----
 .../intel-microcode-20230512_p20230512.ebuild | 41 ++++++++++++++----
 .../intel-microcode-20230613_p20230520.ebuild | 40 +++++++++++++----
 .../intel-microcode-20230808_p20230804.ebuild | 40 +++++++++++++----
 .../intel-microcode-20230808_p20231007.ebuild | 40 +++++++++++++----
 .../intel-microcode-20231114_p20231114.ebuild | 40 +++++++++++++----
 .../intel-microcode-20240312_p20240312.ebuild | 38 +++++++++++++---
 8 files changed, 256 insertions(+), 67 deletions(-)

diff --git 
a/sys-firmware/intel-microcode/intel-microcode-20221108_p20221102.ebuild 
b/sys-firmware/intel-microcode/intel-microcode-20221108_p20221102.ebuild
index 006f4811618a..a8cf0d39ff33 100644
--- a/sys-firmware/intel-microcode/intel-microcode-20221108_p20221102.ebuild
+++ b/sys-firmware/intel-microcode/intel-microcode-20221108_p20221102.ebuild
@@ -1,9 +1,9 @@
-# Copyright 1999-2022 Gentoo Authors
+# Copyright 1999-2024 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 EAPI="7"
 
-inherit linux-info mount-boot
+inherit dist-kernel-utils linux-info mount-boot
 
 # Find updates by searching and clicking the first link (hopefully it's the 
one):
 # 
https://www.intel.com/content/www/us/en/search.html?keyword=Processor+Microcode+Data+File
@@ -23,13 +23,20 @@ 
SRC_URI="https://github.com/intel/Intel-Linux-Processor-Microcode-Data-Files/arc
 LICENSE="intel-ucode"
 SLOT="0"
 KEYWORDS="-* amd64 x86"
-IUSE="hostonly initramfs +split-ucode vanilla"
-REQUIRED_USE="|| ( initramfs split-ucode )"
-
-BDEPEND=">=sys-apps/iucode_tool-2.3"
+IUSE="dist-kernel hostonly +initramfs +split-ucode vanilla"
+REQUIRED_USE="!dist-kernel? ( || ( initramfs split-ucode ) )"
 
+BDEPEND="
+       >=sys-apps/iucode_tool-2.3
+       dist-kernel? (
+               initramfs? ( sys-kernel/installkernel )
+       )
+"
 # !<sys-apps/microcode-ctl-1.17-r2 due to bug #268586
-RDEPEND="hostonly? ( sys-apps/iucode_tool )"
+RDEPEND="
+       dist-kernel? ( virtual/dist-kernel )
+       hostonly? ( sys-apps/iucode_tool )
+"
 
 RESTRICT="binchecks strip"
 
@@ -132,9 +139,18 @@ src_install() {
                --list
        )
 
+       # Instruct Dracut on whether or not we want the microcode in initramfs
+       # Use here 15 instead of 10, intel-microcode overwrites linux-firmware
+       (
+               insinto /usr/lib/dracut/dracut.conf.d
+               newins - 15-${PN}.conf <<<"early_microcode=$(usex initramfs)"
+       )
+
        # The earlyfw cpio needs to be in /boot because it must be loaded before
        # rootfs is mounted.
-       use initramfs && dodir /boot && opts+=( 
--write-earlyfw="${ED}/boot/intel-uc.img" )
+       if ! use dist-kernel && use initramfs; then
+               dodir /boot && opts+=( 
--write-earlyfw="${ED}/boot/intel-uc.img" )
+       fi
 
        keepdir /lib/firmware/intel-ucode
        opts+=( --write-firmware="${ED}/lib/firmware/intel-ucode" )
@@ -188,7 +204,9 @@ pkg_preinst() {
 
                # The earlyfw cpio needs to be in /boot because it must be 
loaded before
                # rootfs is mounted.
-               use initramfs && opts+=( --write-earlyfw=${_initramfs_file} )
+               if ! use dist-kernel && use initramfs; then
+                       opts+=( --write-earlyfw=${_initramfs_file} )
+               fi
 
                if use split-ucode; then
                        opts+=( 
--write-firmware="${ED}/lib/firmware/intel-ucode" )
@@ -259,7 +277,12 @@ pkg_postrm() {
 
 pkg_postinst() {
        # Don't forget to umount /boot if it was previously mounted by us.
-       use initramfs && mount-boot_pkg_postinst
+       if use initramfs; then
+               if [[ -z ${ROOT} ]] && use dist-kernel; then
+                       dist-kernel_reinstall_initramfs "${KV_DIR}" "${KV_FULL}"
+               fi
+               mount-boot_pkg_postinst
+       fi
 
        # We cannot give detailed information if user is affected or not:
        # If MICROCODE_BLACKLIST wasn't modified, user can still use 
MICROCODE_SIGNATURES
diff --git 
a/sys-firmware/intel-microcode/intel-microcode-20230214_p20230212.ebuild 
b/sys-firmware/intel-microcode/intel-microcode-20230214_p20230212.ebuild
index d0d809679e8d..2602f9f0e3ea 100644
--- a/sys-firmware/intel-microcode/intel-microcode-20230214_p20230212.ebuild
+++ b/sys-firmware/intel-microcode/intel-microcode-20230214_p20230212.ebuild
@@ -1,9 +1,9 @@
-# Copyright 1999-2023 Gentoo Authors
+# Copyright 1999-2024 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 EAPI=8
 
-inherit linux-info mount-boot
+inherit dist-kernel-utils linux-info mount-boot
 
 # Find updates by searching and clicking the first link (hopefully it's the 
one):
 # 
https://www.intel.com/content/www/us/en/search.html?keyword=Processor+Microcode+Data+File
@@ -23,13 +23,20 @@ 
SRC_URI="https://github.com/intel/Intel-Linux-Processor-Microcode-Data-Files/arc
 LICENSE="intel-ucode"
 SLOT="0"
 KEYWORDS="-* amd64 x86"
-IUSE="hostonly initramfs +split-ucode vanilla"
-REQUIRED_USE="|| ( initramfs split-ucode )"
+IUSE="dist-kernel hostonly +initramfs +split-ucode vanilla"
+REQUIRED_USE="!dist-kernel? ( || ( initramfs split-ucode ) )"
 
 BDEPEND=">=sys-apps/iucode_tool-2.3"
-
 # !<sys-apps/microcode-ctl-1.17-r2 due to bug #268586
-RDEPEND="hostonly? ( sys-apps/iucode_tool )"
+RDEPEND="
+       dist-kernel? ( virtual/dist-kernel )
+       hostonly? ( sys-apps/iucode_tool )
+"
+IDEPEND="
+       dist-kernel? (
+               initramfs? ( sys-kernel/installkernel )
+       )
+"
 
 RESTRICT="binchecks strip"
 
@@ -132,9 +139,18 @@ src_install() {
                --list
        )
 
+       # Instruct Dracut on whether or not we want the microcode in initramfs
+       # Use here 15 instead of 10, intel-microcode overwrites linux-firmware
+       (
+               insinto /usr/lib/dracut/dracut.conf.d
+               newins - 15-${PN}.conf <<<"early_microcode=$(usex initramfs)"
+       )
+
        # The earlyfw cpio needs to be in /boot because it must be loaded before
        # rootfs is mounted.
-       use initramfs && dodir /boot && opts+=( 
--write-earlyfw="${ED}/boot/intel-uc.img" )
+       if ! use dist-kernel && use initramfs; then
+               dodir /boot && opts+=( 
--write-earlyfw="${ED}/boot/intel-uc.img" )
+       fi
 
        keepdir /lib/firmware/intel-ucode
        opts+=( --write-firmware="${ED}/lib/firmware/intel-ucode" )
@@ -188,7 +204,9 @@ pkg_preinst() {
 
                # The earlyfw cpio needs to be in /boot because it must be 
loaded before
                # rootfs is mounted.
-               use initramfs && opts+=( --write-earlyfw=${_initramfs_file} )
+               if ! use dist-kernel && use initramfs; then
+                       opts+=( --write-earlyfw=${_initramfs_file} )
+               fi
 
                if use split-ucode; then
                        opts+=( 
--write-firmware="${ED}/lib/firmware/intel-ucode" )
@@ -259,7 +277,12 @@ pkg_postrm() {
 
 pkg_postinst() {
        # Don't forget to umount /boot if it was previously mounted by us.
-       use initramfs && mount-boot_pkg_postinst
+       if use initramfs; then
+               if [[ -z ${ROOT} ]] && use dist-kernel; then
+                       dist-kernel_reinstall_initramfs "${KV_DIR}" "${KV_FULL}"
+               fi
+               mount-boot_pkg_postinst
+       fi
 
        # We cannot give detailed information if user is affected or not:
        # If MICROCODE_BLACKLIST wasn't modified, user can still use 
MICROCODE_SIGNATURES
diff --git 
a/sys-firmware/intel-microcode/intel-microcode-20230512_p20230512.ebuild 
b/sys-firmware/intel-microcode/intel-microcode-20230512_p20230512.ebuild
index d0d809679e8d..2602f9f0e3ea 100644
--- a/sys-firmware/intel-microcode/intel-microcode-20230512_p20230512.ebuild
+++ b/sys-firmware/intel-microcode/intel-microcode-20230512_p20230512.ebuild
@@ -1,9 +1,9 @@
-# Copyright 1999-2023 Gentoo Authors
+# Copyright 1999-2024 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 EAPI=8
 
-inherit linux-info mount-boot
+inherit dist-kernel-utils linux-info mount-boot
 
 # Find updates by searching and clicking the first link (hopefully it's the 
one):
 # 
https://www.intel.com/content/www/us/en/search.html?keyword=Processor+Microcode+Data+File
@@ -23,13 +23,20 @@ 
SRC_URI="https://github.com/intel/Intel-Linux-Processor-Microcode-Data-Files/arc
 LICENSE="intel-ucode"
 SLOT="0"
 KEYWORDS="-* amd64 x86"
-IUSE="hostonly initramfs +split-ucode vanilla"
-REQUIRED_USE="|| ( initramfs split-ucode )"
+IUSE="dist-kernel hostonly +initramfs +split-ucode vanilla"
+REQUIRED_USE="!dist-kernel? ( || ( initramfs split-ucode ) )"
 
 BDEPEND=">=sys-apps/iucode_tool-2.3"
-
 # !<sys-apps/microcode-ctl-1.17-r2 due to bug #268586
-RDEPEND="hostonly? ( sys-apps/iucode_tool )"
+RDEPEND="
+       dist-kernel? ( virtual/dist-kernel )
+       hostonly? ( sys-apps/iucode_tool )
+"
+IDEPEND="
+       dist-kernel? (
+               initramfs? ( sys-kernel/installkernel )
+       )
+"
 
 RESTRICT="binchecks strip"
 
@@ -132,9 +139,18 @@ src_install() {
                --list
        )
 
+       # Instruct Dracut on whether or not we want the microcode in initramfs
+       # Use here 15 instead of 10, intel-microcode overwrites linux-firmware
+       (
+               insinto /usr/lib/dracut/dracut.conf.d
+               newins - 15-${PN}.conf <<<"early_microcode=$(usex initramfs)"
+       )
+
        # The earlyfw cpio needs to be in /boot because it must be loaded before
        # rootfs is mounted.
-       use initramfs && dodir /boot && opts+=( 
--write-earlyfw="${ED}/boot/intel-uc.img" )
+       if ! use dist-kernel && use initramfs; then
+               dodir /boot && opts+=( 
--write-earlyfw="${ED}/boot/intel-uc.img" )
+       fi
 
        keepdir /lib/firmware/intel-ucode
        opts+=( --write-firmware="${ED}/lib/firmware/intel-ucode" )
@@ -188,7 +204,9 @@ pkg_preinst() {
 
                # The earlyfw cpio needs to be in /boot because it must be 
loaded before
                # rootfs is mounted.
-               use initramfs && opts+=( --write-earlyfw=${_initramfs_file} )
+               if ! use dist-kernel && use initramfs; then
+                       opts+=( --write-earlyfw=${_initramfs_file} )
+               fi
 
                if use split-ucode; then
                        opts+=( 
--write-firmware="${ED}/lib/firmware/intel-ucode" )
@@ -259,7 +277,12 @@ pkg_postrm() {
 
 pkg_postinst() {
        # Don't forget to umount /boot if it was previously mounted by us.
-       use initramfs && mount-boot_pkg_postinst
+       if use initramfs; then
+               if [[ -z ${ROOT} ]] && use dist-kernel; then
+                       dist-kernel_reinstall_initramfs "${KV_DIR}" "${KV_FULL}"
+               fi
+               mount-boot_pkg_postinst
+       fi
 
        # We cannot give detailed information if user is affected or not:
        # If MICROCODE_BLACKLIST wasn't modified, user can still use 
MICROCODE_SIGNATURES
diff --git 
a/sys-firmware/intel-microcode/intel-microcode-20230613_p20230520.ebuild 
b/sys-firmware/intel-microcode/intel-microcode-20230613_p20230520.ebuild
index 5d1ff1e7f4be..957da662f92e 100644
--- a/sys-firmware/intel-microcode/intel-microcode-20230613_p20230520.ebuild
+++ b/sys-firmware/intel-microcode/intel-microcode-20230613_p20230520.ebuild
@@ -1,9 +1,9 @@
-# Copyright 1999-2023 Gentoo Authors
+# Copyright 1999-2024 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 EAPI=8
 
-inherit linux-info mount-boot
+inherit dist-kernel-utils linux-info mount-boot
 
 # Find updates by searching and clicking the first link (hopefully it's the 
one):
 # 
https://www.intel.com/content/www/us/en/search.html?keyword=Processor+Microcode+Data+File
@@ -44,13 +44,21 @@ S="${WORKDIR}"
 LICENSE="intel-ucode"
 SLOT="0"
 KEYWORDS="-* amd64 x86"
-IUSE="hostonly initramfs +split-ucode vanilla"
-REQUIRED_USE="|| ( initramfs split-ucode )"
+IUSE="dist-kernel hostonly +initramfs +split-ucode vanilla"
+REQUIRED_USE="!dist-kernel? ( || ( initramfs split-ucode ) )"
 RESTRICT="binchecks strip"
 
 BDEPEND=">=sys-apps/iucode_tool-2.3"
 # !<sys-apps/microcode-ctl-1.17-r2 due to bug #268586
-RDEPEND="hostonly? ( sys-apps/iucode_tool )"
+RDEPEND="
+       dist-kernel? ( virtual/dist-kernel )
+       hostonly? ( sys-apps/iucode_tool )
+"
+IDEPEND="
+       dist-kernel? (
+               initramfs? ( sys-kernel/installkernel )
+       )
+"
 
 # Blacklist bad microcode here.
 # 0x000406f1 aka 06-4f-01 aka CPUID 406F1 require newer microcode loader
@@ -138,9 +146,18 @@ src_install() {
                --list
        )
 
+       # Instruct Dracut on whether or not we want the microcode in initramfs
+       # Use here 15 instead of 10, intel-microcode overwrites linux-firmware
+       (
+               insinto /usr/lib/dracut/dracut.conf.d
+               newins - 15-${PN}.conf <<<"early_microcode=$(usex initramfs)"
+       )
+
        # The earlyfw cpio needs to be in /boot because it must be loaded before
        # rootfs is mounted.
-       use initramfs && dodir /boot && opts+=( 
--write-earlyfw="${ED}/boot/intel-uc.img" )
+       if ! use dist-kernel && use initramfs; then
+               dodir /boot && opts+=( 
--write-earlyfw="${ED}/boot/intel-uc.img" )
+       fi
 
        keepdir /lib/firmware/intel-ucode
        opts+=( --write-firmware="${ED}/lib/firmware/intel-ucode" )
@@ -194,7 +211,9 @@ pkg_preinst() {
 
                # The earlyfw cpio needs to be in /boot because it must be 
loaded before
                # rootfs is mounted.
-               use initramfs && opts+=( --write-earlyfw=${_initramfs_file} )
+               if ! use dist-kernel && use initramfs; then
+                       opts+=( --write-earlyfw=${_initramfs_file} )
+               fi
 
                if use split-ucode; then
                        opts+=( 
--write-firmware="${ED}/lib/firmware/intel-ucode" )
@@ -265,7 +284,12 @@ pkg_postrm() {
 
 pkg_postinst() {
        # Don't forget to umount /boot if it was previously mounted by us.
-       use initramfs && mount-boot_pkg_postinst
+       if use initramfs; then
+               if [[ -z ${ROOT} ]] && use dist-kernel; then
+                       dist-kernel_reinstall_initramfs "${KV_DIR}" "${KV_FULL}"
+               fi
+               mount-boot_pkg_postinst
+       fi
 
        # We cannot give detailed information if user is affected or not:
        # If MICROCODE_BLACKLIST wasn't modified, user can still use 
MICROCODE_SIGNATURES
diff --git 
a/sys-firmware/intel-microcode/intel-microcode-20230808_p20230804.ebuild 
b/sys-firmware/intel-microcode/intel-microcode-20230808_p20230804.ebuild
index 5d1ff1e7f4be..957da662f92e 100644
--- a/sys-firmware/intel-microcode/intel-microcode-20230808_p20230804.ebuild
+++ b/sys-firmware/intel-microcode/intel-microcode-20230808_p20230804.ebuild
@@ -1,9 +1,9 @@
-# Copyright 1999-2023 Gentoo Authors
+# Copyright 1999-2024 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 EAPI=8
 
-inherit linux-info mount-boot
+inherit dist-kernel-utils linux-info mount-boot
 
 # Find updates by searching and clicking the first link (hopefully it's the 
one):
 # 
https://www.intel.com/content/www/us/en/search.html?keyword=Processor+Microcode+Data+File
@@ -44,13 +44,21 @@ S="${WORKDIR}"
 LICENSE="intel-ucode"
 SLOT="0"
 KEYWORDS="-* amd64 x86"
-IUSE="hostonly initramfs +split-ucode vanilla"
-REQUIRED_USE="|| ( initramfs split-ucode )"
+IUSE="dist-kernel hostonly +initramfs +split-ucode vanilla"
+REQUIRED_USE="!dist-kernel? ( || ( initramfs split-ucode ) )"
 RESTRICT="binchecks strip"
 
 BDEPEND=">=sys-apps/iucode_tool-2.3"
 # !<sys-apps/microcode-ctl-1.17-r2 due to bug #268586
-RDEPEND="hostonly? ( sys-apps/iucode_tool )"
+RDEPEND="
+       dist-kernel? ( virtual/dist-kernel )
+       hostonly? ( sys-apps/iucode_tool )
+"
+IDEPEND="
+       dist-kernel? (
+               initramfs? ( sys-kernel/installkernel )
+       )
+"
 
 # Blacklist bad microcode here.
 # 0x000406f1 aka 06-4f-01 aka CPUID 406F1 require newer microcode loader
@@ -138,9 +146,18 @@ src_install() {
                --list
        )
 
+       # Instruct Dracut on whether or not we want the microcode in initramfs
+       # Use here 15 instead of 10, intel-microcode overwrites linux-firmware
+       (
+               insinto /usr/lib/dracut/dracut.conf.d
+               newins - 15-${PN}.conf <<<"early_microcode=$(usex initramfs)"
+       )
+
        # The earlyfw cpio needs to be in /boot because it must be loaded before
        # rootfs is mounted.
-       use initramfs && dodir /boot && opts+=( 
--write-earlyfw="${ED}/boot/intel-uc.img" )
+       if ! use dist-kernel && use initramfs; then
+               dodir /boot && opts+=( 
--write-earlyfw="${ED}/boot/intel-uc.img" )
+       fi
 
        keepdir /lib/firmware/intel-ucode
        opts+=( --write-firmware="${ED}/lib/firmware/intel-ucode" )
@@ -194,7 +211,9 @@ pkg_preinst() {
 
                # The earlyfw cpio needs to be in /boot because it must be 
loaded before
                # rootfs is mounted.
-               use initramfs && opts+=( --write-earlyfw=${_initramfs_file} )
+               if ! use dist-kernel && use initramfs; then
+                       opts+=( --write-earlyfw=${_initramfs_file} )
+               fi
 
                if use split-ucode; then
                        opts+=( 
--write-firmware="${ED}/lib/firmware/intel-ucode" )
@@ -265,7 +284,12 @@ pkg_postrm() {
 
 pkg_postinst() {
        # Don't forget to umount /boot if it was previously mounted by us.
-       use initramfs && mount-boot_pkg_postinst
+       if use initramfs; then
+               if [[ -z ${ROOT} ]] && use dist-kernel; then
+                       dist-kernel_reinstall_initramfs "${KV_DIR}" "${KV_FULL}"
+               fi
+               mount-boot_pkg_postinst
+       fi
 
        # We cannot give detailed information if user is affected or not:
        # If MICROCODE_BLACKLIST wasn't modified, user can still use 
MICROCODE_SIGNATURES
diff --git 
a/sys-firmware/intel-microcode/intel-microcode-20230808_p20231007.ebuild 
b/sys-firmware/intel-microcode/intel-microcode-20230808_p20231007.ebuild
index 5d1ff1e7f4be..957da662f92e 100644
--- a/sys-firmware/intel-microcode/intel-microcode-20230808_p20231007.ebuild
+++ b/sys-firmware/intel-microcode/intel-microcode-20230808_p20231007.ebuild
@@ -1,9 +1,9 @@
-# Copyright 1999-2023 Gentoo Authors
+# Copyright 1999-2024 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 EAPI=8
 
-inherit linux-info mount-boot
+inherit dist-kernel-utils linux-info mount-boot
 
 # Find updates by searching and clicking the first link (hopefully it's the 
one):
 # 
https://www.intel.com/content/www/us/en/search.html?keyword=Processor+Microcode+Data+File
@@ -44,13 +44,21 @@ S="${WORKDIR}"
 LICENSE="intel-ucode"
 SLOT="0"
 KEYWORDS="-* amd64 x86"
-IUSE="hostonly initramfs +split-ucode vanilla"
-REQUIRED_USE="|| ( initramfs split-ucode )"
+IUSE="dist-kernel hostonly +initramfs +split-ucode vanilla"
+REQUIRED_USE="!dist-kernel? ( || ( initramfs split-ucode ) )"
 RESTRICT="binchecks strip"
 
 BDEPEND=">=sys-apps/iucode_tool-2.3"
 # !<sys-apps/microcode-ctl-1.17-r2 due to bug #268586
-RDEPEND="hostonly? ( sys-apps/iucode_tool )"
+RDEPEND="
+       dist-kernel? ( virtual/dist-kernel )
+       hostonly? ( sys-apps/iucode_tool )
+"
+IDEPEND="
+       dist-kernel? (
+               initramfs? ( sys-kernel/installkernel )
+       )
+"
 
 # Blacklist bad microcode here.
 # 0x000406f1 aka 06-4f-01 aka CPUID 406F1 require newer microcode loader
@@ -138,9 +146,18 @@ src_install() {
                --list
        )
 
+       # Instruct Dracut on whether or not we want the microcode in initramfs
+       # Use here 15 instead of 10, intel-microcode overwrites linux-firmware
+       (
+               insinto /usr/lib/dracut/dracut.conf.d
+               newins - 15-${PN}.conf <<<"early_microcode=$(usex initramfs)"
+       )
+
        # The earlyfw cpio needs to be in /boot because it must be loaded before
        # rootfs is mounted.
-       use initramfs && dodir /boot && opts+=( 
--write-earlyfw="${ED}/boot/intel-uc.img" )
+       if ! use dist-kernel && use initramfs; then
+               dodir /boot && opts+=( 
--write-earlyfw="${ED}/boot/intel-uc.img" )
+       fi
 
        keepdir /lib/firmware/intel-ucode
        opts+=( --write-firmware="${ED}/lib/firmware/intel-ucode" )
@@ -194,7 +211,9 @@ pkg_preinst() {
 
                # The earlyfw cpio needs to be in /boot because it must be 
loaded before
                # rootfs is mounted.
-               use initramfs && opts+=( --write-earlyfw=${_initramfs_file} )
+               if ! use dist-kernel && use initramfs; then
+                       opts+=( --write-earlyfw=${_initramfs_file} )
+               fi
 
                if use split-ucode; then
                        opts+=( 
--write-firmware="${ED}/lib/firmware/intel-ucode" )
@@ -265,7 +284,12 @@ pkg_postrm() {
 
 pkg_postinst() {
        # Don't forget to umount /boot if it was previously mounted by us.
-       use initramfs && mount-boot_pkg_postinst
+       if use initramfs; then
+               if [[ -z ${ROOT} ]] && use dist-kernel; then
+                       dist-kernel_reinstall_initramfs "${KV_DIR}" "${KV_FULL}"
+               fi
+               mount-boot_pkg_postinst
+       fi
 
        # We cannot give detailed information if user is affected or not:
        # If MICROCODE_BLACKLIST wasn't modified, user can still use 
MICROCODE_SIGNATURES
diff --git 
a/sys-firmware/intel-microcode/intel-microcode-20231114_p20231114.ebuild 
b/sys-firmware/intel-microcode/intel-microcode-20231114_p20231114.ebuild
index 5d1ff1e7f4be..957da662f92e 100644
--- a/sys-firmware/intel-microcode/intel-microcode-20231114_p20231114.ebuild
+++ b/sys-firmware/intel-microcode/intel-microcode-20231114_p20231114.ebuild
@@ -1,9 +1,9 @@
-# Copyright 1999-2023 Gentoo Authors
+# Copyright 1999-2024 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 EAPI=8
 
-inherit linux-info mount-boot
+inherit dist-kernel-utils linux-info mount-boot
 
 # Find updates by searching and clicking the first link (hopefully it's the 
one):
 # 
https://www.intel.com/content/www/us/en/search.html?keyword=Processor+Microcode+Data+File
@@ -44,13 +44,21 @@ S="${WORKDIR}"
 LICENSE="intel-ucode"
 SLOT="0"
 KEYWORDS="-* amd64 x86"
-IUSE="hostonly initramfs +split-ucode vanilla"
-REQUIRED_USE="|| ( initramfs split-ucode )"
+IUSE="dist-kernel hostonly +initramfs +split-ucode vanilla"
+REQUIRED_USE="!dist-kernel? ( || ( initramfs split-ucode ) )"
 RESTRICT="binchecks strip"
 
 BDEPEND=">=sys-apps/iucode_tool-2.3"
 # !<sys-apps/microcode-ctl-1.17-r2 due to bug #268586
-RDEPEND="hostonly? ( sys-apps/iucode_tool )"
+RDEPEND="
+       dist-kernel? ( virtual/dist-kernel )
+       hostonly? ( sys-apps/iucode_tool )
+"
+IDEPEND="
+       dist-kernel? (
+               initramfs? ( sys-kernel/installkernel )
+       )
+"
 
 # Blacklist bad microcode here.
 # 0x000406f1 aka 06-4f-01 aka CPUID 406F1 require newer microcode loader
@@ -138,9 +146,18 @@ src_install() {
                --list
        )
 
+       # Instruct Dracut on whether or not we want the microcode in initramfs
+       # Use here 15 instead of 10, intel-microcode overwrites linux-firmware
+       (
+               insinto /usr/lib/dracut/dracut.conf.d
+               newins - 15-${PN}.conf <<<"early_microcode=$(usex initramfs)"
+       )
+
        # The earlyfw cpio needs to be in /boot because it must be loaded before
        # rootfs is mounted.
-       use initramfs && dodir /boot && opts+=( 
--write-earlyfw="${ED}/boot/intel-uc.img" )
+       if ! use dist-kernel && use initramfs; then
+               dodir /boot && opts+=( 
--write-earlyfw="${ED}/boot/intel-uc.img" )
+       fi
 
        keepdir /lib/firmware/intel-ucode
        opts+=( --write-firmware="${ED}/lib/firmware/intel-ucode" )
@@ -194,7 +211,9 @@ pkg_preinst() {
 
                # The earlyfw cpio needs to be in /boot because it must be 
loaded before
                # rootfs is mounted.
-               use initramfs && opts+=( --write-earlyfw=${_initramfs_file} )
+               if ! use dist-kernel && use initramfs; then
+                       opts+=( --write-earlyfw=${_initramfs_file} )
+               fi
 
                if use split-ucode; then
                        opts+=( 
--write-firmware="${ED}/lib/firmware/intel-ucode" )
@@ -265,7 +284,12 @@ pkg_postrm() {
 
 pkg_postinst() {
        # Don't forget to umount /boot if it was previously mounted by us.
-       use initramfs && mount-boot_pkg_postinst
+       if use initramfs; then
+               if [[ -z ${ROOT} ]] && use dist-kernel; then
+                       dist-kernel_reinstall_initramfs "${KV_DIR}" "${KV_FULL}"
+               fi
+               mount-boot_pkg_postinst
+       fi
 
        # We cannot give detailed information if user is affected or not:
        # If MICROCODE_BLACKLIST wasn't modified, user can still use 
MICROCODE_SIGNATURES
diff --git 
a/sys-firmware/intel-microcode/intel-microcode-20240312_p20240312.ebuild 
b/sys-firmware/intel-microcode/intel-microcode-20240312_p20240312.ebuild
index 5992eadefd5f..957da662f92e 100644
--- a/sys-firmware/intel-microcode/intel-microcode-20240312_p20240312.ebuild
+++ b/sys-firmware/intel-microcode/intel-microcode-20240312_p20240312.ebuild
@@ -3,7 +3,7 @@
 
 EAPI=8
 
-inherit linux-info mount-boot
+inherit dist-kernel-utils linux-info mount-boot
 
 # Find updates by searching and clicking the first link (hopefully it's the 
one):
 # 
https://www.intel.com/content/www/us/en/search.html?keyword=Processor+Microcode+Data+File
@@ -44,13 +44,21 @@ S="${WORKDIR}"
 LICENSE="intel-ucode"
 SLOT="0"
 KEYWORDS="-* amd64 x86"
-IUSE="hostonly initramfs +split-ucode vanilla"
-REQUIRED_USE="|| ( initramfs split-ucode )"
+IUSE="dist-kernel hostonly +initramfs +split-ucode vanilla"
+REQUIRED_USE="!dist-kernel? ( || ( initramfs split-ucode ) )"
 RESTRICT="binchecks strip"
 
 BDEPEND=">=sys-apps/iucode_tool-2.3"
 # !<sys-apps/microcode-ctl-1.17-r2 due to bug #268586
-RDEPEND="hostonly? ( sys-apps/iucode_tool )"
+RDEPEND="
+       dist-kernel? ( virtual/dist-kernel )
+       hostonly? ( sys-apps/iucode_tool )
+"
+IDEPEND="
+       dist-kernel? (
+               initramfs? ( sys-kernel/installkernel )
+       )
+"
 
 # Blacklist bad microcode here.
 # 0x000406f1 aka 06-4f-01 aka CPUID 406F1 require newer microcode loader
@@ -138,9 +146,18 @@ src_install() {
                --list
        )
 
+       # Instruct Dracut on whether or not we want the microcode in initramfs
+       # Use here 15 instead of 10, intel-microcode overwrites linux-firmware
+       (
+               insinto /usr/lib/dracut/dracut.conf.d
+               newins - 15-${PN}.conf <<<"early_microcode=$(usex initramfs)"
+       )
+
        # The earlyfw cpio needs to be in /boot because it must be loaded before
        # rootfs is mounted.
-       use initramfs && dodir /boot && opts+=( 
--write-earlyfw="${ED}/boot/intel-uc.img" )
+       if ! use dist-kernel && use initramfs; then
+               dodir /boot && opts+=( 
--write-earlyfw="${ED}/boot/intel-uc.img" )
+       fi
 
        keepdir /lib/firmware/intel-ucode
        opts+=( --write-firmware="${ED}/lib/firmware/intel-ucode" )
@@ -194,7 +211,9 @@ pkg_preinst() {
 
                # The earlyfw cpio needs to be in /boot because it must be 
loaded before
                # rootfs is mounted.
-               use initramfs && opts+=( --write-earlyfw=${_initramfs_file} )
+               if ! use dist-kernel && use initramfs; then
+                       opts+=( --write-earlyfw=${_initramfs_file} )
+               fi
 
                if use split-ucode; then
                        opts+=( 
--write-firmware="${ED}/lib/firmware/intel-ucode" )
@@ -265,7 +284,12 @@ pkg_postrm() {
 
 pkg_postinst() {
        # Don't forget to umount /boot if it was previously mounted by us.
-       use initramfs && mount-boot_pkg_postinst
+       if use initramfs; then
+               if [[ -z ${ROOT} ]] && use dist-kernel; then
+                       dist-kernel_reinstall_initramfs "${KV_DIR}" "${KV_FULL}"
+               fi
+               mount-boot_pkg_postinst
+       fi
 
        # We cannot give detailed information if user is affected or not:
        # If MICROCODE_BLACKLIST wasn't modified, user can still use 
MICROCODE_SIGNATURES
-- 
2.45.0


Reply via email to