diff --git a/cmd/qfw.c b/cmd/qfw.c index 794e0622f34..aef9f2068a2 100644 --- a/cmd/qfw.c +++ b/cmd/qfw.c @@ -234,6 +234,19 @@ static int do_read(struct cmd_tbl *cmdtp, int flag, int argc, return 0; } +static int do_e820(struct cmd_tbl *cmdtp, int flag, int argc, + char * const argv[]) +{ + if (!IS_ENABLED(CONFIG_X86)) { + printf("Not supported on this architecture\n"); + return CMD_RET_FAILURE; + } + + cmd_qfw_e820(qfw_dev); + + return 0; +} + static struct cmd_tbl fwcfg_commands[] = { U_BOOT_CMD_MKENT(list, 0, 1, qemu_fwcfg_do_list, "", ""), U_BOOT_CMD_MKENT(cpus, 0, 1, qemu_fwcfg_do_cpus, "", ""), @@ -242,6 +255,7 @@ static struct cmd_tbl fwcfg_commands[] = { U_BOOT_CMD_MKENT(table, 0, 1, do_table, "", ""), U_BOOT_CMD_MKENT(arch, 0, 1, do_arch, "", ""), U_BOOT_CMD_MKENT(read, 2, 1, do_read, "", ""), + U_BOOT_CMD_MKENT(e820, 0, 1, do_e820, "", ""), }; static int do_qemu_fw(struct cmd_tbl *cmdtp, int flag, int argc, @@ -278,4 +292,5 @@ U_BOOT_CMD( " - load : load kernel and initrd (if any), and setup for zboot\n" " - table : show /etc/table-loader\n" " - arch : show arch-specific data\n" - " - read : read a flle into memory"); + " - read : read a flle into memory\n" + " - e820 : show QEMU e820 table"); diff --git a/cmd/x86/Makefile b/cmd/x86/Makefile index 5f3f5be2882..f7fb30e034e 100644 --- a/cmd/x86/Makefile +++ b/cmd/x86/Makefile @@ -3,6 +3,7 @@ obj-$(CONFIG_CMD_CBSYSINFO) += cbsysinfo.o obj-y += cpuid.o msr.o mtrr.o obj-$(CONFIG_CMD_CBCMOS) += cbcmos.o +obj-y += qfw_x86.o obj-$(CONFIG_CMD_EXCEPTION) += exception.o obj-$(CONFIG_USE_HOB) += hob.o obj-$(CONFIG_HAVE_FSP) += fsp.o diff --git a/cmd/x86/qfw_x86.c b/cmd/x86/qfw_x86.c new file mode 100644 index 00000000000..fdd1010bbb5 --- /dev/null +++ b/cmd/x86/qfw_x86.c @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * x86-specific qfw commands + * + * Copyright 2025 Simon Glass + */ + +#include +#include +#include +#include + +int cmd_qfw_e820(struct udevice *dev) +{ + struct abuf tab; + int ret; + + ret = qfw_get_file(dev, "etc/e820", &tab); + if (ret) + return CMD_RET_FAILURE; + e820_dump(tab.data, tab.size / sizeof(struct e820_entry)); + abuf_uninit(&tab); + + return 0; +} diff --git a/doc/usage/cmd/qfw.rst b/doc/usage/cmd/qfw.rst index 8b02593d278..fbdb1102136 100644 --- a/doc/usage/cmd/qfw.rst +++ b/doc/usage/cmd/qfw.rst @@ -18,6 +18,7 @@ Synopsis qfw table qfw arch qfw read + qfw e820 Description ----------- @@ -40,6 +41,9 @@ The *qfw arch* command shows some items marked as 'arch local' in QEMU. The *qfw read* command allowing a QEMU file to be read into memory. +The *qfw e820* command shows the memory-map information provided by QEMU. It +uses the x86 e820 format. + kernel_addr address to which the file specified by the -kernel parameter of QEMU shall be loaded. Defaults to environment variable *loadaddr* and further to @@ -199,6 +203,18 @@ provided size information: 00001010: 40 1c 00 00 @... +This shows dumping the E820 table, showing the emulated RAM as well as some +reserved memory: + +:: + + => qfw e820 + Addr Size Type + fd00000000 300000000 Reserved + 0 20000000 RAM + => + + Configuration ------------- diff --git a/include/qfw.h b/include/qfw.h index 35c84a7deaa..c1f558b6f87 100644 --- a/include/qfw.h +++ b/include/qfw.h @@ -464,4 +464,12 @@ int qfw_load_file(struct udevice *dev, const char *fname, ulong addr); */ int qfw_get_file(struct udevice *dev, const char *fname, struct abuf *loader); +/** + * cmd_qfw_e820() - Execute the 'qfw e820' command for x86 + * + * @dev: UCLASS_QFW device + * Return: 0 on success (always), 1 if there is no E820 information + */ +int cmd_qfw_e820(struct udevice *dev); + #endif diff --git a/test/cmd/qfw.c b/test/cmd/qfw.c index 5b8be8af292..4e5fa40621e 100644 --- a/test/cmd/qfw.c +++ b/test/cmd/qfw.c @@ -113,3 +113,21 @@ static int cmd_test_qfw_read(struct unit_test_state *uts) return 0; } CMD_TEST(cmd_test_qfw_read, UTF_CONSOLE); + +/* Test 'qfw e820' command */ +static int cmd_test_qfw_e820(struct unit_test_state *uts) +{ + int ret; + + ret = run_command("qfw e820", 0); + if (!IS_ENABLED(CONFIG_X86)) { + ut_asserteq(1, ret); + return 0; + } + + ut_assertok(ret); + ut_assert_nextline(" Addr Size Type"); + + return 0; +} +CMD_TEST(cmd_test_qfw_e820, UTF_CONSOLE);