现在的位置: 首页 > 综合 > 正文

移植内核2.6.24.4到S3C2440

2014年11月05日 ⁄ 综合 ⁄ 共 10309字 ⁄ 字号 评论关闭

 

百经周折,终于新内核启动了新的系统。
多谢小卒的指导,还有这两篇文章的作者,给了我很多帮助。
很多工作还刚开始,先记录下来,别以后自己都忘了。
---------------------------------------------------------------------------------------------------
移植环境:
主机:CentOS 5.1
交叉编译器:arm-linux-gcc-3.4.1
开发板平台:S3C2440(YL-2440/YLP-2440开发板)
--------------------------------------------------------------------------------------------
准备工作:
下载Linux内核源代码:http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.24.4.tar.bz2 (上去一看,今天2.6.25的内核出来了)
交叉编译工具包:从光盘一般都带,没有到网上找找也有。
解压源码:tar -jxvf linux-2.6.24.4.tar.bz2
安装交叉编译工具:tar -jxvf arm-linux-gcc-3.4.1.tar.bz2 -C /
会将工具安装在/usr/local/arm/3.4.1/中,视各人的环境可能不同,自己修改Makefile中的路径即可。
 
--------------------------------------------------------------------------------------------------------------------
修改配置文件:
1.修改Makefile,匹配交叉编译器。
在内核代码根目录下:vim Makefile
在193行找到ARCH
修改为
ARCH = arm
CROSS_COMPILE ?= /usr/local/arm/3.4.1/bin/arm-linux-
CORSS_COMPILE视自己的环境定
 
2. 为了内核支持devfs 以及在启动时并在/sbin/init 运行之前能自动挂载/dev为devfs 文件系统。编辑fs/Kconfig:
在906 行menu "Pseudo filesystems"下面添加如下代码:
config DEVFS_FS
bool "/dev file system support (OBSOLETE)"
default y
config DEVFS_MOUNT
bool "Automatically mount at boot"
default y
depends on DEVFS_FS
 
3.
 
 
--------------------------------------------------------------------------------------------------------------------
修改源代码:
1. 修改对nand的分区信息。要让内核知道nand flash的分区信息,设置成跟bootloader一致。
在arch/arm/plat-s3c24xx/common-smdk.c中修改smdk_default_nand_part[],注意这个一定要跟bootloader的一致。在我的板子中修改如下:
static struct mtd_partition smdk_default_nand_part[] = {
        [0]={
                .name = "boot",
                .size = SZ_128K + SZ_64K,   //192k 0x00300000
                .offset = 0,
                },
        [1]={
                .name = "kernel",
                .size = SZ_16K * 116,            //2M - 192K    0x01e00000
                .offset = SZ_16K *12,           //192K
                },
        [2]={
                .name = "rootfs",
                .offset = SZ_2M,                 
                .size = SZ_2M * 15,                     //30M
                },
        [3]={
                .name = "User",
                .offset = SZ_32M,
                .size = SZ_32M,
                }
};
 
另外这个文件还要修改smdk_nand_info如下:
static struct s3c2410_platform_nand smdk_nand_info = {
.tacls              = 0,        //default is 20
.twrph0          = 30,       //default is 60
.twrph1          = 0,        //defualt is 20 changed by yangdk
.nr_sets   = ARRAY_SIZE(smdk_nand_sets),
.sets        = smdk_nand_sets,
};
 
 
2. 修改时钟
       在arch/arm/mach-s3c2440/mach-smdk2440.c中修改smdk2440_map_io如下
    static void __init smdk2440_map_io(void)
{
s3c24xx_init_io(smdk2440_iodesc, ARRAY_SIZE(smdk2440_iodesc));
s3c24xx_init_clocks(12000000);      //default is 16934400, changed by yangdk
s3c24xx_init_uarts(smdk2440_uartcfgs, ARRAY_SIZE(smdk2440_uartcfgs));
}
 
3.修改nand Flash的校验方式,去掉ECC校验。
       在drivers/mtd/nand/s3c2410.c 第669行
       将chip->ecc.mode = NAND_ECC_SOFT;
       改为 chip->ecc.mode = NAND_ECC_NONE;
       注意:这个去掉ECC校验的问题,在内核中明确说明是不建议这样做的,因为这样就等于忽略了对NAND FLASH坏块的检测。而我一开始也是编译的时候就去掉了ECC校验的选项,原以为在编译选项中去掉就可以了,结果一直报这样的错:
end_request: I/O error, dev mtdblock2, sector 0
FAT: unable to read boot sector
VFS: Cannot open root device "mtdblock2" or unknown-block(31,2)
Please append a correct "root=" boot option; here are the available partitions:
1f00        192 mtdblock0 (driver?)
1f01       1856 mtdblock1 (driver?)
1f02      30720 mtdblock2 (driver?)
1f03      32768 mtdblock3 (driver?)
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(31,2)
       郁闷了一个整天。后来发现配置中去掉的这个选项在代码中并没有完全去掉,只是去掉了硬件校验的方式,换成了软件校验。只有在代码中给改成NAND_ECC_NONE,才不会校验,但是这样是不提倡的。可是这有这样最后我的系统才起来,阿弥陀佛!
 
 
