ARM linux的启动部分源代码简略分析
673 mdesc = setup_machine(machine_arch_type);
674 machine_name = mdesc->name;
675
676 if (mdesc->soft_reboot)
677 reboot_setup("s");
678
679 if (__atags_pointer)
680 tags = phys_to_virt(__atags_pointer);
681 else if (mdesc->boot_params)
682 tags = phys_to_virt(mdesc->boot_params);
683
684 /*
685 * If we have the old style parameters, convert them to
686 * a tag list.
687 */
688 if (tags->hdr.tag != ATAG_CORE)
689 convert_to_tag_list(tags);
690 if (tags->hdr.tag != ATAG_CORE)
691 tags = (struct tag *)&init_tags;
692
693 if (mdesc->fixup)
694 mdesc->fixup(mdesc, tags, &from, &meminfo);
695
696 if (tags->hdr.tag == ATAG_CORE) {
697 if (meminfo.nr_banks != 0)
698 squash_mem_tags(tags);
699 save_atags(tags);
700 parse_tags(tags);
701 }
702
703 init_mm.start_code = (unsigned long) _text;
704 init_mm.end_code = (unsigned long) _etext;
705 init_mm.end_data = (unsigned long) _edata;
706 init_mm.brk = (unsigned long) _end;
707
708 /* parse_early_param needs a boot_command_line */
709 strlcpy(boot_command_line, from, COMMAND_LINE_SIZE);
710
711 /* populate cmd_line too for later use, preserving boot_command_line */
712 strlcpy(cmd_line, boot_command_line, COMMAND_LINE_SIZE);
713 *cmdline_p = cmd_line;
714
715 parse_early_param();
716
717 paging_init(mdesc);
718 request_standard_resources(&meminfo, mdesc);
719
720 #ifdef CONFIG_SMP
721 smp_init_cpus();
722 #endif
723
724 cpu_init();
725 tcm_init();
726
727 /*
728 * Set up various architecture-specific pointers
729 */
730 init_arch_irq = mdesc->init_irq;
731 system_timer = mdesc->timer;
732 init_machine = mdesc->init_machine;
733
734 #ifdef CONFIG_VT
735 #if defined(CONFIG_VGA_CONSOLE)
736 conswitchp = &vga_con;
737 #elif defined(CONFIG_DUMMY_CONSOLE)
738 conswitchp = &dummy_con;
739 #endif
740 #endif
741 early_trap_init();
742 }
来看一些我们比较感兴趣的地方:
1、666行,struct tag指针类型的局部变量指向了默认的tag列表init_tags,该静态变量在setup_arch()定义同文件的前面有如下定义:
636 /*
637 * This holds our defaults.
638 */
639 static struct init_tags {
640 struct tag_header hdr1;
641 struct tag_core core;
642 struct tag_header hdr2;
643 struct tag_mem32 mem;
644 struct tag_header hdr3;
645 } init_tags __initdata = {
646 { tag_size(tag_core), ATAG_CORE },
647 { 1, PAGE_SIZE, 0xff },
648 { tag_size(tag_mem32), ATAG_MEM },
649 { MEM_SIZE, PHYS_OFFSET },
650 { 0, ATAG_NONE }
651 };
第679行检察__atags_pointer指针的有效性,这个指针是在前面,跳转到start_kernel函数的汇编例程最后设置的几个变量之一,用的是R2寄存器的值。如果bootloader通过R2传递了tag列表的话,自然是要使用bootloader穿的进来的tag列表的。
2、第688行的字符指针类型的局部变量from指向了default_command_line静态变量,这个变量同样在前面有定义:
124 static char default_command_line[COMMAND_LINE_SIZE] __initdata = CONFIG_CMDLINE;
传递给内核的命令行参数,是可以在内核配置的时候设置的。
3、第673行以machine_arch_type为参数调用了setup_machine()函数,而这个函数的定义为:
369 static struct machine_desc * __init setup_machine(unsigned int nr)
370 {
371 struct machine_desc *list;
372
373 /*
374 * locate machine in the list of supported machines.
375 */
376 list = lookup_machine_type(nr);
377 if (!list) {
378 printk("Machine configuration botched (nr %d), "
379 " unable to continue.\n", nr);
380 while (1);
381 }
382
383 printk("Machine: %s\n", list->name);
384
385 return list;
386 }
在arch/arm/kernel/head-common.S文件中,我们看到了一个对于__lookup_machine_type例程的封装的可被C语言程序调用的汇编语言编写的函数lookup_machine_type(),接收机器号,查表,然后返回匹配的struct machine_desc结构体的指针。在这里,对于我们的mini2440,返回的自然是arch/arm/mach-s3c2440/ mach-mini2440.c文件中定义的结构体了:
MACHINE_START(MINI2440, "MINI2440")
/* Maintainer: Michel Pollet
.phys_io =
ARMlinux启 相关文章:
- ARM Linux 更新启动画面(11-21)
- ARM Linux启动分析headarmv.S内幕(11-09)
- arm linux 启动流程(11-09)
- ARM Linux 的启动过程(11-09)
- arm linux 启动流程之 进入内核(11-09)
- ARM Linux启动代码分析(11-09)