Add split microcode detection in alignment with future mkinitcpio changes

This commit is contained in:
dalto 2023-09-10 15:42:34 -05:00
parent 1765da8324
commit b553a85099
3 changed files with 50 additions and 26 deletions

View file

@ -0,0 +1,26 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0-only
COMMAND="${1:?}"
# shellcheck disable=SC2034
KERNEL_VERSION="${2:?}"
# shellcheck disable=SC2034
ENTRY_DIR_ABS="$3"
# shellcheck disable=SC2034
KERNEL_IMAGE="$4"
set -e
[[ "$COMMAND" = "add" ]] || exit 0
for dir in "${KERNEL_INSTALL_BOOT_ROOT}" "/boot"; do
for microcode in "intel-ucode.img" "amd-ucode.img"; do
if [[ -f "${dir}/${microcode}" ]]; then
install -m 0644 "${dir}/${microcode}" "${KERNEL_INSTALL_STAGING_AREA}/microcode-${microcode}" || {
echo "Error: could not copy '$microcode' to the staging area." >&2
exit 1
}
(( KERNEL_INSTALL_VERBOSE )) && printf "+ Found microcode image %s\n" "$microcode" || exit 0
fi
done
done

View file

@ -28,9 +28,9 @@ INITRD_OPTIONS_SHIFT=4
[ "$KERNEL_INSTALL_LAYOUT" = "bls" ] || exit 0
MACHINE_ID="$KERNEL_INSTALL_MACHINE_ID"
ENTRY_TOKEN="$KERNEL_INSTALL_ENTRY_TOKEN"
BOOT_ROOT="$KERNEL_INSTALL_BOOT_ROOT"
MACHINE_ID="${KERNEL_INSTALL_MACHINE_ID:?}"
ENTRY_TOKEN="${KERNEL_INSTALL_ENTRY_TOKEN:?}"
BOOT_ROOT="${KERNEL_INSTALL_BOOT_ROOT:?}"
[ -n "$BOOT_MNT" ] || BOOT_MNT="$(stat -c %m "$BOOT_ROOT")"
if [ "$BOOT_MNT" = '/' ]; then
@ -69,7 +69,7 @@ fi
[ -n "$PRETTY_NAME" ] || PRETTY_NAME="Linux $KERNEL_VERSION"
SORT_KEY="$IMAGE_ID"
[ -z "$SORT_KEY" ] && SORT_KEY="$ID-$KERNEL_VERSION"
[ -z "$SORT_KEY" ] && SORT_KEY="$ID-${KERNEL_VERSION}"
if [ -n "$KERNEL_INSTALL_CONF_ROOT" ]; then
if [ -f "$KERNEL_INSTALL_CONF_ROOT/cmdline" ]; then
@ -116,15 +116,14 @@ install -m 0644 "$KERNEL_IMAGE" "$KERNEL_DEST" || {
chown root:root "$KERNEL_DEST" || :
shift "$INITRD_OPTIONS_SHIFT"
# Identify any needed microcode
UCODE=$(for x in "/boot/*-ucode.img"; do echo $x; done)
# All files listed as arguments, and staged files starting with "initrd" are installed as initrds.
for initrd in "$@" "${KERNEL_INSTALL_STAGING_AREA}"/initrd $UCODE; do
for initrd in "${KERNEL_INSTALL_STAGING_AREA}"/microcode* "${@}" "${KERNEL_INSTALL_STAGING_AREA}"/initrd*; do
[ -f "$initrd" ] || {
# [ "$initrd" = "${KERNEL_INSTALL_STAGING_AREA}/initrd*" ] && continue
echo "Error: initrd ${initrd} not a file." >&2
case "$initrd" in
"${KERNEL_INSTALL_STAGING_AREA}/initrd*" | "${KERNEL_INSTALL_STAGING_AREA}/microcode*")
continue ;;
esac
echo "Error: '$initrd' is not a file." >&2
exit 1
}
@ -145,7 +144,7 @@ mkdir -p "${LOADER_ENTRY%/*}" || {
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && echo "Creating $LOADER_ENTRY"
{
echo "# Boot Loader Specification type#1 entry"
echo "# File created by $0 (systemd 253.5-1-arch)"
echo "# File created by $0 (systemd 254.3-1-arch)"
echo "title $PRETTY_NAME"
echo "version $KERNEL_VERSION"
if [ "$ENTRY_TOKEN" = "$MACHINE_ID" ]; then
@ -157,7 +156,7 @@ mkdir -p "${LOADER_ENTRY%/*}" || {
echo "linux $KERNEL_ENTRY"
have_initrd=
for initrd in "${@}" $UCODE "${KERNEL_INSTALL_STAGING_AREA}"/initrd; do
for initrd in "${KERNEL_INSTALL_STAGING_AREA}"/microcode* "${@}" "${KERNEL_INSTALL_STAGING_AREA}"/initrd; do
[ -f "$initrd" ] || continue
echo "initrd $ENTRY_DIR/${initrd##*/}"
have_initrd=yes

View file

@ -28,9 +28,9 @@ INITRD_OPTIONS_SHIFT=4
[ "$KERNEL_INSTALL_LAYOUT" = "bls" ] || exit 0
MACHINE_ID="$KERNEL_INSTALL_MACHINE_ID"
ENTRY_TOKEN="$KERNEL_INSTALL_ENTRY_TOKEN"
BOOT_ROOT="$KERNEL_INSTALL_BOOT_ROOT"
MACHINE_ID="${KERNEL_INSTALL_MACHINE_ID:?}"
ENTRY_TOKEN="${KERNEL_INSTALL_ENTRY_TOKEN:?}"
BOOT_ROOT="${KERNEL_INSTALL_BOOT_ROOT:?}"
[ -n "$BOOT_MNT" ] || BOOT_MNT="$(stat -c %m "$BOOT_ROOT")"
if [ "$BOOT_MNT" = '/' ]; then
@ -69,7 +69,7 @@ fi
[ -n "$PRETTY_NAME" ] || PRETTY_NAME="Linux $KERNEL_VERSION"
SORT_KEY="$IMAGE_ID"
[ -z "$SORT_KEY" ] && SORT_KEY="$ID-$KERNEL_VERSION-fallback"
[ -z "$SORT_KEY" ] && SORT_KEY="$ID-${KERNEL_VERSION}-fallback"
if [ -n "$KERNEL_INSTALL_CONF_ROOT" ]; then
if [ -f "$KERNEL_INSTALL_CONF_ROOT/cmdline" ]; then
@ -116,15 +116,14 @@ install -m 0644 "$KERNEL_IMAGE" "$KERNEL_DEST" || {
chown root:root "$KERNEL_DEST" || :
shift "$INITRD_OPTIONS_SHIFT"
# Identify any needed microcode
UCODE=$(for x in "/boot/*-ucode.img"; do echo $x; done)
# All files listed as arguments, and staged files starting with "initrd" are installed as initrds.
for initrd in "$@" "${KERNEL_INSTALL_STAGING_AREA}"/initrd-fallback $UCODE; do
for initrd in "${KERNEL_INSTALL_STAGING_AREA}"/microcode* "${@}" "${KERNEL_INSTALL_STAGING_AREA}"/initrd-fallback; do
[ -f "$initrd" ] || {
# [ "$initrd" = "${KERNEL_INSTALL_STAGING_AREA}/initrd*" ] && continue
echo "Error: initrd ${initrd} not a file." >&2
case "$initrd" in
"${KERNEL_INSTALL_STAGING_AREA}/initrd*" | "${KERNEL_INSTALL_STAGING_AREA}/microcode*")
continue ;;
esac
echo "Error: '$initrd' is not a file." >&2
exit 1
}
@ -145,7 +144,7 @@ mkdir -p "${LOADER_ENTRY%/*}" || {
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && echo "Creating $LOADER_ENTRY"
{
echo "# Boot Loader Specification type#1 entry"
echo "# File created by $0 (systemd 253.5-1-arch)"
echo "# File created by $0 (systemd 254.3-1-arch)"
echo "title $PRETTY_NAME"
echo "version $KERNEL_VERSION-fallback"
if [ "$ENTRY_TOKEN" = "$MACHINE_ID" ]; then
@ -157,7 +156,7 @@ mkdir -p "${LOADER_ENTRY%/*}" || {
echo "linux $KERNEL_ENTRY"
have_initrd=
for initrd in "${@}" $UCODE "${KERNEL_INSTALL_STAGING_AREA}"/initrd-fallback; do
for initrd in "${KERNEL_INSTALL_STAGING_AREA}"/microcode* "${@}" "${KERNEL_INSTALL_STAGING_AREA}"/initrd-fallback; do
[ -f "$initrd" ] || continue
echo "initrd $ENTRY_DIR/${initrd##*/}"
have_initrd=yes