* add "-DMM_MKYAFFS2IMAGE" and a target "mm-mkyaffs2image" to utils/Makefile * remove ECC stuff in mm-mkyaffs2image * add block pad code * using yaffs_pack_tags2_tags_only
Signed-off-by: Xiangfu Liu <[email protected]> --- Hi Sebastien this patch is make mkyaffs2image can gnerate correct image for milkymist one utils/Makefile | 9 ++++- utils/mkyaffs2image.c | 96 ++++++++++++++++++++++++++++++++++++------------- yaffs_guts.h | 6 +++ yaffs_packedtags2.c | 8 ++++ 4 files changed, 92 insertions(+), 27 deletions(-) diff --git a/utils/Makefile b/utils/Makefile index 49bf03b..c7fba49 100644 --- a/utils/Makefile +++ b/utils/Makefile @@ -16,9 +16,10 @@ #KERNELDIR = /usr/src/kernel-headers-2.4.18 -CFLAGS = -I/usr/include -I.. -O2 -Wall -DCONFIG_YAFFS_UTIL +CFLAGS = -I/usr/include -I.. -I../direct -O2 -Wall -DCONFIG_YAFFS_UTIL CFLAGS+= -Wshadow -Wpointer-arith -Wwrite-strings -Wstrict-prototypes -Wmissing-declarations CFLAGS+= -Wmissing-prototypes -Wredundant-decls -Wnested-externs -Winline +CFLAGS+= -DMM_MKYAFFS2IMAGE ## Change if you are using a cross-compiler MAKETOOLS = @@ -49,6 +50,10 @@ mkyaffsimage: $(COMMONOBJS) $(MKYAFFSIMAGEOBJS) mkyaffs2image: $(COMMONOBJS) $(MKYAFFS2IMAGEOBJS) $(CC) -o $@ $(COMMONOBJS) $(MKYAFFS2IMAGEOBJS) +mm-mkyaffs2image: $(MKYAFFS2IMAGEOBJS) + $(CC) -o $@ $(MKYAFFS2IMAGEOBJS) clean: - rm -f $(COMMONOBJS) $(MKYAFFSIMAGEOBJS) $(MKYAFFS2IMAGEOBJS) $(COMMONLINKS) $(MKYAFFSLINKS) $(MKYAFFS2LINKS) mkyaffsimage mkyaffs2image core + rm -f $(COMMONOBJS) $(MKYAFFSIMAGEOBJS) $(MKYAFFS2IMAGEOBJS) + rm -f $(COMMONLINKS) $(MKYAFFSLINKS) $(MKYAFFS2LINKS) + rm -f mkyaffsimage mkyaffs2image mm-mkyaffs2image diff --git a/utils/mkyaffs2image.c b/utils/mkyaffs2image.c index fa2229b..58e9f7c 100644 --- a/utils/mkyaffs2image.c +++ b/utils/mkyaffs2image.c @@ -31,22 +31,42 @@ #include <unistd.h> #include <errno.h> #include <assert.h> -#include "yaffs_ecc.h" #include "yaffs_guts.h" +#ifndef MM_MKYAFFS2IMAGE +#include "yaffs_ecc.h" +#endif + #include "yaffs_tagsvalidity.h" #include "yaffs_packedtags2.h" -unsigned yaffs_trace_mask=0; +#define SWAP32(x) ((((x) & 0x000000FF) << 24) | \ + (((x) & 0x0000FF00) << 8 ) | \ + (((x) & 0x00FF0000) >> 8 ) | \ + (((x) & 0xFF000000) >> 24)) + +#define SWAP16(x) ((((x) & 0x00FF) << 8) | \ + (((x) & 0xFF00) >> 8)) #define MAX_OBJECTS 10000 +unsigned yaffs_trace_mask=0; + // Adjust these to match your NAND LAYOUT: +#ifdef MM_MKYAFFS2IMAGE +#define chunkSize 512 +#define spareSize 16 +#define blockSize (128*1024) +#define pagesPerBlock (blockSize/(chunkSize+spareSize)) +#define remainderSize (blockSize%(chunkSize+spareSize)) + +static int write_chunk_count = 0; + +#else #define chunkSize 2048 #define spareSize 64 #define pagesPerBlock 64 - - +#endif typedef struct { @@ -172,7 +192,15 @@ static void little_to_big_endian(struct yaffs_ext_tags *tagsPtr) #endif } -static void shuffle_oob(char *spareData, struct yaffs_packed_tags2 *pt) +static void yaffs_packed_tags2_tags_only_to_big_endian(struct yaffs_packed_tags2_tags_only *ptt) +{ + ptt->seq_number = SWAP32(ptt->seq_number); + ptt->obj_id = SWAP32(ptt->obj_id); + ptt->chunk_id = SWAP32(ptt->chunk_id); + ptt->n_bytes = SWAP32(ptt->n_bytes); +} + +static void shuffle_oob(char *spareData, struct yaffs_packed_tags2_tags_only *pt) { assert(sizeof(*pt) <= spareSize); // NAND LAYOUT: For non-trivial OOB orderings, here would be a good place to shuffle. @@ -181,8 +209,15 @@ static void shuffle_oob(char *spareData, struct yaffs_packed_tags2 *pt) static int write_chunk(u8 *data, u32 id, u32 chunk_id, u32 n_bytes) { +#ifdef MM_MKYAFFS2IMAGE + u8 remainder[remainderSize]; +#endif struct yaffs_ext_tags t; +#ifdef MM_MKYAFFS2IMAGE + struct yaffs_packed_tags2_tags_only pt; +#else struct yaffs_packed_tags2 pt; +#endif char spareData[spareSize]; if (write(outFile,data,chunkSize) != chunkSize) @@ -201,41 +236,51 @@ static int write_chunk(u8 *data, u32 id, u32 chunk_id, u32 n_bytes) // added NCB **CHECK** t.chunk_used = 1; + nPages++; + + memset(&pt, 0, sizeof(pt)); +#ifdef MM_MKYAFFS2IMAGE + yaffs_pack_tags2_tags_only(&pt,&t); + + if (convert_endian) + yaffs_packed_tags2_tags_only_to_big_endian(&pt); + +#else if (convert_endian) { little_to_big_endian(&t); } - nPages++; - - memset(&pt, 0, sizeof(pt)); yaffs_pack_tags2(&pt,&t,1); +#endif memset(spareData, 0xff, sizeof(spareData)); shuffle_oob(spareData, &pt); if (write(outFile,spareData,sizeof(spareData)) != sizeof(spareData)) fatal("write"); + +#ifdef MM_MKYAFFS2IMAGE + write_chunk_count++; + if (write_chunk_count == pagesPerBlock) { + write_chunk_count = 0; + memset(remainder, 0xff, sizeof(remainder)); + if (write(outFile,remainder,sizeof(remainder)) != sizeof(remainder)) + fatal("write"); + } +#endif return 0; } -#define SWAP32(x) ((((x) & 0x000000FF) << 24) | \ - (((x) & 0x0000FF00) << 8 ) | \ - (((x) & 0x00FF0000) >> 8 ) | \ - (((x) & 0xFF000000) >> 24)) - -#define SWAP16(x) ((((x) & 0x00FF) << 8) | \ - (((x) & 0xFF00) >> 8)) - // This one is easier, since the types are more standard. No funky shifts here. static void object_header_little_to_big_endian(struct yaffs_obj_hdr* oh) { - int i; oh->type = SWAP32(oh->type); // GCC makes enums 32 bits. oh->parent_obj_id = SWAP32(oh->parent_obj_id); // int oh->sum_no_longer_used = SWAP16(oh->sum_no_longer_used); // u16 - Not used, but done for completeness. // name = skip. Char array. Not swapped. oh->yst_mode = SWAP32(oh->yst_mode); + #ifdef CONFIG_YAFFS_WINCE // WinCE doesn't implement this, but we need to just in case. // In fact, WinCE would be *THE* place where this would be an issue. // Why? WINCE is little-endian only. @@ -258,7 +303,6 @@ static void object_header_little_to_big_endian(struct yaffs_obj_hdr* oh) oh->equiv_id = SWAP32(oh->equiv_id); // alias - char array. oh->yst_rdev = SWAP32(oh->yst_rdev); - #ifdef CONFIG_YAFFS_WINCE oh->win_ctime[0] = SWAP32(oh->win_ctime[0]); oh->win_ctime[1] = SWAP32(oh->win_ctime[1]); @@ -266,13 +310,6 @@ static void object_header_little_to_big_endian(struct yaffs_obj_hdr* oh) oh->win_atime[1] = SWAP32(oh->win_atime[1]); oh->win_mtime[0] = SWAP32(oh->win_mtime[0]); oh->win_mtime[1] = SWAP32(oh->win_mtime[1]); -#else - - { - int n = sizeof(oh->room_to_grow)/sizeof(oh->room_to_grow[0]); - for(i=0; i < n; i++) - oh->room_to_grow[i] = SWAP32(oh->room_to_grow[i]); - } #endif } @@ -343,6 +380,9 @@ static int write_object_header(int id, enum yaffs_obj_type t, struct stat *s, in static void pad_image(void) { u8 data[chunkSize + spareSize]; +#ifdef MM_MKYAFFS2IMAGE + u8 remainder[remainderSize]; +#endif int padPages = (nPages % pagesPerBlock); if (padPages) @@ -354,6 +394,12 @@ static void pad_image(void) fatal("write"); } } + +#ifdef MM_MKYAFFS2IMAGE + memset(remainder, 0xff, sizeof(remainder)); + if (write(outFile,remainder,sizeof(remainder)) != sizeof(remainder)) + fatal("write"); +#endif } static int process_directory(int parent, const char *path) diff --git a/yaffs_guts.h b/yaffs_guts.h index 307eba2..1cdf89b 100644 --- a/yaffs_guts.h +++ b/yaffs_guts.h @@ -106,6 +106,12 @@ /* Special sequence number for bad block that failed to be marked bad */ #define YAFFS_SEQUENCE_BAD_BLOCK 0xFFFF0000 +#ifdef MM_MKYAFFS2IMAGE +struct list_head { + struct list_head *next, *prev; +}; +#endif + /* ChunkCache is used for short read/write operations.*/ struct yaffs_cache { struct yaffs_obj *object; diff --git a/yaffs_packedtags2.c b/yaffs_packedtags2.c index 6c12aed..4c67647 100644 --- a/yaffs_packedtags2.c +++ b/yaffs_packedtags2.c @@ -99,11 +99,13 @@ void yaffs_pack_tags2(struct yaffs_packed_tags2 *pt, { yaffs_pack_tags2_tags_only(&pt->t, t); +#ifndef MM_MKYAFFS2IMAGE if (tags_ecc) yaffs_ecc_calc_other((unsigned char *)&pt->t, sizeof(struct yaffs_packed_tags2_tags_only), &pt->ecc); +#endif } void yaffs_unpack_tags2_tags_only(struct yaffs_ext_tags *t, @@ -164,6 +166,11 @@ void yaffs_unpack_tags2(struct yaffs_ext_tags *t, struct yaffs_packed_tags2 *pt, struct yaffs_ecc_other ecc; int result; + +#ifdef MM_MKYAFFS2IMAGE + result = 0; +#endif +#ifndef MM_MKYAFFS2IMAGE yaffs_ecc_calc_other((unsigned char *)&pt->t, sizeof(struct yaffs_packed_tags2_tags_only), @@ -173,6 +180,7 @@ void yaffs_unpack_tags2(struct yaffs_ext_tags *t, struct yaffs_packed_tags2 *pt, sizeof(struct yaffs_packed_tags2_tags_only), &pt->ecc, &ecc); +#endif switch (result) { case 0: ecc_result = YAFFS_ECC_RESULT_NO_ERROR; -- 1.7.0.4 _______________________________________________ http://lists.milkymist.org/listinfo.cgi/devel-milkymist.org IRC: #milkymist@Freenode Twitter: www.twitter.com/milkymistvj Ideas? http://milkymist.uservoice.com
