内核版本可通过以下地址获取:
Linux Device Drivers: http://lwn.net/Kernel/LDD2/
Linux kernel官方网站:http://kernel.org/
Linux kernel 一览:https://www.kernel.org/pub/linux/kernel/
我的环境是:
1. 开发板用的是FL-OK6410B(即三星的s3c6410);
2. 待移植的内核版本是2.6.39
3. 编译的系统环境是VMWare7.1.3-Ubuntu10.04
4. 交叉编译链用的是arm-linux-gcc-4.3.2
移植的思路有两个:一个是用最接近ok6410的mini6410,在mini6410的基础上修改,这个方法比较简单快捷;另一个就是网上用的比较多的,使用smdk6410,拷贝一份smdk6410或在其基础上进行修改。这里介绍使用第二种方法,因为smdk6410应该是6410的标准版本,比较干净,要修改增加的内容比较多,可以更好进行系统学习锻炼。
设置编译环境
打开Makefile,定位到196行,修改如下:
ARCH ?=arm
CROSS_COMPILE ?= /usr/local/arm/4.3.2/bin/arm-none-linux-gnueabi-
注意:“ARCH ?= arm”这一行一定要改到,否则make menuconfig后选项有问题。
?:可以尝试用4.2.2或前面的U-BOOT编译可以尝试用4.3.2编译器编译。
一.创建目标平台
拷贝 arch/arm/ 内的平台文件(如arch/arm/mach-s3c64xx/mach-smdk6410.c拷贝为arch/arm/mach-s3c64xx/mach-th6410.c),并把文件内的smdk6410替换为th6410,MACHINE_START(TH6410, "TH6410 ChenPq")的字母要用大写,与Kconfig的配置一致。
增加:
//!add by chenpq at 2013.6.21for nand
#include<linux/mtd/mtd.h>
#include<linux/mtd/partitions.h>
#include <plat/nand.h>
//!
修改相应 Makefile及Kconfig文件:
Arch/arm/mach-s3c64xx/Kconfig增加TH6410的配置,可以参考或拷贝SMDK6410的配置。
Makefile文件增加:
obj-$(CONFIG_MACH_TH6410) +=mach-th6410.o
二.设置机器码
修改路径:arch/arm/tools/mach-types
机器码必须和uboot中的设置匹配(由于前面只是拷贝没有修改,因此要倒回uboot的th6410.h做相应修改,我在这里按照顺序在末尾添加为 2820)
修改刚才拷贝的平台文件
三.配置编译
#cp arch/arm/configs/s3c6400_defconfig.config
#make menuconfig
注意事项:
设置内核启动参数:
默认的commandline(经验证我的文件系统是cramfs,用默认的也行):
Console=ttySAC0,115200 root=/dev/raminit=/linuxrc initrd=0x51000000,6M ramdisk_size=6144
支持NandFlash
Device Drivers --->
<*> Memory Technology Device (MTD)support --->
[*] MTD partitioning support
<*> NAND Device Support --->
<*> NAND Flash support for S3C/S3CSoC
再把这个选项选上
devicedrivers ->
MemoryTechnology Device (MTD) support --->
Cachingblock device access to MTD devices
(此出勾选可防止出现:VFS: Cannot open root device "mtdblock2"or unknown-block(2,0) 错误)
保存退出
由于我的文件系统用的是 cramfs,因此在文件系统支持项要保证支持cramfs.
四.最后编译内核
#make uImage(zImage)
烧录到机器后成功加载文件系统:
VFP support v0.3: implementor 41 architecture 1 part 20 variant b rev 5 s3c-rtc s3c64xx-rtc: setting system clock to 2021-05-30 16:49:14 UTC (1622393354) mmc0: mmc_rescan_try_freq: trying to init card at 300000 Hz VFS: Mounted root (cramfs filesystem) readonly on device 31:2. Freeing init memory: 104K mmc0: mmc_rescan_try_freq: trying to init card at 200000 Hz mmc0: mmc_rescan_try_freq: trying to init card at 100000 Hz mmc1: mmc_rescan_try_freq: trying to init card at 400000 Hz mmc1: mmc_rescan_try_freq: trying to init card at 300000 Hz mmc1: mmc_rescan_try_freq: trying to init card at 200000 Hz mmc1: mmc_rescan_try_freq: trying to init card at 100000 Hz ifconfig: socket: Function not implemented /etc/init.d/rcS: line 11: /etc/init.d/ifconfig-eth0: not found ifconfig: socket: Function not implemented Processing /etc/profile... Done / # ls bin etc lib mnt root sys usr dev home linuxrc proc sbin tmp var / # / # df -a Filesystem 1K-blocks Used Available Use% Mounted on /dev/root 16228 16228 0 100% / proc 0 0 0 0% /proc tmpfs 128616 0 128616 0% /tmp sysfs 0 0 0 0% /sys tmpfs 128616 0 128616 0% /dev / # / # ls bin etc lib mnt root sys usr dev home linuxrc proc sbin tmp var / #
移植过程中可能遇到的问题及解决措施:
错误1:No oob scheme defined for oobsize 218
kernel BUG at drivers/mtd/nand/nand_base.c:3262!
http://blog.csdn.net/acanoe/article/details/7506594
出错原因:不明,还在查,等待更新知识库
启动后报错信息:
3c24xx-nand s3c6400-nand: Tacls=4, 30ns Twrph0=8 60ns,Twrph1=6 45ns
s3c24xx-nand s3c6400-nand: System booted from NAND
s3c24xx-nand s3c6400-nand: NAND soft ECC
NAND device: Manufacturer ID: 0xec, Chip ID: 0xd5 (SamsungNAND 2GiB 3,3V 8-bit)
No oob scheme defined for oobsize 218
kernel BUG at drivers/mtd/nand/nand_base.c:3262!
Unable to handle kernel NULL pointer dereference at virtual address 00000000
pgd = c0004000
[00000000] *pgd=00000000
Internal error: Oops: 805 [#1]
Modules linked in:
CPU: 0 Not tainted (3.0.1 #2)
PC is at __bug+0x20/0x2c
LR is at console_unlock+0x190/0x1e8
pc : [<c0036434>] lr : [<c004eb9c>] psr:60000013
sp : cf833df0 ip : c06a6008 fp : cf833dfc
r10: 00000000 r9 : c0250e50 r8 : cf8c5600
r7 : 00000001 r6 : cf930000 r5 : cf930190 r4 :cf930190
r3 : 00000000 r2 : 79f6f35f r1 : 60000013 r0 :00000037
Flags: nZCv IRQs on FIQs on ModeSVC_32 ISA ARM Segment kernel
Control: 00c5387d Table: 50004008 DAC: 00000017
Process swapper (pid: 1, stack limit = 0xcf832268)
Stack: (0xcf833df0 to 0xcf834000)
3de0: cf833e1c cf833e00 c024ad34 c0036420
3e00: cf930190 cf930000 cf8576e0 00000001 cf833e7c cf833e20 c025169c c024a824
暂行解决办法:在drivers/mtd/nand_base.c 文件中
vim 搜索 /No oob scheme
在128 的后面添加
case 218:
chip->ecc.layout =&nand_oob_128;
break.
解释:让218不进行bug 报错。
错误2:
drivers/rtc/hctosys.c:unable to open rtc device (rtc0)
1. 内核配置选项
--- Real TimeClock
[*] Setsystem time from RTC on startup andresume
(rtc0) RTC used to set the systemtime
[ ] RTCdebugsupport
*** RTCinterfaces***
[*] /sys/class/rtc/rtcN(sysfs)
[*] /dev/rtcN (characterdevices)
[ ] RTC UIE emulation on devinterface
*** on-CPU RTC drivers***
<*> Samsung S3Cseries SoC RTC
2. linux kernel 中已经支持S3C2410的RTC,但是并没有添加到平台设备初始化数组中,所以系统启动时并不会初始化这一部分,需要修改文件mach-smdk.c
static structplatform_device*smdk2410_devices[] __initdata = {
&s3c_device_ohci,
&s3c_device_lcd,
&s3c_device_wdt,
&s3c_device_i2c0,
&s3c_device_iis,
&s3c_device_rtc, //新增代码
};
3. 创建设备节点,在文件系统/dev目录下执行:
sudo mknod rtc c10 135
4. 重新编译内核,查看启动信息
错误3(无法挂载文件系统):
uncorrectable error :
uncorrectable error :
end_request: I/O error, dev mtdblock2,sector 0
Buffer I/O error on device mtdblock2,logical block 0
uncorrectable error :
uncorrectable error :
end_request: I/O error, dev mtdblock2,sector 0
Buffer I/O error on device mtdblock2,logical block 0
uncorrectable error :
uncorrectable error :
end_request: I/O error, dev mtdblock2,sector 8
Buffer I/O error on device mtdblock2,logical block 1
uncorrectable error :
uncorrectable error :
end_request: I/O error, dev mtdblock2,sector 8
Buffer I/O error on device mtdblock2,logical block 1
uncorrectable error :
uncorrectable error :
end_request: I/O error, dev mtdblock2,sector 16
Buffer I/O error on device mtdblock2,logical block 2
mmc0: mmc_rescan_try_freq: trying to initcard at 300000 Hz
uncorrectable error :
uncorrectable error :
end_request: I/O error, dev mtdblock2,sector 16
Buffer I/O error on device mtdblock2,logical block 2
uncorrectable error :
uncorrectable error :
end_request: I/O error, dev mtdblock2,sector 24
Buffer I/O error on device mtdblock2,logical block 3
uncorrectable error :
uncorrectable error :
end_request: I/O error, dev mtdblock2, sector24
Buffer I/O error on device mtdblock2,logical block 3
List of all partitions:
1f00 1024 mtdblock0 (driver?)
1f01 5120 mtdblock1 (driver?)
1f02 2091008 mtdblock2 (driver?)
No filesystem could mount root, tried: cramfs
Kernel panic - not syncing: VFS: Unable tomount root fs on unknown-block(31,2)
主要是缺少对此NAND FLASH的驱动支持
解决方法:
1.
mach-mini6410.c
mini6410_machine_init()加入
#ifdef CONFIG_MTD_NAND_S3C
s3c_device_nand.name= "s3c6410-nand";
#endif
在mini6410_devices[]__initdata中加入
&s3c_device_nand,
2.添加对samsung nand的支持
在"drivers/mtd/nand"中添加s3c_nand.c
在"drivers/mtd/nand/Kconfig"中加入:
config MTD_NAND_S3C tristate"NAND support for Samsung S3C" dependson (ARCH_S3C64XX || ARCH_S5P64XX || ARCH_S5PC1XX) && MTD_NAND help This enables the NAND flash controller on theS3C No board specific support is done by thisdriver, each board must advertise a platform_device for thedriver to attach. config MTD_NAND_S3C_DEBUG bool"S3C NAND driver debug" dependson MTD_NAND_S3C help Enable debugging of the S3C NAND driver config MTD_NAND_S3C_HWECC bool"S3C NAND Hardware ECC" dependson MTD_NAND_S3C help Enable the use of the S3C's internal ECCgenerator when using NAND. Early versions of the chip havehad problems with incorrect ECC generation, and if using these,the default of software ECC is preferable. If you lay down a device with the hardware ECC,then you will currently not be able to switch to software,as there is no implementation for ECC method used by the S3C
在在"drivers/mtd/nand/Makefile"中加入:
obj-$(CONFIG_MTD_NAND_S3C) += s3c_nand.o
3.在"arch/arm/plat-sansung/include/plat/regs-nand.h中加入
/* for s3c_nand.c */ #define S3C_NFCONF S3C2410_NFREG(0x00) #define S3C_NFCONT S3C2410_NFREG(0x04) #define S3C_NFCMMD S3C2410_NFREG(0x08) #define S3C_NFADDR S3C2410_NFREG(0x0c) #define S3C_NFDATA8 S3C2410_NFREG(0x10) #define S3C_NFDATA S3C2410_NFREG(0x10) #define S3C_NFMECCDATA0 S3C2410_NFREG(0x14) #define S3C_NFMECCDATA1 S3C2410_NFREG(0x18) #define S3C_NFSECCDATA S3C2410_NFREG(0x1c) #define S3C_NFSBLK S3C2410_NFREG(0x20) #define S3C_NFEBLK S3C2410_NFREG(0x24) #define S3C_NFSTAT S3C2410_NFREG(0x28) #define S3C_NFMECCERR0 S3C2410_NFREG(0x2c) #define S3C_NFMECCERR1 S3C2410_NFREG(0x30) #define S3C_NFMECC0 S3C2410_NFREG(0x34) #define S3C_NFMECC1 S3C2410_NFREG(0x38) #define S3C_NFSECC S3C2410_NFREG(0x3c) #define S3C_NFMLCBITPT S3C2410_NFREG(0x40) #define S3C_NF8ECCERR0 S3C2410_NFREG(0x44) #define S3C_NF8ECCERR1 S3C2410_NFREG(0x48) #define S3C_NF8ECCERR2 S3C2410_NFREG(0x4c) #define S3C_NFM8ECC0 S3C2410_NFREG(0x50) #define S3C_NFM8ECC1 S3C2410_NFREG(0x54) #define S3C_NFM8ECC2 S3C2410_NFREG(0x58) #define S3C_NFM8ECC3 S3C2410_NFREG(0x5c) #define S3C_NFMLC8BITPT0 S3C2410_NFREG(0x60) #define S3C_NFMLC8BITPT1 S3C2410_NFREG(0x64) #define S3C_NFCONF_NANDBOOT (1<<31) #define S3C_NFCONF_ECCCLKCON (1<<30) #define S3C_NFCONF_ECC_MLC (1<<24) #define S3C_NFCONF_ECC_1BIT (0<<23) #define S3C_NFCONF_ECC_4BIT (2<<23) #define S3C_NFCONF_ECC_8BIT (1<<23) #define S3C_NFCONF_TACLS(x) ((x)<<12) #define S3C_NFCONF_TWRPH0(x) ((x)<<8) #define S3C_NFCONF_TWRPH1(x) ((x)<<4) #define S3C_NFCONF_ADVFLASH (1<<3) #define S3C_NFCONF_PAGESIZE (1<<2) #define S3C_NFCONF_ADDRCYCLE (1<<1) #define S3C_NFCONF_BUSWIDTH (1<<0) #define S3C_NFCONT_ECC_ENC (1<<18) #define S3C_NFCONT_LOCKTGHT (1<<17) #define S3C_NFCONT_LOCKSOFT (1<<16) #define S3C_NFCONT_MECCLOCK (1<<7) #define S3C_NFCONT_SECCLOCK (1<<6) #define S3C_NFCONT_INITMECC (1<<5) #define S3C_NFCONT_INITSECC (1<<4) #define S3C_NFCONT_nFCE1 (1<<2) #define S3C_NFCONT_nFCE0 (1<<1) #define S3C_NFCONT_INITECC (S3C_NFCONT_INITSECC | S3C_NFCONT_INITMECC) #define S3C_NFSTAT_ECCENCDONE (1<<7) #define S3C_NFSTAT_ECCDECDONE (1<<6) #define S3C_NFSTAT_BUSY (1<<0) #define S3C_NFECCERR0_ECCBUSY (1<<31)
4.make menuconfig
Device Drivers-->
<*>Memory Technology Device(MTD) support-->
<*>NAND Device Support-->
去掉<*> NAND Flash support for S3C/S3CSoC
改成勾选我们在"drivers/mtd/nand/Kconfig"添加的内容
<*>NAND support for Samsung S3C
[*] S3C NAND driver debug
[*] S3C NAND Hardware ECC
错误4:
s3c64xx-pata.0: failed to claim resource 0
------------[ cut here ]------------
WARNING: at drivers/base/core.c:143device_release+0x70/0x84()
Device 's3c64xx-adc' does not have arelease() function, it is broken and must be fixed.
Modules linked in:
错误原因: 未找到relese() 释放函数
解决办法:在arch/arm/plat-samsung/dev-nand.c文件中
static structresource s3c_nand_resource[] = { [0] = { .start = S3C_PA_NAND, .end = S3C_PA_NAND +SZ_1M-1, // 给最后加上一个 “ - 1” .flags = IORESOURCE_MEM, }