📄 boot_init.c
字号:
/****************************************************************************
** Copyright (c) 2004, UTStarcom, Inc.
** All Rights Reserved.
**
** Subsystem : Platform support
** File : boot_init.c
** Created By : Sean Yang
** Created On : 2005.01.21
**
** Purpose:
** initilize registers of CPU
**
****************************************************************************/
/****************************************************************************
* includes
****************************************************************************/
/***************************************************************************
* extern functions
***************************************************************************/
/***************************************************************************
* Defines and Typedefs
***************************************************************************/
typedef unsigned char U8;
typedef unsigned short U16;
typedef unsigned int U32;
#define REG_TIM_CNTL 0x007FF13F
#define REG_MEM_REMAP 0x007FF804
#define REG_CS_WAITSEL1 0x007FF808
#define REG_CS_WAITSEL2 0x007FF809
#define REG_PIO_SET 0x007FF811
#define REG_PIO_DATA 0x007FF820
#define REG_DIO1_CTL 0x007FF810
#define REG_DIO1_IO 0x007FF820
#define EXT_SRAM_BASE 0x00200000
#define EXT_SRAM_SIZE 0x001A0000 /* reserve Trace area 384K bytes */
#define BOOTLD_BASE 0x00002000
#define BOOTLD_SIZE 0x0001E000
#define RUNNING_BASE 0x00300000
#define LED_ERR_2 3 /* ram check error */
/***************************************************************************
* Global and Local Data Definitions
***************************************************************************/
void reset_watchdog(void)
{
U8 * regs;
U8 i;
regs = (U8 *)REG_PIO_DATA; /* output high level to PIO5 */
*regs = 0x20;
for (i=0; i<8;i++);
regs = (U8 *)REG_PIO_DATA; /* output low level to PIO5 */
*regs = 0x00;
}
void boot_led_switch(U8 times)
{
U32 loop_cnt1, loop_cnt2, loop_cnt3;
unsigned char * led_ptr = (unsigned char *)0x007ff823;
for (loop_cnt1 = 0; loop_cnt1 < times; loop_cnt1++)
{
*led_ptr |= 0x02; /* turn off */
for (loop_cnt2 = 0; loop_cnt2 < 10; loop_cnt2++)
{
for(loop_cnt3 = 0; loop_cnt3 < 10000; loop_cnt3++) {}/* about 1.6s */
reset_watchdog();
}
*led_ptr &= ~0x02; /* turn on */
for (loop_cnt2 = 0; loop_cnt2 < 10; loop_cnt2++)
{
for(loop_cnt3 = 0; loop_cnt3 < 10000; loop_cnt3++) {}/* about 1.6s */
reset_watchdog();
}
}
}
/****************************************************************************
**
** FUNCTION NAME: lowlevel_init
**
** Description:
** This function performs very low level HW initialization
**
** Argument Type IO Description
** ------------- -------- -- ---------------------------------
** vector U32* Input vector table Address determinate in Relative addressing
** internalRam U32* Input Internal Address determinate in Relative addressing
**
** Global Variables:
**
** Return Value: N/A
**
** HISTORY (Recommended but Optional):
**
** Programmer Date Description of Revision
** -------------------- ---------- ------------------------------
** Sean Yang 2005.01.21 Initial Writing
****************************************************************************/
void lowlevel_init(U32 * vector, U32 * internal_ram)
{
U32 i;
U8 * regs;
regs = (U8 *)REG_TIM_CNTL; /* set timer control register */
*regs = 0x03;
regs = (U8 *)REG_MEM_REMAP; /* before remap memory */
*regs = 0x30;
/* set waiting phase of CS0(FLASH),CS1(SRAM),CS2(FPGA) */
regs = (U8 *)REG_CS_WAITSEL1;
*regs = 0x12;
regs = (U8 *)REG_CS_WAITSEL2;
*regs = 0x02;
/* initialize WatchDog, enable */
regs = (U8 *)REG_PIO_SET; /* set PIO5 to output */
*regs = 0x04;
regs = (U8 *)REG_PIO_DATA; /* output low level to PIO5 */
*regs = 0x00;
regs = (U8 *)REG_DIO1_CTL;
*regs = 0x04;
regs = (U8 *)REG_PIO_DATA;
*regs = 0x00;
/* Setup Exception Vectors in Internal RAM before Remap
Before Remap the internal RAM it's 0x00700000
After Remap the internal RAM it's 0x00000000
Copy the ARM exception vectors and indirect table */
for (i = 0;i < 16; i++ )
{
*internal_ram++ = *vector++;
}
/*Clear internal RAM, but this ram also used for STACK
when call this function, so can not clear the top 4 WORDs*/
for (i = 16; i < 1000; i++)
{
*internal_ram++ = 0;
}
}
/****************************************************************************
**
** FUNCTION NAME: copy_bootld
**
** Description:
** copy boot loader to sram, and run it.
**
** Argument Type IO Description
** ------------- -------- -- ---------------------------------
**
** Global Variables:
**
** Return Value: N/A
**
** HISTORY (Recommended but Optional):
**
** Programmer Date Description of Revision
** -------------------- ---------- ------------------------------
** Sean Yang 2004.01.28 Initial Writing
****************************************************************************/
void copy_bootld(void)
{
U32 i;
U32 * src;
U32 * dest;
unsigned char * cntl_ptr = (unsigned char *)0x007ff816;
unsigned char * led_ptr = (unsigned char *)0x007ff823;
*cntl_ptr |= 0x04; /* set to output */
*led_ptr &= ~0x02; /* turn on */
/* test SRAM, from 0x00300000 to 0x003A0000, the other SRAM will be tested in boot loader 2 */
for (i = 0; i < EXT_SRAM_SIZE / 4; i++) /* write 0x55, and read */
{
*(U32 *)(EXT_SRAM_BASE + i * 4) = 0x55555555;
if (*(U32 *)(EXT_SRAM_BASE + i * 4) != 0x55555555)
{
boot_led_switch(LED_ERR_2);
while(1); /* reset system */
}
if ((i + 1) % 4096 == 0) /* reset watchdog */
reset_watchdog();
}
for (i = 0; i < EXT_SRAM_SIZE / 4; i++) /* write 0xAA, and read */
{
*(U32 *)(EXT_SRAM_BASE + i * 4) = 0xaaaaaaaa;
if (*(U32 *)(EXT_SRAM_BASE + i * 4) != 0xaaaaaaaa)
{
boot_led_switch(LED_ERR_2);
while(1); /* reset system */
}
if ((i + 1) % 4096 == 0) /* reset watchdog */
reset_watchdog();
}
/* clear SRAM, from 0x00200000 to 0x003A0000 */
for (i = 0; i < EXT_SRAM_SIZE / 4; i++)
{
*(U32 *)(EXT_SRAM_BASE + i * 4) = 0;
if ((i + 1) % 4096 == 0) /* reset watchdog */
reset_watchdog();
}
/* copy boot loader to temp area in SRAM, then run it in SRAM to unzip version */
dest = (U32 *)RUNNING_BASE;
src = (U32 *)BOOTLD_BASE;
for (i = 0; i < BOOTLD_SIZE / 4; i++)
{
*dest++ = *src++;
if ((i + 1) % 4096 == 0) /* reset watchdog */
reset_watchdog();
}
*led_ptr |= 0x02; /* turn off */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -