Linux 系统移植arm s3c2410

ARM 94浏览

 

http://blog.csdn.net/LEOBB_DB/archive/2009/11/11/4798076.aspx

 

一、u-boot基本常用命令
1. 基本环境设置
setenv serverip 192.168.1.201
setenv ipaddr  192.168.1.211
setenv gatewayip 192.168.1.1
setenv ethaddr 11:22:33:44:55:66

setenv bootargs root=/dev/mtdblock2 rootfstype=yaffs init=/linuxrc mem=64M console=ttySAC0,115200

saveenv

2. 烧写Boot
tftp 30008000 u-boot-v1.0.bin
nand erase 0 30000
nand write 30008000 0 30000 

3. 加载内核
tftp 30008000 zImage
go 30008000

4. 烧写rootfs
   tftp 30008000 rootfs_udev.yaffs
   tftp 30008000 rootfs_mdev.yaffs    //只考这里其中一个即可
   nand erase 240000 800000
   nand write.yaffs 30008000 240000 $(filesize) 

   setenv bootargs root=/dev/mtdblock2 rootfstype=yaffs init=/linuxrc mem=64M console=ttySAC0,115200
   saveenv

5.  烧写内核

tftp 30008000 zImage
nand erase 40000 200000
nand write 30008000 40000 200000

setenv bootcmd nand read 30008000 40000 200000 /; go 30008000
saveenv

6. erase appfs分区
nand erase 1240000 2DC0000

7. 使用nfs配置:

setenv bootargs root=nfs nfsroot=192.168.1.201:/source/rootfs ip=192.168.1.211 console=ttySAC0,115200 init=/linuxrc mem=64M

二、Linux 2.6.19 fs2410 移植
1.修改nand flash分区:    (1和2让内核可以识别yaffs文件系统,因为本出用的内核不支持yaffs文件系统,所以要分区和打补丁)
   原始分区为八个分区,与64MB不匹配;所以分为四个;可以根据自己的需求来分区
arch/arm/plat-s3c24xx/common-smdk.c

/* NAND parititon from 2.4.18-swl5 */
static struct mtd_partition smdk_default_nand_part[] = {
        [0] = {
                .name   = "BootLoader",
                .size   = 0x00040000,   /* 256KB */
                .offset = 0,
        },
        [1] = {
                .name   = "Kernel",
                .size   = 0x00200000,   /* 2MB */
                .offset = 0x00040000,
        },
        [2] = {
                .name   = "Rootfs",
                .size   = 0x01000000,   /* 16MB */
                .offset = 0x00240000,
        },
        [3] = {
                .name   = "Appfs",
                .size   = 0x02DC0000,   /* 44MB + 792KB */
                .offset = 0x01240000,
        }
};
make
把生成的zImage放
到tftpboot

开发板:
       tftp ipserver
       tftp 30008000 zImage
      go 30008000

//Erase Kernel Partition
nand erase 40000 200000

//Erase Rootfs Partition
nand erase 240000 1000000

//Erase Appfs Partition
nand erase 1240000 2DC0000

2. 挂载yaffs文件系统:
   yaffs2补丁:

./patch-ker.sh c ../linux-2.6.29-fs2410    把补丁打到内核中,
     可以再Kconfig中查看; surce "fs/yaffs2/Kconfig"
      在Makefile中也有更改,且把一些文件考到内核源码中
      由此把yaffs文件系统放入内核中;
make menuconfig
     把File system -->Miscellaneous filesystems-->YAFFS FILE SYSTEM SUPPORT;LETS YAFFS DO ITS OWN  ECC;都选上

3. cs8900网络驱动移植 (cs8900a.c, cs8900a.h,注意*a.c里面有个include cs8900.h 要加个a)考到driver/net   再修改kconfig
(1)
arch/arm/plat-s3c24xx/devs.c

/* CS8900 netif -- Addde by fengyong*/

static struct resource cs8900_resource[] = {
 [0] = {
  .start = 0x19000300,
  .end   = 0x19000310,
  .flags = IORESOURCE_MEM,
 },
 [1] = {
  .start = IRQ_EINT9,
  .end   = IRQ_EINT9,
  .flags = IORESOURCE_IRQ,
 }
};

