diff options
author | Simon Glass <sjg@chromium.org> | 2013-04-20 08:42:41 +0000 |
---|---|---|
committer | Tom Rini <trini@ti.com> | 2013-05-01 11:17:21 -0400 |
commit | f828bf25fe02f0d7148a9180988ab4d5681b8195 (patch) | |
tree | 99c43aaf2246ec97b15ebb2f0603bfd7d2474d08 /common | |
parent | a733b06b69d2cb058c4363952bc0793b1f514305 (diff) | |
download | u-boot-f828bf25fe02f0d7148a9180988ab4d5681b8195.zip u-boot-f828bf25fe02f0d7148a9180988ab4d5681b8195.tar.gz u-boot-f828bf25fe02f0d7148a9180988ab4d5681b8195.tar.bz2 |
sandbox: Add CONFIG_OF_HOSTFILE to read FDT from host file
With sandbox it is tricky to add an FDT to the image at build time (or
later) since we build an ELF file, not a plain binary, and the address
space of the whole U-Boot is not accessible in the emulated memory map
of sandbox.
Sandbox can read files directly from the host, though, so add an option
to read an FDT from a host file on start-up.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'common')
-rw-r--r-- | common/board_f.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/common/board_f.c b/common/board_f.c index 2045055..3a6638f 100644 --- a/common/board_f.c +++ b/common/board_f.c @@ -31,6 +31,7 @@ #include <version.h> #include <environment.h> #include <fdtdec.h> +#include <fs.h> #if defined(CONFIG_CMD_IDE) #include <ide.h> #endif @@ -305,6 +306,55 @@ __weak int arch_cpu_init(void) return 0; } +#ifdef CONFIG_OF_HOSTFILE + +#define CHECK(x) err = (x); if (err) goto failed; + +/* Create an empty device tree blob */ +static int make_empty_fdt(void *fdt) +{ + int err; + + CHECK(fdt_create(fdt, 256)); + CHECK(fdt_finish_reservemap(fdt)); + CHECK(fdt_begin_node(fdt, "")); + CHECK(fdt_end_node(fdt)); + CHECK(fdt_finish(fdt)); + + return 0; +failed: + printf("Unable to create empty FDT: %s\n", fdt_strerror(err)); + return -EACCES; +} + +static int read_fdt_from_file(void) +{ + struct sandbox_state *state = state_get_current(); + void *blob; + int size; + int err; + + blob = map_sysmem(CONFIG_SYS_FDT_LOAD_ADDR, 0); + if (!state->fdt_fname) { + err = make_empty_fdt(blob); + if (!err) + goto done; + return err; + } + err = fs_set_blk_dev("host", NULL, FS_TYPE_SANDBOX); + if (err) + return err; + size = fs_read(state->fdt_fname, CONFIG_SYS_FDT_LOAD_ADDR, 0, 0); + if (size < 0) + return -EIO; + +done: + gd->fdt_blob = blob; + + return 0; +} +#endif + #ifdef CONFIG_SANDBOX static int setup_ram_buf(void) { @@ -328,6 +378,11 @@ static int setup_fdt(void) # else gd->fdt_blob = (ulong *)&_end; # endif +#elif defined(CONFIG_OF_HOSTFILE) + if (read_fdt_from_file()) { + puts("Failed to read control FDT\n"); + return -1; + } #endif /* Allow the early environment to override the fdt address */ gd->fdt_blob = (void *)getenv_ulong("fdtcontroladdr", 16, |