关闭

linux 2.6.22.1内核在s3c2410平台的移植

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

linux 2.6.22.1内核在s3c2410平台的移植(完美版)

-------------------作者:无猫

++++++++++++++++++++++++++++++++++++++++++++++
----------------------------------------------
bootloader编译环境:
vivi版本:0.1.4
交叉编译器(CROSS-COMPILE)版本:2.95.3
(下载地址略:网上很多搜下。)
操作系统:Fedora 7
======================================
linux内核编译环境:
内核版本:linux2.6.22.1
交叉编译器(CROSS-COMPILE)版本: 4.2.0
(下载地址:
http://www.codesourcery.com/gnu_toolchains/arm/download.html
注意:下载选项,要选 ARM EABI 的选项,和 IA32 GNU/linux
操作系统: Fedora 7
======================================
文件系统编译环境:
busybox1.5.1,或1.4.2
交叉编译器(CROSS-COMPILE)版本: 3.3.2
(下载地址:http://linux.omap.com/pub/toolchain/
操作系统: Fedora 7
----------------------------------------------
硬件:
              板子是北京恒颐高科技术有限公司的H2410EB
              内存:               64MB SDRAM(2×16M×16位);
              CPU:                S3C2410 ARM处理器,
              Nor Flash:2MB的Nor Flash,用于固化测试程序(用来下载bootloader,内核,或文件系统);
              NANDflash: 64MB的Nand Flash,用于存储Bootloader、Linux内核及文件系统、应用程序和数据;
++++++++++++++++++++++++++++++++++++++++++++++

 

==================================================================================================
               一: 编译环境搭建
==================================================================================================
一:搭建交叉编译环境
说明:由于编译交叉编译环境比较繁琐,建议大家用已经编译好的交叉编译环境。
下面以3.3.2的交叉编译环境的搭建为例,其他的两个的编译器环境搭建一样。

1. 解压文件命令:
                  tar jxvf             obsolete-gcc-3.3.2.tar.bz2
                 (obsolete-gcc-3.3.2.tar.bz2下载地址:http://linux.omap.com/pub/toolchain/

2. 把解压的文件夹中的 “3.3.2”文件夹拷贝到 /usr/local/arm目录下
                 (如果没有arm目录就新建arm目录,但是一定要是拷贝到这个目录,不然不能运行)。

3. 在命令窗口输入
                  export PATH=/usr/local/arm/3.3.2/bin:$PATH

4. 如果输入 arm- 然后按下tab键能自动补全命令 arm-linux- 说明搭建成功。

 

===================================================================================================
                二:               bootloader 编译
===================================================================================================

二:             bootloader的修改

主要修改分区信息,如果要能下载yaffs文件系统还得另外打补丁,最近我会写编这样的文章。
具体修改:

1.               解压vivi(具体命令略,如果你解压都不会,移植可能对你来说有点困难)
                 [root@localhost vivi]# ls
                 arch               CVS                      drivers init Makefile                   Rules.make test vivi                vivi.map
                 COPYING Documentation include lib             Makefile.newSDK scrīpts               util vivi-elf

2.               [root@localhost vivi]# vim ./arch/s3c2410/smdk.c
修改 NAND flash 分区如下:
----------------------------------------------------------------------
mtd_partition_t default_mtd_partitions[] = {
                  {
                          name:                     "bootloader",
                          offset:                   0,
                          size:                     0x00020000,
                          flag:                     0
                  }, {
                          name:                     "param",
                          offset:                   0x00020000,
                          size:                     0x000E0000,
                          flag:                     0
                  }, {
                          name:                     "kernel",
                          offset:                   0x00100000,
                          size:                     0x00300000,
                          flag:                     0
                  }, {
                          name:                     "root",
                          offset:                   0x00400000,
                          size:                     0x01400000,
                          flag:                     MF_BONFS
                  }, {
                          name:                     "user",
                          offset:                   0x01800000,
                          size:                     0x02C00000,
                          flag:                     MF_BONFS
                  }
};
-------------------------------------------------------------------------

3. 修改Makefile
[root@localhost vivi]# vim Makefile
修改 ARCH              LINUX_INCLUDE_DIR             CROSS_COMPILE 如下:
------------------------------------------------------------------------

ARCH := arm

LINUX_INCLUDE_DIR                 = /usr/local/arm/2.95.3/include/

CROSS_COMPILE             = /usr/local/arm/2.95.3/bin/arm-linux-

3. 编译
[root@localhost vivi]# make

------------------------------------------------------------------------
会在 vivi目录生成你要的 vivi 程序(bootloader)
------------------------------------------------------------------------
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
说明:我的nand falsh的一块为16k,
所以上面的分区:

**************************************
             分区信息
**************************************
bootloader: 128k
param               : 896k
kernel              : 3M
root                : 20M
user                : 40M

**************************************
             bon 操作
**************************************
bon part 0 1M 4M:m 24M:m

解释一下上面的命令:
                  第1个分区从0开始;
                  第2个分区从0x30000(即192K)开始;
                  第3个分区从0x200000(即2M)开始;
                  第4个分区从0x400000(即4M)开始.

***********************************
             bon part info
***********************************

bon part info
BON info. (4 partitions)
No: offset                size                      flags               bad
---------------------------------------------
0: 0x00000000 0x00100000                00000000              0              1M
1: 0x00100000 0x00300000                00000000              0              3M
2: 0x00400000 0x01400000                00000001              0             20M
3: 0x01800000 0x027fc000                00000001              0             39M+1008k

***********************************
             part show
***********************************
mtdpart info. (5 partitions)
name                        offset                  size                  flag
------------------------------------------------
bootloader                : 0x00000000              0x00020000               0 128k
param                     : 0x00020000              0x000e0000               0 896k
kernel                    : 0x00100000              0x00300000               0              3M
root                      : 0x00400000              0x01400000               4             20M
user                      : 0x01800000              0x02c00000               4             44M
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


===================================================================================================
                三: 内核 编译
===================================================================================================

三: 内核 编译

注意:用的编译器是4.2.0的交叉编译器

1. 修改 Makefile
[root@localhost porting]# cd linux-2.6.22
[root@localhost linux-2.6.22]# vim Makefile

修改 ARCH 和 CROSS_COMPILE
--------------------------------------------------------------
ARCH                      ?= arm
CROSS_COMPILE             ?=/usr/local/arm/4.2.0/bin/arm-none-eabi-

2. 修改common-smdk.c文件
[root@localhost linux-2.6.22]# vim arch/arm/plat-s3c24xx/common-smdk.c
------------------------------------------------------------------------------
static struct mtd_partition smdk_default_nand_part[] = {
                  [0] = {
                          .name             = "Boot",
                          .size             = SZ_128K,
                          .offset = 0,
                  },
                  [1] = {
                          .name             = "param",
                          .offset = MTDPART_OFS_APPEND,
                          .size             = SZ_1M - SZ_128K,
                  },
                  [2] = {
                          .name             = "kernel",
                          .offset = SZ_1M,
                          .size             = SZ_1M * 3,
                  },
                  [3] = {
                          .name             = "root",
                          .offset = MTDPART_OFS_APPEND,
                          .size             = SZ_2M * 10,
                  },

/*
                ,
                  [5] = {
                          .name             = "S3C2410 flash partition 5",
                          .offset = SZ_1M * 14,
                          .size             = SZ_1M * 10,
                  },
                  [6] = {
                          .name             = "S3C2410 flash partition 6",
                          .offset = SZ_1M * 24,
                          .size             = SZ_1M * 24,
                  },
                  [7] = {
                          .name             = "S3C2410 flash partition 7",
                          .offset = SZ_1M * 48,
                          .size             = SZ_16M,
                  }
*/

};
---------------------------------------------------------------------------------

3. 去掉nand flash 的ECC
[root@localhost linux-2.6.22]# vim drivers/mtd/nand/s3c2410.c
---------------------------------------------------------------------------------
1、打开drivers/mtd/nand/s3c2410.c
2、搜索关键字NAND_ECC_SOFT,在s3c2410_nand_init_chip函数里
3、修改NAND_ECC_SOFT为NAND_ECC_NONE
---------------------------------------------------------------------------------

4. 支持启动时挂载devfs
为了我们的内核支持devfs以及在启动时并在/sbin/init运行之前能自动挂载/dev为devfs文件系统。
[root@localhost linux-2.6.22]# vi fs/Kconfig

-----------------------------------------------------------------------------------
找到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
----------------------------------------------------------------------------------

5. 编译内核
[root@localhost linux-2.6.22]# cp ./arch/arm/configs/s3c2410_defconfig .config
[root@localhost linux-2.6.21.5]# make xconfig

----------------------------------------------------------------------------------
Userspace binary formats
                   [ ]Kernel support for a.out and ECOFF binaries (BINFMT_AOUT) (去除该选项)

Boot options
             Default kernel command string
              改成:
              noinitrd root=/dev/mtdblock3 console=ttySAC0,115200 init=/linuxrc

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
再选上你想选的选项,如果编译通不过,对照着错误,看下把哪些选项去除,或添加哪些选项。
-----------------------------------------------------------------------------------

6. 编译
[root@localhost linux-2.6.22]# make zImage


===================================================================================================
                四:              文件系统的制作
===================================================================================================

四: 文件系统的制作
                注意:交叉编译器 3.3.2,             busybox1.5.1, 静态编译
                编译更详细的内容:

http://hi.baidu.com/wangy0919/blog/item/5959a819e8325978dab4bd52.html


1. busybox的编译

-----------------------------------------------------------------------------
一 修改busybox中的 Makefile文件
找到 ARCH 和 CROSS_COMPILE 修改成如下
ARCH                      ?= arm
CROSS_COMPILE             ?= /usr/local/arm/3.3.2/bin/arm-linux-

二 配置

[root@localhost busybox-1.4.2]# make defconfig
[root@localhost busybox-1.4.2]# make xconfig
=============================================
修改配置 主要修改如下
=============================================
Busybox Settings
               Build Options
              [*]Build BusyBox as a static binary    
                //选此项静态编译。

Miscellaneous Utilities
               []taskset              //选了就会出错

-------------------------------------------------
三 编译
[root@localhost busybox-1.5.1]# make all install
-----------------------------------------------------------------
最后会在 busybox-1.5.1/_install/目录生成你要的 bin sbin usr 目录
------------------------------------------------------------------

2. 编写linuxrc 文件
-----------------------------------------------------------------
#!/bin/sh
#echo "mount /etc as ramfs"
/bin/mount -n -t ramfs ramfs /etc
/bin/cp -a /mnt/etc/* /etc

echo "re-create the /etc/mtab entries"
# re-create the /etc/mtab entries
/bin/mount -f -t cramfs -o remount,ro /dev/mtdblock/3 /

#mount some file system
echo "mount /dev/shm as tmpfs"
/bin/mount -n -t tmpfs tmpfs /dev/shm


#挂载/proc为proc文件系统
echo "mount /proc as proc"
/bin/mount -n -t proc none /proc

#挂载/sys为sysfs文件系统
echo "mount /sys as sysfs"
/bin/mount -n -t sysfs none /sys

/bin/mount -f -t ramfs ramfs /etc

echo "yaffs is mounted"
/bin/mount -t yaffs /dev/mtdblock/1 /mnt/yaffs
exec /sbin/init
---------------------------------------------------------------------
3. 权限修改
chmod chmod 775 linuxrc

4. 编写 inittab文件

---------------------------------------------------------------------
::sysinit:/etc/init.d/rc

::askfirst:-/bin/sh
tty2::askfirst:-/bin/sh
tty3::askfirst:-/bin/sh
tty4::askfirst:-/bin/sh
tty0::askfirst:-/bin/sh
   
::restart:/sbin/init
        
::ctrlaltdel:/sbin/reboot
::shutdown:/bin/umount -a -r
::shutdown:/sbin/swapoff -a
----------------------------------------------------------------------

5. rc文件
----------------------------------------------------------------------
#!/bin/sh

/bin/mount -a
-----------------------------------------------------------------------

6. fastab 文件
----------------------------------------------------------------------
none             /proc             proc defaults 0 0
none             /dev/pts devpts mode=0622 0 0
tmpfs             /dev/shm tmpfs defaults 0 0
----------------------------------------------------------------------


7. 各文件的关系
----------------------------------------------------------------------
7.1 建立一个目标板的空根目录
我们将在这里构建构建根文件系统,创建基础目录结构. 存放交叉编译后生成的目标应用程序
(BUSYBOX,TINYLOGIN),存放库文件等。
[root@localhost rootfs]# mkdir my_rootfs
[root@localhost rootfs]# pwd
/home/arm/dev_home/rootfs/my_rootfs
[root@localhost rootfs]# cd my_rootfs
[root@localhost my_rootfs]#
7.2 在my_rootfs中建立Linux目录树
[root@localhost my_rootfs]#mkdir bin dev etc home lib mnt proc sbin sys tmp root usr
[root@localhost my_rootfs]#mkdir mnt/etc
[root@localhost my_rootfs]#mkdir usr/bin usr/lib usr/sbin
[root@localhost my_rootfs]#touch linuxrc
[root@localhost my_rootfs]#tree
|bin
|dev
|etc
|home
|lib
|linuxrc
/* 此文件为启动脚本,是一shell脚本文件。本文后面有专门介绍 */
|mnt
| `etc   
|proc
|sbin
|sys
|tmp
|root
`usr
|bin
|lib
`sbin

8. 把上面编译出来的 busybox文件拷贝到 my_rootfs 文件系统

---------------------------------------------------------------
把 busybox1.5.1/_install/目录下的 bin sbin usr 覆盖 my_rootfs
文件夹里的空文件夹。
--------------------------------------------------------------

9. 把 5 生成的文件(rc)拷贝到 /mnt/etc/init.d/目录(先在/mnt/etc/目录新建格init.d目录)
把 4,6生成的文件(inittab和 fastab )放到 /mnt/etc/目录
把 2 生成的文件linuxrc 放到/目录
                   这里所提到的 /目录即my_rootfs目录。
10. 新建/dev设备,在/dev目录(即my_rootfs/dev/).
mknod console c 5 1

8. 生成cramfs文件

下载mkfs.cramfs工具,然后用下面命令生成你要的cramfs文件系统
./mkfs.cramfs ./my_rootfs              ./root.cramfs

移植就这么简单,剩下的就是下载,烧写内核,文件系统等。聪明的你不用我说怎么做了吧
  
:)

 
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:21404次
    • 积分:338
    • 等级:
    • 排名:千里之外
    • 原创:3篇
    • 转载:23篇
    • 译文:0篇
    • 评论:0条
    文章存档