diff options
| author | Rui Miguel Silva <rui.silva@linaro.org> | 2022-05-11 10:55:40 +0100 |
|---|---|---|
| committer | Tom Rini <trini@konsulko.com> | 2022-06-22 11:35:47 -0400 |
| commit | bfef72e4dd1c1d6dfc680867bf24a78597ab0438 (patch) | |
| tree | d403ba89ce489bb4a0e56acd7342ecdff45a95de /cmd | |
| parent | a47ce34403f27178c1264bf60496bbb9a21e5842 (diff) | |
cmd: load: add load command for memory mapped
cp.b is used a lot as a way to load binaries to memory and execute
them, however we may need to integrate this with the efi subsystem to
set it up as a bootdev.
So, introduce a loadm command that will be consistent with the other
loadX commands and will call the efi API's.
ex: loadm $kernel_addr $kernel_addr_r $kernel_size
with this a kernel with CONFIG_EFI_STUB enabled will be loaded and
then subsequently booted with bootefi command.
Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/Kconfig | 5 | ||||
| -rw-r--r-- | cmd/bootefi.c | 12 | ||||
| -rw-r--r-- | cmd/load.c | 48 |
3 files changed, 65 insertions, 0 deletions
diff --git a/cmd/Kconfig b/cmd/Kconfig index 9a0b7203112..dea3729d132 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1160,6 +1160,11 @@ config CMD_LOADB help Load a binary file over serial line. +config CMD_LOADM + bool "loadm" + help + Load a binary over memory mapped. + config CMD_LOADS bool "loads" default y diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 827fcd97dfd..37ce659fa12 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -35,6 +35,18 @@ static void *image_addr; static size_t image_size; /** + * efi_get_image_parameters() - return image parameters + * + * @img_addr: address of loaded image in memory + * @img_size: size of loaded image + */ +void efi_get_image_parameters(void **img_addr, size_t *img_size) +{ + *img_addr = image_addr; + *img_size = image_size; +} + +/** * efi_clear_bootdev() - clear boot device */ static void efi_clear_bootdev(void) diff --git a/cmd/load.c b/cmd/load.c index 7e4a552d90e..1224a7f85bb 100644 --- a/cmd/load.c +++ b/cmd/load.c @@ -1063,6 +1063,44 @@ static ulong load_serial_ymodem(ulong offset, int mode) #endif +#if defined(CONFIG_CMD_LOADM) +static int do_load_memory_bin(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + ulong addr, dest, size; + void *src, *dst; + + if (argc != 4) + return CMD_RET_USAGE; + + addr = simple_strtoul(argv[1], NULL, 16); + + dest = simple_strtoul(argv[2], NULL, 16); + + size = simple_strtoul(argv[3], NULL, 16); + + if (!size) { + printf("loadm: can not load zero bytes\n"); + return 1; + } + + src = map_sysmem(addr, size); + dst = map_sysmem(dest, size); + + memcpy(dst, src, size); + + unmap_sysmem(src); + unmap_sysmem(dst); + + if (IS_ENABLED(CONFIG_CMD_BOOTEFI)) + efi_set_bootdev("Mem", "", "", map_sysmem(dest, 0), size); + + printf("loaded bin to memory: size: %lu\n", size); + + return 0; +} +#endif + /* -------------------------------------------------------------------- */ #if defined(CONFIG_CMD_LOADS) @@ -1137,3 +1175,13 @@ U_BOOT_CMD( ); #endif /* CONFIG_CMD_LOADB */ + +#if defined(CONFIG_CMD_LOADM) +U_BOOT_CMD( + loadm, 4, 0, do_load_memory_bin, + "load binary blob from source address to destination address", + "[src_addr] [dst_addr] [size]\n" + " - load a binary blob from one memory location to other" + " from src_addr to dst_addr by size bytes" +); +#endif /* CONFIG_CMD_LOADM */ |
