Blame SOURCES/dracut_99microcode_ctl-fw_dir_override_module_init.sh

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