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 12*225bb523SAndy Fiddaman# Copyright 2019 OmniOS Community Edition (OmniOSce) Association. 1355908bd7SJohn Levon# 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 2255908bd7SJohn Levon[[ -z "$1" ]] || [[ ! -f "$1" ]] && { 2355908bd7SJohn Levon echo "Syntax: $0 <path to microcode tar>" >&2 2455908bd7SJohn Levon exit 1 2555908bd7SJohn Levon} 2655908bd7SJohn Levon 2755908bd7SJohn Levonucodetar="$1" 2855908bd7SJohn Levon 29*225bb523SAndy Fiddamanmf=../../pkg/manifests/system-microcode-intel.mf 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 3755908bd7SJohn Levontmp=$(mktemp -d) 3855908bd7SJohn Levonmkdir $tmp/out 3955908bd7SJohn Levon 4055908bd7SJohn Levongtar -C $tmp -xvf "$ucodetar" 4155908bd7SJohn Levon 4255908bd7SJohn Levonfind $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/* 56*225bb523SAndy Fiddaman 57*225bb523SAndy Fiddamancp $tmp/Intel-Linux-Processor-Microcode-Data*/license intel/THIRDPARTYLICENSE 58*225bb523SAndy Fiddamanecho Intel Processor Microcode Data Files > intel/THIRDPARTYLICENSE.descrip 59*225bb523SAndy 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) 81*225bb523SAndy Fiddaman [[ $bf = THIRDPARTYLICENSE* ]] && continue 82*225bb523SAndy Fiddaman echo "file path=$fw/$bf group=sys mode=0444 reboot-needed=true" >> $mf 8355908bd7SJohn Levondone 8455908bd7SJohn Levon 85*225bb523SAndy Fiddaman( 86*225bb523SAndy Fiddaman sed '/^$/q' < ../../prototypes/prototype.Makefile 87*225bb523SAndy Fiddaman echo 'INTEL_LINKS = \' 88*225bb523SAndy Fiddaman for i in "${!links[@]}"; do 89*225bb523SAndy Fiddaman echo "\t$i \\" 90*225bb523SAndy Fiddaman done | sed '$s/ .*//' 91*225bb523SAndy Fiddaman echo 92*225bb523SAndy Fiddaman) > Makefile.links 9355908bd7SJohn Levon 9455908bd7SJohn Levonfor i in "${!links[@]}"; do 95*225bb523SAndy 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 10355908bd7SJohn Levonpkgfmt $mf 10455908bd7SJohn Levon 10555908bd7SJohn Levonrm -rf $tmp 106