mtd-utils warnings
Hi Josh,
I have a quick and dirty patch that removes most warnings when compiling mtd-utils. It should be relatively safe and trivial, but I won't give any guarantees for it. Interested?
Jörn
Signature · 16 lines
The only real mistake is the one from which we learn nothing. -- John Powell compr.h | 2 +- fec.c | 10 +++++----- flash_eraseall.c | 5 +++++ ftl_check.c | 4 ++-- jffs2dump.c | 36 ++++++++++++++++++------------------ mkfs.jffs2.c | 23 ++++++++++++----------- mtd_debug.c | 2 +- nandtest.c | 6 +++--- nandwrite.c | 1 - nftl_format.c | 3 ++- recv_image.c | 4 ++-- sumtool.c | 38 +++++++++++++++++++------------------- 12 files changed, 70 insertions(+), 64 deletions(-)
compr.h +1 -1
@@ -67,7 +67,7 @@ int jffs2_set_compressor_priority(const char *name, int priority);struct jffs2_compressor {struct list_head list;int priority;/* used by prirority comr. mode */ -char *name; +const char *name;char compr;/* JFFS2_COMPR_XXX */ int (*compress)(unsigned char *data_in,unsigned char *cpage_out,uint32_t *srclen,uint32_t *destlen,void *model);
fec.c +5 -5
@@ -114,7 +114,7 @@ typedef unsigned short gf;* Primitive polynomials - see Lin & Costello, Appendix A, * and Lee & Messerschmitt, p. 453. */ -static char *allPp[] = {/* GF_BITS polynomial */ +static const char *allPp[] = {/* GF_BITS polynomial */ NULL ,/* 0 no code */ NULL ,/* 1 no code */ "111" ,/* 2 1+x+x^2 */
@@ -226,7 +226,7 @@ gf_mul(x,y)* one place. */ static void * -my_malloc (int sz,char *err_string) +my_malloc (int sz,const char *err_string) {void *p =malloc ( sz );if (p ==NULL ) {
@@ -247,7 +247,7 @@ generate_gf(void) {int i;gf mask; -char *Pp = allPp[GF_BITS ] ; +const char *Pp = allPp[GF_BITS ] ; mask =1 ;/* x ** 0 = 1 */ gf_exp[GF_BITS ] =0 ;/* will be updated at the end of the 1st loop */
@@ -792,7 +792,7 @@ shuffle(gf *pkt[], int index[], int k)* a vector of k*k elements, in row-major order */ static gf * -build_decode_matrix (struct fec_parms *code,gf *pkt[],int index[]) +build_decode_matrix (struct fec_parms *code,int index[]) {int i , k = code->k ;gf *p, *matrix =NEW_GF_MATRIX (k, k);
@@ -846,7 +846,7 @@ fec_decode(struct fec_parms *code, gf *pkt[], int index[], int sz)if (shuffle (pkt, index, k))/* error if true */ return 1 ; - m_dec =build_decode_matrix (code, pkt, index); + m_dec =build_decode_matrix (code, index);if (m_dec ==NULL )return 1 ;/* error */
flash_eraseall.c +5 -0
@@ -43,6 +43,11 @@#define PROGRAM "flash_eraseall"#define VERSION "$Revision: 1.22 $" +#define TRACE () do { \ + printf("trace: %s:%d: %p->%s\n", __FILE__, __LINE__, \ + __builtin_return_address(0), __func__); \ +} while(0) +static const char *exe_name;static const char *mtd_device;static int quiet;/* true -- don't output progress */
ftl_check.c +2 -2
@@ -79,7 +79,7 @@ static void print_size(u_int s)/*====================================================================*/ -static void check_partition (int fd,int verbose) +static void check_partition (int fd) {mtd_info_t mtd;erase_unit_header_t hdr, hdr2;
@@ -224,7 +224,7 @@ int main(int argc, char *argv[])exit (EXIT_FAILURE ); } -check_partition (fd, verbose); +check_partition (fd);close (fd);exit (EXIT_SUCCESS );
jffs2dump.c +18 -18
@@ -199,12 +199,12 @@ void do_dumpcontent (void) }if (p != p_free_begin) -printf ("Empty space found from 0x%08x to 0x%08x\n" , p_free_begin-data, p-data); +printf ("Empty space found from 0x%08lx to 0x%08lx\n" , p_free_begin-data, p-data); p_free_begin =NULL ;if (je16_to_cpu (node->u.magic) !=JFFS2_MAGIC_BITMASK ) {if (!bitchbitmask++) -printf ("Wrong bitmask at 0x%08x, 0x%04x\n" , p - data,je16_to_cpu (node->u.magic)); +printf ("Wrong bitmask at 0x%08lx, 0x%04x\n" , p - data,je16_to_cpu (node->u.magic)); p +=4 ; dirty +=4 ;continue ;
@@ -222,7 +222,7 @@ void do_dumpcontent (void) crc =crc32 (0 , node,sizeof (struct jffs2_unknown_node ) -4 );if (crc !=je32_to_cpu (node->u.hdr_crc)) { -printf ("Wrong hdr_crc at 0x%08x, 0x%08x instead of 0x%08x\n" , p - data,je32_to_cpu (node->u.hdr_crc), crc); +printf ("Wrong hdr_crc at 0x%08lx, 0x%08x instead of 0x%08x\n" , p - data,je32_to_cpu (node->u.hdr_crc), crc); p +=4 ; dirty +=4 ;continue ;
@@ -231,7 +231,7 @@ void do_dumpcontent (void)switch (je16_to_cpu (node->u.nodetype)) {case JFFS2_NODETYPE_INODE : - printf ("%8s Inode node at 0x%08x, totlen 0x%08x, #ino %5d, version %5d, isize %8d, csize %8d, dsize %8d, offset %8d\n", + printf ("%8s Inode node at 0x%08lx, totlen 0x%08x, #ino %5d, version %5d, isize %8d, csize %8d, dsize %8d, offset %8d\n", obsolete ? "Obsolete" : "", p - data, je32_to_cpu (node->i.totlen), je32_to_cpu (node->i.ino), je32_to_cpu ( node->i.version), je32_to_cpu (node->i.isize),
@@ -239,7 +239,7 @@ void do_dumpcontent (void) crc =crc32 (0 , node,sizeof (struct jffs2_raw_inode ) -8 );if (crc !=je32_to_cpu (node->i.node_crc)) { -printf ("Wrong node_crc at 0x%08x, 0x%08x instead of 0x%08x\n" , p - data,je32_to_cpu (node->i.node_crc), crc); +printf ("Wrong node_crc at 0x%08lx, 0x%08x instead of 0x%08x\n" , p - data,je32_to_cpu (node->i.node_crc), crc); p +=PAD (je32_to_cpu (node->i.totlen)); dirty +=PAD (je32_to_cpu (node->i.totlen));;continue ;
@@ -247,7 +247,7 @@ void do_dumpcontent (void) crc =crc32 (0 , p +sizeof (struct jffs2_raw_inode ),je32_to_cpu (node->i.csize));if (crc !=je32_to_cpu (node->i.data_crc)) { -printf ("Wrong data_crc at 0x%08x, 0x%08x instead of 0x%08x\n" , p - data,je32_to_cpu (node->i.data_crc), crc); +printf ("Wrong data_crc at 0x%08lx, 0x%08x instead of 0x%08x\n" , p - data,je32_to_cpu (node->i.data_crc), crc); p +=PAD (je32_to_cpu (node->i.totlen)); dirty +=PAD (je32_to_cpu (node->i.totlen));;continue ;
@@ -259,7 +259,7 @@ void do_dumpcontent (void)case JFFS2_NODETYPE_DIRENT :memcpy (name, node->d.name, node->d.nsize); name [node->d.nsize] =0x0 ; - printf ("%8s Dirent node at 0x%08x, totlen 0x%08x, #pino %5d, version %5d, #ino %8d, nsize %8d, name %s\n", + printf ("%8s Dirent node at 0x%08lx, totlen 0x%08x, #pino %5d, version %5d, #ino %8d, nsize %8d, name %s\n", obsolete ? "Obsolete" : "", p - data, je32_to_cpu (node->d.totlen), je32_to_cpu (node->d.pino), je32_to_cpu ( node->d.version), je32_to_cpu (node->d.ino),
@@ -267,7 +267,7 @@ void do_dumpcontent (void) crc =crc32 (0 , node,sizeof (struct jffs2_raw_dirent ) -8 );if (crc !=je32_to_cpu (node->d.node_crc)) { -printf ("Wrong node_crc at 0x%08x, 0x%08x instead of 0x%08x\n" , p - data,je32_to_cpu (node->d.node_crc), crc); +printf ("Wrong node_crc at 0x%08lx, 0x%08x instead of 0x%08x\n" , p - data,je32_to_cpu (node->d.node_crc), crc); p +=PAD (je32_to_cpu (node->d.totlen)); dirty +=PAD (je32_to_cpu (node->d.totlen));;continue ;
@@ -275,7 +275,7 @@ void do_dumpcontent (void) crc =crc32 (0 , p +sizeof (struct jffs2_raw_dirent ), node->d.nsize);if (crc !=je32_to_cpu (node->d.name_crc)) { -printf ("Wrong name_crc at 0x%08x, 0x%08x instead of 0x%08x\n" , p - data,je32_to_cpu (node->d.name_crc), crc); +printf ("Wrong name_crc at 0x%08lx, 0x%08x instead of 0x%08x\n" , p - data,je32_to_cpu (node->d.name_crc), crc); p +=PAD (je32_to_cpu (node->d.totlen)); dirty +=PAD (je32_to_cpu (node->d.totlen));;continue ;
@@ -289,7 +289,7 @@ void do_dumpcontent (void)int i;struct jffs2_sum_marker * sm; - printf("%8s Inode Sum node at 0x%08x, totlen 0x%08x, sum_num %5d, cleanmarker size %5d\n", + printf("%8s Inode Sum node at 0x%08lx, totlen 0x%08x, sum_num %5d, cleanmarker size %5d\n", obsolete ? "Obsolete" : "", p - data, je32_to_cpu (node->s.totlen),
@@ -298,7 +298,7 @@ void do_dumpcontent (void) crc =crc32 (0 , node,sizeof (struct jffs2_raw_summary ) -8 );if (crc !=je32_to_cpu (node->s.node_crc)) { -printf ("Wrong node_crc at 0x%08x, 0x%08x instead of 0x%08x\n" , p - data,je32_to_cpu (node->s.node_crc), crc); +printf ("Wrong node_crc at 0x%08lx, 0x%08x instead of 0x%08x\n" , p - data,je32_to_cpu (node->s.node_crc), crc); p +=PAD (je32_to_cpu (node->s.totlen)); dirty +=PAD (je32_to_cpu (node->s.totlen));;continue ;
@@ -306,7 +306,7 @@ void do_dumpcontent (void) crc =crc32 (0 , p +sizeof (struct jffs2_raw_summary ),je32_to_cpu (node->s.totlen) -sizeof (struct jffs2_raw_summary ));if (crc !=je32_to_cpu (node->s.sum_crc)) { -printf ("Wrong data_crc at 0x%08x, 0x%08x instead of 0x%08x\n" , p - data,je32_to_cpu (node->s.sum_crc), crc); +printf ("Wrong data_crc at 0x%08lx, 0x%08x instead of 0x%08x\n" , p - data,je32_to_cpu (node->s.sum_crc), crc); p +=PAD (je32_to_cpu (node->s.totlen)); dirty +=PAD (je32_to_cpu (node->s.totlen));;continue ;
@@ -379,7 +379,7 @@ void do_dumpcontent (void)case JFFS2_NODETYPE_CLEANMARKER :if (verbose) { -printf ("%8s Cleanmarker at 0x%08x, totlen 0x%08x\n" , +printf ("%8s Cleanmarker at 0x%08lx, totlen 0x%08x\n" , obsolete ?"Obsolete" :"" , p - data,je32_to_cpu (node->u.totlen)); }
@@ -388,7 +388,7 @@ void do_dumpcontent (void)case JFFS2_NODETYPE_PADDING :if (verbose) { -printf ("%8s Padding node at 0x%08x, totlen 0x%08x\n" , +printf ("%8s Padding node at 0x%08lx, totlen 0x%08x\n" , obsolete ?"Obsolete" :"" , p - data,je32_to_cpu (node->u.totlen)); }
@@ -402,7 +402,7 @@ void do_dumpcontent (void)default :if (verbose) { -printf ("%8s Unknown node at 0x%08x, totlen 0x%08x\n" , +printf ("%8s Unknown node at 0x%08lx, totlen 0x%08x\n" , obsolete ?"Obsolete" :"" , p - data,je32_to_cpu (node->u.totlen)); }
@@ -444,7 +444,7 @@ void do_endianconvert (void) }if (je16_to_cpu (node->u.magic) !=JFFS2_MAGIC_BITMASK ) { -printf ("Wrong bitmask at 0x%08x, 0x%04x\n" , p - data,je16_to_cpu (node->u.magic)); +printf ("Wrong bitmask at 0x%08lx, 0x%04x\n" , p - data,je16_to_cpu (node->u.magic)); newnode.u.magic =cnv_e16 (node->u.magic); newnode.u.nodetype =cnv_e16 (node->u.nodetype);write (fd, &newnode,4 );
@@ -454,7 +454,7 @@ void do_endianconvert (void) crc =crc32 (0 , node,sizeof (struct jffs2_unknown_node ) -4 );if (crc !=je32_to_cpu (node->u.hdr_crc)) { -printf ("Wrong hdr_crc at 0x%08x, 0x%08x instead of 0x%08x\n" , p - data,je32_to_cpu (node->u.hdr_crc), crc); +printf ("Wrong hdr_crc at 0x%08lx, 0x%08x instead of 0x%08x\n" , p - data,je32_to_cpu (node->u.hdr_crc), crc); }switch (je16_to_cpu (node->u.nodetype)) {
@@ -619,7 +619,7 @@ void do_endianconvert (void)break ;default : -printf ("Unknown node type: 0x%04x at 0x%08x, totlen 0x%08x\n" ,je16_to_cpu (node->u.nodetype), p - data,je32_to_cpu (node->u.totlen)); +printf ("Unknown node type: 0x%04x at 0x%08lx, totlen 0x%08x\n" ,je16_to_cpu (node->u.nodetype), p - data,je32_to_cpu (node->u.totlen)); p +=PAD (je32_to_cpu (node->u.totlen)); }
mkfs.jffs2.c +12 -11
@@ -1089,7 +1089,7 @@ static uint32_t highest_xseqno = 0;static struct {int xprefix; -char *string; +const char *string;int length; } xprefix_tbl[] = { {JFFS2_XPREFIX_USER ,XATTR_USER_PREFIX ,XATTR_USER_PREFIX_LEN },
@@ -1231,7 +1231,8 @@ static void write_xattr_entry(struct filesystem_entry *e)struct jffs2_raw_xref ref;struct xattr_entry *xe;char xlist[XATTR_BUFFER_SIZE ], xvalue[XATTR_BUFFER_SIZE ]; -char *xname, *prefix_str; +char *xname; +const char *prefix_str;int i, xprefix, prefix_len;int list_sz, offset, name_len, value_len;
@@ -1479,7 +1480,7 @@ static struct option long_options[] = { {NULL, 0, NULL, 0} }; -static char *helptext = +static const char *helptext ="Usage: mkfs.jffs2 [OPTIONS]\n" "Make a JFFS2 file system image from an existing directory tree\n\n" "Options:\n"
@@ -1518,7 +1519,7 @@ static char *helptext =" -V, --version Display version information\n" " -i, --incremental=FILE Parse FILE and generate appendage output for it\n\n" ; -static char *revtext ="1.60" ; +static const char *revtext ="1.60" ;int load_next_block () {
@@ -1552,7 +1553,7 @@ void process_buffer(int inp_size) {if (je16_to_cpu (node->u.magic) !=JFFS2_MAGIC_BITMASK ) {if (!bitchbitmask++) -printf ("Wrong bitmask at 0x%08x, 0x%04x\n" , p - file_buffer,je16_to_cpu (node->u.magic)); +printf ("Wrong bitmask at 0x%08lx, 0x%04x\n" , p - file_buffer,je16_to_cpu (node->u.magic)); p +=4 ;continue ; }
@@ -1572,7 +1573,7 @@ void process_buffer(int inp_size) {case JFFS2_NODETYPE_INODE :if (verbose) - printf ("%8s Inode node at 0x%08x, totlen 0x%08x, #ino %5d, version %5d, isize %8d, csize %8d, dsize %8d, offset %8d\n", + printf ("%8s Inode node at 0x%08lx, totlen 0x%08x, #ino %5d, version %5d, isize %8d, csize %8d, dsize %8d, offset %8d\n", obsolete ? "Obsolete" : "", p - file_buffer, je32_to_cpu (node->i.totlen), je32_to_cpu (node->i.ino), je32_to_cpu ( node->i.version), je32_to_cpu (node->i.isize),
@@ -1589,7 +1590,7 @@ void process_buffer(int inp_size) { name [node->d.nsize] =0x0 ;if (verbose) - printf ("%8s Dirent node at 0x%08x, totlen 0x%08x, #pino %5d, version %5d, #ino %8d, nsize %8d, name %s\n", + printf ("%8s Dirent node at 0x%08lx, totlen 0x%08x, #pino %5d, version %5d, #ino %8d, nsize %8d, name %s\n", obsolete ? "Obsolete" : "", p - file_buffer, je32_to_cpu (node->d.totlen), je32_to_cpu (node->d.pino), je32_to_cpu ( node->d.version), je32_to_cpu (node->d.ino),
@@ -1600,7 +1601,7 @@ void process_buffer(int inp_size) {case JFFS2_NODETYPE_CLEANMARKER :if (verbose) { -printf ("%8s Cleanmarker at 0x%08x, totlen 0x%08x\n" , +printf ("%8s Cleanmarker at 0x%08lx, totlen 0x%08x\n" , obsolete ?"Obsolete" :"" , p - file_buffer,je32_to_cpu (node->u.totlen)); }
@@ -1610,7 +1611,7 @@ void process_buffer(int inp_size) {case JFFS2_NODETYPE_PADDING :if (verbose) { -printf ("%8s Padding node at 0x%08x, totlen 0x%08x\n" , +printf ("%8s Padding node at 0x%08lx, totlen 0x%08x\n" , obsolete ?"Obsolete" :"" , p - file_buffer,je32_to_cpu (node->u.totlen)); }
@@ -1624,7 +1625,7 @@ void process_buffer(int inp_size) {default :if (verbose) { -printf ("%8s Unknown node at 0x%08x, totlen 0x%08x\n" , +printf ("%8s Unknown node at 0x%08lx, totlen 0x%08x\n" , obsolete ?"Obsolete" :"" , p - file_buffer,je32_to_cpu (node->u.totlen)); }
@@ -1878,7 +1879,7 @@ int main(int argc, char **argv)if (in_fd !=-1 )parse_image (); - root =recursive_add_host_directory (NULL ,"/" , cwd); + root =recursive_add_host_directory (NULL , (char *)"/" , cwd);if (devtable)parse_device_table (root, devtable);
mtd_debug.c +1 -1
@@ -158,7 +158,7 @@ retry:if (buf !=NULL )free (buf);close (outfd); -printf ("Copied %d bytes from address 0x%.8x in flash to %s\n" ,len,offset,filename); +printf ("Copied %zd bytes from address 0x%.8x in flash to %s\n" ,len,offset,filename);return (0 ); err2:
nandtest.c +3 -3
@@ -70,7 +70,7 @@ int erase_and_write(loff_t ofs, unsigned char *data, unsigned char *rbuf) }if (len < meminfo.erasesize) {printf ("\n" ); -fprintf (stderr,"Short write (%d bytes)\n" , len); +fprintf (stderr,"Short write (%zd bytes)\n" , len);exit (1 ); }
@@ -81,7 +81,7 @@ int erase_and_write(loff_t ofs, unsigned char *data, unsigned char *rbuf)if (len < meminfo.erasesize) {printf ("\n" );if (len) -fprintf (stderr,"Short read (%d bytes)\n" , len); +fprintf (stderr,"Short read (%zd bytes)\n" , len);else perror ("read" );exit (1 );
@@ -263,7 +263,7 @@ int main(int argc, char **argv)if (len < meminfo.erasesize) {printf ("\n" );if (len) -fprintf (stderr,"Short read (%d bytes)\n" , len); +fprintf (stderr,"Short read (%zd bytes)\n" , len);else perror ("read" );exit (1 );
nandwrite.c +0 -1
@@ -260,7 +260,6 @@ int main(int argc, char * const argv[])int ret, readlen;int oobinfochanged =0 ;struct nand_oobinfo old_oobinfo; -int readcnt =0 ;bool failed = true;process_options (argc, argv);
nftl_format.c +2 -1
@@ -202,7 +202,8 @@ int main(int argc, char **argv)long MediaUnitOff1 =0 , MediaUnitOff2 =0 ;unsigned char oobbuf[16 ];struct mtd_oob_buf oob = {0 ,16 , oobbuf}; -char *mtddevice, *nftl; +char *mtddevice; +const char *nftl;int c, do_inftl =0 , do_bbt =0 ;
recv_image.c +2 -2
@@ -39,7 +39,7 @@ int main(int argc, char **argv)struct addrinfo *runp;int ret;int sock; -size_t len; +ssize_t len;int flfd;struct mtd_info_user meminfo;unsigned char *eb_buf, *decode_buf, **src_pkts;
@@ -166,7 +166,7 @@ int main(int argc, char **argv)break ; }if (len <sizeof (thispkt)) { -fprintf (stderr,"Wrong length %d bytes (expected %d)\n" , +fprintf (stderr,"Wrong length %zd bytes (expected %ld)\n" , len,sizeof (thispkt));continue ; }
sumtool.c +19 -19
@@ -73,7 +73,7 @@ static unsigned int file_ofs = 0; /* position in the buffer */int target_endian = __BYTE_ORDER; -static struct option long_options[] = { +static const struct option long_options[] = { {"output" ,1 ,NULL ,'o' }, {"input" ,1 ,NULL ,'i' }, {"eraseblock" ,1 ,NULL ,'e' },
@@ -88,7 +88,7 @@ static struct option long_options[] = { {NULL, 0, NULL, 0} }; -static char *helptext = +static const char *helptext ="Usage: sumtool [OPTIONS] -i inputfile -o outputfile\n\n" "Convert the input JFFS2 image to a summarized JFFS2 image\n" "Summary makes mounting faster - if summary support enabled in your kernel\n\n"
@@ -112,7 +112,7 @@ static char *helptext =" eraseblock\n\n" ; -static char *revtext ="$Revision: 1.9 $" ; +static const char *revtext ="$Revision: 1.9 $" ;static unsigned char ffbuf[16 ] = {0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,
@@ -740,7 +740,7 @@ void create_summed_image(int inp_size)if (je16_to_cpu (node->u.magic) !=JFFS2_MAGIC_BITMASK ) {if (!bitchbitmask++) -printf ("Wrong bitmask at 0x%08x, 0x%04x\n" , p - file_buffer,je16_to_cpu (node->u.magic)); +printf ("Wrong bitmask at 0x%08lx, 0x%04x\n" , p - file_buffer,je16_to_cpu (node->u.magic)); p +=4 ;continue ; }
@@ -759,7 +759,7 @@ void create_summed_image(int inp_size) crc =crc32 (0 , node,sizeof (struct jffs2_unknown_node ) -4 );if (crc !=je32_to_cpu (node->u.hdr_crc)) { -printf ("Wrong hdr_crc at 0x%08x, 0x%08x instead of 0x%08x\n" , p - file_buffer,je32_to_cpu (node->u.hdr_crc), crc); +printf ("Wrong hdr_crc at 0x%08lx, 0x%08x instead of 0x%08x\n" , p - file_buffer,je32_to_cpu (node->u.hdr_crc), crc); p +=4 ;continue ; }
@@ -767,7 +767,7 @@ void create_summed_image(int inp_size)switch (je16_to_cpu (node->u.nodetype)) {case JFFS2_NODETYPE_INODE :if (verbose) - printf ("%8s Inode node at 0x%08x, totlen 0x%08x, #ino %5d, version %5d, isize %8d, csize %8d, dsize %8d, offset %8d\n", + printf ("%8s Inode node at 0x%08lx, totlen 0x%08x, #ino %5d, version %5d, isize %8d, csize %8d, dsize %8d, offset %8d\n", obsolete ? "Obsolete" : "", p - file_buffer, je32_to_cpu (node->i.totlen), je32_to_cpu (node->i.ino), je32_to_cpu ( node->i.version), je32_to_cpu (node->i.isize),
@@ -775,14 +775,14 @@ void create_summed_image(int inp_size) crc =crc32 (0 , node,sizeof (struct jffs2_raw_inode ) -8 );if (crc !=je32_to_cpu (node->i.node_crc)) { -printf ("Wrong node_crc at 0x%08x, 0x%08x instead of 0x%08x\n" , p - file_buffer,je32_to_cpu (node->i.node_crc), crc); +printf ("Wrong node_crc at 0x%08lx, 0x%08x instead of 0x%08x\n" , p - file_buffer,je32_to_cpu (node->i.node_crc), crc); p +=PAD (je32_to_cpu (node->i.totlen));continue ; } crc =crc32 (0 , p +sizeof (struct jffs2_raw_inode ),je32_to_cpu (node->i.csize));if (crc !=je32_to_cpu (node->i.data_crc)) { -printf ("Wrong data_crc at 0x%08x, 0x%08x instead of 0x%08x\n" , p - file_buffer,je32_to_cpu (node->i.data_crc), crc); +printf ("Wrong data_crc at 0x%08lx, 0x%08x instead of 0x%08x\n" , p - file_buffer,je32_to_cpu (node->i.data_crc), crc); p +=PAD (je32_to_cpu (node->i.totlen));continue ; }
@@ -797,7 +797,7 @@ void create_summed_image(int inp_size) name [node->d.nsize] =0x0 ;if (verbose) - printf ("%8s Dirent node at 0x%08x, totlen 0x%08x, #pino %5d, version %5d, #ino %8d, nsize %8d, name %s\n", + printf ("%8s Dirent node at 0x%08lx, totlen 0x%08x, #pino %5d, version %5d, #ino %8d, nsize %8d, name %s\n", obsolete ? "Obsolete" : "", p - file_buffer, je32_to_cpu (node->d.totlen), je32_to_cpu (node->d.pino), je32_to_cpu ( node->d.version), je32_to_cpu (node->d.ino),
@@ -805,14 +805,14 @@ void create_summed_image(int inp_size) crc =crc32 (0 , node,sizeof (struct jffs2_raw_dirent ) -8 );if (crc !=je32_to_cpu (node->d.node_crc)) { -printf ("Wrong node_crc at 0x%08x, 0x%08x instead of 0x%08x\n" , p - file_buffer,je32_to_cpu (node->d.node_crc), crc); +printf ("Wrong node_crc at 0x%08lx, 0x%08x instead of 0x%08x\n" , p - file_buffer,je32_to_cpu (node->d.node_crc), crc); p +=PAD (je32_to_cpu (node->d.totlen));continue ; } crc =crc32 (0 , p +sizeof (struct jffs2_raw_dirent ), node->d.nsize);if (crc !=je32_to_cpu (node->d.name_crc)) { -printf ("Wrong name_crc at 0x%08x, 0x%08x instead of 0x%08x\n" , p - file_buffer,je32_to_cpu (node->d.name_crc), crc); +printf ("Wrong name_crc at 0x%08lx, 0x%08x instead of 0x%08x\n" , p - file_buffer,je32_to_cpu (node->d.name_crc), crc); p +=PAD (je32_to_cpu (node->d.totlen));continue ; }
@@ -826,14 +826,14 @@ void create_summed_image(int inp_size)if (je32_to_cpu (node->x.node_crc) ==0xffffffff ) obsolete =1 ;if (verbose) -printf ("%8s Xdatum node at 0x%08x, totlen 0x%08x, " +printf ("%8s Xdatum node at 0x%08lx, totlen 0x%08x, " "#xid %5u, version %5u\n" , obsolete ?"Obsolete" :"" , p - file_buffer,je32_to_cpu (node->x.totlen),je32_to_cpu (node->x.xid),je32_to_cpu (node->x.version)); crc =crc32 (0 , node,sizeof (struct jffs2_raw_xattr ) -4 );if (crc !=je32_to_cpu (node->x.node_crc)) { -printf ("Wrong node_crc at 0x%08x, 0x%08x instead of 0x%08x\n" , +printf ("Wrong node_crc at 0x%08lx, 0x%08x instead of 0x%08x\n" , p - file_buffer,je32_to_cpu (node->x.node_crc), crc); p +=PAD (je32_to_cpu (node->x.totlen));continue ;
@@ -841,7 +841,7 @@ void create_summed_image(int inp_size) length = node->x.name_len +1 +je16_to_cpu (node->x.value_len); crc =crc32 (0 , node->x.data, length);if (crc !=je32_to_cpu (node->x.data_crc)) { -printf ("Wrong data_crc at 0x%08x, 0x%08x instead of 0x%08x\n" , +printf ("Wrong data_crc at 0x%08lx, 0x%08x instead of 0x%08x\n" , p - file_buffer,je32_to_cpu (node->x.data_crc), crc); p +=PAD (je32_to_cpu (node->x.totlen));continue ;
@@ -855,14 +855,14 @@ void create_summed_image(int inp_size)if (je32_to_cpu (node->r.node_crc) ==0xffffffff ) obsolete =1 ;if (verbose) -printf ("%8s Xref node at 0x%08x, totlen 0x%08x, " +printf ("%8s Xref node at 0x%08lx, totlen 0x%08x, " "#ino %5u, xid %5u\n" , obsolete ?"Obsolete" :"" , p - file_buffer,je32_to_cpu (node->r.totlen),je32_to_cpu (node->r.ino),je32_to_cpu (node->r.xid)); crc =crc32 (0 , node,sizeof (struct jffs2_raw_xref ) -4 );if (crc !=je32_to_cpu (node->r.node_crc)) { -printf ("Wrong node_crc at 0x%08x, 0x%08x instead of 0x%08x\n" , +printf ("Wrong node_crc at 0x%08lx, 0x%08x instead of 0x%08x\n" , p - file_buffer,je32_to_cpu (node->r.node_crc), crc); p +=PAD (je32_to_cpu (node->r.totlen));continue ;
@@ -874,7 +874,7 @@ void create_summed_image(int inp_size)case JFFS2_NODETYPE_CLEANMARKER :if (verbose) { -printf ("%8s Cleanmarker at 0x%08x, totlen 0x%08x\n" , +printf ("%8s Cleanmarker at 0x%08lx, totlen 0x%08x\n" , obsolete ?"Obsolete" :"" , p - file_buffer,je32_to_cpu (node->u.totlen)); }
@@ -893,7 +893,7 @@ void create_summed_image(int inp_size)case JFFS2_NODETYPE_PADDING :if (verbose) { -printf ("%8s Padding node at 0x%08x, totlen 0x%08x\n" , +printf ("%8s Padding node at 0x%08lx, totlen 0x%08x\n" , obsolete ?"Obsolete" :"" , p - file_buffer,je32_to_cpu (node->u.totlen)); }
@@ -906,7 +906,7 @@ void create_summed_image(int inp_size)default :if (verbose) { -printf ("%8s Unknown node at 0x%08x, totlen 0x%08x\n" , +printf ("%8s Unknown node at 0x%08lx, totlen 0x%08x\n" , obsolete ?"Obsolete" :"" , p - file_buffer,je32_to_cpu (node->u.totlen)); }
PATCH 1/1 Support large devices for flash_eraseaal
The mtd-abi.h bits may be wrong, not sure. Otherwise it allows me to erase a large device. No guarantees beyond that.
Jörn
Signature · 6 lines
Happiness isn't having what you want, it's wanting what you have. -- unknown flash_eraseall.c | 88 +++++++++++++++++++++++++++++++++++++++++-------- include/mtd/mtd-abi.h | 89 +++++++++++++++++++++++++++++--------------------- 2 files changed, 126 insertions(+), 51 deletions(-)
flash_eraseall.c +74 -14
@@ -48,33 +48,93 @@ static const char *mtd_device;static int quiet;/* true -- don't output progress */ static int jffs2;// format for jffs2 usage +struct mtd_info_user64 { +uint8_t type; +uint32_t flags; +uint64_t size;// Total size of the MTD +uint32_t erasesize; +uint32_t writesize; +uint32_t oobsize;// Amount of OOB data per block (e.g. 16) +/* The below two fields are obsolete and broken, do not use them +* (TODO: remove at some point) */ +uint32_t ecctype; +uint32_t eccsize; +}; +static void process_options (int argc,char *argv[]); -void show_progress (mtd_info_t *meminfo,erase_info_t *erase); +void show_progress (struct mtd_info_user64 *meminfo,struct erase_info_user64 *erase);static void display_help (void );static void display_version (void );static struct jffs2_unknown_node cleanmarker;int target_endian = __BYTE_ORDER; +static int get_info (const char *devname,struct mtd_info_user64 *mtd64) +{ +struct mtd_info_user mtd; +char buf[256 ]; +int fd; + +if ((fd =open (devname,O_RDWR )) <0 ) { +fprintf (stderr,"%s: %s: %s\n" , exe_name, devname,strerror (errno)); +return 1 ; + } + + +if (ioctl (fd,MEMGETINFO , &mtd) !=0 ) { +fprintf (stderr,"%s: %s: unable to get MTD device info\n" , exe_name, devname); +return 1 ; + } +close (fd); + + mtd64->type = mtd.type; + mtd64->flags = mtd.flags; + mtd64->size = mtd.size; + mtd64->erasesize = mtd.erasesize; + mtd64->writesize = mtd.writesize; + mtd64->oobsize = mtd.oobsize; + mtd64->ecctype = mtd.ecctype; + mtd64->eccsize = mtd.eccsize; + +/* I'm glad I only have to do this for one parameter. */ +sprintf (buf,"/sys/class/mtd/%s/size" ,basename ((char *)devname)); + fd =open (buf,O_RDONLY ); +if (fd <0 ) +return 0 ; +read (fd, buf,256 ); + mtd64->size =strtoull (buf,NULL ,0 ); +close (fd); +return 0 ; +} + +static int do_erase (int fd,struct erase_info_user64 *ei64,struct mtd_info_user64 *mtd64) +{ +struct erase_info_user ei; + +if (mtd64->size >=0x100000000ull ) +return ioctl (fd,MEMERASE64 , ei64); +else { + ei.start = ei64->start; + ei.length = ei64->length; +return ioctl (fd,MEMERASE , &ei); + } +} +int main (int argc,char *argv[]) { -mtd_info_t meminfo; +struct mtd_info_user64 meminfo;int fd, clmpos =0 , clmlen =8 ; -erase_info_t erase; +struct erase_info_user64 erase;int isNAND, bbtest =1 ;process_options (argc, argv); +if (get_info (mtd_device, &meminfo)) +return 1 ;if ((fd =open (mtd_device,O_RDWR )) <0 ) {fprintf (stderr,"%s: %s: %s\n" , exe_name, mtd_device,strerror (errno));return 1 ; } - -if (ioctl (fd,MEMGETINFO , &meminfo) !=0 ) { -fprintf (stderr,"%s: %s: unable to get MTD device info\n" , exe_name, mtd_device); -return 1 ; - } - erase.length = meminfo.erasesize; isNAND = meminfo.type ==MTD_NANDFLASH ?1 :0 ;
@@ -130,7 +190,7 @@ int main (int argc, char *argv[])int ret =ioctl (fd,MEMGETBADBLOCK , &offset);if (ret >0 ) {if (!quiet) -printf ("\nSkipping bad block at 0x%08x\n" , erase.start); +printf ("\nSkipping bad block at 0x%08llx\n" , erase.start);continue ; }else if (ret <0 ) {if (errno ==EOPNOTSUPP ) {
@@ -149,7 +209,7 @@ int main (int argc, char *argv[])if (!quiet)show_progress (&meminfo, &erase); -if (ioctl (fd,MEMERASE , &erase) !=0 ) { +if (do_erase (fd, &erase, &meminfo) !=0 ) {fprintf (stderr,"\n%s: %s: MTD Erase failure: %s\n" , exe_name, mtd_device,strerror (errno));continue ; }
@@ -179,7 +239,7 @@ int main (int argc, char *argv[]) } }if (!quiet) -printf (" Cleanmarker written at %x." , erase.start); +printf (" Cleanmarker written at %llx." , erase.start); }if (!quiet) {show_progress (&meminfo, &erase);
@@ -250,9 +310,9 @@ void process_options (int argc, char *argv[]) mtd_device = argv[optind]; } -void show_progress (mtd_info_t *meminfo,erase_info_t *erase) +void show_progress (struct mtd_info_user64 *meminfo,struct erase_info_user64 *erase) { -printf ("\rErasing %d Kibyte @ %x -- %2llu %% complete." , +printf ("\rErasing %d Kibyte @ %llx -- %2llu %% complete." , meminfo->erasesize /1024 , erase->start, (unsigned long long ) erase->start *100 / meminfo->size);fflush (stdout);
include/mtd/mtd-abi.h +52 -37
160 lines not on this page · raw message
Re: [Patch] Support large devices for flash_eraseaal
flash_eraseall.c static const char *mtd_device; · line 109
Quoted 3 lines · Jörn Engel
flash_eraseall.c +2
-0+static int get_info(const char *devname, struct mtd_info_user64 *mtd64) +static int do_erase(int fd, struct erase_info_user64 *ei64, struct mtd_info_user64 *mtd64)
Thinking about it, these two functions probably ought to go into a library of some sorts. I just used flash_eraseall as a proof-of-concept test program, so my interest in this area is exhausted. But maybe someone else feels young and energetic. :)
Jörn
Signature · 2 lines
Sometimes, asking the right question is already the answer. -- Unknown
Re: [Patch] Support large devices for flash_eraseaal
Quoted 9 lines · Jörn Engel
flash_eraseall.c static const char *mtd_device; · line 109
Quoted 3 lines · Jörn Engel
flash_eraseall.c +2
-0+static int get_info(const char *devname, struct mtd_info_user64 *mtd64) +static int do_erase(int fd, struct erase_info_user64 *ei64, struct mtd_info_user64 *mtd64)Thinking about it, these two functions probably ought to go into a library of some sorts. I just used
flash_eraseallas a proof-of-concept test program, so my interest in this area is exhausted. But maybe someone else feels young and energetic. :)
In ubi-utils I created libmtd library. It can be used in other places as well.
Signature · 2 lines
Best regards, Artem Bityutskiy (Битюцкий Артём)