转自:http://blog.csdn.net/cxw3506/article/details/8475965

版权声明:本文为博主原创文章,未经博主允许不得转载。

在移植Linux时,有个结构体需要填写,它以MACHINE_START开始并以MACHINE_END结束,如下mini2440开发板的移植为示例
[cpp] view plain copy MACHINE_START(MINI2440, "MINI2440")
.phys_io = S3C2410_PA_UART,
.io_pg_offst = (((u32)S3C24XX_VA_UART) >> ) & 0xfffc,
.boot_params = S3C2410_SDRAM_PA + 0x100,
.map_io = mini2440_map_io,
.init_machine = mini2440_init,
.init_irq = s3c24xx_init_irq,
.timer = &s3c24xx_timer,
MACHINE_END 其中MACHINE_START、MACHINE_END都是定义的宏,代码如下
[cpp] view plain copy /*
* Set of macros to define architecture features. This is built into
* a table by the linker.
*/
#define MACHINE_START(_type,_name) \
static const struct machine_desc __mach_desc_##_type \
__used \
__attribute__((__section__(".arch.info.init"))) = { \
.nr = MACH_TYPE_##_type, \
.name = _name, #define MACHINE_END \
}; 由上代码可知这两个宏一起定义了一个类型为struct machine_desc的变量,结构体定义如下
[cpp] view plain copy struct machine_desc {
/*
* Note! The first four elements are used
* by assembler code in head.S, head-common.S
*/
unsigned int nr; /* architecture number */
unsigned int phys_io; /* start of physical io */
unsigned int io_pg_offst; /* byte offset for io
* page tabe entry */ const char *name; /* architecture name */
unsigned long boot_params; /* tagged list */ unsigned int video_start; /* start of video RAM */
unsigned int video_end; /* end of video RAM */ unsigned int reserve_lp0 :; /* never has lp0 */
unsigned int reserve_lp1 :; /* never has lp1 */
unsigned int reserve_lp2 :; /* never has lp2 */
unsigned int soft_reboot :; /* soft reboot */
void (*fixup)(struct machine_desc *,
struct tag *, char **,
struct meminfo *);
void (*map_io)(void);/* IO mapping function */
void (*init_irq)(void);
struct sys_timer *timer; /* system tick timer */
void (*init_machine)(void);
}; 这个类型的变量放在内核代码段.arch.info.init中,在内核运行初期,被函数lookup_machine_type(此函数用汇编实现,在汇编文件中)取出,读取流程为 Start_kernel() -> setup_arch() -> setup_machine() -> lookup_machine_type() 在函数setup_machine()中,利用这个结构体类型的变量初始化一些全局变量,以备内核运行时使用,比如 init_arch_irq = mdesc->init_irq; system_timer = mdesc->timer; init_machine = mdesc->init_machine; 这个结构体中,成员init_machine保存的是开发板资源注册的初始化代码,init_irq保存的是中断初始化指针,timer保存的是一个struct sys_timer类型的指针…..如果我们要给自己的开发板定制内核,那么我们必须自己实现以上成员函数,其中函数init_machine()是我们向内核传递开发板设备信息的重要的常规途径,分析mini2440开发板内核移植代码知道,在这个函数中,注册了开发板所用到的所有设备的相关硬件信息! [cpp] view plain copy static void __init mini2440_init(void)
{
struct mini2440_features_t features = { };
int i; printk(KERN_INFO "MINI2440: Option string mini2440=%s\n",
mini2440_features_str); /* Parse the feature string */
mini2440_parse_features(&features, mini2440_features_str); /* turn LCD on */
s3c_gpio_cfgpin(S3C2410_GPC(), S3C2410_GPC0_LEND); /* Turn the backlight early on */
WARN_ON(gpio_request(S3C2410_GPG(), "backlight"));
gpio_direction_output(S3C2410_GPG(), ); /* remove pullup on optional PWM backlight -- unused on 3.5 and 7"s */
s3c_gpio_setpull(S3C2410_GPB(), S3C_GPIO_PULL_UP);
s3c2410_gpio_setpin(S3C2410_GPB(), );
s3c_gpio_cfgpin(S3C2410_GPB(), S3C2410_GPIO_INPUT); /* Make sure the D+ pullup pin is output */
WARN_ON(gpio_request(S3C2410_GPC(), "udc pup"));
gpio_direction_output(S3C2410_GPC(), ); /* mark the key as input, without pullups (there is one on the board) */
for (i = ; i < ARRAY_SIZE(mini2440_buttons); i++) {
s3c_gpio_setpull(mini2440_buttons[i].gpio, S3C_GPIO_PULL_UP);
s3c_gpio_cfgpin(mini2440_buttons[i].gpio, S3C2410_GPIO_INPUT);
}
if (features.lcd_index != -) {
int li; mini2440_fb_info.displays =
&mini2440_lcd_cfg[features.lcd_index]; printk(KERN_INFO "MINI2440: LCD");
for (li = ; li < ARRAY_SIZE(mini2440_lcd_cfg); li++)
if (li == features.lcd_index)
printk(" [%d:%dx%d]", li,
mini2440_lcd_cfg[li].width,
mini2440_lcd_cfg[li].height);
else
printk(" %d:%dx%d", li,
mini2440_lcd_cfg[li].width,
mini2440_lcd_cfg[li].height);
printk("\n");
s3c24xx_fb_set_platdata(&mini2440_fb_info);
} s3c24xx_udc_set_platdata(&mini2440_udc_cfg);
s3c24xx_mci_set_platdata(&mini2440_mmc_cfg);
s3c_nand_set_platdata(&mini2440_nand_info);
s3c_i2c0_set_platdata(NULL); i2c_register_board_info(, mini2440_i2c_devs,
ARRAY_SIZE(mini2440_i2c_devs)); platform_add_devices(mini2440_devices, ARRAY_SIZE(mini2440_devices)); if (features.count) /* the optional features */
platform_add_devices(features.optional, features.count); } 那么成员函数init_machine什么时候被调用呢? 在函数setup_machine()中有一条语句init_machine = mdesc->init_machine;其中init_machine为全局函数指针变量,此变量在函数customize_machine()中被调用,代码如下所示:
[cpp] view plain copy static int __init customize_machine(void) { /* customizes platform devices, or adds new ones */ if (init_machine) init_machine(); return ; } arch_initcall(customize_machine); 在MACHINE_START与MACHINE_END之间还要填写一些参数,参照结构体注释小心填写即可,最好找个例子参考参考。

