diff mbox series

cmd: add FDT setup for bootelf by flag

Message ID 20240212184117.25641-1-Maxim.Moskalets@kaspersky.com
State Changes Requested
Delegated to: Tom Rini
Headers show
Series cmd: add FDT setup for bootelf by flag | expand

Commit Message

Maxim Moskalets Feb. 12, 2024, 6:41 p.m. UTC
Added the ability to use FDT for ELF applications, required to run some OS. To make FDT setup, you need to set the elf_needed_fdt environment variable to a value like y or yes.

Signed-off-by: Maxim Moskalets <Maxim.Moskalets@kaspersky.com>

Cc: Tom Rini <trini@konsulko.com>
---

 cmd/elf.c     | 14 ++++++++++++++
 env/common.c  |  5 +++++
 include/env.h |  7 +++++++
 3 files changed, 26 insertions(+)

Comments

Tom Rini Feb. 12, 2024, 6:43 p.m. UTC | #1
On Mon, Feb 12, 2024 at 09:41:17PM +0300, Maxim Moskalets wrote:

> Added the ability to use FDT for ELF applications, required to run some OS. To make FDT setup, you need to set the elf_needed_fdt environment variable to a value like y or yes.
> 
> Signed-off-by: Maxim Moskalets <Maxim.Moskalets@kaspersky.com>
> 
> Cc: Tom Rini <trini@konsulko.com>
> ---
> 
>  cmd/elf.c     | 14 ++++++++++++++
>  env/common.c  |  5 +++++
>  include/env.h |  7 +++++++
>  3 files changed, 26 insertions(+)

Is there some change compared with the last version of this patch? And,
I was thinking of how to reply to the previous one and I think my
question is why don't we just use a flag being passed to bootelf instead
of this? Doing bootelf addr -d fdt_addr seems clearer than bootelf addr1
addr2 and checking the environment.
diff mbox series

Patch

diff --git a/cmd/elf.c b/cmd/elf.c
index b7b9f506a5..1ee86c03de 100644
--- a/cmd/elf.c
+++ b/cmd/elf.c
@@ -38,6 +38,8 @@  static unsigned long do_bootelf_exec(ulong (*entry)(int, char * const[]),
 /* Interpreter command to boot an arbitrary ELF image from memory */
 int do_bootelf(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
+	struct bootm_headers img = {0};
+	unsigned long fdt_addr; /* Address of the FDT */
 	unsigned long addr; /* Address of the ELF image */
 	unsigned long rc; /* Return value from user code */
 	char *sload = NULL;
@@ -68,6 +70,18 @@  int do_bootelf(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 	else
 		addr = load_elf_image_shdr(addr);
 
+	if (env_get_elf_need_fdt()) {
+		if (argc >= 1 && strict_strtoul(argv[0], 16, &fdt_addr) != -EINVAL) {
+			printf("Got FDT at 0x%08lx ...\n", fdt_addr);
+
+			if (image_setup_libfdt(&img, (void *)fdt_addr, NULL)) {
+				printf("ERROR: Failed to process device tree\n");
+				return 1;
+			}
+		}
+	}
+
+
 	if (!env_get_autostart())
 		return rcode;
 
diff --git a/env/common.c b/env/common.c
index 48a565107c..8cd8558c3f 100644
--- a/env/common.c
+++ b/env/common.c
@@ -346,6 +346,11 @@  bool env_get_autostart(void)
 	return env_get_yesno("autostart") == 1;
 }
 
+bool env_get_elf_need_fdt(void)
+{
+	return env_get_yesno("elf_need_fdt") == 1;
+}
+
 /*
  * Look up the variable from the default environment
  */
diff --git a/include/env.h b/include/env.h
index d2a5954ded..384c312d2e 100644
--- a/include/env.h
+++ b/include/env.h
@@ -148,6 +148,13 @@  int env_get_yesno(const char *var);
  */
 bool env_get_autostart(void);
 
+/**
+ * env_get_elf_need_fdt() - Check if FDT is needed for ELF image
+ *
+ * Return: true if the "elf_need_fdt" env var exists and is set to "yes"
+ */
+bool env_get_elf_need_fdt(void);
+
 /**
  * env_set() - set an environment variable
  *