原创 yaffs2 direct在VC2008下移植

2010-12-12 15:27 2887 2 2 分类: MCU/ 嵌入式

源码下载:http://www.aleph1.co.uk/cgi-bin/viewcvs.cgi/yaffs2/


1. 在VS2008建立工程文件,加入yaffs2核心代码


Core:


 yaffs_checkptrw.c


yaffs_ecc.c


yaffs_guts.c


yaffs_nand.c


yaffs_packedtags1.c


yaffs_packedtags2.c


yaffs_qsort.c


yaffs_tagscompat.c


yaffs_tagsvalidity.c


Direct:


    yaffs_fileem2k.c


yaffs_norif1.c


yaffs_ramdisk.c


yaffscfg2k.c


yaffsfs.c


ynorsim.c


其中dtest.c为main函数入口文件。



 32ee55bb-4355-4616-aef8-ec6f89b01461.JPG


e5957e06-808c-417c-8ca8-7d3563aa29b1.JPG 


 


 


 


 


 


 



 


2.在工程文件Preprocessor Definitions 预编译定义中定义好


CONFIG_YAFFS_DIRECT


CONFIG_YAFFS_SHORT_NAMES_IN_RAM


CONFIG_YAFFS_YAFFS2


CONFIG_YAFFS_PROVIDE_DEFS


CONFIG_YAFFSFS_PROVIDE_VALUES


NO_Y_INLINE


3. 然后第一次编译,无法编译通过


在文件devextras.h中添加如下定义:


 


#ifndef _DEV_T_DEFINED


typedef unsigned int _dev_t;            /* device code */


#if     !__STDC__


/* Non-ANSI name for compatibility */


typedef unsigned int dev_t;


#endif


 


#define _DEV_T_DEFINED


#endif


 


#define u_char unsigned char


#define loff_t int


typedef long off_t;


typedef unsigned long mode_t;


#define __inline__


 


#define __S_IFMT 0170000 /* These bits determine file type.  */


/* File types.  */


#define __S_IFDIR 0040000 /* Directory.  */


#define __S_IFCHR 0020000 /* Character device.  */


#define __S_IFBLK 0060000 /* Block device.  */


#define __S_IFREG 0100000 /* Regular file.  */


#define __S_IFIFO 0010000 /* FIFO.  */


#define __S_IFLNK 0120000 /* Symbolic link.  */


#define __S_IFSOCK 0140000 /* Socket.  */


 


/* Protection bits.  */


#define __S_ISUID 04000 /* Set user ID on execution.  */


#define __S_ISGID 02000 /* Set group ID on execution.  */


#define __S_ISVTX 01000 /* Save swapped text after use (sticky).  */


#define __S_IREAD 0400 /* Read by owner.  */


#define __S_IWRITE 0200 /* Write by owner.  */


#define __S_IEXEC 0100 /* Execute by owner.  */


#define __S_ISTYPE(mode, mask) (((mode) & __S_IFMT) == (mask))


#define S_ISDIR(mode)  __S_ISTYPE((mode), __S_IFDIR)


#define S_ISCHR(mode)  __S_ISTYPE((mode), __S_IFCHR)


#define S_ISBLK(mode)  __S_ISTYPE((mode), __S_IFBLK)


#define S_ISREG(mode)  __S_ISTYPE((mode), __S_IFREG)


#define S_ISSOCK(mode) __S_ISTYPE((mode), __S_IFSOCK)


#define S_ISFIFO(mode) __S_ISTYPE((mode), __S_IFSOCK)


#define S_IRUSR __S_IREAD // Read by owner.  


#define S_IWUSR __S_IWRITE // Write by owner. 


#define S_IXUSR __S_IEXEC // Execute by owner. 


# define S_IREAD S_IRUSR


# define S_IWRITE S_IWUSR


# define S_IEXEC S_IXUSR


# define S_IFDIR __S_IFDIR


 


于此同时在VC2008 目录中的


D:\Program Files\Microsoft Visual Studio 9.0\VC\include\sys\stat.h文件


将下列代码注释掉


/*


#define _S_IFMT         0xF000          // file type mask 


#define _S_IFDIR        0x4000          // directory 


#define _S_IFCHR        0x2000          // character special 


#define _S_IFIFO        0x1000          // pipe 


#define _S_IFREG        0x8000          // regular 


#define _S_IREAD        0x0100          // read permission, owner 


#define _S_IWRITE       0x0080          // write permission, owner 


#define _S_IEXEC        0x0040          //execute/search permission, owner 


 */


/* Non-ANSI names for compatibility */


/*


#define S_IFMT   _S_IFMT


#define S_IFDIR  _S_IFDIR


#define S_IFCHR  _S_IFCHR


#define S_IFREG  _S_IFREG


#define S_IREAD  _S_IREAD


#define S_IWRITE _S_IWRITE


#define S_IEXEC  _S_IEXEC


*/


3.第二次编译有如下错误需要解决


1>.\yaffs2\direct\yaffs_fileem2k.c(113) : error C2143: syntax error : missing ';' before 'type'


 


该错误为:


static int GetBlockFileHandle(int n)


