+// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (c) 2013, Google Inc.
*
*
* (C) Copyright 2000-2006
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier: GPL-2.0+
*/
#include <common.h>
#include <fdt_support.h>
#include <errno.h>
#include <image.h>
-#include <libfdt.h>
+#include <linux/libfdt.h>
+#include <mapmem.h>
#include <asm/io.h>
#ifndef CONFIG_SYS_FDT_PAD
#define CONFIG_SYS_FDT_PAD 0x3000
#endif
+/* adding a ramdisk needs 0x44 bytes in version 2008.10 */
+#define FDT_RAMDISK_OVERHEAD 0x80
+
DECLARE_GLOBAL_DATA_PTR;
static void fdt_error(const char *msg)
puts(" - must RESET the board to recover.\n");
}
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
static const image_header_t *image_get_fdt(ulong fdt_addr)
{
const image_header_t *fdt_hdr = map_sysmem(fdt_addr, 0);
}
return fdt_hdr;
}
+#endif
/**
* boot_fdt_add_mem_rsv_regions - Mark the memreserve sections as unusable
of_len = *of_size + CONFIG_SYS_FDT_PAD;
/* If fdt_high is set use it to select the relocation address */
- fdt_high = getenv("fdt_high");
+ fdt_high = env_get("fdt_high");
if (fdt_high) {
void *desired_addr = (void *)simple_strtoul(fdt_high, NULL, 16);
} else {
of_start =
(void *)(ulong) lmb_alloc_base(lmb, of_len, 0x1000,
- getenv_bootm_mapsize()
- + getenv_bootm_low());
+ env_get_bootm_mapsize()
+ + env_get_bootm_low());
}
if (of_start == NULL) {
*of_flat_tree = of_start;
*of_size = of_len;
- set_working_fdt_addr(*of_flat_tree);
+ set_working_fdt_addr((ulong)*of_flat_tree);
return 0;
error:
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)
{
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
const image_header_t *fdt_hdr;
+ ulong load, load_end;
+ ulong image_start, image_data, image_end;
+#endif
ulong fdt_addr;
char *fdt_blob = NULL;
- ulong image_start, image_data, image_end;
- ulong load, load_end;
void *buf;
-#if defined(CONFIG_FIT)
+#if CONFIG_IS_ENABLED(FIT)
const char *fit_uname_config = images->fit_uname_cfg;
const char *fit_uname_fdt = NULL;
ulong default_addr;
int fdt_noffset;
#endif
const char *select = NULL;
+ int ok_no_fdt = 0;
*of_flat_tree = NULL;
*of_size = 0;
if (argc > 2)
select = argv[2];
if (select || genimg_has_config(images)) {
-#if defined(CONFIG_FIT)
+#if CONFIG_IS_ENABLED(FIT)
if (select) {
/*
* If the FDT blob comes from the FIT image and the
debug("* fdt: cmdline image address = 0x%08lx\n",
fdt_addr);
}
-#if defined(CONFIG_FIT)
+#if CONFIG_IS_ENABLED(FIT)
} else {
/* use FIT configuration provided in first bootm
* command argument
fdt_noffset = fit_get_node_from_config(images,
FIT_FDT_PROP,
fdt_addr);
- if (fdt_noffset == -ENOLINK)
+ if (fdt_noffset == -ENOENT)
return 0;
else if (fdt_noffset < 0)
return 1;
debug("## Checking for 'FDT'/'FDT Image' at %08lx\n",
fdt_addr);
- /* copy from dataflash if needed */
- fdt_addr = genimg_get_image(fdt_addr);
-
/*
* Check if there is an FDT image at the
* address provided in the second bootm argument
*/
buf = map_sysmem(fdt_addr, 0);
switch (genimg_get_format(buf)) {
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
case IMAGE_FORMAT_LEGACY:
/* 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)
- goto error;
+ goto no_fdt;
/*
* move image data to the load address,
if (load == image_start ||
load == image_data) {
- fdt_blob = (char *)image_data;
+ fdt_addr = load;
break;
}
fdt_addr = load;
break;
+#endif
case IMAGE_FORMAT_FIT:
/*
* This case will catch both: new uImage format
* (libfdt based) and raw FDT blob (also libfdt
* based).
*/
-#if defined(CONFIG_FIT)
+#if CONFIG_IS_ENABLED(FIT)
/* check FDT blob vs FIT blob */
if (fit_check_format(buf)) {
ulong load, len;
- fdt_noffset = fit_image_load(images,
- FIT_FDT_PROP,
+ fdt_noffset = boot_get_fdt_fit(images,
fdt_addr, &fit_uname_fdt,
&fit_uname_config,
- arch, IH_TYPE_FLATDT,
- BOOTSTAGE_ID_FIT_FDT_START,
- FIT_LOAD_OPTIONAL, &load, &len);
+ arch, &load, &len);
images->fit_hdr_fdt = map_sysmem(fdt_addr, 0);
images->fit_uname_fdt = fit_uname_fdt;
images->fit_noffset_fdt = fdt_noffset;
fdt_addr = load;
+
break;
} else
#endif
break;
default:
puts("ERROR: Did not find a cmdline Flattened Device Tree\n");
- goto error;
+ goto no_fdt;
}
printf(" Booting using the fdt blob at %#08lx\n", fdt_addr);
}
} else {
debug("## No Flattened Device Tree\n");
- return 0;
+ goto no_fdt;
}
} else {
debug("## No Flattened Device Tree\n");
- return 0;
+ goto no_fdt;
}
*of_flat_tree = fdt_blob;
return 0;
+no_fdt:
+ ok_no_fdt = 1;
error:
*of_flat_tree = NULL;
*of_size = 0;
+ if (!select && ok_no_fdt) {
+ debug("Continuing to boot without FDT\n");
+ return 0;
+ }
return 1;
}
* addresses of some of the devices in the device tree are compared with the
* actual addresses at which U-Boot has placed them.
*
- * Returns 1 on success, 0 on failure. If 0 is returned, U-boot will halt the
+ * Returns 1 on success, 0 on failure. If 0 is returned, U-Boot will halt the
* boot process.
*/
__weak int ft_verify_fdt(void *fdt)
return 1;
}
-__weak int arch_fixup_memory_node(void *blob)
+__weak int arch_fixup_fdt(void *blob)
{
return 0;
}
{
ulong *initrd_start = &images->initrd_start;
ulong *initrd_end = &images->initrd_end;
- int ret;
+ int ret = -EPERM;
+ int fdt_ret;
- if (fdt_chosen(blob, 1) < 0) {
- puts("ERROR: /chosen node create failed");
- puts(" - must RESET the board to recover.\n");
- return -1;
+ if (fdt_root(blob) < 0) {
+ printf("ERROR: root node setup failed\n");
+ goto err;
}
- arch_fixup_memory_node(blob);
- if (IMAGE_OF_BOARD_SETUP)
- ft_board_setup(blob, gd->bd);
+ if (fdt_chosen(blob) < 0) {
+ printf("ERROR: /chosen node create failed\n");
+ goto err;
+ }
+ if (arch_fixup_fdt(blob) < 0) {
+ printf("ERROR: arch-specific fdt fixup failed\n");
+ goto err;
+ }
+ /* Update ethernet nodes */
fdt_fixup_ethernet(blob);
+ if (IMAGE_OF_BOARD_SETUP) {
+ 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;
+ }
+ }
+ if (IMAGE_OF_SYSTEM_SETUP) {
+ fdt_ret = ft_system_setup(blob, gd->bd);
+ if (fdt_ret) {
+ printf("ERROR: system-specific fdt fixup failed: %s\n",
+ fdt_strerror(fdt_ret));
+ goto err;
+ }
+ }
/* Delete the old LMB reservation */
- lmb_free(lmb, (phys_addr_t)(u32)(uintptr_t)blob,
- (phys_size_t)fdt_totalsize(blob));
+ if (lmb)
+ lmb_free(lmb, (phys_addr_t)(u32)(uintptr_t)blob,
+ (phys_size_t)fdt_totalsize(blob));
- ret = fdt_resize(blob);
+ ret = fdt_shrink_to_minimum(blob, 0);
if (ret < 0)
- return ret;
+ goto err;
of_size = ret;
if (*initrd_start && *initrd_end) {
fdt_set_totalsize(blob, of_size);
}
/* Create a new LMB reservation */
- lmb_reserve(lmb, (ulong)blob, of_size);
+ if (lmb)
+ lmb_reserve(lmb, (ulong)blob, of_size);
- fdt_initrd(blob, *initrd_start, *initrd_end, 1);
+ fdt_initrd(blob, *initrd_start, *initrd_end);
if (!ft_verify_fdt(blob))
- return -1;
+ goto err;
-#ifdef CONFIG_SOC_K2HK
+#if defined(CONFIG_SOC_KEYSTONE)
if (IMAGE_OF_BOARD_SETUP)
ft_board_setup_ex(blob, gd->bd);
#endif
return 0;
+err:
+ printf(" - must RESET the board to recover.\n\n");
+
+ return ret;
}