热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

mkyaffs2image工具解析

终于可以成功制作页大小为2K64Bytes的nandflash的image文件了。令人兴奋啊:)这两天一直苦于自己制作的yaffs2image文件系统无法被linu

终于可以成功制作页大小为2K + 64 Bytes 的nand flash的image 文件了。令人兴奋啊 :)

这两天一直苦于自己制作的yaffs2 image文件系统无法被linux-2.6.29.1内核识别,而使用FriendlyARM的mkyaffs2imag-128M工具就没有这个问题。一开始便判断是mkyaffs2image工具有问题,没有生成正确格式的yaffs2 image文件,从而导致内核无法识别,并抛出以下错误信息:

----------------------------------------------------------------------------------------------------------------

……

block 155 is bad
yaffs_read_super: isCheckpointed 0
VFS: Mounted root (yaffs filesystem) readonly on device 31:2.
Freeing init memory: 164K
Warning: unable to open an initial console.
Failed to execute /linuxrc.  Attempting defaults...
Kernel panic - not syncing: No init found.  Try passing init= option to kernel.

----------------------------------------------------------------------------------------------------------------

网上查了很多相关的资料,对2K data + 64bytes spare 的nand flash上yaffs2文件的存储格式并没有较为清晰的说明。不知道数据的存储模式,就无法正确生成image文件。苦恼了好几天,甚至有些想放弃了。。。

然而今天得到了一个意外的收获,http://www.bluewatersys.com/quickstart/9260sambootassistant.php上大概阐述了2K yaffs2 nand flash中数据的组织形式(虽然后来发现该文章中关于结构yaffs2_PackedTags的大小表述有错,应该是28字节,而非25字节),经过修改后,并且纠正相关bug,成功生成正确的yaffs2 image 文件,download进s3c2440开发板后,顺利启动系统。

有一点很重要,就是mkyaffs2image生成的image 文件的OOB区数据格式要与linux kernel对nand flash进行读取时的数据格式保持一致,所以mkyaffs2image.c中来自linux kernel的数据结构,即包含了mtd-abi.h头文件。

PS:下面本人会附上mkyaffs2image.c的全部内容,供朋友们参考,希望给meet with同样error的兄弟们一些帮助:)

PART2 About 64bytes OOB

下图为64bytes OOB区中的数据组织结构:

图1 64bytes OOB area

PS:

1) OOB最前端的2bytes为0xFF 0xFF,用于标识为非坏块。

2) 每256bytes的数据需要3bytes有ECC校验,因此2K的数据需要24bytes的ECC。

以下为经过修改过后的mkyaffs2image.c的源码:

 

 /*
 * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
 *
 * Copyright (C) 2002-2007 Aleph One Ltd.
 *   for Toby Churchill Ltd and Brightstar Engineering
 *
 * Created by Charles Manning
 * Nick Bane modifications flagged NCB
 * Endian handling patches by James Ng.
 * mkyaffs2image hacks by NCB
 *
 * 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.
 */

/*
 * makeyaffs2image.c 
 *
 * Makes a YAFFS2 file system image that can be used to load up a file system.
 * Uses default Linux MTD layout - change if you need something different.
 */
 
#include
#include
#include
#include
#include
#include
#include
#include
#define __user
#include
#include "yaffs_ecc.h"
#include "yaffs_guts.h"

#include "yaffs_packedtags2.h"

#include "mtd-abi.h" //ADDED BY LIUHAO 2009-11-11

unsigned yaffs_traceMask=0;

#define MAX_OBJECTS 10000

#define chunkSize 2048
#define spareSize 64

//MODIFIED BY LIUHAO 2009-11-11 START
//#define PT2_BYTES 25 //Original
#define PT2_BYTES 28
//MODIFIED BY LIUHAO 2009-11-11 END

const char * mkyaffsimage_c_version = "$Id: mkyaffs2image.c,v 1.4 2007-02-14 01:09:06 wookey Exp $";

 
static int layout_no;


static struct nand_oobinfo oob_layout[] = {
    /* KSI:
     * Dummy "raw" layout - no ECC, all the bytes are free. Does NOT
     * really work, only used for compatibility with CVS YAFFS2 that
     * never ever worked with any stock MTD.
     */
    {
        .useecc = MTD_NANDECC_AUTOPLACE,
        .eccbytes = 0,
        .eccpos = {},
        .oobfree = { {0, 64} }
    },
    /* KSI:
     * Regular MTD AUTOPLACED ECC for large page NAND devices, the
     * only one existing in stock MTD so far. It corresponds to layout# 1
     * in command line arguments. Any other layouts could be added to
     * the list when they made their way in kernel's MTD. The structure
     * is simply copied from kernel's drivers/mtd/nand/nand_base.c as-is.
     */
    {
        .useecc = MTD_NANDECC_AUTOPLACE,
        .eccbytes = 24,
        .eccpos = {
            40, 41, 42, 43, 44, 45, 46, 47,
            48, 49, 50, 51, 52, 53, 54, 55,
            56, 57, 58, 59, 60, 61, 62, 63},
        .oobfree = { {2, 38} }
    },
    /* End-of-list marker */
    {
        .useecc = -1,
    }
};

