Browse files

add rtems-mkyaffs2image support

  • Loading branch information...
1 parent 01ee204 commit 4f5938aebf5d14197c1a8de8531184fe4f12cbca Xiangfu Liu committed Sep 13, 2011
Showing with 80 additions and 19 deletions.
  1. +5 −1 utils/Makefile
  2. +67 −17 utils/mkyaffs2image.c
  3. +8 −1 yaffs_packedtags2.c
View
6 utils/Makefile
@@ -16,7 +16,7 @@
#KERNELDIR = /usr/src/kernel-headers-2.4.18
-CFLAGS = -O2 -Wall -DCONFIG_YAFFS_UTIL
+CFLAGS = -O2 -Wall -DCONFIG_YAFFS_UTIL
CFLAGS+= -Wshadow -Wpointer-arith -Wwrite-strings -Wstrict-prototypes -Wmissing-declarations
CFLAGS+= -Wmissing-prototypes -Wredundant-decls -Wnested-externs -Winline
@@ -62,6 +62,10 @@ mkyaffsimage: $(MKYAFFSIMAGEOBJS) $(COMMONOBJS)
mkyaffs2image: $(MKYAFFS2IMAGEOBJS) $(COMMONOBJS)
$(CC) -o $@ $^
+rtems-mkyaffs2image: CFLAGS:= $(CFLAGS) -DRTEMS_MKYAFFS2IMAGE
+rtems-mkyaffs2image: $(MKYAFFS2IMAGEOBJS)
+ $(CC) -o $@ $(MKYAFFS2IMAGEOBJS)
clean:
rm -f $(COMMONOBJS) $(MKYAFFSIMAGEOBJS) $(MKYAFFS2IMAGEOBJS) $(ALL_LINKS) mkyaffsimage mkyaffs2image core
+ rm -f rtems-mkyaffs2image
View
84 utils/mkyaffs2image.c
@@ -31,21 +31,39 @@
#include <unistd.h>
#include <errno.h>
#include <assert.h>
-#include "yaffs_ecc.h"
#include "yaffs_guts.h"
+#ifndef RTEMS_MKYAFFS2IMAGE
+#include "yaffs_ecc.h"
+#endif
+
#include "yaffs_packedtags2.h"
unsigned yaffs_trace_mask=0;
#define MAX_OBJECTS 10000
// Adjust these to match your NAND LAYOUT:
-#define chunkSize 2048
-#define spareSize 64
-#define pagesPerBlock 64
+#ifdef RTEMS_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
+#define SWAP32(x) ((((x) & 0x000000FF) << 24) | \
+ (((x) & 0x0000FF00) << 8 ) | \
+ (((x) & 0x00FF0000) >> 8 ) | \
+ (((x) & 0xFF000000) >> 24))
+#define SWAP16(x) ((((x) & 0x00FF) << 8) | \
+ (((x) & 0xFF00) >> 8))
typedef struct
{
@@ -171,7 +189,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.
@@ -180,8 +206,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 RTEMS_MKYAFFS2IMAGE
+ u8 remainder[remainderSize];
+#endif
struct yaffs_ext_tags t;
+#ifdef RTEMS_MKYAFFS2IMAGE
+ struct yaffs_packed_tags2_tags_only pt;
+#else
struct yaffs_packed_tags2 pt;
+#endif
char spareData[spareSize];
if (write(outFile,data,chunkSize) != chunkSize)
@@ -200,32 +233,40 @@ 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 RTEMS_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 RTEMS_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)
{
@@ -331,6 +372,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 RTEMS_MKYAFFS2IMAGE
+ u8 remainder[remainderSize];
+#endif
int padPages = (nPages % pagesPerBlock);
if (padPages)
@@ -342,6 +386,12 @@ static void pad_image(void)
fatal("write");
}
}
+
+#ifdef RTEMS_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)
View
9 yaffs_packedtags2.c
@@ -97,10 +97,12 @@ void yaffs_pack_tags2(struct yaffs_packed_tags2 *pt,
{
yaffs_pack_tags2_tags_only(&pt->t, t);
+#ifndef RTEMS_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,
@@ -149,15 +151,20 @@ void yaffs_unpack_tags2(struct yaffs_ext_tags *t, struct yaffs_packed_tags2 *pt,
if (pt->t.seq_number != 0xffffffff && tags_ecc) {
/* Chunk is in use and we need to do ECC */
- struct yaffs_ecc_other ecc;
int result;
+
+#ifdef RTEMS_MKYAFFS2IMAGE
+ result = 0;
+#else
+ struct yaffs_ecc_other ecc;
yaffs_ecc_calc_other((unsigned char *)&pt->t,
sizeof(struct yaffs_packed_tags2_tags_only),
&ecc);
result =
yaffs_ecc_correct_other((unsigned char *)&pt->t,
sizeof(struct yaffs_packed_tags2_tags_only),
&pt->ecc, &ecc);
+#endif
switch (result) {
case 0:
ecc_result = YAFFS_ECC_RESULT_NO_ERROR;

5 comments on commit 4f5938a

@sbourdeauducq
M-Labs member

Can you move this somewhere else?

This repository is supposedly for generic code that will be hopefully merged upstream YAFFS - not for code that depends on a particular layout of the flash.

Thanks!

@sbourdeauducq
M-Labs member

You could use another branch, for example.

@xiangfu
M-Labs member
@sbourdeauducq
M-Labs member

Hmm... in fact, the tool already hardcodes NAND parameters:
// Adjust these to match your NAND LAYOUT:
#define chunkSize 2048
#define spareSize 64
#define pagesPerBlock 64

So, ok to leave this tool here, but name it nor-mkyaffs2image. The modifications have nothing to do with RTEMS, and everything to do with NOR layout.

@xiangfu
M-Labs member
Please sign in to comment.