kernel: microcode in every initramfs through mkinitcpio's microcode hook (issue 1977)
Declares amd-ucode and intel-ucode, the drop-in /etc/mkinitcpio.conf.d/mesh-microcode.conf, the initramfs script and mesh-kernel-initramfs.service; kernel_boot answers the running revision and whether the images were built with the drop-in. Tests: 1977/AC1-AC5. Builds: L1, L2, L3, L4, L5 (issue 1977 note 2)
This commit is contained in:
@@ -23,6 +23,30 @@ type BootState struct {
|
||||
Booted string `json:"booted"`
|
||||
FallbackPresent bool `json:"fallback_present"`
|
||||
BootFreeKiB int64 `json:"boot_free_kib"`
|
||||
// MicrocodeRevision is the revision the CPU runs, the first "microcode" line of /proc/cpuinfo ("" when it has none).
|
||||
MicrocodeRevision string `json:"microcode_revision"`
|
||||
// ImagesBuiltWithMicrocode is true when the initramfs images were last built with the microcode drop-in as it is now
|
||||
// (novox/hq issue 1977).
|
||||
ImagesBuiltWithMicrocode bool `json:"images_built_with_microcode"`
|
||||
}
|
||||
|
||||
// stateDir is the module's own directory on the machine, where the initramfs script records the drop-in it built with.
|
||||
const stateDir = "var/lib/mesh-kernel"
|
||||
|
||||
const microcodeDropIn = "etc/mkinitcpio.conf.d/mesh-microcode.conf"
|
||||
|
||||
var cpuMicrocode = regexp.MustCompile(`(?m)^microcode\s*:\s*(\S+)`)
|
||||
|
||||
// microcode reads the revision the CPU runs and whether the images carry the drop-in as it is now.
|
||||
func (m *Machine) microcode(b *BootState) {
|
||||
if raw, err := m.read("proc/cpuinfo"); err == nil {
|
||||
if r := cpuMicrocode.FindStringSubmatch(raw); r != nil {
|
||||
b.MicrocodeRevision = r[1]
|
||||
}
|
||||
}
|
||||
built, err := m.read(stateDir + "/initramfs-built")
|
||||
now, err2 := m.read(microcodeDropIn)
|
||||
b.ImagesBuiltWithMicrocode = err == nil && err2 == nil && built == now
|
||||
}
|
||||
|
||||
var grubKernel = regexp.MustCompile(`(?m)^\s*linux\s+(?:/boot)?/(vmlinuz-\S+)`)
|
||||
@@ -33,6 +57,7 @@ var bootImage = regexp.MustCompile(`BOOT_IMAGE=(?:/boot)?/?(\S+)`)
|
||||
// systemd-boot, a grub.cfg without it GRUB.
|
||||
func (m *Machine) Boot() (*BootState, error) {
|
||||
b := &BootState{Loader: "none", Entries: []string{}, Kernels: []string{}}
|
||||
m.microcode(b)
|
||||
files, _ := filepath.Glob(m.path("boot/vmlinuz-*"))
|
||||
for _, f := range files {
|
||||
b.Kernels = append(b.Kernels, filepath.Base(f))
|
||||
|
||||
Reference in New Issue
Block a user