Linux2.6.32.2移植到Micro2440

原文地址:Linux2.6.32.2移植到Mini2440 作者:frankzfz

前几天一直在移植U-Boot2009.8,基本的移植已经结束,不过的使用tftp下载内核时还是有点问题,现在有点迫不及待的先移植了LInux2.6.32.2内核,先使用友善之臂的supervivi,下载引导Linux内核,算是给自己一点鼓励,成功后再使用U-Boot引导Linux内核。主要参考了友善之臂的移植文档。
 自从Linux-2.6.31开始,Linux内核就已经官方支持了mini2440,但是官方的内核版本对Mini2440的支持比较有限,所以还是需要一定的改变。不过,随着内核的发展,相信支持的也会越来越全面的。
1.移植内核的准备工作
(1)使用的环境
    操作系统:虚拟机VMware7.0+Ubuntu 9.10
    交叉编译工具使用:友善之臂的arm-linux-gcc-4.3.2
(2)获取内核
    获取内核的网址是:http://www.kernel.org/pub/linux/kernel/
    可以看到你里面有各种版本的Linux,下载现在要移植的Linux-2.6.32.2版本,如果Linux可以上网的话,可以使用wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.32.2.tar.gz,命令直接在当前的目录下进行下载。
(3)交叉编译工具
    交叉编译工具使用友善之臂的arm-linux-gcc-4.3.2,他们提供的编译器是符合EABI标准的编译器。其中关于EABI的介绍可以参看下面的连接:http://linux.chinaunix.net/bbs/thread-1143604-1-8.html,交叉编译器可以从www.arm9.net网站下载。
(4)硬件平台
    友善之臂的Mini2440,NandFlash128M,NorFlash2M的。NandFlash容量的不同,在后边制作根文件系统的时候会有所不同。
2. 修改内核以适应本开发板
   (1)假设我们把内核文件下载到了opt/kernel/目录下,进行解压操作。

#cd opt/kernel
# tar -zxvf linux-2.6.32.tar.gz

得到Linux-2.6.32文件夹
(2)修改Makefile文件
首先,我们要使Linux的默认的平台是arm平台,进入Linux-2.6.32文件夹中,修改此目录下的Makefile文件。大约在182行,修改成下面的代码,使其平台是ARM平台,交叉编译是arm-linux-.

export KBUILD_BUILDHOST := $(SUBARCH)
ARCH        ?= arm            //使用的目标平台
CROSS_COMPILE    ?= arm-linux- //使用的交叉编译器,这里使用的系统默认的

接下来,测试一下Linux内核是否可以顺利的编译通过。

#make s3c2410_defconfig //使用缺省的配置文件,也就是SMDK2440的缺省配置文件
# make   //编译时间大约在20分钟左右

(3)关于机器码
   很关键的一点是,在启动内核时,是根据bootloader传入的机器码(MACH_TYPE),来决定应启动那种目标平台,在这一版本中,友善之臂申请了字节的机器码1999,这和先前的2.6.29版本的内核,还是有所区别的。在文件opt/kernel/linux-2.6.32.2/arch/arm/tools/mach-types中

exeda            MACH_EXEDA        EXEDA            1994
mx31sf005        MACH_MX31SF005        MX31SF005        1995
f5d8231_4_v2        MACH_F5D8231_4_V2    F5D8231_4_V2        1996
q2440            MACH_Q2440        Q2440            1997
qq2440            MACH_QQ2440        QQ2440            1998
mini2440        MACH_MINI2440        MINI2440        1999 //机器码
colibri300        MACH_COLIBRI300        COLIBRI300        2000
jades            MACH_JADES        JADES            2001
spark            MACH_SPARK        SPARK            2002

如果传入的机器码和目标板的机器码不同时,经常出现下面的错误:

Uncompressing Linux.................................................................................................................................. done, booting 
the kernel. 
运行到这就停止了。 
 

在U-Boot2009.06版本中也加入了mini2440机器码,在下面的文件中u-boot-2009.08/include/asm-arm/mach-typs.h,大约在1985行。

#define MACH_TYPE_ARMATA 1993
#define MACH_TYPE_EXEDA 1994
#define MACH_TYPE_MX31SF005 1995
#define MACH_TYPE_F5D8231_4_V2 1996
#define MACH_TYPE_Q2440 1997
#define MACH_TYPE_QQ2440 1998
#define MACH_TYPE_MINI2440 1999
#define MACH_TYPE_COLIBRI300 2000
#define MACH_TYPE_JADES 2001
#define MACH_TYPE_SPARK 2002

