Esempio n. 1
0
int
fdt_platform_load_dtb(void)
{
	struct fdt_header *hdr;
	const char *s;
	char *p;
	int rv;

	/*
	 * If the U-boot environment contains a variable giving the address of a
	 * valid blob in memory, use it.  The U-boot README says the right
	 * variable for fdt data loaded into ram is fdt_addr_r, so try that
	 * first.  Board vendors also use both fdtaddr and fdt_addr names.
	 */
	s = ub_env_get("fdt_addr_r");
	if (s == NULL)
		s = ub_env_get("fdtaddr");
	if (s == NULL)
		s = ub_env_get("fdt_addr");
	if (s != NULL && *s != '\0') {
		hdr = (struct fdt_header *)strtoul(s, &p, 16);
		if (*p == '\0') {
			if (fdt_load_dtb_addr(hdr) == 0) {
				printf("Using DTB provided by U-Boot at "
				    "address %p.\n", hdr);
				return (0);
			}
		}
	}

	rv = 1;

	/*
	 * Try to get FDT filename first from loader env and then from u-boot env
	 */
	s = getenv("fdt_file");
	if (s == NULL)
		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);
			rv = 0;
		}
	}

	if (rv == 0) {
		s = getenv("fdt_overlays");
		if (s == NULL)
			s = ub_env_get("fdt_overlays");
		if (s != NULL && *s != '\0') {
			printf("Loading DTB overlays: '%s'\n", s);
			fdt_load_dtb_overlays(s);
		}
	}

	return (rv);
}
Esempio n. 2
0
int
fdt_setup_fdtp()
{
	struct preloaded_file *bfp;
	vm_offset_t va;
	
	debugf("fdt_setup_fdtp()\n");

	/* 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 '%s'.\n", 
			    bfp->f_name);
			return (0);
		}
	}

	/* If we were given the address of a valid blob in memory, use it. */
	if (fdt_to_load != NULL) {
		if (fdt_load_dtb_addr(fdt_to_load) == 0) {
			printf("Using DTB from memory address 0x%08X.\n",
			    (unsigned int)fdt_to_load);
			return (0);
		}
	}

	if (fdt_platform_load_dtb() == 0)
		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) {
			printf("Using DTB compiled into kernel.\n");
			return (0);
		}
	}
	
	command_errmsg = "No device tree blob found!\n";
	return (1);
}