Changeset View
Changeset View
Standalone View
Standalone View
sysutils/devcpu-data/files/microcode_update.in
#!/bin/sh | #!/bin/sh | ||||
# PROVIDE: microcode_update | # PROVIDE: microcode_update | ||||
# REQUIRE: root mountcritlocal | # REQUIRE: root mountcritlocal | ||||
# KEYWORD: nojail | # KEYWORD: nojail | ||||
# BEFORE: SERVERS | # BEFORE: SERVERS | ||||
# | # | ||||
# Add the following line to /etc/rc.conf to enable flow-capture: | # Add the following line to /etc/rc.conf to enable flow-capture: | ||||
# microcode_update_enable (bool): Set it to "YES" to update microcode on startup | # microcode_update_enable (bool): Set it to "YES" to update microcode on startup | ||||
# Set to "NO" by default. | # Set to "NO" by default. | ||||
# microcode_update_datadir (str): Directory, microcode updates stored in. | # microcode_update_datadir (str): Directory, microcode updates stored in. | ||||
# Default is "%%DATADIR%%" | # Default is "%%DATADIR%%" | ||||
# microcode_update_cpus (str): A list of cpus to update on startup, or "ALL" for all. | # microcode_update_cpus (str): A list of cpus to update on startup, or "ALL" for all. | ||||
# Example: microcode_update_cpus_cpus="0 CPU0" | # Example: microcode_update_cpus="0 1" | ||||
# Set to "ALL" by default. | # Set to "ALL" by default. | ||||
# microcode_update_flags (str): Flags for cpucontrol(8). | # microcode_update_flags (str): Flags for cpucontrol(8). | ||||
. /etc/rc.subr | . /etc/rc.subr | ||||
name="microcode_update" | name="microcode_update" | ||||
rcvar=microcode_update_enable | rcvar=microcode_update_enable | ||||
stop_cmd=":" | stop_cmd=":" | ||||
Show All 11 Lines | if ! kldload cpuctl > /dev/null 2>&1; then | ||||
return 1 | return 1 | ||||
fi | fi | ||||
fi | fi | ||||
} | } | ||||
microcode_update_start() | microcode_update_start() | ||||
{ | { | ||||
echo "Updating CPU Microcode..." | echo "Updating CPU Microcode..." | ||||
if [ "${microcode_cpus}" = "ALL" ]; then | if [ "${microcode_update_cpus}" = "ALL" ]; then | ||||
ncpu=`/sbin/sysctl -n hw.ncpu` | ncpu=`/sbin/sysctl -n hw.ncpu` | ||||
cpus=`jot ${ncpu} 0`; | cpus=`jot ${ncpu} 0`; | ||||
else | else | ||||
cpus=${microcode_cpus} | cpus=${microcode_update_cpus} | ||||
fi | fi | ||||
for i in ${cpus}; do | for i in ${cpus}; do | ||||
${CMT} -u ${microcode_update_flags} \ | ${CMT} -u ${microcode_update_flags} \ | ||||
-d "${microcode_update_datadir}" /dev/cpuctl${i} 2>&1 | \ | -d "${microcode_update_datadir}" /dev/cpuctl${i} 2>&1 | \ | ||||
logger -p daemon.notice -t microcode_update || \ | logger -p daemon.notice -t microcode_update || \ | ||||
(echo "Microcode Update Failed." && exit 1) | (echo "Microcode Update Failed." && exit 1) | ||||
done | done | ||||
if [ "${microcode_cpus}" = "ALL" ]; then | if [ "${microcode_update_cpus}" = "ALL" ]; then | ||||
CPUCONTROL_UPDATED=$(cpucontrol -h 2>&1 | grep -q -- -e; echo $?) | CPUCONTROL_UPDATED=$(cpucontrol -h 2>&1 | grep -q -- -e; echo $?) | ||||
if [ ${CPUCONTROL_UPDATED} -ne 0 ]; then | if [ ${CPUCONTROL_UPDATED} -ne 0 ]; then | ||||
echo "Please update your system in order to update CPU microcode." | echo "Please update your system in order to update CPU microcode." | ||||
else | else | ||||
${CMT} -e /dev/cpuctl0 >/dev/null 2>&1 | ${CMT} -e /dev/cpuctl0 >/dev/null 2>&1 | ||||
if [ $? -ne 0 ]; then | if [ $? -ne 0 ]; then | ||||
echo "Re-evalulation of CPU flags Failed." | echo "Re-evalulation of CPU flags Failed." | ||||
exit 1 | exit 1 | ||||
fi | fi | ||||
fi | fi | ||||
fi | fi | ||||
echo "Done." | echo "Done." | ||||
} | } | ||||
load_rc_config $name | load_rc_config $name | ||||
# Set default values | # Set default values | ||||
if [ -n "${microcode_cpus}" ]; then | |||||
if [ -n "${microcode_update_cpus}" ]; then | |||||
echo "Warning: Ignoring deprecated rc variable, microcode_cpus." | |||||
else | |||||
echo "Warning: rc variable microcode_cpus is deprecated. | |||||
Warning: Set microcode_udpate_cpus instead." | |||||
microcode_update_cpus="${microcode_cpus}" | |||||
fi | |||||
fi | |||||
: ${microcode_update_enable="NO"} | : ${microcode_update_enable="NO"} | ||||
: ${microcode_update_datadir="%%DATADIR%%"} | : ${microcode_update_datadir="%%DATADIR%%"} | ||||
: ${microcode_cpus="ALL"} | : ${microcode_update_cpus="ALL"} | ||||
: ${microcode_update_flags=""} | : ${microcode_update_flags=""} | ||||
run_rc_command "$1" | run_rc_command "$1" |