1、mkyaffsimage工具只能生成老式的yaffs1映象文件,需要修改才能支持新格式。
yaffs1新、老格式的不同在于oob区的使用发生了变化:一是ECC检验码的位置发生了变化,二是可用空间即标记(tag)的数据结构定义发生了变化。
2、huanghuang@huanghuang-desktop:/work/system/Development/yaffs2/utils$sudo vi mkyaffsimage.c
以下红色字为新增的。。
#include
#include
#include
#include
#include
#include
#include
#include
#include "yaffs_ecc.h"
#include "yaffs_guts.h"
#include "yaffs_packedtags1.h"
#define MAX_OBJECTS 10000
const char * mkyaffsimage_c_version = "$Id: mkyaffsimage.c,v 1.7 2003/07/16 03:00:48 charles Exp $";
。。。。。。。。。。
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];
/* дҳÊý¾Ý£¬512×Ö½Ú */
error = write(outFile,data,512);
if(error < 0) return error;
/* ¹¹Ôìtag */
etags.chunkId = chunkId;
etags.serialNumber = 0;
etags.byteCount = nBytes;
etags.objectId = objId;
etags.chunkDeleted = 0;
yaffs_PackTags1(&pt1, &etags);
/* ¼ÆËãtag±¾ÉíµÄECCÂë */
yaffs_CalcTagsECC((yaffs_Tags *)&pt1);
memset(oobbuf, 0xff, 16);
memcpy(oobbuf+8, &pt1, 8);
/*
* ʹÓÃÓëÄÚºËMTD²ãÏàͬµÄ·½·¨¼ÆËãÒ»Ò³Êý¾Ý(512×Ö½Ú)µÄECCÂë
* ²¢°ÑËüÃÇÌîÈëoob
*/
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++;
/* дoobÊý¾Ý£¬16×Ö½Ú */
return write(outFile, oobbuf, 16);
#endif
}
。。。。。。。。
3、从内核源文件drivers/mtd/nand/nand_ecc.c修改,分别摘取nand_calculate_ecc函数、nand_ecc_precalc_table数组,并且去除函数中的第一个形参“struct mtd_info *mtd”。
huanghuang@huanghuang-desktop:/work/system/Development/yaffs2/utils$ sudo vi 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;
/* Initialize variables */
reg1 = reg2 = reg3 = 0;
/* Build up column parity */
for(i = 0; i < 256; i++) {
/* Get CP0 - CP5 from table */
idx = nand_ecc_precalc_table[*dat++];
reg1 ^= (idx & 0x3f);
/* All bit XOR = 1 ? */
if (idx & 0x40) {
reg3 ^= (uint8_t) i;
reg2 ^= ~((uint8_t) i);
}
}
/* Create non-inverted ECC code from line parity */
tmp1 = (reg3 & 0x80) >> 0; /* B7 -> B7 */
tmp1 |= (reg2 & 0x80) >> 1; /* B7 -> B6 */
tmp1 |= (reg3 & 0x40) >> 1; /* B6 -> B5 */
tmp1 |= (reg2 & 0x40) >> 2; /* B6 -> B4 */
tmp1 |= (reg3 & 0x20) >> 2; /* B5 -> B3 */
tmp1 |= (reg2 & 0x20) >> 3; /* B5 -> B2 */
tmp1 |= (reg3 & 0x10) >> 3; /* B4 -> B1 */
tmp1 |= (reg2 & 0x10) >> 4; /* B4 -> B0 */
tmp2 = (reg3 & 0x08) << 4; /* B3 -> B7 */
tmp2 |= (reg2 & 0x08) << 3; /* B3 -> B6 */
tmp2 |= (reg3 & 0x04) << 3; /* B2 -> B5 */
tmp2 |= (reg2 & 0x04) << 2; /* B2 -> B4 */
tmp2 |= (reg3 & 0x02) << 2; /* B1 -> B3 */
tmp2 |= (reg2 & 0x02) << 1; /* B1 -> B2 */
tmp2 |= (reg3 & 0x01) << 1; /* B0 -> B1 */
tmp2 |= (reg2 & 0x01) << 0; /* B7 -> B0 */
/* Calculate final ECC code */
#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);
4、修改Makefile
huanghuang@huanghuang-desktop:/work/system/Development/yaffs2/utils$sudo cp ../yaffs_packedtags1.c ./
huanghuang@huanghuang-desktop:/work/system/Development/yaffs2/utils$ sudo vi Makefile
MKYAFFSSOURCES = mkyaffsimage.c yaffs_packedtags1.c nand_ecc.c
MKYAFFSIMAGEOBJS = $(MKYAFFSSOURCES:.c=.o)
5、huanghuang@huanghuang-desktop:/work/system/Development/yaffs2/utils$ sudo make
Makefile mkyaffsimage yaffs_ecc.c yaffs_packedtags2.o
Makefile.rej mkyaffsimage.c yaffs_ecc.o yaffs_tagsvalidity.c
mkyaffs2image mkyaffsimage.o yaffs_packedtags1.c yaffs_tagsvalidity.o
mkyaffs2image.c nand_ecc.c yaffs_packedtags1.o
mkyaffs2image.o nand_ecc.o yaffs_packedtags2.c
6、huanghuang@huanghuang-desktop:/work/system/Development/yaffs2/utils$sudo cp mkyaffsimage /usr/local/bin