diff mbox series

[LEDE-DEV,2/3] x86: add intel microcode entries to grub config

Message ID 20180403131337.3094-3-tomek_n@o2.pl
State Superseded
Delegated to: Zoltan HERPAI
Headers show
Series intel-microcode: load as early as possible | expand

Commit Message

Tomasz Maciej Nowak April 3, 2018, 1:13 p.m. UTC
Create initrd enries for x86 images, that'll load intel microcode as
early as possible. Also restrict the late load of microcode to AMD
processors.

Signed-off-by: Tomasz Maciej Nowak <tomek_n@o2.pl>
---
 target/linux/x86/base-files/lib/preinit/02_load_x86_ucode | 6 ++++--
 target/linux/x86/image/Makefile                           | 4 ++--
 target/linux/x86/image/grub-iso.cfg                       | 3 +++
 target/linux/x86/image/grub.cfg                           | 3 +++
 4 files changed, 12 insertions(+), 4 deletions(-)

Comments

Philip Prindeville April 9, 2018, 7 p.m. UTC | #1
Inline.  Has this been tested with UEFI?


> On Apr 3, 2018, at 7:13 AM, Tomasz Maciej Nowak <tomek_n@o2.pl> wrote:
> 
> Create initrd enries for x86 images, that'll load intel microcode as
> early as possible. Also restrict the late load of microcode to AMD
> processors.
> 
> Signed-off-by: Tomasz Maciej Nowak <tomek_n@o2.pl>
> ---
> target/linux/x86/base-files/lib/preinit/02_load_x86_ucode | 6 ++++--
> target/linux/x86/image/Makefile                           | 4 ++--
> target/linux/x86/image/grub-iso.cfg                       | 3 +++
> target/linux/x86/image/grub.cfg                           | 3 +++
> 4 files changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/target/linux/x86/base-files/lib/preinit/02_load_x86_ucode b/target/linux/x86/base-files/lib/preinit/02_load_x86_ucode
> index fb309c75c1..68ebdf8651 100644
> --- a/target/linux/x86/base-files/lib/preinit/02_load_x86_ucode
> +++ b/target/linux/x86/base-files/lib/preinit/02_load_x86_ucode
> @@ -2,8 +2,10 @@
> # Copyright (C) 2018 OpenWrt.org
> 
> do_load_x86_ucode() {
> -	if [ -e "/sys/devices/system/cpu/microcode/reload" ]; then
> -		echo 1 > /sys/devices/system/cpu/microcode/reload
> +	if [ "$(grep -c AuthenticAMD /proc/cpuinfo)" -gt "0" ]; then


Way too complicated.  Try:

if grep -q AuthenticAMD /proc/cpuinfo; then

instead.  -q inhibits output, and instead you get true for having matches, and false for no matches.



> +		if [ -e "/sys/devices/system/cpu/microcode/reload" ]; then
> +			echo 1 > /sys/devices/system/cpu/microcode/reload
> +		fi
> 	fi
> }
> 
> diff --git a/target/linux/x86/image/Makefile b/target/linux/x86/image/Makefile
> index 8a3cb327e3..a05f4babd9 100644
> --- a/target/linux/x86/image/Makefile
> +++ b/target/linux/x86/image/Makefile
> @@ -9,8 +9,8 @@ include $(INCLUDE_DIR)/image.mk
> 
> export PATH=$(TARGET_PATH):/sbin
> 
> -GRUB2_MODULES = biosdisk boot chain configfile ext2 linux ls part_msdos reboot serial vga
> -GRUB2_MODULES_ISO = biosdisk boot chain configfile iso9660 linux ls part_msdos reboot serial vga
> +GRUB2_MODULES = biosdisk boot chain configfile ext2 linux ls part_msdos reboot serial test vga
> +GRUB2_MODULES_ISO = biosdisk boot chain configfile iso9660 linux ls part_msdos reboot serial test vga


What is “test” in this case?


