command: add FDT setup for bootelf by flag
PATCH 1/1 command: add FDT setup for bootelf by flag
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.
---
cmd/elf.c | 14 ++++++++++++++ env/common.c | 5 +++++ include/env.h | 7 +++++++ 3 files changed, 26 insertions(+)
cmd/elf.c +14 -0
@@ -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[]) { +unsigned long fdt_addr; +struct bootm_headers img = {0 };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,0 ,NULL )) { +printf ("ERROR: Failed to process device tree\n" ); +return 1 ; + } + } + } + +if (!env_get_autostart ())return rcode;
env/common.c +5 -0
@@ -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 */
include/env.h +7 -0
@@ -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 *
Signature · 1 line
2.39.2
Quoted 14 lines · Maxim Moskalets
cmd/elf.c +2
-0@@ -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[]) { +unsigned long fdt_addr; +struct bootm_headers img = {0 };unsigned long addr;/* Address of the ELF image */ unsigned long rc;/* Return value from user code */ char *sload =NULL ;
cmd/elf.c int do_bootelf(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) · line 73
Quoted 4 lines
cmd/elf.c +1
-0@@ -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 ()) {
Should the ! be there? This looks reversed...
cmd/elf.c int do_bootelf(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) · line 86
Quoted 13 lines
cmd/elf.c +11
-0+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,0 ,NULL )) { +printf ("ERROR: Failed to process device tree\n" ); +return 1 ; + } + } + } + +if (!env_get_autostart ())return rcode;
There are a few style nits that I have with this change like the double blank line at the end. Try running scripts/checkpatch.pl on your patch. We could also combine the conditions and pull the code in a tab. Also I recognize that you just copied the != -EINVAL from a few lines earlier and it does work, but it's better to check for == 0 instead.
if (env_get_elf_need_fdt() && argc >= 1 &&
strict_strtoul(argv[0], 16, &fdt_addr) == 0) {
printf("Got FDT at 0x%08lx ...\n", fdt_addr);
if (image_setup_libfdt(&img, (void *)fdt_addr, 0, NULL)) {
printf("ERROR: Failed to process device tree\n");
return 1;
}
}regards,
dan carpenter