blob: 46a644908e9d0f46c9016fcb970a149362d5b34b [file] [log] [blame]
Giulio Benetti6986d6b2020-01-10 15:51:48 +01001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2019
4 * Author(s): Giulio Benetti <giulio.benetti@benettiengineering.com>
5 */
6
Giulio Benetti6986d6b2020-01-10 15:51:48 +01007#include <dm.h>
Simon Glass97589732020-05-10 11:40:02 -06008#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -06009#include <log.h>
Giulio Benetti6986d6b2020-01-10 15:51:48 +010010#include <ram.h>
11#include <spl.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060012#include <asm/global_data.h>
Giulio Benetti6986d6b2020-01-10 15:51:48 +010013#include <asm/io.h>
14#include <asm/armv7m.h>
Jesse Taube97826632022-03-17 14:33:21 -040015#include <serial.h>
Giulio Benetti6986d6b2020-01-10 15:51:48 +010016
17DECLARE_GLOBAL_DATA_PTR;
18
19int dram_init(void)
20{
21#ifndef CONFIG_SUPPORT_SPL
22 int rv;
23 struct udevice *dev;
24
25 rv = uclass_get_device(UCLASS_RAM, 0, &dev);
26 if (rv) {
27 debug("DRAM init failed: %d\n", rv);
28 return rv;
29 }
30
31#endif
32 return fdtdec_setup_mem_size_base();
33}
34
35int dram_init_banksize(void)
36{
37 return fdtdec_setup_memory_banksize();
38}
39
40#ifdef CONFIG_SPL_BUILD
41#ifdef CONFIG_SPL_OS_BOOT
42int spl_start_uboot(void)
43{
44 debug("SPL: booting kernel\n");
45 /* break into full u-boot on 'c' */
46 return serial_tstc() && serial_getc() == 'c';
47}
48#endif
49
50int spl_dram_init(void)
51{
52 struct udevice *dev;
53 int rv;
54
55 rv = uclass_get_device(UCLASS_RAM, 0, &dev);
56 if (rv)
57 debug("DRAM init failed: %d\n", rv);
58 return rv;
59}
60
61void spl_board_init(void)
62{
Giulio Benetti6986d6b2020-01-10 15:51:48 +010063 preloader_console_init();
Giulio Benetti79fef472021-04-04 20:21:34 +020064 spl_dram_init();
Giulio Benetti6986d6b2020-01-10 15:51:48 +010065 arch_cpu_init(); /* to configure mpu for sdram rw permissions */
66}
67
68u32 spl_boot_device(void)
69{
Jesse Taube9fcbb552024-02-19 18:00:59 -050070 /* There is no way to find the boot device so look if there is a valid IVT in RAM for MMC */
71 u32 nor_ivt = *(u32 *)(CONFIG_SYS_LOAD_ADDR - 0xC00);
72
73 if (nor_ivt == 0x402000d1)
74 return BOOT_DEVICE_MMC1;
75 return BOOT_DEVICE_NOR;
Giulio Benetti6986d6b2020-01-10 15:51:48 +010076}
77#endif
78
Giulio Benetti6986d6b2020-01-10 15:51:48 +010079int board_init(void)
80{
81 gd->bd->bi_boot_params = gd->bd->bi_dram[0].start + 0x100;
82
83 return 0;
84}