Commit f828bf25fe02f0d7148a9180988ab4d5681b8195

Authored by Simon Glass
Committed by Tom Rini
1 parent a733b06b69

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>

Showing 5 changed files with 70 additions and 1 deletions Side-by-side Diff

arch/sandbox/cpu/start.c
... ... @@ -104,6 +104,13 @@
104 104 }
105 105 SB_CMDLINE_OPT_SHORT(command, 'c', 1, "Execute U-Boot command");
106 106  
  107 +static int sb_cmdline_cb_fdt(struct sandbox_state *state, const char *arg)
  108 +{
  109 + state->fdt_fname = arg;
  110 + return 0;
  111 +}
  112 +SB_CMDLINE_OPT_SHORT(fdt, 'd', 1, "Specify U-Boot's control FDT");
  113 +
107 114 int main(int argc, char *argv[])
108 115 {
109 116 struct sandbox_state *state;
arch/sandbox/include/asm/state.h
... ... @@ -34,6 +34,7 @@
34 34 /* The complete state of the test system */
35 35 struct sandbox_state {
36 36 const char *cmd; /* Command to execute */
  37 + const char *fdt_fname; /* Filename of FDT binary */
37 38 enum exit_type_id exit_type; /* How we exited U-Boot */
38 39 const char *parse_err; /* Error to report from parsing */
39 40 int argc; /* Program arguments */
... ... @@ -31,6 +31,7 @@
31 31 #include <version.h>
32 32 #include <environment.h>
33 33 #include <fdtdec.h>
  34 +#include <fs.h>
34 35 #if defined(CONFIG_CMD_IDE)
35 36 #include <ide.h>
36 37 #endif
... ... @@ -305,6 +306,55 @@
305 306 return 0;
306 307 }
307 308  
  309 +#ifdef CONFIG_OF_HOSTFILE
  310 +
  311 +#define CHECK(x) err = (x); if (err) goto failed;
  312 +
  313 +/* Create an empty device tree blob */
  314 +static int make_empty_fdt(void *fdt)
  315 +{
  316 + int err;
  317 +
  318 + CHECK(fdt_create(fdt, 256));
  319 + CHECK(fdt_finish_reservemap(fdt));
  320 + CHECK(fdt_begin_node(fdt, ""));
  321 + CHECK(fdt_end_node(fdt));
  322 + CHECK(fdt_finish(fdt));
  323 +
  324 + return 0;
  325 +failed:
  326 + printf("Unable to create empty FDT: %s\n", fdt_strerror(err));
  327 + return -EACCES;
  328 +}
  329 +
  330 +static int read_fdt_from_file(void)
  331 +{
  332 + struct sandbox_state *state = state_get_current();
  333 + void *blob;
  334 + int size;
  335 + int err;
  336 +
  337 + blob = map_sysmem(CONFIG_SYS_FDT_LOAD_ADDR, 0);
  338 + if (!state->fdt_fname) {
  339 + err = make_empty_fdt(blob);
  340 + if (!err)
  341 + goto done;
  342 + return err;
  343 + }
  344 + err = fs_set_blk_dev("host", NULL, FS_TYPE_SANDBOX);
  345 + if (err)
  346 + return err;
  347 + size = fs_read(state->fdt_fname, CONFIG_SYS_FDT_LOAD_ADDR, 0, 0);
  348 + if (size < 0)
  349 + return -EIO;
  350 +
  351 +done:
  352 + gd->fdt_blob = blob;
  353 +
  354 + return 0;
  355 +}
  356 +#endif
  357 +
308 358 #ifdef CONFIG_SANDBOX
309 359 static int setup_ram_buf(void)
310 360 {
... ... @@ -328,6 +378,11 @@
328 378 # else
329 379 gd->fdt_blob = (ulong *)&_end;
330 380 # endif
  381 +#elif defined(CONFIG_OF_HOSTFILE)
  382 + if (read_fdt_from_file()) {
  383 + puts("Failed to read control FDT\n");
  384 + return -1;
  385 + }
331 386 #endif
332 387 /* Allow the early environment to override the fdt address */
333 388 gd->fdt_blob = (void *)getenv_ulong("fdtcontroladdr", 16,
doc/README.fdt-control
... ... @@ -142,7 +142,11 @@
142 142  
143 143 and then flash image.bin onto your board.
144 144  
145   -You cannot use both of these options at the same time.
  145 +If CONFIG_OF_HOSTFILE is defined, then it will be read from a file on
  146 +startup. This is only useful for sandbox. Use the -d flag to U-Boot to
  147 +specify the file to read.
  148 +
  149 +You cannot use more than one of these options at the same time.
146 150  
147 151 If you wish to put the fdt at a different address in memory, you can
148 152 define the "fdtcontroladdr" environment variable. This is the hex
include/configs/sandbox.h
... ... @@ -26,6 +26,7 @@
26 26 #define CONFIG_SANDBOX_BITS_PER_LONG 64
27 27  
28 28 #define CONFIG_OF_CONTROL
  29 +#define CONFIG_OF_HOSTFILE
29 30 #define CONFIG_OF_LIBFDT
30 31 #define CONFIG_LMB
31 32  
... ... @@ -71,6 +72,7 @@
71 72 #define CONFIG_SYS_MEMTEST_START 0x00100000
72 73 #define CONFIG_SYS_MEMTEST_END (CONFIG_SYS_MEMTEST_START + 0x1000)
73 74 #define CONFIG_PHYS_64BIT
  75 +#define CONFIG_SYS_FDT_LOAD_ADDR 0x1000000
74 76  
75 77 /* Size of our emulated memory */
76 78 #define CONFIG_SYS_SDRAM_BASE 0