配置及编译内核
先把默认配置文件拷贝过来
cp arch/arm/configs/s3c2410_defconfig .config
配置
Make menuconfig
 
[*] Enable loadable module support --->
       [*]   Module unloading
       [*]   Automatic kernel module loading
       选择这两个,剩下的可以去掉
 
System Type ---->
       [*] S3C2410 DMA support
       [*] Support ARM920T processor
       S3C2410 Machines --->
              [*] SMDK2410/A9M2410 
       S3C2440 Machines --->
              [*] SMDK2440
              [*] SMDK2440 with S3C2440 CPU module
 
System Type这部分,只选这些,其他可以全部去掉,我的这个还选上了队Thumb的支持。另外,网上一些帖子都说只选上SMDK2440就可以了,其他的都去掉,事实上是不行的,我试了多次,都在编译时
到arch/arm/plat-s3c24xx/s3c24xx.o时,报错:
arch/arm/plat-s3c24xx/s3c244x.c: In function `s3c244x_init_clocks':
arch/arm/plat-s3c24xx/s3c244x.c:121: error: implicit declaration of function `s3c2410_baseclk_add'
make[1]: *** [arch/arm/plat-s3c24xx/s3c244x.o] 错误 1
make: *** [arch/arm/plat-s3c24xx] 错误 2
我再选上SMDK2410/A9M2410,问题解决。
 
Boot option ----->
       修改启动参数为:
       noinitrd root=/dev/mtdblock2 init=/linuxrc console=ttySAC0,115200
       可能根据个人板子的设置会不一样,我的是从Nand Flash中加载文件系统,其中mtdblock2是存放我的Linux文件系统的分区。不过,在bootloader可以传递内核参数的情况下这个设置是无效的。
 
Device Drivers --->
       <*> Memory Technology Device (MTD) support --->
              [*]   MTD partitioning support
              <*> NAND Device Support --->
                      <*>   NAND Flash support for S3C2410/S3C2440 SoC
                      [ ]    S3C2410 NAND Hardware ECC     //这个要去掉
       [*] Network device support --->
               [*]   Ethernet (10 or 100Mbit) ---> 
                   <*>   DM9000 support
       < > Real Time Clock --->   //这个去掉
 
       去掉红字的两个部分,黑子部分选上,其他的选择默认就可以了。
 
File systems --->
       <*> ROM file system support
       因为我的文件系统用cramfs,选择这个,其他用默认。
 
 
到此为止,基本完成。下面正式编译
make zImage
……
上个厕所,洗把脸,吃个苹果,20分钟后陆续出现这个
 SYSMAP System.map
 SYSMAP .tmp_System.map
 OBJCOPY arch/arm/boot/Image
 Kernel: arch/arm/boot/Image is ready
 AS      arch/arm/boot/compressed/head.o
 GZIP    arch/arm/boot/compressed/piggy.gz
 AS      arch/arm/boot/compressed/piggy.o
 CC      arch/arm/boot/compressed/misc.o
 LD      arch/arm/boot/compressed/vmlinux
 OBJCOPY arch/arm/boot/zImage
 Kernel: arch/arm/boot/zImage is ready
