Chinaunix首页 | 论坛 | 博客
  • 博客访问: 32521
  • 博文数量: 9
  • 博客积分: 372
  • 博客等级: 一等列兵
  • 技术积分: 140
  • 用 户 组: 普通用户
  • 注册时间: 2010-04-16 11:59
文章分类

全部博文(9)

文章存档

2013年(1)

2010年(8)

我的朋友

分类: LINUX

2010-04-16 14:02:00

飞凌OK-2440-III文件系统移植-------busybox+mdev

编译busybox的组合
busybox-1.0.0   arm-linux-gcc-2.95.3
busybox-1.1.3   arm-linux-gcc-3.3.2
buxybox-1.7.3   arm-linux-gcc-3.4.1

目标板:飞凌OK-2440-III

编译平台:redhat9

一、配置安装busybox

交叉编译工具:arm-linux-gcc-3.3.2

Busybox-1.1.3

Gcc-3.3.2busybox-1.1.3搭配才可以正常编译。

配置busybox

 #make menuconfig

 

  Busybox Settings >

 

  General Configuration >

  [*] Support for devfs

 

  Init Utilities >

  [*] init

  [*] Support reading an inittab file /* init读取/etc/inittab配置文件,不知道怎么回事,这个和他的意思是反的,选上之后反倒不支持inittab文件了,不选才支持,你可以自己试试。 */

   [*]     Be _extra_ quiet on boot      

   [*]     Support running init from within an initrd (not initramfs)

   [*] poweroff, halt, and reboot

   [*] mesg

 

  Shells >

 

  Choose your default shell (ash) >

  /* (X) ash 选中ash,这样生成的时候才会生成bin/sh文件

  * 看看我们前头的linuxrc脚本的头一句:

  * #!/bin/sh 是由bin/sh来解释执行的

  */ (我开始就因为在这里没选上,结果就造成启动不起来 

  [*] ash

 

添加历史记录、自动补全、删除字符的功能:

   Shells --->

---   Bourne Shell Options                                          

   [ ]   Hide message on interactive shell startup                  

   [ ]   Standalone shell                                           

   [*]   command line editing                                       

   [*]     vi-style line editing commands                           

      (15)    history size                                         

   [*]     history saving                                           

   [*]     tab completion                                           

   [*]       username completion                                    

   [ ]     Fancy shell prompts

 

  Coreutils >

  [*] cp

  [*] cat

  [*] ls  ls里关于颜色的一定不能选,不然在DNW里打开了是乱码

  [*] mkdir

  [*] echo (basic SuSv3 version taking no options)

  [*] env

  [*] mv

  [*] pwd

  [*] rm

  [*] touch

Miscellaneous Utilities  --->

                 [] taskset要去掉

 

  Editors >

  [*] vi

 

  Linux System Utilities >

  [*] mount

  [*] umount

  [*] Support loopback mounts

  [*] Support for the old /etc/mtab file

 

    Linux Module Utilities  --->

    [*] insmod                

    [*] rmmod      

    [*] lsmod       

    [*]   lsmod pretty output for 2.6.x Linux kernels       

    [*] modprobe      

    [*]   Multiple options parsing             

                     ---   Options common to multiple modutils       

    [*]   Support tainted module checking with new kernels       

    [ ]   Support version 2.2.x to 2.4.x Linux kernels    //此项一定不要选!!!     

    [*]   Support version 2.6.x Linux kernels                                      

 

    Networking Utilities >

    [*] ifconfig  

    [*] ping 

 

     Archival Utilities  --->

     [*] tar

     [*]     Enable archive creation (NEW)

     [*]     Enable -j option to handle .tar.bz2 files   

Linux Module Utilities  --->

          []Support version 2.2.x to 2.4.x Linux kernels 要去掉

保存之后,执行:make ARCH=arm CROSS_COMPILE=/usr/local/arm/3.3.2/bin/arm-linux- 编译。。。。。

如果编译通过,执行make install安装,安装完成之后在busybox-1.1.3目录下生成_install目录,里面就是编译好的busybox根文件系统。

2创建根文件系统目录

   要创建的目录有:bin sbin dev etc lib home root usr var proc mnt tmp sys

可以先创建一个目录比如/home/ok2440,然后cd /home/ok2440 执行:mkdir bin sbin dev etc lib home root usr var proc mnt tmp sys命令,目录创建好之后把busybox生成的_install目录里那些都复制过来。。。。。。

。。。。。。开始创建文件。。。。。。。。

我们在etc下面要写两个文件fstab inittab 和一个文件夹init.d

(a) fstab的内容是:

proc /proc proc defaults 0 0

tmpfs /tmp tmpfs defaults 0 0

sysfs /sys sysfs defaults 0 0

tmpfs /dev tmpfs defaults 0 0

(b) fstab文件的作用

/etc/fstab存放的是系统中的文件系统信息。当正确的设置了该文件,则可以通过"mount /directoryname"命令来加载一个文 件系统,每种文件系统都对应一个独立的行,每行中的字段都有空格或tab键分开。同时fsckmountumount的等命令都利用该程序。

inittab的内容是:

#/etc/inittab

::sysinit:/etc/init.d/rcS

s3c2410_serial0::askfirst:-/bin/sh    如果不使用mdevs3c2410_serial0改成ttySAC0

::ctrlaltdel:/sbin/reboot

::shutdown:/bin/umount -a -r

(c) init.d\rcS文件的内容:

#!/bin/sh

ifconfig eth0 192.168.1.17

mount -t tmpfs mdev /dev

mkdir /dev/pts

mount -t devpts devpts /dev/pts

mount -t sysfs sysfs /sys

mount -a

echo /sbin/mdev > /proc/sys/kernel/hotplug

mdev –s

echo gugugu9999

(d)记的要将rcS文件的属性改成可执行的,这一步很重要,必须改。

改变其属性:chmod 775 etc/init.d/rcS

(e)我在配置busybox的时候用的是动态库,所以要把/usr/local/arm/3.4.1/arm-linux/lib下面的3个库文件和一个加载器拷贝到/filesystem_install/lib下:ld-2.3.2.so ld-linux.so.2 libc.so.6  libcrypt.so.1  libm.so.6

或者cp  ld*  /s3c2410/root/lib

cp  *.so*  /s3c2410/root/lib

cp  libcrypt*  /s3c2410/root/lib

(f)/filesystem_install/dev下建立设备节点:

 Console    null 

。。。。。。。。其他的不用建,因为使用了mdev,会在/dev目录下生成所有的设备。。。。。。。。。。

另外,  mdev需要改写/dev/sys两个目录。所以必须保证这两个目录是可写的(一般会用到sysfs,tmpfs。所以要重新编译内核)

linux-2.6.19 -- make menuconfig

File systems --->

    Pseudo filesystems --->

        

sysfs file system support  选上

        

Virtual memory file system support (former shm fs)  选上

        

   Tmpfs POSIX Access Control Lists  选上

 

用这样的命令建立:

sudo mknod console c 5 1

sudo mknod null c 1 3

。。。。。。。必要的文件都建立好了。。需要说明的是,想制作yaffsyaffs2的文件系统,必须要有相应的编译工具,光盘里有个mkyaffs2image,将它复制到虚拟机linux/bin目录下就可以了,或者自己制作它,下面说说制作步骤(使用光盘提供的mkyaffs2image的话可以直接跳过去):

三.修改制作yaffs映象文件的工具

  yaffs 源码中有个 utils 目录,里面是工具 mkyaffsimage mkyaffs2image的源代码,前者用来制作 yaffs1 映象文件,后者用来制作 yaffs2 映象文件。目前 mkyaffsimage 工具只能生成老格式的yaffs1 映象文件,需要修改才能支持新格式。

(1)下载的yaffs2解压出来是这样的一个目录/Development下面有两个文件夹:yaffs  yaffs2,我们需要进入yaffs2,然后再进入utils,这个下面有3个文件,我们需要加两个文件,nand-ecc.c  yaffs_packedtags1.c yaffs_packedtags1.c这个文件是从上一节目录拷贝过来的,nand-ecc.c的原码如下:

#include

typedef unsigned char       u_char;

typedef unsigned short      u_short;

typedef unsigned int        u_int;

typedef unsigned long       u_long;

typedef unsigned char       uint8_t;

typedef unsigned short      uint16_t;

typedef unsigned int        uint32_t;

static const u_char nand_ecc_precalc_table[] = {

    0x00, 0x55, 0x56, 0x03, 0x59, 0x0c, 0x0f, 0x5a, 0x5a, 0x0f, 0x0c, 0x59, 0x03, 0x56, 0x55, 0x00,

    0x65, 0x30, 0x33, 0x66, 0x3c, 0x69, 0x6a, 0x3f, 0x3f, 0x6a, 0x69, 0x3c, 0x66, 0x33, 0x30, 0x65,

    0x66, 0x33, 0x30, 0x65, 0x3f, 0x6a, 0x69, 0x3c, 0x3c, 0x69, 0x6a, 0x3f, 0x65, 0x30, 0x33, 0x66,

    0x03, 0x56, 0x55, 0x00, 0x5a, 0x0f, 0x0c, 0x59, 0x59, 0x0c, 0x0f, 0x5a, 0x00, 0x55, 0x56, 0x03,

    0x69, 0x3c, 0x3f, 0x6a, 0x30, 0x65, 0x66, 0x33, 0x33, 0x66, 0x65, 0x30, 0x6a, 0x3f, 0x3c, 0x69,

    0x0c, 0x59, 0x5a, 0x0f, 0x55, 0x00, 0x03, 0x56, 0x56, 0x03, 0x00, 0x55, 0x0f, 0x5a, 0x59, 0x0c,

    0x0f, 0x5a, 0x59, 0x0c, 0x56, 0x03, 0x00, 0x55, 0x55, 0x00, 0x03, 0x56, 0x0c, 0x59, 0x5a, 0x0f,

    0x6a, 0x3f, 0x3c, 0x69, 0x33, 0x66, 0x65, 0x30, 0x30, 0x65, 0x66, 0x33, 0x69, 0x3c, 0x3f, 0x6a,

    0x6a, 0x3f, 0x3c, 0x69, 0x33, 0x66, 0x65, 0x30, 0x30, 0x65, 0x66, 0x33, 0x69, 0x3c, 0x3f, 0x6a,

    0x0f, 0x5a, 0x59, 0x0c, 0x56, 0x03, 0x00, 0x55, 0x55, 0x00, 0x03, 0x56, 0x0c, 0x59, 0x5a, 0x0f

    0x0c, 0x59, 0x5a, 0x0f, 0x55, 0x00, 0x03, 0x56, 0x56, 0x03, 0x00, 0x55, 0x0f, 0x5a, 0x59, 0x0c,

    0x69, 0x3c, 0x3f, 0x6a, 0x30, 0x65, 0x66, 0x33, 0x33, 0x66, 0x65, 0x30, 0x6a, 0x3f, 0x3c, 0x69,

    0x03, 0x56, 0x55, 0x00, 0x5a, 0x0f, 0x0c, 0x59, 0x59, 0x0c, 0x0f, 0x5a, 0x00, 0x55, 0x56, 0x03,

    0x66, 0x33, 0x30, 0x65, 0x3f, 0x6a, 0x69, 0x3c, 0x3c, 0x69, 0x6a, 0x3f, 0x65, 0x30, 0x33, 0x66,

    0x65, 0x30, 0x33, 0x66, 0x3c, 0x69, 0x6a, 0x3f, 0x3f, 0x6a, 0x69, 0x3c, 0x66, 0x33, 0x30, 0x65,

    0x00, 0x55, 0x56, 0x03, 0x59, 0x0c, 0x0f, 0x5a, 0x5a, 0x0f, 0x0c, 0x59, 0x03, 0x56, 0x55, 0x00

};

int nand_calculate_ecc(const u_char *dat, u_char *ecc_code)

{

    uint8_t idx, reg1, reg2, reg3, tmp1, tmp2;

    int i;

    reg1 = reg2 = reg3 = 0;

    for(i = 0; i < 256; i++) {

        idx = nand_ecc_precalc_table[*dat++];

        reg1 ^= (idx & 0x3f);

        if (idx & 0x40) {

            reg3 ^= (uint8_t) i;

            reg2 ^= ~((uint8_t) i);

        }

    }

    tmp1  = (reg3 & 0x80) >> 0;

    tmp1 |= (reg2 & 0x80) >> 1;

    tmp1 |= (reg3 & 0x40) >> 1;

    tmp1 |= (reg2 & 0x40) >> 2;

    tmp1 |= (reg3 & 0x20) >> 2;

    tmp1 |= (reg2 & 0x20) >> 3;

    tmp1 |= (reg3 & 0x10) >> 3;

    tmp1 |= (reg2 & 0x10) >> 4;

    tmp2  = (reg3 & 0x08) << 4;

    tmp2 |= (reg2 & 0x08) << 3;

    tmp2 |= (reg3 & 0x04) << 3;

    tmp2 |= (reg2 & 0x04) << 2;

    tmp2 |= (reg3 & 0x02) << 2;

    tmp2 |= (reg2 & 0x02) << 1;

    tmp2 |= (reg3 & 0x01) << 1;

    tmp2 |= (reg2 & 0x01) << 0;

#ifdef CONFIG_MTD_NAND_ECC_SMC

     ecc_code[0] = ~tmp2;

    ecc_code[1] = ~tmp1;

#else

    ecc_code[0] = ~tmp1;

    ecc_code[1] = ~tmp2;

#endif

 

    ecc_code[2] = ((~reg1) << 2) | 0x03;

    return 0;

}

EXPORT_SYMBOL(nand_calculate_ecc);

static inline int countbits(uint32_t byte)

{

    int res = 0;

    for (;byte; byte >>= 1)

        res += byte & 0x01;

    return res;

}

int nand_correct_data(u_char *dat, u_char *read_ecc, u_char *calc_ecc)

{

    uint8_t s0, s1, s2;

#ifdef CONFIG_MTD_NAND_ECC_SMC

    s0 = calc_ecc[0] ^ read_ecc[0];

    s1 = calc_ecc[1] ^ read_ecc[1];

    s2 = calc_ecc[2] ^ read_ecc[2];

#else

    s1 = calc_ecc[0] ^ read_ecc[0];

    s0 = calc_ecc[1] ^ read_ecc[1];

    s2 = calc_ecc[2] ^ read_ecc[2];

#endif

    if ((s0 | s1 | s2) == 0)

        return 0;

    if( ((s0 ^ (s0 >> 1)) & 0x55) == 0x55 &&

        ((s1 ^ (s1 >> 1)) & 0x55) == 0x55 &&

        ((s2 ^ (s2 >> 1)) & 0x54) == 0x54) {

        uint32_t byteoffs, bitnum;

        byteoffs = (s1 << 0) & 0x80;

        byteoffs |= (s1 << 1) & 0x40;

        byteoffs |= (s1 << 2) & 0x20;

        byteoffs |= (s1 << 3) & 0x10;

        byteoffs |= (s0 >> 4) & 0x08;

        byteoffs |= (s0 >> 3) & 0x04;

        byteoffs |= (s0 >> 2) & 0x02;

        byteoffs |= (s0 >> 1) & 0x01;

        bitnum = (s2 >> 5) & 0x04;

        bitnum |= (s2 >> 4) & 0x02;

        bitnum |= (s2 >> 3) & 0x01;

        dat[byteoffs] ^= (1 << bitnum);

        return 1;

    }

 

    if(countbits(s0 | ((uint32_t)s1 << 8) | ((uint32_t)s2 <<16)) == 1)

        return 1;

    return -1;

}

mkyaffsimage.c里边修改原码为:

加这个头文件:#include "yaffs_packedtags1.h"

static int write_chunk(__u8 *data, __u32 objId, __u32 chunkId, __u32 nBytes)

{

       #ifdef CONFIG_YAFFS_9BYTE_TAGS

       yaffs_Tags t;

       yaffs_Spare s;

 

       error = write(outFile,data,512);

       if(error < 0) return error;

 

       memset(&t,0xff,sizeof (yaffs_Tags));

       memset(&s,0xff,sizeof (yaffs_Spare));

      

       t.chunkId = chunkId;

       t.serialNumber = 0;

       t.byteCount = nBytes;

       t.objectId = objId;

 

    if (convert_endian)

    {

        little_to_big_endian(&t);

    }

      

       yaffs_CalcTagsECC(&t);

       yaffs_LoadTagsIntoSpare(&s,&t);

       yaffs_CalcECC(data,&s);

       nPages++;

       return write(outFile,&s,sizeof(yaffs_Spare));

    #else

        yaffs_PackedTags1 pt1;

        yaffs_ExtendedTags  etags;

        __u8 ecc_code[6];

        __u8 oobbuf[16];

        error = write(outFile,data,512);

        if(error < 0) return error;

        etags.chunkId       = chunkId;

        etags.serialNumber  = 0;

        etags.byteCount     = nBytes;

        etags.objectId      = objId;

        etags.chunkDeleted  = 0;

        yaffs_PackTags1(&pt1, &etags);

        yaffs_CalcTagsECC((yaffs_Tags *)&pt1);

        memset(oobbuf, 0xff, 16);

        memcpy(oobbuf+8, &pt1, 8);

        nand_calculate_ecc(data, &ecc_code[0]);

        nand_calculate_ecc(data+256, &ecc_code[3]);

        oobbuf[0] = ecc_code[0];

        oobbuf[1] = ecc_code[1];

        oobbuf[2] = ecc_code[2];

        oobbuf[3] = ecc_code[3];

        oobbuf[6] = ecc_code[4];

        oobbuf[7] = ecc_code[5];

        nPages++;

        return write(outFile, oobbuf, 16);

#endif    

}

修改Makefile文件:

MKYAFFSSOURCES = mkyaffsimage.c      yaffs_packedtags1.c nand-ecc.c

yaffs_packedtags1.cnand-ecc.c是我们加上去的

这样我们就可以用make命令来生成工具文件了:mkyaffsimage mkyaffs2image

。。。。。。。。。。。以上是自己制作mkyaffsimage工具的步骤。。。。。。。。。。很繁琐,还是用光盘里的mkyaffs2image省事。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

接下来就是制作文件系统镜像了。

转到咱们建立的那个/ok2440目录的上一级,也就是/home目录,然后执行:mkyaffs2image ok2440 ok2440.yaffs 就可以生成文件系统镜像了,将ok2440.yaffs烧进板子,看看能不能正常挂载吧。。。。。。。。。。(当看到gugugu9999   Please press Enter to activate this console.就表明你成功了!!!)

 

原创文章 转载请注明转自    gugugu9999.cublog.cn

阅读(1178) | 评论(1) | 转发(1) |
给主人留下些什么吧!~~

walterpeng2011-11-10 14:10:18

这么好的文章,不多说,一个字:顶!