2015-11-10 16:34 GMT+13:00 979746084@qq.com <979746084@qq.com>:
Which is Yaffs2's on flash spare structure?
For yaffs1, yaffs_spare is the actual on-flash spare structure
struct yaffs_spare {
u8 tb1;
u8 tb0;  //前四个字节表示yaffs_tag信息
u8 tb2;
u8 tb3;
u8 page_status;   //一个字节作为删除标记 /* set to 0 to delete the chunk */
u8 block_status;  //一个字节作为坏块标记位,非0xff表示坏块
u8 tb4;  //中间两个字节表示yaffs_tag信息
u8 tb5;
u8 ecc1[3];  //数组,三个字节存放相应chunk的后256字节ECC校验结果
u8 tb6;  //接着又两个字节的yaffs_tag信息
u8 tb7;
u8 ecc2[3];  //数组,三个字节存放相应chunk的前256字节的ECC校验结果
};

the following two, yaffs_tags and yaffs_packed_tags1 are the logical structure,why there are two ,they are nearly the same?

struct yaffs_tags {
u32 chunk_id:20; //20位用来表示chunk_id
u32 serial_number:2; //2位用来表示序列号
u32 n_bytes_lsb:10; //10位用来表示该页内有效的字节数
u32 obj_id:18; //18位用来表示obj_id,唯一标识一个对象
u32 ecc:12; //yaffs_tags本身的ECC校验和
u32 n_bytes_msb:2; //还有两位未使用,保持为1
};

struct yaffs_packed_tags1 {
u32 chunk_id:20;//20位的chunkID
u32 serial_number:2;//2位的serial num序列号
u32 n_bytes:10;//10位表示有效字节数
u32 obj_id:18;//18位表示objID
u32 ecc:12;//12位表示ECC校验值
u32 deleted:1;//1位的删除标记
u32 unused_stuff:1;//1位,未使用
unsigned should_be_ff;//为全1

};


For yaffs2, yaffs_packed_tags2_tags_only and yaffs_packed_tags are only the tags of yaffs2, not the whole yaffs2 spare, So whtat's the real on-flash yaffs2's spare structure?

struct yaffs_packed_tags2_tags_only {
unsigned seq_number;//顺序号
unsigned obj_id;//对象ID
unsigned chunk_id;//chunkID
unsigned n_bytes;//字节数
};

struct yaffs_packed_tags2 {
struct yaffs_packed_tags2_tags_only t;//tags标签
struct yaffs_ecc_other ecc;//ECC校验值,12字节,存储的是上面的tags标签的ECC校验值
};


What is important is the information that is stored: ie. it must store the yaffs_packed_tags2_tags_only as a minimum.

If the flash space where the tags is stored is already ECC corrected, then that is enough. If not, then the other option is to
instead store the yaffs_packed_tags2 structure which is both the tags + an ECC block to protect the tags.

Which to use will depend on the type of flash and ECC you are using and whether you are using inband tags etc.

For example, consider the following scenarios:

1. Using inband tags:
The tags (yaffs_packed_tags2_tags_only) are stored alongside the data in the data portion of the NAND page. The whole data portion (including the tags) is
protected by ECC stored in the spare area.

2. Using out of band tags, but ECC is already available on spare area:
Some parts (eg. some Micron ONFI parts) have built in ECC and have a fixed layout where some of the spare bytes are used for ECC but other bytes are still
available for storing tags and these bytes are protected by the ECC. In this case you can store just the tags since there is no need for extra ECC on the tags.

3. Some parts do not provide any ECC on the spare area. If you want to store tags in the spare area (ie. out of band tags) then it is advisable to use yaffs_packed_tags2
since that also performs extra ECC on the tags.

Regards

-- Charles