小高兴一下,编译成功!
 
 
烧写新内核
……
启动新内核:
Read chip id = ec76
Nand flash status = c0
Set boot params = root=/dev/mtdblock2 init=/linuxrc load_ramdisk=0 console=ttySAC1,115200 mem=65536K devfs=mount
Load Kernel...
Linux version 2.6.24.4 (root@centos) (gcc version 3.4.1) #13 Thu Apr 17 10:45:28 CST 2008
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177
Machine: SMDK2410
ATAG_INITRD is deprecated; please update your bootloader.
Memory policy: ECC disabled, Data cache writeback
CPU S3C2440A (id 0x32440001)
S3C244X: core 400.000 MHz, memory 100.000 MHz, peripheral 50.000 MHz
S3C24XX Clocks, (c) 2004 Simtec Electronics
CLOCK: Slow mode (1.500 MHz), fast, MPLL on, UPLL on
CPU0: D VIVT write-back cache
CPU0: I cache: 16384 bytes, associativity 64, 32 byte lines, 8 sets
CPU0: D cache: 16384 bytes, associativity 64, 32 byte lines, 8 sets
Built 1 zonelists in Zone order, mobility grouping on. Total pages: 16256
Kernel command line: root=/dev/mtdblock2 init=/linuxrc load_ramdisk=0 console=ttySAC1,115200 mem=65536K devfs=mount
irq: clearing pending ext status 0000d400
irq: clearing subpending status 00000092
PID hash table entries: 256 (order: 8, 1024 bytes)
timer tcon=00590000, tcnt a2c1, tcfg 00000200,00000000, usec 00001eb8
Console: colour dummy device 80x30
console [ttySAC1] enabled
Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)
Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)
Memory: 64MB = 64MB total
Memory: 61568KB available (2896K code, 299K data, 124K init)
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
net_namespace: 64 bytes
NET: Registered protocol family 16
S3C2410 Power Management, (c) 2004 Simtec Electronics
S3C2440: Initialising architecture
S3C2440: IRQ Support
S3C2440: Clock Support, DVS off
S3C24XX DMA Driver, (c) 2003-2004,2006 Simtec Electronics
DMA channel 0 at c4800000, irq 33
DMA channel 1 at c4800040, irq 34
DMA channel 2 at c4800080, irq 35
DMA channel 3 at c48000c0, irq 36
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 2048 (order: 2, 16384 bytes)
TCP bind hash table entries: 2048 (order: 1, 8192 bytes)
TCP: Hash tables configured (established 2048 bind 2048)
TCP reno registered
NetWinder Floating Point Emulator V0.97 (double precision)
JFFS2 version 2.2. (NAND) 漏 2001-2006 Red Hat, Inc.
fuse init (API version 7.9)
io scheduler noop registered
io scheduler anticipatory registered (default)
io scheduler deadline registered
io scheduler cfq registered
s3c2410-lcd s3c2410-lcd: no platform data for lcd, cannot attach
s3c2410-lcd: probe of s3c2410-lcd failed with error -22
lp: driver loaded but no devices found
ppdev: user-space parallel port driver
Serial: 8250/16550 driver $Revision: 1.90 $ 4 ports, IRQ sharing enabled
s3c2440-uart.0: s3c2410_serial0 at MMIO 0x50000000 (irq = 70) is a S3C2440
s3c2440-uart.1: s3c2410_serial1 at MMIO 0x50004000 (irq = 73) is a S3C2440
s3c2440-uart.2: s3c2410_serial2 at MMIO 0x50008000 (irq = 76) is a S3C2440
RAMDISK driver initialized: 16 RAM disks of 4096K size 1024 blocksize
loop: module loaded
dm9000 Ethernet Driver
Uniform Multi-Platform E-IDE driver Revision: 7.00alpha2
ide: Assuming 50MHz system bus speed for PIO modes; override with idebus=xx
S3C24XX NAND Driver, (c) 2004 Simtec Electronics
s3c2440-nand s3c2440-nand: Tacls=1, 10ns Twrph0=7 70ns, Twrph1=1 10ns
NAND device: Manufacturer ID: 0xec, Chip ID: 0x76 (Samsung NAND 64MiB 3,3V 8-bit)
NAND_ECC_NONE selected by board driver. This is not recommended !!
Scanning device for bad blocks
Creating 4 MTD partitions on "NAND 64MiB 3,3V 8-bit":
0x00000000-0x00030000 : "bootloader"
0x00030000-0x00200000 : "kernel_zImage"
0x00200000-0x02000000 : "rootfs"
0x02000000-0x04000000 : "User"
usbmon: debugfs is not available
s3c2410-ohci s3c2410-ohci: S3C24XX OHCI
s3c2410-ohci s3c2410-ohci: new USB bus registered, assigned bus number 1
s3c2410-ohci s3c2410-ohci: irq 42, io mem 0x49000000
usb usb1: configuration #1 chosen from 1 choice
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 2 ports detected
mice: PS/2 mouse device common for all mice
s3c2440-i2c s3c2440-i2c: slave address 0x10
s3c2440-i2c s3c2440-i2c: bus frequency set to 390 KHz
s3c2440-i2c s3c2440-i2c: i2c-0: S3C I2C adapter
S3C2410 Watchdog Timer, (c) 2004 Simtec Electronics
s3c2410-wdt s3c2410-wdt: watchdog inactive, reset disabled, irq enabled
TCP cubic registered
NET: Registered protocol family 1
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
VFS: Mounted root (cramfs filesystem) readonly.
Freeing init memory: 124K
init started: BusyBox v1.9.2 (2008-04-16 00:31:28 CST)
starting pid 772, tty '': '/etc/init.d/rcS'
#mount all.......
# starting mdev....
******************************************
        yangdk linux-2.6.24.4 boot
 
******************************************
starting pid 778, tty '': '/bin/sh'
 
Processing /etc/profile......Done!
/ #
说明内核已经正常工作了。。。
 
从红色部分知道,已经加载文件系统成功了!文件系统是在busybox1.9.2的基础上建立的。主要是参考了http://blog.chinaunix.net/u2/63560/showart_518011.html ,谢谢作者!
另外一个注意的是使用mkcramfs工具的时候要使用-e选项指定版本号为2.6.24.4,来和新的内核匹配,否则的话就会像我之前和郁闷的出现这样的错误。
Warning: unable to open an initial console.
clk: version magic '2.6.12-h1940 ARMv4 gcc-3.4' should be '2.6.24.4 mod_unload ARMv4 '
s3c2410mci: version magic '2.6.12-h1940 ARMv4 gcc-3.4' should be '2.6.24.4 mod_unload ARMv4 '
为这个还要费尽周折找到mkcramfs的源代码才知道有-e这么一个选项,其实可以通过mkcramfs –help来查看的,却没想到,真晕~~~
 

抱歉!评论已关闭.