三星uboot1.1.6源码分析——start.s(7)--C语言部分(1)

上一篇终于把uboot汇编部分的代码分析完了,这篇开始c语言部分代码的分析。

-------------------------------------------------------------------------------------------------------------------------------------------------------------

void start_armboot (void)

{
init_fnc_t **init_fnc_ptr;

------------------------------------------------------

typedef int (init_fnc_t) (void);

------------------------------------------------------
char *s;
#ifndef CFG_NO_FLASH
ulong size;
#endif


#if defined(CONFIG_VFD) || defined(CONFIG_LCD)
unsigned long addr;
#endif


#if defined(CONFIG_BOOT_MOVINAND)
uint *magic = (uint *) (PHYS_SDRAM_1);
#endif


/* Pointer is writable since we allocated a register for it */

还记得上一篇博客中的那个UBOOT内存映射图吗?下面这段代码对着那个图,很容易看明白,只是稍微有一点改变。
#ifdef CONFIG_MEMORY_UPPER_CODE /* by scsuh */
ulong gd_base;


gd_base = CFG_UBOOT_BASE + CFG_UBOOT_SIZE - CFG_MALLOC_LEN - CFG_STACK_SIZE - sizeof(gd_t);
#ifdef CONFIG_USE_IRQ
gd_base -= (CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ);
#endif
gd = (gd_t*)gd_base;
#else
gd = (gd_t*)(_armboot_start - CFG_MALLOC_LEN - sizeof(gd_t));
#endif

--------------------------------------------------------------------------------------------

其中有:

.globl _armboot_start
_armboot_start:
.word _start

-------------------------------------------

typedef structglobal_data {
bd_t*bd;
unsigned long flags;
unsigned long baudrate;
unsigned long have_console; /* serial_init() was called */
unsigned long reloc_off; /* Relocation Offset */
unsigned long env_addr; /* Address  of Environment struct */
unsigned long env_valid; /* Checksum of Environment valid? */
unsigned long fb_base; /* base address of frame buffer */
#ifdef CONFIG_VFD
unsigned char vfd_type; /* display type */
#endif
#if 0
unsigned long cpu_clk; /* CPU clock in Hz!*/
unsigned long bus_clk;
unsigned long ram_size; /* RAM size */
unsigned long reset_status; /* reset status register at boot */
#endif
void **jt;/* jump table */
} gd_t;

这个结构体在另外一篇博客中有说。

------------------------------------------------------------------------------------------------------

/* compiler optimization barrier needed for GCC >= 3.4 */
__asm__ __volatile__("": : :"memory");


memset ((void*)gd, 0, sizeof (gd_t));
gd->bd = (bd_t*)((char*)gd - sizeof(bd_t));
memset (gd->bd, 0, sizeof (bd_t));

    这个以前也说过。

--------------------------------------------------------------------------------------------


monitor_flash_len = _bss_start - _armboot_start;


for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) 
{
if ((*init_fnc_ptr)() != 0) 
{
hang ();
}
}
-----------------------------------

这一部分是重头戏,主要的函数都在这里,而且这个函数调用的方式很好,值得学习。

init_fnc_t *init_sequence[] = {
cpu_init, /* basic cpu dependent setup */
board_init, /* basic board dependent setup */
interrupt_init,/* set up exceptions */
env_init, /* initialize environment */
init_baudrate,/* initialze baudrate settings */
serial_init, /* serial communications setup */
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
dram_init, /* configure available RAM banks */
display_dram_config,
NULL,
};

---------------------------------------------------------------------------------------------------

...................

...................

省略的这部分代码,以后专门写一篇博客分析。
/* main_loop() can return to retry autoboot, if so just run it again. */
for (;;) {
main_loop ();
}


/* NOTREACHED - no way out of command loop except booting */
}

--------------------------------------------------------------------------------------------------

总:这一篇博客主要是为分析c语言部分代码开了个头,下一篇开始,我们便进入那个数组里面的函数,去看一看,具体函数的实现。---------------------------------------下篇见。





你可能感兴趣的:(basic,语言,三星,compiler,代码分析,optimization)