Chinaunix首页 | 论坛 | 博客
  • 博客访问: 82260
  • 博文数量: 28
  • 博客积分: 65
  • 博客等级: 民兵
  • 技术积分: 115
  • 用 户 组: 普通用户
  • 注册时间: 2012-08-04 11:06
文章分类

全部博文(28)

文章存档

2014年(22)

2013年(5)

2012年(1)

我的朋友

分类: 嵌入式

2014-04-21 16:24:54

void __init setup_arch(char **cmdline_p)
{义变量

点击(此处)折叠或打开

  1. struct tag *tags = (struct tag *)&init_tags;
  2. struct machine_desc *mdesc;
  3. char *from = default_command_line;
unwind_init();
再次检测cpu
setup_processor();
再次检测Machine_ID 并返回board的结构体 struct machine_desc

点击(此处)折叠或打开

  1. mdesc = setup_machine(machine_arch_type);
  2. machine_desc = mdesc;
  3. machine_name = mdesc->name;
if (mdesc->soft_reboot)
reboot_setup("s");
if (__atags_pointer)     /*    __atags_pointer undefined    */
tags = phys_to_virt(__atags_pointer);
else if (mdesc->boot_params)    /*   执行    */
tags = phys_to_virt(mdesc->boot_params);


#if defined(CONFIG_DEPRECATED_PARAM_STRUCT)
if (tags->hdr.tag != ATAG_CORE)
convert_to_tag_list(tags);
#endif
if (tags->hdr.tag != ATAG_CORE)
tags = (struct tag *)&init_tags;
if (mdesc->fixup)
mdesc->fixup(mdesc, tags, &from, &meminfo);

解析uboot传递进来的tags setup.h中有
#define __tag  __used __attribute__((__section__(".taglist.init")))

#define __tagtable(tag, fn) \
static struct tagtable __tagtable_##fn  __tag = { tag, fn }
setup.c中 有

点击(此处)折叠或打开

  1. static int __init parse_tag_mem32(const struct tag *tag)
  2. {
  3. return arm_add_memory(tag->u.mem.start, tag->u.mem.size);
  4. }
  5. ___tagtable(ATAG_MEM, parse_tag_mem32);
宏替换后得到:
 static struct tagtable __tagtable_parse_tag_cmdline
   __used __attribute__((__section__(".taglist.init"))) //强制到taglist属性段
={ATAG_MEM, parse_tag_mem32      }  

解析uboot传进来的tags   
   

点击(此处)折叠或打开

  1. if (tags->hdr.tag == ATAG_CORE) {
  2. if (meminfo.nr_banks != 0)
  3. squash_mem_tags(tags);
  4. save_atags(tags);
  5. parse_tags(tags);// go
  6. }
  7.     

    点击(此处)折叠或打开

    1. static void __init parse_tags(const struct tag *t)
    2. {
    3.     for (; t->hdr.size; t = tag_next(t))
    4.         if (!parse_tag(t))
    5.             printk(KERN_WARNING
    6.                 "Ignoring unrecognised tag 0x%08x\n",
    7.                 t->hdr.tag);
    8. }     
               

    点击(此处)折叠或打开

    1. static int __init parse_tag(const struct tag *tag)
    2. {
    3.     extern struct tagtable __tagtable_begin, __tagtable_end;
    4.     struct tagtable *t;

    5.     for (t = &__tagtable_begin; t < &__tagtable_end; t++)
    6.         if (tag->hdr.tag == t->tag) {
    7.             t->parse(tag);
    8.             break;
    9.         }

    10.     return t < &__tagtable_end;
    11. }


init_mm.start_code = (unsigned long) _text;
init_mm.end_code   = (unsigned long) _etext;
init_mm.end_data   = (unsigned long) _edata;
init_mm.brk   = (unsigned long) _end;


/* parse_early_param needs a boot_command_line */
strlcpy(boot_command_line, from, COMMAND_LINE_SIZE);
/* populate cmd_line too for later use, preserving boot_command_line */
strlcpy(cmd_line, boot_command_line, COMMAND_LINE_SIZE);
*cmdline_p = cmd_line;
/* *****执行一些先期命令 *******/
parse_early_param();

点击(此处)折叠或打开

  1. struct obs_kernel_param {
  2.     const char *str;
  3.     int (*setup_func)(char *);
  4.     int early;  //是否为早期处理函数
  5. };
关于early和非early的函数

点击(此处)折叠或打开

  1. #define __setup_param(str, unique_id, fn, early)            \
  2.     static const char __setup_str_##unique_id[] __initconst    \
  3.         __aligned(1) = str; \
  4.     static struct obs_kernel_param __setup_##unique_id    \
  5.         __used __section(.init.setup)            \
  6.         __attribute__((aligned((sizeof(long)))))    \
  7.         = { __setup_str_##unique_id, fn, early }

  8. #define __setup(str, fn)     \
  9. __setup_param(str, fn, fn, 0)

  10. #define early_param(str, fn)                    \
  11.     __setup_param(str, fn, fn, 1)
  12. 对下面函数
  13. static int __init init_setup(char *str)
  14. {unsigned int i;
  15. execute_command = str;
  16. for (i = 1; i < MAX_INIT_ARGS; i++)
  17. argv_init[i] = NULL;return 1;}
  18. __setup("init=", init_setup);
  19. 宏替换得:
  20. static const char __setup_str_init_setup[] __initconst __aligned(1) = "init="; 
  21. static struct obs_kernel_param  __setup_init_setup   
  22.   __used __section(.init.setup)     __attribute__((aligned((sizeof(long)))))    
  23.        = { __setup_str_init_setup, init_setup, 0 }

  24. 对下面函数:
  25. static int __init nosmp(char *str)
  26. {
  27. setup_max_cpus = 0;
  28. arch_disable_smp_support();
  29. return 0;
  30. }
  31. early_param("nosmp", nosmp);
  32. 宏替换得: 
  33. static const char __setup_str_nosmp[] __initconst  __aligned(1) = nosmp; 
  34.   static struct obs_kernel_param   __setup_nosmp  
  35.     __used __section(.init.setup)        __attribute__((aligned((sizeof(long)))))   
  36.     = { __setup_str_nosmp, nosmp} 


arm_memblock_init(&meminfo, mdesc);
/******最终调用了medesc->map_io()*****/
paging_init(mdesc);
/****paging_init(mdesc)-->  devicemaps_init(mdesc)-->mdesc->map_io()
如果平台为smdk2440的board则相当于调用了smdk2440_map_io在mach-smdk2440.c中定义****/

request_standard_resources(mdesc);
#ifdef CONFIG_SMP
if (is_smp())
smp_init_cpus();
#endif
reserve_crashkernel();
cpu_init();
tcm_init();
#ifdef CONFIG_MULTI_IRQ_HANDLER
handle_arch_irq = mdesc->handle_irq;
#endif
#ifdef CONFIG_VT
#if defined(CONFIG_VGA_CONSOLE)
conswitchp = &vga_con;
#elif defined(CONFIG_DUMMY_CONSOLE)
conswitchp = &dummy_con;
#endif
#endif
early_trap_init();

/*如果设备描述结构体定义了init_early函数(应该是早期初始化之意),则在这里调用。*/
if (mdesc->init_early)
mdesc->init_early();
}

阅读(2166) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~