xref: /illumos-gate/usr/src/data/ucode/update.intel (revision 25b05a3e)
155908bd7SJohn Levon#!/bin/ksh
255908bd7SJohn Levon
355908bd7SJohn Levon# This file and its contents are supplied under the terms of the
455908bd7SJohn Levon# Common Development and Distribution License ("CDDL"), version 1.0.
555908bd7SJohn Levon# You may only use this file in accordance with the terms of version
655908bd7SJohn Levon# 1.0 of the CDDL.
755908bd7SJohn Levon#
855908bd7SJohn Levon# A full copy of the text of the CDDL should have accompanied this
955908bd7SJohn Levon# source. A copy of the CDDL is also available via the Internet at
1055908bd7SJohn Levon# http://www.illumos.org/license/CDDL.
1155908bd7SJohn Levon
12225bb523SAndy Fiddaman# Copyright 2019 OmniOS Community Edition (OmniOSce) Association.
13eb7a235aSDan McDonald# Copyright 2019 Joyent, Inc.
1455908bd7SJohn Levon
1555908bd7SJohn Levon# A simple update script that extracts an Intel microcode download file
1655908bd7SJohn Levon# into the intel/ directory, and updates the hardlinks in the
1755908bd7SJohn Levon# system/kernel/platform manifest.
1855908bd7SJohn Levon
1955908bd7SJohn Levonset -e
2055908bd7SJohn Levonset -o pipefail
2155908bd7SJohn Levon
22eb7a235aSDan McDonald[[ -z "$1" ]] || [[ ! -f "$1" ]] && {
23eb7a235aSDan McDonald	echo "Syntax: $0 <path to microcode tar>" >&2
24eb7a235aSDan McDonald	exit 1
25eb7a235aSDan McDonald}
2616b19c8cSDan McDonald
27eb7a235aSDan McDonalducodetar="$1"
2855908bd7SJohn Levon
29*25b05a3eSAndy Fiddamanmf=../../pkg/manifests/system-microcode-intel.p5m
3055908bd7SJohn Levon[[ -f $mf ]] || {
3155908bd7SJohn Levon	echo "Run from usr/src/data/ucode" 2>&1
3255908bd7SJohn Levon	exit 1
3355908bd7SJohn Levon}
3455908bd7SJohn Levon
3555908bd7SJohn Levonfw=platform/i86pc/ucode/GenuineIntel
3655908bd7SJohn Levon
37eb7a235aSDan McDonaldtmp=$(mktemp -d)
38eb7a235aSDan McDonaldmkdir $tmp/out
39eb7a235aSDan McDonald
40eb7a235aSDan McDonaldgtar -C $tmp -xvf "$ucodetar"
41eb7a235aSDan McDonald
42eb7a235aSDan McDonaldfind $tmp/Intel-Linux-Processor-Microcode-Data*/intel-ucode*/ -type f \
4355908bd7SJohn Levon    | while read f; do
4455908bd7SJohn Levon	echo "Converting $(basename $f)"
4555908bd7SJohn Levon	cp $f $tmp/intel-fw
4655908bd7SJohn Levon	ucodeadm -i -R $tmp/out $tmp/intel-fw
4755908bd7SJohn Levon	rm -f $tmp/intel-fw
4855908bd7SJohn Levondone
4955908bd7SJohn Levon
5055908bd7SJohn Levonpkgfmt -u $mf
5155908bd7SJohn Levonmv $mf $mf.tmp
5255908bd7SJohn Levonegrep -v "(file|hardlink) path=$fw" $mf.tmp > $mf
5355908bd7SJohn Levonrm -f $mf.tmp
5455908bd7SJohn Levon
5555908bd7SJohn Levonrm -f intel/*
56225bb523SAndy Fiddaman
57eb7a235aSDan McDonaldcp $tmp/Intel-Linux-Processor-Microcode-Data*/license intel/THIRDPARTYLICENSE
58225bb523SAndy Fiddamanecho Intel Processor Microcode Data Files > intel/THIRDPARTYLICENSE.descrip
59225bb523SAndy Fiddaman
6055908bd7SJohn Levonrm -f Makefile.links
6155908bd7SJohn Levon
6255908bd7SJohn Levontypeset -A seen
6355908bd7SJohn Levontypeset -A inodes
6455908bd7SJohn Levontypeset -A links
6555908bd7SJohn Levon
6655908bd7SJohn Levonfor f in $tmp/out/*; do
6755908bd7SJohn Levon	bf=$(basename $f)
6855908bd7SJohn Levon	[[ -n "${seen[$bf]}" ]] && continue
6955908bd7SJohn Levon	inode=$(stat -c %i $f)
7055908bd7SJohn Levon	if [[ -n "${inodes[$inode]}" ]]; then
7155908bd7SJohn Levon		links[$bf]=${inodes[$inode]}
7255908bd7SJohn Levon	else
7355908bd7SJohn Levon		inodes[$inode]=$bf
7455908bd7SJohn Levon		cp $f intel/$bf
7555908bd7SJohn Levon	fi
7655908bd7SJohn Levon	seen[$bf]=1
7755908bd7SJohn Levondone
7855908bd7SJohn Levon
7955908bd7SJohn Levonfor f in intel/*; do
8055908bd7SJohn Levon	bf=$(basename $f)
81225bb523SAndy Fiddaman	[[ $bf = THIRDPARTYLICENSE* ]] && continue
82225bb523SAndy Fiddaman	echo "file path=$fw/$bf group=sys mode=0444 reboot-needed=true" >> $mf
8355908bd7SJohn Levondone
8455908bd7SJohn Levon
85225bb523SAndy Fiddaman(
86225bb523SAndy Fiddaman	sed '/^$/q' < ../../prototypes/prototype.Makefile
87225bb523SAndy Fiddaman	echo 'INTEL_LINKS = \'
88225bb523SAndy Fiddaman	for i in "${!links[@]}"; do
89225bb523SAndy Fiddaman		echo "\t$i \\"
90225bb523SAndy Fiddaman	done | sed '$s/ .*//'
91225bb523SAndy Fiddaman	echo
92225bb523SAndy Fiddaman) > Makefile.links
9355908bd7SJohn Levon
9455908bd7SJohn Levonfor i in "${!links[@]}"; do
95225bb523SAndy Fiddaman	echo "hardlink path=$fw/$i target=${links[$i]}" >> $mf
9655908bd7SJohn Levon	cat << EOM >> Makefile.links
9755908bd7SJohn Levon\$(ROOTINTELDIR)/$i: \$(ROOTINTELDIR)/${links[$i]}
9855908bd7SJohn Levon	\$(RM) \$@; \$(LN) \$^ \$@
9955908bd7SJohn Levon
10055908bd7SJohn LevonEOM
10155908bd7SJohn Levondone
10255908bd7SJohn Levon
10386d41711SAndy Fiddamanpkgfmt -fv2 $mf
10455908bd7SJohn Levon
10555908bd7SJohn Levonrm -rf $tmp