原文地址:
http://blog.csdn.net/myarrow/article/details/8609564
1. 简介
内核提供了一个重要的结构体struct machine_desc ,这个结构体在内核移植中起到相当重要的作用,内核通过machine_desc结构体来控制系统体系架构相关部分的初始化。
machine_desc结构体通过MACHINE_START宏来初始化,在代码中, 通过在start_kernel->setup_arch中调用setup_machine_fdt来获取。
2. machine_desc结构体
machine_desc结构体定义如下:
-
-
struct machine_desc {
-
unsigned int nr;
-
const char *name;
-
unsigned long boot_params;
-
const char **dt_compat;
-
-
-
unsigned int nr_irqs;
-
-
unsigned int video_start;
-
unsigned int video_end;
-
-
unsigned int reserve_lp0 :1;
-
unsigned int reserve_lp1 :1;
-
unsigned int reserve_lp2 :1;
-
unsigned int soft_reboot :1;
-
void (*fixup)(struct machine_desc *,
-
struct tag *, char **,
-
struct meminfo *);
-
void (*reserve)(void);
-
void (*map_io)(void);
-
void (*init_early)(void);
-
void (*init_irq)(void);
-
struct sys_timer *timer;
-
void (*init_machine)(void);
-
#ifdef CONFIG_MULTI_IRQ_HANDLER
-
void (*handle_irq)(struct pt_regs *);
-
#endif
-
};
/* 在文件:arch/arm/include/asm/mach/arch.h */
struct machine_desc {
unsigned int nr; /* architecture number */
const char *name; /* architecture name */
unsigned long boot_params; /* tagged list */
const char **dt_compat; /* array of device tree
* 'compatible' strings */
unsigned int nr_irqs; /* number of IRQs */
unsigned int video_start; /* start of video RAM */
unsigned int video_end; /* end of video RAM */
unsigned int reserve_lp0 :1; /* never has lp0 */
unsigned int reserve_lp1 :1; /* never has lp1 */
unsigned int reserve_lp2 :1; /* never has lp2 */
unsigned int soft_reboot :1; /* soft reboot */
void (*fixup)(struct machine_desc *,
struct tag *, char **,
struct meminfo *);
void (*reserve)(void);/* reserve mem blocks */
void (*map_io)(void);/* IO mapping function */
void (*init_early)(void);
void (*init_irq)(void);
struct sys_timer *timer; /* system tick timer */
void (*init_machine)(void);
#ifdef CONFIG_MULTI_IRQ_HANDLER
void (*handle_irq)(struct pt_regs *);
#endif
};
3. machine_desc初始化
machine_desc初始化例子如下:
-
MACHINE_START(MA, "myboard")
-
.boot_params = PLAT_PHYS_OFFSET + 0x800,
-
.fixup = ma_fixup,
-
.reserve = &ma_reserve,
-
.map_io = ma_map_io,
-
.init_irq = ma_init_irq,
-
.timer = &ma_timer,
-
.init_machine = machine_ma_board_init,
-
MACHINE_END
MACHINE_START(MA, "myboard")
.boot_params = PLAT_PHYS_OFFSET + 0x800,
.fixup = ma_fixup,
.reserve = &ma_reserve, //内存在交给Linux管理之前,进行预留
.map_io = ma_map_io,
.init_irq = ma_init_irq,
.timer = &ma_timer,
.init_machine = machine_ma_board_init,
MACHINE_END
MACHINE_START和MACHINE_END宏定义如下:
-
-
-
-
-
#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 \
-
};
阅读(1092) | 评论(0) | 转发(0) |