1.配置:make 100ask24x0_config
2.分析编译:makefile
①第一个文件:cpu/arm920t/start.s
②连接第二个文件:board/100ask24x0/u-boot.lds
+0x33F80000
硬件部件的初始化:
①初始化:关看门狗 初始化时钟 初始化SDRAN
②把程序从nand flash拷贝到SDRAM
③设置栈(sp)
④调用C函数
↑从cpu/arm920t/start.s入手
a.设为svc模式
b.关闭看门狗
c.屏蔽中断
d.初始化sdram
e.设置栈
f.时钟
g.重定位,代码从lash考到sdram里面去
h.清BSS段
↑为硬件初始化,为第一阶段
i.start_armboot → C函数 →第二阶段
***判断是从nandflash启动还是norflash启动:首先先把址0地址用一个
变量保存下来,再写入一个地址进去0地址,然后再判断0地址是不是等于自己写进去的那个地址,如果是则说明0地址是可写的为nandflash启动,如果不是则说明是不可写的为norflash启动
u_boot的目标:启动内核
nand read.jffs 0x30007Fc0 ← ①从flash中读出内核 =》要能读出flash ①nandflash:nand_init
②norflsah : flash_init
bootm 0x30007Fc0 ← ②启动内核
环境变量的初始化 env_relocate
环境变量有两种:①默认的
②flash上保存的
分析知道:start_armboot经过flash.init(norflash初始化),nand_init(nandflash初始化),之后无线循环在main_loop函数中
main_loop:
main_loop主要流程
{
1. 生成环境变量mtdparts, 调用mtdparts_init
2. 在启动过程中
若无空格键按下则boot_zImage,即run_command(getenv("bootcmd"),0)
有空格键按下则 run_command("menu",0)
3. shell过程,读取用户的输入并执行相应的命令
{
从控制台获得命令,保存在全局变量comsole_buffer中
解析命令行字符串,分割命令与参数,最后执行 run_command(...);
}
}
bootcmd=nand read.jffs2 0x30007FC0 kernel; bootm 0x30007FC0
第一条命令 从flash上读出内核 kernel是一个分区标志
第二条命令 启动命令指示了启动地址
①启动内核:
s=getevn("bootcmd")
run_command(s)
②u-boot界面:
readline(读入串口数据)
readline (CFG_PROMPT);
u-boot的核心就是输入命令
9-4:
md.w 0 打印0地址的内容
u-boot命令: ①输入命令字符串
②动作肯定对应了某一个函数
在u-boot中增加命令:
①把cmd_bootm.c中的头文件全部复制下来,然后新建一个helo_com.c文件,把刚才复制的头文件粘贴到这里
②把这个.c文件放到u-boot中的common目录下面
③找到一个已经写好的命令把格式复制下来:如 int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
ulong iflag;
ulong addr;
ulong data, len, checksum;
ulong *len_ptr;
uint unc_len = CFG_BOOTM_LEN;
int i, verify;
char *name, *s;
int (*appl)(int, char *[]);
image_header_t *hdr = &header;
s = getenv ("verify");
verify = (s && (*s == 'n')) ? 0 : 1;
}
改为 :
int do_hello (cmd_tbl_t *cmdtp,int flag,int argc ,char *argv[])
{
int i;
printf ("hello,work!, %d\n ",argc);
for (i = 0;i<argc;i++)
{
printf("argv[%d]:%s\n",i,atgv[i]);
}
return 0;
}
④再把U_BOOT_CMD(
bootm, CFG_MAXARGS, 1, do_bootm,
"bootm - boot application image from memory\n",
"[addr [arg ...]]\n - boot application image stored in memory\n"
"\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
"\t'arg' can be the address of an initrd image\n"
#ifdef CONFIG_OF_FLAT_TREE
"\tWhen booting a Linux kernel which requires a flat device-tree\n"
"\ta third argument is required which is the address of the of the\n"
"\tdevice-tree blob. To boot that kernel without an initrd image,\n"
"\tuse a '-' for the second argument. If you do not pass a third\n"
"\ta bd_info struct will be passed instead\n"
#endif
);
拷贝过来改为:
U_BOOT_CMD(
hello, CFG_MAXARGS, 1, do_hello,
"hello - just for test\n", →短的帮助信息
"hello, long help ............\n" →长的帮助信息
);
⑤写好.c文件后把代码考到u-boot的common目录下保存
⑥再打开common目录下的makefile文件,添加cmd_hello.o进去然后保存
⑦make
⑧把新生成的u-boot.bin烧到开发板上
@可知start.S的流程为:
——异常向量
——上电复位后进入复位异常向量
——跳到启动代码处
——设置处理器进入管理模式
——关闭看门狗
——关闭中断
——设置时钟分频
——关闭MMU和CACHE
——进入lowlever_init.S
——检查当前代码所处的位置,如果在FLASH中就将代码搬移到RAM中