在/kernel/linux-2.6.32.2/arch/arm/mach-s3c2440目录下有一个mach-mini2440.c这个就是该版本自带的一个mini2440的文件。不过我们不使用它,直接将其删除。
 将/kernel/linux-2.6.32.2/arch/arm/mach-s3c2440目录下的mach-smdk2440.c,复制一份,命名为mach-mini2440.c文件,因为,Mini2440和smdk2440的结构最为相似,上面的外围的电路也很相似,所以在其基础上进行修改移植。打开刚刚改名的mach-mini2440.c,找到MACHINE_START(S3C2440, "SMDK2440")
修改为下面的内容

MACHINE_START(MINI2440, "FriendlyARM MINI2440 development board")

(4)修改时钟源 
在 mach-mini2440.c的第 160 行static void __init smdk2440_map_io(void)函数中,把其中的 16934400(代表原 SMDK2440 目标板上的晶振是 16.9344MHz)改为 mini2440 开发板上实际使用的 12000000(代表 mini2440 开发板上的晶振 12MHz,元器件标号为 X2), 

static void __init mini2440_map_io(void)
{
    s3c24xx_init_io(mini2440_iodesc, ARRAY_SIZE(mini2440_iodesc));
    s3c24xx_init_clocks(12000000); //修改为 12000000
    s3c24xx_init_uarts(mini2440_uartcfgs, ARRAY_SIZE(mini2440_uartcfgs));
}

用VIM打开刚才复制得到的mach-mini2440.c文件,原来是smdk2440,所以将该文件中的所有的smdk2440替换成mini2440,可以在vim中,输入下面的命令进行替换;g表示全局替换,global.

%/smdk2440/mini2440/g

    除此之外,还要在 mini2440_machine_init(void)函数中,把smdk_machine_init()函数调用注释掉,因为我们后面会编写自己的初始化函数,不需要调用smdk2440 原来的。

static void __init mini2440_machine_init(void)
{
    s3c24xx_fb_set_platdata(&mini2440_fb_info);
    s3c_i2c0_set_platdata(NULL);
    s3c_device_nand.dev.platform_data = &mini2440_nand_info; //添加
    platform_add_devices(mini2440_devices, ARRAY_SIZE(mini2440_devices));
    
//smdk_machine_init()
}

编译测试,

#make mini2440_defconfig  //使用mini2440官方自带的配置文件

//编译的时间较长,最后在arch/arm/boot目录下生成zImage,也就是要下载到板子上的内核文件

#make zImage                        

这时下载到板子上不会启动系统,因为根文件系统还没有烧写。
(5)内核的配置菜单
    在这里先不用任何的配置,不过我们在这个版本的内核中,还是可以看到了对mini2440的支持选项可以选择。
在kernel/Linux-2.6.32.2/目录下使用下面的命令
    由于我的ubuntu9.10的make menuconfig显示的时候有乱码,在配置busybox时,无法选择选项,所以使用了图形话的配置界面。需要安装一些qt的文件。

make xconfig

(6)修改Nand分区信息
   在我们创建的mach-mini2440.c文件中添加NandFlash的分区信息,主要参考友善之臂的分区表。
   内容如下:添加下面的结构体

static struct mtd_partition mini2440_default_nand_part[] = {
    [0] = {
        .name    = "U-boot",//这里是 bootloader所在的分区,可以放置 u-boot,    
        .size    = 0x00040000,//
对应/dev/mtdblock0 
        .offset    = 0,
    },
    [1] = {
        .name    = "param",// ;这里是supervivi的参数区,其实也属于bootloader的
        .offset = 0x00040000,//
一部分,如果u-boot 比较大,可以把此区域覆盖掉
        .size    = 0x00020000,//不会影响系统启动,对应/dev/mtdblock1 
    },
    [2] = {
        .name    = "Kernel",//内核所在的分区,大小为 5M,足够放下大部分自己定制的
        .offset = 0x00060000,//
巨型内核了,比如内核使用了更大的Linux Logo图片
        .size    = 0x00500000,//
对应/dev/mtdblock2 
    },
    [3] = {
        .name    = "root",//文件系统分区,主要用来存放yaffs2 文件系统
        .offset = 0x00560000,//
内容,对应/dev/mtdblock3
        .size    = 1024 * 1024 * 1024, //

    },

 //此区域代表了整片的nand flash,主要是预留使用,比如以后可以通过应用程序访
问读取/dev/mtdblock4就能实现备份整片nand flash了。 可以没哟这个分区

