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 12f739c8b7SAndy Fiddaman# Copyright 2022 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 19f739c8b7SAndy Fiddamanfunction errexit { 20f739c8b7SAndy Fiddaman echo "$@" >&2 21eb7a235aSDan McDonald exit 1 22eb7a235aSDan McDonald} 2316b19c8cSDan McDonald 24f739c8b7SAndy Fiddaman[[ -n "$1" && -f "$1" ]] || errexit "Syntax: $0 <path to microcode tar>" 25f739c8b7SAndy Fiddaman 26eb7a235aSDan McDonalducodetar="$1" 2755908bd7SJohn Levon 28f739c8b7SAndy FiddamanFW=platform/i86pc/ucode/GenuineIntel 29*dd03b475SAndy FiddamanLINKSF=intel/Makefile.links 30f739c8b7SAndy Fiddaman 31f739c8b7SAndy Fiddamanexport LC_ALL=C.UTF-8 32f739c8b7SAndy Fiddaman 33f739c8b7SAndy Fiddamanset -e 34f739c8b7SAndy Fiddamanset -o pipefail 35f739c8b7SAndy Fiddaman 3625b05a3eSAndy Fiddamanmf=../../pkg/manifests/system-microcode-intel.p5m 37f739c8b7SAndy Fiddaman[[ -f $mf ]] || errexit "Run from usr/src/data/ucode" 38f739c8b7SAndy Fiddaman 39f739c8b7SAndy Fiddamanfunction find_cmd { 40f739c8b7SAndy Fiddaman typeset cmd="$1" 41f739c8b7SAndy Fiddaman typeset var=$(echo $cmd | tr '[:lower:]' '[:upper:]') 42f739c8b7SAndy Fiddaman typeset -n path="$var" 43f739c8b7SAndy Fiddaman path=$(whence -fp "$cmd") 44f739c8b7SAndy Fiddaman if (($? != 0)) || [ ! -x "$path" ]; then 45f739c8b7SAndy Fiddaman errexit "Cannot find executable '$cmd' in PATH" 46f739c8b7SAndy Fiddaman fi 4755908bd7SJohn Levon} 4855908bd7SJohn Levon 49f739c8b7SAndy Fiddaman# This script uses a few commands which are not part of illumos and are 50f739c8b7SAndy Fiddaman# expected to be available in the path. 51f739c8b7SAndy Fiddamanfind_cmd gtar 52f739c8b7SAndy Fiddamanfind_cmd pkgfmt 53f739c8b7SAndy Fiddaman# Search for 'ucodeadm'. If you need to use an updated ucodeadm to handle this 54f739c8b7SAndy Fiddaman# firmware update, as is occasionally necessary, ensure it occurs earlier in 55f739c8b7SAndy Fiddaman# the path than /usr/sbin. 56f739c8b7SAndy Fiddamanfind_cmd ucodeadm 5755908bd7SJohn Levon 58eb7a235aSDan McDonaldtmp=$(mktemp -d) 59f739c8b7SAndy Fiddaman[[ -n "$tmp" && -d "$tmp" ]] 60f739c8b7SAndy Fiddamanmkdir $tmp/out || errexit "Failed to create temporary directory" 61f739c8b7SAndy Fiddamantrap 'rm -rf $tmp' EXIT 62f739c8b7SAndy Fiddaman 63f739c8b7SAndy Fiddaman# The distributed microcode archive uses GNU extensions 64f739c8b7SAndy Fiddaman$GTAR -C $tmp -xvf "$ucodetar" 65eb7a235aSDan McDonald 66f739c8b7SAndy Fiddamanpath=$({ cd $tmp; echo Intel-Linux-Processor-Microcode-Data*; }) 67f739c8b7SAndy Fiddamanver=${path##*-} 68f739c8b7SAndy Fiddamanecho "** Updating to microcode version $ver" 69eb7a235aSDan McDonald 70f739c8b7SAndy Fiddamanfind $tmp/$path/intel-ucode*/ -type f | while read f; do 7155908bd7SJohn Levon echo "Converting $(basename $f)" 7255908bd7SJohn Levon cp $f $tmp/intel-fw 73f739c8b7SAndy Fiddaman $UCODEADM -i -R $tmp/out $tmp/intel-fw 7455908bd7SJohn Levon rm -f $tmp/intel-fw 7555908bd7SJohn Levondone 7655908bd7SJohn Levon 77f739c8b7SAndy Fiddaman$PKGFMT -u $mf 7855908bd7SJohn Levonmv $mf $mf.tmp 79f739c8b7SAndy Fiddamanegrep -v "(file|hardlink) path=$FW" $mf.tmp > $mf 8055908bd7SJohn Levonrm -f $mf.tmp 8155908bd7SJohn Levon 82*dd03b475SAndy Fiddamanrm -f intel/*-* 83225bb523SAndy Fiddaman 84f739c8b7SAndy Fiddamancp $tmp/$path/license intel/THIRDPARTYLICENSE 85225bb523SAndy Fiddamanecho Intel Processor Microcode Data Files > intel/THIRDPARTYLICENSE.descrip 86225bb523SAndy Fiddaman 87*dd03b475SAndy Fiddamanrm -f $LINKSF 8855908bd7SJohn Levon 8955908bd7SJohn Levontypeset -A seen 9055908bd7SJohn Levontypeset -A inodes 9155908bd7SJohn Levontypeset -A links 9255908bd7SJohn Levon 9355908bd7SJohn Levonfor f in $tmp/out/*; do 9455908bd7SJohn Levon bf=$(basename $f) 9555908bd7SJohn Levon [[ -n "${seen[$bf]}" ]] && continue 9655908bd7SJohn Levon inode=$(stat -c %i $f) 9755908bd7SJohn Levon if [[ -n "${inodes[$inode]}" ]]; then 9855908bd7SJohn Levon links[$bf]=${inodes[$inode]} 9955908bd7SJohn Levon else 10055908bd7SJohn Levon inodes[$inode]=$bf 10155908bd7SJohn Levon cp $f intel/$bf 10255908bd7SJohn Levon fi 10355908bd7SJohn Levon seen[$bf]=1 10455908bd7SJohn Levondone 10555908bd7SJohn Levon 10655908bd7SJohn Levonfor f in intel/*; do 10755908bd7SJohn Levon bf=$(basename $f) 108225bb523SAndy Fiddaman [[ $bf = THIRDPARTYLICENSE* ]] && continue 109*dd03b475SAndy Fiddaman [[ $bf = Makefile* ]] && continue 110f739c8b7SAndy Fiddaman echo "file path=$FW/$bf group=sys mode=0444 reboot-needed=true" >> $mf 11155908bd7SJohn Levondone 11255908bd7SJohn Levon 113225bb523SAndy Fiddaman( 114225bb523SAndy Fiddaman sed '/^$/q' < ../../prototypes/prototype.Makefile 115225bb523SAndy Fiddaman echo 'INTEL_LINKS = \' 116225bb523SAndy Fiddaman for i in "${!links[@]}"; do 117225bb523SAndy Fiddaman echo "\t$i \\" 118225bb523SAndy Fiddaman done | sed '$s/ .*//' 119225bb523SAndy Fiddaman echo 120*dd03b475SAndy Fiddaman) > $LINKSF 12155908bd7SJohn Levon 12255908bd7SJohn Levonfor i in "${!links[@]}"; do 123f739c8b7SAndy Fiddaman echo "hardlink path=$FW/$i target=${links[$i]}" >> $mf 124*dd03b475SAndy Fiddaman cat << EOM >> $LINKSF 12555908bd7SJohn Levon\$(ROOTINTELDIR)/$i: \$(ROOTINTELDIR)/${links[$i]} 12655908bd7SJohn Levon \$(RM) \$@; \$(LN) \$^ \$@ 12755908bd7SJohn Levon 12855908bd7SJohn LevonEOM 12955908bd7SJohn Levondone 13055908bd7SJohn Levon 131f739c8b7SAndy Fiddamansed -i "/pkg.fmri.*microcode\/intel@/s/@[0-9]*/@$ver/" $mf 132f739c8b7SAndy Fiddaman 133f739c8b7SAndy Fiddaman$PKGFMT -fv2 $mf 13455908bd7SJohn Levon 135