struct platform_device net_device_cs8900 = {
 .name    = "cs8900",
 .id    = -1,
 .num_resources   = ARRAY_SIZE(cs8900_resource),
 .resource   = cs8900_resource,
};

EXPORT_SYMBOL(net_device_cs8900);

(2)
arch/arm/plat-s3c/include/plat/devs.h

extern struct platform_device net_device_cs8900;   //Added by fengyong

(3)
arch/arm/mach-s32410/mach-smdk2410.c

static struct platform_device *smdk2410_devices[] __initdata = {
 &s3c_device_usb,
 &s3c_device_lcd,
 &s3c_device_wdt,
 &s3c_device_i2c0,
 &s3c_device_iis, 
 &net_device_cs8900,    //Added by fengyong
};

(4)
drivers/net/Kconfig

加入
config CS8900A
 tristate "CS8900A support"
 depends on ARM && ARCH_S3C2410
 ---help---
   Support for cs8900a chipset.

   To compile this driver as a module, choose M here.  The module
   will be called cs8900a.

(5)修改drivers/net/Makefile

obj-$(CONFIG_CS8900A) += cs8900a.o  就在menuconfig中加入了cs8900a选项,

  (6)vim etc/init.d/rcs配置网路
    #networking
         /sbin/ifconfig lo 127.0.0.1 up
        /sbin/ifconfig eth0 ip netmask 255.......   up
       /sbin/route add default gw 192.168.1.1

4. USB MassStorage 驱动移植
static void __init smdk2410_init(void)
{
 u32 val = 0;

 s3c24xx_fb_set_platdata(&fs2410_fb_info);

 s3c_i2c0_set_platdata(NULL);
 platform_add_devices(smdk2410_devices, ARRAY_SIZE(smdk2410_devices));
 smdk_machine_init();

 //Added by fengyong
 val = (0x78 << 12) | (0x02 << 4) | (0x03);
 writel(val, S3C2410_UPLLCON);
}

mount -t  vfat  /dev/sda1 /mnt/udisk  出错则修改内核配置
file system--dos/fat/nt ---(437)default    -- 改成  936
编译

开发板上  mount -t vfat -o iocharset=cp936 /dev/sda1 /mnt/udisk  会出现中文显示

5. SD卡
make menuconfig
device driver--mmc/sd/sd10 card suppport选中--mmc block device driver ,use bounce ,samsumg s3c sd/mmc card interface support 退出

arch/arm/mach-s32410/mach-smdk2410.c
static struct platform_device *smdk2410_devices[] __initdata = {
 &s3c_device_usb,
 &s3c_device_lcd,
 &s3c_device_wdt,
 &s3c_device_i2c0,
 &s3c_device_iis,
 &s3c_device_sdi,        //Added
 &net_device_cs8900,
};

drivers/mmc/host/s3cmic.c
 s3cmci_probe函数中:

 //host->irq_cd = s3c2410_gpio_getirq(host->pdata->gpio_detect);
 host->irq_cd = IRQ_EINT18;
 s3c2410_gpio_cfgpin(S3C2410_GPG10, S3C2410_GPG10_EINT18);

make zImage

mount -t vfat -o iocharset=cp932 /dev/mmcblk0p1 /mnt/sdfs

6. LCD
arch/arm/mach-s32410/mach-smdk2410.c
#include <mach/fb.h>

/* LCD driver info */
static struct s3c2410fb_display fs2410_lcd_cfg[] __initdata = {
        {
                /* Config for 320x240 LCD */
                .lcdcon5 = S3C2410_LCDCON5_FRM565 |
                           S3C2410_LCDCON5_INVVLINE |
                           S3C2410_LCDCON5_INVVFRAME |
                           S3C2410_LCDCON5_PWREN |
                           S3C2410_LCDCON5_HWSWP,

                .type           = S3C2410_LCDCON1_TFT,
                .width          = 320,
                .height         = 240,
                .pixclock       = 100000, /* HCLK/10 */
                .xres           = 320,
                .yres           = 240,
                .bpp            = 16,
                .left_margin    = 13,
                .right_margin   = 8,
                .hsync_len      = 4,   //58
                .upper_margin   = 2,
                .lower_margin   = 7,
                .vsync_len      = 4, //18
        },
};

static struct s3c2410fb_mach_info fs2410_fb_info __initdata = {
        .displays       = fs2410_lcd_cfg,
        .num_displays   = ARRAY_SIZE(fs2410_lcd_cfg),
        .default_display = 0,

        .gpccon = 0xaaaaaaaa,
        .gpccon_mask = 0xffffffff,
        .gpcup = 0x0000ffff,
        .gpcup_mask = 0xffffffff,

        .gpdcon = 0xaaaaaaaa,
        .gpdcon_mask = 0xffffffff,
        .gpdup = 0x0000ffff,
        .gpdup_mask = 0xffffffff,
 
        .lpcsel         = ((0xCE6) & ~7) | 1<<4,
};

static void __init smdk2410_init(void)
{
        s3c24xx_fb_set_platdata(&fs2410_fb_info);       //Added by fengyong for LCD

        s3c_i2c0_set_platdata(NULL);
        platform_add_devices(smdk2410_devices, ARRAY_SIZE(smdk2410_devices));
        smdk_machine_init();
}

make menuconfig
   device driver ---graphics supports(选中)--support for frme buffer (---s3c2410)
                                                                --bootup logo  缺省
make zImage

bmp_arry_320*240.exe工具修改位图为开发板识别格式
cp name.img /dev/fb0

7. rootfs 文件系统

udev 和mdev:

在/etc/init.d/rcS脚本中

mdev:

    /bin/echo /sbin/mdev > /proc/sys/kernel/hotplug
    /sbin/mdev -s
    放开,屏蔽udev
udev:
  vi /etc/init.d/rcS
     /sbin/udevd --daemon
     /sbin/udevstart
    屏蔽mdev

加到mounting file system .....后面
    /bin/mknod  /dev/null  c  1 3
    /bin/mknod /dev/console c 5 1

mdev和udev在rootfs中只能使用其中一种。

烧写制作3种文件系统:

crmafs:
   ./mkfs.cramfs rootfs rootfs.cramfs //制作crmafs映像  

   tftp 30008000 rootfs.cramfs
   nand erase 240000 800000
   nand write 30008000 240000 $(filesize) 

   setenv bootargs root=/dev/mtdblock2 rootfstype=cramfs init=/linuxrc mem=64M console=ttySAC0,115200
   saveenv

jffs2:
   ./mkfs.jffs2 -r ./rootfs -o rootfs.jffs2 -e 0x4000 --pad=0x800000 -n //制作jffs2映像
 
   tftp 30008000 rootfs.jffs2
   nand erase 240000 800000
   nand write.jffs2 30008000 240000 800000 

   setenv bootargs root=/dev/mtdblock2 rootfstype=jffs2 rw init=/linuxrc mem=64M console=ttySAC0,115200
   saveenv

yaffs:
   ./mkyaffs2image rootfs rpptfs.yaffs
 
   tftp 30008000 rootfs.yaffs
   nand erase 240000 800000
   nand write.yaffs 30008000 240000 $(filesize) 

   setenv bootargs root=/dev/mtdblock2 rootfstype=yaffs init=/linuxrc mem=64M console=ttySAC0,115200
   saveenv
8.wget 下载图片,并在显示屏上显示
    inux下安装ftp(apt-get install vsftpd)
    将图片拷贝到/home/ftp下(首先建好ftp目录)
   启动内核(tftp 30008000 zImage  & go 30008000)
   wget ftp://192.168.1.137/i.img

   cp i.img /dev/fb0

9.启动优化

1. make menuconfig : drivers/character devices --> pty 255->8   //255表有255个pty设备结点,telnet能同时登陆的用户个数
  
2. tty
  /include/linux/vt.h

#define MIN_NR_CONSOLES 1       /* must be at least 1 */
#define MAX_NR_CONSOLES 8       //63    /* serial lines start at 64 */  //表示有63个tty设备结点,串口虚拟终端个数,不是uart series;
#define MAX_NR_USER_CONSOLES 8  //63    /* must be root to allocate above this */