blob: 6a2f57709cb3eda045a9a53da30bf393e5986a27 [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001/*
2 * (C) Copyright 2016, ZIXC Corporation.
3 *
4 * (C) Copyright 2002-2006
5 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
6 *
7 * (C) Copyright 2002
8 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
9 * Marius Groeger <mgroeger@sysgo.de>
10 *
11 */
12#include <common.h>
13#include <command.h>
14#include <malloc.h>
15#include <stdio_dev.h>
16#include <version.h>
17#include <net.h>
18#include <serial.h>
19#include <nand.h>
20#include <onenand_uboot.h>
21#include <mmc.h>
22#include <timer.h>
23#include <asm/arch/lsp_crpm.h>
24#include <asm/arch/cpu.h>
25#include <config.h>
26#include <drvs_gpio.h>
27
28DECLARE_GLOBAL_DATA_PTR;
29
30ulong monitor_flash_len;
31
32#if defined(CONFIG_HARD_I2C) || \
33 defined(CONFIG_SOFT_I2C)
34#include <i2c.h>
35#endif
36
37/*
38 ************************************************************************
39 * Init Utilities *
40 ************************************************************************
41 * Some of this code should be moved into the core functions,
42 * or dropped completely,
43 * but let's get it working (again) first...
44 */
45
46#if defined(CONFIG_ARM_DCC) && !defined(CONFIG_BAUDRATE)
47#define CONFIG_BAUDRATE 115200
48#endif
49static int init_baudrate(void)
50{
51 char tmp[64]; /* long enough for environment variables */
52 int i = getenv_f("baudrate", tmp, sizeof(tmp));
53
54 gd->baudrate = (i > 0)
55 ? (int) simple_strtoul(tmp, NULL, 10)
56 : CONFIG_BAUDRATE;
57
58 return (0);
59}
60
61static int display_banner(void)
62{
63 printf("\n\n%s\n\n", version_string);
64 debug("U-Boot code: 0x%08lX -> 0x%08lX BSS: -> 0x%08lX\n",
65 _TEXT_BASE,
66 _bss_start_ofs + _TEXT_BASE, _bss_end_ofs + _TEXT_BASE);
67#ifdef CONFIG_MODEM_SUPPORT
68 debug("Modem Support enabled\n");
69#endif
70#if CONFIG_USE_IRQ
71 debug("IRQ Stack: 0x%08lx\n", IRQ_STACK_START);
72 debug("FIQ Stack: 0x%08lx\n", FIQ_STACK_START);
73#endif
74
75 return (0);
76}
77
78/*
79 * WARNING: this code looks "cleaner" than the PowerPC version, but
80 * has the disadvantage that you either get nothing, or everything.
81 * On PowerPC, you might see "DRAM: " before the system hangs - which
82 * gives a simple yet clear indication which part of the
83 * initialization if failing.
84 */
85static int display_dram_config(void)
86{
87 int i;
88
89#if DEBUG
90 puts("RAM Configuration:\n");
91
92 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
93 printf("Bank #%d: 0x%08lx ", i, gd->bd->bi_dram[i].start);
94 print_size(gd->bd->bi_dram[i].size, "\n");
95 }
96#else
97 ulong size = 0;
98
99 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
100 size += gd->bd->bi_dram[i].size;
101
102 puts("DRAM: ");
103 print_size(size, "\n");
104#endif
105
106 return (0);
107}
108
109#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
110static int init_func_i2c(void)
111{
112 puts("I2C: ");
113 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
114 puts("ready\n");
115 return (0);
116}
117#endif
118
119
120/*
121 * Breathe some life into the board...
122 *
123 * Initialize a serial port as console, and carry out some hardware
124 * tests.
125 *
126 * The first part of initialization is running from Flash memory;
127 * its main purpose is to initialize the RAM so that we
128 * can relocate the monitor code to RAM.
129 */
130
131typedef int (init_fnc_t) (void);
132
133int print_cpuinfo(void);
134
135/* ================================================================================
136 *
137 */
138void __dram_init_banksize(void)
139{
140 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
141 gd->bd->bi_dram[0].size = gd->ram_size;
142}
143
144/* ================================================================================
145 *
146 */
147void dram_init_banksize(void)
148 __attribute__((weak, alias("__dram_init_banksize")));
149
150
151/* ================================================================================
152 *
153 */
154init_fnc_t *init_sequence[] = {
155#if defined(CONFIG_ARCH_CPU_INIT)
156 arch_cpu_init, /* basic arch cpu dependent setup */
157#endif
158#if defined(CONFIG_BOARD_EARLY_INIT_F)
159 board_early_init_f,
160#endif
161 gpio_pad_init2rst,
162 //clk_init,
163 timer_init, /* initialize timer */
164#ifdef CONFIG_FSL_ESDHC
165 get_clocks,
166#endif
167 env_init, /* initialize environment */
168 init_baudrate, /* initialze baudrate settings */
169#if (CONFIG_PRINTF||CONFIG_UART_DL)
170 serial_init, /* serial communications setup */
171#endif
172 console_init_f, /* stage 1 init of console */
173 display_banner, /* say that we are here */
174#if defined(CONFIG_DISPLAY_CPUINFO)
175 print_cpuinfo, /* display cpu info (and speed) */
176#endif
177#if defined(CONFIG_DISPLAY_BOARDINFO)
178 checkboard, /* display board info */
179#endif
180#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
181 init_func_i2c,
182#endif
183 dram_init, /* configure available RAM banks */
184 NULL,
185};
186
187
188/* ================================================================================
189 *
190 */
191void board_init_f(ulong bootflag)
192{
193 bd_t *bd;
194 init_fnc_t **init_fnc_ptr;
195 gd_t *id;
196 ulong addr, addr_sp;
197
198 /* Pointer is writable since we allocated a register for it */
199 gd = (gd_t *) ((CONFIG_SYS_INIT_SP_ADDR) & ~0x07);
200 /* compiler optimization barrier needed for GCC >= 3.4 */
201 __asm__ __volatile__("": : :"memory");
202
203 memset((void *)gd, 0, sizeof(gd_t));
204
205 gd->mon_len = CONFIG_SYS_UBOOT_SIZE; //zhouqi gd->mon_len = _bss_end_ofs;
206
207 for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
208 if ((*init_fnc_ptr)() != 0) {
209 hang ();
210 }
211 }
212
213 debug("monitor len: 0x%08lX\n", gd->mon_len);
214 /*
215 * Ram is setup, size stored in gd !!
216 */
217 debug("ramsize: 0x%08lX\n", gd->ram_size);
218
219 addr = CONFIG_SYS_SDRAM_BASE + gd->ram_size;
220
221//#if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
222 /* reserve TLB table */
223 addr -= (4096 * 4);
224
225 /* round down to next 64 kB limit */
226 addr &= ~(0x10000 - 1);
227
228 gd->tlb_addr = addr;
229 debug("TLB table at: 0x%08lx\n", addr);
230//#endif
231
232 /* round down to next 4 kB limit */
233 addr &= ~(4096 - 1);
234 debug("Top of RAM usable for U-Boot at: 0x%08lx\n", addr);
235
236 /*
237 * reserve memory for U-Boot code, data & bss
238 * round down to next 4 kB limit
239 */
240 addr -= gd->mon_len;
241 addr &= ~(4096 - 1);
242
243 debug("Reserving %ldk for U-Boot at: 0x%08lx\n", gd->mon_len >> 10, addr);
244
245 addr_sp = addr - CFG_DENALI_DMA_BUF_SIZE; //zhouqi for nand dma buffer
246 debug("Reserving %dk for nand dma buffer at: 0x%08lx\n", CFG_DENALI_DMA_BUF_SIZE >> 10, addr_sp);
247
248#ifdef CONFIG_LCD //zhouqi exchange with u-boot code
249#ifdef CONFIG_FB_ADDR
250 gd->fb_base = CONFIG_FB_ADDR;
251#else
252 /* reserve memory for LCD display (always full pages) */
253 addr = lcd_setmem(addr);
254 gd->fb_base = addr;
255#endif /* CONFIG_FB_ADDR */
256#endif /* CONFIG_LCD */
257
258#ifndef CONFIG_SPL_BUILD
259 /*
260 * reserve memory for malloc() arena
261 */
262 addr_sp = addr - TOTAL_MALLOC_LEN - CFG_DENALI_DMA_BUF_SIZE; /* zhouqi */
263 debug("Reserving %dk for malloc() at: 0x%08lx\n",
264 TOTAL_MALLOC_LEN >> 10, addr_sp);
265 /*
266 * (permanently) allocate a Board Info struct
267 * and a permanent copy of the "global" data
268 */
269 addr_sp -= sizeof (bd_t);
270 bd = (bd_t *) addr_sp;
271 gd->bd = bd;
272 debug("Reserving %zu Bytes for Board Info at: 0x%08lx\n",
273 sizeof (bd_t), addr_sp);
274
275#ifdef CONFIG_MACH_TYPE
276 gd->bd->bi_arch_number = CONFIG_MACH_TYPE; /* board id for Linux */
277#endif
278
279 addr_sp -= sizeof (gd_t);
280 id = (gd_t *) addr_sp;
281 debug("Reserving %zu Bytes for Global Data at: 0x%08lx\n",
282 sizeof (gd_t), addr_sp);
283
284 /* setup stackpointer for exeptions */
285 gd->irq_sp = addr_sp;
286#if CONFIG_USE_IRQ
287 addr_sp -= (CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ);
288 debug("Reserving %zu Bytes for IRQ stack at: 0x%08lx\n",
289 CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ, addr_sp);
290#endif
291 /* leave 3 words for abort-stack */
292 addr_sp -= 12;
293
294 /* 8-byte alignment for ABI compliance */
295 addr_sp &= ~0x07;
296#else //define CONFIG_SPL_BUILD
297 addr_sp += 128; /* leave 32 words for abort-stack */
298 gd->irq_sp = addr_sp;
299#endif
300
301 debug("New Stack Pointer is: 0x%08lx\n", addr_sp);
302
303#ifdef CONFIG_POST
304 post_bootmode_init();
305 post_run(NULL, POST_ROM | post_bootmode_get(0));
306#endif
307
308 gd->bd->bi_baudrate = gd->baudrate;
309 /* Ram ist board specific, so move it to board code ... */
310 dram_init_banksize();
311 display_dram_config(); /* and display it */
312
313 gd->relocaddr = addr;
314 gd->start_addr_sp = addr_sp;
315 gd->reloc_off = addr - _TEXT_BASE;
316 debug("relocation Offset is: 0x%08lx\n", gd->reloc_off);
317 memcpy(id, (void *)gd, sizeof(gd_t));
318
319 relocate_code(addr_sp, id, addr);
320
321 /* NOTREACHED - relocate_code() does not return */
322}
323
324#if !defined(CONFIG_SYS_NO_FLASH)
325static char *failed = "*** failed ***\n";
326#endif
327
328
329
330
331extern void pinmux_reset(void);
332extern void gpio_reset(void);
333extern void pcu_clear_8in1_Int(void);
334
335
336/* ================================================================================
337 *
338 */
339void board_init_r(gd_t *id, ulong dest_addr)
340{
341 char *s;
342 //bd_t *bd;
343 ulong malloc_start;
344 u32 nand_status = 0;
345
346 gd = id;
347 //bd = gd->bd;
348
349 gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
350
351 monitor_flash_len = _end_ofs;
352 //if flash type is nand flash,close I&D cache
353 get_boot_flashtype();
354 if(read_boot_flashtype()==IF_TYPE_NAND)
355 {
356 /* Disable caches */
357 icache_disable();
358 dcache_disable();
359 }
360 else
361 {
362 /* Enable caches */
363 icache_enable();
364 dcache_enable();
365 nand_status = readl(0x1306058);
366 nand_status &= ~(0x7 << 4);
367 writel(nand_status, 0x1306058); /* nand contrl reset, Solve the problems of pull high and self-excited vibration of NAND controller pin. */
368 }
369
370 debug("monitor flash len: 0x%08lX\n", monitor_flash_len);
371 board_init(); /* Setup chipselects */
372
373 debug("Now running in RAM - U-Boot at: 0x%08lX\n", dest_addr);
374
375 /* The Malloc area is immediately below the monitor copy in DRAM */
376 malloc_start = dest_addr - TOTAL_MALLOC_LEN;
377 mem_malloc_init (malloc_start, TOTAL_MALLOC_LEN);
378
379 /* initialize environment */
380 env_relocate();
381
382 /* IP Address */
383 gd->bd->bi_ip_addr = getenv_IPaddr("ipaddr");
384
385 stdio_init(); /* get the devices list going. */
386
387 jumptable_init();
388
389 console_init_r(); /* fully init console as a device */
390
391 /* set up exceptions */
392 interrupt_init();
393 /* enable exceptions */
394 enable_interrupts();
395
396 /* Initialize from environment */
397 s = getenv("loadaddr");
398 if (s != NULL)
399 {
400 load_addr = simple_strtoul(s, NULL, 16);
401 }
402
403 //gpio_reset();
404 //pinmux_reset();
405 //pcu_clear_8in1_Int();
406
407 sys_entry();
408
409}
410
411
412void hang(void)
413{
414 puts("### [u-boot] ERROR ### Please RESET the board ###\n");
415 for (;;);
416}
417