xref: /illumos-gate/usr/src/data/ucode/update.intel (revision 37395faa43a95e030f79ca75d81f5e4fdfcd2b19)
1#!/bin/ksh
2
3# This file and its contents are supplied under the terms of the
4# Common Development and Distribution License ("CDDL"), version 1.0.
5# You may only use this file in accordance with the terms of version
6# 1.0 of the CDDL.
7#
8# A full copy of the text of the CDDL should have accompanied this
9# source. A copy of the CDDL is also available via the Internet at
10# http://www.illumos.org/license/CDDL.
11
12# Copyright 2019 OmniOS Community Edition (OmniOSce) Association.
13# Copyright 2019 Joyent, Inc.
14
15# A simple update script that extracts an Intel microcode download file
16# into the intel/ directory, and updates the hardlinks in the
17# system/kernel/platform manifest.
18
19set -e
20set -o pipefail
21
22[[ -z "$1" ]] || [[ ! -f "$1" ]] && {
23	echo "Syntax: $0 <path to microcode tar>" >&2
24	exit 1
25}
26
27ucodetar="$1"
28
29mf=../../pkg/manifests/system-microcode-intel.mf
30[[ -f $mf ]] || {
31	echo "Run from usr/src/data/ucode" 2>&1
32	exit 1
33}
34
35fw=platform/i86pc/ucode/GenuineIntel
36
37tmp=$(mktemp -d)
38mkdir $tmp/out
39
40gtar -C $tmp -xvf "$ucodetar"
41
42find $tmp/Intel-Linux-Processor-Microcode-Data*/intel-ucode*/ -type f \
43    | while read f; do
44	echo "Converting $(basename $f)"
45	cp $f $tmp/intel-fw
46	ucodeadm -i -R $tmp/out $tmp/intel-fw
47	rm -f $tmp/intel-fw
48done
49
50pkgfmt -u $mf
51mv $mf $mf.tmp
52egrep -v "(file|hardlink) path=$fw" $mf.tmp > $mf
53rm -f $mf.tmp
54
55rm -f intel/*
56
57cp $tmp/Intel-Linux-Processor-Microcode-Data*/license intel/THIRDPARTYLICENSE
58echo Intel Processor Microcode Data Files > intel/THIRDPARTYLICENSE.descrip
59
60rm -f Makefile.links
61
62typeset -A seen
63typeset -A inodes
64typeset -A links
65
66for f in $tmp/out/*; do
67	bf=$(basename $f)
68	[[ -n "${seen[$bf]}" ]] && continue
69	inode=$(stat -c %i $f)
70	if [[ -n "${inodes[$inode]}" ]]; then
71		links[$bf]=${inodes[$inode]}
72	else
73		inodes[$inode]=$bf
74		cp $f intel/$bf
75	fi
76	seen[$bf]=1
77done
78
79for f in intel/*; do
80	bf=$(basename $f)
81	[[ $bf = THIRDPARTYLICENSE* ]] && continue
82	echo "file path=$fw/$bf group=sys mode=0444 reboot-needed=true" >> $mf
83done
84
85(
86	sed '/^$/q' < ../../prototypes/prototype.Makefile
87	echo 'INTEL_LINKS = \'
88	for i in "${!links[@]}"; do
89		echo "\t$i \\"
90	done | sed '$s/ .*//'
91	echo
92) > Makefile.links
93
94for i in "${!links[@]}"; do
95	echo "hardlink path=$fw/$i target=${links[$i]}" >> $mf
96	cat << EOM >> Makefile.links
97\$(ROOTINTELDIR)/$i: \$(ROOTINTELDIR)/${links[$i]}
98	\$(RM) \$@; \$(LN) \$^ \$@
99
100EOM
101done
102
103pkgfmt $mf
104
105rm -rf $tmp
106