2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2013-03-11 06:49:53 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2011 The Chromium OS Authors.
|
|
|
|
* (C) Copyright 2002-2006
|
|
|
|
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
|
|
|
*
|
|
|
|
* (C) Copyright 2002
|
|
|
|
* Sysgo Real-Time Solutions, GmbH <www.elinos.com>
|
|
|
|
* Marius Groeger <mgroeger@sysgo.de>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2018-11-16 01:43:52 +00:00
|
|
|
#include <bloblist.h>
|
2020-05-10 17:40:00 +00:00
|
|
|
#include <bootstage.h>
|
2019-12-28 17:44:58 +00:00
|
|
|
#include <clock_legacy.h>
|
2015-11-09 06:47:45 +00:00
|
|
|
#include <console.h>
|
2018-08-06 08:23:41 +00:00
|
|
|
#include <cpu.h>
|
2019-11-14 19:57:34 +00:00
|
|
|
#include <cpu_func.h>
|
2022-09-02 11:57:50 +00:00
|
|
|
#include <cyclic.h>
|
2022-07-31 18:28:48 +00:00
|
|
|
#include <display_options.h>
|
2014-07-23 12:55:04 +00:00
|
|
|
#include <dm.h>
|
2019-08-01 15:46:43 +00:00
|
|
|
#include <env.h>
|
2019-08-02 15:44:25 +00:00
|
|
|
#include <env_internal.h>
|
2022-03-04 15:43:02 +00:00
|
|
|
#include <event.h>
|
2013-03-11 06:49:53 +00:00
|
|
|
#include <fdtdec.h>
|
2013-04-20 08:42:41 +00:00
|
|
|
#include <fs.h>
|
2019-12-28 17:45:07 +00:00
|
|
|
#include <hang.h>
|
2013-03-11 14:30:42 +00:00
|
|
|
#include <i2c.h>
|
2019-11-14 19:57:45 +00:00
|
|
|
#include <init.h>
|
2013-03-11 06:49:53 +00:00
|
|
|
#include <initcall.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2015-02-28 05:06:36 +00:00
|
|
|
#include <malloc.h>
|
2015-03-22 22:08:59 +00:00
|
|
|
#include <mapmem.h>
|
2013-04-26 02:53:43 +00:00
|
|
|
#include <os.h>
|
2013-03-11 06:49:53 +00:00
|
|
|
#include <post.h>
|
2017-03-31 14:40:38 +00:00
|
|
|
#include <relocate.h>
|
2019-11-14 19:57:24 +00:00
|
|
|
#include <serial.h>
|
2018-11-16 01:44:09 +00:00
|
|
|
#include <spl.h>
|
2014-06-23 21:20:19 +00:00
|
|
|
#include <status_led.h>
|
2018-08-06 08:23:34 +00:00
|
|
|
#include <sysreset.h>
|
2016-02-24 16:14:50 +00:00
|
|
|
#include <timer.h>
|
2013-06-11 18:14:42 +00:00
|
|
|
#include <trace.h>
|
2016-01-19 02:52:21 +00:00
|
|
|
#include <video.h>
|
2013-03-11 14:30:42 +00:00
|
|
|
#include <watchdog.h>
|
2020-05-10 17:39:56 +00:00
|
|
|
#include <asm/cache.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2013-03-11 06:49:53 +00:00
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/sections.h>
|
2014-07-23 12:55:04 +00:00
|
|
|
#include <dm/root.h>
|
2017-03-31 14:40:35 +00:00
|
|
|
#include <linux/errno.h>
|
2022-09-18 11:23:27 +00:00
|
|
|
#include <linux/log2.h>
|
2013-03-11 06:49:53 +00:00
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
|
|
|
/*
|
2015-04-29 02:25:03 +00:00
|
|
|
* TODO(sjg@chromium.org): IMO this code should be
|
2013-03-11 06:49:53 +00:00
|
|
|
* refactored to a single function, something like:
|
|
|
|
*
|
|
|
|
* void led_set_state(enum led_colour_t colour, int on);
|
|
|
|
*/
|
|
|
|
/************************************************************************
|
|
|
|
* Coloured LED functionality
|
|
|
|
************************************************************************
|
|
|
|
* May be supplied by boards if desired
|
|
|
|
*/
|
2014-06-23 21:20:19 +00:00
|
|
|
__weak void coloured_LED_init(void) {}
|
|
|
|
__weak void red_led_on(void) {}
|
|
|
|
__weak void red_led_off(void) {}
|
|
|
|
__weak void green_led_on(void) {}
|
|
|
|
__weak void green_led_off(void) {}
|
|
|
|
__weak void yellow_led_on(void) {}
|
|
|
|
__weak void yellow_led_off(void) {}
|
|
|
|
__weak void blue_led_on(void) {}
|
|
|
|
__weak void blue_led_off(void) {}
|
2013-03-11 06:49:53 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Why is gd allocated a register? Prior to reloc it might be better to
|
|
|
|
* just pass it around to each function in this file?
|
|
|
|
*
|
|
|
|
* After reloc one could argue that it is hardly used and doesn't need
|
|
|
|
* to be in a register. Or if it is it should perhaps hold pointers to all
|
|
|
|
* global data for all modules, so that post-reloc we can avoid the massive
|
|
|
|
* literal pool we get on ARM. Or perhaps just encourage each module to use
|
|
|
|
* a structure...
|
|
|
|
*/
|
|
|
|
|
2014-07-17 11:01:34 +00:00
|
|
|
#if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG)
|
2013-03-11 14:30:42 +00:00
|
|
|
static int init_func_watchdog_init(void)
|
|
|
|
{
|
2017-03-14 15:08:10 +00:00
|
|
|
# if defined(CONFIG_HW_WATCHDOG) && \
|
|
|
|
(defined(CONFIG_M68K) || defined(CONFIG_MICROBLAZE) || \
|
2018-10-09 18:46:40 +00:00
|
|
|
defined(CONFIG_SH) || \
|
2016-06-13 12:24:23 +00:00
|
|
|
defined(CONFIG_DESIGNWARE_WATCHDOG) || \
|
2015-03-10 07:04:36 +00:00
|
|
|
defined(CONFIG_IMX_WATCHDOG))
|
2014-07-17 11:01:34 +00:00
|
|
|
hw_watchdog_init();
|
2013-03-11 14:30:42 +00:00
|
|
|
puts(" Watchdog enabled\n");
|
2016-06-13 12:24:24 +00:00
|
|
|
# endif
|
2022-09-02 12:10:46 +00:00
|
|
|
schedule();
|
2013-03-11 14:30:42 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int init_func_watchdog_reset(void)
|
|
|
|
{
|
2022-09-02 12:10:46 +00:00
|
|
|
schedule();
|
2013-03-11 14:30:42 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_WATCHDOG */
|
|
|
|
|
2014-10-08 20:57:22 +00:00
|
|
|
__weak void board_add_ram_info(int use_default)
|
2013-03-11 14:30:42 +00:00
|
|
|
{
|
|
|
|
/* please define platform specific board_add_ram_info() */
|
|
|
|
}
|
|
|
|
|
2013-03-11 06:49:53 +00:00
|
|
|
static int init_baud_rate(void)
|
|
|
|
{
|
2017-08-03 18:22:13 +00:00
|
|
|
gd->baudrate = env_get_ulong("baudrate", 10, CONFIG_BAUDRATE);
|
2013-03-11 06:49:53 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int display_text_info(void)
|
|
|
|
{
|
2015-07-31 15:31:37 +00:00
|
|
|
#if !defined(CONFIG_SANDBOX) && !defined(CONFIG_EFI_APP)
|
2014-11-15 22:46:53 +00:00
|
|
|
ulong bss_start, bss_end, text_base;
|
2013-03-11 06:49:53 +00:00
|
|
|
|
2013-03-11 07:06:48 +00:00
|
|
|
bss_start = (ulong)&__bss_start;
|
|
|
|
bss_end = (ulong)&__bss_end;
|
2014-02-22 16:53:43 +00:00
|
|
|
|
2022-10-21 00:22:39 +00:00
|
|
|
#ifdef CONFIG_TEXT_BASE
|
|
|
|
text_base = CONFIG_TEXT_BASE;
|
2014-07-17 11:01:34 +00:00
|
|
|
#else
|
2014-11-15 22:46:53 +00:00
|
|
|
text_base = CONFIG_SYS_MONITOR_BASE;
|
2014-07-17 11:01:34 +00:00
|
|
|
#endif
|
2014-11-15 22:46:53 +00:00
|
|
|
|
|
|
|
debug("U-Boot code: %08lX -> %08lX BSS: -> %08lX\n",
|
2018-01-15 10:10:02 +00:00
|
|
|
text_base, bss_start, bss_end);
|
2013-04-26 02:53:43 +00:00
|
|
|
#endif
|
2013-03-11 06:49:53 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-08-06 08:23:34 +00:00
|
|
|
#ifdef CONFIG_SYSRESET
|
|
|
|
static int print_resetinfo(void)
|
|
|
|
{
|
|
|
|
struct udevice *dev;
|
|
|
|
char status[256];
|
2022-10-10 18:29:40 +00:00
|
|
|
bool status_printed = false;
|
2018-08-06 08:23:34 +00:00
|
|
|
int ret;
|
|
|
|
|
2022-10-10 18:29:40 +00:00
|
|
|
/* Not all boards have sysreset drivers available during early
|
|
|
|
* boot, so don't fail if one can't be found.
|
|
|
|
*/
|
|
|
|
for (ret = uclass_first_device_check(UCLASS_SYSRESET, &dev); dev;
|
|
|
|
ret = uclass_next_device_check(&dev)) {
|
|
|
|
if (ret) {
|
|
|
|
debug("%s: %s sysreset device (error: %d)\n",
|
|
|
|
__func__, dev->name, ret);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!sysreset_get_status(dev, status, sizeof(status))) {
|
|
|
|
printf("%s%s", status_printed ? " " : "", status);
|
|
|
|
status_printed = true;
|
|
|
|
}
|
2018-08-06 08:23:34 +00:00
|
|
|
}
|
2022-10-10 18:29:40 +00:00
|
|
|
if (status_printed)
|
|
|
|
printf("\n");
|
2018-08-06 08:23:34 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-08-06 08:23:41 +00:00
|
|
|
#if defined(CONFIG_DISPLAY_CPUINFO) && CONFIG_IS_ENABLED(CPU)
|
|
|
|
static int print_cpuinfo(void)
|
|
|
|
{
|
|
|
|
struct udevice *dev;
|
|
|
|
char desc[512];
|
|
|
|
int ret;
|
|
|
|
|
2020-05-03 13:58:50 +00:00
|
|
|
dev = cpu_get_current_dev();
|
|
|
|
if (!dev) {
|
|
|
|
debug("%s: Could not get CPU device\n",
|
|
|
|
__func__);
|
|
|
|
return -ENODEV;
|
2018-08-06 08:23:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = cpu_get_desc(dev, desc, sizeof(desc));
|
|
|
|
if (ret) {
|
|
|
|
debug("%s: Could not get CPU description (err = %d)\n",
|
|
|
|
dev->name, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-10-11 05:06:55 +00:00
|
|
|
printf("CPU: %s\n", desc);
|
2018-08-06 08:23:41 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-03-11 06:49:53 +00:00
|
|
|
static int announce_dram_init(void)
|
|
|
|
{
|
|
|
|
puts("DRAM: ");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-09-18 11:23:27 +00:00
|
|
|
/*
|
|
|
|
* From input size calculate its nearest rounded unit scale (multiply of 2^10)
|
|
|
|
* and value in calculated unit scale multiplied by 10 (as fractional fixed
|
|
|
|
* point number with one decimal digit), which is human natural format,
|
|
|
|
* same what uses print_size() function for displaying. Mathematically it is:
|
|
|
|
* round_nearest(val * 2^scale) = size * 10; where: 10 <= val < 10240.
|
|
|
|
*
|
|
|
|
* For example for size=87654321 we calculate scale=20 and val=836 which means
|
|
|
|
* that input has natural human format 83.6 M (mega = 2^20).
|
|
|
|
*/
|
|
|
|
#define compute_size_scale_val(size, scale, val) do { \
|
|
|
|
scale = ilog2(size) / 10 * 10; \
|
|
|
|
val = (10 * size + ((1ULL << scale) >> 1)) >> scale; \
|
|
|
|
if (val == 10240) { val = 10; scale += 10; } \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if the sizes in their natural units written in decimal format with
|
|
|
|
* one fraction number are same.
|
|
|
|
*/
|
|
|
|
static int sizes_near(unsigned long long size1, unsigned long long size2)
|
|
|
|
{
|
|
|
|
unsigned int size1_scale, size1_val, size2_scale, size2_val;
|
|
|
|
|
|
|
|
compute_size_scale_val(size1, size1_scale, size1_val);
|
|
|
|
compute_size_scale_val(size2, size2_scale, size2_val);
|
|
|
|
|
|
|
|
return size1_scale == size2_scale && size1_val == size2_val;
|
|
|
|
}
|
|
|
|
|
2013-03-11 06:49:53 +00:00
|
|
|
static int show_dram_config(void)
|
|
|
|
{
|
2014-05-03 00:28:05 +00:00
|
|
|
unsigned long long size;
|
2013-03-11 06:49:53 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
debug("\nRAM Configuration:\n");
|
|
|
|
for (i = size = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
|
|
|
|
size += gd->bd->bi_dram[i].size;
|
2015-08-06 08:31:20 +00:00
|
|
|
debug("Bank #%d: %llx ", i,
|
|
|
|
(unsigned long long)(gd->bd->bi_dram[i].start));
|
2013-03-11 06:49:53 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
print_size(gd->bd->bi_dram[i].size, "\n");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
debug("\nDRAM: ");
|
|
|
|
|
2022-09-18 11:23:27 +00:00
|
|
|
print_size(gd->ram_size, "");
|
|
|
|
if (!sizes_near(gd->ram_size, size)) {
|
|
|
|
printf(" (effective ");
|
|
|
|
print_size(size, ")");
|
|
|
|
}
|
2013-03-11 14:30:42 +00:00
|
|
|
board_add_ram_info(0);
|
|
|
|
putc('\n');
|
2013-03-11 06:49:53 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-31 14:40:32 +00:00
|
|
|
__weak int dram_init_banksize(void)
|
2013-03-11 06:49:53 +00:00
|
|
|
{
|
2020-08-12 11:02:39 +00:00
|
|
|
gd->bd->bi_dram[0].start = gd->ram_base;
|
2013-03-11 06:49:53 +00:00
|
|
|
gd->bd->bi_dram[0].size = get_effective_memsize();
|
2017-03-31 14:40:32 +00:00
|
|
|
|
|
|
|
return 0;
|
2013-03-11 06:49:53 +00:00
|
|
|
}
|
|
|
|
|
2021-08-19 03:12:24 +00:00
|
|
|
#if CONFIG_IS_ENABLED(SYS_I2C_LEGACY)
|
2013-03-11 14:30:42 +00:00
|
|
|
static int init_func_i2c(void)
|
|
|
|
{
|
|
|
|
puts("I2C: ");
|
2013-09-21 16:13:34 +00:00
|
|
|
i2c_init_all();
|
2013-03-11 14:30:42 +00:00
|
|
|
puts("ready\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-01-17 10:43:08 +00:00
|
|
|
#if defined(CONFIG_VID)
|
|
|
|
__weak int init_func_vid(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-03-11 06:49:53 +00:00
|
|
|
static int setup_mon_len(void)
|
|
|
|
{
|
2014-05-08 14:08:44 +00:00
|
|
|
#if defined(__ARM__) || defined(__MICROBLAZE__)
|
2014-02-22 16:53:43 +00:00
|
|
|
gd->mon_len = (ulong)&__bss_end - (ulong)_start;
|
2021-05-19 10:02:39 +00:00
|
|
|
#elif defined(CONFIG_SANDBOX)
|
|
|
|
gd->mon_len = 0;
|
|
|
|
#elif defined(CONFIG_EFI_APP)
|
2013-04-26 02:53:43 +00:00
|
|
|
gd->mon_len = (ulong)&_end - (ulong)_init;
|
2017-03-14 15:08:10 +00:00
|
|
|
#elif defined(CONFIG_NIOS2) || defined(CONFIG_XTENSA)
|
2014-07-17 11:01:34 +00:00
|
|
|
gd->mon_len = CONFIG_SYS_MONITOR_LEN;
|
2022-04-06 13:21:25 +00:00
|
|
|
#elif defined(CONFIG_SH) || defined(CONFIG_RISCV)
|
2015-08-24 06:52:35 +00:00
|
|
|
gd->mon_len = (ulong)(&__bss_end) - (ulong)(&_start);
|
2016-05-15 00:49:28 +00:00
|
|
|
#elif defined(CONFIG_SYS_MONITOR_BASE)
|
2013-03-11 14:30:42 +00:00
|
|
|
/* TODO: use (ulong)&__bss_end - (ulong)&__text_start; ? */
|
|
|
|
gd->mon_len = (ulong)&__bss_end - CONFIG_SYS_MONITOR_BASE;
|
2013-03-11 07:06:48 +00:00
|
|
|
#endif
|
2013-03-11 06:49:53 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-11-16 01:44:09 +00:00
|
|
|
static int setup_spl_handoff(void)
|
|
|
|
{
|
|
|
|
#if CONFIG_IS_ENABLED(HANDOFF)
|
2022-01-13 02:26:17 +00:00
|
|
|
gd->spl_handoff = bloblist_find(BLOBLISTT_U_BOOT_SPL_HANDOFF,
|
2018-11-16 01:44:09 +00:00
|
|
|
sizeof(struct spl_handoff));
|
|
|
|
debug("Found SPL hand-off info %p\n", gd->spl_handoff);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-11 06:49:53 +00:00
|
|
|
__weak int arch_cpu_init(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-09-21 10:18:46 +00:00
|
|
|
__weak int mach_cpu_init(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-11 06:49:53 +00:00
|
|
|
/* Get the top of usable RAM */
|
2022-09-09 15:32:40 +00:00
|
|
|
__weak phys_size_t board_get_usable_ram_top(phys_size_t total_size)
|
2013-03-11 06:49:53 +00:00
|
|
|
{
|
2020-05-09 19:21:14 +00:00
|
|
|
#if defined(CONFIG_SYS_SDRAM_BASE) && CONFIG_SYS_SDRAM_BASE > 0
|
2014-12-23 17:34:49 +00:00
|
|
|
/*
|
2015-04-29 02:25:03 +00:00
|
|
|
* Detect whether we have so much RAM that it goes past the end of our
|
2014-12-23 17:34:49 +00:00
|
|
|
* 32-bit address space. If so, clip the usable RAM so it doesn't.
|
|
|
|
*/
|
|
|
|
if (gd->ram_top < CONFIG_SYS_SDRAM_BASE)
|
|
|
|
/*
|
|
|
|
* Will wrap back to top of 32-bit space when reservations
|
|
|
|
* are made.
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
#endif
|
2013-03-11 06:49:53 +00:00
|
|
|
return gd->ram_top;
|
|
|
|
}
|
|
|
|
|
2022-09-13 18:31:28 +00:00
|
|
|
__weak int arch_setup_dest_addr(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-11 06:49:53 +00:00
|
|
|
static int setup_dest_addr(void)
|
|
|
|
{
|
|
|
|
debug("Monitor len: %08lX\n", gd->mon_len);
|
|
|
|
/*
|
|
|
|
* Ram is setup, size stored in gd !!
|
|
|
|
*/
|
2022-09-09 15:32:41 +00:00
|
|
|
debug("Ram size: %08llX\n", (unsigned long long)gd->ram_size);
|
2022-04-06 14:33:32 +00:00
|
|
|
#if CONFIG_VAL(SYS_MEM_TOP_HIDE)
|
2013-03-11 06:49:53 +00:00
|
|
|
/*
|
|
|
|
* Subtract specified amount of memory to hide so that it won't
|
|
|
|
* get "touched" at all by U-Boot. By fixing up gd->ram_size
|
|
|
|
* the Linux kernel should now get passed the now "corrected"
|
2017-03-06 17:02:28 +00:00
|
|
|
* memory size and won't touch it either. This should work
|
|
|
|
* for arch/ppc and arch/powerpc. Only Linux board ports in
|
|
|
|
* arch/powerpc with bootwrapper support, that recalculate the
|
|
|
|
* memory size from the SDRAM controller setup will have to
|
|
|
|
* get fixed.
|
2013-03-11 06:49:53 +00:00
|
|
|
*/
|
2017-03-06 17:02:28 +00:00
|
|
|
gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE;
|
|
|
|
#endif
|
2013-03-11 06:49:53 +00:00
|
|
|
#ifdef CONFIG_SYS_SDRAM_BASE
|
2018-07-16 10:26:10 +00:00
|
|
|
gd->ram_base = CONFIG_SYS_SDRAM_BASE;
|
2013-03-11 06:49:53 +00:00
|
|
|
#endif
|
2018-07-16 10:26:10 +00:00
|
|
|
gd->ram_top = gd->ram_base + get_effective_memsize();
|
2013-03-11 06:49:53 +00:00
|
|
|
gd->ram_top = board_get_usable_ram_top(gd->mon_len);
|
2013-05-27 00:37:30 +00:00
|
|
|
gd->relocaddr = gd->ram_top;
|
2022-09-09 15:32:41 +00:00
|
|
|
debug("Ram top: %08llX\n", (unsigned long long)gd->ram_top);
|
2022-09-13 18:31:28 +00:00
|
|
|
|
|
|
|
return arch_setup_dest_addr();
|
2013-03-11 06:49:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_PRAM
|
|
|
|
/* reserve protected RAM */
|
|
|
|
static int reserve_pram(void)
|
|
|
|
{
|
|
|
|
ulong reg;
|
|
|
|
|
2017-08-03 18:22:13 +00:00
|
|
|
reg = env_get_ulong("pram", 10, CONFIG_PRAM);
|
2013-05-27 00:37:30 +00:00
|
|
|
gd->relocaddr -= (reg << 10); /* size is in kB */
|
2013-03-11 06:49:53 +00:00
|
|
|
debug("Reserving %ldk for protected RAM at %08lx\n", reg,
|
2013-05-27 00:37:30 +00:00
|
|
|
gd->relocaddr);
|
2013-03-11 06:49:53 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_PRAM */
|
|
|
|
|
|
|
|
/* Round memory pointer down to next 4 kB limit */
|
|
|
|
static int reserve_round_4k(void)
|
|
|
|
{
|
2013-05-27 00:37:30 +00:00
|
|
|
gd->relocaddr &= ~(4096 - 1);
|
2013-03-11 06:49:53 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-03-29 17:57:41 +00:00
|
|
|
__weak int arch_reserve_mmu(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-01-19 02:52:21 +00:00
|
|
|
static int reserve_video(void)
|
|
|
|
{
|
2022-10-18 13:46:31 +00:00
|
|
|
if (IS_ENABLED(CONFIG_VIDEO)) {
|
2022-10-16 21:57:41 +00:00
|
|
|
ulong addr;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
addr = gd->relocaddr;
|
|
|
|
ret = video_reserve(&addr);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
debug("Reserving %luk for video at: %08lx\n",
|
|
|
|
((unsigned long)gd->relocaddr - addr) >> 10, addr);
|
|
|
|
gd->relocaddr = addr;
|
|
|
|
}
|
2013-03-11 14:30:42 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-01-19 02:52:20 +00:00
|
|
|
static int reserve_trace(void)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_TRACE
|
|
|
|
gd->relocaddr -= CONFIG_TRACE_BUFFER_SIZE;
|
|
|
|
gd->trace_buff = map_sysmem(gd->relocaddr, CONFIG_TRACE_BUFFER_SIZE);
|
2019-06-14 19:52:22 +00:00
|
|
|
debug("Reserving %luk for trace data at: %08lx\n",
|
|
|
|
(unsigned long)CONFIG_TRACE_BUFFER_SIZE >> 10, gd->relocaddr);
|
2016-01-19 02:52:20 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-11 06:49:53 +00:00
|
|
|
static int reserve_uboot(void)
|
|
|
|
{
|
2018-05-25 13:08:14 +00:00
|
|
|
if (!(gd->flags & GD_FLG_SKIP_RELOC)) {
|
|
|
|
/*
|
|
|
|
* reserve memory for U-Boot code, data & bss
|
|
|
|
* round down to next 4 kB limit
|
|
|
|
*/
|
|
|
|
gd->relocaddr -= gd->mon_len;
|
|
|
|
gd->relocaddr &= ~(4096 - 1);
|
|
|
|
#if defined(CONFIG_E500) || defined(CONFIG_MIPS)
|
|
|
|
/* round down to next 64 kB limit so that IVPR stays aligned */
|
|
|
|
gd->relocaddr &= ~(65536 - 1);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
debug("Reserving %ldk for U-Boot at: %08lx\n",
|
|
|
|
gd->mon_len >> 10, gd->relocaddr);
|
|
|
|
}
|
2013-05-27 00:37:30 +00:00
|
|
|
|
|
|
|
gd->start_addr_sp = gd->relocaddr;
|
|
|
|
|
2013-03-11 06:49:53 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-03-10 09:15:05 +00:00
|
|
|
/*
|
|
|
|
* reserve after start_addr_sp the requested size and make the stack pointer
|
|
|
|
* 16-byte aligned, this alignment is needed for cast on the reserved memory
|
|
|
|
* ref = x86_64 ABI: https://reviews.llvm.org/D30049: 16 bytes
|
|
|
|
* = ARMv8 Instruction Set Overview: quad word, 16 bytes
|
|
|
|
*/
|
|
|
|
static unsigned long reserve_stack_aligned(size_t size)
|
|
|
|
{
|
|
|
|
return ALIGN_DOWN(gd->start_addr_sp - size, 16);
|
|
|
|
}
|
|
|
|
|
2019-08-16 16:57:44 +00:00
|
|
|
#ifdef CONFIG_SYS_NONCACHED_MEMORY
|
|
|
|
static int reserve_noncached(void)
|
|
|
|
{
|
2019-08-27 17:54:31 +00:00
|
|
|
/*
|
|
|
|
* The value of gd->start_addr_sp must match the value of malloc_start
|
2022-10-29 00:27:09 +00:00
|
|
|
* calculated in board_r.c:initr_malloc(), which is passed to
|
|
|
|
* dlmalloc.c:mem_malloc_init() and then used by
|
2019-08-27 17:54:31 +00:00
|
|
|
* cache.c:noncached_init()
|
|
|
|
*
|
|
|
|
* These calculations must match the code in cache.c:noncached_init()
|
|
|
|
*/
|
|
|
|
gd->start_addr_sp = ALIGN(gd->start_addr_sp, MMU_SECTION_SIZE) -
|
|
|
|
MMU_SECTION_SIZE;
|
|
|
|
gd->start_addr_sp -= ALIGN(CONFIG_SYS_NONCACHED_MEMORY,
|
|
|
|
MMU_SECTION_SIZE);
|
2019-08-16 16:57:44 +00:00
|
|
|
debug("Reserving %dM for noncached_alloc() at: %08lx\n",
|
|
|
|
CONFIG_SYS_NONCACHED_MEMORY >> 20, gd->start_addr_sp);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-03-11 06:49:53 +00:00
|
|
|
/* reserve memory for malloc() area */
|
|
|
|
static int reserve_malloc(void)
|
|
|
|
{
|
2020-03-10 09:15:05 +00:00
|
|
|
gd->start_addr_sp = reserve_stack_aligned(TOTAL_MALLOC_LEN);
|
2013-03-11 06:49:53 +00:00
|
|
|
debug("Reserving %dk for malloc() at: %08lx\n",
|
2018-01-15 10:10:02 +00:00
|
|
|
TOTAL_MALLOC_LEN >> 10, gd->start_addr_sp);
|
2019-08-16 16:57:44 +00:00
|
|
|
#ifdef CONFIG_SYS_NONCACHED_MEMORY
|
|
|
|
reserve_noncached();
|
|
|
|
#endif
|
|
|
|
|
2013-03-11 06:49:53 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (permanently) allocate a Board Info struct */
|
|
|
|
static int reserve_board(void)
|
|
|
|
{
|
2014-07-17 11:01:34 +00:00
|
|
|
if (!gd->bd) {
|
2020-06-26 06:13:33 +00:00
|
|
|
gd->start_addr_sp = reserve_stack_aligned(sizeof(struct bd_info));
|
|
|
|
gd->bd = (struct bd_info *)map_sysmem(gd->start_addr_sp,
|
|
|
|
sizeof(struct bd_info));
|
|
|
|
memset(gd->bd, '\0', sizeof(struct bd_info));
|
2014-07-17 11:01:34 +00:00
|
|
|
debug("Reserving %zu Bytes for Board Info at: %08lx\n",
|
2020-06-26 06:13:33 +00:00
|
|
|
sizeof(struct bd_info), gd->start_addr_sp);
|
2014-07-17 11:01:34 +00:00
|
|
|
}
|
2013-03-11 06:49:53 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int reserve_global_data(void)
|
|
|
|
{
|
2020-03-10 09:15:05 +00:00
|
|
|
gd->start_addr_sp = reserve_stack_aligned(sizeof(gd_t));
|
2013-05-27 00:37:30 +00:00
|
|
|
gd->new_gd = (gd_t *)map_sysmem(gd->start_addr_sp, sizeof(gd_t));
|
2013-03-11 06:49:53 +00:00
|
|
|
debug("Reserving %zu Bytes for Global Data at: %08lx\n",
|
2018-01-15 10:10:02 +00:00
|
|
|
sizeof(gd_t), gd->start_addr_sp);
|
2013-03-11 06:49:53 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int reserve_fdt(void)
|
|
|
|
{
|
2020-11-28 08:43:07 +00:00
|
|
|
if (!IS_ENABLED(CONFIG_OF_EMBED)) {
|
|
|
|
/*
|
|
|
|
* If the device tree is sitting immediately above our image
|
|
|
|
* then we must relocate it. If it is embedded in the data
|
|
|
|
* section, then it will be relocated with other data.
|
|
|
|
*/
|
|
|
|
if (gd->fdt_blob) {
|
|
|
|
gd->fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob), 32);
|
|
|
|
|
|
|
|
gd->start_addr_sp = reserve_stack_aligned(gd->fdt_size);
|
|
|
|
gd->new_fdt = map_sysmem(gd->start_addr_sp, gd->fdt_size);
|
|
|
|
debug("Reserving %lu Bytes for FDT at: %08lx\n",
|
|
|
|
gd->fdt_size, gd->start_addr_sp);
|
|
|
|
}
|
2013-03-11 06:49:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-05-22 11:05:30 +00:00
|
|
|
static int reserve_bootstage(void)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_BOOTSTAGE
|
|
|
|
int size = bootstage_get_size();
|
|
|
|
|
2020-03-10 09:15:05 +00:00
|
|
|
gd->start_addr_sp = reserve_stack_aligned(size);
|
2017-05-22 11:05:30 +00:00
|
|
|
gd->new_bootstage = map_sysmem(gd->start_addr_sp, size);
|
|
|
|
debug("Reserving %#x Bytes for bootstage at: %08lx\n", size,
|
|
|
|
gd->start_addr_sp);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-13 12:57:00 +00:00
|
|
|
__weak int arch_reserve_stacks(void)
|
2013-03-11 06:49:53 +00:00
|
|
|
{
|
2015-02-06 22:06:45 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2013-03-05 14:39:45 +00:00
|
|
|
|
2015-02-06 22:06:45 +00:00
|
|
|
static int reserve_stacks(void)
|
|
|
|
{
|
|
|
|
/* make stack pointer 16-byte aligned */
|
2020-03-10 09:15:05 +00:00
|
|
|
gd->start_addr_sp = reserve_stack_aligned(16);
|
2013-03-11 06:49:53 +00:00
|
|
|
|
|
|
|
/*
|
2015-04-29 02:25:03 +00:00
|
|
|
* let the architecture-specific code tailor gd->start_addr_sp and
|
2015-02-06 22:06:45 +00:00
|
|
|
* gd->irq_sp
|
2013-03-11 06:49:53 +00:00
|
|
|
*/
|
2015-02-06 22:06:45 +00:00
|
|
|
return arch_reserve_stacks();
|
2013-03-11 06:49:53 +00:00
|
|
|
}
|
|
|
|
|
2018-11-16 01:43:52 +00:00
|
|
|
static int reserve_bloblist(void)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_BLOBLIST
|
2020-09-28 00:46:18 +00:00
|
|
|
/* Align to a 4KB boundary for easier reading of addresses */
|
2021-01-14 03:29:43 +00:00
|
|
|
gd->start_addr_sp = ALIGN_DOWN(gd->start_addr_sp -
|
|
|
|
CONFIG_BLOBLIST_SIZE_RELOC, 0x1000);
|
|
|
|
gd->new_bloblist = map_sysmem(gd->start_addr_sp,
|
|
|
|
CONFIG_BLOBLIST_SIZE_RELOC);
|
2018-11-16 01:43:52 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-11 06:49:53 +00:00
|
|
|
static int display_new_sp(void)
|
|
|
|
{
|
2013-05-27 00:37:30 +00:00
|
|
|
debug("New Stack Pointer is: %08lx\n", gd->start_addr_sp);
|
2013-03-11 06:49:53 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-24 11:12:15 +00:00
|
|
|
__weak int arch_setup_bdinfo(void)
|
2020-07-24 11:12:14 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-24 11:12:15 +00:00
|
|
|
int setup_bdinfo(void)
|
|
|
|
{
|
2020-07-24 11:12:16 +00:00
|
|
|
struct bd_info *bd = gd->bd;
|
|
|
|
|
2020-07-24 11:12:17 +00:00
|
|
|
if (IS_ENABLED(CONFIG_SYS_HAS_SRAM)) {
|
|
|
|
bd->bi_sramstart = CONFIG_SYS_SRAM_BASE; /* start of SRAM */
|
|
|
|
bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE; /* size of SRAM */
|
|
|
|
}
|
|
|
|
|
2020-07-24 11:12:15 +00:00
|
|
|
return arch_setup_bdinfo();
|
|
|
|
}
|
|
|
|
|
2013-03-11 06:49:53 +00:00
|
|
|
#ifdef CONFIG_POST
|
|
|
|
static int init_post(void)
|
|
|
|
{
|
|
|
|
post_bootmode_init();
|
|
|
|
post_run(NULL, POST_ROM | post_bootmode_get(0));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int reloc_fdt(void)
|
|
|
|
{
|
2020-11-28 08:43:07 +00:00
|
|
|
if (!IS_ENABLED(CONFIG_OF_EMBED)) {
|
|
|
|
if (gd->flags & GD_FLG_SKIP_RELOC)
|
|
|
|
return 0;
|
|
|
|
if (gd->new_fdt) {
|
|
|
|
memcpy(gd->new_fdt, gd->fdt_blob,
|
|
|
|
fdt_totalsize(gd->fdt_blob));
|
|
|
|
gd->fdt_blob = gd->new_fdt;
|
|
|
|
}
|
2013-03-11 06:49:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-05-22 11:05:30 +00:00
|
|
|
static int reloc_bootstage(void)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_BOOTSTAGE
|
|
|
|
if (gd->flags & GD_FLG_SKIP_RELOC)
|
|
|
|
return 0;
|
|
|
|
if (gd->new_bootstage) {
|
|
|
|
int size = bootstage_get_size();
|
|
|
|
|
|
|
|
debug("Copying bootstage from %p to %p, size %x\n",
|
|
|
|
gd->bootstage, gd->new_bootstage, size);
|
|
|
|
memcpy(gd->new_bootstage, gd->bootstage, size);
|
|
|
|
gd->bootstage = gd->new_bootstage;
|
2019-10-21 23:26:50 +00:00
|
|
|
bootstage_relocate();
|
2017-05-22 11:05:30 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-11-16 01:43:52 +00:00
|
|
|
static int reloc_bloblist(void)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_BLOBLIST
|
2021-11-04 03:09:20 +00:00
|
|
|
/*
|
|
|
|
* Relocate only if we are supposed to send it
|
|
|
|
*/
|
|
|
|
if ((gd->flags & GD_FLG_SKIP_RELOC) &&
|
|
|
|
CONFIG_BLOBLIST_SIZE == CONFIG_BLOBLIST_SIZE_RELOC) {
|
|
|
|
debug("Not relocating bloblist\n");
|
2018-11-16 01:43:52 +00:00
|
|
|
return 0;
|
2021-11-04 03:09:20 +00:00
|
|
|
}
|
2018-11-16 01:43:52 +00:00
|
|
|
if (gd->new_bloblist) {
|
|
|
|
int size = CONFIG_BLOBLIST_SIZE;
|
|
|
|
|
|
|
|
debug("Copying bloblist from %p to %p, size %x\n",
|
|
|
|
gd->bloblist, gd->new_bloblist, size);
|
2021-01-14 03:29:43 +00:00
|
|
|
bloblist_reloc(gd->new_bloblist, CONFIG_BLOBLIST_SIZE_RELOC,
|
|
|
|
gd->bloblist, size);
|
2018-11-16 01:43:52 +00:00
|
|
|
gd->bloblist = gd->new_bloblist;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-11 06:49:53 +00:00
|
|
|
static int setup_reloc(void)
|
|
|
|
{
|
2021-11-13 17:34:04 +00:00
|
|
|
if (!(gd->flags & GD_FLG_SKIP_RELOC)) {
|
2022-10-21 00:22:39 +00:00
|
|
|
#ifdef CONFIG_TEXT_BASE
|
2017-06-08 08:18:25 +00:00
|
|
|
#ifdef ARM
|
2021-11-13 17:34:04 +00:00
|
|
|
gd->reloc_off = gd->relocaddr - (unsigned long)__image_copy_start;
|
2022-06-24 12:15:01 +00:00
|
|
|
#elif defined(CONFIG_MICROBLAZE)
|
|
|
|
gd->reloc_off = gd->relocaddr - (u32)_start;
|
2017-06-08 08:18:25 +00:00
|
|
|
#elif defined(CONFIG_M68K)
|
2021-11-13 17:34:04 +00:00
|
|
|
/*
|
|
|
|
* On all ColdFire arch cpu, monitor code starts always
|
|
|
|
* just after the default vector table location, so at 0x400
|
|
|
|
*/
|
2022-10-21 00:22:39 +00:00
|
|
|
gd->reloc_off = gd->relocaddr - (CONFIG_TEXT_BASE + 0x400);
|
2019-04-08 19:20:41 +00:00
|
|
|
#elif !defined(CONFIG_SANDBOX)
|
2022-10-21 00:22:39 +00:00
|
|
|
gd->reloc_off = gd->relocaddr - CONFIG_TEXT_BASE;
|
2015-02-12 00:40:17 +00:00
|
|
|
#endif
|
2014-07-17 11:01:34 +00:00
|
|
|
#endif
|
2021-11-13 17:34:04 +00:00
|
|
|
}
|
|
|
|
|
2013-03-11 06:49:53 +00:00
|
|
|
memcpy(gd->new_gd, (char *)gd, sizeof(gd_t));
|
|
|
|
|
2021-11-13 17:34:04 +00:00
|
|
|
if (gd->flags & GD_FLG_SKIP_RELOC) {
|
|
|
|
debug("Skipping relocation due to flag\n");
|
|
|
|
} else {
|
|
|
|
debug("Relocation Offset is: %08lx\n", gd->reloc_off);
|
|
|
|
debug("Relocating to %08lx, new gd at %08lx, sp at %08lx\n",
|
|
|
|
gd->relocaddr, (ulong)map_to_sysmem(gd->new_gd),
|
|
|
|
gd->start_addr_sp);
|
|
|
|
}
|
2013-03-11 06:49:53 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
dm: Add callback to modify the device tree
Certain boards come in different variations by way of utilizing daughter
boards, for example. These boards might contain additional chips, which
are added to the main board's busses, e.g. I2C.
The device tree support for such boards would either, quite naturally,
employ the overlay mechanism to add such chips to the tree, or would use
one large default device tree, and delete the devices that are actually
not present.
Regardless of approach, even on the U-Boot level, a modification of the
device tree is a prerequisite to have such modular families of boards
supported properly.
Therefore, we add an option to make the U-Boot device tree (the actual
copy later used by the driver model) writeable, and add a callback
method that allows boards to modify the device tree at an early stage,
at which, hopefully, also the application of device tree overlays will
be possible.
Signed-off-by: Mario Six <mario.six@gdsys.cc>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Stefan Roese <sr@denx.de>
2017-02-22 15:07:22 +00:00
|
|
|
#ifdef CONFIG_OF_BOARD_FIXUP
|
|
|
|
static int fix_fdt(void)
|
|
|
|
{
|
|
|
|
return board_fix_fdt((void *)gd->fdt_blob);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-03-11 06:49:53 +00:00
|
|
|
/* ARM calls relocate_code from its crt0.S */
|
2017-01-16 14:03:49 +00:00
|
|
|
#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
|
|
|
|
!CONFIG_IS_ENABLED(X86_64)
|
2013-03-11 06:49:53 +00:00
|
|
|
|
|
|
|
static int jump_to_copy(void)
|
|
|
|
{
|
2015-08-04 18:33:39 +00:00
|
|
|
if (gd->flags & GD_FLG_SKIP_RELOC)
|
|
|
|
return 0;
|
2013-03-05 14:39:52 +00:00
|
|
|
/*
|
|
|
|
* x86 is special, but in a nice way. It uses a trampoline which
|
|
|
|
* enables the dcache if possible.
|
|
|
|
*
|
|
|
|
* For now, other archs use relocate_code(), which is implemented
|
|
|
|
* similarly for all archs. When we do generic relocation, hopefully
|
|
|
|
* we can make all archs enable the dcache prior to relocation.
|
|
|
|
*/
|
2015-02-24 16:40:36 +00:00
|
|
|
#if defined(CONFIG_X86) || defined(CONFIG_ARC)
|
2013-03-05 14:39:52 +00:00
|
|
|
/*
|
|
|
|
* SDRAM and console are now initialised. The final stack can now
|
|
|
|
* be setup in SDRAM. Code execution will continue in Flash, but
|
|
|
|
* with the stack in SDRAM and Global Data in temporary memory
|
|
|
|
* (CPU cache)
|
|
|
|
*/
|
2015-08-11 02:44:32 +00:00
|
|
|
arch_setup_gd(gd->new_gd);
|
2013-03-05 14:39:52 +00:00
|
|
|
board_init_f_r_trampoline(gd->start_addr_sp);
|
|
|
|
#else
|
2013-05-27 00:37:30 +00:00
|
|
|
relocate_code(gd->start_addr_sp, gd->new_gd, gd->relocaddr);
|
2013-03-05 14:39:52 +00:00
|
|
|
#endif
|
2013-03-11 06:49:53 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Record the board_init_f() bootstage (after arch_cpu_init()) */
|
2017-05-22 11:05:25 +00:00
|
|
|
static int initf_bootstage(void)
|
2013-03-11 06:49:53 +00:00
|
|
|
{
|
2017-06-07 16:28:46 +00:00
|
|
|
bool from_spl = IS_ENABLED(CONFIG_SPL_BOOTSTAGE) &&
|
|
|
|
IS_ENABLED(CONFIG_BOOTSTAGE_STASH);
|
2017-05-22 11:05:25 +00:00
|
|
|
int ret;
|
|
|
|
|
2017-05-22 11:05:35 +00:00
|
|
|
ret = bootstage_init(!from_spl);
|
2017-05-22 11:05:25 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2017-05-22 11:05:35 +00:00
|
|
|
if (from_spl) {
|
|
|
|
const void *stash = map_sysmem(CONFIG_BOOTSTAGE_STASH_ADDR,
|
|
|
|
CONFIG_BOOTSTAGE_STASH_SIZE);
|
|
|
|
|
|
|
|
ret = bootstage_unstash(stash, CONFIG_BOOTSTAGE_STASH_SIZE);
|
|
|
|
if (ret && ret != -ENOENT) {
|
|
|
|
debug("Failed to unstash bootstage: err=%d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
2017-05-22 11:05:25 +00:00
|
|
|
|
2013-03-11 06:49:53 +00:00
|
|
|
bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_F, "board_init_f");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-07-23 12:55:04 +00:00
|
|
|
static int initf_dm(void)
|
|
|
|
{
|
2017-07-24 09:43:34 +00:00
|
|
|
#if defined(CONFIG_DM) && CONFIG_VAL(SYS_MALLOC_F_LEN)
|
2014-07-23 12:55:04 +00:00
|
|
|
int ret;
|
|
|
|
|
2020-05-10 17:39:59 +00:00
|
|
|
bootstage_start(BOOTSTAGE_ID_ACCUM_DM_F, "dm_f");
|
2014-07-23 12:55:04 +00:00
|
|
|
ret = dm_init_and_scan(true);
|
2020-05-10 17:39:59 +00:00
|
|
|
bootstage_accum(BOOTSTAGE_ID_ACCUM_DM_F);
|
2014-07-23 12:55:04 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2020-11-28 08:43:05 +00:00
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_TIMER_EARLY)) {
|
|
|
|
ret = dm_timer_init();
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
2016-02-24 16:14:50 +00:00
|
|
|
#endif
|
2014-07-23 12:55:04 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-01-20 05:16:12 +00:00
|
|
|
/* Architecture-specific memory reservation */
|
|
|
|
__weak int reserve_arch(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-01-22 20:28:25 +00:00
|
|
|
__weak int checkcpu(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-02-05 06:54:42 +00:00
|
|
|
__weak int clear_bss(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-03-04 15:43:04 +00:00
|
|
|
static int misc_init_f(void)
|
|
|
|
{
|
|
|
|
return event_notify_null(EVT_MISC_INIT_F);
|
|
|
|
}
|
|
|
|
|
2017-01-16 14:03:50 +00:00
|
|
|
static const init_fnc_t init_sequence_f[] = {
|
2013-03-11 06:49:53 +00:00
|
|
|
setup_mon_len,
|
2015-02-28 05:06:34 +00:00
|
|
|
#ifdef CONFIG_OF_CONTROL
|
2015-02-28 05:06:35 +00:00
|
|
|
fdtdec_setup,
|
2015-02-28 05:06:34 +00:00
|
|
|
#endif
|
2019-06-01 22:53:24 +00:00
|
|
|
#ifdef CONFIG_TRACE_EARLY
|
2013-06-11 18:14:42 +00:00
|
|
|
trace_early_init,
|
2014-12-09 23:03:58 +00:00
|
|
|
#endif
|
2014-11-11 01:00:18 +00:00
|
|
|
initf_malloc,
|
2017-12-04 20:48:28 +00:00
|
|
|
log_init,
|
2017-05-22 11:05:31 +00:00
|
|
|
initf_bootstage, /* uses its own timer, so does not need DM */
|
2022-03-04 15:43:02 +00:00
|
|
|
event_init,
|
2018-11-16 01:43:52 +00:00
|
|
|
#ifdef CONFIG_BLOBLIST
|
|
|
|
bloblist_init,
|
|
|
|
#endif
|
2018-11-16 01:44:09 +00:00
|
|
|
setup_spl_handoff,
|
2020-11-28 08:43:04 +00:00
|
|
|
#if defined(CONFIG_CONSOLE_RECORD_INIT_F)
|
|
|
|
console_record_init,
|
|
|
|
#endif
|
2017-03-28 16:27:18 +00:00
|
|
|
#if defined(CONFIG_HAVE_FSP)
|
|
|
|
arch_fsp_init,
|
2013-03-11 14:30:42 +00:00
|
|
|
#endif
|
2013-03-11 06:49:53 +00:00
|
|
|
arch_cpu_init, /* basic arch cpu dependent setup */
|
2016-09-21 10:18:46 +00:00
|
|
|
mach_cpu_init, /* SoC/machine dependent CPU setup */
|
2014-09-03 23:36:59 +00:00
|
|
|
initf_dm,
|
2013-03-11 06:49:53 +00:00
|
|
|
#if defined(CONFIG_BOARD_EARLY_INIT_F)
|
|
|
|
board_early_init_f,
|
|
|
|
#endif
|
2017-03-28 16:27:26 +00:00
|
|
|
#if defined(CONFIG_PPC) || defined(CONFIG_SYS_FSL_CLK) || defined(CONFIG_M68K)
|
2017-03-28 16:27:19 +00:00
|
|
|
/* get CPU and bus clocks according to the environment variable */
|
2013-03-11 14:30:42 +00:00
|
|
|
get_clocks, /* get CPU and bus clocks (etc.) */
|
2017-03-28 16:27:23 +00:00
|
|
|
#endif
|
2017-05-10 21:58:06 +00:00
|
|
|
#if !defined(CONFIG_M68K)
|
2013-03-11 06:49:53 +00:00
|
|
|
timer_init, /* initialize timer */
|
2017-05-10 21:58:06 +00:00
|
|
|
#endif
|
2013-03-11 14:30:42 +00:00
|
|
|
#if defined(CONFIG_BOARD_POSTCLK_INIT)
|
|
|
|
board_postclk_init,
|
2013-03-11 06:49:53 +00:00
|
|
|
#endif
|
|
|
|
env_init, /* initialize environment */
|
|
|
|
init_baud_rate, /* initialze baudrate settings */
|
|
|
|
serial_init, /* serial communications setup */
|
|
|
|
console_init_f, /* stage 1 init of console */
|
|
|
|
display_options, /* say that we are here */
|
|
|
|
display_text_info, /* show debugging info if required */
|
2013-03-11 14:30:42 +00:00
|
|
|
checkcpu,
|
2018-08-06 08:23:34 +00:00
|
|
|
#if defined(CONFIG_SYSRESET)
|
|
|
|
print_resetinfo,
|
|
|
|
#endif
|
2017-01-23 20:31:25 +00:00
|
|
|
#if defined(CONFIG_DISPLAY_CPUINFO)
|
2013-03-11 06:49:53 +00:00
|
|
|
print_cpuinfo, /* display cpu info (and speed) */
|
2017-01-23 20:31:25 +00:00
|
|
|
#endif
|
2017-06-16 22:25:12 +00:00
|
|
|
#if defined(CONFIG_DTB_RESELECT)
|
|
|
|
embedded_dtb_select,
|
|
|
|
#endif
|
2013-03-11 06:49:53 +00:00
|
|
|
#if defined(CONFIG_DISPLAY_BOARDINFO)
|
2015-01-14 08:07:05 +00:00
|
|
|
show_board_info,
|
2013-03-11 14:30:42 +00:00
|
|
|
#endif
|
|
|
|
INIT_FUNC_WATCHDOG_INIT
|
|
|
|
misc_init_f,
|
|
|
|
INIT_FUNC_WATCHDOG_RESET
|
2021-08-19 03:12:24 +00:00
|
|
|
#if CONFIG_IS_ENABLED(SYS_I2C_LEGACY)
|
2013-03-11 14:30:42 +00:00
|
|
|
init_func_i2c,
|
|
|
|
#endif
|
2018-01-17 10:43:08 +00:00
|
|
|
#if defined(CONFIG_VID) && !defined(CONFIG_SPL)
|
|
|
|
init_func_vid,
|
2013-03-11 06:49:53 +00:00
|
|
|
#endif
|
|
|
|
announce_dram_init,
|
|
|
|
dram_init, /* configure available RAM banks */
|
2013-03-11 14:30:42 +00:00
|
|
|
#ifdef CONFIG_POST
|
|
|
|
post_init_f,
|
|
|
|
#endif
|
|
|
|
INIT_FUNC_WATCHDOG_RESET
|
|
|
|
#if defined(CONFIG_SYS_DRAM_TEST)
|
|
|
|
testdram,
|
|
|
|
#endif /* CONFIG_SYS_DRAM_TEST */
|
|
|
|
INIT_FUNC_WATCHDOG_RESET
|
|
|
|
|
2013-03-11 06:49:53 +00:00
|
|
|
#ifdef CONFIG_POST
|
|
|
|
init_post,
|
|
|
|
#endif
|
2013-03-11 14:30:42 +00:00
|
|
|
INIT_FUNC_WATCHDOG_RESET
|
2013-03-11 06:49:53 +00:00
|
|
|
/*
|
|
|
|
* Now that we have DRAM mapped and working, we can
|
|
|
|
* relocate the code and continue running from DRAM.
|
|
|
|
*
|
|
|
|
* Reserve memory at end of RAM for (top down in that order):
|
|
|
|
* - area that won't get touched by U-Boot and Linux (optional)
|
|
|
|
* - kernel log buffer
|
|
|
|
* - protected RAM
|
|
|
|
* - LCD framebuffer
|
|
|
|
* - monitor code
|
|
|
|
* - board info struct
|
|
|
|
*/
|
|
|
|
setup_dest_addr,
|
2020-08-13 04:42:26 +00:00
|
|
|
#ifdef CONFIG_OF_BOARD_FIXUP
|
|
|
|
fix_fdt,
|
|
|
|
#endif
|
2013-03-11 06:49:53 +00:00
|
|
|
#ifdef CONFIG_PRAM
|
|
|
|
reserve_pram,
|
|
|
|
#endif
|
|
|
|
reserve_round_4k,
|
2020-03-29 17:57:41 +00:00
|
|
|
arch_reserve_mmu,
|
2016-01-19 02:52:21 +00:00
|
|
|
reserve_video,
|
2016-01-19 02:52:20 +00:00
|
|
|
reserve_trace,
|
2013-03-11 06:49:53 +00:00
|
|
|
reserve_uboot,
|
|
|
|
reserve_malloc,
|
|
|
|
reserve_board,
|
|
|
|
reserve_global_data,
|
|
|
|
reserve_fdt,
|
2017-05-22 11:05:30 +00:00
|
|
|
reserve_bootstage,
|
2018-11-16 01:43:52 +00:00
|
|
|
reserve_bloblist,
|
2015-01-20 05:16:12 +00:00
|
|
|
reserve_arch,
|
2013-03-11 06:49:53 +00:00
|
|
|
reserve_stacks,
|
2017-03-31 14:40:32 +00:00
|
|
|
dram_init_banksize,
|
2013-03-11 06:49:53 +00:00
|
|
|
show_dram_config,
|
2013-03-11 14:30:42 +00:00
|
|
|
INIT_FUNC_WATCHDOG_RESET
|
2020-07-24 11:12:20 +00:00
|
|
|
setup_bdinfo,
|
2013-03-11 06:49:53 +00:00
|
|
|
display_new_sp,
|
2013-03-11 14:30:42 +00:00
|
|
|
INIT_FUNC_WATCHDOG_RESET
|
2013-03-11 06:49:53 +00:00
|
|
|
reloc_fdt,
|
2017-05-22 11:05:30 +00:00
|
|
|
reloc_bootstage,
|
2018-11-16 01:43:52 +00:00
|
|
|
reloc_bloblist,
|
2013-03-11 06:49:53 +00:00
|
|
|
setup_reloc,
|
2015-02-24 16:40:36 +00:00
|
|
|
#if defined(CONFIG_X86) || defined(CONFIG_ARC)
|
2015-01-01 23:18:09 +00:00
|
|
|
copy_uboot_to_ram,
|
|
|
|
do_elf_reloc_fixups,
|
|
|
|
#endif
|
2016-08-10 15:36:43 +00:00
|
|
|
clear_bss,
|
cyclic: get rid of cyclic_init()
Currently, we must call cyclic_init() at some point before
cyclic_register() becomes possible. That turns out to be somewhat
awkward, especially with SPL, and has resulted in a watchdog callback
not being registered, thus causing the board to prematurely reset.
We already rely on gd->cyclic reliably being set to NULL by the asm
code that clears all of gd. Now that the cyclic list is a hlist, and
thus an empty list is represented by a NULL head pointer, and struct
cyclic_drv has no other members, we can just as well drop a level of
indirection and put the hlist_head directly in struct
global_data. This doesn't increase the size of struct global_data,
gets rid of an early malloc(), and generates slightly smaller code.
But primarily, this avoids having to call cyclic_init() early; the cyclic
infrastructure is simply ready to register callbacks as soon as we
enter C code.
We can still end up with schedule() being called from asm very early,
so we still need to check that gd itself has been properly initialized
[*], but once it has, gd->cyclic_list is perfectly fine to access, and
will just be an empty list.
As for cyclic_uninit(), it was never really the opposite of
cyclic_init() since it didn't free the struct cyclic_drv nor set
gd->cyclic to NULL. Rename it to cyclic_unregister_all() and use that
in test/, and also insert a call at the end of the board_init_f
sequence so that gd->cyclic_list is a fresh empty list before we enter
board_init_r().
A small piece of ugliness is that I had to add a cast in
cyclic_get_list() to silence a "discards 'volatile' qualifier"
warning, but that is completely equivalent to the existing handling of
the uclass_root_s list_head member.
[*] I'm not really sure where we guarantee that the register used for
gd contains 0 until it gets explicitly initialized, but that must be
the case, otherwise testing gd for being NULL would not make much sense.
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Reviewed-by: Stefan Roese <sr@denx.de>
Tested-by: Stefan Roese <sr@denx.de>
Tested-by: Tim Harvey <tharvey@gateworks.com> # imx8mm-venice-*
2022-10-28 11:50:54 +00:00
|
|
|
/*
|
|
|
|
* Deregister all cyclic functions before relocation, so that
|
|
|
|
* gd->cyclic_list does not contain any references to pre-relocation
|
|
|
|
* devices. Drivers will register their cyclic functions anew when the
|
|
|
|
* devices are probed again.
|
|
|
|
*
|
|
|
|
* This should happen as late as possible so that the window where a
|
|
|
|
* watchdog device is not serviced is as small as possible.
|
|
|
|
*/
|
|
|
|
cyclic_unregister_all,
|
2017-01-16 14:03:49 +00:00
|
|
|
#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
|
|
|
|
!CONFIG_IS_ENABLED(X86_64)
|
2013-03-11 06:49:53 +00:00
|
|
|
jump_to_copy,
|
|
|
|
#endif
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
void board_init_f(ulong boot_flags)
|
|
|
|
{
|
|
|
|
gd->flags = boot_flags;
|
2013-11-27 18:32:40 +00:00
|
|
|
gd->have_console = 0;
|
2013-03-11 06:49:53 +00:00
|
|
|
|
|
|
|
if (initcall_run_list(init_sequence_f))
|
|
|
|
hang();
|
|
|
|
|
2015-07-31 15:31:37 +00:00
|
|
|
#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
|
2015-12-16 16:24:10 +00:00
|
|
|
!defined(CONFIG_EFI_APP) && !CONFIG_IS_ENABLED(X86_64) && \
|
|
|
|
!defined(CONFIG_ARC)
|
2013-03-11 06:49:53 +00:00
|
|
|
/* NOTREACHED - jump_to_copy() does not return */
|
|
|
|
hang();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-02-24 16:40:36 +00:00
|
|
|
#if defined(CONFIG_X86) || defined(CONFIG_ARC)
|
2013-03-05 14:39:52 +00:00
|
|
|
/*
|
|
|
|
* For now this code is only used on x86.
|
|
|
|
*
|
|
|
|
* init_sequence_f_r is the list of init functions which are run when
|
|
|
|
* U-Boot is executing from Flash with a semi-limited 'C' environment.
|
|
|
|
* The following limitations must be considered when implementing an
|
|
|
|
* '_f_r' function:
|
|
|
|
* - 'static' variables are read-only
|
|
|
|
* - Global Data (gd->xxx) is read/write
|
|
|
|
*
|
|
|
|
* The '_f_r' sequence must, as a minimum, copy U-Boot to RAM (if
|
|
|
|
* supported). It _should_, if possible, copy global data to RAM and
|
|
|
|
* initialise the CPU caches (to speed up the relocation process)
|
|
|
|
*
|
|
|
|
* NOTE: At present only x86 uses this route, but it is intended that
|
|
|
|
* all archs will move to this when generic relocation is implemented.
|
|
|
|
*/
|
2017-01-16 14:03:50 +00:00
|
|
|
static const init_fnc_t init_sequence_f_r[] = {
|
2017-01-16 14:03:49 +00:00
|
|
|
#if !CONFIG_IS_ENABLED(X86_64)
|
2013-03-05 14:39:52 +00:00
|
|
|
init_cache_f_r,
|
2017-01-16 14:03:49 +00:00
|
|
|
#endif
|
2013-03-05 14:39:52 +00:00
|
|
|
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
void board_init_f_r(void)
|
|
|
|
{
|
|
|
|
if (initcall_run_list(init_sequence_f_r))
|
|
|
|
hang();
|
|
|
|
|
2016-03-12 05:06:51 +00:00
|
|
|
/*
|
|
|
|
* The pre-relocation drivers may be using memory that has now gone
|
|
|
|
* away. Mark serial as unavailable - this will fall back to the debug
|
|
|
|
* UART if available.
|
2017-12-04 20:48:28 +00:00
|
|
|
*
|
|
|
|
* Do the same with log drivers since the memory may not be available.
|
2016-03-12 05:06:51 +00:00
|
|
|
*/
|
2017-12-04 20:48:28 +00:00
|
|
|
gd->flags &= ~(GD_FLG_SERIAL_READY | GD_FLG_LOG_READY);
|
2017-09-06 01:49:45 +00:00
|
|
|
#ifdef CONFIG_TIMER
|
|
|
|
gd->timer = NULL;
|
|
|
|
#endif
|
2016-03-12 05:06:51 +00:00
|
|
|
|
2013-03-05 14:39:52 +00:00
|
|
|
/*
|
|
|
|
* U-Boot has been copied into SDRAM, the BSS has been cleared etc.
|
|
|
|
* Transfer execution from Flash to RAM by calculating the address
|
|
|
|
* of the in-RAM copy of board_init_r() and calling it
|
|
|
|
*/
|
2015-02-25 14:59:02 +00:00
|
|
|
(board_init_r + gd->reloc_off)((gd_t *)gd, gd->relocaddr);
|
2013-03-05 14:39:52 +00:00
|
|
|
|
|
|
|
/* NOTREACHED - board_init_r() does not return */
|
|
|
|
hang();
|
|
|
|
}
|
2015-03-24 08:12:47 +00:00
|
|
|
#endif /* CONFIG_X86 */
|