blob: 005845df4f56d42efb5017023414ab4d1036719c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
#!/bin/sh
# PROVIDE: microcode_update
# REQUIRE: root mountcritlocal
# KEYWORD: nojail
# BEFORE: SERVERS
#
# 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
# Set to "NO" by default.
# microcode_update_datadir (str): Directory, microcode updates stored in.
# Default is "%%DATADIR%%"
# microcode_update_cpus (str): A list of cpus to update on startup, or "ALL" for all.
# Example: microcode_update_cpus_cpus="0 CPU0"
# Set to "ALL" by default.
# microcode_update_flags (str): Flags for cpucontrol(8).
. /etc/rc.subr
name="microcode_update"
rcvar=microcode_update_enable
stop_cmd=":"
start_precmd="microcode_update_prepare"
start_cmd="microcode_update_start"
requires_modules="cpuctl"
CMT="/usr/sbin/cpucontrol"
microcode_update_prepare()
{
if ! kldstat -q -m cpuctl; then
if ! kldload cpuctl > /dev/null 2>&1; then
warn "Can't load cpuctl module."
return 1
fi
fi
}
microcode_update_start()
{
echo "Updating CPU Microcode..."
if [ "${microcode_cpus}" = "ALL" ]; then
ncpu=`/sbin/sysctl -n hw.ncpu`
cpus=`jot ${ncpu} 0`;
else
cpus=${microcode_cpus}
fi
for i in ${cpus}; do
${CMT} -u ${microcode_update_flags} \
-d "${microcode_update_datadir}" /dev/cpuctl${i} 2>&1 | \
logger -p daemon.notice -t microcode_update || \
(echo "Microcode Update Failed." && exit 1)
done
if [ "${microcode_cpus}" = "ALL" ]; then
CPUCONTROL_UPDATED=$(cpucontrol -h 2>&1 | grep -q -- -e; echo $?)
if [ ${CPUCONTROL_UPDATED} -ne 0 ]; then
echo "Please update your system in order to update CPU microcode."
else
${CMT} -e /dev/cpuctl0 >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Re-evalulation of CPU flags Failed."
exit 1
fi
fi
fi
echo "Done."
}
load_rc_config $name
# Set default values
: ${microcode_update_enable="NO"}
: ${microcode_update_datadir="%%DATADIR%%"}
: ${microcode_cpus="ALL"}
: ${microcode_update_flags=""}
run_rc_command "$1"
|