Skip to contentSkip to conversation

x86: Fixes and improvements for coreboot

PATCH Superseded Simon Glass 1 participant 10 messages Aug 17, 2023

Subsystems (3)

v1 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

cover x86: Fixes and improvements for coreboot

This little series fixes various bugs and annoyances in coreboot and coreboot64:

- Make coreboot64 debug UART start reliably
- Avoid the long USB-init delay on startup
- Correct the timer speed on coreboo64
- Fix a bootstd cros bug (will likely be squashed into another patch)
- Fix the terribly slow console scrolling

Simon Glass (9):
x86: coreboot: Rearrange arch_cpu_init()
x86: Set the CPU vendor in SPL
x86: Allow APCI in SPL
x86: coreboot: Look for DBG2 UART in SPL too
x86: coreboot: Enable CONFIG_SYS_NS16550_MEM32
x86: coreboot: Drop USB init on startup
x86: coreboot: Align options between coreboot and coreboot64
bootstd: cros: Correct condition for reading the kernel
x86: coreboot: Enable VIDEO_COPY

 arch/x86/cpu/coreboot/coreboot.c | 16 +++++++++-------
 arch/x86/cpu/x86_64/cpu.c        |  7 +++++++
 arch/x86/dts/coreboot.dts        |  1 +
 boot/bootmeth_cros.c             |  4 ++--
 configs/coreboot64_defconfig     | 10 +++++++++-
 configs/coreboot_defconfig       | 12 ++----------
 drivers/serial/Kconfig           |  2 +-
 drivers/video/coreboot.c         | 12 ++++++++++++
 lib/Kconfig                      |  8 ++++++++
 9 files changed, 51 insertions(+), 21 deletions(-)
Signature · 1 line
2.41.0.694.ge786442a9b-goog
#1 lore raw

PATCH 1/9 x86: coreboot: Rearrange arch_cpu_init()

Init errors in SPL are currently ignored by this function.

Change the code to init the CPU, reporting an error if something is wrong. After that, look for the coreboot table.

---

 arch/x86/cpu/coreboot/coreboot.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
