移植Linux3.4.2版本内核到mini2440(一)

    该移植工作主要参考了韦东山的《嵌入式Linux应用开发完全手册》,第二期毕业班视频教程和友善之臂mini2440光盘提供的《Mini2440 Linux移植开发实战指南.pdf》,使用的bootloader是我根据韦东山老师制作的2012.04.01版本u-boot,具体制作方法可参考我的另一篇博客《u-boot-2012.04.01修改移植和制作补丁文件 》,交叉编译器使用的是arm-linux-gcc : v4.3.2。

一. 内核启动流程,据此配置内核(机器ID)
1. 获取内核源码 www.kernel.org
https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.4.2.tar.bz2
2. 解压内核
# tar xjvf linux-3.4.2.tar.bz2
3. 修改顶层Makefile,指定交叉编译器
ARCH ?= arm
CROSS_COMPILE ?= arm-linux-
4. 使用默认配置编译内核,可使用如下命令查看内核有哪些默认配置
# find -name “*defconfig”
使用缺省内核配置文件,s3c2410_defconfig 是SMDK2410 的缺省配置文件
# make s3c2410_defconfig
编译、测试
# make uImage
拷贝uImage到tftpboot目录
# cp arch/arm/boot/uImage /work/tftpboot/uImage_3.4.2
下载、启动内核
# tftp 32000000 uImage_3.4.2
# bootm 32000000
结果,启动后会产生乱码,原因是bootargs参数并未指定串口波特率,修改bootargs如下即可正常启动看到输出
# set bootargs console=ttySAC0,115200 root=/dev/mtdblock3
5. 修改晶振频率
# vim arch/arm/mach-s3c24xx/mach-smdk2440.c
–s3c24xx_init_clocks(16934400);
++s3c24xx_init_clocks(12000000);
编译、测试
# make s3c2410_defconfig //支持内核较多
# make uImage

    # set machid 16a                        //SMDK2440的机器ID
    # set bootargs console=ttySAC0,115200 root=/dev/mtdblock3
    # tftp 32000000 uImage_3.4.2
    # bootm 32000000
可正常输出内核启动信息,说明串口工作正常

二. 修改分区, 制作新的文件系统
2.1 修改分区,和我修改后的u-boot-2012.04.01一致,参考友善之臂文档《Mini2440 Linux移植开发实战指南.pdf》
0x00000000-0x00060000 : “bootloader”
0x00060000-0x00080000 : “params”
0x00050000-0x00580000 : “kernel”
0x00580000- : “root”
# vim arch/arm/mach-s3c24xx/common-smdk.c

点击(此处)折叠或打开

static struct mtd_partition smdk_default_nand_part[] = {
        [0] = {
                .name = "bootloader",
                .size = SZ_256K + SZ_128K,
                .offset = 0,
        },
        [1] = {
                .name = "params",
                .offset = SZ_256K + SZ_128K,
                .size = SZ_128K,
        },
        [2] = {
                .name = "kernel",
                .offset = SZ_512K,
                .size = 0x00500000,
        },
        [3] = {
                .name = "root",
                .offset = SZ_512K + 0x00500000,
                .size = MTDPART_SIZ_FULL,
        },
};    

    编译、测试
        # make uImage
        # cp arch/arm/boot/uImage /work/tftpboot/uImage_3.4.2 

        # setenv bootcmd 'tftp 32000000 uImage_3.4.2;bootm 32000000'
        # boot

可看到打印出如下分区信息

List of all partitions:
1f00 384 mtdblock0 (driver?)
1f01 128 mtdblock1 (driver?)
1f02 5120 mtdblock2 (driver?)
1f03 1042944 mtdblock3 (driver?)


    烧写文件系统、测试fs_mini_mdev.yaffs2<该文件系统来自韦东山老师的教程>
        # tftp 32000000 fs_mini_mdev.yaffs2
        # nand erase.part root
        # nand write.yaffs 32000000 0x580000  $filesize
    测试
        # set bootargs console=ttySAC0,115200 root=/dev/mtdblock3
        # setenv bootcmd 'tftp 32000000 uImage_3.4.2;bootm 32000000'
        # boot
    结果:
        No filesystem could mount root, tried:  ext3 ext2 cramfs vfat msdos iso9660 romfs

    测试jffs2
        # tftp 32000000 fs_mini_mdev.jffs2
        # nand erase.part root
        # nand write.jffs2 32000000 580000  $filesize
        # set bootargs console=ttySAC0,115200 root=/dev/mtdblock3 rootfstype=jffs2
        # boot
    不能使用

