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