Arm linux 内核移植及系统初始化过程分析.docx

上传人:b****2 文档编号:24242915 上传时间:2023-05-25 格式:DOCX 页数:26 大小:25.23KB
下载 相关 举报
Arm linux 内核移植及系统初始化过程分析.docx_第1页
第1页 / 共26页
Arm linux 内核移植及系统初始化过程分析.docx_第2页
第2页 / 共26页
Arm linux 内核移植及系统初始化过程分析.docx_第3页
第3页 / 共26页
Arm linux 内核移植及系统初始化过程分析.docx_第4页
第4页 / 共26页
Arm linux 内核移植及系统初始化过程分析.docx_第5页
第5页 / 共26页
点击查看更多>>
下载资源
资源描述

Arm linux 内核移植及系统初始化过程分析.docx

《Arm linux 内核移植及系统初始化过程分析.docx》由会员分享,可在线阅读,更多相关《Arm linux 内核移植及系统初始化过程分析.docx(26页珍藏版)》请在冰豆网上搜索。

Arm linux 内核移植及系统初始化过程分析.docx

Armlinux内核移植及系统初始化过程分析

第四届云计算大会门票抢购:

史上最低价,每日限5张!

【分享季1】:

网友推荐130个经典资源,分享再赠分!

Armlinux内核移植及系统初始化过程分析

分类:

Linux2011-03-2514:

48282人阅读评论(0)收藏举报

================================================================

浅谈分析Armlinux内核移植及系统初始化的过程

(一)

================================================================

学习嵌入式ARMlinux,主要想必三个方向发展:

1、嵌入式linux应用软件开发

2、linux内核的剪裁和移植

3、嵌入式linux底层驱动的开发

本文就Armlinux内核移植及系统初始化过程进行分析:

咨询QQ:

313807838

主要介绍内核移植过程中涉及文件的分布及其用途,以及简单介绍系统的初始化过程。

整个armlinux内核的启动可分为三个阶段:

第一阶段主要是进行cpu和体系结构的检查、cpu本身的初始化以及页表的建立等;第二阶段主要是对系统中的一些基础设施进行初始化;最后则是更高层次的初始化,如根设备和外部设备的初始化。

了解系统的初始化过程,有益于更好地移植内核。

1.内核移植

2.涉及文件分布介绍

2.1.内核移植

2.2.涉及的头文件

/linux-2.6.18.8/include

[root@localhostinclude]#tree-L1

.

|--Kbuild

|--acpi

|--asm->asm-arm

|--asm-alpha

|--asm-arm------------------------------->

(1)

|--asm-sparc

|--asm-sparc64

|--config

|--keys

|--linux------------------------------->

(2)

|--math-emu

|--media

|--mtd

|--net

|--pcmcia

|--rdma

|--rxrpc

|--scsi

|--sound

`--video

内核移植过程中涉及到的头文件包括处理器相关的头文件

(1)和处理器无关的头文件

(2)。

2.3.内核移植2.4.涉及的源文件

/linux-2.6.18.8/arch/arm

[root@localhostarm]#tree-L1

.

|--Kconfig

|--Kconfig-nommu

|--Kconfig.debug

|--Makefile

|--boot------------------------------->

(2)

|--common

|--configs

|--kernel------------------------------->(3)

|--lib

|--mach-at91rm9200

……

|--mach-omap1

|--mach-omap2

|--mach-realview

|--mach-rpc

|--mach-s3c2410------------------------------->(4)

|--mach-sa1100

|--mach-versatile

|--mm------------------------------->(5)

|--nwfpe

|--oprofile

|--plat-omap

|--tools------------------------------->

(1)

`--vfp

(1)

/linux-2.6.18.8/arch/arm/tools

[root@localhosttools]#tree-L1

.

|--Makefile

|--gen-mach-types

`--mach-types

Mach-types文件定义了不同系统平台的系统平台号。

移植linux内核到新的平台上需要对新的平台登记系统平台号。

Mach-types文件格式如下:

#machine_is_xxxCONFIG_xxxxMACH_TYPE_xxxnumber

s3c2410ARCH_S3C2410S3C2410182

smdk2410ARCH_SMDK2410SMDK2410193

之所以需要这些信息,是因为脚本文件linux/arch/arm/tools/gen-mach-types需要linux/arch/tools/mach-types来产生linux/include/asm-arm/mach-types.h文件,该文件中设置了一些宏定义,需要这些宏定义来为目标系统选择合适的代码。

(2)

linux-2.6.18.8/arch/arm/boot/compressed

[root@localhostcompressed]#tree-L1

.

|--Makefile

|--Makefile.debug

|--big-endian.S

|--head-at91rm9200.S

2浅谈分析Armlinux内核移植及系统初始化的过程

|--head.S

|--ll_char_wr.S

|--misc.c

|--ofw-shark.c

|--piggy.S

`--vmlinux.lds.in

Head.s是内核映像的入口代码,是自引导程序。

自引导程序包含一些初始化程序,这些程序都是体系结构相关的。

