uboot启动流程二
来源:互联网 发布:java设计模式的书 编辑:程序博客网 时间:2024/05/01 02:34
#if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0)
s = getenv ("bootdelay"); //得到环境变量中bootdelay
bootdelay = s ? (int)simple_strtol(s, NULL, 10) : CONFIG_BOOTDELAY;
debug ("### main_loop entered: bootdelay=%d/n/n", bootdelay);
#ifdef CONFIG_BOOTCOUNT_LIMIT //启动次数的限制功能,如果到达一定次数,将不能启动u-boot.
if (bootlimit && (bootcount > bootlimit)) {//检查是否超出启动次数限制
printf ("Warning: Bootlimit (%u) exceeded. Using altbootcmd./n",
(unsigned)bootlimit);
s = getenv ("altbootcmd");//启动延时
}
else
#endif /* CONFIG_BOOTCOUNT_LIMIT */
s = getenv ("bootcmd");// 获得启动参数
debug ("### main_loop: bootcmd=/"%s/"/n", s ? s : "<UNDEFINED>");
// 这里如果bootdelay大于0,并且中间没有被中断的话,执行命令行参数
if (bootdelay >= 0 && s && !abortboot (bootdelay)) {
# ifdef CONFIG_AUTOBOOT_KEYED
int prev = disable_ctrlc(1); /* disable Control C checking */
# endif
# ifndef CONFIG_SYS_HUSH_PARSER
run_command (s, 0); //运行启动的命令行,例如 可以使用tftp命令
# else
parse_string_outer(s, FLAG_PARSE_SEMICOLON |
FLAG_EXIT_FROM_LOOP);
# endif
#define CONFIG_BOOTM_LINUX 1
#define CONFIG_BOOTM_NETBSD 1
#define CONFIG_BOOTM_RTEMS 1
#ifdef CONFIG_BOOTM_LINUX
extern boot_os_fn do_bootm_linux;
#endif
#ifdef CONFIG_BOOTM_NETBSD
static boot_os_fn do_bootm_netbsd;
#endif
void (*theKernel)(int zero, int arch, uint params);
theKernel = (void (*)(int, int, uint))images->ep;
image是bootm_headers结构体的指针,可以在inlcude/image.h文件中看到这个结构体的定义如下:
typedef struct bootm_headers {
............................
int fit_noffset_fdt;/* FDT blob subimage node offset */
#endif
#ifndef USE_HOSTCC
image_info_t os; /* os image info */
ulong ep; /* entry point of OS */
ulong rd_start, rd_end;/* ramdisk start/end */
...............
}
theKernel (0, machid, bd->bi_boot_params);
要知道哪个地址是启动内核,哪个地址启动文件系统,要分析common/cmd_bootm.c中的函数 do_bootm,因为引导kernel就是bootm这条命令的工作,do_bootm是命令bootm的执行函数现在我们来分析一下common/cmd_bootm.c中的函数do_bootm,这是bootm命令的处理函数.do_bootm()函数中的很多功能都是分成了函数的形式,而在以前的版本中没有这么有结构层次,这里我们也只是分析对引导Linux内核有作用的部分,因为这是一个在common文件夹下的文件,也就意味着,在引导别的操作系统时也会用到这个函数,而不单单是Linux操作系统.
int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
ulong iflag;
ulong load_end = 0;
int ret;
boot_os_fn *boot_fn;
#ifndef CONFIG_RELOC_FIXUP_WORKS
static int relocated = 0;
/* relocate boot function table */
if (!relocated) {
int i;
for (i = 0; i < ARRAY_SIZE(boot_os); i++)
if (boot_os[i] != NULL)
boot_os[i] += gd->reloc_off;
relocated = 1;
}
#endif
/* determine if we have a sub command */
if (argc > 1) {
char *endp;
simple_strtoul(argv[1], &endp, 16);
if ((*endp != 0) && (*endp != ':') && (*endp != '#'))
return do_bootm_subcommand(cmdtp, flag, argc, argv);
}
if (bootm_start(cmdtp, flag, argc, argv)) //提取mkimage生成的文件头部,放到bootm_headers_t结构体中
return 1;
iflag = disable_interrupts();
#if defined(CONFIG_CMD_USB)
usb_stop();
#endif
#ifdef CONFIG_AMIGAONEG3SE
/*
* We've possible left the caches enabled during
* bios emulation, so turn them off again
*/
icache_disable();
dcache_disable();
#endif
ret = bootm_load_os(images.os, &load_end, 1); //加载操作系统的关键部分 确定使用的地址
if (ret < 0) { //出错处理
if (ret == BOOTM_ERR_RESET)
do_reset (cmdtp, flag, argc, argv);
if (ret == BOOTM_ERR_OVERLAP) {
if (images.legacy_hdr_valid) {
if (image_get_type (&images.legacy_hdr_os_copy) == IH_TYPE_MULTI)
puts ("WARNING: legacy format multi component "
"image overwritten/n");
} else {
puts ("ERROR: new format image overwritten - "
"must RESET the board to recover/n");
show_boot_progress (-113);
do_reset (cmdtp, flag, argc, argv);
}
}
if (ret == BOOTM_ERR_UNIMPLEMENTED) {
if (iflag)
enable_interrupts();
show_boot_progress (-7);
return 1;
}
}
lmb_reserve(&images.lmb, images.os.load, (load_end - images.os.load));
if (images.os.type == IH_TYPE_STANDALONE) {//独立的应用程序
if (iflag)
enable_interrupts();
/* This may return when 'autostart' is 'no' */
bootm_start_standalone(iflag, argc, argv);
return 0;
}
show_boot_progress (8);
#ifdef CONFIG_SILENT_CONSOLE //这里处理Linux操作系统
if (images.os.os == IH_OS_LINUX)
fixup_silent_linux(); //该函数中处理bootarg参数
#endif
boot_fn = boot_os[images.os.os];
if (boot_fn == NULL) {
if (iflag)
enable_interrupts();
printf ("ERROR: booting os '%s' (%d) is not supported/n",
genimg_get_os_name(images.os.os), images.os.os);
show_boot_progress (-8);
return 1;
}
arch_preboot_os();
/*下面的函数,继续引导内核的镜像,复制image header 到全局变量header;
检查header的魔数,检查数,header和image中的这两个。确定image的体系结构和类型(KERNEL or MULTI),关闭中断,加载image到header中的加载地址*/
boot_fn(0, argc, argv, &images); //调用do_bootm_linux()函数
show_boot_progress (-9);
#ifdef DEBUG
puts ("/n## Control returned to monitor - resetting.../n");
#endif
do_reset (cmdtp, flag, argc, argv);
return 1;
}
static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)
{
uint8_t comp = os.comp;
ulong load = os.load;
ulong blob_start = os.start;
ulong blob_end = os.end;
ulong image_start = os.image_start;
ulong image_len = os.image_len;
uint unc_len = CONFIG_SYS_BOOTM_LEN;
const char *type_name = genimg_get_type_name (os.type);
switch (comp) { //判断image的压缩类型
case IH_COMP_NONE:
if (load == blob_start) {
printf (" XIP %s ... ", type_name);
} else {
printf (" Loading %s ... ", type_name);
//如果在Image head中加载的地址和bootm命令参数2指定的地址相同,则不需要复制,直接执行
if (load != image_start) {
memmove_wd ((void *)load,
(void *)image_start, image_len, CHUNKSZ);
}
}
*load_end = load + image_len;
puts("OK/n");
break;
case IH_COMP_GZIP:
printf (" Uncompressing %s ... ", type_name);
if (gunzip ((void *)load, unc_len,
(uchar *)image_start, &image_len) != 0) {
puts ("GUNZIP: uncompress, out-of-mem or overwrite error "
"- must RESET board to recover/n");
if (boot_progress)
show_boot_progress (-6);
return BOOTM_ERR_RESET;
}
*load_end = load + image_len;
break;
#ifdef CONFIG_BZIP2
case IH_COMP_BZIP2: //判断是什么类型的压缩类型
printf (" Uncompressing %s ... ", type_name);
int i = BZ2_bzBuffToBuffDecompress ((char*)load,
&unc_len, (char *)image_start, image_len,
CONFIG_SYS_MALLOC_LEN < (4096 * 1024), 0);
if (i != BZ_OK) {
printf ("BUNZIP2: uncompress or overwrite error %d "
"- must RESET board to recover/n", i);
if (boot_progress)
show_boot_progress (-6);
return BOOTM_ERR_RESET;
}
*load_end = load + unc_len;
break;
#endif /* CONFIG_BZIP2 */
#ifdef CONFIG_LZMA
case IH_COMP_LZMA:
printf (" Uncompressing %s ... ", type_name);
....................
return 0;
}
uboot源代码的tools/目录下有mkimage工具,这个工具可以用来制作不压缩或者压缩的多种可启动映象文件。
mkimage在制作映象文件的时候,是在原来的可执行映象文件的前面加上一个0x40字节的头,记录参数所指定的信息,这样uboot才能识别这个映象是针对哪个CPU体系结构的,哪个OS的,哪种类型,加载内存中的哪个位置, 入口点在内存的那个位置以及映象名是什么?到这里整个U-Boot是如何启动Linux内核的,基本上也就清楚了,特别是如何向Linux内核传送的参数。
* CPU register settings //这里也就是我们的theKernel中的作用
o r0 = 0.
o r1 = machine type number.
o r2 = physical address of tagged list in system RAM.
* CPU mode
o All forms of interrupts must be disabled (IRQs and FIQs.)
o The CPU must be in SVC mode. (A special exception exists for Angel.)
* Caches, MMUs
o The MMU must be off.
o Instruction cache may be on or off.
o Data cache must be off and must not contain any stale data.
* Devices
o DMA to/from devices should be quiesced.
* The boot loader is expected to call the kernel image by jumping directly to the first instruction of the kernel image.
转载: http://blog.csdn.net/lfj200701/article/details/5657902
- uboot启动流程二
- uboot 启动流程分析(二) — 第二阶段
- uboot 启动流程分析(二) — 第二阶段
- uboot启动流程分析之二
- uboot启动流程
- uboot启动流程
- uboot 启动流程分析
- Uboot 启动流程简介
- Uboot启动流程分析
- uboot启动流程
- uboot启动流程
- Uboot启动流程分析
- Uboot启动流程
- uboot 启动流程 freescale
- uboot启动流程-s3c2410
- G870 uboot启动流程
- uboot 启动流程
- Uboot 启动流程简介
- 【Paypal】网站付款标准版
- Hadoop平台优化综述
- Ruby/Rails及相关26本英文图书简评
- NDK的awk错误:Android NDK: Host 'awk' tool is outdated. Please define......
- Android基础
- uboot启动流程二
- C# Dictionary 的几种遍历方法
- 面试总结(1)
- 基于 Android NDK 的学习之旅-----环境搭建
- 早安励志,晚安温情
- IOCP中为什么使用WSAIoctl获取AcceptEx函数指针
- 祝大家新年快乐(论坛版主2011年全年总结。
- 如何在30岁前年薪超过30万
- wxWidget里面的Event Loop