QQ2440V3
kernel 2.6.13
看linux启动过程,一直想搞清楚kernel是如何知道RAM大小的。
这个要先从VIVI启动说起。
1.VIVI
/vivi/lib/boot_kernel.c
static void setup_linux_param(ulong param_base)
{
struct param_struct *params = (struct param_struct *)param_base;
char *linux_cmd;
printk("Setup linux parameters at 0x%08lx\n", param_base);
memset(params, 0, sizeof(struct param_struct));
params->u1.s.page_size = LINUX_PAGE_SIZE;
params->u1.s.nr_pages = (DRAM_SIZE >> LINUX_PAGE_SHIFT);
...
}
|
在函数setup_linux_param设置了page_size与nr_pages,输入的参数param_base为0x3000000+0x100,也就是把RAM的信息保存在内存的0x100处。
接下来看kernel如何处理
2.kernel
1) 指定boot_params位置
/arch/arm/mach-s3c2410.c
MACHINE_START(SBC2440, "SBC2440")
.phys_ram = S3C2410_SDRAM_PA,
.phys_io = S3C2410_PA_UART,
.io_pg_offst = (((u32)S3C24XX_VA_UART) >> 18) & 0xfffc,
.boot_params = S3C2410_SDRAM_PA + 0x100,
.init_irq = sbc2440_init_irq,
.map_io = sbc2440_map_io,
.init_machine = sbc2440_init,
.timer = &s3c24xx_timer,
MACHINE_END
|
见红体字部分,在machine_desc中设置boot_params为0x30000000+0x100
2)读取boot param
void __init setup_arch(char **cmdline_p)
{
struct tag *tags = (struct tag *)&init_tags;
struct machine_desc *mdesc;
char *from = default_command_line;
setup_processor();
mdesc = setup_machine(machine_arch_type);
machine_name = mdesc->name;
if (mdesc->soft_reboot)
reboot_setup("s");
if (mdesc->boot_params)
tags = phys_to_virt(mdesc->boot_params);
/*
* If we have the old style parameters, convert them to
* a tag list.
*/
if (tags->hdr.tag != ATAG_CORE)
convert_to_tag_list(tags);
if (tags->hdr.tag != ATAG_CORE)
tags = (struct tag *)&init_tags;
if (mdesc->fixup)
mdesc->fixup(mdesc, tags, &from, &meminfo);
if (tags->hdr.tag == ATAG_CORE) {
if (meminfo.nr_banks != 0)
squash_mem_tags(tags);
parse_tags(tags);
}
...
|
见加红部分。
如果指定了boot_params,tags指向0x30000000+0x100处,接着调用convert_to_tag_list把boot_params转化为struct tag结构。
就这样把ram大小传递给kernel
阅读(1146) | 评论(0) | 转发(0) |