|
|
078ac8 |
#! /bin/bash -efu
|
|
|
c59b13 |
|
|
|
c59b13 |
# Generator of RPM "Provides:" tags for Intel microcode files.
|
|
|
c59b13 |
#
|
|
|
c59b13 |
# SPDX-License-Identifier: CC0-1.0
|
|
|
c59b13 |
|
|
|
c59b13 |
IFS=$'\n'
|
|
|
c59b13 |
UPDATED="intel-beta"
|
|
|
c59b13 |
CODENAMES="codenames"
|
|
|
c59b13 |
|
|
|
c59b13 |
if [ "$#" -ge 1 ]; then
|
|
|
c59b13 |
CODENAMES="$1"
|
|
|
c59b13 |
shift
|
|
|
c59b13 |
fi
|
|
|
c59b13 |
|
|
|
c59b13 |
# Match only FF-MM-SS ucode files under intel-ucode/intel-ucode-with-caveats
|
|
|
c59b13 |
# directories.
|
|
|
c59b13 |
for f in $(grep -E '/intel-ucode.*/[0-9a-f][0-9a-f]-[0-9a-f][0-9a-f]-[0-9a-f][0-9a-f]$'); do
|
|
|
c59b13 |
ucode=$(basename "$f")
|
|
|
c59b13 |
ucode_caveat="$(basename "$(dirname "$(dirname "$f")")")"
|
|
|
c59b13 |
ucode_fname="$ucode_caveat/$ucode"
|
|
|
c59b13 |
file_sz="$(stat -c "%s" "$f")"
|
|
|
c59b13 |
skip=0
|
|
|
81200a |
ext_hdr=0
|
|
|
81200a |
ext_sig_cnt=0
|
|
|
81200a |
ext_sig_pos=0
|
|
|
81200a |
next_skip=0
|
|
|
c59b13 |
|
|
|
81200a |
# Microcode header format description:
|
|
|
81200a |
# https://gitlab.com/iucode-tool/iucode-tool/blob/master/intel_microcode.c
|
|
|
c59b13 |
while :; do
|
|
|
c59b13 |
[ "$skip" -lt "$file_sz" ] || break
|
|
|
c59b13 |
|
|
|
81200a |
# Do we parse ext_sig table or another microcode header?
|
|
|
81200a |
if [ 0 != "$next_skip" ]; then
|
|
|
81200a |
# Check whether we should abort ext_sig table parsing
|
|
|
81200a |
[ \( "${skip}" -lt "${next_skip}" \) -a \
|
|
|
81200a |
\( "${ext_sig_pos}" -lt "${ext_sig_cnt}" \) ] || {
|
|
|
81200a |
skip="${next_skip}"
|
|
|
81200a |
next_skip=0
|
|
|
81200a |
continue
|
|
|
81200a |
}
|
|
|
81200a |
|
|
|
81200a |
# ext_sig, 12 bytes in size
|
|
|
81200a |
IFS=' ' read cpuid pf_mask <<- EOF
|
|
|
81200a |
$(hexdump -s "$skip" -n 8 \
|
|
|
81200a |
-e '"" 1/4 "%08x " 1/4 "%u" "\n"' "$f")
|
|
|
81200a |
EOF
|
|
|
81200a |
|
|
|
81200a |
skip="$((skip + 12))"
|
|
|
81200a |
ext_sig_pos="$((ext_sig_pos + 1))"
|
|
|
81200a |
else
|
|
|
81200a |
# Microcode header, 48 bytes, last 3 fields reserved
|
|
|
81200a |
IFS=' ' read hdrver rev \
|
|
|
81200a |
date_y date_d date_m \
|
|
|
81200a |
cpuid cksum ldrver \
|
|
|
81200a |
pf_mask datasz totalsz <<- EOF
|
|
|
81200a |
$(hexdump -s "$skip" -n 36 \
|
|
|
81200a |
-e '"" 1/4 "%u " 1/4 "%#x " \
|
|
|
81200a |
1/2 "%04x " 1/1 "%02x " 1/1 "%02x " \
|
|
|
81200a |
1/4 "%08x " 1/4 "%x " 1/4 "%#x " \
|
|
|
81200a |
1/4 "%u " 1/4 "%u " 1/4 "%u" "\n"' "$f")
|
|
|
81200a |
EOF
|
|
|
81200a |
|
|
|
81200a |
[ 0 != "$datasz" ] || datasz=2000
|
|
|
81200a |
[ 0 != "$totalsz" ] || totalsz=2048
|
|
|
81200a |
|
|
|
81200a |
# TODO: add some sanity/safety checks here. As of now,
|
|
|
81200a |
# there's a (pretty fragile) assumption that all
|
|
|
81200a |
# the matched files are valid Intel microcode
|
|
|
81200a |
# files in the expected format.
|
|
|
81200a |
|
|
|
81200a |
# ext_sig table is after the microcode payload,
|
|
|
81200a |
# check for its presence
|
|
|
81200a |
if [ 48 -lt "$((totalsz - datasz))" ]; then
|
|
|
81200a |
next_skip="$((skip + totalsz))"
|
|
|
81200a |
skip="$((skip + datasz + 48))"
|
|
|
81200a |
ext_sig_pos=0
|
|
|
81200a |
|
|
|
81200a |
# ext_sig table header, 20 bytes in size,
|
|
|
81200a |
# last 3 fields are reserved.
|
|
|
81200a |
IFS=' ' read ext_sig_cnt <<- EOF
|
|
|
81200a |
$(hexdump -s "$skip" -n 4 \
|
|
|
81200a |
-e '"" 1/4 "%u" "\n"' "$f")
|
|
|
81200a |
EOF
|
|
|
81200a |
|
|
|
81200a |
skip="$((skip + 20))"
|
|
|
81200a |
else
|
|
|
81200a |
skip="$((skip + totalsz))"
|
|
|
81200a |
next_skip=0
|
|
|
81200a |
fi
|
|
|
81200a |
fi
|
|
|
c59b13 |
|
|
|
c59b13 |
#[ -n "$rev" ] || continue
|
|
|
c59b13 |
|
|
|
c59b13 |
# Basic "Provides:" tag. Everything else is bells and whistles.
|
|
|
c59b13 |
# It's possible that microcode files for different platform_id's
|
|
|
c59b13 |
# and the same CPUID have the same version, that's why "sort -u"
|
|
|
c59b13 |
# in the end.
|
|
|
c59b13 |
printf "firmware(intel-ucode/%s) = %s\n" "$ucode" "$rev"
|
|
|
c59b13 |
|
|
|
c59b13 |
# Generate extended "Provides:" tags with additional
|
|
|
c59b13 |
# information, which allow more precise matching.
|
|
|
c59b13 |
printf "iucode_date(fname:%s;cpuid:%s;pf_mask:0x%x) = %s.%s.%s\n" \
|
|
|
c59b13 |
"$ucode_fname" "$cpuid" "$pf_mask" "$date_y" "$date_m" "$date_d"
|
|
|
c59b13 |
printf "iucode_rev(fname:%s;cpuid:%s;pf_mask:0x%x) = %s\n" \
|
|
|
c59b13 |
"$ucode_fname" "$cpuid" "$pf_mask" "$rev"
|
|
|
c59b13 |
|
|
|
c59b13 |
# Generate tags for each possible platform_id
|
|
|
c59b13 |
_pf=1
|
|
|
c59b13 |
_pf_mask="$pf_mask"
|
|
|
c59b13 |
while [ 0 -lt "$_pf_mask" ]; do
|
|
|
c59b13 |
[ 1 -ne "$((_pf_mask % 2))" ] || \
|
|
|
c59b13 |
# We try to provide a more specific firmware()
|
|
|
c59b13 |
# dependency here. It has incorrect file name,
|
|
|
c59b13 |
# but allows constructing a required RPM
|
|
|
c59b13 |
# capability name by (directly) using
|
|
|
c59b13 |
# the contents of /proc/cpuinfo and
|
|
|
c59b13 |
# /sys/devices/system/cpu/cpu*/microcode/processor_flags
|
|
|
c59b13 |
# (except for a Deschutes CPU with sig 0x1632)
|
|
|
c59b13 |
printf "iucode_rev(fname:%s;platform_id:0x%x) = %s\n" \
|
|
|
c59b13 |
"$ucode_fname" "$_pf" "$rev"
|
|
|
c59b13 |
|
|
|
c59b13 |
_pf_mask=$((_pf_mask / 2))
|
|
|
c59b13 |
_pf=$((_pf * 2))
|
|
|
c59b13 |
done
|
|
|
c59b13 |
|
|
|
c59b13 |
# Generate tags with codename information, in case
|
|
|
c59b13 |
# it is available
|
|
|
c59b13 |
if [ -e "$CODENAMES" ]; then
|
|
|
c56524 |
cpuid_up="$(echo "$cpuid" | tr 'a-z' 'A-Z')"
|
|
|
c56524 |
cpuid_short="$(printf "%x" "0x$cpuid")"
|
|
|
c56524 |
(grep ' '"$cpuid_up"' ' "$CODENAMES" || :; grep ';'"$cpuid_short"';' "$CODENAMES" || :) \
|
|
|
c56524 |
| while IFS=$';\t' read segm int_fname codename stepping candidate_pf cpuid_cn cname variants rest; do
|
|
|
c56524 |
[ "x${segm###}" = "x$segm" ] || continue
|
|
|
c56524 |
[ -n "${segm}" ] || continue
|
|
|
c59b13 |
codename=$(echo "$codename" | tr ' (),' '_[];')
|
|
|
c59b13 |
candidate_pf=$(printf "%u" "0x${candidate_pf}")
|
|
|
c56524 |
(IFS=','; for s in $stepping; do
|
|
|
c56524 |
[ \( 0 -ne "$pf_mask" \) -a \
|
|
|
c56524 |
\( 0 -eq "$((candidate_pf & pf_mask))" \) ] || { \
|
|
|
c56524 |
printf "iucode_rev(fname:%s;cpuid:%s;pf_mask:0x%x;segment:\"%s\";codename:\"%s\";stepping:\"%s\";pf_model:0x%x) = %s\n" \
|
|
|
c56524 |
"$ucode_fname" "$cpuid" "$pf_mask" \
|
|
|
c56524 |
"$segm" "$codename" "$s" "$candidate_pf" \
|
|
|
c56524 |
"$rev";
|
|
|
c56524 |
printf "iucode_date(fname:%s;cpuid:%s;pf_mask:0x%x;segment:\"%s\";codename:\"%s\";stepping:\"%s\";pf_model:0x%x) = %s.%s.%s\n" \
|
|
|
c56524 |
"$ucode_fname" "$cpuid" "$pf_mask" \
|
|
|
c56524 |
"$segm" "$codename" "$s" "$candidate_pf" \
|
|
|
c56524 |
"$date_y" "$date_m" "$date_d";
|
|
|
c56524 |
if [ "$cpuid_short" = "$cpuid_cn" -a -n "$variants" ]; then
|
|
|
c56524 |
(IFS=','; for v in $variants; do
|
|
|
c56524 |
v=$(echo "$v" | tr ' (),' '_[];')
|
|
|
c56524 |
printf "iucode_rev(fname:%s;cpuid:%s;pf_mask:0x%x;segment:\"%s\";codename:\"%s_%s\";stepping:\"%s\";pf_model:0x%x) = %s\n" \
|
|
|
c56524 |
"$ucode_fname" "$cpuid" "$pf_mask" \
|
|
|
c56524 |
"$segm" "$codename" "$v" "$s" "$candidate_pf" \
|
|
|
c56524 |
"$rev";
|
|
|
c56524 |
printf "iucode_date(fname:%s;cpuid:%s;pf_mask:0x%x;segment:\"%s\";codename:\"%s_%s\";stepping:\"%s\";pf_model:0x%x) = %s.%s.%s\n" \
|
|
|
c56524 |
"$ucode_fname" "$cpuid" "$pf_mask" \
|
|
|
c56524 |
"$segm" "$codename" "$v" "$s" "$candidate_pf" \
|
|
|
c56524 |
"$date_y" "$date_m" "$date_d";
|
|
|
c56524 |
done)
|
|
|
c56524 |
fi
|
|
|
c56524 |
}
|
|
|
c56524 |
done)
|
|
|
c59b13 |
done
|
|
|
c59b13 |
fi
|
|
|
c59b13 |
|
|
|
c59b13 |
# Kludge squared: generate additional "Provides:" tags
|
|
|
c59b13 |
# for the files in the overrides tarball (that a placed
|
|
|
c59b13 |
# in a separate caveat with a specific name)
|
|
|
c59b13 |
[ "x${ucode_caveat}" != "x${UPDATED}" ] || {
|
|
|
c59b13 |
printf "firmware_updated(intel-ucode/%s) = %s\n" \
|
|
|
c59b13 |
"$ucode" "$rev";
|
|
|
c59b13 |
}
|
|
|
c59b13 |
done
|
|
|
c59b13 |
done | sort -u
|