> GRUB_TERMINALS =
> GRUB_SERIAL_CONFIG =
> GRUB_TERMINAL_CONFIG =
> diff --git a/target/linux/x86/image/grub-iso.cfg b/target/linux/x86/image/grub-iso.cfg
> index 3d47a95a4b..30b587bd1c 100644
> --- a/target/linux/x86/image/grub-iso.cfg
> +++ b/target/linux/x86/image/grub-iso.cfg
> @@ -7,4 +7,7 @@ set root='(cd)'
> 
> menuentry "OpenWrt" {
> 	linux /boot/vmlinuz @CMDLINE@ noinitrd
> +	if [ -e /boot/intel-ucode.img ]; then
> +		initrd /boot/intel-ucode.img
> +	fi
> }
> diff --git a/target/linux/x86/image/grub.cfg b/target/linux/x86/image/grub.cfg
> index 9ec6b2d39c..dde24b95ce 100644
> --- a/target/linux/x86/image/grub.cfg
> +++ b/target/linux/x86/image/grub.cfg
> @@ -7,6 +7,9 @@ set root='(@ROOT@)'
> 
> menuentry "OpenWrt" {
> 	linux /boot/vmlinuz @CMDLINE@ noinitrd
> +	if [ -e /boot/intel-ucode.img ]; then
> +		initrd /boot/intel-ucode.img
> +	fi
> }
> menuentry "OpenWrt (failsafe)" {
> 	linux /boot/vmlinuz failsafe=true @CMDLINE@ noinitrd
> -- 
> 2.16.3
Tomasz Maciej Nowak April 9, 2018, 7:54 p.m. UTC | #2
W dniu 09.04.2018 o 21:00, Philip Prindeville pisze:
> Inline.  Has this been tested with UEFI?

No, I don't have any UEFI system which can be employed for testing.

> 
> 
>> On Apr 3, 2018, at 7:13 AM, Tomasz Maciej Nowak <tomek_n@o2.pl> wrote:
>>
>> Create initrd enries for x86 images, that'll load intel microcode as
>> early as possible. Also restrict the late load of microcode to AMD
>> processors.
>>
>> Signed-off-by: Tomasz Maciej Nowak <tomek_n@o2.pl>
>> ---
>> target/linux/x86/base-files/lib/preinit/02_load_x86_ucode | 6 ++++--
>> target/linux/x86/image/Makefile                           | 4 ++--
>> target/linux/x86/image/grub-iso.cfg                       | 3 +++
>> target/linux/x86/image/grub.cfg                           | 3 +++
>> 4 files changed, 12 insertions(+), 4 deletions(-)
>>
>> diff --git a/target/linux/x86/base-files/lib/preinit/02_load_x86_ucode b/target/linux/x86/base-files/lib/preinit/02_load_x86_ucode
>> index fb309c75c1..68ebdf8651 100644
>> --- a/target/linux/x86/base-files/lib/preinit/02_load_x86_ucode
>> +++ b/target/linux/x86/base-files/lib/preinit/02_load_x86_ucode
>> @@ -2,8 +2,10 @@
>> # Copyright (C) 2018 OpenWrt.org
>>
>> do_load_x86_ucode() {
>> -	if [ -e "/sys/devices/system/cpu/microcode/reload" ]; then
>> -		echo 1 > /sys/devices/system/cpu/microcode/reload
>> +	if [ "$(grep -c AuthenticAMD /proc/cpuinfo)" -gt "0" ]; then
> 
> 
> Way too complicated.  Try:
> 
> if grep -q AuthenticAMD /proc/cpuinfo; then
> 
> instead.  -q inhibits output, and instead you get true for having matches, and false for no matches.
> 
Thanks, will change in v2.

> 
> 
>> +		if [ -e "/sys/devices/system/cpu/microcode/reload" ]; then
>> +			echo 1 > /sys/devices/system/cpu/microcode/reload
>> +		fi
>> 	fi
>> }
>>
>> diff --git a/target/linux/x86/image/Makefile b/target/linux/x86/image/Makefile
>> index 8a3cb327e3..a05f4babd9 100644
>> --- a/target/linux/x86/image/Makefile
>> +++ b/target/linux/x86/image/Makefile
>> @@ -9,8 +9,8 @@ include $(INCLUDE_DIR)/image.mk
>>
>> export PATH=$(TARGET_PATH):/sbin
>>
>> -GRUB2_MODULES = biosdisk boot chain configfile ext2 linux ls part_msdos reboot serial vga
>> -GRUB2_MODULES_ISO = biosdisk boot chain configfile iso9660 linux ls part_msdos reboot serial vga
>> +GRUB2_MODULES = biosdisk boot chain configfile ext2 linux ls part_msdos reboot serial test vga
>> +GRUB2_MODULES_ISO = biosdisk boot chain configfile iso9660 linux ls part_msdos reboot serial test vga
> 
> 
> What is “test” in this case?

GRUB module for shell-like tests, used in grub-iso.cfg and grub-cfg see 
below.

> 
> 
>> GRUB_TERMINALS =
>> GRUB_SERIAL_CONFIG =
>> GRUB_TERMINAL_CONFIG =
>> diff --git a/target/linux/x86/image/grub-iso.cfg b/target/linux/x86/image/grub-iso.cfg
>> index 3d47a95a4b..30b587bd1c 100644
>> --- a/target/linux/x86/image/grub-iso.cfg
>> +++ b/target/linux/x86/image/grub-iso.cfg
>> @@ -7,4 +7,7 @@ set root='(cd)'
>>
>> menuentry "OpenWrt" {
>> 	linux /boot/vmlinuz @CMDLINE@ noinitrd
>> +	if [ -e /boot/intel-ucode.img ]; then
>> +		initrd /boot/intel-ucode.img
>> +	fi
>> }
>> diff --git a/target/linux/x86/image/grub.cfg b/target/linux/x86/image/grub.cfg
>> index 9ec6b2d39c..dde24b95ce 100644
>> --- a/target/linux/x86/image/grub.cfg
>> +++ b/target/linux/x86/image/grub.cfg
>> @@ -7,6 +7,9 @@ set root='(@ROOT@)'
>>
>> menuentry "OpenWrt" {
>> 	linux /boot/vmlinuz @CMDLINE@ noinitrd
>> +	if [ -e /boot/intel-ucode.img ]; then
>> +		initrd /boot/intel-ucode.img
>> +	fi
>> }
>> menuentry "OpenWrt (failsafe)" {
>> 	linux /boot/vmlinuz failsafe=true @CMDLINE@ noinitrd
>> -- 
>> 2.16.3
> 

Thank You for the review.
diff mbox series

Patch

diff --git a/target/linux/x86/base-files/lib/preinit/02_load_x86_ucode b/target/linux/x86/base-files/lib/preinit/02_load_x86_ucode
index fb309c75c1..68ebdf8651 100644
--- a/target/linux/x86/base-files/lib/preinit/02_load_x86_ucode
+++ b/target/linux/x86/base-files/lib/preinit/02_load_x86_ucode
@@ -2,8 +2,10 @@ 
 # Copyright (C) 2018 OpenWrt.org
 
 do_load_x86_ucode() {
-	if [ -e "/sys/devices/system/cpu/microcode/reload" ]; then
-		echo 1 > /sys/devices/system/cpu/microcode/reload
+	if [ "$(grep -c AuthenticAMD /proc/cpuinfo)" -gt "0" ]; then
+		if [ -e "/sys/devices/system/cpu/microcode/reload" ]; then
+			echo 1 > /sys/devices/system/cpu/microcode/reload
+		fi
 	fi
 }
 
diff --git a/target/linux/x86/image/Makefile b/target/linux/x86/image/Makefile
index 8a3cb327e3..a05f4babd9 100644
--- a/target/linux/x86/image/Makefile
+++ b/target/linux/x86/image/Makefile
@@ -9,8 +9,8 @@  include $(INCLUDE_DIR)/image.mk
 
 export PATH=$(TARGET_PATH):/sbin
 
-GRUB2_MODULES = biosdisk boot chain configfile ext2 linux ls part_msdos reboot serial vga
-GRUB2_MODULES_ISO = biosdisk boot chain configfile iso9660 linux ls part_msdos reboot serial vga
+GRUB2_MODULES = biosdisk boot chain configfile ext2 linux ls part_msdos reboot serial test vga
+GRUB2_MODULES_ISO = biosdisk boot chain configfile iso9660 linux ls part_msdos reboot serial test vga
 GRUB_TERMINALS =
 GRUB_SERIAL_CONFIG =
 GRUB_TERMINAL_CONFIG =
diff --git a/target/linux/x86/image/grub-iso.cfg b/target/linux/x86/image/grub-iso.cfg
index 3d47a95a4b..30b587bd1c 100644
--- a/target/linux/x86/image/grub-iso.cfg
+++ b/target/linux/x86/image/grub-iso.cfg
@@ -7,4 +7,7 @@  set root='(cd)'
 
 menuentry "OpenWrt" {
 	linux /boot/vmlinuz @CMDLINE@ noinitrd
+	if [ -e /boot/intel-ucode.img ]; then
+		initrd /boot/intel-ucode.img
+	fi
 }
diff --git a/target/linux/x86/image/grub.cfg b/target/linux/x86/image/grub.cfg
index 9ec6b2d39c..dde24b95ce 100644
--- a/target/linux/x86/image/grub.cfg
+++ b/target/linux/x86/image/grub.cfg
@@ -7,6 +7,9 @@  set root='(@ROOT@)'
 
 menuentry "OpenWrt" {
 	linux /boot/vmlinuz @CMDLINE@ noinitrd
+	if [ -e /boot/intel-ucode.img ]; then
+		initrd /boot/intel-ucode.img
+	fi
 }
 menuentry "OpenWrt (failsafe)" {
 	linux /boot/vmlinuz failsafe=true @CMDLINE@ noinitrd