2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2013-05-08 08:06:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2013, Google Inc.
|
|
|
|
*
|
|
|
|
* (C) Copyright 2008 Semihalf
|
|
|
|
*
|
|
|
|
* (C) Copyright 2000-2006
|
|
|
|
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <fdt_support.h>
|
2019-01-14 21:38:17 +00:00
|
|
|
#include <fdtdec.h>
|
2019-08-01 15:46:50 +00:00
|
|
|
#include <env.h>
|
2013-05-08 08:06:00 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <image.h>
|
2020-05-10 17:40:01 +00:00
|
|
|
#include <lmb.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2020-02-03 14:36:16 +00:00
|
|
|
#include <malloc.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2018-03-04 16:20:11 +00:00
|
|
|
#include <linux/libfdt.h>
|
2015-03-22 22:08:59 +00:00
|
|
|
#include <mapmem.h>
|
2013-05-08 08:06:00 +00:00
|
|
|
#include <asm/io.h>
|
2019-10-23 14:46:40 +00:00
|
|
|
#include <tee/optee.h>
|
2013-05-08 08:06:00 +00:00
|
|
|
|
|
|
|
#ifndef CONFIG_SYS_FDT_PAD
|
|
|
|
#define CONFIG_SYS_FDT_PAD 0x3000
|
|
|
|
#endif
|
|
|
|
|
2018-03-21 09:03:33 +00:00
|
|
|
/* adding a ramdisk needs 0x44 bytes in version 2008.10 */
|
|
|
|
#define FDT_RAMDISK_OVERHEAD 0x80
|
|
|
|
|
2013-05-08 08:06:00 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
|
|
|
static void fdt_error(const char *msg)
|
|
|
|
{
|
|
|
|
puts("ERROR: ");
|
|
|
|
puts(msg);
|
|
|
|
puts(" - must RESET the board to recover.\n");
|
|
|
|
}
|
|
|
|
|
2019-05-23 11:14:07 +00:00
|
|
|
#if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT)
|
2013-05-08 08:06:00 +00:00
|
|
|
static const image_header_t *image_get_fdt(ulong fdt_addr)
|
|
|
|
{
|
|
|
|
const image_header_t *fdt_hdr = map_sysmem(fdt_addr, 0);
|
|
|
|
|
|
|
|
image_print_contents(fdt_hdr);
|
|
|
|
|
|
|
|
puts(" Verifying Checksum ... ");
|
|
|
|
if (!image_check_hcrc(fdt_hdr)) {
|
|
|
|
fdt_error("fdt header checksum invalid");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!image_check_dcrc(fdt_hdr)) {
|
|
|
|
fdt_error("fdt checksum invalid");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
puts("OK\n");
|
|
|
|
|
|
|
|
if (!image_check_type(fdt_hdr, IH_TYPE_FLATDT)) {
|
|
|
|
fdt_error("uImage is not a fdt");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (image_get_comp(fdt_hdr) != IH_COMP_NONE) {
|
|
|
|
fdt_error("uImage is compressed");
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-09-19 03:10:18 +00:00
|
|
|
if (fdt_check_header((void *)image_get_data(fdt_hdr)) != 0) {
|
2013-05-08 08:06:00 +00:00
|
|
|
fdt_error("uImage data is not a fdt");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return fdt_hdr;
|
|
|
|
}
|
2014-05-28 09:33:33 +00:00
|
|
|
#endif
|
2013-05-08 08:06:00 +00:00
|
|
|
|
2019-01-14 21:38:17 +00:00
|
|
|
static void boot_fdt_reserve_region(struct lmb *lmb, uint64_t addr,
|
2021-05-07 12:50:33 +00:00
|
|
|
uint64_t size, enum lmb_flags flags)
|
2019-01-14 21:38:17 +00:00
|
|
|
{
|
2019-03-06 13:23:52 +00:00
|
|
|
long ret;
|
2019-01-14 21:38:17 +00:00
|
|
|
|
2021-05-07 12:50:33 +00:00
|
|
|
ret = lmb_reserve_flags(lmb, addr, size, flags);
|
2019-03-06 13:23:52 +00:00
|
|
|
if (ret >= 0) {
|
2021-05-07 12:50:33 +00:00
|
|
|
debug(" reserving fdt memory region: addr=%llx size=%llx flags=%x\n",
|
|
|
|
(unsigned long long)addr,
|
|
|
|
(unsigned long long)size, flags);
|
2019-01-14 21:38:17 +00:00
|
|
|
} else {
|
|
|
|
puts("ERROR: reserving fdt memory region failed ");
|
2021-05-07 12:50:33 +00:00
|
|
|
printf("(addr=%llx size=%llx flags=%x)\n",
|
|
|
|
(unsigned long long)addr,
|
|
|
|
(unsigned long long)size, flags);
|
2019-01-14 21:38:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-08 08:06:00 +00:00
|
|
|
/**
|
2019-01-14 21:38:17 +00:00
|
|
|
* boot_fdt_add_mem_rsv_regions - Mark the memreserve and reserved-memory
|
|
|
|
* sections as unusable
|
2013-05-08 08:06:00 +00:00
|
|
|
* @lmb: pointer to lmb handle, will be used for memory mgmt
|
|
|
|
* @fdt_blob: pointer to fdt blob base address
|
|
|
|
*
|
2019-01-14 21:38:17 +00:00
|
|
|
* Adds the and reserved-memorymemreserve regions in the dtb to the lmb block.
|
|
|
|
* Adding the memreserve regions prevents u-boot from using them to store the
|
|
|
|
* initrd or the fdt blob.
|
2013-05-08 08:06:00 +00:00
|
|
|
*/
|
|
|
|
void boot_fdt_add_mem_rsv_regions(struct lmb *lmb, void *fdt_blob)
|
|
|
|
{
|
|
|
|
uint64_t addr, size;
|
2019-01-14 21:38:17 +00:00
|
|
|
int i, total, ret;
|
|
|
|
int nodeoffset, subnode;
|
|
|
|
struct fdt_resource res;
|
2021-05-07 12:50:33 +00:00
|
|
|
enum lmb_flags flags;
|
2013-05-08 08:06:00 +00:00
|
|
|
|
|
|
|
if (fdt_check_header(fdt_blob) != 0)
|
|
|
|
return;
|
|
|
|
|
2019-01-14 21:38:17 +00:00
|
|
|
/* process memreserve sections */
|
2013-05-08 08:06:00 +00:00
|
|
|
total = fdt_num_mem_rsv(fdt_blob);
|
|
|
|
for (i = 0; i < total; i++) {
|
|
|
|
if (fdt_get_mem_rsv(fdt_blob, i, &addr, &size) != 0)
|
|
|
|
continue;
|
2021-05-07 12:50:33 +00:00
|
|
|
boot_fdt_reserve_region(lmb, addr, size, LMB_NONE);
|
2019-01-14 21:38:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* process reserved-memory */
|
|
|
|
nodeoffset = fdt_subnode_offset(fdt_blob, 0, "reserved-memory");
|
|
|
|
if (nodeoffset >= 0) {
|
|
|
|
subnode = fdt_first_subnode(fdt_blob, nodeoffset);
|
|
|
|
while (subnode >= 0) {
|
|
|
|
/* check if this subnode has a reg property */
|
|
|
|
ret = fdt_get_resource(fdt_blob, subnode, "reg", 0,
|
|
|
|
&res);
|
2020-01-07 06:21:42 +00:00
|
|
|
if (!ret && fdtdec_get_is_enabled(fdt_blob, subnode)) {
|
2021-05-07 12:50:33 +00:00
|
|
|
flags = LMB_NONE;
|
|
|
|
if (fdtdec_get_bool(fdt_blob, subnode,
|
|
|
|
"no-map"))
|
|
|
|
flags = LMB_NOMAP;
|
2019-01-14 21:38:17 +00:00
|
|
|
addr = res.start;
|
|
|
|
size = res.end - res.start + 1;
|
2021-05-07 12:50:33 +00:00
|
|
|
boot_fdt_reserve_region(lmb, addr, size, flags);
|
2019-01-14 21:38:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
subnode = fdt_next_subnode(fdt_blob, subnode);
|
|
|
|
}
|
2013-05-08 08:06:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* boot_relocate_fdt - relocate flat device tree
|
|
|
|
* @lmb: pointer to lmb handle, will be used for memory mgmt
|
|
|
|
* @of_flat_tree: pointer to a char* variable, will hold fdt start address
|
|
|
|
* @of_size: pointer to a ulong variable, will hold fdt length
|
|
|
|
*
|
|
|
|
* boot_relocate_fdt() allocates a region of memory within the bootmap and
|
|
|
|
* relocates the of_flat_tree into that region, even if the fdt is already in
|
|
|
|
* the bootmap. It also expands the size of the fdt by CONFIG_SYS_FDT_PAD
|
|
|
|
* bytes.
|
|
|
|
*
|
|
|
|
* of_flat_tree and of_size are set to final (after relocation) values
|
|
|
|
*
|
|
|
|
* returns:
|
|
|
|
* 0 - success
|
|
|
|
* 1 - failure
|
|
|
|
*/
|
|
|
|
int boot_relocate_fdt(struct lmb *lmb, char **of_flat_tree, ulong *of_size)
|
|
|
|
{
|
|
|
|
void *fdt_blob = *of_flat_tree;
|
|
|
|
void *of_start = NULL;
|
2022-04-08 00:09:19 +00:00
|
|
|
u64 start, size, usable;
|
2013-05-08 08:06:00 +00:00
|
|
|
char *fdt_high;
|
2022-04-08 00:09:19 +00:00
|
|
|
ulong mapsize, low;
|
2013-05-08 08:06:00 +00:00
|
|
|
ulong of_len = 0;
|
2022-04-08 00:09:19 +00:00
|
|
|
int bank;
|
2013-05-08 08:06:00 +00:00
|
|
|
int err;
|
|
|
|
int disable_relocation = 0;
|
|
|
|
|
|
|
|
/* nothing to do */
|
|
|
|
if (*of_size == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (fdt_check_header(fdt_blob) != 0) {
|
|
|
|
fdt_error("image is not a fdt");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* position on a 4K boundary before the alloc_current */
|
|
|
|
/* Pad the FDT by a specified amount */
|
|
|
|
of_len = *of_size + CONFIG_SYS_FDT_PAD;
|
|
|
|
|
|
|
|
/* If fdt_high is set use it to select the relocation address */
|
2017-08-03 18:22:12 +00:00
|
|
|
fdt_high = env_get("fdt_high");
|
2013-05-08 08:06:00 +00:00
|
|
|
if (fdt_high) {
|
2021-07-24 15:03:29 +00:00
|
|
|
void *desired_addr = (void *)hextoul(fdt_high, NULL);
|
2013-05-08 08:06:00 +00:00
|
|
|
|
|
|
|
if (((ulong) desired_addr) == ~0UL) {
|
|
|
|
/* All ones means use fdt in place */
|
|
|
|
of_start = fdt_blob;
|
|
|
|
lmb_reserve(lmb, (ulong)of_start, of_len);
|
|
|
|
disable_relocation = 1;
|
|
|
|
} else if (desired_addr) {
|
|
|
|
of_start =
|
|
|
|
(void *)(ulong) lmb_alloc_base(lmb, of_len, 0x1000,
|
|
|
|
(ulong)desired_addr);
|
|
|
|
if (of_start == NULL) {
|
|
|
|
puts("Failed using fdt_high value for Device Tree");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
of_start =
|
|
|
|
(void *)(ulong) lmb_alloc(lmb, of_len, 0x1000);
|
|
|
|
}
|
|
|
|
} else {
|
2022-04-08 00:09:19 +00:00
|
|
|
mapsize = env_get_bootm_mapsize();
|
|
|
|
low = env_get_bootm_low();
|
|
|
|
of_start = NULL;
|
|
|
|
|
|
|
|
for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) {
|
|
|
|
start = gd->bd->bi_dram[bank].start;
|
|
|
|
size = gd->bd->bi_dram[bank].size;
|
|
|
|
|
|
|
|
/* DRAM bank addresses are too low, skip it. */
|
|
|
|
if (start + size < low)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
usable = min(size, (u64)mapsize);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* At least part of this DRAM bank is usable, try
|
|
|
|
* using it for LMB allocation.
|
|
|
|
*/
|
|
|
|
of_start =
|
|
|
|
(void *)(ulong) lmb_alloc_base(lmb, of_len, 0x1000,
|
|
|
|
start + usable);
|
|
|
|
/* Allocation succeeded, use this block. */
|
|
|
|
if (of_start != NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reduce the mapping size in the next bank
|
|
|
|
* by the size of attempt in current bank.
|
|
|
|
*/
|
|
|
|
mapsize -= usable - max(start, (u64)low);
|
|
|
|
if (!mapsize)
|
|
|
|
break;
|
|
|
|
}
|
2013-05-08 08:06:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (of_start == NULL) {
|
|
|
|
puts("device tree - allocation error\n");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (disable_relocation) {
|
|
|
|
/*
|
|
|
|
* We assume there is space after the existing fdt to use
|
|
|
|
* for padding
|
|
|
|
*/
|
|
|
|
fdt_set_totalsize(of_start, of_len);
|
|
|
|
printf(" Using Device Tree in place at %p, end %p\n",
|
|
|
|
of_start, of_start + of_len - 1);
|
|
|
|
} else {
|
|
|
|
debug("## device tree at %p ... %p (len=%ld [0x%lX])\n",
|
|
|
|
fdt_blob, fdt_blob + *of_size - 1, of_len, of_len);
|
|
|
|
|
|
|
|
printf(" Loading Device Tree to %p, end %p ... ",
|
|
|
|
of_start, of_start + of_len - 1);
|
|
|
|
|
|
|
|
err = fdt_open_into(fdt_blob, of_start, of_len);
|
|
|
|
if (err != 0) {
|
|
|
|
fdt_error("fdt move failed");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
puts("OK\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
*of_flat_tree = of_start;
|
|
|
|
*of_size = of_len;
|
|
|
|
|
2018-12-17 19:14:42 +00:00
|
|
|
if (CONFIG_IS_ENABLED(CMD_FDT))
|
|
|
|
set_working_fdt_addr(map_to_sysmem(*of_flat_tree));
|
2013-05-08 08:06:00 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
error:
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-09-26 01:43:41 +00:00
|
|
|
* select_fdt() - Select and locate the FDT to use
|
2013-05-08 08:06:00 +00:00
|
|
|
*
|
2021-09-26 01:43:41 +00:00
|
|
|
* @images: pointer to the bootm images structure
|
|
|
|
* @select: name of FDT to select, or NULL for any
|
|
|
|
* @arch: expected FDT architecture
|
|
|
|
* @fdt_addrp: pointer to a ulong variable, will hold FDT pointer
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: 0 if OK, -ENOPKG if no FDT (but an error should not be reported),
|
2021-09-26 01:43:41 +00:00
|
|
|
* other -ve value on other error
|
2013-05-08 08:06:00 +00:00
|
|
|
*/
|
|
|
|
|
2021-09-26 01:43:41 +00:00
|
|
|
static int select_fdt(bootm_headers_t *images, const char *select, u8 arch,
|
|
|
|
ulong *fdt_addrp)
|
|
|
|
{
|
|
|
|
const char *buf;
|
|
|
|
ulong fdt_addr;
|
2019-01-15 14:26:37 +00:00
|
|
|
|
2016-02-23 05:55:43 +00:00
|
|
|
#if CONFIG_IS_ENABLED(FIT)
|
2021-09-26 01:43:41 +00:00
|
|
|
const char *fit_uname_config = images->fit_uname_cfg;
|
|
|
|
const char *fit_uname_fdt = NULL;
|
|
|
|
ulong default_addr;
|
|
|
|
int fdt_noffset;
|
2021-09-26 01:43:40 +00:00
|
|
|
|
2021-09-26 01:43:41 +00:00
|
|
|
if (select) {
|
2013-05-08 08:06:00 +00:00
|
|
|
/*
|
|
|
|
* If the FDT blob comes from the FIT image and the
|
|
|
|
* FIT image address is omitted in the command line
|
|
|
|
* argument, try to use ramdisk or os FIT image
|
|
|
|
* address or default load address.
|
|
|
|
*/
|
|
|
|
if (images->fit_uname_rd)
|
|
|
|
default_addr = (ulong)images->fit_hdr_rd;
|
|
|
|
else if (images->fit_uname_os)
|
|
|
|
default_addr = (ulong)images->fit_hdr_os;
|
|
|
|
else
|
2019-12-28 17:45:02 +00:00
|
|
|
default_addr = image_load_addr;
|
2013-05-08 08:06:00 +00:00
|
|
|
|
2021-09-26 01:43:41 +00:00
|
|
|
if (fit_parse_conf(select, default_addr, &fdt_addr,
|
|
|
|
&fit_uname_config)) {
|
2013-05-08 08:06:00 +00:00
|
|
|
debug("* fdt: config '%s' from image at 0x%08lx\n",
|
|
|
|
fit_uname_config, fdt_addr);
|
2021-09-26 01:43:41 +00:00
|
|
|
} else if (fit_parse_subimage(select, default_addr, &fdt_addr,
|
|
|
|
&fit_uname_fdt)) {
|
2013-05-08 08:06:00 +00:00
|
|
|
debug("* fdt: subimage '%s' from image at 0x%08lx\n",
|
|
|
|
fit_uname_fdt, fdt_addr);
|
|
|
|
} else
|
|
|
|
#endif
|
2021-09-26 01:43:41 +00:00
|
|
|
{
|
|
|
|
fdt_addr = hextoul(select, NULL);
|
|
|
|
debug("* fdt: cmdline image address = 0x%08lx\n",
|
|
|
|
fdt_addr);
|
2013-05-08 08:06:00 +00:00
|
|
|
}
|
2021-09-26 01:43:41 +00:00
|
|
|
#if CONFIG_IS_ENABLED(FIT)
|
|
|
|
} else {
|
|
|
|
/* use FIT configuration provided in first bootm
|
|
|
|
* command argument
|
2013-05-08 08:06:00 +00:00
|
|
|
*/
|
2021-09-26 01:43:41 +00:00
|
|
|
fdt_addr = map_to_sysmem(images->fit_hdr_os);
|
|
|
|
fdt_noffset = fit_get_node_from_config(images, FIT_FDT_PROP,
|
|
|
|
fdt_addr);
|
|
|
|
if (fdt_noffset == -ENOENT)
|
|
|
|
return -ENOPKG;
|
|
|
|
else if (fdt_noffset < 0)
|
|
|
|
return fdt_noffset;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
debug("## Checking for 'FDT'/'FDT Image' at %08lx\n",
|
|
|
|
fdt_addr);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if there is an FDT image at the
|
|
|
|
* address provided in the second bootm argument
|
|
|
|
* check image type, for FIT images get a FIT node.
|
|
|
|
*/
|
|
|
|
buf = map_sysmem(fdt_addr, 0);
|
|
|
|
switch (genimg_get_format(buf)) {
|
2019-05-23 11:14:07 +00:00
|
|
|
#if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT)
|
2021-09-26 01:43:41 +00:00
|
|
|
case IMAGE_FORMAT_LEGACY: {
|
2021-09-26 01:43:40 +00:00
|
|
|
const image_header_t *fdt_hdr;
|
|
|
|
ulong load, load_end;
|
|
|
|
ulong image_start, image_data, image_end;
|
|
|
|
|
2013-05-08 08:06:00 +00:00
|
|
|
/* verify fdt_addr points to a valid image header */
|
|
|
|
printf("## Flattened Device Tree from Legacy Image at %08lx\n",
|
|
|
|
fdt_addr);
|
|
|
|
fdt_hdr = image_get_fdt(fdt_addr);
|
|
|
|
if (!fdt_hdr)
|
2021-09-26 01:43:41 +00:00
|
|
|
return -ENOPKG;
|
2013-05-08 08:06:00 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* move image data to the load address,
|
|
|
|
* make sure we don't overwrite initial image
|
|
|
|
*/
|
|
|
|
image_start = (ulong)fdt_hdr;
|
|
|
|
image_data = (ulong)image_get_data(fdt_hdr);
|
|
|
|
image_end = image_get_image_end(fdt_hdr);
|
|
|
|
|
2013-05-16 13:53:23 +00:00
|
|
|
load = image_get_load(fdt_hdr);
|
|
|
|
load_end = load + image_get_data_size(fdt_hdr);
|
2013-05-08 08:06:00 +00:00
|
|
|
|
2013-05-16 13:53:23 +00:00
|
|
|
if (load == image_start ||
|
|
|
|
load == image_data) {
|
2015-11-24 08:54:22 +00:00
|
|
|
fdt_addr = load;
|
2013-05-08 08:06:00 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-05-16 13:53:23 +00:00
|
|
|
if ((load < image_end) && (load_end > image_start)) {
|
2013-05-08 08:06:00 +00:00
|
|
|
fdt_error("fdt overwritten");
|
2021-09-26 01:43:41 +00:00
|
|
|
return -EFAULT;
|
2013-05-08 08:06:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
debug(" Loading FDT from 0x%08lx to 0x%08lx\n",
|
2013-05-16 13:53:23 +00:00
|
|
|
image_data, load);
|
2013-05-08 08:06:00 +00:00
|
|
|
|
2013-05-16 13:53:23 +00:00
|
|
|
memmove((void *)load,
|
2013-05-08 08:06:00 +00:00
|
|
|
(void *)image_data,
|
|
|
|
image_get_data_size(fdt_hdr));
|
|
|
|
|
2013-05-16 13:53:23 +00:00
|
|
|
fdt_addr = load;
|
2013-05-08 08:06:00 +00:00
|
|
|
break;
|
2021-09-26 01:43:40 +00:00
|
|
|
}
|
2014-05-28 09:33:33 +00:00
|
|
|
#endif
|
2021-09-26 01:43:41 +00:00
|
|
|
case IMAGE_FORMAT_FIT:
|
|
|
|
/*
|
|
|
|
* This case will catch both: new uImage format
|
|
|
|
* (libfdt based) and raw FDT blob (also libfdt
|
|
|
|
* based).
|
|
|
|
*/
|
2016-02-23 05:55:43 +00:00
|
|
|
#if CONFIG_IS_ENABLED(FIT)
|
2013-05-08 08:06:00 +00:00
|
|
|
/* check FDT blob vs FIT blob */
|
2021-02-16 00:08:09 +00:00
|
|
|
if (!fit_check_format(buf, IMAGE_SIZE_INVAL)) {
|
2013-05-16 13:53:23 +00:00
|
|
|
ulong load, len;
|
2013-05-08 08:06:00 +00:00
|
|
|
|
2021-09-26 01:43:41 +00:00
|
|
|
fdt_noffset = boot_get_fdt_fit(images, fdt_addr,
|
|
|
|
&fit_uname_fdt,
|
|
|
|
&fit_uname_config,
|
|
|
|
arch, &load, &len);
|
2013-05-08 08:06:00 +00:00
|
|
|
|
2020-12-02 19:47:03 +00:00
|
|
|
if (fdt_noffset < 0)
|
2021-09-26 01:43:41 +00:00
|
|
|
return -ENOENT;
|
2020-12-02 19:47:03 +00:00
|
|
|
|
2013-05-16 13:53:23 +00:00
|
|
|
images->fit_hdr_fdt = map_sysmem(fdt_addr, 0);
|
2013-05-08 08:06:00 +00:00
|
|
|
images->fit_uname_fdt = fit_uname_fdt;
|
|
|
|
images->fit_noffset_fdt = fdt_noffset;
|
2013-05-16 13:53:23 +00:00
|
|
|
fdt_addr = load;
|
2017-09-04 20:12:16 +00:00
|
|
|
|
2013-05-08 08:06:00 +00:00
|
|
|
break;
|
2021-09-26 01:43:41 +00:00
|
|
|
} else
|
2013-05-08 08:06:00 +00:00
|
|
|
#endif
|
2021-09-26 01:43:41 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* FDT blob
|
|
|
|
*/
|
|
|
|
debug("* fdt: raw FDT blob\n");
|
|
|
|
printf("## Flattened Device Tree blob at %08lx\n",
|
|
|
|
(long)fdt_addr);
|
2013-05-08 08:06:00 +00:00
|
|
|
}
|
2021-09-26 01:43:41 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
puts("ERROR: Did not find a cmdline Flattened Device Tree\n");
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
*fdt_addrp = fdt_addr;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* boot_get_fdt - main fdt handling routine
|
|
|
|
* @argc: command argument count
|
|
|
|
* @argv: command argument list
|
|
|
|
* @arch: architecture (IH_ARCH_...)
|
|
|
|
* @images: pointer to the bootm images structure
|
|
|
|
* @of_flat_tree: pointer to a char* variable, will hold fdt start address
|
|
|
|
* @of_size: pointer to a ulong variable, will hold fdt length
|
|
|
|
*
|
|
|
|
* boot_get_fdt() is responsible for finding a valid flat device tree image.
|
|
|
|
* Currently supported are the following ramdisk sources:
|
|
|
|
* - multicomponent kernel/ramdisk image,
|
|
|
|
* - commandline provided address of decicated ramdisk image.
|
|
|
|
*
|
|
|
|
* returns:
|
|
|
|
* 0, if fdt image was found and valid, or skipped
|
|
|
|
* of_flat_tree and of_size are set to fdt start address and length if
|
|
|
|
* fdt image is found and valid
|
|
|
|
*
|
|
|
|
* 1, if fdt image is found but corrupted
|
|
|
|
* of_flat_tree and of_size are set to 0 if no fdt exists
|
|
|
|
*/
|
|
|
|
int boot_get_fdt(int flag, int argc, char *const argv[], uint8_t arch,
|
|
|
|
bootm_headers_t *images, char **of_flat_tree, ulong *of_size)
|
|
|
|
{
|
|
|
|
ulong img_addr;
|
|
|
|
ulong fdt_addr;
|
|
|
|
char *fdt_blob = NULL;
|
|
|
|
void *buf;
|
|
|
|
const char *select = NULL;
|
|
|
|
|
|
|
|
*of_flat_tree = NULL;
|
|
|
|
*of_size = 0;
|
|
|
|
|
|
|
|
img_addr = (argc == 0) ? image_load_addr : hextoul(argv[0], NULL);
|
|
|
|
buf = map_sysmem(img_addr, 0);
|
|
|
|
|
|
|
|
if (argc > 2)
|
|
|
|
select = argv[2];
|
|
|
|
if (select || genimg_has_config(images)) {
|
|
|
|
int ret;
|
2013-05-08 08:06:00 +00:00
|
|
|
|
2021-09-26 01:43:41 +00:00
|
|
|
ret = select_fdt(images, select, arch, &fdt_addr);
|
|
|
|
if (ret == -ENOPKG)
|
|
|
|
goto no_fdt;
|
|
|
|
else if (ret)
|
|
|
|
return 1;
|
2013-05-16 13:53:23 +00:00
|
|
|
printf(" Booting using the fdt blob at %#08lx\n", fdt_addr);
|
|
|
|
fdt_blob = map_sysmem(fdt_addr, 0);
|
2013-05-08 08:06:00 +00:00
|
|
|
} else if (images->legacy_hdr_valid &&
|
|
|
|
image_check_type(&images->legacy_hdr_os_copy,
|
|
|
|
IH_TYPE_MULTI)) {
|
|
|
|
ulong fdt_data, fdt_len;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now check if we have a legacy multi-component image,
|
|
|
|
* get second entry data start address and len.
|
|
|
|
*/
|
|
|
|
printf("## Flattened Device Tree from multi component Image at %08lX\n",
|
|
|
|
(ulong)images->legacy_hdr_os);
|
|
|
|
|
|
|
|
image_multi_getimg(images->legacy_hdr_os, 2, &fdt_data,
|
|
|
|
&fdt_len);
|
|
|
|
if (fdt_len) {
|
|
|
|
fdt_blob = (char *)fdt_data;
|
|
|
|
printf(" Booting using the fdt at 0x%p\n", fdt_blob);
|
|
|
|
|
|
|
|
if (fdt_check_header(fdt_blob) != 0) {
|
|
|
|
fdt_error("image is not a fdt");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fdt_totalsize(fdt_blob) != fdt_len) {
|
|
|
|
fdt_error("fdt size != image size");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
debug("## No Flattened Device Tree\n");
|
2014-11-27 21:24:16 +00:00
|
|
|
goto no_fdt;
|
2013-05-08 08:06:00 +00:00
|
|
|
}
|
2019-01-15 14:26:37 +00:00
|
|
|
#ifdef CONFIG_ANDROID_BOOT_IMAGE
|
|
|
|
} else if (genimg_get_format(buf) == IMAGE_FORMAT_ANDROID) {
|
|
|
|
struct andr_img_hdr *hdr = buf;
|
2020-07-20 00:48:15 +00:00
|
|
|
ulong fdt_data, fdt_len;
|
|
|
|
u32 fdt_size, dtb_idx;
|
|
|
|
/*
|
|
|
|
* Firstly check if this android boot image has dtb field.
|
|
|
|
*/
|
|
|
|
dtb_idx = (u32)env_get_ulong("adtb_idx", 10, 0);
|
|
|
|
if (android_image_get_dtb_by_index((ulong)hdr, dtb_idx, &fdt_addr, &fdt_size)) {
|
|
|
|
fdt_blob = (char *)map_sysmem(fdt_addr, 0);
|
|
|
|
if (fdt_check_header(fdt_blob))
|
|
|
|
goto no_fdt;
|
2019-01-15 14:26:37 +00:00
|
|
|
|
2020-07-20 00:48:15 +00:00
|
|
|
debug("## Using FDT in Android image dtb area with idx %u\n", dtb_idx);
|
|
|
|
} else if (!android_image_get_second(hdr, &fdt_data, &fdt_len) &&
|
|
|
|
!fdt_check_header((char *)fdt_data)) {
|
2019-04-01 10:45:36 +00:00
|
|
|
fdt_blob = (char *)fdt_data;
|
|
|
|
if (fdt_totalsize(fdt_blob) != fdt_len)
|
|
|
|
goto error;
|
2019-01-15 14:26:37 +00:00
|
|
|
|
2019-04-01 10:45:36 +00:00
|
|
|
debug("## Using FDT in Android image second area\n");
|
|
|
|
} else {
|
2019-04-01 10:52:52 +00:00
|
|
|
fdt_addr = env_get_hex("fdtaddr", 0);
|
|
|
|
if (!fdt_addr)
|
|
|
|
goto no_fdt;
|
2019-01-15 14:26:37 +00:00
|
|
|
|
2019-04-01 10:52:52 +00:00
|
|
|
fdt_blob = map_sysmem(fdt_addr, 0);
|
|
|
|
if (fdt_check_header(fdt_blob))
|
|
|
|
goto no_fdt;
|
2019-01-15 14:26:37 +00:00
|
|
|
|
2019-04-01 10:52:52 +00:00
|
|
|
debug("## Using FDT at ${fdtaddr}=Ox%lx\n", fdt_addr);
|
2019-04-01 10:45:36 +00:00
|
|
|
}
|
2019-01-15 14:26:37 +00:00
|
|
|
#endif
|
2013-05-08 08:06:00 +00:00
|
|
|
} else {
|
|
|
|
debug("## No Flattened Device Tree\n");
|
2014-11-27 21:24:16 +00:00
|
|
|
goto no_fdt;
|
2013-05-08 08:06:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*of_flat_tree = fdt_blob;
|
|
|
|
*of_size = fdt_totalsize(fdt_blob);
|
|
|
|
debug(" of_flat_tree at 0x%08lx size 0x%08lx\n",
|
|
|
|
(ulong)*of_flat_tree, *of_size);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2014-11-27 21:24:16 +00:00
|
|
|
no_fdt:
|
2019-04-01 10:45:35 +00:00
|
|
|
debug("Continuing to boot without FDT\n");
|
|
|
|
return 0;
|
2013-05-08 08:06:00 +00:00
|
|
|
error:
|
|
|
|
return 1;
|
|
|
|
}
|
2013-05-08 08:06:01 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Verify the device tree.
|
|
|
|
*
|
|
|
|
* This function is called after all device tree fix-ups have been enacted,
|
|
|
|
* so that the final device tree can be verified. The definition of "verified"
|
|
|
|
* is up to the specific implementation. However, it generally means that the
|
|
|
|
* addresses of some of the devices in the device tree are compared with the
|
|
|
|
* actual addresses at which U-Boot has placed them.
|
|
|
|
*
|
2016-02-06 03:30:11 +00:00
|
|
|
* Returns 1 on success, 0 on failure. If 0 is returned, U-Boot will halt the
|
2013-05-08 08:06:01 +00:00
|
|
|
* boot process.
|
|
|
|
*/
|
|
|
|
__weak int ft_verify_fdt(void *fdt)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-01-24 17:47:09 +00:00
|
|
|
__weak int arch_fixup_fdt(void *blob)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-05-08 08:06:01 +00:00
|
|
|
int image_setup_libfdt(bootm_headers_t *images, void *blob,
|
|
|
|
int of_size, struct lmb *lmb)
|
|
|
|
{
|
|
|
|
ulong *initrd_start = &images->initrd_start;
|
|
|
|
ulong *initrd_end = &images->initrd_end;
|
2014-10-24 00:58:53 +00:00
|
|
|
int ret = -EPERM;
|
|
|
|
int fdt_ret;
|
2013-05-08 08:06:01 +00:00
|
|
|
|
2015-05-21 09:27:03 +00:00
|
|
|
if (fdt_root(blob) < 0) {
|
|
|
|
printf("ERROR: root node setup failed\n");
|
|
|
|
goto err;
|
|
|
|
}
|
2014-04-18 08:41:00 +00:00
|
|
|
if (fdt_chosen(blob) < 0) {
|
2014-10-24 00:58:53 +00:00
|
|
|
printf("ERROR: /chosen node create failed\n");
|
|
|
|
goto err;
|
2013-05-08 08:06:01 +00:00
|
|
|
}
|
2014-07-12 13:24:06 +00:00
|
|
|
if (arch_fixup_fdt(blob) < 0) {
|
2014-10-24 00:58:53 +00:00
|
|
|
printf("ERROR: arch-specific fdt fixup failed\n");
|
|
|
|
goto err;
|
|
|
|
}
|
2020-06-05 07:22:54 +00:00
|
|
|
|
2021-02-08 12:54:31 +00:00
|
|
|
fdt_ret = optee_copy_fdt_nodes(blob);
|
2020-06-05 07:22:54 +00:00
|
|
|
if (fdt_ret) {
|
|
|
|
printf("ERROR: transfer of optee nodes to new fdt failed: %s\n",
|
|
|
|
fdt_strerror(fdt_ret));
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2022-04-12 20:00:43 +00:00
|
|
|
/* Store name of configuration node as u-boot,bootconf in /chosen node */
|
|
|
|
if (images->fit_uname_cfg)
|
|
|
|
fdt_find_and_setprop(blob, "/chosen", "u-boot,bootconf",
|
|
|
|
images->fit_uname_cfg,
|
|
|
|
strlen(images->fit_uname_cfg) + 1, 1);
|
|
|
|
|
2017-04-28 12:51:44 +00:00
|
|
|
/* Update ethernet nodes */
|
|
|
|
fdt_fixup_ethernet(blob);
|
2020-03-20 09:59:24 +00:00
|
|
|
#if CONFIG_IS_ENABLED(CMD_PSTORE)
|
|
|
|
/* Append PStore configuration */
|
|
|
|
fdt_fixup_pstore(blob);
|
|
|
|
#endif
|
2021-09-26 01:43:26 +00:00
|
|
|
if (IS_ENABLED(CONFIG_OF_BOARD_SETUP)) {
|
2021-02-04 14:44:04 +00:00
|
|
|
const char *skip_board_fixup;
|
|
|
|
|
|
|
|
skip_board_fixup = env_get("skip_board_fixup");
|
|
|
|
if (skip_board_fixup && ((int)simple_strtol(skip_board_fixup, NULL, 10) == 1)) {
|
|
|
|
printf("skip board fdt fixup\n");
|
|
|
|
} else {
|
|
|
|
fdt_ret = ft_board_setup(blob, gd->bd);
|
|
|
|
if (fdt_ret) {
|
|
|
|
printf("ERROR: board-specific fdt fixup failed: %s\n",
|
|
|
|
fdt_strerror(fdt_ret));
|
|
|
|
goto err;
|
|
|
|
}
|
2014-10-24 00:58:53 +00:00
|
|
|
}
|
2014-07-12 13:24:06 +00:00
|
|
|
}
|
2021-09-26 01:43:27 +00:00
|
|
|
if (IS_ENABLED(CONFIG_OF_SYSTEM_SETUP)) {
|
2015-08-05 15:17:03 +00:00
|
|
|
fdt_ret = ft_system_setup(blob, gd->bd);
|
|
|
|
if (fdt_ret) {
|
2014-10-24 00:58:54 +00:00
|
|
|
printf("ERROR: system-specific fdt fixup failed: %s\n",
|
|
|
|
fdt_strerror(fdt_ret));
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
}
|
2013-05-08 08:06:01 +00:00
|
|
|
|
|
|
|
/* Delete the old LMB reservation */
|
2016-03-04 00:10:13 +00:00
|
|
|
if (lmb)
|
|
|
|
lmb_free(lmb, (phys_addr_t)(u32)(uintptr_t)blob,
|
|
|
|
(phys_size_t)fdt_totalsize(blob));
|
2013-05-08 08:06:01 +00:00
|
|
|
|
2016-09-20 16:10:43 +00:00
|
|
|
ret = fdt_shrink_to_minimum(blob, 0);
|
2013-05-08 08:06:01 +00:00
|
|
|
if (ret < 0)
|
2014-10-24 00:58:53 +00:00
|
|
|
goto err;
|
2013-05-08 08:06:01 +00:00
|
|
|
of_size = ret;
|
|
|
|
|
|
|
|
if (*initrd_start && *initrd_end) {
|
|
|
|
of_size += FDT_RAMDISK_OVERHEAD;
|
|
|
|
fdt_set_totalsize(blob, of_size);
|
|
|
|
}
|
|
|
|
/* Create a new LMB reservation */
|
2016-03-04 00:10:13 +00:00
|
|
|
if (lmb)
|
|
|
|
lmb_reserve(lmb, (ulong)blob, of_size);
|
2013-05-08 08:06:01 +00:00
|
|
|
|
2014-04-18 08:40:59 +00:00
|
|
|
fdt_initrd(blob, *initrd_start, *initrd_end);
|
2013-05-08 08:06:01 +00:00
|
|
|
if (!ft_verify_fdt(blob))
|
2014-10-24 00:58:53 +00:00
|
|
|
goto err;
|
2013-05-08 08:06:01 +00:00
|
|
|
|
2021-09-13 00:32:32 +00:00
|
|
|
#if defined(CONFIG_ARCH_KEYSTONE)
|
2021-09-26 01:43:26 +00:00
|
|
|
if (IS_ENABLED(CONFIG_OF_BOARD_SETUP))
|
2014-04-04 17:16:47 +00:00
|
|
|
ft_board_setup_ex(blob, gd->bd);
|
|
|
|
#endif
|
|
|
|
|
2013-05-08 08:06:01 +00:00
|
|
|
return 0;
|
2014-10-24 00:58:53 +00:00
|
|
|
err:
|
|
|
|
printf(" - must RESET the board to recover.\n\n");
|
|
|
|
|
|
|
|
return ret;
|
2013-05-08 08:06:01 +00:00
|
|
|
}
|