typedef struct {
 dev_t dev;
 ino_t ino;
 int   obj;
} objItem;


static objItem obj_list[MAX_OBJECTS];
static int n_obj = 0;
static int obj_id = YAFFS_NOBJECT_BUCKETS + 1;

static int nObjects = 0, nDirectories = 0, nPages = 0;

static int outFile;

static int error;

static int convert_endian = 0;

static int obj_compare(const void *a, const void * b)
{
    objItem *oa, *ob;

    oa = (objItem *)a;
    ob = (objItem *)b;

    if(oa->dev dev) return -1;
    if(oa->dev > ob->dev) return 1;
    if(oa->ino ino) return -1;
    if(oa->ino > ob->ino) return 1;

    return 0;
}


static void add_obj_to_list(dev_t dev, ino_t ino, int obj)
{
 if(n_obj  {
  obj_list[n_obj].dev = dev;
  obj_list[n_obj].ino = ino;
  obj_list[n_obj].obj = obj;
  n_obj++;
  qsort(obj_list,n_obj,sizeof(objItem),obj_compare);
  
 }
 else
 {
  // oops! not enough space in the object array
  fprintf(stderr,"Not enough space in object array/n");
  exit(2);
 }
}


static int find_obj_in_list(dev_t dev, ino_t ino)
{
 objItem *i = NULL;
 objItem test;

 test.dev = dev;
 test.ino = ino;
 
 if(n_obj > 0)
 {
  i = bsearch(&test,obj_list,n_obj,sizeof(objItem),obj_compare);
 }

 if(i)
 {
  return i->obj;
 }
 return -1;
}

static void yaffs_PutDataECC(const __u8 * data, unsigned char *oob_buf)
{
    unsigned char ecc_code[3];
    int eccsteps = chunkSize / 256;
    int eccidx = 0, datidx = 0, i;
    struct nand_oobinfo *oobsel;
    __u32 *oob_config;

    oobsel = &oob_layout[layout_no];
    oob_config = oobsel->eccpos; //LIUHAO: 24bytes的ECC在spare area中的位置

    for (; eccsteps; eccsteps--) {
        yaffs_ECCCalculate (&data[datidx], ecc_code);
  for (i &#61; 0; i <3; i&#43;&#43;, eccidx&#43;&#43;)
      oob_buf[oob_config[eccidx]] &#61; ecc_code[i];
  datidx &#43;&#61; 256;
    }
}


/* KSI:
 * No big endian for now. This is left for a later time. The existing code
 * is FUBAR.
 */
#if 0
/* This little function converts a little endian tag to a big endian tag.
 * NOTE: The tag is not usable after this other than calculating the CRC
 * with.
 */
static void little_to_big_endian(yaffs_Tags *tagsPtr)
{
#if 0 // FIXME NCB
    yaffs_TagsUnion * tags &#61; (yaffs_TagsUnion* )tagsPtr; // Work in bytes.
    yaffs_TagsUnion   temp;

    memset(&temp, 0, sizeof(temp));
    // Ick, I hate magic numbers.
    temp.asBytes[0] &#61; ((tags->asBytes[2] & 0x0F) <<4) | ((tags->asBytes[1] & 0xF0) >> 4);
    temp.asBytes[1] &#61; ((tags->asBytes[1] & 0x0F) <<4) | ((tags->asBytes[0] & 0xF0) >> 4);
    temp.asBytes[2] &#61; ((tags->asBytes[0] & 0x0F) <<4) | ((tags->asBytes[2] & 0x30) >> 2) | ((tags->asBytes[3] & 0xC0) >> 6);
    temp.asBytes[3] &#61; ((tags->asBytes[3] & 0x3F) <<2) | ((tags->asBytes[2] & 0xC0) >> 6);
    temp.asBytes[4] &#61; ((tags->asBytes[6] & 0x03) <<6) | ((tags->asBytes[5] & 0xFC) >> 2);
    temp.asBytes[5] &#61; ((tags->asBytes[5] & 0x03) <<6) | ((tags->asBytes[4] & 0xFC) >> 2);
    temp.asBytes[6] &#61; ((tags->asBytes[4] & 0x03) <<6) | (tags->asBytes[7] & 0x3F);
    temp.asBytes[7] &#61; (tags->asBytes[6] & 0xFC) | ((tags->asBytes[7] & 0xC0) >> 6);

    // Now copy it back.
    tags->asBytes[0] &#61; temp.asBytes[0];
    tags->asBytes[1] &#61; temp.asBytes[1];
    tags->asBytes[2] &#61; temp.asBytes[2];
    tags->asBytes[3] &#61; temp.asBytes[3];
    tags->asBytes[4] &#61; temp.asBytes[4];
    tags->asBytes[5] &#61; temp.asBytes[5];
    tags->asBytes[6] &#61; temp.asBytes[6];
    tags->asBytes[7] &#61; temp.asBytes[7];
#endif
}
#endif

static void nandmtd2_pt2buf(unsigned char *buf, yaffs_PackedTags2 *pt)
{
 int  i, j &#61; 0, k, n;
 //MODIFIED BY LIUHAO 2009-11-11
 //unsigned char pt2_byte_buf[PT2_BYTES];  //Original
 unsigned char pt2_byte_buf[PT2_BYTES] &#61; {0};
 
 *((unsigned int *) &pt2_byte_buf[0]) &#61; pt->t.sequenceNumber;
 *((unsigned int *) &pt2_byte_buf[4]) &#61; pt->t.objectId;
 *((unsigned int *) &pt2_byte_buf[8]) &#61; pt->t.chunkId;
 *((unsigned int *) &pt2_byte_buf[12]) &#61; pt->t.byteCount;
 pt2_byte_buf[16] &#61; pt->ecc.colParity;
 //MODIFIED BY LIUHAO 2009-11-11 START
#if 0
 //Original
 pt2_byte_buf[17] &#61; pt->ecc.lineParity & 0xff;
 pt2_byte_buf[18] &#61; (pt->ecc.lineParity >> 8) & 0xff;
 pt2_byte_buf[19] &#61; (pt->ecc.lineParity >> 16) & 0xff;
 pt2_byte_buf[20] &#61; (pt->ecc.lineParity >> 24) & 0xff;
 pt2_byte_buf[21] &#61; pt->ecc.lineParityPrime & 0xff;
 pt2_byte_buf[22] &#61; (pt->ecc.lineParityPrime >> 8) & 0xff;
 pt2_byte_buf[23] &#61; (pt->ecc.lineParityPrime >> 16) & 0xff;
 pt2_byte_buf[24] &#61; (pt->ecc.lineParityPrime >> 24) & 0xff;
#else
 pt2_byte_buf[20] &#61; pt->ecc.lineParity & 0xff;
 pt2_byte_buf[21] &#61; (pt->ecc.lineParity >> 8) & 0xff;
 pt2_byte_buf[22] &#61; (pt->ecc.lineParity >> 16) & 0xff;
 pt2_byte_buf[23] &#61; (pt->ecc.lineParity >> 24) & 0xff;
 pt2_byte_buf[24] &#61; pt->ecc.lineParityPrime & 0xff;
 pt2_byte_buf[25] &#61; (pt->ecc.lineParityPrime >> 8) & 0xff;
 pt2_byte_buf[26] &#61; (pt->ecc.lineParityPrime >> 16) & 0xff;
 pt2_byte_buf[27] &#61; (pt->ecc.lineParityPrime >> 24) & 0xff;
#endif

 k &#61; oob_layout[layout_no].oobfree[j][0];
 n &#61; oob_layout[layout_no].oobfree[j][1];
  
 if (n &#61;&#61; 0) {
  fprintf(stderr, "No OOB space for tags");
  exit(-1);
 }
                                
 for (i &#61; 0; i   if (n &#61;&#61; 0) {
   j&#43;&#43;;
   k &#61; oob_layout[layout_no].oobfree[j][0];
   n &#61; oob_layout[layout_no].oobfree[j][1];
   if (n &#61;&#61; 0) {
    fprintf(stderr, "No OOB space for tags");
    exit(-1);
   }
  }
  buf[k&#43;&#43;] &#61; pt2_byte_buf[i];
  n--;
 }
}

static int write_chunk(__u8 *data, __u32 objId, __u32 chunkId, __u32 nBytes)
{
 yaffs_ExtendedTags t;
 yaffs_PackedTags2 pt;

 yaffs_PackedTags2TagsPart ptt; //ADDED BY LIUHAO 2009-11-11

 //ADDED BY LIUHAO 2009-11-11 
 //unsigned char spare_buf[spareSize];  //Original
 unsigned char spare_buf[spareSize] &#61; {0};


 error &#61; write(outFile,data,chunkSize);
 if(error <0) return error;

 yaffs_InitialiseTags(&t);
 
 t.chunkId &#61; chunkId;
// t.serialNumber &#61; 0;
 t.serialNumber &#61; 1; // **CHECK**
 t.byteCount &#61; nBytes;
 t.objectId &#61; objId;
 
 t.sequenceNumber &#61; YAFFS_LOWEST_SEQUENCE_NUMBER;

// added NCB **CHECK**
 t.chunkUsed &#61; 1;

 //ADDED BY LIUHAO 2009-11-11
 //t.extraHeaderInfoAvailable &#61; 1;

/* KSI: Broken anyway -- e.g. &t is pointer to a wrong type... */
#if 0
 if (convert_endian)
 {
         little_to_big_endian(&t);
 }
#endif

//MODIFIED BY LIUHAO 2009-11-11 START
#if 0
 yaffs_PackTags2(&pt,&t); //Original
#else
 memset(&pt, 0, sizeof(yaffs_PackedTags2));
 yaffs_PackTags2TagsPart(&pt.t,&t);
 yaffs_ECCCalculateOther(
  (unsigned char *)&pt.t, 
  sizeof(yaffs_PackedTags2TagsPart),
  &pt.ecc);
#endif
//MODIFIED BY LIUHAO 2009-11-11 END

    memset(spare_buf, 0xff, sizeof(spare_buf));
        
    if (layout_no &#61;&#61; 0) {
  memcpy(spare_buf, &pt, sizeof(yaffs_PackedTags2));
 } else {
  nandmtd2_pt2buf(spare_buf, &pt);
 } 

    yaffs_PutDataECC(data, &spare_buf[0]);

 nPages&#43;&#43;;

 return write(outFile,spare_buf,spareSize);
}

#define SWAP32(x)   ((((x) & 0x000000FF) <<24) | /
                     (((x) & 0x0000FF00) <<8 ) | /
                     (((x) & 0x00FF0000) >> 8 ) | /
                     (((x) & 0xFF000000) >> 24))

#define SWAP16(x)   ((((x) & 0x00FF) <<8) | /
                     (((x) & 0xFF00) >> 8))
        
