start_kernel() -> setup_arch(&command_line) -> mdesc = setup_machine(machine_arch_type) -> list = lookup_machine_type(nr) -> return struct machine_desc.
內核在啟動的時候就是最先運行start_kernel() , 然后她就會調用體系結構相關的setup_arch(&command_line), 如arm體系結構的在arch/arm/kernel/setup.c中, 進一步, 她就要初始化板級相關的設備,?? 但在此之前, 她必須找到這塊目標板的描述結構, 所以她就先通過lookup_machine_type(nr)來查找這個結構, 傳入的參數(shù)是又uboot傳過來的, 存儲在r2中. 如假設她傳入的是'SMDK2410' 的nr, lookup_machine_type(nr) 就會找到如下的machine_desc. 這個結構在一個專門描述sddk2410的文件中--arch/arm/mach-s3c2410/mach-smdk2410.c
MACHINE_START(SMDK2410, "SMDK2410") /* @TODO: request a new identifier and switch
* to SMDK2410 */
/* Maintainer: Jonas Dietsche */
.phys_io??? = S3C2410_PA_UART,
.io_pg_offst??? = (((u32)S3C24XX_VA_UART) >> 18) & 0xfffc,
.boot_params??? = S3C2410_SDRAM_PA + 0x100,
//重要的板級初始化函數(shù)
.map_io? = smdk2410_map_io,
.init_irq??? = s3c24xx_init_irq,
.init_machine??? = smdk2410_init,
.timer? = &s3c24xx_timer,
MACHINE_END
MACHINE_START的第一個參數(shù)是用來構造機器的類型的, 如這里的SMDK2410 ,
又下面的定義
.nr? = MACH_TYPE_##_type
有 nr = MACH_TYPE_SMDK2410
而 MACH_TYPE_SMDK2410這些機器類型則在/include/asm-arm/mach-types.h中定義:
#define MACH_TYPE_SMDK2410 193
完整的結構描述如下:
struct machine_desc {
/*
* Note! The first four elements are used
* by assembler code in head-armv.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 :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????? (*map_io)(void);/* IO mapping function??? */
void????? (*init_irq)(void);
struct sys_timer??? *timer;? /* system tick timer??? */
void????? (*init_machine)(void);
};
/*
* 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??? \
};
在arch/arm/mach-s3c2410/mach-smdk2410.c 定義了以下兩個函數(shù)實現(xiàn):
static struct map_desc smdk2410_iodesc[] __initdata = {
/* nothing here yet */
};
static struct platform_device *smdk2410_devices[] __initdata = {
&s3c_device_usb,
&s3c_device_lcd,
&s3c_device_wdt,
&s3c_device_i2c,
&s3c_device_iis,
};
static void __init smdk2410_map_io(void)
{
//主要是做外圍設備的物理地址到虛擬地址的映射
s3c24xx_init_io(smdk2410_iodesc, ARRAY_SIZE(smdk2410_iodesc));
//頻率的初始化
s3c24xx_init_clocks(0);
//串口的初始化
s3c24xx_init_uarts(smdk2410_uartcfgs, ARRAY_SIZE(smdk2410_uartcfgs));
}
static void __init smdk2410_init(void)
{
//注冊smdk2410特有的設備
platform_add_devices(smdk2410_devices, ARRAY_SIZE(smdk2410_devices));
//smdk系列的初始化, 我們知道smdk有2410, 2412, 2440等等, 所以這里她又抽象出了一些共有的相同的部分, 都使用下面的函數(shù)做初始化工作.
smdk_machine_init();
}
/* devices we initialise */
static struct platform_device __initdata *smdk_devs[] = {
&s3c_device_nand,
&smdk_led4,
&smdk_led5,
&smdk_led6,
&smdk_led7,
};
void __init smdk_machine_init(void)
{
/* Configure the LEDs (even if we have no LED support)*/
s3c2410_gpio_cfgpin(S3C2410_GPF4, S3C2410_GPF4_OUTP);
s3c2410_gpio_cfgpin(S3C2410_GPF5, S3C2410_GPF5_OUTP);
s3c2410_gpio_cfgpin(S3C2410_GPF6, S3C2410_GPF6_OUTP);
s3c2410_gpio_cfgpin(S3C2410_GPF7, S3C2410_GPF7_OUTP);
s3c2410_gpio_setpin(S3C2410_GPF4, 1);
s3c2410_gpio_setpin(S3C2410_GPF5, 1);
s3c2410_gpio_setpin(S3C2410_GPF6, 1);
s3c2410_gpio_setpin(S3C2410_GPF7, 1);
if (machine_is_smdk2443())
smdk_nand_info.twrph0 = 50;
//注意這一行, 注冊了nand flash的分區(qū)信息
s3c_device_nand.dev.platform_data = &smdk_nand_info;
//再一次注冊設備, 但這一次是smdk共有的. 如nand flash等等
platform_add_devices(smdk_devs, ARRAY_SIZE(smdk_devs));
//電源管理的初始化
s3c2410_pm_init();
}
關鍵詞標簽:linux,板級設備
相關閱讀
熱門文章 安裝紅帽子RedHat Linux9.0操作系統(tǒng)教程 Tomcat9.0如何安裝_Tomcat9.0環(huán)境變量配置方法 多種操作系統(tǒng)NTP客戶端配置 Linux操作系統(tǒng)修改IP
人氣排行 Linux下獲取CPUID、硬盤序列號與MAC地址 dmidecode命令查看內存型號 linux tc實現(xiàn)ip流量限制 安裝紅帽子RedHat Linux9.0操作系統(tǒng)教程 linux下解壓rar文件 lcx.exe、nc.exe、sc.exe入侵中的使用方法 Ubuntu linux 關機、重啟、注銷 命令 查看linux服務器硬盤IO讀寫負載