* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
+ *
+ * Nick Bane modifications flagged NCB
+ *
*/
#include <stdlib.h>
#define MAX_OBJECTS 10000
+const char * mkyaffsimage_c_version = "$Id: mkyaffsimage.c,v 1.6 2002-12-13 00:13:06 charles Exp $";
+
// External functions for ECC on data
void nand_calculate_ecc (const u_char *dat, u_char *ecc_code);
int nand_correct_data (u_char *dat, u_char *read_ecc, u_char *calc_ecc);
-
-
-
typedef struct
{
dev_t dev;
static int error;
-int obj_compare(const void *a, const void * b)
+static int obj_compare(const void *a, const void * b)
{
objItem *oa, *ob;
}
-void add_obj_to_list(dev_t dev, ino_t ino, int obj)
+static void add_obj_to_list(dev_t dev, ino_t ino, int obj)
{
if(n_obj < MAX_OBJECTS)
{
}
-int find_obj_in_list(dev_t dev, ino_t ino)
+static int find_obj_in_list(dev_t dev, ino_t ino)
{
objItem *i = NULL;
objItem test;
-
+
test.dev = dev;
test.ino = ino;
return -1;
}
+// NCB added 10/9/2002
+static __u16 yaffs_CalcNameSum(const char *name)
+{
+ __u16 sum = 0;
+ __u16 i = 1;
+
+ __u8 *bname = (__u8 *)name;
+
+ while (*bname)
+ {
+ sum += (*bname) * i;
+ i++;
+ bname++;
+ }
+ return sum;
+}
-void yaffs_CalcECC(const __u8 *data, yaffs_Spare *spare)
+static void yaffs_CalcECC(const __u8 *data, yaffs_Spare *spare)
{
nand_calculate_ecc (data , spare->ecc1);
nand_calculate_ecc (&data[256] , spare->ecc2);
}
-void yaffs_CalcTagsECC(yaffs_Tags *tags)
+static void yaffs_CalcTagsECC(yaffs_Tags *tags)
{
// Todo don't do anything yet. Need to calculate ecc
unsigned char *b = ((yaffs_TagsUnion *)tags)->asBytes;
for(i = 0; i < 8; i++)
{
- for(j = 1; j &0x7f; j<<=1)
+// NCB modified 20-9-02 for(j = 1; j &0x7f; j<<=1)
+ for(j = 1; j &0xff; j<<=1)
{
bit++;
if(b[i] & j)
{
yaffs_TagsUnion *tu = (yaffs_TagsUnion *)tagsPtr;
- yaffs_CalcTagsECC(tagsPtr);
+ //yaffs_CalcTagsECC(tagsPtr);
sparePtr->tagByte0 = tu->asBytes[0];
sparePtr->tagByte1 = tu->asBytes[1];
-int write_chunk(__u8 *data, __u32 objId, __u32 chunkId, __u32 nBytes)
+static int write_chunk(__u8 *data, __u32 objId, __u32 chunkId, __u32 nBytes)
{
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;
}
-int write_object_header(int objId, yaffs_ObjectType t, struct stat *s, int parent, const char *name, int equivalentObj, const char * alias)
+static int write_object_header(int objId, yaffs_ObjectType t, struct stat *s, int parent, const char *name, int equivalentObj, const char * alias)
{
__u8 bytes[512];
strncpy(oh->name,name,YAFFS_MAX_NAME_LENGTH);
+
if(t != YAFFS_OBJECT_TYPE_HARDLINK)
{
oh->st_mode = s->st_mode;
oh->st_uid = s->st_uid;
- oh->st_gid = s->st_uid;
+// NCB 12/9/02 oh->st_gid = s->st_uid;
+ oh->st_gid = s->st_gid;
oh->st_atime = s->st_atime;
oh->st_mtime = s->st_mtime;
oh->st_ctime = s->st_ctime;
}
-int process_directory(int parent, const char *path)
+static int process_directory(int parent, const char *path)
{
DIR *dir;
struct dirent *entry;
- nDirectories++;
+ nDirectories++;
dir = opendir(path);
char symname[500];
- memset(symname,0,500);
+ memset(symname,0, sizeof(symname));
- readlink(full_name,symname,499);
+ readlink(full_name,symname,sizeof(symname) -1);
printf("symlink to \"%s\"\n",symname);
error = write_object_header(newObj, YAFFS_OBJECT_TYPE_SYMLINK, &stats, parent, entry->d_name, -1, symname);
{
printf("directory\n");
error = write_object_header(newObj, YAFFS_OBJECT_TYPE_DIRECTORY, &stats, parent, entry->d_name, -1, NULL);
- process_directory(1,full_name);
+// NCB modified 10/9/2001 process_directory(1,full_name);
+ process_directory(newObj,full_name);
}
}
}
{
printf("usage: mkyaffsimage dir image_file\n");
printf(" dir the directory tree to be converted\n");
- printf(" image_file the ouput file to hold the image\n");
+ printf(" image_file the output file to hold the image\n");
exit(1);
}
}
printf("Processing directory %s into image file %s\n",argv[1],argv[2]);
-
+ error = write_object_header(1, YAFFS_OBJECT_TYPE_DIRECTORY, &stats, 1,"", -1, NULL);
+ if(error)
error = process_directory(YAFFS_OBJECTID_ROOT,argv[1]);
close(outFile);