/* KSI: Removed for now. TBD later when the proper util (from scratch) is written */
#if 0
// This one is easier, since the types are more standard. No funky shifts here.
static void object_header_little_to_big_endian(yaffs_ObjectHeader* oh)
{
    oh->type &#61; SWAP32(oh->type); // GCC makes enums 32 bits.
    oh->parentObjectId &#61; SWAP32(oh->parentObjectId); // int
    oh->sum__NoLongerUsed &#61; SWAP16(oh->sum__NoLongerUsed); // __u16 - Not used, but done for completeness.
    // name &#61; skip. Char array. Not swapped.
    oh->yst_mode &#61; SWAP32(oh->yst_mode);
#ifdef CONFIG_YAFFS_WINCE // WinCE doesn&#39;t implement this, but we need to just in case. 
    // In fact, WinCE would be *THE* place where this would be an issue!
    oh->notForWinCE[0] &#61; SWAP32(oh->notForWinCE[0]);
    oh->notForWinCE[1] &#61; SWAP32(oh->notForWinCE[1]);
    oh->notForWinCE[2] &#61; SWAP32(oh->notForWinCE[2]);
    oh->notForWinCE[3] &#61; SWAP32(oh->notForWinCE[3]);
    oh->notForWinCE[4] &#61; SWAP32(oh->notForWinCE[4]);
#else
    // Regular POSIX.
    oh->yst_uid &#61; SWAP32(oh->yst_uid);
    oh->yst_gid &#61; SWAP32(oh->yst_gid);
    oh->yst_atime &#61; SWAP32(oh->yst_atime);
    oh->yst_mtime &#61; SWAP32(oh->yst_mtime);
    oh->yst_ctime &#61; SWAP32(oh->yst_ctime);
#endif

    oh->fileSize &#61; SWAP32(oh->fileSize); // Aiee. An int... signed, at that!
    oh->equivalentObjectId &#61; SWAP32(oh->equivalentObjectId);
    // alias  - char array.
    oh->yst_rdev &#61; SWAP32(oh->yst_rdev);

#ifdef CONFIG_YAFFS_WINCE
    oh->win_ctime[0] &#61; SWAP32(oh->win_ctime[0]);
    oh->win_ctime[1] &#61; SWAP32(oh->win_ctime[1]);
    oh->win_atime[0] &#61; SWAP32(oh->win_atime[0]);
    oh->win_atime[1] &#61; SWAP32(oh->win_atime[1]);
    oh->win_mtime[0] &#61; SWAP32(oh->win_mtime[0]);
    oh->win_mtime[1] &#61; SWAP32(oh->win_mtime[1]);
    oh->roomToGrow[0] &#61; SWAP32(oh->roomToGrow[0]);
    oh->roomToGrow[1] &#61; SWAP32(oh->roomToGrow[1]);
    oh->roomToGrow[2] &#61; SWAP32(oh->roomToGrow[2]);
    oh->roomToGrow[3] &#61; SWAP32(oh->roomToGrow[3]);
    oh->roomToGrow[4] &#61; SWAP32(oh->roomToGrow[4]);
    oh->roomToGrow[5] &#61; SWAP32(oh->roomToGrow[5]);
#else
    oh->roomToGrow[0] &#61; SWAP32(oh->roomToGrow[0]);
    oh->roomToGrow[1] &#61; SWAP32(oh->roomToGrow[1]);
    oh->roomToGrow[2] &#61; SWAP32(oh->roomToGrow[2]);
    oh->roomToGrow[3] &#61; SWAP32(oh->roomToGrow[3]);
    oh->roomToGrow[4] &#61; SWAP32(oh->roomToGrow[4]);
    oh->roomToGrow[5] &#61; SWAP32(oh->roomToGrow[5]);
    oh->roomToGrow[6] &#61; SWAP32(oh->roomToGrow[6]);
    oh->roomToGrow[7] &#61; SWAP32(oh->roomToGrow[7]);
    oh->roomToGrow[8] &#61; SWAP32(oh->roomToGrow[8]);
    oh->roomToGrow[9] &#61; SWAP32(oh->roomToGrow[9]);
    oh->roomToGrow[10] &#61; SWAP32(oh->roomToGrow[10]);
    oh->roomToGrow[11] &#61; SWAP32(oh->roomToGrow[11]);
#endif
}
#endif

