Linux mtd subsysterm has updated the nand spare data layout and YAFFS filesystem has changed to use yaffs_Packedtags1 data structure. Therefore, mkyaffsimage should discard the "yaffs_Spare" data structure and use "yaffs_Packedtags1" according to the new YAFFS filesystem implementation. Signed-off-by: Stanley.Miao --- utils/Makefile | 3 +- utils/mkyaffsimage.c | 167 ++++++++++++++----------------------------------- 2 files changed, 50 insertions(+), 120 deletions(-) diff --git a/utils/Makefile b/utils/Makefile index 49bf03b..45554eb 100644 --- a/utils/Makefile +++ b/utils/Makefile @@ -29,7 +29,8 @@ COMMONLINKS = yaffs_ecc.c COMMONOBJS = $(COMMONLINKS:.c=.o) MKYAFFSSOURCES = mkyaffsimage.c -MKYAFFSIMAGEOBJS = $(MKYAFFSSOURCES:.c=.o) +MKYAFFSLINKS = yaffs_packedtags1.c yaffs_tagsvalidity.c +MKYAFFSIMAGEOBJS = $(MKYAFFSSOURCES:.c=.o) $(MKYAFFSLINKS:.c=.o) MKYAFFS2SOURCES = mkyaffs2image.c MKYAFFS2LINKS = yaffs_packedtags2.c yaffs_tagsvalidity.c diff --git a/utils/mkyaffsimage.c b/utils/mkyaffsimage.c index e8434e8..f9d9d76 100644 --- a/utils/mkyaffsimage.c +++ b/utils/mkyaffsimage.c @@ -30,6 +30,9 @@ #include "yaffs_ecc.h" #include "yaffs_guts.h" +#include "yaffs_tagsvalidity.h" +#include "yaffs_packedtags1.h" + #define MAX_OBJECTS 10000 @@ -112,151 +115,77 @@ static int find_obj_in_list(dev_t dev, ino_t ino) return -1; } -// NCB added 10/9/2002 -static __u16 yaffs_CalcNameSum(const char *name) +unsigned int yaffs_CalcTagsECC(yaffs_Tags *tags) { - __u16 sum = 0; - __u16 i = 1; - - __u8 *bname = (__u8 *)name; - - while (*bname) - { - sum += (*bname) * i; - i++; - bname++; - } - return sum; -} - - -static void yaffs_CalcECC(const __u8 *data, yaffs_Spare *spare) -{ - yaffs_ECCCalculate(data , spare->ecc1); - yaffs_ECCCalculate(&data[256] , spare->ecc2); -} - -static void yaffs_CalcTagsECC(yaffs_Tags *tags) -{ - // Todo don't do anything yet. Need to calculate ecc - unsigned char *b = ((yaffs_TagsUnion *)tags)->asBytes; - unsigned i,j; - unsigned ecc = 0; + /* Calculate an ecc */ + unsigned char *b = ((yaffs_TagsUnion *) tags)->asBytes; + unsigned i, j; + unsigned ecc = 0; unsigned bit = 0; - // Clear ECC fields - if (!convert_endian) - { - tags->ecc = 0; - } - else - { - // Because we're in "munged tag" mode, we have to clear it manually - b[6] &= 0xC0; - b[7] &= 0x03; - } - - for(i = 0; i < 8; i++) - { -// NCB modified 20-9-02 for(j = 1; j &0x7f; j<<=1) - for(j = 1; j &0xff; j<<=1) - { + for (i = 0; i < 8; i++) { + for (j = 1; j & 0xff; j <<= 1) { bit++; - if(b[i] & j) - { + if (b[i] & j) ecc ^= bit; - } } } - - // Write out ECC - if (!convert_endian) - { - tags->ecc = ecc; - } - else - { - // We have to munge the ECC again. - b[6] |= ((ecc >> 6) & 0x3F); - b[7] |= ((ecc & 0x3F) << 2); - } -} -static void yaffs_LoadTagsIntoSpare(yaffs_Spare *sparePtr, yaffs_Tags *tagsPtr) -{ - yaffs_TagsUnion *tu = (yaffs_TagsUnion *)tagsPtr; - - //yaffs_CalcTagsECC(tagsPtr); - - sparePtr->tagByte0 = tu->asBytes[0]; - sparePtr->tagByte1 = tu->asBytes[1]; - sparePtr->tagByte2 = tu->asBytes[2]; - sparePtr->tagByte3 = tu->asBytes[3]; - sparePtr->tagByte4 = tu->asBytes[4]; - sparePtr->tagByte5 = tu->asBytes[5]; - sparePtr->tagByte6 = tu->asBytes[6]; - sparePtr->tagByte7 = tu->asBytes[7]; + + return ecc; } /* 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) +static void little_to_big_endian(yaffs_TagsUnion *temp, yaffs_Tags *tagsPtr) { - yaffs_TagsUnion * tags = (yaffs_TagsUnion* )tagsPtr; // Work in bytes. - yaffs_TagsUnion temp; - - memset(&temp, 0, sizeof(temp)); - // Ick, I hate magic numbers. - temp.asBytes[0] = ((tags->asBytes[2] & 0x0F) << 4) | ((tags->asBytes[1] & 0xF0) >> 4); - temp.asBytes[1] = ((tags->asBytes[1] & 0x0F) << 4) | ((tags->asBytes[0] & 0xF0) >> 4); - temp.asBytes[2] = ((tags->asBytes[0] & 0x0F) << 4) | ((tags->asBytes[2] & 0x30) >> 2) | ((tags->asBytes[3] & 0xC0) >> 6); - temp.asBytes[3] = ((tags->asBytes[3] & 0x3F) << 2) | ((tags->asBytes[2] & 0xC0) >> 6); - temp.asBytes[4] = ((tags->asBytes[6] & 0x03) << 6) | ((tags->asBytes[5] & 0xFC) >> 2); - temp.asBytes[5] = ((tags->asBytes[5] & 0x03) << 6) | ((tags->asBytes[4] & 0xFC) >> 2); - temp.asBytes[6] = ((tags->asBytes[4] & 0x03) << 6) | (tags->asBytes[7] & 0x3F); - temp.asBytes[7] = (tags->asBytes[6] & 0xFC) | ((tags->asBytes[7] & 0xC0) >> 6); - - // Now copy it back. - tags->asBytes[0] = temp.asBytes[0]; - tags->asBytes[1] = temp.asBytes[1]; - tags->asBytes[2] = temp.asBytes[2]; - tags->asBytes[3] = temp.asBytes[3]; - tags->asBytes[4] = temp.asBytes[4]; - tags->asBytes[5] = temp.asBytes[5]; - tags->asBytes[6] = temp.asBytes[6]; - tags->asBytes[7] = temp.asBytes[7]; + yaffs_TagsUnion * tags = (yaffs_TagsUnion *)tagsPtr; + + memset(temp, 0, sizeof(*temp)); + temp->asBytes[0] = ((tags->asBytes[2] & 0x0F) << 4) | ((tags->asBytes[1] & 0xF0) >> 4); + temp->asBytes[1] = ((tags->asBytes[1] & 0x0F) << 4) | ((tags->asBytes[0] & 0xF0) >> 4); + temp->asBytes[2] = ((tags->asBytes[0] & 0x0F) << 4) | \ + ((tags->asBytes[2] & 0x30) >> 2) | \ + ((tags->asBytes[3] & 0xC0) >> 6); + temp->asBytes[3] = ((tags->asBytes[3] & 0x3F) << 2) | ((tags->asBytes[2] & 0xC0) >> 6); + temp->asBytes[4] = ((tags->asBytes[6] & 0x03) << 6) | ((tags->asBytes[5] & 0xFC) >> 2); + temp->asBytes[5] = ((tags->asBytes[5] & 0x03) << 6) | ((tags->asBytes[4] & 0xFC) >> 2); + temp->asBytes[6] = ((tags->asBytes[4] & 0x03) << 6) | (tags->asBytes[7] & 0x3F); + temp->asBytes[7] = (tags->asBytes[6] & 0xFC) | \ + ((tags->asBytes[7] & 0x40) >> 5) | \ + ((tags->asBytes[7] & 0x80) >> 7); } static int write_chunk(__u8 *data, __u32 objId, __u32 chunkId, __u32 nBytes) { - yaffs_Tags t; - yaffs_Spare s; + yaffs_ExtendedTags t; + yaffs_PackedTags1 pt; + yaffs_TagsUnion temp; error = write(outFile,data,512); if(error < 0) return error; - memset(&t,0xff,sizeof (yaffs_Tags)); - memset(&s,0xff,sizeof (yaffs_Spare)); - + yaffs_InitialiseTags(&t); + t.chunkId = chunkId; - t.serialNumber = 0; - t.byteCountLSB = nBytes; + t.serialNumber = 1; + t.byteCount = nBytes; t.objectId = objId; + t.chunkUsed = 1; - if (convert_endian) - { - little_to_big_endian(&t); - } - - yaffs_CalcTagsECC(&t); - yaffs_LoadTagsIntoSpare(&s,&t); - yaffs_CalcECC(data,&s); - + yaffs_PackTags1(&pt, &t); nPages++; - - return write(outFile,&s,sizeof(yaffs_Spare)); - + + if (convert_endian) { + little_to_big_endian(&temp, &pt); + pt.ecc = yaffs_CalcTagsECC((yaffs_Tags *)&temp); + little_to_big_endian(&temp, &pt); + return write(outFile, &temp, 16); + } else { + pt.ecc = yaffs_CalcTagsECC((yaffs_Tags *)&pt); + return write(outFile, &pt, 16); + } } #define SWAP32(x) ((((x) & 0x000000FF) << 24) | \ -- 1.5.4.3