diff options
author | ian <ian@FreeBSD.org> | 2014-02-22 22:18:20 +0000 |
---|---|---|
committer | ian <ian@FreeBSD.org> | 2014-02-22 22:18:20 +0000 |
commit | 43dd7e1f063400b8cae6eb34df3b44995ff6d65c (patch) | |
tree | 9b251e269a983d86ba12602dcd35f6ffc726eca6 | |
parent | 9e48499196550691019d14fa0694357a14039db4 (diff) | |
download | FreeBSD-src-43dd7e1f063400b8cae6eb34df3b44995ff6d65c.zip FreeBSD-src-43dd7e1f063400b8cae6eb34df3b44995ff6d65c.tar.gz |
Add a feature for automatically finding and loading a dtb file by name.
The name is taken from the u-boot env vars fdtfile or fdt_file. If the
name isn't fully-qualified a search is done in module_path locations.
The search order for a usable dtb in fdt_setup_fdtp() is now
- A dtb loaded with an explicit "load -t dtb" command.
- A dtb already loaded into memory somehow[*] and pointed to by fdt_to_load.
- A dtb in the memory pointed to by the u-boot env vars fdtaddr or fdt_addr.
- A file named by the u-boot env vars fdtfile or fdt_file.
- A static dtb compiled into the kernel.
* Presumably by some arch-specific command or code.
-rw-r--r-- | sys/boot/fdt/fdt_loader_cmd.c | 46 |
1 files changed, 43 insertions, 3 deletions
diff --git a/sys/boot/fdt/fdt_loader_cmd.c b/sys/boot/fdt/fdt_loader_cmd.c index b553a85..1d74d62 100644 --- a/sys/boot/fdt/fdt_loader_cmd.c +++ b/sys/boot/fdt/fdt_loader_cmd.c @@ -254,11 +254,36 @@ fdt_load_dtb_addr(struct fdt_header *header) } static int +fdt_load_dtb_file(const char * filename) +{ + struct preloaded_file *bfp, *oldbfp; + int err; + + debugf("fdt_load_dtb_file(%s)\n", filename); + + oldbfp = file_findfile(NULL, "dtb"); + + /* Attempt to load and validate a new dtb from a file. */ + if ((bfp = file_loadraw(filename, "dtb")) == NULL) { + sprintf(command_errbuf, "failed to load file '%s'", filename); + return (1); + } + if ((err = fdt_load_dtb(bfp->f_addr)) != 0) { + file_discard(bfp); + return (err); + } + + /* A new dtb was validated, discard any previous file. */ + if (oldbfp) + file_discard(oldbfp); + return (0); +} + +static int fdt_setup_fdtp() { struct preloaded_file *bfp; struct fdt_header *hdr; - int err; const char *s; char *p; vm_offset_t va; @@ -268,7 +293,8 @@ fdt_setup_fdtp() /* If we already loaded a file, use it. */ if ((bfp = file_findfile(NULL, "dtb")) != NULL) { if (fdt_load_dtb(bfp->f_addr) == 0) { - printf("Using DTB from loaded file.\n"); + printf("Using DTB from loaded file '%s'.\n", + bfp->f_name); return (0); } } @@ -295,12 +321,26 @@ fdt_setup_fdtp() if (*p == '\0') { if (fdt_load_dtb_addr(hdr) == 0) { printf("Using DTB provided by U-Boot at " - "address 0x%08X.\n", hdr); + "address 0x%p.\n", hdr); return (0); } } } + /* + * If the U-boot environment contains a variable giving the name of a + * file, use it if we can load and validate it. + */ + s = ub_env_get("fdtfile"); + if (s == NULL) + s = ub_env_get("fdt_file"); + if (s != NULL && *s != '\0') { + if (fdt_load_dtb_file(s) == 0) { + printf("Loaded DTB from file '%s'.\n", s); + return (0); + } + } + /* If there is a dtb compiled into the kernel, use it. */ if ((va = fdt_find_static_dtb()) != 0) { if (fdt_load_dtb(va) == 0) { |