2010年5月4日 星期二

移植Linux-2.6.30.4到mini2440

移植Linux-2.6.30.4到mini2440
1)交叉編譯器使用CodeSourcery提供的符合EABI標準的arm-none-linux-gnueabi-gcc-4.3.3交叉編譯器,下載地址:
http://www.codesourcery.com/sgpp/lite/arm/portal/package4571/public/arm-none-linux-gnueabi/arm-2009q1-203-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
2)下載後,解壓到/opt/目錄:
# tar jxvf arm-2009q1-203-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2 -C /opt/
3)因為/opt/arm-2009q1/bin/目錄中的可執行檔均以不常用的" arm-none-linux-gnueabi- "開頭,做幾個arm-linux-xxx軟鏈結以方便日後使用:
ln -s arm-none-linux-gnueabi-gdbtui arm-linux-gdbtui
ln -s arm-none-linux-gnueabi-addr2line arm-linux-addr2line
ln -s arm-none-linux-gnueabi-gprof arm-linux-gprof
ln -s arm-none-linux-gnueabi-ar arm-linux-ar
ln -s arm-none-linux-gnueabi-as arm-linux-as
ln -s arm-none-linux-gnueabi-nm arm-linux-nm
ln -s arm-none-linux-gnueabi-ld arm-linux-ld
ln -s arm-none-linux-gnueabi-c++ arm-linux-c++
ln -s arm-none-linux-gnueabi-objcopy arm-linux-objcopy
ln -s arm-none-linux-gnueabi-c++filt arm-linux-c++filt
ln -s arm-none-linux-gnueabi-cpp arm-linux-cpp
ln -s arm-none-linux-gnueabi-ranlib arm-linux-ranlib
ln -s arm-none-linux-gnueabi-objdump arm-linux-objdump
ln -s arm-none-linux-gnueabi-readelf arm-linux-readelf
ln -s arm-none-linux-gnueabi-size arm-linux-size
ln -s arm-none-linux-gnueabi-gcov arm-linux-gcov
ln -s arm-none-linux-gnueabi-strings arm-linux-strings
ln -s arm-none-linux-gnueabi-gdb arm-linux-gdb
ln -s arm-none-linux-gnueabi-strip arm-linux-strip
ln -s arm-none-linux-gnueabi-sprite arm-linux-sprite
4)同時在/opt/arm-2009q1/bin/目錄建立如下三個腳本:
腳本arm-linux-g++的內容:
#!/bin/sh
arm-none-linux-gnueabi-g++ -march=armv4t $*
腳本arm-linux-gcc的內容:
#!/bin/sh
arm-none-linux-gnueabi-gcc -march=armv4t $*
腳本arm-linux-gcc-4.3.3的內容:
#!/bin/sh
arm-none-linux-gnueabi-gcc-4.3.3 -march=armv4t $*




5)為以上三個腳本加上可執行屬性:
# chmod +x arm-linux-g++
# chmod +x arm-linux-gcc
# chmod +x arm-linux-gcc-4.3.3

6)輸出交叉編譯器的可執行檔的路徑到PATH環境變數:
# export PATH=/opt/arm-2009q1/bin:$PATH

以後要用到arm-linux-gcc-4.3.3交叉編譯器時都應該先在終端上執行上面一句!

7)查看是否安裝成功:
# arm-linux-gcc -v
如果成功的話,可以看到如下資訊:
Using built-in specs.
Target: arm-none-linux-gnueabi
Configured with: /scratch/mitchell/builds/4.3-arm-none-linux-gnueabi-respin/src/gcc-4.3/configure --build=i686-pc-linux-gnu --host=i686-pc-linux-gnu --target=arm-none-linux-gnueabi --enable-threads --disable-libmudflap --disable-libssp --disable-libstdcxx-pch --with-gnu-as --with-gnu-ld --with-specs='%{funwind-tables|fno-unwind-tables|mabi=*|ffreestanding|nostdlib:;:-funwind-tables}' --enable-languages=c,c++ --enable-shared --enable-symvers=gnu --enable-__cxa_atexit --with-pkgversion='Sourcery G++ Lite 2009q1-203' --with-bugurl=https://support.codesourcery.com/GNUToolchain/ --disable-nls --prefix=/opt/codesourcery --with-sysroot=/opt/codesourcery/arm-none-linux-gnueabi/libc --with-build-sysroot=/scratch/mitchell/builds/4.3-arm-none-linux-gnueabi-respin/lite/install/arm-none-linux-gnueabi/libc --with-gmp=/scratch/mitchell/builds/4.3-arm-none-linux-gnueabi-respin/lite/obj/host-libs-2009q1-203-arm-none-linux-gnueabi-i686-pc-linux-gnu/usr --with-mpfr=/scratch/mitchell/builds/4.3-arm-none-linux-gnueabi-respin/lite/obj/host-libs-2009q1-203-arm-none-linux-gnueabi-i686-pc-linux-gnu/usr --disable-libgomp --enable-poison-system-directories --with-build-time-tools=/scratch/mitchell/builds/4.3-arm-none-linux-gnueabi-respin/lite/install/arm-none-linux-gnueabi/bin --with-build-time-tools=/scratch/mitchell/builds/4.3-arm-none-linux-gnueabi-respin/lite/install/arm-none-linux-gnueabi/bin
Thread model: posix
gcc version 4.3.3 (Sourcery G++ Lite 2009q1-203)