    [4] = {
        .name    = "nand",
        .offset = 0x00000000,
        .size    = 1024 * 1024 * 1024, //

    }
};

还需要添加NandFlash的设置表。

//这里是开发板的nand flash 设置表,因为板子上只有一片,因此也就只有一个表 

static struct s3c2410_nand_set mini2440_nand_sets[] = {
    [0] = {
        .name        = "NAND",
        .nr_chips    = 1,
        .nr_partitions    = ARRAY_SIZE(mini2440_default_nand_part),
        .partitions    = mini2440_default_nand_part,
    },
};


//这里是nand flash本身的一些特性,一般需要对照datasheet填写,大部分情况下按照以下参数填写即可 

static struct s3c2410_platform_nand mini2440_nand_info = {
    .tacls        = 20,
    .twrph0        = 60,
    .twrph1        = 20,
    .nr_sets    = ARRAY_SIZE(mini2440_nand_sets),
    .sets        = mini2440_nand_sets,
    .ignore_unset_ecc = 1,
};

还需要把 nand flash 设备注册到系统中,

static struct platform_device *mini2440_devices[] __initdata = {
    &s3c_device_usb,
    &s3c_device_lcd,
    &s3c_device_wdt,
    &s3c_device_i2c0,
    &s3c_device_iis,
    &s3c_device_nand,//把nand flash设备添加到开发板的设备列表结构 
};

在mini2440_machine_init函数中添加平台的数据信息。

static void __init mini2440_machine_init(void)
{
    s3c24xx_fb_set_platdata(&mini2440_fb_info);
    s3c_i2c0_set_platdata(NULL);
    s3c_device_nand.dev.platform_data = &mini2440_nand_info; //添加
    platform_add_devices(mini2440_devices, ARRAY_SIZE(mini2440_devices));
}

不过还要在该文件中添加几个头文件才能编译成功:

/*添加下面的四个文件*/
#include <linux/mtd/mtd.h>
#include <linux/mtd/nand.h>
#include <linux/mtd/nand_ecc.h>
#include <linux/mtd/partitions.h>


#include <plat/s3c2410.h>
#include <plat/s3c2440.h>
#include <plat/clock.h>
#include <plat/devs.h>
#include <plat/cpu.h>
#include <plat/nand.h> //添加

到这里就完成了NandFlash的驱动的移植,可以下载到开发板运行看看启动的信息了。
makge zImage后,把生成的内核的文件下载到开发板中,可以看到下面的启动信息;
激动人心的时刻到了;