在对系统作完初始化设置工作后,调用misc.c文件中的decompress_kernel()函数解压缩内核映像到指定的位置,然后跳转到kernel的入口地址。

Vmlinux.lds.in用来生成内核映像的内存配置文件。

(3)

linux-2.6.18.8/arch/arm/kernel

[root@localhostkernel]#tree-L1

.

|--Makefile

|--apm.c

|--armksyms.c

|--arthur.c

|--asm-offsets.c

|--bios32.c

|--calls.S

|--dma.c

|--ecard.c

|--entry-armv.S

|--entry-common.S

|--entry-header.S

|--fiq.c

|--head-common.S

|--head-nommu.S

|--head.S

|--init_task.c

|--io.c

|--irq.c

|--isa.c

|--module.c

|--process.c

|--ptrace.c

|--ptrace.h

|--semaphore.c

|--setup.c

|--smp.c

|--sys_arm.c

|--time.c

|--traps.c

`--vmlinux.lds.S

内核入口处也是由一段汇编语言实现的,由head.s和head-common.s两个文件组成。

Head.s是内核的入口文件,在head.s的末尾处#include"head-common.S"。

经过一系列的初始化后,跳转到linux-2.6.18.8/init/main.c中的start_kernel()函数中,开始内核的基本初始化过程。

/linux-2.6.18.8/init

[root@localhostinit]#tree

.

|--Kconfig

|--Makefile

|--calibrate.c

|--do_mounts.c

|--do_mounts.h

|--do_mounts_initrd.c

|--do_mounts_md.c

|--do_mounts_rd.c

|--initramfs.c

|--main.c

`--version.c

(4)

/linux-2.6.18.8/arch/arm/mach-s3c2410

[root@localhostmach-s3c2410]#tree-L1

.

|--Kconfig

|--Makefile

|--Makefile.boot

|--bast-irq.c

|--bast.h

|--clock.c

|--clock.h

|--common-smdk.c

|--common-smdk.h

|--cpu.c

|--cpu.h

|--devs.c

|--devs.h

|--dma.c

|--gpio.c

|--irq.c

|--irq.h

|--mach-anubis.c

|--mach-smdk2410.c

|--pm-simtec.c

|--pm.c

|--pm.h

|--s3c2400-gpio.c

|--s3c2400.h

|--s3c2410-clock.c

|--s3c2410-gpio.c

|--s3c2410.c

|--s3c2410.h

|--sleep.S

|--time.c

|--usb-simtec.c

