qfw: Add a subcommand to read a QEMU file into memory

Provide a simple command to read a named file into memory.

Skip this test on sandbox for now, as it doesn't support this feature in
its emulation of QEMU.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass
2025-07-05 10:19:03 -06:00
parent 1541ec049b
commit d75533b613
3 changed files with 67 additions and 1 deletions

View File

@@ -219,6 +219,21 @@ static int do_arch(struct cmd_tbl *cmdtp, int flag, int argc,
return 0;
}
static int do_read(struct cmd_tbl *cmdtp, int flag, int argc,
char * const argv[])
{
int ret;
if (argc < 2)
return CMD_RET_USAGE;
ret = qfw_load_file(qfw_dev, argv[1], hextoul(argv[0], NULL));
if (ret)
return CMD_RET_FAILURE;
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, "", ""),
@@ -226,6 +241,7 @@ static struct cmd_tbl fwcfg_commands[] = {
U_BOOT_CMD_MKENT(dump, 0, 1, do_dump, "", ""),
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, "", ""),
};
static int do_qemu_fw(struct cmd_tbl *cmdtp, int flag, int argc,
@@ -261,4 +277,5 @@ U_BOOT_CMD(
" - cpus : print online cpu number\n"
" - load <kernel addr> <initrd addr> : load kernel and initrd (if any), and setup for zboot\n"
" - table : show /etc/table-loader\n"
" - arch : show arch-specific data");
" - arch : show arch-specific data\n"
" - read <addr> <filename> : read a flle into memory");

View File

@@ -17,6 +17,7 @@ Synopsis
qfw load [kernel_addr [initrd_addr]]
qfw table
qfw arch
qfw read <addr> <filename>
Description
-----------
@@ -37,6 +38,8 @@ must be updated to take account of the address to which the tables are copied.
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.
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
@@ -47,6 +50,12 @@ initrd_addr
be loaded. Defaults to environment variable *ramdiskaddr* and further to
the value of *CFG_RAMDISK_ADDR*.
addr
address to which `filename` is read into memory
filename
filename of file to read into memory (as shown by *qfw list*)
Examples
--------
@@ -164,6 +173,31 @@ This shows the *qfw table* command on an x86 target:
irq0 overr = 0x00000001
hpet = 0x00000000
This shows reading a named qfw file into memory then dumping it, using the
provided size information:
::
=> qfw list
Addr Size Sel Name
-------- -------- --- ------------
0 0 20 bios-geometry
0 0 21 bootorder
1ec3f000 14 22 etc/acpi/rsdp
1ec3f040 20000 23 etc/acpi/tables
0 4 24 etc/boot-fail-wait
0 28 25 etc/e820
0 18 26 etc/smbios/smbios-anchor
0 151 27 etc/smbios/smbios-tables
0 6 28 etc/system-states
0 1000 29 etc/table-loader
0 0 2a etc/tpm/log
0 2400 2b genroms/kvmvapic.bin
=> qfw read 1000 etc/acpi/rsdp
=> md.b 1000 14
00001000: 52 53 44 20 50 54 52 20 00 42 4f 43 48 53 20 00 RSD PTR .BOCHS .
00001010: 40 1c 00 00 @...
Configuration
-------------

View File

@@ -98,3 +98,18 @@ static int cmd_test_qfw_arch(struct unit_test_state *uts)
return 0;
}
CMD_TEST(cmd_test_qfw_arch, UTF_CONSOLE);
/* Test 'qfw read' command */
static int cmd_test_qfw_read(struct unit_test_state *uts)
{
char *ptr = map_sysmem(0x1000, 0x100);
if (IS_ENABLED(CONFIG_SANDBOX))
return -EAGAIN;
ut_assertok(run_command("qfw read 1000 etc/acpi/rsdp", 0));
ut_asserteq_strn("RSD PTR ", ptr);
return 0;
}
CMD_TEST(cmd_test_qfw_read, UTF_CONSOLE);