2.2 制作根文件系统  
    ① 编译安装busybox
            编译 busybox-1.20.0.tar.bz2
            # tar xjvf busybox-1.20.0.tar.bz2
            # cd busybox-1.20.0
            # make menuconfig
                Busybox Settings  ---> 
                    Build Options  ---> 
                        ()  Cross Compiler prefix 
                                填入arm-linux-  
        保存、退出,执行make
            # make
        创建文件系统目录
            # cd /work/nfsroot
            # mkdir fs_mini_mdev_new
        安装
            # make install CONFIG_PREFIX=/work/nfsroot/fs_mini_mdev_new
    ② 安装libc库,使用arm-linux-gcc 4.3.2 中的库文件
            # cd /work/nfsroot/fs_mini_mdev_new
            # mkdir lib
            # cd lib
            # cp /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/armv4t/lib/*so* ./ -d 
            # cd ../
            # mkdir usr/lib -p
            # cd usr/lib
            # cp /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/armv4t/usr/lib/*so* ./ -d

    ③ 构建etc目录
            # cp -rf ../fs_mini_mdev/etc ./
        修改inttab
            # vim inittab
                将s3c2410_serial0改为console
    ④ 构建dev目录
            # mkdir dev
            # cd dev
            # mknod console c 5 1 
            # mknod null c 1 3
    ⑤ 创建其他目录
            # mkdir proc tmp mnt sys root

    ⑥ 制作jffs2根文件系统,参考《嵌入式Linux应用开发完全手册》
            # mkfs.jffs2 -n -s 2048 -e 128KiB -d fs_mini_mdev_new -o fs_mini_mdev_new.jffs2 
    ⑦ 烧写测试
            # cp fs_mini_mdev_new.jffs2 /work/tftpboot
            # tftp 32000000 fs_mini_mdev_new.jffs2
            # nand erase.part root
            # nand write.jffs2 32000000 580000  $filesize
            # set bootargs console=ttySAC0,115200 root=/dev/mtdblock3 rootfstype=jffs2
            # boot
    ⑧ 结果
            Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000004
    出错、退出

解决方法
配置内核
    # make menuconfig
        Kernel Features  --->  
            [*] Use the ARM EABI to compile the kernel  //选中该项
    # make uImage
    # cp arch/arm/boot/uImage /work/tftpboot/uImage_3.4.2_eabi

测试
        # tftp 32000000 uImage_3.4.2_eabi
        # bootm 32000000
可正常启动
        Please press Enter to activate this console. 
        / # 

三. 移植YAFFS文件系统

获取yaffs2源码
    # git clone git://www.aleph1.co.uk/yaffs2

给内核打yaffs2补丁,参考readme
    # cd yaffs2
    # ./patch-ker.sh c m /work/kernel/linux-3.4.2

配置内核使其支持yaffs2文件系统
    # make menuconfig
        File systems --->
            [*]Miscellaneous filesystems --->
                <*> yaffs2 file system support
    # make uImage

制作yaffs2根文件系统
    # mkyaffs2image fs_mini_mdev_new fs_mini_mdev_new.yaffs2
    # mv fs_mini_mdev_new.yaffs2 /work/tftpboot/
    # cp arch/arm/boot/uImage /work/tftpboot/uImage_3.4.2_yaffs2

烧写Yaffs2文件系统
    # tftp 32000000 fs_mini_mdev_new.yaffs2
    # nand erase.part root                                         //擦除root分区
    # nand write.yaffs 32000000 580000  $filesize         //亲测用nand write.jffs2会出错,找不到init进程

启动内核
    # tftp 32000000 uImage_3.4.2_yaffs2
    # set bootargs console=ttySAC0,115200 root=/dev/mtdblock3
    # bootm 32000000 

