Ravenports generated: 21 Feb 2024 20:00
[ravenports.git] / bucket_59 / cpu-microcode-rc
1 # Buildsheet autogenerated by ravenadm tool -- Do not edit.
2
3 NAMEBASE=               cpu-microcode-rc
4 VERSION=                1.0
5 KEYWORDS=               sysutils
6 VARIANTS=               standard
7 SDESC[standard]=        RC script for CPU microcode updates
8 HOMEPAGE=               none
9 CONTACT=                nobody
10
11 DOWNLOAD_GROUPS=        none
12 SPKGS[standard]=        single
13
14 OPTIONS_AVAILABLE=      none
15 OPTIONS_STANDARD=       none
16
17 NOT_FOR_ARCH=           aarch64
18
19 FPC_EQUIVALENT=         sysutils/cpu-microcode-rc
20
21 SKIP_BUILD=             yes
22
23 SKIP_INSTALL=           yes
24 RC_SUBR=                microcode_update:single
25 SUB_FILES=              pkg-message-single
26 SUB_LIST=               DATADIR="{{PREFIX}}/share/cpucontrol"
27
28 [FILE:215:descriptions/desc.single]
29 An RC script for use with the cpuctl(4) microcode update facility to keep
30 your processor's firmware up-to-date.  CPU microcode data must be installed
31 from a vendor.  See devcpu-data-amd and devcpu-data-intel ports.
32
33
34 [FILE:2251:files/microcode_update.in]
35 #!/bin/sh
36
37 # PROVIDE:      microcode_update
38 # REQUIRE:      root mountcritlocal
39 # KEYWORD:      nojail
40 # BEFORE:       SERVERS
41
42 #
43 # Add the following line to /etc/rc.conf to enable flow-capture:
44 # microcode_update_enable (bool):       Set it to "YES" to update microcode on startup
45 #                                       Set to "NO" by default.
46 # microcode_update_datadir (str):       Directory, microcode updates stored in.
47 #                                       Default is "%%DATADIR%%"
48 # microcode_update_cpus (str):          A list of cpus to update on startup, or "ALL" for all.
49 #                                       Example: microcode_update_cpus="0 1"
50 #                                       Set to "ALL" by default. 
51 # microcode_update_flags (str):         Flags for cpucontrol(8).
52
53 . /etc/rc.subr
54
55 name="microcode_update"
56 rcvar=microcode_update_enable
57 stop_cmd=":"
58 start_cmd="microcode_update_start"
59 required_modules="cpuctl"
60
61 CMT="/usr/sbin/cpucontrol"
62
63 microcode_update_start()
64 {
65         echo "Updating CPU Microcode..."
66         if [ "${microcode_update_cpus}" = "ALL" ]; then
67                 ncpu=`/sbin/sysctl -n hw.ncpu`
68                 cpus=`jot ${ncpu} 0`;
69         else
70                 cpus=${microcode_update_cpus}
71         fi
72         for i in ${cpus}; do
73                 ${CMT} -u ${microcode_update_flags} \
74                     -d "${microcode_update_datadir}" /dev/cpuctl${i} 2>&1 | \
75                     logger -p daemon.notice -t microcode_update || \
76                     (echo "Microcode Update Failed." && exit 1)
77         done
78         if [ "${microcode_update_cpus}" = "ALL" ]; then
79                 CPUCONTROL_UPDATED=$(cpucontrol -h 2>&1 | grep -q -- -e; echo $?)
80                 if [ ${CPUCONTROL_UPDATED} -ne 0 ]; then
81                         echo "Please update your system in order to update CPU microcode."
82                 else
83                         ${CMT} -e /dev/cpuctl0 >/dev/null 2>&1
84                         if [ $? -ne 0 ]; then
85                                 echo "Re-evalulation of CPU flags Failed."
86                                 exit 1
87                         fi
88                 fi
89         fi
90         echo "Done."
91 }
92
93 load_rc_config $name
94
95 # Set default values
96 if [ -n "${microcode_cpus}" ]; then
97         if [ -n "${microcode_update_cpus}" ]; then
98                 echo "Warning: Ignoring deprecated rc variable, microcode_cpus."
99         else
100                 echo "Warning: rc variable microcode_cpus is deprecated.
101 Warning: Set microcode_udpate_cpus instead."
102                 microcode_update_cpus="${microcode_cpus}"
103         fi
104 fi
105
106 : ${microcode_update_enable="NO"}
107 : ${microcode_update_datadir="%%DATADIR%%"}
108 : ${microcode_update_cpus="ALL"}
109 : ${microcode_update_flags=""}
110
111 run_rc_command "$1"
112
113
114 [FILE:1554:files/pkg-message-single.in]
115 This port includes an RC script, which is one of two methods to update
116 the CPU microcode on a FreeBSD system.
117
118 1. The first method does not require the RC script included here and is
119    only supported with Intel processors.  It is the preferred method,
120    because it ensures that any CPU features introduced by a microcode
121    update are visible to the kernel by applying the update before the
122    kernel performs CPU feature detection.
123
124    To enable updates using the first method, add the following lines to
125    /boot/loader.conf:
126
127    cpu_microcode_load="YES"
128    cpu_microcode_name="/boot/firmware/intel-ucode.bin"
129
130    The microcode update will be loaded when the system is rebooted.
131
132
133 2. The second method, which uses the RC script included here, can be
134    enabled by adding the following line to /etc/rc.conf:
135
136    microcode_update_enable="YES"
137
138    The microcode update is then applied upon reboot or when the microcode
139    update service is run via:
140
141    # service microcode_update start
142
143    If the CPU requires a microcode update, a console message such as the
144    following will appear:
145
146    Updating CPU Microcode...
147    %%DATADIR%%/m32306c3_00000022.fw: updating cpu /dev/cpuctl0 from rev 0x17 to rev 0x22... done.
148    %%DATADIR%%/m32306c3_00000022.fw: updating cpu /dev/cpuctl2 from rev 0x17 to rev 0x22... done.
149    %%DATADIR%%/m32306c3_00000022.fw: updating cpu /dev/cpuctl4 from rev 0x17 to rev 0x22... done.
150    %%DATADIR%%/m32306c3_00000022.fw: updating cpu /dev/cpuctl6 from rev 0x17 to rev 0x22... done.
151    Done.
152
153 It is safe to enable both methods.
154