arch/x86/cpu/coreboot/coreboot.c +9 -3
index d7eedbd7436e..6a551e4c6713 100644
@@ -20,7 +20,14 @@
 
 int arch_cpu_init(void)
 {
-	int ret = get_coreboot_info(&lib_sysinfo);
+	int ret;
+
+	ret = IS_ENABLED(CONFIG_X86_RUN_64BIT) ? x86_cpu_reinit_f() :
+		 x86_cpu_init_f();
+	if (ret) 
+		return ret;
+
+	ret = get_coreboot_info(&lib_sysinfo);
 	if (ret != 0) {
 		printf("Failed to parse coreboot tables.\n");
 		return ret;
@@ -28,8 +35,7 @@ int arch_cpu_init(void)
 
 	timestamp_init();
 
-	return IS_ENABLED(CONFIG_X86_RUN_64BIT) ? x86_cpu_reinit_f() :
-		 x86_cpu_init_f();
+	return 0;
 }
 
 int checkcpu(void)
Signature · 1 line
2.41.0.694.ge786442a9b-goog
#2 lore raw

PATCH 2/9 x86: Set the CPU vendor in SPL

In reply to Simon Glass

We don't read this information in 64-bit mode, since we don't have the macros for doing it. Set it to Intel by default. This allows the TSC timer to work correctly.

---

 arch/x86/cpu/x86_64/cpu.c | 7 +++++++
 1 file changed, 7 insertions(+)
arch/x86/cpu/x86_64/cpu.c +7 -0
index d1c3873dd6a7..2647bff891f8 100644
@@ -8,8 +8,11 @@
 #include <cpu_func.h>
 #include <debug_uart.h>
 #include <init.h>
+#include <asm/cpu.h>
 #include <asm/global_data.h>
 
+DECLARE_GLOBAL_DATA_PTR;
+
 int cpu_has_64bit(void)
 {
 	return true;
@@ -38,6 +41,10 @@ int x86_mp_init(void)
 
 int x86_cpu_reinit_f(void)
 {
+	/* set the vendor to Intel so that native_calibrate_tsc() works */
+	gd->arch.x86_vendor = X86_VENDOR_INTEL;
+	gd->arch.has_mtrr = true;
+
 	return 0;
 }
 
Signature · 1 line
2.41.0.694.ge786442a9b-goog
#3 lore raw

PATCH 3/9 x86: Allow APCI in SPL

In reply to Simon Glass

This is needed so we can find the DBG2 table provided by coreboot. Add a Kconfig so it can be enabled.

---

 lib/Kconfig | 8 ++++++++
 1 file changed, 8 insertions(+)
lib/Kconfig +8 -0
index 42e559ad0b51..1d63099b8e18 100644
@@ -289,6 +289,14 @@ config ACPI
 	  not necessarily include generation of tables
 	  (see GENERATE_ACPI_TABLE), but allows for tables to be located.
 
+config SPL_ACPI
+	bool "Enable support for ACPI libraries in SPL"
+	depends on SPL && SUPPORT_ACPI
+	help
+	  Provides library functions for dealing with ACPI tables in SPL. This
+	  does not necessarily include generation of tables
+	  (see GENERATE_ACPI_TABLE), but allows for tables to be located.
+
 config GENERATE_ACPI_TABLE
 	bool "Generate an ACPI (Advanced Configuration and Power Interface) table"
 	depends on ACPI
Signature · 1 line
2.41.0.694.ge786442a9b-goog
#4 lore raw

PATCH 4/9 x86: coreboot: Look for DBG2 UART in SPL too

In reply to Simon Glass

If coreboot does not set up sysinfo for the UART, SPL currently hangs. Use the DBG2 teechnique there as well. This allows coreboot64 to boot from coreboot even if the console info is missing from sysinfo

---

 configs/coreboot64_defconfig | 1 +
 drivers/serial/Kconfig       | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
configs/coreboot64_defconfig +1 -0
index 55064d1ce66f..9f228420cfa9 100644
@@ -55,5 +55,6 @@ CONFIG_SYS_64BIT_LBA=y
 CONFIG_SOUND=y
 CONFIG_SOUND_I8254=y
 CONFIG_CONSOLE_SCROLL_LINES=5
+CONFIG_SPL_ACPI=y
 # CONFIG_GZIP is not set
 CONFIG_CMD_CBFS=y
drivers/serial/Kconfig +1 -1
index 7ca42df6a7e2..27b4b9d96507 100644
@@ -672,7 +672,7 @@ config COREBOOT_SERIAL
 config COREBOOT_SERIAL_FROM_DBG2
 	bool "Obtain UART from ACPI tables"
 	depends on COREBOOT_SERIAL
-	default y if !SPL
+	default y
 	help
 	  Select this to try to find a DBG2 record in the ACPI tables, in the
 	  event that coreboot does not provide information about the UART in the
Signature · 1 line
2.41.0.694.ge786442a9b-goog
#5 lore raw

PATCH 5/9 x86: coreboot: Enable CONFIG_SYS_NS16550_MEM32

In reply to Simon Glass

The debug UART on modern machines uses a 32-bit wide transfer. Without this, setting debug output causes a hang or no output. It is not obvious (when enabling CONFIG_DEBUG_UART) that this is needed.

Enable 32-bit access to avoid this trap.

---

 configs/coreboot64_defconfig | 1 +
 configs/coreboot_defconfig   | 1 +
 2 files changed, 2 insertions(+)
configs/coreboot64_defconfig +1 -0
index 9f228420cfa9..2e80b5af92ef 100644
@@ -52,6 +52,7 @@ CONFIG_ATAPI=y
 CONFIG_LBA48=y
 CONFIG_SYS_64BIT_LBA=y
 # CONFIG_PCI_PNP is not set
+CONFIG_SYS_NS16550_MEM32=y
 CONFIG_SOUND=y
 CONFIG_SOUND_I8254=y
 CONFIG_CONSOLE_SCROLL_LINES=5
configs/coreboot_defconfig +1 -0
index 77214f1b4c06..ae44705a1d51 100644
@@ -60,6 +60,7 @@ CONFIG_LBA48=y
 CONFIG_SYS_64BIT_LBA=y
 CONFIG_NVME_PCI=y
 # CONFIG_PCI_PNP is not set
+CONFIG_SYS_NS16550_MEM32=y
 CONFIG_SOUND=y
 CONFIG_SOUND_I8254=y
 CONFIG_CONSOLE_SCROLL_LINES=5
Signature · 1 line
2.41.0.694.ge786442a9b-goog
#6 lore raw

PATCH 6/9 x86: coreboot: Drop USB init on startup

In reply to Simon Glass

This is very annoying as it is quite slow on many machines. Also, U-Boot has an existing 'preboot' mechanism to enable this feature if desired.

Drop this code so that it is possible to choose whether to init USB or not.

---

 arch/x86/cpu/coreboot/coreboot.c | 4 ----
 1 file changed, 4 deletions(-)
arch/x86/cpu/coreboot/coreboot.c +0 -4
index 6a551e4c6713..5e3af5e561bc 100644
@@ -82,10 +82,6 @@ static void board_final_init(void)
 
 int last_stage_init(void)
 {
-	/* start usb so that usb keyboard can be used as input device */
-	if (IS_ENABLED(CONFIG_USB_KEYBOARD))
-		usb_init();
-
 	board_final_init();
 
 	return 0;
Signature · 1 line
2.41.0.694.ge786442a9b-goog
#7 lore raw

PATCH 7/9 x86: coreboot: Align options between coreboot and coreboot64

In reply to Simon Glass

These two builds are similar but have some different options for no good reason. Line them up to be as similar as possible.

---

 configs/coreboot64_defconfig |  7 ++++++-
 configs/coreboot_defconfig   | 10 ----------
 2 files changed, 6 insertions(+), 11 deletions(-)
configs/coreboot64_defconfig +6 -1
index 2e80b5af92ef..e5cb3f3d4ebd 100644
@@ -18,6 +18,9 @@ CONFIG_USE_BOOTARGS=y
 CONFIG_BOOTARGS="root=/dev/sdb3 init=/sbin/init rootwait ro"
 CONFIG_PRE_CONSOLE_BUFFER=y
 CONFIG_SYS_CONSOLE_INFO_QUIET=y
+CONFIG_LOG=y
+CONFIG_LOGF_LINE=y
+CONFIG_LOGF_FUNC=y
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_LAST_STAGE_INIT=y
 CONFIG_SPL_NO_BSS_LIMIT=y
@@ -51,11 +54,13 @@ CONFIG_SYS_ATA_ALT_OFFSET=0
 CONFIG_ATAPI=y
 CONFIG_LBA48=y
 CONFIG_SYS_64BIT_LBA=y
+CONFIG_NVME_PCI=y
 # CONFIG_PCI_PNP is not set
 CONFIG_SYS_NS16550_MEM32=y
 CONFIG_SOUND=y
 CONFIG_SOUND_I8254=y
 CONFIG_CONSOLE_SCROLL_LINES=5
 CONFIG_SPL_ACPI=y
+CONFIG_CMD_DHRYSTONE=y
 # CONFIG_GZIP is not set
-CONFIG_CMD_CBFS=y
+CONFIG_SMBIOS_PARSER=y
configs/coreboot_defconfig +0 -10
index ae44705a1d51..790b84a87bc7 100644
@@ -25,23 +25,14 @@ CONFIG_LAST_STAGE_INIT=y
 CONFIG_PCI_INIT_R=y
 CONFIG_CMD_IDE=y
 CONFIG_CMD_MMC=y
-CONFIG_CMD_PART=y
 CONFIG_CMD_SATA=y
 CONFIG_CMD_USB=y
 # CONFIG_CMD_SETEXPR is not set
-CONFIG_CMD_DHCP=y
 CONFIG_BOOTP_BOOTFILESIZE=y
-CONFIG_CMD_PING=y
 CONFIG_CMD_TIME=y
 CONFIG_CMD_SOUND=y
-CONFIG_CMD_EXT2=y
-CONFIG_CMD_EXT4=y
 CONFIG_CMD_EXT4_WRITE=y
-CONFIG_CMD_FAT=y
-CONFIG_CMD_FS_GENERIC=y
 CONFIG_MAC_PARTITION=y
-CONFIG_ISO_PARTITION=y
-CONFIG_EFI_PARTITION=y
 CONFIG_ENV_OVERWRITE=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
 CONFIG_USE_BOOTFILE=y
@@ -67,4 +58,3 @@ CONFIG_CONSOLE_SCROLL_LINES=5
 CONFIG_CMD_DHRYSTONE=y
 # CONFIG_GZIP is not set
 CONFIG_SMBIOS_PARSER=y
-CONFIG_CMD_CBFS=y
Signature · 1 line
2.41.0.694.ge786442a9b-goog
#8 lore raw

PATCH 8/9 bootstd: cros: Correct condition for reading the kernel

In reply to Simon Glass

A typo prevents this code from behaving as it should. The tests pass because they do not actually read the kernel. Fix the typo.

---

 boot/bootmeth_cros.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
boot/bootmeth_cros.c +2 -2
index 20e0b1e89c36..3439d31121b3 100644
@@ -406,7 +406,7 @@ static int cros_read_file(struct udevice *dev, struct bootflow *bflow,
 	return -ENOSYS;
 }
 
-#if CONFIG_IS_ENABLED(BOOSTD_FULL)
+#if CONFIG_IS_ENABLED(BOOTSTD_FULL)
 static int cros_read_all(struct udevice *dev, struct bootflow *bflow)
 {
 	int ret;
@@ -458,7 +458,7 @@ static struct bootmeth_ops cros_bootmeth_ops = {
 	.read_bootflow	= cros_read_bootflow,
 	.read_file	= cros_read_file,
 	.boot		= cros_boot,
-#if CONFIG_IS_ENABLED(BOOSTD_FULL)
+#if CONFIG_IS_ENABLED(BOOTSTD_FULL)
 	.read_all	= cros_read_all,
 #endif /* BOOSTD_FULL */
 };
Signature · 1 line
2.41.0.694.ge786442a9b-goog
#9 lore raw

PATCH 9/9 x86: coreboot: Enable VIDEO_COPY

In reply to Simon Glass

At least on modern machines the write-back mechanism for the frame buffer is quite slow when scrolling, since it must read the entire frame buffer and write it back.

Enable the VIDEO_COPY feature to resolve this problem.

---

 arch/x86/dts/coreboot.dts    |  1 +
 configs/coreboot64_defconfig |  1 +
 configs/coreboot_defconfig   |  1 +
 drivers/video/coreboot.c     | 12 ++++++++++++
 4 files changed, 15 insertions(+)
arch/x86/dts/coreboot.dts +1 -0
index f9ff5346a79b..0eb31cae42c1 100644
@@ -42,6 +42,7 @@
 	};
 
 	coreboot-fb {
+		bootph-some-ram;
 		compatible = "coreboot-fb";
 	};
 };
configs/coreboot64_defconfig +1 -0
index e5cb3f3d4ebd..54360255c691 100644
@@ -59,6 +59,7 @@ CONFIG_NVME_PCI=y
 CONFIG_SYS_NS16550_MEM32=y
 CONFIG_SOUND=y
 CONFIG_SOUND_I8254=y
+CONFIG_VIDEO_COPY=y
 CONFIG_CONSOLE_SCROLL_LINES=5
 CONFIG_SPL_ACPI=y
 CONFIG_CMD_DHRYSTONE=y
configs/coreboot_defconfig +1 -0
index 790b84a87bc7..78694d635532 100644
@@ -54,6 +54,7 @@ CONFIG_NVME_PCI=y
 CONFIG_SYS_NS16550_MEM32=y
 CONFIG_SOUND=y
 CONFIG_SOUND_I8254=y
+CONFIG_VIDEO_COPY=y
 CONFIG_CONSOLE_SCROLL_LINES=5
 CONFIG_CMD_DHRYSTONE=y
 # CONFIG_GZIP is not set
drivers/video/coreboot.c +12 -0
index c586475e41ed..5b718ae3e5a5 100644
@@ -73,6 +73,17 @@ err:
 	return ret;
 }
 
+static int coreboot_video_bind(struct udevice *dev)
+{
+	struct video_uc_plat *uc_plat = dev_get_uclass_plat(dev);
+
+	/* Set the maximum supported resolution */
+	uc_plat->size = 4096 * 2160 * 4;
+	log_debug("%s: Frame buffer size %x\n", __func__, uc_plat->size);
+
+	return 0;
+}
+
 static const struct udevice_id coreboot_video_ids[] = {
 	{ .compatible = "coreboot-fb" },
 	{ }
@@ -82,5 +93,6 @@ U_BOOT_DRIVER(coreboot_video) = {
 	.name	= "coreboot_video",
 	.id	= UCLASS_VIDEO,
 	.of_match = coreboot_video_ids,
+	.bind	= coreboot_video_bind,
 	.probe	= coreboot_video_probe,
 };
Signature · 1 line
2.41.0.694.ge786442a9b-goog