可修改bootcmd参数便捷启动
    # setenv bootcmd 'tftp 32000000 uImage_3.4.2_yaffs2;bootm 32000000'

四. 裁剪内核

查看现在内核大小

    # ls arch/arm/boot/uImage -l
        -rw-r--r-- 1 root root 2486104 Dec 30 22:41 arch/arm/boot/uImage
    # make menuconfig         //去掉不需要的项

a. 去掉不需要支持的单板
    System Type  ---> 
        SAMSUNG S3C24XX SoCs Support  ---> 
         *** S3C24XX SoCs ***                                                        
                [ ] SAMSUNG S3C2410                                                       
                [ ] SAMSUNG S3C2412                                                  
                [ ] SAMSUNG S3C2416/S3C2450                                          
                [*] SAMSUNG S3C2440                                      
                [ ] SAMSUNG S3C2442                                              
                [ ] SAMSUNG S3C2443                                         
                    *** S3C2440 Boards ***                                      
                [ ] Simtec Electronics ANUBIS                                  
                [ ] Avantech AT2440EVB development board                            
                [*] MINI2440 development board                                     
                [ ] NexVision NEXCODER 2440 Light Board                       
                [ ] Simtec IM2440D20 (OSIRIS) module                                
                [ ] HP iPAQ rx3715                                            
                [*] SMDK2440                                                       
                [*] SMDK2440 with S3C2440 CPU module         

b. 裁剪对文件系统的支持
    File systems  ---> 
        < > Second extended fs support                      //去掉对ext2的支持
        < > Ext3 journalling file system support             //去掉对ext3的支持
        DOS/FAT/NT Filesystems  --->                         //不作修改,对U盘的支持需要
c. 裁剪对驱动的支持
    Device Drivers  ---> 
        Input device support  ---> 
            [ ]     Provide legacy /dev/psaux device   //delete
            [ ]   Mice  --->                                   //delete
            [ ]   Keyboards  --->                             //delete
 d.继续裁剪
    File systems  ---> 
            CD-ROM/DVD Filesystems  --->
                < > ISO 9660 CDROM file system support //去掉对光盘的支持
            [*] Miscellaneous filesystems  ---> 
                < >   Compressed ROM file system support (cramfs) //delete
                [ ]     Include support for ZLIB compressed file systems //delete
                < >   ROM file system support //delete
    Device Drivers  --->
        Input device support  ---> 
            [*]   Touchscreens  --->
                <*>   Samsung S3C2410/generic touchscreen input driver //配置上该项
                < >   USB Touchscreen Driver   //delete

    Device Drivers  --->
            <*> Sound card support  ---> 
            <*>   Advanced Linux Sound Architecture  ---> 
            [ ]   USB sound devices  ---> //delete
    Device Drivers  --->
            [*] USB support  --->
                    [ ]   The shared table of common (or usual) storage devices   //delete

保存、退出编译内核

    # make uImage
    # cp arch/arm/boot/uImage /work/tftpboot/uImage_3.4.2_sm

烧写内核

    # tftp 30000000 uImage_3.4.2_sm
    # nand erase.part kernel; nand write 30000000 kernel

启动内核

    # set bootcmd 'nand read 30000000 kernel;bootm 30000000'
    # set bootargs console=ttySAC0,115200 root=/dev/mtdblock3
    # set machid 16a
    # save
    # boot

可正常启动

制作内核补丁

        # cp .config config_mini2440
        # make distclean
        # cd ..
        # mv linux-3.4.2 linux-3.4.2_mini2440 
        # tar xjv linux-3.4.2.tar.bz2
        # diff -urN linux-3.4.2 linux-3.4.2_mini2440 > linux-3.4.2_mini2440.patch

附上我移植的内核补丁,kernel_patch
使用内核补丁:

        # patch -p1 < ../linux-3.4.2_mini2440.patch 
        # cp config_mini2440 .config
        # make uImage

总结:移植测试过程采用的是SMDK2440的机器ID(16a),默认没有加入对网卡DM9000的支持,到这里该内核还不能够通过NFS方式挂接根文件系统,将在下一步完善该功能~~~,很多详细内容未作详细介绍,可参考我提到的资料~

原文地址:http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=29339876&id=4060797

你可能感兴趣的:(kernel)