File: initramfs.hook

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 (98 lines) | stat: -rwxr-xr-x 2,739 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/sh
# amd64-microcode initramfs-tools hook script
# Copyright (C) 2012-2014 Henrique de Moraes Holschuh <hmh@debian.org>
# Released under the GPL v2 or later license
#
# Generates a copy of the minimal microcode for the current system if
# possible, and installs it in the initramfs.
#

PREREQ=""
AMD64UCODE_CONFIG=/etc/default/amd64-microcode

prereqs()
{
   echo "$PREREQ"
}

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

. /usr/share/initramfs-tools/hook-functions

verbose()
{
	if [ "${verbose}" = "y" ] ; then
		echo "amd64-microcode: $*"
	fi
	:
}

AUCODE_FW_DIR=/lib/firmware/amd-ucode
AMD64UCODE_INITRAMFS=auto
[ -r ${AMD64UCODE_CONFIG} ] && . ${AMD64UCODE_CONFIG}

[ -z "${AMD64UCODE_INITRAMFS}" ] && AMD64UCODE_INITRAMFS=no

if [ ! -d "${AUCODE_FW_DIR}" ] ; then
	verbose "no AMD64 processor microcode datafiles to install"
	exit 0;
fi

case "${AMD64UCODE_INITRAMFS}" in
    no|0)
        verbose "disabled by ${AMD64UCODE_CONFIG}"
        exit 0
        ;;
    early)
	echo "W: amd64-microcode: early mode not supported, forcing late initramfs mode" >&2
        AMD64UCODE_INITRAMFS=yes
        ;;
    yes|1|auto)
        ;;
    *)
        echo "E: amd64-microcode: invalid AMD64UCODE_INITRAMFS, using automatic mode" >&2
        AMD64UCODE_INITRAMFS=auto
esac

if [ "${AMD64UCODE_INITRAMFS}" = "auto" ] ; then
        grep -q "^vendor_id[[:blank:]]*:[[:blank:]]*.*AuthenticAMD" /proc/cpuinfo || {
                verbose "no AMD processors detected, nothing to do"
                exit 0
        }
fi

# See Debian bug #716917.  Blacklist all non-LTS/non-Debian kernel versions
# before kernel 3.4  Only known-bad kernel is 2.6.38.
#
# This doesn't blacklist early kernels in the LTS branches, we don't have enough
# information at the initramfs-tools layer, due to the way Debian and Ubuntu version
# kernel packages.

if dpkg --compare-versions "${version}" le 3.4 && \
     { dpkg --compare-versions "${version}" lt 2.6.32 || \
      { dpkg --compare-versions "${version}" ge 2.6.33 && dpkg --compare-versions "${version}" lt 3.0 ; } || \
      { dpkg --compare-versions "${version}" ge 3.1 && dpkg --compare-versions "${version}" lt 3.2 ; } || \
      dpkg --compare-versions "${version}" ge 3.3 ; \
     }; then
	echo "E: amd64-microcode: unsupported kernel version!" >&2
	exit 0
fi

verbose "installing all microcode datafiles for AMD64 processors"

# Generate firmware dir
mkdir -m 755 -p "${DESTDIR}${AUCODE_FW_DIR}" || true
cp -fr "${AUCODE_FW_DIR}/." "${DESTDIR}${AUCODE_FW_DIR}/."

if ! rmdir "${DESTDIR}${AUCODE_FW_DIR}" 2>/dev/null ; then
	# The directory was not empty, so we have work to do
	verbose "installing AMD64 processor microcode update support into initramfs..."
	force_load microcode
fi

: