| /* |
| * (C) Copyright 2016, ZIXC Corporation. |
| * |
| * (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> |
| #include <command.h> |
| #include <malloc.h> |
| #include <stdio_dev.h> |
| #include <version.h> |
| #include <net.h> |
| #include <serial.h> |
| #include <nand.h> |
| #include <onenand_uboot.h> |
| #include <mmc.h> |
| #include <timer.h> |
| #include <asm/arch/lsp_crpm.h> |
| #include <asm/arch/cpu.h> |
| #include <config.h> |
| #include <drvs_gpio.h> |
| |
| DECLARE_GLOBAL_DATA_PTR; |
| |
| ulong monitor_flash_len; |
| |
| #if defined(CONFIG_HARD_I2C) || \ |
| defined(CONFIG_SOFT_I2C) |
| #include <i2c.h> |
| #endif |
| |
| /* |
| ************************************************************************ |
| * Init Utilities * |
| ************************************************************************ |
| * Some of this code should be moved into the core functions, |
| * or dropped completely, |
| * but let's get it working (again) first... |
| */ |
| |
| #if defined(CONFIG_ARM_DCC) && !defined(CONFIG_BAUDRATE) |
| #define CONFIG_BAUDRATE 115200 |
| #endif |
| static int init_baudrate(void) |
| { |
| char tmp[64]; /* long enough for environment variables */ |
| int i = getenv_f("baudrate", tmp, sizeof(tmp)); |
| |
| gd->baudrate = (i > 0) |
| ? (int) simple_strtoul(tmp, NULL, 10) |
| : CONFIG_BAUDRATE; |
| |
| return (0); |
| } |
| |
| static int display_banner(void) |
| { |
| printf("\n\n%s\n\n", version_string); |
| debug("U-Boot code: 0x%08lX -> 0x%08lX BSS: -> 0x%08lX\n", |
| _TEXT_BASE, |
| _bss_start_ofs + _TEXT_BASE, _bss_end_ofs + _TEXT_BASE); |
| #ifdef CONFIG_MODEM_SUPPORT |
| debug("Modem Support enabled\n"); |
| #endif |
| #if CONFIG_USE_IRQ |
| debug("IRQ Stack: 0x%08lx\n", IRQ_STACK_START); |
| debug("FIQ Stack: 0x%08lx\n", FIQ_STACK_START); |
| #endif |
| |
| return (0); |
| } |
| |
| /* |
| * WARNING: this code looks "cleaner" than the PowerPC version, but |
| * has the disadvantage that you either get nothing, or everything. |
| * On PowerPC, you might see "DRAM: " before the system hangs - which |
| * gives a simple yet clear indication which part of the |
| * initialization if failing. |
| */ |
| static int display_dram_config(void) |
| { |
| int i; |
| |
| #if DEBUG |
| puts("RAM Configuration:\n"); |
| |
| for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { |
| printf("Bank #%d: 0x%08lx ", i, gd->bd->bi_dram[i].start); |
| print_size(gd->bd->bi_dram[i].size, "\n"); |
| } |
| #else |
| ulong size = 0; |
| |
| for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) |
| size += gd->bd->bi_dram[i].size; |
| |
| puts("DRAM: "); |
| print_size(size, "\n"); |
| #endif |
| |
| return (0); |
| } |
| |
| #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C) |
| static int init_func_i2c(void) |
| { |
| puts("I2C: "); |
| i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE); |
| puts("ready\n"); |
| return (0); |
| } |
| #endif |
| |
| |
| /* |
| * Breathe some life into the board... |
| * |
| * Initialize a serial port as console, and carry out some hardware |
| * tests. |
| * |
| * The first part of initialization is running from Flash memory; |
| * its main purpose is to initialize the RAM so that we |
| * can relocate the monitor code to RAM. |
| */ |
| |
| typedef int (init_fnc_t) (void); |
| |
| int print_cpuinfo(void); |
| |
| /* ================================================================================ |
| * |
| */ |
| void __dram_init_banksize(void) |
| { |
| gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE; |
| gd->bd->bi_dram[0].size = gd->ram_size; |
| } |
| |
| /* ================================================================================ |
| * |
| */ |
| void dram_init_banksize(void) |
| __attribute__((weak, alias("__dram_init_banksize"))); |
| |
| |
| /* ================================================================================ |
| * |
| */ |
| init_fnc_t *init_sequence[] = { |
| #if defined(CONFIG_ARCH_CPU_INIT) |
| arch_cpu_init, /* basic arch cpu dependent setup */ |
| #endif |
| #if defined(CONFIG_BOARD_EARLY_INIT_F) |
| board_early_init_f, |
| #endif |
| gpio_pad_init2rst, |
| //clk_init, |
| timer_init, /* initialize timer */ |
| #ifdef CONFIG_FSL_ESDHC |
| get_clocks, |
| #endif |
| env_init, /* initialize environment */ |
| init_baudrate, /* initialze baudrate settings */ |
| #if (CONFIG_PRINTF||CONFIG_UART_DL) |
| serial_init, /* serial communications setup */ |
| #endif |
| console_init_f, /* stage 1 init of console */ |
| display_banner, /* say that we are here */ |
| #if defined(CONFIG_DISPLAY_CPUINFO) |
| print_cpuinfo, /* display cpu info (and speed) */ |
| #endif |
| #if defined(CONFIG_DISPLAY_BOARDINFO) |
| checkboard, /* display board info */ |
| #endif |
| #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C) |
| init_func_i2c, |
| #endif |
| dram_init, /* configure available RAM banks */ |
| NULL, |
| }; |
| |
| |
| /* ================================================================================ |
| * |
| */ |
| void board_init_f(ulong bootflag) |
| { |
| bd_t *bd; |
| init_fnc_t **init_fnc_ptr; |
| gd_t *id; |
| ulong addr, addr_sp; |
| |
| /* Pointer is writable since we allocated a register for it */ |
| gd = (gd_t *) ((CONFIG_SYS_INIT_SP_ADDR) & ~0x07); |
| /* compiler optimization barrier needed for GCC >= 3.4 */ |
| __asm__ __volatile__("": : :"memory"); |
| |
| memset((void *)gd, 0, sizeof(gd_t)); |
| |
| gd->mon_len = CONFIG_SYS_UBOOT_SIZE; //zhouqi gd->mon_len = _bss_end_ofs; |
| |
| for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) { |
| if ((*init_fnc_ptr)() != 0) { |
| hang (); |
| } |
| } |
| |
| debug("monitor len: 0x%08lX\n", gd->mon_len); |
| /* |
| * Ram is setup, size stored in gd !! |
| */ |
| debug("ramsize: 0x%08lX\n", gd->ram_size); |
| |
| addr = CONFIG_SYS_SDRAM_BASE + gd->ram_size; |
| |
| //#if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF)) |
| /* reserve TLB table */ |
| addr -= (4096 * 4); |
| |
| /* round down to next 64 kB limit */ |
| addr &= ~(0x10000 - 1); |
| |
| gd->tlb_addr = addr; |
| debug("TLB table at: 0x%08lx\n", addr); |
| //#endif |
| |
| /* round down to next 4 kB limit */ |
| addr &= ~(4096 - 1); |
| debug("Top of RAM usable for U-Boot at: 0x%08lx\n", addr); |
| |
| /* |
| * reserve memory for U-Boot code, data & bss |
| * round down to next 4 kB limit |
| */ |
| addr -= gd->mon_len; |
| addr &= ~(4096 - 1); |
| |
| debug("Reserving %ldk for U-Boot at: 0x%08lx\n", gd->mon_len >> 10, addr); |
| |
| addr_sp = addr - CFG_DENALI_DMA_BUF_SIZE; //zhouqi for nand dma buffer |
| debug("Reserving %dk for nand dma buffer at: 0x%08lx\n", CFG_DENALI_DMA_BUF_SIZE >> 10, addr_sp); |
| |
| #ifdef CONFIG_LCD //zhouqi exchange with u-boot code |
| #ifdef CONFIG_FB_ADDR |
| gd->fb_base = CONFIG_FB_ADDR; |
| #else |
| /* reserve memory for LCD display (always full pages) */ |
| addr = lcd_setmem(addr); |
| gd->fb_base = addr; |
| #endif /* CONFIG_FB_ADDR */ |
| #endif /* CONFIG_LCD */ |
| |
| #ifndef CONFIG_SPL_BUILD |
| /* |
| * reserve memory for malloc() arena |
| */ |
| addr_sp = addr - TOTAL_MALLOC_LEN - CFG_DENALI_DMA_BUF_SIZE; /* zhouqi */ |
| debug("Reserving %dk for malloc() at: 0x%08lx\n", |
| TOTAL_MALLOC_LEN >> 10, addr_sp); |
| /* |
| * (permanently) allocate a Board Info struct |
| * and a permanent copy of the "global" data |
| */ |
| addr_sp -= sizeof (bd_t); |
| bd = (bd_t *) addr_sp; |
| gd->bd = bd; |
| debug("Reserving %zu Bytes for Board Info at: 0x%08lx\n", |
| sizeof (bd_t), addr_sp); |
| |
| #ifdef CONFIG_MACH_TYPE |
| gd->bd->bi_arch_number = CONFIG_MACH_TYPE; /* board id for Linux */ |
| #endif |
| |
| addr_sp -= sizeof (gd_t); |
| id = (gd_t *) addr_sp; |
| debug("Reserving %zu Bytes for Global Data at: 0x%08lx\n", |
| sizeof (gd_t), addr_sp); |
| |
| /* setup stackpointer for exeptions */ |
| gd->irq_sp = addr_sp; |
| #if CONFIG_USE_IRQ |
| addr_sp -= (CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ); |
| debug("Reserving %zu Bytes for IRQ stack at: 0x%08lx\n", |
| CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ, addr_sp); |
| #endif |
| /* leave 3 words for abort-stack */ |
| addr_sp -= 12; |
| |
| /* 8-byte alignment for ABI compliance */ |
| addr_sp &= ~0x07; |
| #else //define CONFIG_SPL_BUILD |
| addr_sp += 128; /* leave 32 words for abort-stack */ |
| gd->irq_sp = addr_sp; |
| #endif |
| |
| debug("New Stack Pointer is: 0x%08lx\n", addr_sp); |
| |
| #ifdef CONFIG_POST |
| post_bootmode_init(); |
| post_run(NULL, POST_ROM | post_bootmode_get(0)); |
| #endif |
| |
| gd->bd->bi_baudrate = gd->baudrate; |
| /* Ram ist board specific, so move it to board code ... */ |
| dram_init_banksize(); |
| display_dram_config(); /* and display it */ |
| |
| gd->relocaddr = addr; |
| gd->start_addr_sp = addr_sp; |
| gd->reloc_off = addr - _TEXT_BASE; |
| debug("relocation Offset is: 0x%08lx\n", gd->reloc_off); |
| memcpy(id, (void *)gd, sizeof(gd_t)); |
| |
| relocate_code(addr_sp, id, addr); |
| |
| /* NOTREACHED - relocate_code() does not return */ |
| } |
| |
| #if !defined(CONFIG_SYS_NO_FLASH) |
| static char *failed = "*** failed ***\n"; |
| #endif |
| |
| |
| |
| |
| extern void pinmux_reset(void); |
| extern void gpio_reset(void); |
| extern void pcu_clear_8in1_Int(void); |
| |
| |
| /* ================================================================================ |
| * |
| */ |
| void board_init_r(gd_t *id, ulong dest_addr) |
| { |
| char *s; |
| //bd_t *bd; |
| ulong malloc_start; |
| u32 nand_status = 0; |
| |
| gd = id; |
| //bd = gd->bd; |
| |
| gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */ |
| |
| monitor_flash_len = _end_ofs; |
| //if flash type is nand flash,close I&D cache |
| get_boot_flashtype(); |
| if(read_boot_flashtype()==IF_TYPE_NAND) |
| { |
| /* Disable caches */ |
| icache_disable(); |
| dcache_disable(); |
| } |
| else |
| { |
| /* Enable caches */ |
| icache_enable(); |
| dcache_enable(); |
| nand_status = readl(0x1306058); |
| nand_status &= ~(0x7 << 4); |
| writel(nand_status, 0x1306058); /* nand contrl reset, Solve the problems of pull high and self-excited vibration of NAND controller pin. */ |
| } |
| |
| debug("monitor flash len: 0x%08lX\n", monitor_flash_len); |
| board_init(); /* Setup chipselects */ |
| |
| debug("Now running in RAM - U-Boot at: 0x%08lX\n", dest_addr); |
| |
| /* The Malloc area is immediately below the monitor copy in DRAM */ |
| malloc_start = dest_addr - TOTAL_MALLOC_LEN; |
| mem_malloc_init (malloc_start, TOTAL_MALLOC_LEN); |
| |
| /* initialize environment */ |
| env_relocate(); |
| |
| /* IP Address */ |
| gd->bd->bi_ip_addr = getenv_IPaddr("ipaddr"); |
| |
| stdio_init(); /* get the devices list going. */ |
| |
| jumptable_init(); |
| |
| console_init_r(); /* fully init console as a device */ |
| |
| /* set up exceptions */ |
| interrupt_init(); |
| /* enable exceptions */ |
| enable_interrupts(); |
| |
| /* Initialize from environment */ |
| s = getenv("loadaddr"); |
| if (s != NULL) |
| { |
| load_addr = simple_strtoul(s, NULL, 16); |
| } |
| |
| //gpio_reset(); |
| //pinmux_reset(); |
| //pcu_clear_8in1_Int(); |
| |
| sys_entry(); |
| |
| } |
| |
| |
| void hang(void) |
| { |
| puts("### [u-boot] ERROR ### Please RESET the board ###\n"); |
| for (;;); |
| } |
| |