您的位置:首页 > 编程语言

uboot移植第一天——代码分析(1)

2017-05-04 18:00 337 查看
uboot版本 :u-boot-1.1.6

编译器 :gcc version 3.4.5

开发板 :jz2440

.globl _start
_start: b       reset
*跳转到reset执行*


1、set the cpu to SVC32 mode——设置为管理模式

2、turn off the watchdog——关闭看门狗

3、mask all IRQs by setting all bits in the INTMR——关闭外部中断

4、设置时钟比例

5、bl cpu_init_crit

flush v4 I/D caches——用于同步

disable MMU stuff and caches——关闭mmu和cache

bl lowlevel_init——存储控制器初始化

这里要注意SMRDATA中的值,根据数据手册和当前时钟配置

重定位——即就是把falsh中的代码复制到ram中,本开发板复制到sdram中;

stack_setup——设置堆栈,因为接下来要调c函数,来进行更复杂的处理。

clear_bss——清bss段,该段存放的是初始化为零或为未初始化的变量,只要额外的放在一个段就行,使用时取就行;

进入uboot的第二阶段

ldr pc, _start_armboot
_start_armboot: .word start_armboot


第二阶段分析:

void start_armboot (void)
{
init_fnc_t **init_fnc_ptr;//函数指针的指针,在下面的for循环中循环调用init_sequence数组中的函数,进行对板子的各种初始化
char *s;
#ifndef CFG_NO_FLASH
ulong size;
#endif
#if defined(CONFIG_VFD) || defined(CONFIG_LCD)
unsigned long addr;
#endif

/* Pointer is writable since we allocated a register for it */
gd = (gd_t*)(_armboot_start - CFG_MALLOC_LEN - sizeof(gd_t));//为全局变量(存储在一个结构体中)分配空间,在链接地址(代码运行时的所在的地址)-堆空间大小(#define设置)-结构体大小gd指向地址
/* 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));//bd指向板子相关信息存储的地址
memset (gd->bd, 0, sizeof (bd_t));

monitor_flash_len = _bss_start - _armboot_start;
//计算出uboot的代码段大小,自己看代码这个跟lds链接脚本有关
for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
if ((*init_fnc_ptr)() != 0) {
hang ();
}
}
//上面的for循环是调用各种初始化函数,init_fnc_ptr 是函数指针的指针,init_sequence[]函数指针数组
#ifndef CFG_NO_FLASH
/* configure available FLASH banks */
size = flash_init ();//初始化并识别开发板的norflash
display_flash_config (size);
#endif /* CFG_NO_FLASH */

#ifdef CONFIG_VFD
#   ifndef PAGE_SIZE
#     define PAGE_SIZE 4096
#   endif
/*
* reserve memory for VFD display (always full pages)
*/
/* bss_end is defined in the board-specific linker script */
addr = (_bss_end + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
size = vfd_setmem (addr);
gd->fb_base = addr;
#endif /* CONFIG_VFD */

#ifdef CONFIG_LCD
#   ifndef PAGE_SIZE
#     define PAGE_SIZE 4096
#   endif
/*
* reserve memory for LCD display (always full pages)
*/
/* bss_end is defined in the board-specific linker script */
addr = (_bss_end + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
size = lcd_setmem (addr);
gd->fb_base = addr;
#endif /* CONFIG_LCD */

/* armboot_start is defined in the board-specific linker script */
mem_malloc_init (_armboot_start - CFG_MALLOC_LEN);

#if (CONFIG_COMMANDS & CFG_CMD_NAND)
puts ("NAND:  ");
nand_init();        /* go init the NAND */
//初始化并识别开发板的nandflash
#endif


以上对uboot做了个非常粗略的分析,因本人初学记录下的学习笔记,若有不对之处,望各位指出。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  uboot学习