Blame SOURCES/dracut_99microcode_ctl-fw_dir_override_module_init.sh

383126
#!/bin/bash
383126
383126
# Hack in additional firmware directories for supported caveats.
383126
#
383126
# SPDX-License-Identifier: CC0-1.0
383126
383126
check() {
383126
	return 0
383126
}
383126
383126
install() {
383126
	local FW_DIR=/lib/firmware
383126
	local DATA_DIR=/usr/share/microcode_ctl/ucode_with_caveats
383126
	local CFG_DIR="/etc/microcode_ctl/ucode_with_caveats"
383126
	local check_caveats=/usr/libexec/microcode_ctl/check_caveats
383126
383126
	local verbose_opt
383126
	local cc_out
383126
	local path
383126
	local ignored
383126
	local do_skip_host_only
383126
	local p
383126
383126
	verbose_opt=
383126
	[ 4 -gt "$stdloglvl" ] || verbose_opt="-v"
383126
383126
	# HACK: we override external fw_dir variable in order to get
383126
	#       an additional ucode based on the kernel version.
383126
	dinfo "  microcode_ctl module: mangling fw_dir"
383126
383126
	[ -z "$fw_dir_l" ] || {
383126
		dinfo "    microcode_ctl: avoid touching fw_dir as" \
383126
		      "it has been changed (fw_dir_l is '$fw_dir_l')"
383126
383126
		return 0
383126
	}
383126
383126
	# Reset fw_dir to avoid inclusion of kernel-version-specific directories
383126
	# populated with microcode for the late load
383126
	[ "x$fw_dir" != \
383126
	  "x/lib/firmware/updates /lib/firmware /lib/firmware/$kernel" ] || {
383126
		fw_dir="/lib/firmware/updates /lib/firmware"
383126
		dinfo "    microcode_ctl: reset fw_dir to \"${fw_dir}\""
383126
	}
383126
383126
	fw_dir_add=""
383126
	while read -d $'\n' -r i; do
383126
		dinfo "    microcode_ctl: processing data directory " \
383126
		      "\"$DATA_DIR/$i\"..."
383126
383126
		if [ "x" != "x$hostonly" ]; then
383126
			do_skip_host_only=0
383126
383126
			local sho_overrides="
383126
				$CFG_DIR/skip-host-only-check
383126
				$CFG_DIR/skip-host-only-check-$i
383126
				$FW_DIR/$kernel/skip-host-only-check
383126
				$FW_DIR/$kernel/skip-host-only-check-$i"
383126
383126
			for p in $(echo "$sho_overrides"); do
383126
				[ -e "$p" ] || continue
383126
383126
				do_skip_host_only=1
383126
				dinfo "    microcode_ctl: $i; skipping" \
383126
				      "Host-Only check, since \"$p\" exists."
383126
				break
383126
			done
383126
		else
383126
			do_skip_host_only=1
383126
		fi
383126
383126
		match_model_opt=""
383126
		[ 1 = "$do_skip_host_only" ] || match_model_opt="-m"
383126
383126
		if ! cc_out=$($check_caveats -e -k "$kernel" -c "$i" \
383126
				$verbose_opt $match_model_opt)
383126
		then
383126
			dinfo "    microcode_ctl: kernel version \"$kernel\"" \
383126
			      "failed early load check for \"$i\", skipping"
383126
			continue
383126
		fi
383126
383126
		path=$(printf "%s" "$cc_out" | sed -n 's/^paths //p')
383126
		[ -n "$path" ] || {
383126
			ignored=$(printf "%s" "$cc_out" | \
383126
					sed -n 's/^skip_cfgs //p')
383126
383126
			if [ -n "$ignored" ]; then
383126
				dinfo "    microcode_ctl: configuration" \
383126
				      "\"$i\" is ignored"
383126
			else
383126
				dinfo "    microcode_ctl: no microcode paths" \
383126
				      "are associated with \"$i\", skipping"
383126
			fi
383126
383126
			continue
383126
		}
383126
383126
		dinfo "      microcode_ctl: $i: caveats check for kernel" \
383126
		      "version \"$kernel\" passed, adding" \
383126
		      "\"$DATA_DIR/$i\" to fw_dir variable"
383126
383126
		if [ 0 -eq "$do_skip_host_only" ]; then
383126
			fw_dir_add="$DATA_DIR/$i "
383126
		else
383126
			fw_dir_add="$DATA_DIR/$i $fw_dir_add"
383126
		fi
383126
	# The list of directories is reverse-sorted in order to preserve the
383126
	# "last wins" policy in case of presence of multiple microcode
383126
	# revisions.
383126
	#
383126
	# In case of hostonly == 0, all microcode revisions will be included,
383126
	# but since the microcode search is done with the "first wins" policy
383126
	# by the (early) microcode loading code, the correct microcode revision
383126
	# still has to be picked.
383126
	#
383126
	# Note that dracut without patch [1] puts only the last directory
383126
	# in the early cpio; we try to address this by putting only the last
383126
	# matching caveat in the search path, but that workaround works only
383126
	# for host-only mode; non-host-only mode early cpio generation is still
383126
	# broken without that patch.
383126
	#
383126
	# [1] https://github.com/dracutdevs/dracut/commit/c44d2252bb4b
383126
	done <<-EOF
383126
	$(find "$DATA_DIR" -maxdepth 1 -mindepth 1 -type d -printf "%f\n" \
383126
		| LC_ALL=C sort)
383126
	EOF
383126
383126
	fw_dir="${fw_dir_add}${fw_dir}"
383126
	dinfo "    microcode_ctl: final fw_dir: \"${fw_dir}\""
383126
}
383126