二、準備源碼包
1)Linux 2.6.30.4的下載地址:
http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.30.4.tar.bz2

2)yaffs2檔系統的下載位址:
http://www.aleph1.co.uk/cgi-bin/viewcvs.cgi/
點擊Download GNU tarball,下載cvs-root.tar.gz

請把linux-2.6.30.4.tar.bz2和cvs-root.tar.gz放在同一目錄內!

三、移植內核
1)解壓內核源碼包
# tar jxvf linux-2.6.30.4.tar.bz2

2)進入內核目錄
# cd linux-2.6.30.4

3)修改頂層Makefile
# gedit Makefile
在193行
ARCH ?= $(SUBARCH)
CROSS_COMPILE ?=
修改為
ARCH ?= arm
CROSS_COMPILE ?= /opt/arm-2009q1/bin/arm-linux-

4)修改機器碼
# gedit arch/arm/tools/mach-types
在379行
s3c2440 ARCH_S3C2440 S3C2440 362
修改為
s3c2440 ARCH_S3C2440 S3C2440 782
與supervivi傳入的機器碼參數一致即可!

5)修改時鐘頻率
# gedit arch/arm/mach-s3c2440/mach-smdk2440.c
在160行
static void __init smdk2440_map_io(void)
{
s3c24xx_init_io(smdk2440_iodesc, ARRAY_SIZE(smdk2440_iodesc));
//s3c24xx_init_clocks(16934400); //注釋這句,加入下一句
s3c24xx_init_clocks(12000000);
s3c24xx_init_uarts(smdk2440_uartcfgs, ARRAY_SIZE(smdk2440_uartcfgs));
}

6)修改Nand Flash分區
# gedit arch/arm/plat-s3c24xx/common-smdk.c
在109行
static struct mtd_partition smdk_default_nand_part[] = {
[0] = {
.name = "supervivi",
.size = 0x00030000,
.offset = 0,
},
[1] = {
.name = "Kernel",
.offset = 0x00050000,
.size = 0x00200000,
},
[2] = {
.name = "root",
.offset = 0x00250000,
.size = 0x03dac000,
}
};


四、配置內核
# cp arch/arm/configs/s3c2410_defconfig .config
# make menuconfig
機器類型只選以下三項:
System Type ---> S3C2410 Machines --->



[*] SMDK2410/A9M2410



S3C2440 Machines --->



[*] SMDK2440



[*] SMDK2440 with S3C2440 CPU module

內核特性加上以下兩項:
Kernel Features --->



[*] Use the ARM EABI to compile the kernel
[*] Allow old ABI binaries to run with this(EXPERIMENTA) kernel


如果你想瞭解每個配置選項的意義,請點擊:Linux 2.6.19.x 內核編譯配置選項簡介

五、編譯內核
# make zImage


六、下載、燒寫內核鏡像
先使用友善之臂公司提供的yaffs2根檔系統鏡像做測試,可以運行到這裏:
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 2048 mtdblock1 (driver?)
1f02 63152 mtdblock2 (driver?)
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(31,2)
[] (unwind_backtrace+0x0/0xdc) from [] (panic+0x40/0x110)
[] (panic+0x40/0x110) from [] (mount_block_root+0x1d0/0x210)
[] (mount_block_root+0x1d0/0x210) from [] (prepare_namespac)
[] (prepare_namespace+0x164/0x1bc) from [] (kernel_init+0xb)
[] (kernel_init+0xb4/0xe0) from [] (do_exit+0x0/0x578)
[] (do_exit+0x0/0x578) from [<00000001>] (0x1)


七、加入對yaffs2檔系統的支援
1)回到上級目錄
# cd ..

2)解壓yaffs2檔系統源碼包
# tar zxvf cvs-root.tar.gz

3)進入yaffs2源碼目錄
# cd cvs/yaffs2

4)打補丁
# ./patch-ker.sh c ../../linux-2.6.30.4
Updating ../../linux-2.6.30.4/fs/Kconfig
Updating ../../linux-2.6.30.4/fs/Makefile

5)回到內核目錄
# cd ../../linux-2.6.30.4

6)重新配置
# make menuconfig
選上以下一項:
File systems ---> [*] Miscellaneous filesystems ---> <*> YAFFS2 file system support

7)重新編譯內核
# make zImage


八、重新下載、燒寫內核鏡像
yaffs: dev is 32505858 name is "mtdblock2"
yaffs: passed flags ""
yaffs: Attempting MTD mount on 31.2, "mtdblock2"
yaffs_read_super: isCheckpointed 0
VFS: Mounted root (yaffs filesystem) on device 31:2.
Freeing init memory: 120K
mount: mounting /dev/sda2 on /opt failed: No such file or directory
mkdir: cannot create directory '/udisk': File exists
mount: mounting /dev/sda1 on /udisk failed: No such file or directory

Please press Enter to activate this console.
[root@jjx /]#

成功進入控制臺,內核算是移植成功了~~










1 則留言:

  1. mini2440 u-boot & kernel 系統移植
    https://chenlinslim.wordpress.com/

    回覆刪除