发现一个不错的博客链接,后续针对这个流程进行学习一下
bootm原理
基础知识
vmlinux
vmlinux是可引导的,可压缩的内核镜像,vm代表virtual memory。vmlinux是elf格式的文件,是最原始的内核文件
Image
Image是经过objcopy处理的只包含二进制数据的内核代码,它已经不是elf格式了,但是还没有经过压缩
zImage
Image经过gzip压缩得到zImage
uImage
zImage加上一个64字节的头信息,在头中说明镜像文件的类型,加载位置,生成时间,大小等信息,变生成了uImage
xipImage
这种格式的镜像文件多放在nor flash上,且运行时不需要拷贝到内存中,可以直接在nor flash上运行
bootm实现
bootm命令的定义
U_BOOT_CMD(
bootm, CONFIG_SYS_MAXARGS, 1, do_bootm,
"boot application image from memory", bootm_help_text
);
bootm主函数
/*******************************************************************/
/* bootm - boot application image from image in memory */
/*******************************************************************/
int do_bootm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
#ifdef CONFIG_NEEDS_MANUAL_RELOC //没定义
static int relocated = 0;
if (!relocated) {
int i;
/* relocate names of sub-command table */
for (i = 0; i < ARRAY_SIZE(cmd_bootm_sub); i++)
cmd_bootm_sub[i].name += gd->reloc_off;
relocated = 1;
}
#endif
/* determine if we have a sub command */
argc--; argv++;
if (argc > 0) { //假设我们传了一个参数"0x10000000"
char *endp;
simple_strtoul(argv[0], &endp, 16);
/* endp pointing to NULL means that argv[0] was just a
* valid number, pass it along to the normal bootm processing
*
* If endp is ':' or '#' assume a FIT identifier so pass
* along for normal processing.
*
* Right now we assume the first arg should never be '-'
*/
if ((*endp != 0) && (*endp != ':') && (*endp != '#'))
return do_bootm_subcommand(cmdtp, flag, argc, argv);
}
return do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START |
BOOTM_STATE_FINDOS | BOOTM_STATE_FINDOTHER |
BOOTM_STATE_LOADOS |
#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
BOOTM_STATE_RAMDISK |
#endif
#if defined(CONFIG_PPC) || defined(CONFIG_MIPS)
BOOTM_STATE_OS_CMDLINE |
#endif
BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO |
BOOTM_STATE_OS_GO, &images, 1); //images是一个比较重要的全局变量
}
下面列出bootm_headers的内容,等会一个一个填充
- do_bootm_states函数
1 |
|
bootm_start
- boot_start函数
1 |
|
bootm_find_os
- boot_find_os
1 |
|
- image_get_kern
image_get_kern 在boot_get_kern中调用
1 |
|
- image_print_contents
image_print_contents打印uimage头信息
1 |
|
bootm_load_os
- bootm_load_os
1 | static int bootm_load_os(bootm_headers_t *images, int boot_progress) |
bootm_os_get_boot_func
- bootm_os_get_boot_func
1 |
|
boot_selected_os
- boot_selected_os
1 |
|
- do_bootm_linux
1 | int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images) |
- boot_prep_linux
1 | static void boot_prep_linux(bootm_headers_t *images) |
- boot_jump_linux
1 | static void boot_jump_linux(bootm_headers_t *images, int flag) |