File: initramfs.init-premount

package info (click to toggle)
amd64-microcode 2.20141028.1
  • links: PTS, VCS
  • area: non-free
  • in suites: jessie-kfreebsd
  • size: 140 kB
  • sloc: sh: 133; makefile: 41
file content (63 lines) | stat: -rwxr-xr-x 1,699 bytes parent folder | download | duplicates (3)
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
#!/bin/sh
# amd64-microcode initramfs-tools boot script
# Copyright (C) 2012,2013 Henrique de Moraes Holschuh <hmh@debian.org>
# Released under the GPL v2 or later license
#
# Triggers kernel firmware update requests for processor microcode
# when required.
#

# dependencies: firmware loader, microcode kernel support (built-in/module)

PREREQ=""

prereqs()
{
   echo "$PREREQ"
}

case $1 in
prereqs)
   prereqs
   exit 0
   ;;
esac

# hack to strip spaces
is_amd()
{
    [ "x$1" = "xvendor_id" ] && [ "x$2" = "xAuthenticAMD" ] && HAS_AMD=1
}

# Only continue if we do possibly have firmware to install
[ -d /lib/firmware/amd-ucode ] || exit 0

# module load will already have caused the microcode to be fetched
{ while read -r module trash ; do [ "x$module" = "xmicrocode" ] && exit 0 ; done ; } < /proc/modules

# don't run on non-AMD
HAS_AMD=0
{ while IFS=: read -r field value ; do is_amd $field $value ; done ; } < /proc/cpuinfo
[ $HAS_AMD -eq 0 ] && exit 0;

. /scripts/functions

if [ -e /sys/devices/system/cpu/microcode/reload ] ; then
    echo 1 > /sys/devices/system/cpu/microcode/reload || {
	log_warning_msg "could not update the microcode of every processor"
    }
else
    # Try all online processors, broken kernels need this,
    # fixed kernels will accept it only on the BSP and update
    # all processors anyway, and -EINVAL all others... but we
    # don't know which one is the BSP, so we try all of them
    # and hide errors, the kernel will log any real problem.

    log_begin_msg "Requesting microcode update using per-core interface"
    for i in /sys/devices/system/cpu/cpu[0-9]*/microcode/reload ; do
	echo 1 2>/dev/null > "$i" || true
    done
    log_end_msg
fi

: