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 2020 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# Remove this once we start using pkgfmt without it in the rest of -gate. 23export PKGFMT_OUTPUT=v1 24 25# Change me if the world evolves, but for now, this is the source of 26# truth for Intel microcode. 27REPOSOURCE="https://github.com/intel/Intel-Linux-Processor-Microcode-Data-Files" 28 29tmp=$(mktemp -d) 30mkdir $tmp/out 31mf=../../pkg/manifests/system-microcode-intel.mf 32[[ -f $mf ]] || { 33 echo "Run from usr/src/data/ucode" 2>&1 34 exit 1 35} 36 37fw=platform/i86pc/ucode/GenuineIntel 38 39if [[ -z "$1" ]]; then 40 goback=`pwd` 41 cd $tmp 42 # Hope git is available if we need it... 43 git clone $REPOSOURCE || { 44 echo "Git clone of $REPOSOURCE failed." 2>&1 45 exit 1 46 } 47 cd $goback 48 # Change with REPOSOURCE name 49 dir=$tmp/Intel-Linux-Processor-Microcode-Data-Files 50elif [[ -d "$1" ]]; then 51 dir=$1 52else 53 gtar -C $tmp -xvf "$1" 54 # This will expand properly if the tarball appends a release 55 # to the name. 56 dir=$tmp/Intel-Linux-Processor-Microcode-Data-Files* 57fi 58 59find $dir/intel-ucode*/ -type f \ 60 | while read f; do 61 echo "Converting $(basename $f)" 62 cp $f $tmp/intel-fw 63 ucodeadm -i -R $tmp/out $tmp/intel-fw 64 rm -f $tmp/intel-fw 65done 66 67pkgfmt -u $mf 68mv $mf $mf.tmp 69egrep -v "(file|hardlink) path=$fw" $mf.tmp > $mf 70rm -f $mf.tmp 71 72rm -f intel/* 73 74cp $dir/license intel/THIRDPARTYLICENSE 75echo Intel Processor Microcode Data Files > intel/THIRDPARTYLICENSE.descrip 76 77rm -f Makefile.links 78 79typeset -A seen 80typeset -A inodes 81typeset -A links 82 83for f in $tmp/out/*; do 84 bf=$(basename $f) 85 [[ -n "${seen[$bf]}" ]] && continue 86 inode=$(stat -c %i $f) 87 if [[ -n "${inodes[$inode]}" ]]; then 88 links[$bf]=${inodes[$inode]} 89 else 90 inodes[$inode]=$bf 91 cp $f intel/$bf 92 fi 93 seen[$bf]=1 94done 95 96for f in intel/*; do 97 bf=$(basename $f) 98 [[ $bf = THIRDPARTYLICENSE* ]] && continue 99 echo "file path=$fw/$bf group=sys mode=0444 reboot-needed=true" >> $mf 100done 101 102( 103 sed '/^$/q' < ../../prototypes/prototype.Makefile 104 echo 'INTEL_LINKS = \' 105 for i in "${!links[@]}"; do 106 echo "\t$i \\" 107 done | sed '$s/ .*//' 108 echo 109) > Makefile.links 110 111for i in "${!links[@]}"; do 112 echo "hardlink path=$fw/$i target=${links[$i]}" >> $mf 113 cat << EOM >> Makefile.links 114\$(ROOTINTELDIR)/$i: \$(ROOTINTELDIR)/${links[$i]} 115 \$(RM) \$@; \$(LN) \$^ \$@ 116 117EOM 118done 119 120pkgfmt $mf 121 122rm -rf $tmp 123