{


    int h;


    int requiredSize;


   


    char name[40];


    NToName(name,n);


    int fSize;


    int i;


将其改为:


static int GetBlockFileHandle(int n)


{


    int h;


    int requiredSize;


   


    char name[40];


    int fSize;


    int i;


NToName(name,n);


备注:VC2008 C代码编译过程中,变量的使用需在大括号之后声明好


继续编译工程文件同样出现类似的问题依次改之。


1>yaffs_fileem2k.c


1>.\yaffs2\direct\yaffs_fileem2k.c(265) : error C2275: '__u8' : illegal use of this type as an expression


该错误为:


            else


            {


                yaffs_PackedTags2 pt;


                yaffs_PackTags2(&pt,tags, !dev->param.noTagsECC);


                __u8 * ptab = (__u8 *)&pt;


将其改为:


            else


            {


                yaffs_PackedTags2 pt;


                __u8 * ptab;


                yaffs_PackTags2(&pt,tags, !dev->param.noTagsECC);


                ptab = (__u8 *)&pt;


1>yaffs_fileem2k.c


1>.\yaffs2\direct\yaffs_fileem2k.c(417) : error C2275: 'yaffs_PackedTags2TagsPart' : illegal use of this type as an expression


该错误为:


   


    if(dev->param.inbandTags){


        /* Got to suck the tags out of the data area */


        if(!data) {


            localData=1;


            data = yaffs_GetTempBuffer(dev,__LINE__);


        }


 


       


        yaffs_PackedTags2TagsPart * pt2tp;


        pt2tp=(yaffs_PackedTags2TagsPart*)&data[dev->nDataBytesPerChunk];


 


 


将其改为:


    if(dev->param.inbandTags){


        yaffs_PackedTags2TagsPart * pt2tp;


        /* Got to suck the tags out of the data area */


        if(!data) {


            localData=1;


            data = yaffs_GetTempBuffer(dev,__LINE__);


        }


 


       


        pt2tp = (yaffs_PackedTags2TagsPart *)&data[dev->nDataBytesPerChunk];


4.错误改好后dtest.c文件内容如下:


/*


 * YAFFS: Yet another FFS. A NAND-flash specific file system.


 *


 * Copyright (C) 2002 Aleph One Ltd.


 *   for Toby Churchill Ltd and Brightstar Engineering


 *


 * Created by Charles Manning <charles@aleph1.co.uk>


 *


 * This program is free software; you can redistribute it and/or modify


 * it under the terms of the GNU General Public License version 2 as


 * published by the Free Software Foundation.


 *


 */


 


#include <stdio.h>


#include <string.h>


#include <unistd.h>


#include <fcntl.h>


#include "yaffsfs.h"


 


int random_seed;


int simulate_power_failure;


 


int main(int argc, char *argv[])


{


    int fd;


    char readbuf[10];


    int writebyte;


    int readbyte;


    int i;


    yaffs_StartUp();                                              //初始化 


    for (i=0 ;i<10 ;i++)


    {


       readbuf=0;


    }


    yaffs_mount("/yaffs2");                                       //挂载


    fd = yaffs_open("/yaffs2/MyFile", O_CREAT,S_IREAD | S_IWRITE);//建立文件


    yaffs_close(fd);


 


    fd = yaffs_open("/yaffs2/MyFile", O_RDWR,0);                  //写文件


    writebyte = yaffs_write(fd,"hoguowi",7);


    yaffs_close(fd);


 


    fd = yaffs_open("/yaffs2/MyFile", O_RDWR,0);                  //读文件


    readbyte = yaffs_read(fd, readbuf, 7) ;


    yaffs_close(fd);


 


    return 0;


   


}


5.此时工程顺利编译通过。


   Debug运行程序时候,可以观察到我们写入的文件与读出的数据一样。在文件/yaffs2/MyFile写入了“hoguowi”字符,读出的数据放在readbuf里面,内容为”hoguowi”,验证了程序按设想的正常运行。


 


备注:编译虽然通过了却存在两处警告需要我们注意,警告如下


1>yaffscfg2k.c


1>D:\Program Files\Microsoft Visual Studio 9.0\VC\include\errno.h(73) : warning C4005: 'ENAMETOOLONG' : macro redefinition


1>        g:\nandflash\yaffs2\direct\yaffsfs.h(118) : see previous definition of 'ENAMETOOLONG'


1>D:\Program Files\Microsoft Visual Studio 9.0\VC\include\errno.h(76) : warning C4005: 'ENOTEMPTY' : macro redefinition


1>                       g:\nandflash\yaffs2\direct\yaffsfs.h(114) : see previous definition of 'ENOTEMPTY'


下面两个变量


ENAMETOOLONG


ENOTEMPTY


分别在yaffsfs.h和vc2008的errno.h中被定义了两次


在errno.h中定义为


#define ENAMETOOLONG    38  


#define ENOTEMPTY       41 


在yaffsfs.h定义为


#define ENAMETOOLONG    36


#define ENOTEMPTY       39


还有O_CREAT在VC中被定义的数值为256,在ubuntu中被定义为64


 


 

文章评论0条评论)

登录后参与讨论
我要评论
0
2
关闭 站长推荐上一条 /2 下一条