Patrick Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame] | 1 | From 910760408430de32ad08b1e5ddf894cc9f2f3d0c Mon Sep 17 00:00:00 2001 |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 2 | From: Rui Miguel Silva <rui.silva@linaro.org> |
| 3 | Date: Thu, 24 Jun 2021 09:25:00 +0100 |
Patrick Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame] | 4 | Subject: [PATCH 01/26] cmd: load: add load command for memory mapped |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 5 | |
| 6 | cp.b is used a lot as a way to load binaries to memory and execute |
| 7 | them, however we may need to integrate this with the efi subsystem to |
| 8 | set it up as a bootdev. |
| 9 | |
| 10 | So, introduce a loadm command that will be consistent with the other |
| 11 | loadX commands and will call the efi API's. |
| 12 | |
| 13 | ex: loadm $kernel_addr $kernel_addr_r $kernel_size |
| 14 | |
| 15 | with this a kernel with CONFIG_EFI_STUB enabled will be loaded and |
| 16 | then subsequently booted with bootefi command. |
| 17 | |
| 18 | Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org> |
Patrick Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame] | 19 | Upstream-Status: Accepted [2022.10-rc1] |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 20 | --- |
| 21 | README | 1 + |
| 22 | cmd/Kconfig | 6 ++++ |
| 23 | cmd/bootefi.c | 12 ++++++++ |
| 24 | cmd/load.c | 48 ++++++++++++++++++++++++++++++++ |
| 25 | include/efi_loader.h | 2 ++ |
| 26 | lib/efi_loader/efi_device_path.c | 9 ++++++ |
| 27 | 6 files changed, 78 insertions(+) |
| 28 | |
| 29 | diff --git a/README b/README |
Patrick Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame] | 30 | index b7ab6e5070..cd76f95e74 100644 |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 31 | --- a/README |
| 32 | +++ b/README |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 33 | @@ -2578,6 +2578,7 @@ rarpboot- boot image via network using RARP/TFTP protocol |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 34 | diskboot- boot from IDE devicebootd - boot default, i.e., run 'bootcmd' |
| 35 | loads - load S-Record file over serial line |
| 36 | loadb - load binary file over serial line (kermit mode) |
| 37 | +loadm - load binary blob from source address to destination address |
| 38 | md - memory display |
| 39 | mm - memory modify (auto-incrementing) |
| 40 | nm - memory modify (constant address) |
| 41 | diff --git a/cmd/Kconfig b/cmd/Kconfig |
Patrick Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame] | 42 | index 09193b61b9..ba2f321ae9 100644 |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 43 | --- a/cmd/Kconfig |
| 44 | +++ b/cmd/Kconfig |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 45 | @@ -1143,6 +1143,12 @@ config CMD_LOADB |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 46 | help |
| 47 | Load a binary file over serial line. |
| 48 | |
| 49 | +config CMD_LOADM |
| 50 | + bool "loadm" |
| 51 | + default y |
| 52 | + help |
| 53 | + Load a binary over memory mapped. |
| 54 | + |
| 55 | config CMD_LOADS |
| 56 | bool "loads" |
| 57 | default y |
| 58 | diff --git a/cmd/bootefi.c b/cmd/bootefi.c |
Patrick Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame] | 59 | index 827fcd97df..37ce659fa1 100644 |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 60 | --- a/cmd/bootefi.c |
| 61 | +++ b/cmd/bootefi.c |
| 62 | @@ -34,6 +34,18 @@ static struct efi_device_path *bootefi_device_path; |
| 63 | static void *image_addr; |
| 64 | static size_t image_size; |
| 65 | |
| 66 | +/** |
| 67 | + * efi_get_image_parameters() - return image parameters |
| 68 | + * |
| 69 | + * @img_addr: address of loaded image in memory |
| 70 | + * @img_size: size of loaded image |
| 71 | + */ |
| 72 | +void efi_get_image_parameters(void **img_addr, size_t *img_size) |
| 73 | +{ |
| 74 | + *img_addr = image_addr; |
| 75 | + *img_size = image_size; |
| 76 | +} |
| 77 | + |
| 78 | /** |
| 79 | * efi_clear_bootdev() - clear boot device |
| 80 | */ |
| 81 | diff --git a/cmd/load.c b/cmd/load.c |
Patrick Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame] | 82 | index 7e4a552d90..1224a7f85b 100644 |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 83 | --- a/cmd/load.c |
| 84 | +++ b/cmd/load.c |
| 85 | @@ -1063,6 +1063,44 @@ static ulong load_serial_ymodem(ulong offset, int mode) |
| 86 | |
| 87 | #endif |
| 88 | |
| 89 | +#if defined(CONFIG_CMD_LOADM) |
| 90 | +static int do_load_memory_bin(struct cmd_tbl *cmdtp, int flag, int argc, |
| 91 | + char *const argv[]) |
| 92 | +{ |
| 93 | + ulong addr, dest, size; |
| 94 | + void *src, *dst; |
| 95 | + |
| 96 | + if (argc != 4) |
| 97 | + return CMD_RET_USAGE; |
| 98 | + |
| 99 | + addr = simple_strtoul(argv[1], NULL, 16); |
| 100 | + |
| 101 | + dest = simple_strtoul(argv[2], NULL, 16); |
| 102 | + |
| 103 | + size = simple_strtoul(argv[3], NULL, 16); |
| 104 | + |
| 105 | + if (!size) { |
| 106 | + printf("loadm: can not load zero bytes\n"); |
| 107 | + return 1; |
| 108 | + } |
| 109 | + |
| 110 | + src = map_sysmem(addr, size); |
| 111 | + dst = map_sysmem(dest, size); |
| 112 | + |
| 113 | + memcpy(dst, src, size); |
| 114 | + |
| 115 | + unmap_sysmem(src); |
| 116 | + unmap_sysmem(dst); |
| 117 | + |
| 118 | + if (IS_ENABLED(CONFIG_CMD_BOOTEFI)) |
| 119 | + efi_set_bootdev("Mem", "", "", map_sysmem(dest, 0), size); |
| 120 | + |
| 121 | + printf("loaded bin to memory: size: %lu\n", size); |
| 122 | + |
| 123 | + return 0; |
| 124 | +} |
| 125 | +#endif |
| 126 | + |
| 127 | /* -------------------------------------------------------------------- */ |
| 128 | |
| 129 | #if defined(CONFIG_CMD_LOADS) |
| 130 | @@ -1137,3 +1175,13 @@ U_BOOT_CMD( |
| 131 | ); |
| 132 | |
| 133 | #endif /* CONFIG_CMD_LOADB */ |
| 134 | + |
| 135 | +#if defined(CONFIG_CMD_LOADM) |
| 136 | +U_BOOT_CMD( |
| 137 | + loadm, 4, 0, do_load_memory_bin, |
| 138 | + "load binary blob from source address to destination address", |
| 139 | + "[src_addr] [dst_addr] [size]\n" |
| 140 | + " - load a binary blob from one memory location to other" |
| 141 | + " from src_addr to dst_addr by size bytes" |
| 142 | +); |
| 143 | +#endif /* CONFIG_CMD_LOADM */ |
| 144 | diff --git a/include/efi_loader.h b/include/efi_loader.h |
Patrick Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame] | 145 | index 11930fbea8..5b41985244 100644 |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 146 | --- a/include/efi_loader.h |
| 147 | +++ b/include/efi_loader.h |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 148 | @@ -591,6 +591,8 @@ efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle, |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 149 | void efi_save_gd(void); |
| 150 | /* Call this to relocate the runtime section to an address space */ |
| 151 | void efi_runtime_relocate(ulong offset, struct efi_mem_desc *map); |
| 152 | +/* Call this to get image parameters */ |
| 153 | +void efi_get_image_parameters(void **img_addr, size_t *img_size); |
| 154 | /* Add a new object to the object list. */ |
| 155 | void efi_add_handle(efi_handle_t obj); |
| 156 | /* Create handle */ |
| 157 | diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c |
Patrick Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame] | 158 | index 171661b897..2493d74326 100644 |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 159 | --- a/lib/efi_loader/efi_device_path.c |
| 160 | +++ b/lib/efi_loader/efi_device_path.c |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 161 | @@ -1158,6 +1158,8 @@ efi_status_t efi_dp_from_name(const char *dev, const char *devnr, |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 162 | { |
| 163 | struct blk_desc *desc = NULL; |
| 164 | struct disk_partition fs_partition; |
| 165 | + size_t image_size; |
| 166 | + void *image_addr; |
| 167 | int part = 0; |
| 168 | char *filename; |
| 169 | char *s; |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 170 | @@ -1173,6 +1175,13 @@ efi_status_t efi_dp_from_name(const char *dev, const char *devnr, |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 171 | } else if (!strcmp(dev, "Uart")) { |
| 172 | if (device) |
| 173 | *device = efi_dp_from_uart(); |
| 174 | + } else if (!strcmp(dev, "Mem")) { |
| 175 | + efi_get_image_parameters(&image_addr, &image_size); |
| 176 | + |
| 177 | + if (device) |
| 178 | + *device = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE, |
| 179 | + (uintptr_t)image_addr, |
| 180 | + image_size); |
| 181 | } else { |
| 182 | part = blk_get_device_part_str(dev, devnr, &desc, &fs_partition, |
| 183 | 1); |
| 184 | -- |
Patrick Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame] | 185 | 2.17.1 |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 186 | |