static int write_object_header(int objId, yaffs_ObjectType t, struct stat *s, int parent, const char *name, int equivalentObj, const char * alias)
{
 __u8 bytes[chunkSize];
 
 
 yaffs_ObjectHeader *oh &#61; (yaffs_ObjectHeader *)bytes;
 
 memset(bytes,0xff,sizeof(bytes));
 
 oh->type &#61; t;

 oh->parentObjectId &#61; parent;
 
 strncpy(oh->name,name,YAFFS_MAX_NAME_LENGTH);
 
 
 if(t !&#61; YAFFS_OBJECT_TYPE_HARDLINK)
 {
  oh->yst_mode &#61; s->st_mode;
  oh->yst_uid &#61; s->st_uid;
// NCB 12/9/02  oh->yst_gid &#61; s->yst_uid;
  oh->yst_gid &#61; s->st_gid;
  oh->yst_atime &#61; s->st_atime;
  oh->yst_mtime &#61; s->st_mtime;
  oh->yst_ctime &#61; s->st_ctime;
  oh->yst_rdev  &#61; s->st_rdev;
 }
 
 if(t &#61;&#61; YAFFS_OBJECT_TYPE_FILE)
 {
  oh->fileSize &#61; s->st_size;
 }
 
 if(t &#61;&#61; YAFFS_OBJECT_TYPE_HARDLINK)
 {
  oh->equivalentObjectId &#61; equivalentObj;
 }
 
 if(t &#61;&#61; YAFFS_OBJECT_TYPE_SYMLINK)
 {
  strncpy(oh->alias,alias,YAFFS_MAX_ALIAS_LENGTH);
 }

/* KSI: FUBAR. Left for a leter time. */
#if 0
 if (convert_endian)
 {
      object_header_little_to_big_endian(oh);
 }
#endif
 
 return write_chunk(bytes,objId,0,0xffff);
 
}


static int process_directory(int parent, const char *path)
{

 DIR *dir;
 struct dirent *entry;

 nDirectories&#43;&#43;;
 
 dir &#61; opendir(path);

 if(dir)
 {
  while((entry &#61; readdir(dir)) !&#61; NULL)
  {
  
   /* Ignore . and .. */
   if(strcmp(entry->d_name,".") &&
      strcmp(entry->d_name,".."))
    {
     char full_name[500];
    struct stat stats;
    int equivalentObj;
    int newObj;
    
    sprintf(full_name,"%s/%s",path,entry->d_name);
    
    lstat(full_name,&stats);
    
    if(S_ISLNK(stats.st_mode) ||
        S_ISREG(stats.st_mode) ||
        S_ISDIR(stats.st_mode) ||
        S_ISFIFO(stats.st_mode) ||
        S_ISBLK(stats.st_mode) ||
        S_ISCHR(stats.st_mode) ||
        S_ISSOCK(stats.st_mode))
    {
    
     newObj &#61; obj_id&#43;&#43;;
     nObjects&#43;&#43;;
     
     printf("Object %d, %s is a ",newObj,full_name);
     
     /* We&#39;re going to create an object for it */
     if((equivalentObj &#61; find_obj_in_list(stats.st_dev, stats.st_ino)) > 0)
     {
       /* we need to make a hard link */
       printf("hard link to object %d/n",equivalentObj);
      error &#61;  write_object_header(newObj, YAFFS_OBJECT_TYPE_HARDLINK, &stats, parent, entry->d_name, equivalentObj, NULL);
     }
     else 
     {
      
      add_obj_to_list(stats.st_dev,stats.st_ino,newObj);
      
      if(S_ISLNK(stats.st_mode))
      {
     
       char symname[500];
      
       memset(symname,0, sizeof(symname));
     
       readlink(full_name,symname,sizeof(symname) -1);
      
       printf("symlink to /"%s/"/n",symname);
       error &#61;  write_object_header(newObj, YAFFS_OBJECT_TYPE_SYMLINK, &stats, parent, entry->d_name, -1, symname);

      }
      else if(S_ISREG(stats.st_mode))
      {
       printf("file, ");
       error &#61;  write_object_header(newObj, YAFFS_OBJECT_TYPE_FILE, &stats, parent, entry->d_name, -1, NULL);

       if(error >&#61; 0)
       {
        int h;
        __u8 bytes[chunkSize];
        int nBytes;
        int chunk &#61; 0;
        
        h &#61; open(full_name,O_RDONLY);
        if(h >&#61; 0)
        {
         memset(bytes,0xff,sizeof(bytes));
         while((nBytes &#61; read(h,bytes,sizeof(bytes))) > 0)
         {
          chunk&#43;&#43;;
          write_chunk(bytes,newObj,chunk,nBytes);
          memset(bytes,0xff,sizeof(bytes));
         }
         if(nBytes <0) 
            error &#61; nBytes;
            
         printf("%d data chunks written/n",chunk);
                close(h);
        }
        else
        {
         perror("Error opening file");
        }
        
       }       
              
      }
      else if(S_ISSOCK(stats.st_mode))
      {
       printf("socket/n");
       error &#61;  write_object_header(newObj, YAFFS_OBJECT_TYPE_SPECIAL, &stats, parent, entry->d_name, -1, NULL);
      }
      else if(S_ISFIFO(stats.st_mode))
      {
       printf("fifo/n");
       error &#61;  write_object_header(newObj, YAFFS_OBJECT_TYPE_SPECIAL, &stats, parent, entry->d_name, -1, NULL);
      }
      else if(S_ISCHR(stats.st_mode))
      {
       printf("character device/n");
       error &#61;  write_object_header(newObj, YAFFS_OBJECT_TYPE_SPECIAL, &stats, parent, entry->d_name, -1, NULL);
      }
      else if(S_ISBLK(stats.st_mode))
      {
       printf("block device/n");
       error &#61;  write_object_header(newObj, YAFFS_OBJECT_TYPE_SPECIAL, &stats, parent, entry->d_name, -1, NULL);
      }
      else if(S_ISDIR(stats.st_mode))
      {
       printf("directory/n");
       error &#61;  write_object_header(newObj, YAFFS_OBJECT_TYPE_DIRECTORY, &stats, parent, entry->d_name, -1, NULL);
       process_directory(newObj,full_name);
      }
     }
    }
    else
    {
     printf(" we don&#39;t handle this type/n");
    }
   }
  }
  closedir(dir);
 }
 
 return 0;

}

void usage(void)
{
 printf("usage: mkyaffs2image layout# dir image_file [convert]/n");
 printf(" layout#    NAND OOB layout # (0 - raw, 1 - nand_oob_64)/n");
 printf(" dir        the directory tree to be converted/n");
 printf(" image_file the output file to hold the image/n");
 printf(" &#39;convert&#39;  make a big-endian img on a little-endian machine. BROKEN !/n");
 exit(1);
}

int main(int argc, char *argv[])
{
 struct stat stats;
 int i;
 
 printf("mkyaffs2image: image building tool for YAFFS2 built "__DATE__"/n");
 
 if ((argc <4) || (sscanf(argv[1], "%u", &layout_no) !&#61; 1))
 {
         usage();
 }

 i &#61; 0;
 
 while (oob_layout[i].useecc !&#61; -1)
         i&#43;&#43;;
         
        if (layout_no >&#61; i)
                usage();

 if ((argc &#61;&#61; 5) && (!strncmp(argv[4], "convert", strlen("convert"))))
 {
                fprintf (stderr, "WARNING: ENDIAN CONVERSION IS BROKEN/n");
         /* KSI: Broken as of now. TBD. Fail. */
         usage();
                convert_endian &#61; 1;
        }
    
 if(stat(argv[2],&stats) <0)
 {
  printf("Could not stat %s/n",argv[2]);
  exit(1);
 }
 
 if(!S_ISDIR(stats.st_mode))
 {
  printf(" %s is not a directory/n",argv[2]);
  exit(1);
 }
 
 outFile &#61; open(argv[3],O_CREAT | O_TRUNC | O_WRONLY, S_IREAD | S_IWRITE);
 
 
 if(outFile <0)
 {
  printf("Could not open output file %s/n",argv[3]);
  exit(1);
 }
 
 printf("Processing directory %s into image file %s/n",argv[2],argv[3]);
 error &#61;  write_object_header(1, YAFFS_OBJECT_TYPE_DIRECTORY, &stats, 1,"", -1, NULL);

 if(error)
 error &#61; process_directory(YAFFS_OBJECTID_ROOT,argv[2]);
 
 close(outFile);
 
 if(error <0)
 {
  perror("operation incomplete");
  exit(1);
 }
 else
 {
  printf("Operation complete./n"
         "%d objects in %d directories/n"
         "%d NAND pages/n",nObjects, nDirectories, nPages);
 }
 
 close(outFile);
 
 exit(0);

PART2 About 16bytes OOB

另外&#xff0c;下面用关键性的数据结构简单展示一下16bytes OOB区内的组织格式&#xff1a;

typedef struct {
 unsigned chunkId:20;
 unsigned serialNumber:2;
 unsigned byteCountLSB:10;
 unsigned objectId:18;
 unsigned ecc:12;
 unsigned byteCountMSB:2;
} yaffs_Tags;

//LIUHAO: yaffs_TagsUnion共用体&#xff0c;方便实现对yaffs_Tags中数据的处理。
typedef union {
 yaffs_Tags asTags;
 __u8 asBytes[8];
} yaffs_TagsUnion;

//LIUHAO: 512bytes data &#43; 16bytes spare时spare区中的数据格式
//其中ecc1[3]为512bytes前半区的ecc校验码
//  ecc2[3]为512bytes后半区的ecc校验码

/* Spare structure for YAFFS1 */
typedef struct {
 __u8 tagByte0;
 __u8 tagByte1;
 __u8 tagByte2;
 __u8 tagByte3;
 __u8 pageStatus; /* set to 0 to delete the chunk */
 __u8 blockStatus;
 __u8 tagByte4;
 __u8 tagByte5;
 __u8 ecc1[3];
 __u8 tagByte6;
 __u8 tagByte7;
 __u8 ecc2[3];
} yaffs_Spare;

 

总结&#xff1a;

对于未知的领域和问题&#xff0c;唯独我们坚持&#xff0c;才会最终得到正确的答案。一句话说得好&#xff1a;人类最伟大的品质在于坚持&#xff0c;所有的梦想和目标都会因些而实现。


推荐阅读
  • 海马s5近光灯能否直接更换为H7?
    本文主要介绍了海马s5车型的近光灯是否可以直接更换为H7灯泡,并提供了完整的教程下载地址。此外,还详细讲解了DSP功能函数中的数据拷贝、数据填充和浮点数转换为定点数的相关内容。 ... [详细]
  • 微软头条实习生分享深度学习自学指南
    本文介绍了一位微软头条实习生自学深度学习的经验分享,包括学习资源推荐、重要基础知识的学习要点等。作者强调了学好Python和数学基础的重要性,并提供了一些建议。 ... [详细]
  • 电话号码的字母组合解题思路和代码示例
    本文介绍了力扣题目《电话号码的字母组合》的解题思路和代码示例。通过使用哈希表和递归求解的方法,可以将给定的电话号码转换为对应的字母组合。详细的解题思路和代码示例可以帮助读者更好地理解和实现该题目。 ... [详细]
  • 云原生边缘计算之KubeEdge简介及功能特点
    本文介绍了云原生边缘计算中的KubeEdge系统,该系统是一个开源系统,用于将容器化应用程序编排功能扩展到Edge的主机。它基于Kubernetes构建,并为网络应用程序提供基础架构支持。同时,KubeEdge具有离线模式、基于Kubernetes的节点、群集、应用程序和设备管理、资源优化等特点。此外,KubeEdge还支持跨平台工作,在私有、公共和混合云中都可以运行。同时,KubeEdge还提供数据管理和数据分析管道引擎的支持。最后,本文还介绍了KubeEdge系统生成证书的方法。 ... [详细]
  • 《数据结构》学习笔记3——串匹配算法性能评估
    本文主要讨论串匹配算法的性能评估,包括模式匹配、字符种类数量、算法复杂度等内容。通过借助C++中的头文件和库,可以实现对串的匹配操作。其中蛮力算法的复杂度为O(m*n),通过随机取出长度为m的子串作为模式P,在文本T中进行匹配,统计平均复杂度。对于成功和失败的匹配分别进行测试,分析其平均复杂度。详情请参考相关学习资源。 ... [详细]
  • CF:3D City Model(小思维)问题解析和代码实现
    本文通过解析CF:3D City Model问题,介绍了问题的背景和要求,并给出了相应的代码实现。该问题涉及到在一个矩形的网格上建造城市的情景,每个网格单元可以作为建筑的基础,建筑由多个立方体叠加而成。文章详细讲解了问题的解决思路,并给出了相应的代码实现供读者参考。 ... [详细]
  • 本文分析了Wince程序内存和存储内存的分布及作用。Wince内存包括系统内存、对象存储和程序内存,其中系统内存占用了一部分SDRAM,而剩下的30M为程序内存和存储内存。对象存储是嵌入式wince操作系统中的一个新概念,常用于消费电子设备中。此外,文章还介绍了主电源和后备电池在操作系统中的作用。 ... [详细]
  • 本文介绍了在Ubuntu 11.10 x64环境下安装Android开发环境的步骤,并提供了解决常见问题的方法。其中包括安装Eclipse的ADT插件、解决缺少GEF插件的问题以及解决无法找到'userdata.img'文件的问题。此外,还提供了相关插件和系统镜像的下载链接。 ... [详细]
  • 本文介绍了利用ARMA模型对平稳非白噪声序列进行建模的步骤及代码实现。首先对观察值序列进行样本自相关系数和样本偏自相关系数的计算,然后根据这些系数的性质选择适当的ARMA模型进行拟合,并估计模型中的位置参数。接着进行模型的有效性检验,如果不通过则重新选择模型再拟合,如果通过则进行模型优化。最后利用拟合模型预测序列的未来走势。文章还介绍了绘制时序图、平稳性检验、白噪声检验、确定ARMA阶数和预测未来走势的代码实现。 ... [详细]
  • 原文地址http://balau82.wordpress.com/2010/02/28/hello-world-for-bare-metal-arm-using-qemu/最开始时 ... [详细]
  • 本文为Codeforces 1294A题目的解析,主要讨论了Collecting Coins整除+不整除问题。文章详细介绍了题目的背景和要求,并给出了解题思路和代码实现。同时提供了在线测评地址和相关参考链接。 ... [详细]
  • 本文介绍了如何使用PHP向系统日历中添加事件的方法,通过使用PHP技术可以实现自动添加事件的功能,从而实现全局通知系统和迅速记录工具的自动化。同时还提到了系统exchange自带的日历具有同步感的特点,以及使用web技术实现自动添加事件的优势。 ... [详细]
  • VScode格式化文档换行或不换行的设置方法
    本文介绍了在VScode中设置格式化文档换行或不换行的方法,包括使用插件和修改settings.json文件的内容。详细步骤为:找到settings.json文件,将其中的代码替换为指定的代码。 ... [详细]
  • 本文介绍了在开发Android新闻App时,搭建本地服务器的步骤。通过使用XAMPP软件,可以一键式搭建起开发环境,包括Apache、MySQL、PHP、PERL。在本地服务器上新建数据库和表,并设置相应的属性。最后,给出了创建new表的SQL语句。这个教程适合初学者参考。 ... [详细]
  • 本文介绍了设计师伊振华受邀参与沈阳市智慧城市运行管理中心项目的整体设计,并以数字赋能和创新驱动高质量发展的理念,建设了集成、智慧、高效的一体化城市综合管理平台,促进了城市的数字化转型。该中心被称为当代城市的智能心脏,为沈阳市的智慧城市建设做出了重要贡献。 ... [详细]
author-avatar
mobiledu2502926273
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有