Skip to content
Snippets Groups Projects
fdtdec.c 27.1 KiB
Newer Older
  • Learn to ignore specific revisions
  • 	snprintf(prop_name, sizeof(prop_name), "%s-memory%s", mem_type,
    		 suffix);
    	mem = fdt_getprop(blob, config_node, prop_name, NULL);
    	if (!mem) {
    		debug("%s: No memory type for '%s', using /memory\n", __func__,
    		      prop_name);
    		mem = "/memory";
    	}
    
    	node = fdt_path_offset(blob, mem);
    	if (node < 0) {
    		debug("%s: Failed to find node '%s': %s\n", __func__, mem,
    		      fdt_strerror(node));
    		return -ENOENT;
    	}
    
    	/*
    	 * Not strictly correct - the memory may have multiple banks. We just
    	 * use the first
    	 */
    	if (fdtdec_decode_region(blob, node, "reg", &base, &size)) {
    		debug("%s: Failed to decode memory region %s\n", __func__,
    		      mem);
    		return -EINVAL;
    	}
    
    	snprintf(prop_name, sizeof(prop_name), "%s-offset%s", mem_type,
    		 suffix);
    	if (fdtdec_decode_region(blob, config_node, prop_name, &offset,
    				 &offset_size)) {
    		debug("%s: Failed to decode memory region '%s'\n", __func__,
    		      prop_name);
    		return -EINVAL;
    	}
    
    	*basep = base + offset;
    	*sizep = offset_size;
    
    	return 0;
    }
    
    
    int setup_fdt(void)
    {
    #ifdef CONFIG_OF_CONTROL
    # ifdef CONFIG_OF_EMBED
    	/* Get a pointer to the FDT */
    	gd->fdt_blob = __dtb_dt_begin;
    # elif defined CONFIG_OF_SEPARATE
    #  ifdef CONFIG_SPL_BUILD
    	/* FDT is at end of BSS */
    	gd->fdt_blob = (ulong *)&__bss_end;
    #  else
    	/* FDT is at end of image */
    	gd->fdt_blob = (ulong *)&_end;
    #endif
    # elif defined(CONFIG_OF_HOSTFILE)
    	if (sandbox_read_fdt_from_file()) {
    		puts("Failed to read control FDT\n");
    		return -1;
    	}
    # endif
    # ifndef CONFIG_SPL_BUILD
    	/* Allow the early environment to override the fdt address */
    	gd->fdt_blob = (void *)getenv_ulong("fdtcontroladdr", 16,
    						(uintptr_t)gd->fdt_blob);
    # endif