load Image of Linux...Uncompressing Linux.................
Linux version 2.6.32.(zfz@zfz) (gcc version 4.3.(Sourcery G++ Lite 2008q3-70
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177 
CPU: VIVT data cache, VIVT instruction cache 
Machine: FriendlyARM MINI2440 development board 
ATAG_INITRD is deprecated; please update your bootloader. 
Memory policy: ECC disabled, Data cache writeback 
CPU S3C2440A (id 0x32440001) 
S3C24XX Clocks, (c) 2004 Simtec Electronics 
S3C244X: core 405.000 MHz, memory 101.250 MHz, peripheral 50.625 MHz 
CLOCK: Slow mode (1.500 MHz), fast, MPLL on, UPLL on 
Built 1 zonelists in Zone order, mobility grouping on. Total pages: 16256 
Kernel command line: noinitrd root=/dev/mtdblock3 init=/linuxrc console=ttySAC0 
PID hash table entries: 256 (order: -2, 1024 bytes) 
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: 60596KB available (3588K code, 417K data, 132K init, 0K highmem) 
SLUB: Genslabs=11, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=
Hierarchical RCU implementation. 
NR_IRQS:85 
irq: clearing subpending status 00000002 
Console: colour dummy device 80x30 
console [ttySAC0] enabled 
Calibrating delay loop... 201.93 BogoMIPS (lpj=504832) 
Mount-cache hash table entries: 512 
CPU: Testing write buffer coherency: ok 
NET: Registered protocol family 16 
S3C2440: Initialising architecture 
S3C2440: IRQ Support 
S3C24XX DMA Driver, (c) 2003-2004,2006 Simtec Electronics 
DMA channel 0 at c4808000, irq 33 
DMA channel 1 at c4808040, irq 34 
DMA channel 2 at c4808080, irq 35 
DMA channel 3 at c48080c0, irq 36 
S3C244X: Clock Support, DVS off 
bio: create slab <bio-0> at 0 
usbcore: registered new interface driver usbfs 
usbcore: registered new interface driver hub 
usbcore: registered new device driver usb 
s3c-i2c s3c2440-i2c: slave address 0x10 
s3c-i2c s3c2440-i2c: bus frequency set to 98 KHz 
s3c-i2c s3c2440-i2c: i2c-0: S3C I2C adapter 
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 
NET: Registered protocol family 1 
RPC: Registered udp transport module. 
RPC: Registered tcp transport module. 
RPC: Registered tcp NFSv4.1 backchannel transport module. 
JFFS2 version 2.2. (NAND) ?&#169; 2001-2006 Red Hat, Inc. 
ROMFS MTD (C) 2007 Red Hat, Inc. 
msgmni has been set to 118 
alg: No test for stdrng (krng) 
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 
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 
brd: module loaded 
S3C24XX NAND Driver, (c) 2004 Simtec Electronics 
s3c24xx-nand s3c2440-nand: Tacls=3, 29ns Twrph0=7 69ns, Twrph1=3 29ns 
s3c24xx-nand s3c2440-nand: NAND soft ECC 
NAND device: Manufacturer ID: 0xec, Chip ID: 0xf1 (Samsung NAND 128MiB 3,3V 8-b)
Scanning device for bad blocks 
Creating 5 MTD partitions on "NAND 128MiB 3,3V 8-bit": 
0x000000000000-0x000000040000 : "U-boot" 
0x000000040000-0x000000060000 : "param" 
ftl_cs: FTL header not found. 
0x000000060000-0x000000560000 : "Kernel" 
uncorrectable error : 
0x000000560000-0x000040560000 : "root" 
mtd: partition "root" extends beyond the end of device "NAND 128MiB 3,3V 8-bit"0
ftl_cs: FTL header not found. 
0x000000000000-0x000040000000 : "nand" 
mtd: partition "nand" extends beyond the end of device "NAND 128MiB 3,3V 8-bit"0
dm9000 Ethernet Driver, V1.31 
ohci_hcd: USB 1.'Open' Host Controller (OHCI) Driver 
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 
usbcore: registered new interface driver libusual 
mice: PS/2 mouse device common for all mice 
S3C24XX RTC, (c) 2004,2006 Simtec Electronics 
i2c /dev entries driver 
S3C2410 Watchdog Timer, (c) 2004 Simtec Electronics 
s3c2410-wdt s3c2410-wdt: watchdog inactive, reset disabled, irq enabled 
cpuidle: using governor ladder 
sdhci: Secure Digital Host Controller Interface driver 
sdhci: Copyright(c) Pierre Ossman 
usbcore: registered new interface driver hiddev 
usbcore: registered new interface driver usbhid 
usbhid: v2.6:USB HID core driver 
Advanced Linux Sound Architecture Driver Version 1.0.21. 
No device for DAI UDA134X 
No device for DAI s3c24xx-i2s 
ALSA device list: 
  No soundcards found. 
TCP cubic registered 
NET: Registered protocol family 17 
drivers/rtc/hctosys.c: unable to open rtc device (rtc0) 
List of all partitions: 
1f00 256 mtdblock0 (driver?) 
1f01 128 mtdblock1 (driver?) 
1f02 5120 mtdblock2 (driver?) 
1f03 125568 mtdblock3 (driver?) 
1f04 131072 mtdblock4 (driver?) 
No filesystem could mount root, tried: ext3 cramfs vfat msdos romfs 
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(31,3) 
[<c002e9f8>] (unwind_backtrace+0x0/0xdc) from [<c02d0390>] (panic+0x40/0x120) 
[<c02d0390>] (panic+0x40/0x120) from [<c0008e84>] (mount_block_root+0x1d0/0x210)
[<c0008e84>] (mount_block_root+0x1d0/0x210) from [<c000911c>] (prepare_namespac)
[<c000911c>] (prepare_namespace+0x164/0x1bc) from [<c000843c>] (kernel_init+0xd)
[<c000843c>] (kernel_init+0xd8/0x10c) from [<c002a854>] (kernel_thread_exit+0x0)

在红色的部分,我们可以看到Linux内核启动是可以识别出了NandFlash的大小和,ID号,还有我们分的5个分区的大小。
这时我们还没有把我们的根文件系统烧写进去,所以还是没有办法出来下面的这句话:

Please press Enter to activate this console.

 到此。基本的Linux内核就移植完了,下一步移植根文件系统。

PS:因为我的板子是Micro2440,bootloader是super vivi;因此需要主要第2步第(3)点的机器码1999修改为super vivi对应的机器码:782或者362(其实linux启动时会显示mach type的:MACH_TYPE = 782)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值