3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
12 #include <stdio_dev.h>
15 #include <environment.h>
17 #include <onenand_uboot.h>
20 #ifdef CONFIG_BITBANGMII
24 DECLARE_GLOBAL_DATA_PTR;
26 ulong monitor_flash_len;
28 static char *failed = "*** failed ***\n";
31 * mips_io_port_base is the begin of the address space to which x86 style
32 * I/O ports are mapped.
34 const unsigned long mips_io_port_base = -1;
36 int __board_early_init_f(void)
39 * Nothing to do in this dummy implementation
43 int board_early_init_f(void)
44 __attribute__((weak, alias("__board_early_init_f")));
46 static int init_func_ram(void)
48 #ifdef CONFIG_BOARD_TYPES
49 int board_type = gd->board_type;
51 int board_type = 0; /* use dummy arg */
55 gd->ram_size = initdram(board_type);
56 if (gd->ram_size > 0) {
57 print_size(gd->ram_size, "\n");
64 static int display_banner(void)
67 printf("\n\n%s\n\n", version_string);
71 #ifndef CONFIG_SYS_NO_FLASH
72 static void display_flash_config(ulong size)
75 print_size(size, "\n");
79 static int init_baudrate(void)
81 gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE);
87 * Breath some life into the board...
89 * The first part of initialization is running from Flash memory;
90 * its main purpose is to initialize the RAM so that we
91 * can relocate the monitor code to RAM.
95 * All attempts to come up with a "common" initialization sequence
96 * that works for all boards and architectures failed: some of the
97 * requirements are just _too_ different. To get rid of the resulting
98 * mess of board dependend #ifdef'ed code we now make the whole
99 * initialization sequence configurable to the user.
101 * The requirements for any new initalization function is simple: it
102 * receives a pointer to the "global data" structure as it's only
103 * argument, and returns an integer return code, where 0 means
104 * "continue" and != 0 means "fatal error, hang the system".
106 typedef int (init_fnc_t)(void);
108 init_fnc_t *init_sequence[] = {
111 env_init, /* initialize environment */
112 #ifdef CONFIG_INCA_IP
113 incaip_set_cpuclk, /* set cpu clock according to env. variable */
115 init_baudrate, /* initialize baudrate settings */
116 serial_init, /* serial communications setup */
118 display_banner, /* say that we are here */
125 void board_init_f(ulong bootflag)
129 init_fnc_t **init_fnc_ptr;
130 ulong addr, addr_sp, len;
133 /* Pointer is writable since we allocated a register for it.
136 /* compiler optimization barrier needed for GCC >= 3.4 */
137 __asm__ __volatile__("" : : : "memory");
139 memset((void *)gd, 0, sizeof(gd_t));
141 for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
142 if ((*init_fnc_ptr)() != 0)
147 * Now that we have DRAM mapped and working, we can
148 * relocate the code and continue running from DRAM.
150 addr = CONFIG_SYS_SDRAM_BASE + gd->ram_size;
152 /* We can reserve some RAM "on top" here.
155 /* round down to next 4 kB limit.
158 debug("Top of RAM usable for U-Boot at: %08lx\n", addr);
160 /* Reserve memory for U-Boot code, data & bss
161 * round down to next 16 kB limit
163 len = bss_end() - CONFIG_SYS_MONITOR_BASE;
165 addr &= ~(16 * 1024 - 1);
167 debug("Reserving %ldk for U-Boot at: %08lx\n", len >> 10, addr);
169 /* Reserve memory for malloc() arena.
171 addr_sp = addr - TOTAL_MALLOC_LEN;
172 debug("Reserving %dk for malloc() at: %08lx\n",
173 TOTAL_MALLOC_LEN >> 10, addr_sp);
176 * (permanently) allocate a Board Info struct
177 * and a permanent copy of the "global" data
179 addr_sp -= sizeof(bd_t);
180 bd = (bd_t *)addr_sp;
182 debug("Reserving %zu Bytes for Board Info at: %08lx\n",
183 sizeof(bd_t), addr_sp);
185 addr_sp -= sizeof(gd_t);
186 id = (gd_t *)addr_sp;
187 debug("Reserving %zu Bytes for Global Data at: %08lx\n",
188 sizeof(gd_t), addr_sp);
190 /* Reserve memory for boot params.
192 addr_sp -= CONFIG_SYS_BOOTPARAMS_LEN;
193 bd->bi_boot_params = addr_sp;
194 debug("Reserving %dk for boot params() at: %08lx\n",
195 CONFIG_SYS_BOOTPARAMS_LEN >> 10, addr_sp);
198 * Finally, we set up a new (bigger) stack.
200 * Leave some safety gap for SP, force alignment on 16 byte boundary
201 * Clear initial stack frame
205 s = (ulong *)addr_sp;
209 debug("Stack Pointer at: %08lx\n", addr_sp);
212 * Save local variables to board info struct
214 bd->bi_memstart = CONFIG_SYS_SDRAM_BASE; /* start of DRAM */
215 bd->bi_memsize = gd->ram_size; /* size of DRAM in bytes */
216 bd->bi_baudrate = gd->baudrate; /* Console Baudrate */
218 memcpy(id, (void *)gd, sizeof(gd_t));
220 relocate_code(addr_sp, id, addr);
222 /* NOTREACHED - relocate_code() does not return */
226 * This is the next part if the initialization sequence: we are now
227 * running from RAM and have a "normal" C environment, i. e. global
228 * data can be written, BSS has been cleared, the stack size in not
229 * that critical any more, etc.
232 void board_init_r(gd_t *id, ulong dest_addr)
234 #ifndef CONFIG_SYS_NO_FLASH
240 gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
242 debug("Now running in RAM - U-Boot at: %08lx\n", dest_addr);
244 gd->reloc_off = dest_addr - CONFIG_SYS_MONITOR_BASE;
246 monitor_flash_len = image_copy_end() - dest_addr;
252 /* The Malloc area is immediately below the monitor copy in DRAM */
253 mem_malloc_init(CONFIG_SYS_MONITOR_BASE + gd->reloc_off -
254 TOTAL_MALLOC_LEN, TOTAL_MALLOC_LEN);
256 #ifndef CONFIG_SYS_NO_FLASH
257 /* configure available FLASH banks */
259 display_flash_config(size);
260 bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
261 bd->bi_flashsize = size;
263 #if CONFIG_SYS_MONITOR_BASE == CONFIG_SYS_FLASH_BASE
264 bd->bi_flashoffset = monitor_flash_len; /* reserved area for U-Boot */
266 bd->bi_flashoffset = 0;
269 bd->bi_flashstart = 0;
270 bd->bi_flashsize = 0;
271 bd->bi_flashoffset = 0;
274 #ifdef CONFIG_CMD_NAND
276 nand_init(); /* go init the NAND */
279 #if defined(CONFIG_CMD_ONENAND)
283 /* relocate environment function pointers etc. */
286 #if defined(CONFIG_PCI)
288 * Do pci configuration
293 /** leave this here (after malloc(), environment and PCI are working) **/
294 /* Initialize stdio devices */
299 /* Initialize the console (after the relocation and devices init) */
301 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/
303 /* Initialize from environment */
304 load_addr = getenv_ulong("loadaddr", 16, load_addr);
306 #ifdef CONFIG_CMD_SPI
308 spi_init(); /* go init the SPI */
312 #if defined(CONFIG_MISC_INIT_R)
313 /* miscellaneous platform dependent initialisations */
317 #ifdef CONFIG_BITBANGMII
320 #if defined(CONFIG_CMD_NET)
322 eth_initialize(gd->bd);
325 /* main_loop() can return to retry autoboot, if so just run it again. */
329 /* NOTREACHED - no way out of command loop except booting */