MACHINE_START与MACHINE_END【转】的更多相关文章

  1. linux中MACHINE_START&END在9g10ek上实现

    在linux的板卡初始化文件中有machine的相关定义 //arch/arm/mach-at91/board-sam9261ek.c MACHINE_START(AT91SAM9G10EK, &qu ...

  2. ARM Linux 3.x的设备树(Device Tree)

    http://blog.csdn.net/21cnbao/article/details/8457546 宋宝华 Barry Song <21cnbao@gmail.com> 1.     ...

  3. ARM Linux 3.x的设备树(Device Tree)

    1. ARM Device Tree起源 Linus Torvalds在2011年3月17日的ARM Linux邮件列表宣称“this whole ARM thing is a f*cking pai ...

  4. platform_device与platform_driver

    转自:http://blog.csdn.net/zhandoushi1982/article/details/5130207 做Linux方面也有三个多月了,对代码中的有些结构一直不是很明白,比如pl ...

  5. 【转】 ARM Linux 3.x的设备树(Device Tree)

    1.    ARM Device Tree起源 http://blog.csdn.net/21cnbao/article/details/8457546 Linus Torvalds在2011年3月1 ...

  6. 基于linux2.6.38.8内核启动过程完全解析[一]

    转载: ************************************************************************************************ ...

  7. ARM-Linux S5PV210 UART驱动(6)----platform device的添加

    开发板是飞凌OK210 arch/arm/mach-s5pv210/mach-smdkc110.c 首先是UART的寄存器默认配置信息: /* Following are default values ...

  8. 【转】ARM Linux 3.x的设备树(Device Tree)

    原文网址:http://blog.csdn.net/21cnbao/article/details/8457546 1.    ARM Device Tree起源 Linus Torvalds在201 ...

  9. 移植Linux-3.4.2内核到S3C2440

    一.BootLoader引导内核过程     1.Bootloader的工作     1.1.将内核读入内存     2.2.保存内核启动参数到指定位置,内核启动时去这个位置解析参数     3.3. ...

随机推荐

  1. Spring MVC实践

    MVC 设计概述 在早期 Java Web 的开发中,统一把显示层.控制层.数据层的操作全部交给 JSP 或者 JavaBean 来进行处理,我们称之为 Model1: 出现的弊端: JSP 和 Ja ...

  2. BZOJ4011 HNOI2015落忆枫音(动态规划+拓扑排序)

    DAG中每个点选一条入边就可以构成一棵有向树,所以如果没有环答案就是∏degreei. 考虑去掉含环的答案.可以看做把环缩点,剩下的点仍然可以任意选入边.于是去除的方案数即为∏degreei/∏deg ...

  3. 【SPOJ - GSS2】Can you answer these queries II(线段树)

    区间连续不重复子段最大值,要维护历史的最大值和当前的最大值,打两个lazy,离线 #include<cstdio> #include<cstring> #include< ...

  4. [HNOI2012][BZOJ2732] 射箭 [二分+半平面交]

    题面 BZOJ题面 思路 半平面交代码讲解戳这里,用的就是这道题 我们射箭的函数形如$y=Ax^2+Bx$ 考虑每一个靶子$(x_0,y_1,y_2)$,实际上是关于$A,B$的不等式限制条件 我们只 ...

  5. [NOI2001]炮兵阵地 状压DP

    题面: 司令部的将军们打算在N*M的网格地图上部署他们的炮兵部队.一个N*M的地图由N行M列组成,地图的每一格可能是山地(用“H” 表示),也可能是平原(用“P”表示),如下图.在每一格平原地形上最多 ...

  6. 【BZOJ1486】最小圈(分数规划)

    [BZOJ1486]最小圈(分数规划) 题面 BZOJ 洛谷 求图中边权和除以点数最小的环 题解 分数规划 二分答案之后将边权修改为边权减去二分值 检查有无负环即可 #include<iostr ...

  7. BZOJ1060:[ZJOI2007]时态同步——题解

    http://www.lydsy.com/JudgeOnline/problem.php?id=1060 https://www.luogu.org/problemnew/show/P1131 小Q在 ...

  8. BZOJ4896 [Thu Summer Camp2016]补退选 【trie树】

    题目链接 BZOJ4896 题解 \(thu\)怎么那么喜欢出\(trie\)树的题... 我们当然可以按题意模拟建\(trie\) 询问的时候,由于存在删除操作,不满足单调性,不能直接二分答案 我们 ...

  9. maven打包jar源码至私服

    1. setting文件 配置私服中设置的用户和密码 <servers> <server> <id>releases</id> <username ...

  10. Apache 403 错误解决方法-让别人可以访问你的服务器(转)

    有一次做好了一个效果放在自己电脑的服务器上,让同学查看(同处于校园网中),却不知apache一直显示403 错误,对方没有权限访问,我知道这应该是配置文件httpd.conf中的问题,网上搜了一下其他 ...