新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 淺談分析Arm linux 內(nèi)核移植及系統(tǒng)初始化的過(guò)程一

淺談分析Arm linux 內(nèi)核移植及系統(tǒng)初始化的過(guò)程一

作者: 時(shí)間:2016-11-09 來(lái)源:網(wǎng)絡(luò) 收藏
學(xué)習(xí)嵌入式ARMlinux,主要想必三個(gè)方向發(fā)展:

1、嵌入式linux應(yīng)用軟件開(kāi)發(fā)
2、linux內(nèi)核的剪裁和移植
3、嵌入式linux底層驅(qū)動(dòng)的開(kāi)發(fā)
主 要介紹內(nèi)核移植過(guò)程中涉及文件的分布及其用途,以及簡(jiǎn)單介紹系統(tǒng)的初始化過(guò)程。整個(gè)armlinux內(nèi)核的啟動(dòng)可分為三個(gè)階段:第一階段主要是進(jìn)行 cpu和體系結(jié)構(gòu)的檢查、cpu本身的初始化以及頁(yè)表的建立等;第二階段主要是對(duì)系統(tǒng)中的一些基礎(chǔ)設(shè)施進(jìn)行初始化;最后則是更高層次的初始化,如根設(shè)備和 外部設(shè)備的初始化。了解系統(tǒng)的初始化過(guò)程,有益于更好地移植內(nèi)核。
1. 內(nèi)核移植

本文引用地址:http://butianyuan.cn/article/201611/318025.htm

2. 涉及文件分布介紹
2.1. 內(nèi)核移植

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
內(nèi)核移植過(guò)程中涉及到的頭文件包括處理器相關(guān)的頭文件(1)和處理器無(wú)關(guān)的頭文件(2)。
2.3. 內(nèi)核移植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文件定義了不同系統(tǒng)平臺(tái)的系統(tǒng)平臺(tái)號(hào)。移植linux內(nèi)核到新的平臺(tái)上需要對(duì)新的平臺(tái)登記系統(tǒng)平臺(tái)號(hào)。
Mach-types文件格式如下:
#machine_is_xxx CONFIG_xxxx MACH_TYPE_xxx number
s3c2410 ARCH_S3C2410 S3C2410 182
smdk2410 ARCH_SMDK2410 SMDK2410 193
之 所以需要這些信息,是因?yàn)槟_本文件linux/arch/arm/tools/gen-mach-types需要linux/arch/tools /mach-types來(lái)產(chǎn)生linux/include/asm-arm/mach-types.h文件,該文件中設(shè)置了一些宏定義,需要這些宏定義來(lái) 為目標(biāo)系統(tǒng)選擇合適的代碼。
(2)
linux-2.6.18.8/arch/arm/boot/compressed
[root@localhostcompressed]#tree-L1
.
|--Makefile
|--Makefile.debug
|--big-endian.S
|--head-at91rm9200.S

2淺談分析Arm linux 內(nèi)核移植及系統(tǒng)初始化的過(guò)程
|--head.S
|--ll_char_wr.S
|--misc.c
|--ofw-shark.c
|--piggy.S
`--vmlinux.lds.in
Head.s是 內(nèi)核映像的入口代碼,是自引導(dǎo)程序。自引導(dǎo)程序包含一些初始化程序,這些程序都是體系結(jié)構(gòu)相關(guān)的。在對(duì)系統(tǒng)作完初始化設(shè)置工作后,調(diào)用misc.c文件中 的decompress_kernel()函數(shù)解壓縮內(nèi)核映像到指定的位置,然后跳轉(zhuǎn)到kernel的入口地址。
Vmlinux.lds.in用來(lái)生成內(nèi)核映像的內(nèi)存配置文件。
(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
內(nèi)核入口處也是由一段匯編語(yǔ)言實(shí)現(xiàn)的,由head.s和head-common.s兩個(gè)文件組成。
Head.s是 內(nèi)核的入口文件,在head.s的末尾處#i nclude"head-common.S"。經(jīng)過(guò)一系列的初始化后,跳轉(zhuǎn)到linux-2.6.18.8/init/main.c中的 start_kernel()函數(shù)中,開(kāi)始內(nèi)核的基本初始化過(guò)程。
/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
這個(gè)目錄中的文件都是板級(jí)相關(guān)的,其中比較重要是如下幾個(gè):
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. 處理器和設(shè)備4.
這里主要介紹處理器和設(shè)備的描述和操作過(guò)程。設(shè)備描述在linux/arch/arm/mach-s3c2410/devs.c和linux/arch/arm/mach-s3c2410/common-smdk.c中實(shí)現(xiàn)。最后以nandflash為例具體介紹。



評(píng)論


技術(shù)專區(qū)

關(guān)閉