diff options
Diffstat (limited to 'romfs/tools')
-rw-r--r-- | romfs/tools/Makefile | 14 | ||||
-rw-r--r-- | romfs/tools/build_ffs.c | 688 | ||||
-rw-r--r-- | romfs/tools/cfg_parse.c | 128 | ||||
-rw-r--r-- | romfs/tools/cfgparse.h | 39 | ||||
-rw-r--r-- | romfs/tools/create_crc.c | 686 | ||||
-rw-r--r-- | romfs/tools/create_flash.c | 146 | ||||
-rw-r--r-- | romfs/tools/createcrc.h | 5 |
7 files changed, 944 insertions, 762 deletions
diff --git a/romfs/tools/Makefile b/romfs/tools/Makefile index dcdba83..8f399a8 100644 --- a/romfs/tools/Makefile +++ b/romfs/tools/Makefile @@ -1,5 +1,5 @@ # ***************************************************************************** -# * Copyright (c) 2004, 2007 IBM Corporation +# * Copyright (c) 2004, 2008 IBM Corporation # * All rights reserved. # * This program and the accompanying materials # * are made available under the terms of the BSD License @@ -10,6 +10,11 @@ # * IBM Corporation - initial implementation # ****************************************************************************/ +# FIXME review -I ... +# export NEW_BUILD=1 + +TOPCMNDIR ?= ../.. +INCLCMNDIR ?= ../../include include $(TOPCMNDIR)/make.rules @@ -20,9 +25,14 @@ CFLAGS += $(FLAG) SRCS = build_ffs.c cfg_parse.c create_flash.c create_crc.c OBJS = $(SRCS:%.c=%.o) +all: build_romfs + build_romfs: $(OBJS) $(HOSTCC) $(HOSTCFLAGS) $(FLAG) -o $@ $^ +testing: build_romfs + make -C test + %.o: %.c $(HOSTCC) $(CPPFLAGS) $(HOSTCFLAGS) $(FLAG) -c $< -o $@ @@ -39,7 +49,7 @@ depend: $(MAKE) Makefile.dep Makefile.dep: Makefile - $(HOSTCC) -MM $(CPPFLAGS) $(CFLAGS) $(SRCS) > Makefile.dep + $(HOSTCC) -MM $(CPPFLAGS) $(HOSTCFLAGS) $(SRCS) > Makefile.dep # Include dependency file if available: -include Makefile.dep diff --git a/romfs/tools/build_ffs.c b/romfs/tools/build_ffs.c index 1374123..d00fecb 100644 --- a/romfs/tools/build_ffs.c +++ b/romfs/tools/build_ffs.c @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright (c) 2004, 2007 IBM Corporation + * Copyright (c) 2004, 2008 IBM Corporation * All rights reserved. * This program and the accompanying materials * are made available under the terms of the BSD License @@ -15,7 +15,6 @@ #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> -#include <netinet/in.h> #include <fcntl.h> #include <string.h> #include <unistd.h> @@ -25,346 +24,453 @@ #define FFS_TARGET_HEADER_SIZE (4 * 8) -/* put this somewhere else */ -#define FLAG_LLFW 1 +extern int verbose; -unsigned int glob_rom_pos = 0; -unsigned int glob_num_files = 0; +#define pad8_num(x) (((x) + 7) & ~7) -typedef struct { - uint32_t high; - uint32_t low; -} uint64s_t; +static int +file_exist(const char *name, int errdisp) +{ + struct stat fileinfo; + + memset((void *) &fileinfo, 0, sizeof(struct stat)); + if (stat(name, &fileinfo) != 0) { + if (0 != errdisp) { + perror(name); + } + return 0; + } + if (S_ISREG(fileinfo.st_mode)) { + return 1; + } + return 0; +} + +static int +file_getsize(const char *name) +{ + int rc; + struct stat fi; + + rc = stat(name, &fi); + if (rc != 0) + return -1; + return fi.st_size; +} + +static int +ffshdr_compare(const void *_a, const void *_b) +{ + const struct ffs_header_t *a = *(struct ffs_header_t * const *) _a; + const struct ffs_header_t *b = *(struct ffs_header_t * const *) _b; + + if (a->romaddr == b->romaddr) + return 0; + if (a->romaddr > b->romaddr) + return 1; + return -1; +} + +static void +hdr_print(struct ffs_header_t *hdr) +{ + printf("hdr: %p\n", hdr); + printf("\taddr: %08llx token: %s\n" + "\tflags: %08llx romaddr: %08llx image_len: %08x\n" + "\tsave_len: %08llx ffsize: %08x hdrsize: %08x\n" + "\ttokensize: %08x\n", + hdr->addr, hdr->token, hdr->flags, hdr->romaddr, + hdr->imagefile_length, hdr->save_data_len, + hdr->ffsize, hdr->hdrsize, hdr->tokensize); +} + +int +reorder_ffs_chain(struct ffs_chain_t *fs) +{ + int i, j; + int free_space; + unsigned long long addr; + struct ffs_header_t *hdr; + int fix, flx, res, tab_size = fs->count; + struct ffs_header_t *fix_tab[tab_size]; /* fixed offset */ + struct ffs_header_t *flx_tab[tab_size]; /* flexible offset */ + struct ffs_header_t *res_tab[tab_size]; /* result */ + + /* determine size data to be able to do the reordering */ + for (hdr = fs->first; hdr; hdr = hdr->next) { + if (hdr->linked_to) + hdr->imagefile_length = 0; + else + hdr->imagefile_length = file_getsize(hdr->imagefile); + if (hdr->imagefile_length == -1) + return -1; + + hdr->tokensize = pad8_num(strlen(hdr->token) + 1); + hdr->hdrsize = FFS_TARGET_HEADER_SIZE + hdr->tokensize; + hdr->ffsize = + hdr->hdrsize + pad8_num(hdr->imagefile_length) + 8; + } + + memset(res_tab, 0, tab_size * sizeof(struct ffs_header_t *)); + memset(fix_tab, 0, tab_size * sizeof(struct ffs_header_t *)); + memset(flx_tab, 0, tab_size * sizeof(struct ffs_header_t *)); + + /* now start with entries having fixed offs, reorder if needed */ + for (fix = 0, flx = 0, hdr = fs->first; hdr; hdr = hdr->next) + if (needs_fix_offset(hdr)) + fix_tab[fix++] = hdr; + else + flx_tab[flx++] = hdr; + qsort(fix_tab, fix, sizeof(struct ffs_header_t *), ffshdr_compare); + + /* + * for fixed files we need to also remove the hdrsize from the + * free space because it placed in front of the romaddr + */ + for (addr = 0, res = 0, i = 0, j = 0; i < fix; i++) { + fix_tab[i]->addr = fix_tab[i]->romaddr - fix_tab[i]->hdrsize; + free_space = fix_tab[i]->addr - addr; + + /* insert as many flexible files as possible */ + for (; free_space > 0 && j < flx; j++) { + if (flx_tab[j]->ffsize <= free_space) { /* fits */ + flx_tab[j]->addr = addr; + free_space -= flx_tab[j]->ffsize; + addr += flx_tab[j]->ffsize; + res_tab[res++] = flx_tab[j]; + } else + break; + } + res_tab[res++] = fix_tab[i]; + addr = fix_tab[i]->romaddr + fix_tab[i]->ffsize - + fix_tab[i]->hdrsize; + } + /* at the end fill up the table with remaining flx entries */ + for (; j < flx; j++) { + flx_tab[j]->addr = addr; + addr += flx_tab[j]->ffsize; + res_tab[res++] = flx_tab[j]; + } + + if (verbose) { + printf("--- resulting order ---\n"); + for (i = 0; i < tab_size; i++) + hdr_print(res_tab[i]); + } -int file_exist(char *, int); -/* change done 2005-March-09 */ -int write_to_file(int fd, unsigned char *buf, int size); -/* by Rolf Schaefer */ + /* to check if the requested romfs images is greater than + * the specified romfs_size it is necessary to add 8 for + * the CRC to the totalsize */ + addr += 8; -#define pad8_num(x) ((x) + (-(x) & 7)) + /* sanity checking if user specified maximum romfs size */ + if ((fs->romfs_size != 0) && addr > fs->romfs_size) { + fprintf(stderr, "[build_romfs] romfs_size specified as %d " + "bytes, but %lld bytes need to be written.\n", + fs->romfs_size, addr); + return 1; + } + + /* resort result list */ + for (i = 0; i < tab_size - 1; i++) + res_tab[i]->next = res_tab[i + 1]; + res_tab[i]->next = NULL; + fs->first = res_tab[0]; + return 0; +} + +/** + * allocate memory for a romfs file including header + */ +static unsigned char * +malloc_file(int hdrsz, int datasz, int *ffsz) +{ + void *tmp; + + /* complete file size is: + * header + 8byte aligned(data) + end of file marker (-1) */ + *ffsz = hdrsz + pad8_num(datasz) + 8; + /* get the mem */ + tmp = malloc(*ffsz); + + if (!tmp) + return NULL; + + memset(tmp, 0, *ffsz); + + return (unsigned char *) tmp; +} + +static int +copy_file(struct ffs_header_t *hdr, unsigned char *ffile, int datasize, + int ffile_offset, int ffsize) +{ + int cnt = 0; + int imgfd; + int i; + + if (!file_exist(hdr->imagefile, 1)) { + printf("access error to file: %s\n", hdr->imagefile); + free(ffile); + return -1; + } + + imgfd = open(hdr->imagefile, O_RDONLY); + if (0 >= imgfd) { + perror(hdr->imagefile); + free(ffile); + return -1; + } + + /* now copy file to file buffer */ + /* FIXME using fread might be a good idea so + that we do not need to deal with shortened + reads/writes. Also error handling looks + broken to me. Are we sure that all data is + read when exiting this loop? */ + while (1) { + i = read(imgfd, ffile + ffile_offset, ffsize - ffile_offset); + if (i <= 0) + break; + ffile_offset += i; + cnt += i; + } + + /* sanity check */ + if (cnt != datasize) { + printf("BUG!!! copy error on image file [%s](e%d, g%d)\n", + hdr->imagefile, datasize, cnt); + close(imgfd); + free(ffile); + return -1; + } + + close(imgfd); + + return cnt; +} + +static uint64_t +next_file_offset(struct ffs_header_t *hdr, int rom_pos, int ffsize) +{ + uint64_t tmp; + + /* no next file; end of filesystem */ + if (hdr->next == NULL) + return 0; + + if (hdr->next->romaddr > 0) { + /* the next file does not follow directly after the + * current file because it requested to be + * placed at a special address; + * we need to calculate the offset of the + * next file; + * the next file starts at hdr->next->romaddr which + * is the address requested by the user */ + tmp = hdr->next->romaddr; + /* the next file starts, however, a bit earlier; + * we need to point at the header of the next file; + * therefore it is necessary to subtract the header size + * of the _next_ file */ + tmp -= FFS_TARGET_HEADER_SIZE; + /* also remove the length of the filename of the _next_ + * file */ + tmp -= pad8_num(strlen(hdr->next->token) + 1); + /* and it needs to be relative to the current file */ + tmp -= rom_pos; + return tmp; + } + + /* if no special treatment is required the next file just + * follows after the current file; + * therefore just return the complete filesize as offset */ + return ffsize; +} -int build_ffs(struct ffs_chain_t *fs, char *outfile) +static int +next_file_address(struct ffs_header_t *hdr, unsigned int rom_pos, int hdrsize, + unsigned int num_files) { - int ofdCRC; /* change done 2005-April-07 by Rolf Schaefer */ - int ofd, ffsize, datasize, imgfd, i, cnt; + /* check if file wants a specific address */ + void *tmp; + + if ((hdr->flags & FLAG_LLFW) == 0) + /* flag to get a specific address has been set */ + return rom_pos; + + if (hdr->romaddr == 0) + /* if the requested address is 0 then + * something is not right; ignore the flag */ + return rom_pos; + + /* check if romaddress is below current position */ + if (hdr->romaddr < (rom_pos + hdrsize)) { + printf("[%s] ERROR: requested impossible " "romaddr of %llx\n", + hdr->token, hdr->romaddr); + return -1; + } + + /* spin offset to new positon */ + if (pad8_num(hdr->romaddr) != hdr->romaddr) { + printf("BUG!!!! pad8_num(hdr->romaddr) != hdr->romaddr\n"); + return -1; + } + + tmp = malloc(hdr->romaddr - rom_pos - hdrsize); + + if (!tmp) + return -1; + + memset(tmp, 0, hdr->romaddr - rom_pos - hdrsize); + if (buildDataStream(tmp, hdr->romaddr - rom_pos - hdrsize)) { + free(tmp); + printf("write failed\n"); + return -1; + } + + free(tmp); + + if (!num_files) + printf("\nWARNING: The filesystem will have no entry header!\n" + " It is still usable but you need to find\n" + " the FS by yourself in the image.\n\n"); + + return hdr->romaddr - hdrsize; +} + +int +build_ffs(struct ffs_chain_t *fs, const char *outfile, int notime) +{ + int ofdCRC; + int ffsize, datasize, i; int tokensize, hdrsize, ffile_offset, hdrbegin; struct ffs_header_t *hdr; - unsigned char *ffile, c; - struct stat fileinfo; - uint64s_t val64; + unsigned char *ffile; + unsigned int rom_pos = 0; + unsigned int num_files = 0; + uint64_t tmp; if (NULL == fs->first) { return 1; } hdr = fs->first; - + /* check output file and open it for creation */ if (file_exist(outfile, 0)) { - printf("Output file (%s) will be overwritten\n", - outfile); + printf("Output file (%s) will be overwritten\n", outfile); } - ofd = open(".crc_flash", O_CREAT | O_WRONLY | O_TRUNC, 0666); - ofdCRC = open(outfile, O_CREAT | O_WRONLY | O_TRUNC, 0666); /* change done 2005-April-07 by Rolf Schaefer */ - if (0 > ofd || 0 > ofdCRC) { - perror(outfile); - return 1; - } + while (hdr) { - while (1) { - /* - * first estimate the size of the file including header - * to allocate the memory in advance. - */ - if (NULL == hdr->linked_to) { - memset((void*)&fileinfo, 0, sizeof(struct stat)); - if (stat(hdr->imagefile, &fileinfo) != 0) { - perror(hdr->imagefile); - return 1; - } - datasize = fileinfo.st_size; - } else { - datasize = 0; + if (hdr->linked_to) { + printf("\nBUG!!! links not supported anymore\n"); + return 1; } - ffile_offset = 0, - tokensize = pad8_num(strlen(hdr->token) + 1 /* ens trl 0 */); - hdrsize = FFS_TARGET_HEADER_SIZE + tokensize; - ffsize = hdrsize + pad8_num(datasize) + 8 /* -1 */; - /* get the mem */ - ffile = (unsigned char*) malloc(ffsize); + /* add +1 to strlen for zero termination */ + tokensize = pad8_num(strlen(hdr->token) + 1); + hdrsize = FFS_TARGET_HEADER_SIZE + tokensize; + datasize = file_getsize(hdr->imagefile); + + if (datasize == -1) { + perror(hdr->imagefile); + return 1; + } + + ffile_offset = 0; + ffile = malloc_file(hdrsize, datasize, &ffsize); + if (NULL == ffile) { perror("alloc mem for ffile"); return 1; } - memset((void*)ffile, 0 , ffsize); /* check if file wants a specific address */ - if ((hdr->romaddr > 0) || (0 != (hdr->flags & FLAG_LLFW))) { - /* check if romaddress is below current position */ - if (hdr->romaddr < (glob_rom_pos + hdrsize)) { - printf("[%s] ERROR: requested impossible " - "romaddr of %llx\n", - hdr->token, hdr->romaddr); - close(ofd); - free(ffile); - return 1; - } - - /* spin offset to new positon */ - if (pad8_num(hdr->romaddr) != hdr->romaddr) { - printf("BUG!!!! pad8_num(hdr->romaddr) != hdr->romaddr\n"); - close(ofd); - free(ffile); - return 1; - } - i = hdr->romaddr - glob_rom_pos - hdrsize; - while (0 < i) { - c = 0; -/* change done 09.03.2005 */ - if (0 != write_to_file(ofd, &c, 1)) { -/* by Rolf Schaefer */ - printf("write failed\n"); - close(ofd); - free(ffile); - } - glob_rom_pos++; - i--; - } - if (glob_rom_pos != (hdr->romaddr - hdrsize)) { - printf("BUG!!! hdr->romaddr != glob_rom_pos (%llx, %x)\n", - hdr->romaddr, glob_rom_pos); - } - if (0 == glob_num_files) { - printf("\nWARNING: The filesystem will have no " - "entry header !\n" - " It is still usable but you need " - "to find\n" - " the FS by yourself in the image.\n\n"); - } - } - hdrbegin = glob_rom_pos; - ///printf("OFFS=%6x FSIZE=%6d ", glob_rom_pos, ffsize); - - /* write header ********************************************/ - /* next addr ***********************************************/ - val64.high= 0; - val64.low = 0; - //printf("\n\n\nFFS_TARGET_HEADER_SIZE = %d\n", FFS_TARGET_HEADER_SIZE); - //printf( "FFS_TARGET_HEADER_SIZE = 0x%x\n", FFS_TARGET_HEADER_SIZE); - //printf( "glob_rom_pos = 0x%x\n", glob_rom_pos); - //printf( "ffsize = %d\n", ffsize); - //printf( "ffsize = 0x%x\n", ffsize); - - if (NULL != hdr->next) { - //printf( "next-romaddr = 0x%lx\n", hdr->next->romaddr); - //printf( "strlen(hdr->next->token= %d\n", pad8_num(strlen(hdr->next->token))); - //printf( "strlen(hdr->next->token= 0x%d\n", pad8_num(strlen(hdr->next->token))); - if (hdr->next->romaddr > 0) { - /* FIXME this is quite ugly, any other idea? */ - val64.low = hdr->next->romaddr - - (FFS_TARGET_HEADER_SIZE + - pad8_num(strlen(hdr->next->token))); - val64.low -= glob_rom_pos; - val64.low = htonl(val64.low); - } - //printf( "val64.low = 0x%lx\n", val64.low); - - if (0 == val64.low) { - //next address relative to rombase - //val64.low = htonl(glob_rom_pos + ffsize); - // - //changed next pointer to be relative - //to current fileposition; needed to glue - //different romfs-volumes together - val64.low = htonl(ffsize); - } - } - //printf("\n\n\n"); - - memcpy(ffile + ffile_offset, &val64, 8); - glob_rom_pos += 8; - ffile_offset += 8; + rom_pos = next_file_address(hdr, rom_pos, hdrsize, num_files); + hdrbegin = rom_pos; - /* length **************************************************/ - if (NULL == hdr->linked_to) { - val64.low = htonl(datasize); - hdr->save_data_len = datasize; - } else { - printf("\nBUG!!! links not supported anymore\n"); - close(ofd); + if (hdrbegin == -1) { + /* something went wrong */ free(ffile); return 1; - - /* - if (0 == hdr->linked_to->save_data_valid) { - printf("ERROR: this version does not support" - "forward references in links\n"); - close(ofd); - free(ffile); - return 1; - } - val64.low = htonl(hdr->linked_to->save_data_len); - */ } - memcpy(ffile + ffile_offset, &val64, 8); - glob_rom_pos += 8; + + /* write header ******************************************* */ + /* next addr ********************************************** */ + tmp = next_file_offset(hdr, rom_pos, ffsize); + + *(uint64_t *) (ffile + ffile_offset) = cpu_to_be64(tmp); + rom_pos += 8; ffile_offset += 8; - /* flags ***************************************************/ - val64.low = htonl(hdr->flags); - memcpy(ffile + ffile_offset, &val64, 8); - glob_rom_pos += 8; + /* length ************************************************* */ + hdr->save_data_len = datasize; + + *(uint64_t *) (ffile + ffile_offset) = cpu_to_be64(datasize); + rom_pos += 8; ffile_offset += 8; - /* datapointer *********************************************/ - if (NULL == hdr->linked_to) { - //save-data pointer is relative to rombase - hdr->save_data = hdrbegin + hdrsize; - hdr->save_data_valid = 1; - //pointer relative to rombase: - //val64.low = htonl(hdr->save_data); - // - //changed pointers to be relative to file: - val64.low = htonl(hdr->save_data - hdrbegin); - } else { - printf("\nBUG!!! links not supported anymore\n"); - close(ofd); - free(ffile); - return 1; + /* flags ************************************************** */ + *(uint64_t *) (ffile + ffile_offset) = cpu_to_be64(hdr->flags); + rom_pos += 8; + ffile_offset += 8; - /* - if (0 == hdr->linked_to->save_data_valid) { - printf("ERROR: this version does not support" - "forward references in links\n"); - close(ofd); - free(ffile); - return 1; - } - val64.low = htonl(hdr->linked_to->save_data); - */ - } - memcpy(ffile + ffile_offset, &val64, 8); - glob_rom_pos += 8; + /* datapointer ******************************************** */ + + //save-data pointer is relative to rombase + hdr->save_data = hdrbegin + hdrsize; + hdr->save_data_valid = 1; + //changed pointers to be relative to file: + tmp = hdr->save_data - hdrbegin; + + *(uint64_t *) (ffile + ffile_offset) = cpu_to_be64(tmp); + rom_pos += 8; ffile_offset += 8; - /* name (token) ********************************************/ + /* name (token) ******************************************* */ memset(ffile + ffile_offset, 0, tokensize); - strcpy((char *)ffile + ffile_offset, hdr->token); - glob_rom_pos += tokensize; + strcpy((char *) ffile + ffile_offset, hdr->token); + rom_pos += tokensize; ffile_offset += tokensize; - /* image file **********************************************/ - if (NULL == hdr->linked_to) { - if (! file_exist(hdr->imagefile, 1)) { - printf("access error to file: %s\n", hdr->imagefile); - close(ofd); - free(ffile); - return 1; - } - - imgfd = open(hdr->imagefile, O_RDONLY); - if (0 >= imgfd) { - perror(hdr->imagefile); - close(ofd); - free(ffile); - return 1; - } - - /* now copy file to file buffer */ - cnt = 0; - while (1) { - i = read(imgfd, ffile + ffile_offset, ffsize-ffile_offset); - if (i <= 0) break; - glob_rom_pos += i; - ffile_offset += i; - cnt += i; - } - - /* pad file */ - glob_rom_pos += pad8_num(datasize) - datasize; - ffile_offset += pad8_num(datasize) - datasize; - - /* sanity check */ - if (cnt != datasize) { - printf("BUG!!! copy error on image file [%s](e%d, g%d)\n", - hdr->imagefile, datasize, cnt); - close(imgfd); - close(ofd); - free(ffile); - return 1; - } - close(imgfd); - } + /* image file ********************************************* */ + i = copy_file(hdr, ffile, datasize, ffile_offset, ffsize); + + if (i == -1) + return 1; - /* limiter *************************************************/ - val64.low = -1; - val64.high = -1; - memcpy(ffile + ffile_offset, &val64, 8); - glob_rom_pos += 8; + /* pad file */ + rom_pos += i + pad8_num(datasize) - datasize; + ffile_offset += i + pad8_num(datasize) - datasize; + + /* limiter ************************************************ */ + *(uint64_t *) (ffile + ffile_offset) = -1; + rom_pos += 8; ffile_offset += 8; - /* *********************************************************/ - ///printf("FLEN=%6d TOK=%-11s FILE=%s\n", - /// ffsize, - /// hdr->token, - /// hdr->imagefile); -/* change done 9.3.2005*/ - if (write_to_file(ofd, ffile, ffsize) != 0) { - printf("Failed while processing file '%s' (size = %d bytes)\n", - hdr->imagefile, datasize); + if (buildDataStream(ffile, ffsize) != 0) { + printf + ("Failed while processing file '%s' (size = %d bytes)\n", + hdr->imagefile, datasize); return 1; } -/* by Rolf Schaefer */ free(ffile); hdr = hdr->next; - glob_num_files++; - - if (NULL == hdr) break; + num_files++; } -/* change done 09.03.2005 */ - writeDataStream(ofdCRC); -/* by Rolf Schaefer */ - close(ofd); - close(ofdCRC); - - return 0; -} - -int file_exist(char *name, int errdisp) -{ - struct stat fileinfo; - memset((void*)&fileinfo, 0, sizeof(struct stat)); - if (stat(name, &fileinfo) != 0) { - if (0 != errdisp) { - perror(name); - } - return 0; - } - if (S_ISREG(fileinfo.st_mode)) { + /* + * FIXME Current limination seems to be about 4MiB. + */ + ofdCRC = open(outfile, O_CREAT | O_WRONLY | O_TRUNC, 0666); + if (0 > ofdCRC) { + perror(outfile); return 1; } - return 0; -} - -/* changes done 2005_March-09 */ -int write_to_file(int fd, unsigned char *buf, int size) -{ - int i; - - if (buildDataStream(buf, size) != 0) - return -1; - - for ( ; size; size -= i, buf += i) { - i = write(fd, buf, size); - if (i < 0) { - perror("write to image"); - return 1; - } - } - -/*by Rolf Schaefer */ + i = writeDataStream(ofdCRC, notime); + close(ofdCRC); + if (i) + return 1; return 0; } diff --git a/romfs/tools/cfg_parse.c b/romfs/tools/cfg_parse.c index da4d75b..5137fbe 100644 --- a/romfs/tools/cfg_parse.c +++ b/romfs/tools/cfg_parse.c @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright (c) 2004, 2007 IBM Corporation + * Copyright (c) 2004, 2008 IBM Corporation * All rights reserved. * This program and the accompanying materials * are made available under the terms of the BSD License @@ -19,28 +19,32 @@ #include <cfgparse.h> -int glob_come_from_cr = 0; +static int inbetween_white(char *s, int max, char **start, char **end, + char **next); +static int add_header(struct ffs_chain_t *, struct ffs_header_t *); -int find_next_entry(int file, struct ffs_chain_t *chain) +static int glob_come_from_cr = 0; + +static int +find_next_entry(int file, struct ffs_chain_t *chain) { #define MAX_LINE_SIZE 1024 - char lnbuf[MAX_LINE_SIZE], b0=0, b1=0; + char lnbuf[MAX_LINE_SIZE], b0 = 0, b1 = 0; char *start, *end, *next; - struct ffs_header_t *hdr; //, *hdr2; + struct ffs_header_t *hdr; //, *hdr2; int lc, rc; char c; - + /* search for new config line */ if (0 == glob_come_from_cr) { while (1 == (rc = read(file, &c, 1))) { //printf("b0=%c b1=%c c=%c\n", - // b0, b1, c); + // b0, b1, c); b0 = b1; b1 = c; /* this looks for starting sign "<CR>[^#]" */ - if ( ((0x0a == b0) || (0x0d == b0)) && - (('#' != b1) && (0x0a != b1) && - (0x0d != b1))) { + if (((0x0a == b0) || (0x0d == b0)) && + (('#' != b1) && (0x0a != b1) && (0x0d != b1))) { break; } } @@ -60,7 +64,7 @@ int find_next_entry(int file, struct ffs_chain_t *chain) } /* now buffer it until end of line */ - memset((void*) lnbuf, 0, MAX_LINE_SIZE); + memset((void *) lnbuf, 0, MAX_LINE_SIZE); lnbuf[0] = c; lc = 1; while ((1 == read(file, &(lnbuf[lc]), 1)) && (lc < MAX_LINE_SIZE)) { @@ -79,7 +83,7 @@ int find_next_entry(int file, struct ffs_chain_t *chain) perror("alloc memory"); return 2; } - memset((void*)hdr, 0, sizeof(struct ffs_header_t)); + memset((void *) hdr, 0, sizeof(struct ffs_header_t)); /* attach header to chain */ if (0 != add_header(chain, hdr)) { @@ -127,19 +131,20 @@ int find_next_entry(int file, struct ffs_chain_t *chain) /* check if entry is linked to another header */ if (':' == *start) { - printf("\nERROR: links are removed as feature in this version\n"); + printf + ("\nERROR: links are removed as feature in this version\n"); return 2; /* - start++; - if (0 != find_entry_by_token(chain, hdr->imagefile+1, &hdr2)) { - printf("[%s]: link to [%s] not found\n", - hdr->token, hdr->imagefile+1); - dump_fs_contents(chain); - return 2; - } - hdr->linked_to = hdr2; - */ + start++; + if (0 != find_entry_by_token(chain, hdr->imagefile+1, &hdr2)) { + printf("[%s]: link to [%s] not found\n", + hdr->token, hdr->imagefile+1); + dump_fs_contents(chain); + return 2; + } + hdr->linked_to = hdr2; + */ } /**********************************************************/ @@ -175,21 +180,27 @@ int find_next_entry(int file, struct ffs_chain_t *chain) return 0; } -void debug_print_range(char *s, char *e) +int +read_config(int conf_file, struct ffs_chain_t *ffs_chain) { - while (s < e) { - printf("%c", *s); - s++; + int rc; + + while (1) { + rc = find_next_entry(conf_file, ffs_chain); + if (rc != 0) + break; } + return rc; } -int inbetween_white(char *s, int max, char **start, char **end, char **next) +static int +inbetween_white(char *s, int max, char **start, char **end, char **next) { int pos = 0, posalt; if (NULL != *start) { pos = *start - s; - s = *start; + s = *start; } /* wind to first non white */ @@ -212,7 +223,7 @@ int inbetween_white(char *s, int max, char **start, char **end, char **next) /* wind to end of non white or end of buffer */ posalt = pos; while (pos < max) { - if ((' ' == *s) || (' ' == *s) || + if ((' ' == *s) || (' ' == *s) || (0x0a == *s) || (0x0d == *s)) { break; } @@ -235,11 +246,13 @@ int inbetween_white(char *s, int max, char **start, char **end, char **next) return 0; } -int add_header(struct ffs_chain_t *chain, struct ffs_header_t *hdr) +int +add_header(struct ffs_chain_t *chain, struct ffs_header_t *hdr) { struct ffs_header_t *next; if (NULL == chain->first) { + chain->count = 1; chain->first = hdr; return 0; } @@ -250,40 +263,13 @@ int add_header(struct ffs_chain_t *chain, struct ffs_header_t *hdr) next = next->next; } next->next = hdr; + chain->count++; return 0; } -int find_entry_by_token(struct ffs_chain_t *chain, char *token, - struct ffs_header_t **hdr) -{ - struct ffs_header_t *next; - - if (NULL == chain->first) { - *hdr = NULL; - return 1; - } - next = chain->first; - - //printf("debug: search for [%s]...\n", token); - - while (1) { - //printf(" > [%s]\n", next->token); - if (strcmp(token, next->token) == 0) { - *hdr = next; - //printf(" > found\n"); - break; - } - if (NULL == next->next) { - //printf(" > reached end of chain, not found\n"); - return 1; - } - next = next->next; - } - return 0; -} - -void dump_fs_contents(struct ffs_chain_t *chain) +void +dump_fs_contents(struct ffs_chain_t *chain) { struct ffs_header_t *next; @@ -308,11 +294,11 @@ void dump_fs_contents(struct ffs_chain_t *chain) printf("flags<%llx>, ", next->flags); printf("romaddr<%llx>, ", next->romaddr); - + if (NULL != next->linked_to) { printf("linked to [%s]", next->linked_to->token); } - + printf("\n"); if (NULL == next->next) { break; @@ -320,10 +306,11 @@ void dump_fs_contents(struct ffs_chain_t *chain) next = next->next; } - + } -void free_chain_memory(struct ffs_chain_t *chain) +void +free_chain_memory(struct ffs_chain_t *chain) { struct ffs_header_t *hdr, *next_hdr; @@ -353,7 +340,8 @@ void free_chain_memory(struct ffs_chain_t *chain) /* * Detect duplicate entries in the romfs list */ -void find_duplicates(struct ffs_chain_t *chain) +void +find_duplicates(struct ffs_chain_t *chain) { struct ffs_header_t *act, *sub; @@ -366,12 +354,12 @@ void find_duplicates(struct ffs_chain_t *chain) do { sub = act->next; while (sub != NULL) { - + if (act->token == NULL || sub->token == NULL) { printf("find_duplicates: token not set!\n"); - } - else if (strcmp(act->token, sub->token) == 0) { - printf("*** NOTE: duplicate romfs file '%s'.\n", act->token); + } else if (strcmp(act->token, sub->token) == 0) { + printf("*** NOTE: duplicate romfs file '%s'.\n", + act->token); } sub = sub->next; } @@ -379,5 +367,5 @@ void find_duplicates(struct ffs_chain_t *chain) act = act->next; } while (act != NULL); - + } diff --git a/romfs/tools/cfgparse.h b/romfs/tools/cfgparse.h index 7ccf9b7..ed5c885 100644 --- a/romfs/tools/cfgparse.h +++ b/romfs/tools/cfgparse.h @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright (c) 2004, 2007 IBM Corporation + * Copyright (c) 2004, 2008 IBM Corporation * All rights reserved. * This program and the accompanying materials * are made available under the terms of the BSD License @@ -12,31 +12,48 @@ #ifndef CFGPARSE_H #define CFGPARSE_H +#include <byteswap.h> +#include <endian.h> + +#if __BYTE_ORDER == __BIG_ENDIAN +#define cpu_to_be64(x) (x) +#else +#define cpu_to_be64(x) bswap_64(x) +#endif + struct ffs_chain_t { + int count; + unsigned int romfs_size; struct ffs_header_t *first; }; +#define FLAG_LLFW 1 /* low level firmware at fix offs in romfs */ + +#define needs_fix_offset(hdr) ((hdr)->flags & FLAG_LLFW) + struct ffs_header_t { unsigned long long flags; unsigned long long romaddr; - char *token; - char *imagefile; - int imagefile_length; + char *token; + char *imagefile; + int imagefile_length; struct ffs_header_t *linked_to; struct ffs_header_t *next; unsigned long long save_data; unsigned long long save_data_len; int save_data_valid; + + unsigned long long addr; /* tmp */ + int hdrsize; /* tmp */ + int tokensize; /* tmp */ + int ffsize; /* tmp */ }; -int find_next_entry(int file, struct ffs_chain_t *chain); -int inbetween_white(char *s, int max, char **start, char **end, char **next); -void debug_print_range(char *s, char *e); -void free_chain_memory(struct ffs_chain_t *chain); -int add_header(struct ffs_chain_t *, struct ffs_header_t *); -int find_entry_by_token(struct ffs_chain_t *, char *, struct ffs_header_t **); void dump_fs_contents(struct ffs_chain_t *chain); void find_duplicates(struct ffs_chain_t *chain); +void free_chain_memory(struct ffs_chain_t *chain); -int build_ffs(struct ffs_chain_t *fs, char *outfile); +int read_config(int conf_file, struct ffs_chain_t *ffs_chain); +int reorder_ffs_chain(struct ffs_chain_t *fs); +int build_ffs(struct ffs_chain_t *fs, const char *outfile, int notime); #endif diff --git a/romfs/tools/create_crc.c b/romfs/tools/create_crc.c index 2db79b7..38235e5 100644 --- a/romfs/tools/create_crc.c +++ b/romfs/tools/create_crc.c @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright (c) 2004, 2007 IBM Corporation + * Copyright (c) 2004, 2008 IBM Corporation * All rights reserved. * This program and the accompanying materials * are made available under the terms of the BSD License @@ -24,460 +24,444 @@ #include <time.h> #include <calculatecrc.h> #include <product.h> -#include <byteswap.h> -#include <endian.h> - -int createHeaderImage(void); -unsigned int calCRCEthernet32(unsigned char *TextPtr, unsigned long int TextLength, unsigned int AccumCRC); -int createCRCParameter(uint64_t *ui64RegisterMask, unsigned int *iRegisterLength); -uint64_t calCRCbyte(unsigned char *TextPtr, uint32_t Residual, uint64_t AccumCRC); -uint64_t calCRCword(unsigned char *TextPtr, uint32_t Residual, uint64_t AccumCRC); +#include "createcrc.h" + +int createHeaderImage(int); +unsigned int calCRCEthernet32(unsigned char *TextPtr, + unsigned long int TextLength, + unsigned int AccumCRC); +int createCRCParameter(uint64_t * ui64RegisterMask, + unsigned int *iRegisterLength); +uint64_t calCRCbyte(unsigned char *TextPtr, uint32_t Residual, + uint64_t AccumCRC); +uint64_t calCRCword(unsigned char *TextPtr, uint32_t Residual, + uint64_t AccumCRC); uint64_t checkCRC(unsigned char *TextPtr, uint32_t Residual, uint64_t AccumCRC); -int insert64bit(uint64_t ui64CRC, uint32_t uliPosition); -static uint64_t ui64globalFileSize=0; // file length in bytes -static unsigned char pucFileStream[4400000]; // space for the file stream >= 4MB + 4bytes -static uint64_t ui64globalHeaderSize=0; // header length in bytes -static int iglobalHeaderFlag = 1; // flag to filter detect the header in buildDataStream() +/* file length in bytes */ +static uint64_t ui64globalFileSize = 0; +/* space for the file stream >= 4MB + 4bytes */ +static unsigned char pucFileStream[4400000]; +/* header length in bytes */ +static uint64_t ui64globalHeaderSize = 0; +/* flag to filter detect the header in buildDataStream() */ +static int iglobalHeaderFlag = 1; static uint64_t ui64Generator1; -/*----------------------------------------------------------------------*/ -/* */ -/* Build the file image and store it as Data Stream of bytes */ -/* calculate a first CRC for the first file and */ -/* chatch the position of this CRC */ -/*----------------------------------------------------------------------*/ -int buildDataStream(unsigned char *pucbuf, int size) + +/** + * Build the file image and store it as Data Stream of bytes + * calculate a first CRC for the first file and + * catch the position of this CRC + */ +int +buildDataStream(unsigned char *pucbuf, int size) { if (ui64globalFileSize + size > sizeof(pucFileStream)) { printf("Error: File size is too big!\n"); return -1; } - for( ; size; size -=1, pucbuf +=1) { + /* copy the data into the destination buffer */ + memcpy(pucFileStream + ui64globalFileSize, pucbuf, size); + ui64globalFileSize += size; - pucFileStream[ui64globalFileSize] = *pucbuf; - ui64globalFileSize++; - } - if(iglobalHeaderFlag == 1) { // catch header + if (iglobalHeaderFlag == 1) { // catch header - ui64globalHeaderSize = ui64globalFileSize; - iglobalHeaderFlag = 0; - } + ui64globalHeaderSize = ui64globalFileSize; + iglobalHeaderFlag = 0; + } return 0; } -/*--------------------------------------------------------------------------------- */ -/* + -+ write Header.img + -+ + -+ note: use insert64bit to write all uint64_t variables because of + -+ Big Endian - Little Endian problem between Intel CPU and PowerPC CPU */ -/* -------------------------------------------------------------------------------- */ -int createHeaderImage(void) + +/** + * write Header.img + */ +int +createHeaderImage(int notime) { int iCounter; - uint64_t ui64RomAddr, ui64DataAddr, ui64FlashlenAddr; + uint64_t ui64RomAddr, ui64DataAddr; time_t caltime; - struct tm *tm; + struct tm *tm; char *pcVersion; - char dastr[16]; - unsigned long long da; + char dastr[16] = { 0, }; + unsigned long long da = 0; union { unsigned char pcArray[FLASHFS_HEADER_DATA_SIZE]; struct stH stHeader; } uHeader; - memset(uHeader.pcArray,0x00, FLASHFS_HEADER_DATA_SIZE); // initialize Header + /* initialize Header */ + memset(uHeader.pcArray, 0x00, FLASHFS_HEADER_DATA_SIZE); /* read driver info */ - if(NULL != (pcVersion = getenv("DRIVER_NAME"))) { - strncpy(uHeader.stHeader.version, pcVersion,16); - } - else if (NULL != (pcVersion = getenv("USER")) ) { - strncpy(uHeader.stHeader.version, pcVersion,16); - } - else if(pcVersion == NULL) { - strncpy(uHeader.stHeader.version, "No known user!",16 ); - } - - /* read time and write it into data stream */ - if ( (caltime = time(NULL)) ==-1) { - printf("time error\n"); - } - if ( (tm = localtime(&caltime)) == NULL) { - printf("local time error\n"); + if (NULL != (pcVersion = getenv("DRIVER_NAME"))) { + strncpy(uHeader.stHeader.version, pcVersion, 16); + } else if (NULL != (pcVersion = getenv("USER"))) { + strncpy(uHeader.stHeader.version, pcVersion, 16); + } else if (pcVersion == NULL) { + strncpy(uHeader.stHeader.version, "No known user!", 16); } - // length must be 13 instead 12 because of terminating NUL. Therefore uH.stH.platform_revison - // must be writen later to overwrite the terminating NUL - if(strftime(dastr, 15, "0x%Y%m%d%H%M", tm) == 0) { - printf("strftime error\n"); + if (!notime) { + /* read time and write it into data stream */ + if ((caltime = time(NULL)) == -1) { + printf("time error\n"); + } + if ((tm = localtime(&caltime)) == NULL) { + printf("local time error\n"); + } + // length must be 13 instead 12 because of terminating + // NUL. Therefore uH.stH.platform_revison must be + // writen later to overwrite the terminating NUL + if (strftime(dastr, 15, "0x%Y%m%d%H%M", tm) == 0) { + printf("strftime error\n"); + } + da = cpu_to_be64(strtoll(dastr, NULL, 16)); } - da=strtoll(dastr,NULL, 16); - #if __BYTE_ORDER == __LITTLE_ENDIAN - da=__bswap_64(da) >> 16; - #else - da = da << 16; - #endif memcpy(uHeader.stHeader.date, &da, 8); - strcpy(uHeader.stHeader.magic,FLASHFS_MAGIC); // write Magic value into data stream - strcpy(uHeader.stHeader.platform_name,FLASHFS_PLATFORM_MAGIC); // write platform name into data stream - strcpy(uHeader.stHeader.platform_revision,FLASHFS_PLATFORM_REVISION); // write platform recision into data stream - - - /* fill end of file info (8 bytes of FF) into data stream */ - uHeader.stHeader.ui64FileEnd = (uint64_t)(0xFFFFFFFF); - uHeader.stHeader.ui64FileEnd = (uHeader.stHeader.ui64FileEnd << 32) + (uint64_t)0xFFFFFFFF; + /* write Magic value into data stream */ + strcpy(uHeader.stHeader.magic, FLASHFS_MAGIC); + /* write platform name into data stream */ + strcpy(uHeader.stHeader.platform_name, FLASHFS_PLATFORM_MAGIC); + /* write platform revision into data stream */ + strcpy(uHeader.stHeader.platform_revision, FLASHFS_PLATFORM_REVISION); - /* read address of next file and address of header date, both are 64 bit values */ - ui64RomAddr = 0; - ui64DataAddr = 0; - for(iCounter = 0; iCounter < 8; iCounter++) { - ui64RomAddr = ( ui64RomAddr << 8 ) + pucFileStream[FLASHFS_ROMADDR + iCounter]; // addr of next file - ui64DataAddr = ( ui64DataAddr << 8) + pucFileStream[FLASHFS_DATADDR + iCounter]; // addr of header data + /* fill end of file info (8 bytes of FF) into data stream */ + uHeader.stHeader.ui64FileEnd = -1; + + /* read address of next file and address of header date, both are 64 bit values */ + ui64RomAddr = 0; + ui64DataAddr = 0; + for (iCounter = 0; iCounter < 8; iCounter++) { + /* addr of next file */ + ui64RomAddr = (ui64RomAddr << 8) + pucFileStream[FLASHFS_ROMADDR + iCounter]; + /* addr of header data */ + ui64DataAddr = (ui64DataAddr << 8) + pucFileStream[FLASHFS_DATADDR + iCounter]; } /* calculate final flash-header-size and flash-file-size */ - ui64globalHeaderSize = (uint32_t)ui64DataAddr + (uint32_t)FLASHFS_HEADER_DATA_SIZE; // calculate end addr of header - ui64globalHeaderSize -=8; // cut 64 bit to place CRC for File-End - ui64globalFileSize += 8; // add 64 bit to place CRC behind File-End - - if( ui64globalHeaderSize < ui64RomAddr ) { - memset( &pucFileStream[ui64DataAddr], 0, (ui64RomAddr-ui64DataAddr)); // fill free space in Header with zeros - // place data to header - memcpy( &pucFileStream[ui64DataAddr], uHeader.pcArray, FLASHFS_HEADER_DATA_SIZE); // insert header data - - // insert header length into data stream - ui64FlashlenAddr = (uint64_t)FLASHFS_HEADER_SIZE_ADDR; - insert64bit(ui64globalHeaderSize, ui64FlashlenAddr ); - - // insert flash length into data stream - ui64FlashlenAddr = ((uint64_t)ui64DataAddr +(uint64_t)FLASHFS_FILE_SIZE_ADDR ); - insert64bit(ui64globalFileSize, ui64FlashlenAddr); - - // insert zeros as placeholder for CRC - insert64bit(0, (ui64globalHeaderSize -8) ); - insert64bit(0, (ui64globalFileSize -8) ); - - return 0; - } - else { - printf("%s\n","--- Header File to long"); + /* calculate end addr of header */ + ui64globalHeaderSize = (uint32_t) ui64DataAddr + (uint32_t) FLASHFS_HEADER_DATA_SIZE; + /* cut 64 bit to place CRC for File-End */ + ui64globalHeaderSize -= 8; + /* add 64 bit to place CRC behind File-End */ + ui64globalFileSize += 8; + + if (ui64globalHeaderSize >= ui64RomAddr) { + printf("%s\n", "--- Header File to long"); return 1; } + + /* fill free space in Header with zeros */ + memset(&pucFileStream[ui64DataAddr], 0, (ui64RomAddr - ui64DataAddr)); + /* place data to header */ + memcpy(&pucFileStream[ui64DataAddr], uHeader.pcArray, + FLASHFS_HEADER_DATA_SIZE); + + /* insert header length into data stream */ + *(uint64_t *) (pucFileStream + FLASHFS_HEADER_SIZE_ADDR) = + cpu_to_be64(ui64globalHeaderSize); + + /* insert flash length into data stream */ + *(uint64_t *) (pucFileStream + ui64DataAddr + FLASHFS_FILE_SIZE_ADDR) = + cpu_to_be64(ui64globalFileSize); + + /* insert zeros as placeholder for CRC */ + *(uint64_t *) (pucFileStream + ui64globalHeaderSize - 8) = 0; + *(uint64_t *) (pucFileStream + ui64globalFileSize - 8) = 0; + + return 0; } -/*--------------------------------------------------------------------- */ -/* */ -/* calculate standart ethernet 32 bit CRC */ -/* generator polynome is 0x104C11DB7 */ -/* this algorithm can be used for encoding and decoding */ -/*----------------------------------------------------------------------*/ -unsigned int calCRCEthernet32(unsigned char *TextPtr, unsigned long int TextLength, unsigned int AccumCRC) { - const unsigned int CrcTableHigh[16] = { - 0x00000000, 0x4C11DB70, 0x9823B6E0, 0xD4326D90, - 0x34867077, 0x7897AB07, 0xACA5C697, 0xE0B41DE7, - 0x690CE0EE, 0x251D3B9E, 0xF12F560E, 0xBD3E8D7E, - 0x5D8A9099, 0x119B4BE9, 0xC5A92679, 0x89B8FD09 - }; - const unsigned CrcTableLow[16] = { - 0x00000000, 0x04C11DB7, 0x09823B6E, 0x0D4326D9, - 0x130476DC, 0x17C56B6B, 0x1A864DB2, 0x1E475005, - 0x2608EDB8, 0x22C9F00F, 0x2F8AD6D6, 0x2B4BCB61, - 0x350C9B64, 0x31CD86D3, 0x3C8EA00A, 0x384FBDBD - }; - - unsigned char* Buffer = TextPtr; - unsigned long int Residual = TextLength; - - - while ( Residual > 0 ) { - unsigned int Temp = ((AccumCRC >> 24) ^ *Buffer) & 0x000000ff; - AccumCRC <<= 8; - AccumCRC ^= CrcTableHigh[ Temp/16 ]; - AccumCRC ^= CrcTableLow[ Temp%16 ]; - ++Buffer; - --Residual; - } - return AccumCRC; + +/** + * calculate standart ethernet 32 bit CRC + * generator polynome is 0x104C11DB7 + * this algorithm can be used for encoding and decoding + */ +unsigned int +calCRCEthernet32(unsigned char *TextPtr, unsigned long int TextLength, + unsigned int AccumCRC) +{ + const unsigned int CrcTableHigh[16] = { + 0x00000000, 0x4C11DB70, 0x9823B6E0, 0xD4326D90, + 0x34867077, 0x7897AB07, 0xACA5C697, 0xE0B41DE7, + 0x690CE0EE, 0x251D3B9E, 0xF12F560E, 0xBD3E8D7E, + 0x5D8A9099, 0x119B4BE9, 0xC5A92679, 0x89B8FD09 + }; + const unsigned CrcTableLow[16] = { + 0x00000000, 0x04C11DB7, 0x09823B6E, 0x0D4326D9, + 0x130476DC, 0x17C56B6B, 0x1A864DB2, 0x1E475005, + 0x2608EDB8, 0x22C9F00F, 0x2F8AD6D6, 0x2B4BCB61, + 0x350C9B64, 0x31CD86D3, 0x3C8EA00A, 0x384FBDBD + }; + + unsigned char *Buffer = TextPtr; + unsigned long int Residual = TextLength; + + + while (Residual > 0) { + unsigned int Temp = ((AccumCRC >> 24) ^ *Buffer) & 0x000000ff; + AccumCRC <<= 8; + AccumCRC ^= CrcTableHigh[Temp / 16]; + AccumCRC ^= CrcTableLow[Temp % 16]; + ++Buffer; + --Residual; + } + return AccumCRC; } -/*------------------------------------------------------- calculate CRC */ -/* */ -/* */ -/*----------------------------------------------------------------------*/ -/* create CRC Parameter: CRC Polynome, Shiftregister Mask and length */ -// ui64Generator[0] = 0; -// ui64Generator[1] = 0x42F0E1EB; -// ui64Generator[1] = (ui64Generator[1] << 32) + 0xA9EA3693; -// iRegisterLength = 63; -// ui64RegisterMask = 0xffffffff; -// ui64RegisterMask = ((ui64RegisterMask) << 32) + 0xffffffff; -/* ucl=0x00000000ffffffff = Mask for 32 bit LSFR to cut down number of bits - in the variable to get the same length as LFSR - - il = length of LSFR = degree of generator polynom reduce il by one to calculate the degree - of the highest register in LSFR - - Examples: - CRC-16 for Tap: x16 + x15 + x2 + 1 - generator = 0x8005, il = 16, ucl = 0x000000000000FFFF - - CRC-16 for Floppy: x16 + x12 + x5 +1 - generator = 0x1021, il = 16, ucl = 0x000000000000FFFF - - CRC-32 for Ethernet: x32 + x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5 + x4 + x2 + x + 1 - generator = 0x04C11DB7, il = 32, ucl = 0x00000000FFFFFFFF - - CRC-64 SP-TrEMBL x64 + x4 + x3 + x + 1 (maximal-length LFSR) - renerator = 0x1B, il = 64, ucl = 0xFFFFFFFFFFFFFFFF - - CRC-64 improved x64 + x63 + x61 + x59 + x58 + x56 + x55 + x52 + x49 + x48 + x47 + x46+ x44 + - x41 + x37 + x36 + x34 + x32 + x31 + x28 + x26 + x23 + x22 + x19 + x16 + x13 + - x12 + x10 + x9 + x6 + x4 + x3 + 1 (see http://www.cs.ud.ac.uk/staff/D.Jones/crcbote.pdf) - grenerator = 0xAD93D23594C9362D, il = 64, ucl = 0xFFFFFFFFFFFFFFFF - - CRC-64 DLT1 spec x64 + x62 + x57 + x55 + x54 + x53 + x52 + x47 + x46 + x45 + x40 + x39 + x38 + x37 + - x35 + x33 + x32 + x31 + x29 + x27 + x24 + x23 + x22 + x21 + x19 + x17 + x13 + x12 + - x10 + x9 + x7 + x4 + x + 1 - (see http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-182.pdf -> page63) - generator = 0x42F0E1EBA9EA3693 - - CRC-64 from internet G(x)= 1006003C000F0D50B -*/ - -/*--------------------------------------------------------------------- */ -int createCRCParameter(uint64_t *ui64RegisterMask, unsigned int *uiRegisterLength) + +/** + * create CRC Parameter: CRC Polynome, Shiftregister Mask and length + * + * ui64Generator[0] = 0; + * ui64Generator[1] = 0x42F0E1EB; + * ui64Generator[1] = (ui64Generator[1] << 32) + 0xA9EA3693; + * iRegisterLength = 63; + * ui64RegisterMask = 0xffffffff; + * ui64RegisterMask = ((ui64RegisterMask) << 32) + 0xffffffff; + * + * ucl=0x00000000ffffffff = Mask for 32 bit LSFR to cut down number of bits + * in the variable to get the same length as LFSR + * + * il = length of LSFR = degree of generator polynom reduce il by one to calculate the degree + * of the highest register in LSFR + * + * Examples: + * CRC-16 for Tap: x16 + x15 + x2 + 1 + * generator = 0x8005, il = 16, ucl = 0x000000000000FFFF + * + * CRC-16 for Floppy: x16 + x12 + x5 +1 + * generator = 0x1021, il = 16, ucl = 0x000000000000FFFF + * + * CRC-32 for Ethernet: x32 + x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5 + x4 + x2 + x + 1 + * generator = 0x04C11DB7, il = 32, ucl = 0x00000000FFFFFFFF + * + * CRC-64 SP-TrEMBL x64 + x4 + x3 + x + 1 (maximal-length LFSR) + * generator = 0x1B, il = 64, ucl = 0xFFFFFFFFFFFFFFFF + * + * CRC-64 improved + * x64 + x63 + x61 + x59 + x58 + x56 + x55 + x52 + x49 + x48 + x47 + x46+ x44 + + * x41 + x37 + x36 + x34 + x32 + x31 + x28 + x26 + x23 + x22 + x19 + x16 + x13 + + * x12 + x10 + x9 + x6 + x4 + x3 + 1 + * (see http://www.cs.ud.ac.uk/staff/D.Jones/crcbote.pdf) + * generator = 0xAD93D23594C9362D, il = 64, ucl = 0xFFFFFFFFFFFFFFFF + * + * CRC-64 DLT1 spec + * x64 + x62 + x57 + x55 + x54 + x53 + x52 + x47 + x46 + x45 + x40 + x39 + x38 + x37 + + * x35 + x33 + x32 + x31 + x29 + x27 + x24 + x23 + x22 + x21 + x19 + x17 + x13 + x12 + + * x10 + x9 + x7 + x4 + x + 1 + * (see http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-182.pdf -> page63) + * generator = 0x42F0E1EBA9EA3693 + * + * CRC-64 from internet G(x)= 1006003C000F0D50B + */ +int +createCRCParameter(uint64_t * ui64RegisterMask, unsigned int *uiRegisterLength) { - enum Generators {Tape_16, Floppy_16, Ethernet_32, SPTrEMBL_64, SPTrEMBL_improved_64,DLT1_64}; + enum Generators { Tape_16, Floppy_16, Ethernet_32, SPTrEMBL_64, + SPTrEMBL_improved_64, DLT1_64 + }; enum Generators Generator; Generator = CRC_METHODE; - switch (Generator){ - case Tape_16:{ - *ui64RegisterMask = 0x0000ffff; - ui64Generator1 = 0x00008005; - *uiRegisterLength = 16; + switch (Generator) { + case Tape_16:{ + *ui64RegisterMask = 0x0000ffff; + ui64Generator1 = 0x00008005; + *uiRegisterLength = 16; break; } - case Floppy_16: { - *ui64RegisterMask = 0x0000ffff; - ui64Generator1 = 0x00001021; - *uiRegisterLength = 16; + case Floppy_16:{ + *ui64RegisterMask = 0x0000ffff; + ui64Generator1 = 0x00001021; + *uiRegisterLength = 16; break; } - case Ethernet_32: { - *ui64RegisterMask = 0xffffffff; - ui64Generator1 = 0x04C11DB7; - *uiRegisterLength = 32; + case Ethernet_32:{ + *ui64RegisterMask = 0xffffffff; + ui64Generator1 = 0x04C11DB7; + *uiRegisterLength = 32; break; } - case SPTrEMBL_64: { - *ui64RegisterMask = 0xffffffff; - *ui64RegisterMask = ((*ui64RegisterMask) << 32) + 0xffffffff; - ui64Generator1 = 0x0000001B; - *uiRegisterLength = 64; + case SPTrEMBL_64:{ + *ui64RegisterMask = 0xffffffff; + *ui64RegisterMask = + ((*ui64RegisterMask) << 32) + 0xffffffff; + ui64Generator1 = 0x0000001B; + *uiRegisterLength = 64; break; } - case SPTrEMBL_improved_64: { - *ui64RegisterMask = 0xffffffff; - *ui64RegisterMask = ((*ui64RegisterMask) << 32) + 0xffffffff; - ui64Generator1 = 0xAD93D235; - ui64Generator1 = (ui64Generator1 << 32) + 0x94C9362D; - *uiRegisterLength = 64; + case SPTrEMBL_improved_64:{ + *ui64RegisterMask = 0xffffffff; + *ui64RegisterMask = + ((*ui64RegisterMask) << 32) + 0xffffffff; + ui64Generator1 = 0xAD93D235; + ui64Generator1 = (ui64Generator1 << 32) + 0x94C9362D; + *uiRegisterLength = 64; break; } - case DLT1_64:{ - *ui64RegisterMask = 0xffffffff; - *ui64RegisterMask = ((*ui64RegisterMask) << 32) + 0xffffffff; - ui64Generator1 = 0x42F0E1EB; - ui64Generator1 = (ui64Generator1 << 32) + 0xA9EA3693; - *uiRegisterLength = 64; - break; + case DLT1_64:{ + *ui64RegisterMask = 0xffffffff; + *ui64RegisterMask = + ((*ui64RegisterMask) << 32) + 0xffffffff; + ui64Generator1 = 0x42F0E1EB; + ui64Generator1 = (ui64Generator1 << 32) + 0xA9EA3693; + *uiRegisterLength = 64; + break; } } - (*uiRegisterLength)--; + (*uiRegisterLength)--; return 0; } -/*------------------------------------------------ create CRC Parameter */ -/* */ -/* Check CRC by using Linear Feadback Shift Register (LFSR) */ -/*----------------------------------------------------------------------*/ -uint64_t calCRCbyte(unsigned char *cPtr, uint32_t ui32NoWords, uint64_t AccumCRC) { - uint64_t ui64Mask, ui64Generator0; +/** + * Check CRC by using Linear Feadback Shift Register (LFSR) + */ +uint64_t +calCRCbyte(unsigned char *cPtr, uint32_t ui32NoWords, uint64_t AccumCRC) +{ + + uint64_t ui64Mask, ui64Generator0; uint8_t ui8Buffer; unsigned int uiRegisterLength; - int iShift; + int iShift; - createCRCParameter(&ui64Mask, &uiRegisterLength); + createCRCParameter(&ui64Mask, &uiRegisterLength); ui8Buffer = (*cPtr); - while ( ui32NoWords > 0) { - for (iShift = 7;iShift >= 0; iShift--) { - - ui64Generator0 = (AccumCRC >> uiRegisterLength); - AccumCRC <<= 1; - ui64Generator0 &= 0x01; - ui64Generator0 = (0-ui64Generator0); - AccumCRC ^= (ui64Generator1 & ui64Generator0); - } - AccumCRC ^= ui8Buffer; - AccumCRC &= ui64Mask; - ui32NoWords -= 1; - cPtr += 1; + while (ui32NoWords > 0) { + for (iShift = 7; iShift >= 0; iShift--) { + + ui64Generator0 = (AccumCRC >> uiRegisterLength); + AccumCRC <<= 1; + ui64Generator0 &= 0x01; + ui64Generator0 = (0 - ui64Generator0); + AccumCRC ^= (ui64Generator1 & ui64Generator0); + } + AccumCRC ^= ui8Buffer; + AccumCRC &= ui64Mask; + ui32NoWords -= 1; + cPtr += 1; ui8Buffer = (*cPtr); - } - return AccumCRC; + } + return AccumCRC; } -/*--------------------------------------------------------------checkCRC */ -/* */ -/* Check CRC by using Linear Feadback Shift Register (LFSR) */ -/*----------------------------------------------------------------------*/ -uint64_t calCRCword(unsigned char *cPtr, uint32_t ui32NoWords, uint64_t AccumCRC) { - uint64_t ui64Mask, ui64Generator0; +/** + * Check CRC by using Linear Feadback Shift Register (LFSR) + */ +uint64_t +calCRCword(unsigned char *cPtr, uint32_t ui32NoWords, uint64_t AccumCRC) +{ + + uint64_t ui64Mask, ui64Generator0; uint16_t ui16Buffer; unsigned int uiRegisterLength; - int iShift; + int iShift; - createCRCParameter(&ui64Mask, &uiRegisterLength); + createCRCParameter(&ui64Mask, &uiRegisterLength); - if( (ui32NoWords%2) != 0) { // if Data string does not end at word boundery add one byte - ui32NoWords++; + if ((ui32NoWords % 2) != 0) { + /* if Data string does not end at word boundery add one byte */ + ui32NoWords++; cPtr[ui32NoWords] = 0; } - ui16Buffer = ( (*(cPtr+0)) * 256) + (*(cPtr+1)); - while ( ui32NoWords > 0) { - for (iShift = 15;iShift >= 0; iShift--) { - ui64Generator0 = (AccumCRC >> uiRegisterLength); - AccumCRC <<= 1; - ui64Generator0 &= 0x01; - ui64Generator0 = (0-ui64Generator0); - AccumCRC ^= (ui64Generator1 & ui64Generator0); - } - AccumCRC ^= ui16Buffer; - AccumCRC &= ui64Mask; - ui32NoWords -= 2; - cPtr += 2; - ui16Buffer = ( (*(cPtr+0)) * 256) + (*(cPtr+1)); - } - return AccumCRC; + ui16Buffer = ((*(cPtr + 0)) * 256) + (*(cPtr + 1)); + while (ui32NoWords > 0) { + for (iShift = 15; iShift >= 0; iShift--) { + ui64Generator0 = (AccumCRC >> uiRegisterLength); + AccumCRC <<= 1; + ui64Generator0 &= 0x01; + ui64Generator0 = (0 - ui64Generator0); + AccumCRC ^= (ui64Generator1 & ui64Generator0); + } + AccumCRC ^= ui16Buffer; + AccumCRC &= ui64Mask; + ui32NoWords -= 2; + cPtr += 2; + ui16Buffer = ((*(cPtr + 0)) * 256) + (*(cPtr + 1)); + } + return AccumCRC; } -/*------------------------------------------------------------- checkCRCnew */ -/* */ -/* */ -/*------------------------------------------------------------------------- */ -uint64_t checkCRC(unsigned char *cPtr, uint32_t ui32NoWords, uint64_t AccumCRC) { - enum Generators {Ethernet_32}; +uint64_t +checkCRC(unsigned char *cPtr, uint32_t ui32NoWords, uint64_t AccumCRC) +{ + + enum Generators { Ethernet_32 }; enum Generators Generator; uint64_t ui64Buffer = AccumCRC; Generator = CRC_METHODE; switch (Generator) { - case Ethernet_32: { - // (ui32NoWords - 4),no need of 4 bytes 0x as with shift-register method - AccumCRC = calCRCEthernet32( cPtr, (ui32NoWords-4), AccumCRC ); - break; + case Ethernet_32:{ + /* (ui32NoWords - 4),no need of 4 bytes 0x as + * with shift-register method */ + AccumCRC = + calCRCEthernet32(cPtr, (ui32NoWords - 4), AccumCRC); + break; } - default :{ - AccumCRC = calCRCword( cPtr, ui32NoWords, AccumCRC); + default:{ + AccumCRC = calCRCword(cPtr, ui32NoWords, AccumCRC); break; } } - - if( calCRCbyte(cPtr, ui32NoWords, ui64Buffer) != AccumCRC) { + + if (calCRCbyte(cPtr, ui32NoWords, ui64Buffer) != AccumCRC) { printf("\n --- big Endian - small Endian problem --- \n"); AccumCRC--; } - - return( AccumCRC); -} - - -/*--------------------------------------------------------------------- CRC */ -/* */ -/* Insert 64 bit as Big Endian */ -/* into DataStream starting at (uli)Position */ -/*------------------------------------------------------------------------- */ -int insert64bit(uint64_t ui64CRC, uint32_t ui32Position) -{ - - pucFileStream[ui32Position] = (char) ((ui64CRC >> 56) & 0x00FF); - pucFileStream[ui32Position+1] = (char) ((ui64CRC >> 48) & 0x00FF); - pucFileStream[ui32Position+2] = (char) ((ui64CRC >> 40) & 0x00FF); - pucFileStream[ui32Position+3] = (char) ((ui64CRC >> 32) & 0x00FF); - pucFileStream[ui32Position+4] = (char) ((ui64CRC >> 24) & 0x00FF); - pucFileStream[ui32Position+5] = (char) ((ui64CRC >> 16) & 0x00FF); - pucFileStream[ui32Position+6] = (char) ((ui64CRC >> 8) & 0x00FF); - pucFileStream[ui32Position+7] = (char) (ui64CRC & 0x00FF); - - return 0; + return (AccumCRC); } -/*----------------------------------------------------------- insertCRC */ -/* */ -/* insert header and file CRC into data stream */ -/* do CRC check on header and file */ -/* write data stream to disk */ -/*----------------------------------------------------------------------*/ -int writeDataStream(int iofd) + +/** + * insert header and file CRC into data stream + * do CRC check on header and file + * write data stream to disk + */ +int +writeDataStream(int iofd, int notime) { - uint64_t ui64FileCRC=0, ui64HeaderCRC=0, ui64RegisterMask; + uint64_t ui64FileCRC = 0, ui64HeaderCRC = 0, ui64RegisterMask; unsigned int uiRegisterLength; - if(0 != createHeaderImage()) { + if (0 != createHeaderImage(notime)) { return 1; } - createCRCParameter( &ui64RegisterMask, &uiRegisterLength); + createCRCParameter(&ui64RegisterMask, &uiRegisterLength); -/* calculate CRC---------------------------------------------------- */ + /* calculate CRC */ ui64HeaderCRC = checkCRC(pucFileStream, ui64globalHeaderSize, 0); - insert64bit(ui64HeaderCRC, (ui64globalHeaderSize-8) ); + *(uint64_t *) (pucFileStream + ui64globalHeaderSize - 8) = + cpu_to_be64(ui64HeaderCRC); ui64FileCRC = checkCRC(pucFileStream, ui64globalFileSize, 0); - insert64bit(ui64FileCRC, (ui64globalFileSize -8) ); - -/* report CRCs and proof if CRCs are correct implemented */ - //printf("\n"); - //printf("%s%X%X\n","Generator = 0x1",(uint32_t)(ui64Generator1>>32),(uint32_t)ui64Generator1); - - //printf("%s%x%s%u%-9s%s%X%X\n","header size = 0x", (uint32_t)ui64globalHeaderSize, "/", (uint32_t)ui64globalHeaderSize," bytes","file CRC = 0x",(uint32_t)(ui64HeaderCRC >> 32),(uint32_t)ui64HeaderCRC); - - //printf("Firmware Header CRC = 0x%08x\n", (uint32_t)ui64HeaderCRC); - //printf("Flash Image CRC = 0x%08x\n", (uint32_t)ui64FileCRC); + *(uint64_t *) (pucFileStream + ui64globalFileSize - 8) = + cpu_to_be64(ui64FileCRC); - //printf("%s%x%s%u%-9s%s%X%X\n","flash size = 0x", (uint32_t)ui64globalFileSize, "/", (uint32_t)ui64globalFileSize," bytes","file CRC = 0x",(uint32_t)(ui64FileCRC >> 32),(uint32_t)ui64FileCRC); + /* check CRC-implementation */ + ui64HeaderCRC = calCRCword(pucFileStream, ui64globalHeaderSize, 0); + ui64FileCRC = calCRCword(pucFileStream, ui64globalFileSize, 0); -/* check CRC-implementation */ - ui64HeaderCRC = calCRCword( pucFileStream, ui64globalHeaderSize, 0); - ui64FileCRC = calCRCword( pucFileStream, ui64globalFileSize, 0); - - //printf("%s%X%X\n","header CRC check = 0x", (uint32_t)(ui64HeaderCRC >> 32),(uint32_t)ui64HeaderCRC); - //printf("%s%X%X\n","flash CRC check = 0x", (uint32_t)(ui64FileCRC >> 32),(uint32_t)ui64FileCRC); - - if( (ui64HeaderCRC == 0) && (ui64FileCRC == 0) ) { - //printf("\n%s\n","CRCs correct implemented. ---> Data will be written to disk."); - /* write file image to disk */ - if (0 < write(iofd, pucFileStream, ui64globalFileSize)) { - return 0; - } - else { - printf("<< write failed >>\n"); - return -1; - } - - } - else { - printf("\n\n %s \n %s \n\n","CRCs not correct implemented."," ---> Data will not be written do disk."); + if ((ui64HeaderCRC != 0) || (ui64FileCRC != 0)) { + printf("\n\n %s \n %s \n\n", "CRCs not correct implemented.", + " ---> Data will not be written do disk."); return -1; } -} -/*----------------------------------------------------- writeDataStream */ + /* write file image to disk */ + if (0 < write(iofd, pucFileStream, ui64globalFileSize)) + return 0; + printf("<< write failed >>\n"); + return -1; +} diff --git a/romfs/tools/create_flash.c b/romfs/tools/create_flash.c index 1c968bd..f99fd62 100644 --- a/romfs/tools/create_flash.c +++ b/romfs/tools/create_flash.c @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright (c) 2004, 2007 IBM Corporation + * Copyright (c) 2004, 2008 IBM Corporation * All rights reserved. * This program and the accompanying materials * are made available under the terms of the BSD License @@ -16,72 +16,148 @@ #include <fcntl.h> #include <string.h> #include <unistd.h> +#include <getopt.h> #include <cfgparse.h> -#undef DEBUGGING +int verbose = 0; -#ifdef DEBUGGING -#define dprintf(_x...) printf(_x) -#else -#define dprintf(_x...) -#endif +#define dprintf(fmt, args...) if (verbose) printf(fmt, ##args) -void print_usage() +static void +print_usage(void) { - printf("args: description_file output_file\n\n"); + printf + ("Usage: build_romfs [-?] [--help] [-s|--romfs-size <romfs_size>]\n" + "\t[-p|--smart-pad] [-n|--notime] <config-file> <output-file>\n"); } -int main (int argc, char *argv[]) +unsigned long +str_to_num(const char *str) +{ + char *s = (char *) str; + unsigned long num = strtoul(s, &s, 0); + if (s) { + if (s[0] == 'K') + num <<= 10; + if (s[0] == 'M') + num <<= 20; + } + return num; +} + +/* + * NOTE: We should consider to install an exit handler which does the + * unlink() of the output file. In case of error we just do exit() and + * forget about all the clumsy error handling free/close code, which + * blows up the code significantly and makes it hard to read. + */ +int +main(int argc, char *argv[]) { int conf_file, rc; struct ffs_chain_t ffs_chain; + int c; + int smart_pad = 0; /* default */ + int notime = 0; + const char *config_file = "boot_rom.ffs"; + const char *output_file = "boot_rom.bin"; - if (argc != 3) { + memset((void *) &ffs_chain, 0, sizeof(struct ffs_chain_t)); + + while (1) { + int option_index = 0; + static struct option long_options[] = { + {"romfs-size", 1, 0, 's'}, + {"smart-pad", 0, 0, 'p'}, + {"notime", 0, 0, 'n'}, + {"verbose", 0, 0, 'v'}, + {"help", 1, 0, 'h'}, + {0, 0, 0, 0} + }; + c = getopt_long(argc, argv, "s:ph?nv", long_options, + &option_index); + if (c == -1) + break; + + switch (c) { + case 's': + ffs_chain.romfs_size = str_to_num(optarg); + break; + case 'p': + smart_pad = 1; + break; + case 'n': + notime = 1; + break; + case 'v': + verbose = 1; + break; + case '?': + case 'h': + print_usage(); + return EXIT_SUCCESS; + default: + printf("?? getopt returned character code 0%o ??\n", c); + } + } + + /* two files must always be specified: config-file and output-file */ + if (optind + 2 != argc) { print_usage(); return EXIT_FAILURE; } - dprintf("ROMFS FILESYSTEM CREATION V0.1 (bad parser)\n"); - dprintf("Build directory structure...\n"); + config_file = argv[optind++]; + output_file = argv[optind++]; + + dprintf("ROMFS FILESYSTEM CREATION V0.3 (bad parser)\n" + "Build directory structure...\n" + " smart padding %s, maximum romfs size %d bytes\n", + smart_pad ? "enabled" : "disabled", ffs_chain.romfs_size); - memset((void*) &ffs_chain, 0, sizeof(struct ffs_chain_t)); - conf_file = open(argv[1], O_RDONLY); + conf_file = open(config_file, O_RDONLY); if (0 >= conf_file) { perror("load config file:"); return EXIT_FAILURE; } - while (0 == (rc = find_next_entry(conf_file, &ffs_chain))); + rc = read_config(conf_file, &ffs_chain); + close(conf_file); + if (rc < 1) { + fprintf(stderr, "flash cannot be built due to config errors\n"); + return EXIT_FAILURE; + } + + rc = EXIT_SUCCESS; - if (1 >= rc) { -#ifdef DEBUGGING + if (verbose) dump_fs_contents(&ffs_chain); -#endif - dprintf("Build ffs and write to image file...\n"); - if (build_ffs(&ffs_chain, argv[2]) != 0) { - fprintf(stderr, "build ffs failed\n"); - rc = EXIT_FAILURE; - } else { - rc = EXIT_SUCCESS; - } - } else { - fprintf(stderr, "flash cannot be built due to config errors\n"); + if (smart_pad) + /* FIXME: size is only verified during reorder */ + rc = reorder_ffs_chain(&ffs_chain); + + if (rc == EXIT_FAILURE) + goto out; + + dprintf("Build ffs and write to image file...\n"); + if (build_ffs(&ffs_chain, output_file, notime) != 0) { + fprintf(stderr, "build ffs failed\n"); rc = EXIT_FAILURE; + } else { + rc = EXIT_SUCCESS; } - /* Check if there are any duplicate entries in the image: */ + /* Check if there are any duplicate entries in the image, + print warning if this is the case. */ find_duplicates(&ffs_chain); - free_chain_memory(&ffs_chain); - close(conf_file); dprintf("\n"); + out: /* If the build failed, remove the target image file */ - if (rc == EXIT_FAILURE) { - unlink(argv[2]); - } + if (rc == EXIT_FAILURE) + unlink(output_file); return rc; } - diff --git a/romfs/tools/createcrc.h b/romfs/tools/createcrc.h index 10490ad..1f23598 100644 --- a/romfs/tools/createcrc.h +++ b/romfs/tools/createcrc.h @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright (c) 2004, 2007 IBM Corporation + * Copyright (c) 2004, 2008 IBM Corporation * All rights reserved. * This program and the accompanying materials * are made available under the terms of the BSD License @@ -14,5 +14,6 @@ int buildDataStream(unsigned char *pucbuf, int size); int createHeaderImgage(char *pcFilename); -void writeDataStream(int ofd); +int writeDataStream(int ofd, int notime); + #endif |