Commit 95fac6ab4589ec0767b1eac662577866e2b2f423

Authored by Simon Glass
1 parent 9f6044256e

sandbox: Use os functions to read host device tree

At present we use U-Boot's filesystem layer to read the sandbox device tree,
but this is problematic since it relies on a temporary feauture added
there. Since we plan to implement proper block layer support for sandbox,
change this code to use the os layer functions instead. Also use the new
fdt_create_empty_tree() instead of our own code.

Signed-off-by: Simon Glass <sjg@chromium.org>

Showing 2 changed files with 21 additions and 44 deletions Side-by-side Diff

... ... @@ -282,45 +282,39 @@
282 282  
283 283 #ifdef CONFIG_OF_HOSTFILE
284 284  
285   -#define CHECK(x) err = (x); if (err) goto failed;
286   -
287   -/* Create an empty device tree blob */
288   -static int make_empty_fdt(void *fdt)
289   -{
290   - int err;
291   -
292   - CHECK(fdt_create(fdt, 256));
293   - CHECK(fdt_finish_reservemap(fdt));
294   - CHECK(fdt_begin_node(fdt, ""));
295   - CHECK(fdt_end_node(fdt));
296   - CHECK(fdt_finish(fdt));
297   -
298   - return 0;
299   -failed:
300   - printf("Unable to create empty FDT: %s\n", fdt_strerror(err));
301   - return -EACCES;
302   -}
303   -
304 285 static int read_fdt_from_file(void)
305 286 {
306 287 struct sandbox_state *state = state_get_current();
  288 + const char *fname = state->fdt_fname;
307 289 void *blob;
308   - int size;
  290 + ssize_t size;
309 291 int err;
  292 + int fd;
310 293  
311 294 blob = map_sysmem(CONFIG_SYS_FDT_LOAD_ADDR, 0);
312 295 if (!state->fdt_fname) {
313   - err = make_empty_fdt(blob);
  296 + err = fdt_create_empty_tree(blob, 256);
314 297 if (!err)
315 298 goto done;
316   - return err;
  299 + printf("Unable to create empty FDT: %s\n", fdt_strerror(err));
  300 + return -EINVAL;
317 301 }
318   - err = fs_set_blk_dev("host", NULL, FS_TYPE_SANDBOX);
319   - if (err)
320   - return err;
321   - size = fs_read(state->fdt_fname, CONFIG_SYS_FDT_LOAD_ADDR, 0, 0);
322   - if (size < 0)
  302 +
  303 + size = os_get_filesize(fname);
  304 + if (size < 0) {
  305 + printf("Failed to file FDT file '%s'\n", fname);
  306 + return -ENOENT;
  307 + }
  308 + fd = os_open(fname, OS_O_RDONLY);
  309 + if (fd < 0) {
  310 + printf("Failed to open FDT file '%s'\n", fname);
  311 + return -EACCES;
  312 + }
  313 + if (os_read(fd, blob, size) != size) {
  314 + os_close(fd);
323 315 return -EIO;
  316 + }
  317 + os_close(fd);
324 318  
325 319 done:
326 320 gd->fdt_blob = blob;
... ... @@ -452,23 +452,6 @@
452 452 int part;
453 453 disk_partition_t tmpinfo;
454 454  
455   - /*
456   - * For now, we have a special case for sandbox, since there is no
457   - * real block device support.
458   - */
459   - if (0 == strcmp(ifname, "host")) {
460   - *dev_desc = NULL;
461   - info->start = info->size = info->blksz = 0;
462   - info->bootable = 0;
463   - strcpy((char *)info->type, BOOT_PART_TYPE);
464   - strcpy((char *)info->name, "Sandbox host");
465   -#ifdef CONFIG_PARTITION_UUIDS
466   - info->uuid[0] = 0;
467   -#endif
468   -
469   - return 0;
470   - }
471   -
472 455 /* If no dev_part_str, use bootdevice environment variable */
473 456 if (!dev_part_str || !strlen(dev_part_str) ||
474 457 !strcmp(dev_part_str, "-"))