`--usb-simtec.h

这个目录中的文件都是板级相关的,其中比较重要是如下几个:

linux/arch/arm/mach-s3c2410/cpu.c

linux/arch/arm/mach-s3c2410/common-smdk.c

linux/arch/arm/mach-s3c2410/devs.c

linux/arch/arm/mach-s3c2410/mach-smdk2410.c

linux/arch/arm/mach-s3c2410/Makefile.boot

linux/arch/arm/mach-s3c2410/s3c2410.c

3.处理器和设备4.

这里主要介绍处理器和设备的描述和操作过程。

设备描述在linux/arch/arm/mach-s3c2410/devs.c和linux/arch/arm/mach-s3c2410/common-smdk.c中实现。

最后以nandflash为例具体介绍。

================================================================

浅谈分析Armlinux内核移植及系统初始化的过程

(二)

================================================================

3浅谈分析Armlinux内核移植及系统初始化的过程。

咨询QQ:

313807838

4.1.处理器、设备4.2.描述

设备描述主要两个结构体完成:

structresource和structplatform_device。

先来看看着两个结构体的定义:

structresource{

resource_size_tstart;

resource_size_tend;

constchar*name;

unsignedlongflags;

structresource*parent,*sibling,*child;

};

Resource结构体主要是描述了设备在系统中的起止地址、名称、标志以及为了链式描述方便指向本结构体类型的指针。

Resource定义的实例将被添加到platform_device结构体对象中去。

structplatform_device{

constchar*name;

u32id;

structdevicedev;

u32num_resources;

structresource*resource;

};

Platform_device结构体包括结构体的名称、ID号、平台相关的信息、设备的数目以及上面定义的resource信息。

Platform_device结构对象将被直接通过设备操作函数注册导系统中去。

具体注册和注销过程在下一节介绍。

4.3.处理器、设备4.4.操作

(1)intplatform_device_register(structplatform_device*pdev);注册设备

(2)voidplatform_device_unregister(structplatform_device*pdev);注销设备

(3)intplatform_add_devices(structplatform_device**devs,intnum);添加设备,通过调用上面两个函数实现。

4.5.添加Nandflash设备4.6.

下面以nandflash设备的描述为例,具体介绍下设备的描述和注册过程。

//resource结构体实例s3c_nand_resource对nandflash控制器描述,包括控制器的起止地址和标志。

staticstructresources3c_nand_resource[]={

[0]={

.start=S3C2410_PA_NAND,

.end=S3C2410_PA_NAND+S3C24XX_SZ_NAND-1,

.flags=IORESOURCE_MEM,

}

};

//platform_device结构体实例s3c_device_nand定义了设备的名称、ID号并把resource对象作为其成员之一。

structplatform_devices3c_device_nand={

.name="s3c2410-nand",

.id=-1,

.num_resources=ARRAY_SIZE(s3c_nand_resource),

.resource=s3c_nand_resource,

};

//nandflash的分区情况,由mtd_partition结构体定义。

staticstructmtd_partitionsmdk_default_nand_part[]={

[0]={

.name="BootAgent",

.size=SZ_16K,

.offset=0,

},

[1]={

.name="S3C2410flashpartition1",

.offset=0,

.size=SZ_2M,

},

[2]={

.name="S3C2410flashpartition2",

.offset=SZ_4M,

.size=SZ_4M,

},

[3]={

.name="S3C2410flashpartition3",

.offset=SZ_8M,

.size=SZ_2M,

},

[4]={

.name="S3C2410flashpartition4",

================================================================

浅谈分析Armlinux内核移植及系统初始化的过程(三)

================================================================

4、浅谈分析Armlinux内核移植及系统初始化的过程QQ:

313807838

.offset=SZ_1M*10,

.size=SZ_4M,

},

[5]={

.name="S3C2410flashpartition5",

.offset=SZ_1M*14,

.size=SZ_1M*10,

},

[6]={

.name="S3C2410flashpartition6",

.offset=SZ_1M*24,

.size=SZ_1M*24,

},

[7]={

.name="S3C2410flashpartition7",

.offset=SZ_1M*48,

.size=SZ_16M,

}

};

staticstructs3c2410_nand_setsmdk_nand_sets[]={

[0]={

.name="NAND",

.nr_chips=1,

.nr_partitions=ARRAY_SIZE(smdk_default_nand_part),

.partitions=smdk_default_nand_part,

},

};

/*chooseasetoftimingswhichshouldsuitmost512Mbit

*chipsandbeyond.

*/

staticstructs3c2410_platform_nandsmdk_nand_info={

.tacls=20,

.twrph0=60,

.twrph1=20,

.nr_sets=ARRAY_SIZE(smdk_nand_sets),

.sets=smdk_nand_sets,

};

/*devicesweinitialise*/

//最后将nandflash设备加入到系统即将注册的设备集合中。

staticstructplatform_device__initdata*smdk_devs[]={

&s3c_device_nand,

&smdk_led4,

&smdk_led5,

&smdk_led6,

&smdk_led7,

};

然后通过smdk_machine_init()函数,调用设备添加函数platform_add_devices(smdk_devs,ARRAY_SIZE(smdk_devs))完成设备的注册。

具体过程参见系统初始化的相关部分。

5.系统初始化

5.1.系统初始化的主干线

Start_kernel()èsetup_arch()èreset_init()èkernel_thread(init…)èinit()èdo_basic_setup()èdriver_init()èdo_initcall()

Start_kernel()函数负责初始化内核各个子系统,最后调用reset_init(),启动一个叫做init的内核线程,继续初始化。

Start_kernel()函数在init/main.c中实现。

asmlinkagevoid__initstart_kernel(void)

{

char*command_line;

externstructkernel_param__start___param[],__stop___param[];

smp_setup_processor_id();

/*

*Needtorunasearlyaspossible,toinitializethe

*lockdephash:

*/

lockdep_init();

local_irq_disable();

early_boot_irqs_off();

early_init_irq_lock_class();

/*

*Interruptsarestilldisabled.Donecessarysetups,then

*enablethem

*/

lock_kernel();

boot_cpu_init();

page_address_init();

printk(KERN_NOTICE);

printk(linux_banner);

setup_arch(&command_line);

//setupprocessorandmachineanddestinatesomepointersfordo_initcalls()s

5、浅谈分析Armlinux内核移植及系统初始化的过程咨询QQ:

313807838

//forexampleinit_machinepointerisinitializedwithsmdk_machine_init(),and//init_machine()iscalledbycustomize_machine(),andtheisprocessedby//arch_initcall(fn).Thereforesmdk_machine_init()isissured.byedwin

setup_per_cpu_areas();

smp_prepare_boot_cpu();/*arch-specificboot-cpuhooks*/

/*

*Setuptheschedulerpriorstartinganyinterrupts(suchasthe

*timerinterrupt).Fulltopologysetuphappensatsmp_init()

*time-butmeanwhilewestillhaveaingscheduler.

*/

sched_init();

/*

*Disablepreemption-earlybootupschedulingisextremely

*fragileuntilwecpu_idle()forthefirsttime.

*/

preempt_disable();

build_all_zonelists();

page_alloc_init();

printk(KERN_NOTICE"Kernelcommandline:

%s/n",saved_command_line);

parse_early_param();

parse_args("Bootingkernel",command_line,__start___param,

__stop___param-__start___param,

&unknown_bootoption);

sort_main_extable();

unwind_init();

trap_init();

rcu_init();

init_IRQ();

pidhash_init();

init_timers();

hrtimers_init();

softirq_init(

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 管理学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1