mtd-utils: update to latest mtd-abi.h from kernel.org
Subsystems (2)
PATCH v5 1/3 mtd-utils: update to latest mtd-abi.h from kernel.org
--- include/mtd/mtd-abi.h | 89 ++++++++++++++++++++++++++++-------------------- 1 files changed, 52 insertions(+), 37 deletions(-)
include/mtd/mtd-abi.h +52 -37
@@ -1,23 +1,35 @@/* -* $Id: mtd-abi.h,v 1.13 2005/11/07 11:14:56 gleixner Exp $ -* * Portions of MTD ABI definition which are shared by kernel and user space */ #ifndef __MTD_ABI_H__#define __MTD_ABI_H__ +#include <linux/types.h> +struct erase_info_user { -uint32_t start; -uint32_t length; +__u32 start; +__u32 length; +}; + +struct erase_info_user64 { +__u64 start; +__u64 length; };struct mtd_oob_buf { -uint32_t start; -uint32_t length; +__u32 start; +__u32 length;unsigned char *ptr; }; +struct mtd_oob_buf64 { +__u64 start; +__u32 pad; +__u32 length; +__u64 usr_ptr; +}; +#define MTD_ABSENT 0#define MTD_RAM 1#define MTD_ROM 2
@@ -29,7 +41,7 @@ struct mtd_oob_buf {#define MTD_WRITEABLE 0x400/* Device is writeable */ #define MTD_BIT_WRITEABLE 0x800/* Single bits can be flipped */ #define MTD_NO_ERASE 0x1000/* No erase necessary */ -#define MTD_STUPID_LOCK 0x2000/* Always locked after reset */ +#define MTD_POWERUP_LOCK 0x2000/* Always locked after reset */ // Some common devices / combinations of capabilities #define MTD_CAP_ROM 0
@@ -50,30 +62,30 @@ struct mtd_oob_buf {#define MTD_OTP_USER 2struct mtd_info_user { -uint8_t type; -uint32_t flags; -uint32_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) +__u8 type; +__u32 flags; +__u32 size;// Total size of the MTD +__u32 erasesize; +__u32 writesize; +__u32 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; +__u32 ecctype; +__u32 eccsize; };struct region_info_user { -uint32_t offset;/* At which this region starts, +__u32 offset;/* At which this region starts, * from the beginning of the MTD */ -uint32_t erasesize;/* For this region */ -uint32_t numblocks;/* Number of blocks in this region */ -uint32_t regionindex; +__u32 erasesize;/* For this region */ +__u32 numblocks;/* Number of blocks in this region */ +__u32 regionindex; };struct otp_info { -uint32_t start; -uint32_t length; -uint32_t locked; +__u32 start; +__u32 length; +__u32 locked; };#define MEMGETINFO _IOR('M', 1, struct mtd_info_user)
@@ -86,8 +98,8 @@ struct otp_info {#define MEMGETREGIONINFO _IOWR('M', 8, struct region_info_user)#define MEMSETOOBSEL _IOW('M', 9, struct nand_oobinfo)#define MEMGETOOBSEL _IOR('M', 10, struct nand_oobinfo) -#define MEMGETBADBLOCK _IOW('M', 11, loff_t) -#define MEMSETBADBLOCK _IOW('M', 12, loff_t) +#define MEMGETBADBLOCK _IOW('M', 11, __kernel_loff_t) +#define MEMSETBADBLOCK _IOW('M', 12, __kernel_loff_t)#define OTPSELECT _IOR('M', 13, int)#define OTPGETREGIONCOUNT _IOW('M', 14, int)#define OTPGETREGIONINFO _IOW('M', 15, struct otp_info)
@@ -95,21 +107,24 @@ struct otp_info {#define ECCGETLAYOUT _IOR('M', 17, struct nand_ecclayout)#define ECCGETSTATS _IOR('M', 18, struct mtd_ecc_stats)#define MTDFILEMODE _IO('M', 19) +#define MEMERASE64 _IOW('M', 20, struct erase_info_user64) +#define MEMWRITEOOB64 _IOWR('M', 21, struct mtd_oob_buf64) +#define MEMREADOOB64 _IOWR('M', 22, struct mtd_oob_buf64)/* * Obsolete legacy interface. Keep it in order not to break userspace * interfaces */ struct nand_oobinfo { -uint32_t useecc; -uint32_t eccbytes; -uint32_t oobfree[8 ][2 ]; -uint32_t eccpos[32 ]; +__u32 useecc; +__u32 eccbytes; +__u32 oobfree[8 ][2 ]; +__u32 eccpos[32 ]; };struct nand_oobfree { -uint32_t offset; -uint32_t length; +__u32 offset; +__u32 length; };#define MTD_MAX_OOBFREE_ENTRIES 8
@@ -118,9 +133,9 @@ struct nand_oobfree {* diagnosis and to allow creation of raw images */ struct nand_ecclayout { -uint32_t eccbytes; -uint32_t eccpos[64 ]; -uint32_t oobavail; +__u32 eccbytes; +__u32 eccpos[64 ]; +__u32 oobavail;struct nand_oobfree oobfree[MTD_MAX_OOBFREE_ENTRIES ]; };
@@ -133,10 +148,10 @@ struct nand_ecclayout {* @bbtblocks: number of blocks reserved for bad block tables */ struct mtd_ecc_stats { -uint32_t corrected; -uint32_t failed; -uint32_t badblocks; -uint32_t bbtblocks; +__u32 corrected; +__u32 failed; +__u32 badblocks; +__u32 bbtblocks; };/*
Signature · 1 line
1.6.5
PATCH v5 3/3 mtd-utils: clean up compiler warnings
Seen on gcc 4.2.4 IA32:
flashcp.c:255:2: warning: #warning "Check for smaller erase regions"
nftl_format.c:214: warning: assignment discards qualifiers from pointer target type nftl_format.c:219: warning: assignment discards qualifiers from pointer target type serve_image.c:129: warning: format ‘%ld’ expects type ‘long int’, but argument 3 has type ‘__off64_t’ fec.c:120: warning: initialization discards qualifiers from pointer target type
<many more of these>
fec.c:417: warning: passing argument 2 of ‘my_malloc’ discards qualifiers from pointer target type <many more of these>
recv_image.c:164: warning: comparison of unsigned expression < 0 is always false
recv_image.c:59: warning: ‘start_seq’ may be used uninitialized in this function recv_image.c:56: warning: ‘fec’ may be used uninitialized in this function
recv_image.c:49: warning: ‘image_crc’ may be used uninitialized in this function
sumtool.c:112: warning: initialization discards qualifiers from pointer target type
sumtool.c:115: warning: initialization discards qualifiers from pointer target type mkfs.ubifs.c:1171: warning: format ‘%lu’ expects type ‘long unsigned int’, but argument 4 has type ‘ino_t’ mkfs.ubifs.c:1171: warning: format ‘%lu’ expects type ‘long unsigned int’, but argument 6 has type ‘ino_t’
--- fec.c | 6 +++--- mkfs.ubifs/mkfs.ubifs.c | 4 ++-- nftl_format.c | 3 ++- recv_image.c | 8 ++++---- serve_image.c | 5 +++-- sumtool.c | 4 ++-- 6 files changed, 16 insertions(+), 14 deletions(-)
fec.c +3 -3
@@ -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 */
mkfs.ubifs/mkfs.ubifs.c +2 -2
@@ -1168,8 +1168,8 @@ static int add_dent_node(ino_t dir_inum, const char *name, ino_t inum,char *kname;int len; -dbg_msg (3 ,"%s ino %lu type %u dir ino %lu" , name, inum, - (unsigned )type, dir_inum); +dbg_msg (3 ,"%s ino %lu type %u dir ino %lu" , name, (unsigned long )inum, + (unsigned )type, (unsigned long )dir_inum);memset (dent,0 ,UBIFS_DENT_NODE_SZ ); dname.name = (void *)name;
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 +4 -4
@@ -39,24 +39,24 @@ 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;int nr_blocks =0 ;int pkts_per_block;int block_nr =-1 ; -uint32_t image_crc; +uint32_t image_crc =0 ;int total_pkts =0 ;int ignored_pkts =0 ;loff_t mtdoffset =0 ;int badcrcs =0 ;int duplicates =0 ;int file_mode =0 ; -struct fec_parms *fec; +struct fec_parms *fec =NULL ;int i;struct eraseblock *eraseblocks =NULL ; -uint32_t start_seq; +uint32_t start_seq =0 ;struct timeval start, now;unsigned long fec_time =0 , flash_time =0 , crc_time =0 , rflash_time =0 , erase_time =0 , net_time =0 ;
serve_image.c +3 -2
@@ -125,8 +125,9 @@ int main(int argc, char **argv) }if (st.st_size % erasesize) { -fprintf (stderr,"Image size %ld bytes is not a multiple of erasesize %d bytes\n" , - st.st_size, erasesize); +fprintf (stderr,"Image size %lld bytes is not a multiple " +"of erasesize %d bytes\n" , + (long long )st.st_size, erasesize);exit (1 ); } image =mmap (NULL , st.st_size,PROT_READ ,MAP_PRIVATE , rfd,0 );
sumtool.c +2 -2
@@ -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 ,
Signature · 1 line
1.6.5
PATCH v5 2/3 mtd-utils: support >4GiB devices
In reply to Kevin CernekeeThis patch updates the following programs to handle >4GiB flash devices:
flash_eraseflash_eraseall
flashcpmtd_debug
nanddump
nandtest
nandwrite
It also lays the groundwork for >4GiB support in:
flash_lockflash_unlock
The latter two utilities would require MEMLOCK64 / MEMUNLOCK64 functionality on the kernel side (currently unimplemented). For now they still use MEMLOCK / MEMUNLOCK and cannot access blocks above 4GiB.
By default, the compatibility layer (mtd_ioctl.c) will attempt to use the MTD sysfs interface and MEM*64 ioctls in 2.6.31+. It will fall back to the older ABI if it determines that the running kernel does not support the new calls.
--- Makefile | 19 +++- flash_erase.c | 59 ++++++---- flash_eraseall.c | 31 +++-- flash_lock.c | 21 ++-- flash_unlock.c | 9 +- flashcp.c | 22 ++-- mtd_debug.c | 114 ++++++++++--------- mtd_ioctl.c | 307 +++++++++++++++++++++++++++++++++++++++++++++++++ mtd_ioctl.h | 39 ++++++ nanddump.c | 23 +++-- nandtest.c | 35 +++--- nandwrite.c | 60 +++++----- 13 files changed, 570 insertions(+), 171 deletions(-) create mode 100644 mtd_ioctl.c create mode 100644 mtd_ioctl.h
Makefile +18 -1
@@ -41,7 +41,24 @@ $(BUILDDIR)/mkfs.jffs2: $(addprefix $(BUILDDIR)/,\ LDFLAGS_mkfs.jffs2 = $(ZLIBLDFLAGS) $(LZOLDFLAGS) LDLIBS_mkfs.jffs2 = -lz -llzo2 -$(BUILDDIR)/flash_eraseall: $(BUILDDIR)/crc32.o $(BUILDDIR)/flash_eraseall.o +$(BUILDDIR)/flash_eraseall: $(BUILDDIR)/crc32.o $(BUILDDIR)/flash_eraseall.o \ + $(BUILDDIR)/mtd_ioctl.o + +$(BUILDDIR)/flash_erase: $(BUILDDIR)/flash_erase.o $(BUILDDIR)/mtd_ioctl.o + +$(BUILDDIR)/nandwrite: $(BUILDDIR)/nandwrite.o $(BUILDDIR)/mtd_ioctl.o + +$(BUILDDIR)/nandtest: $(BUILDDIR)/nandtest.o $(BUILDDIR)/mtd_ioctl.o + +$(BUILDDIR)/nanddump: $(BUILDDIR)/nanddump.o $(BUILDDIR)/mtd_ioctl.o + +$(BUILDDIR)/flashcp: $(BUILDDIR)/flashcp.o $(BUILDDIR)/mtd_ioctl.o + +$(BUILDDIR)/flash_lock: $(BUILDDIR)/flash_lock.o $(BUILDDIR)/mtd_ioctl.o + +$(BUILDDIR)/flash_unlock: $(BUILDDIR)/flash_unlock.o $(BUILDDIR)/mtd_ioctl.o + +$(BUILDDIR)/mtd_debug: $(BUILDDIR)/mtd_debug.o $(BUILDDIR)/mtd_ioctl.o $(BUILDDIR)/jffs2reader: $(BUILDDIR)/jffs2reader.o LDFLAGS_jffs2reader = $(ZLIBLDFLAGS) $(LZOLDFLAGS)
flash_erase.c +34 -25
144 lines not on this page · raw message
flash_eraseall.c +18 -13
@@ -36,6 +36,7 @@#include <sys/ioctl.h> #include <sys/mount.h> #include "crc32.h" +#include "mtd_ioctl.h" #include <mtd/mtd-user.h> #include <mtd/jffs2-user.h>
@@ -49,7 +50,7 @@ static int quiet; /* true -- don't output progress */static int jffs2;// format for jffs2 usage static void process_options (int argc,char *argv[]); -void show_progress (mtd_info_t *meminfo,erase_info_t *erase); +void show_progress (mtd_info64_t *meminfo,erase_info64_t *erase);static void display_help (void );static void display_version (void );static struct jffs2_unknown_node cleanmarker;
@@ -57,9 +58,9 @@ int target_endian = __BYTE_ORDER;int main (int argc,char *argv[]) { -mtd_info_t meminfo; +mtd_info64_t meminfo;int fd, clmpos =0 , clmlen =8 ; -erase_info_t erase; +erase_info64_t erase;int isNAND, bbtest =1 ;process_options (argc, argv);
@@ -70,11 +71,12 @@ int main (int argc, char *argv[]) } -if (ioctl (fd,MEMGETINFO , &meminfo) !=0 ) { +if (mtd_ioctl_getinfo (fd, &meminfo) !=0 ) {fprintf (stderr,"%s: %s: unable to get MTD device info\n" , exe_name, mtd_device);return 1 ; } +memset (&erase,0 ,sizeof (erase)); erase.length = meminfo.erasesize; isNAND = meminfo.type ==MTD_NANDFLASH ?1 :0 ;
@@ -130,7 +132,8 @@ 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" , + (unsigned long long )erase.start);continue ; }else if (ret <0 ) {if (errno ==EOPNOTSUPP ) {
@@ -149,7 +152,7 @@ int main (int argc, char *argv[])if (!quiet)show_progress (&meminfo, &erase); -if (ioctl (fd,MEMERASE , &erase) !=0 ) { +if (mtd_ioctl_erase (fd, &erase) !=0 ) {fprintf (stderr,"\n%s: %s: MTD Erase failure: %s\n" , exe_name, mtd_device,strerror (errno));continue ; }
@@ -160,11 +163,12 @@ int main (int argc, char *argv[])/* write cleanmarker */ if (isNAND) { -struct mtd_oob_buf oob; - oob.ptr = (unsigned char *) &cleanmarker; +struct mtd_oob_buf64 oob; +memset (&oob,0 ,sizeof (oob)); + oob.usr_ptr = (uintptr_t ) &cleanmarker; oob.start = erase.start + clmpos; oob.length = clmlen; -if (ioctl (fd,MEMWRITEOOB , &oob) !=0 ) { +if (mtd_ioctl_writeoob (fd, &oob) !=0 ) {fprintf (stderr,"\n%s: %s: MTD writeoob failure: %s\n" , exe_name, mtd_device,strerror (errno));continue ; }
@@ -179,7 +183,8 @@ int main (int argc, char *argv[]) } }if (!quiet) -printf (" Cleanmarker written at %x." , erase.start); +printf (" Cleanmarker written at %llx." , + (unsigned long long )erase.start); }if (!quiet) {show_progress (&meminfo, &erase);
@@ -250,10 +255,10 @@ 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 (mtd_info64_t *meminfo,erase_info64_t *erase) { -printf ("\rErasing %d Kibyte @ %x -- %2llu %% complete." , - meminfo->erasesize /1024 , erase->start, +printf ("\rErasing %d Kibyte @ %llx -- %2llu %% complete." , + meminfo->erasesize /1024 , (unsigned long long )erase->start, (unsigned long long ) erase->start *100 / meminfo->size);fflush (stdout); }
flash_lock.c +11 -10
@@ -15,14 +15,15 @@#include <string.h> #include <mtd/mtd-user.h> +#include "mtd_ioctl.h" int main (int argc,char *argv[]) {int fd; -struct mtd_info_user mtdInfo; -struct erase_info_user mtdLockInfo; -int num_sectors; -int ofs; +struct mtd_info_user64 mtdInfo; +struct erase_info_user64 mtdLockInfo; +long long num_sectors; +long long ofs;/* * Parse command line options
@@ -45,17 +46,17 @@ int main(int argc, char *argv[])exit (1 ); } -if (ioctl (fd,MEMGETINFO , &mtdInfo)) +if (mtd_ioctl_getinfo (fd, &mtdInfo)) {fprintf (stderr,"Could not get MTD device info from %s\n" , argv[1 ]);close (fd);exit (1 ); } -sscanf (argv[2 ],"%x" ,&ofs); -sscanf (argv[3 ],"%d" ,&num_sectors); +sscanf (argv[2 ],"%llx" ,&ofs); +sscanf (argv[3 ],"%lld" ,&num_sectors);if (ofs > mtdInfo.size - mtdInfo.erasesize) { -fprintf (stderr,"%x is beyond device size %x\n" ,ofs,(unsigned int )(mtdInfo.size - mtdInfo.erasesize)); +fprintf (stderr,"%llx is beyond device size %llx\n" ,ofs,(unsigned long long )(mtdInfo.size - mtdInfo.erasesize));exit (1 ); }
@@ -65,14 +66,14 @@ int main(int argc, char *argv[])else {if (num_sectors > mtdInfo.size/mtdInfo.erasesize) { -fprintf (stderr,"%d are too many sectors, device only has %d\n" ,num_sectors,(int )(mtdInfo.size/mtdInfo.erasesize)); +fprintf (stderr,"%lld are too many sectors, device only has %lld\n" ,num_sectors,(long long )(mtdInfo.size/mtdInfo.erasesize));exit (1 ); } } mtdLockInfo.start = ofs; mtdLockInfo.length = (num_sectors -1 ) * mtdInfo.erasesize; -if (ioctl (fd,MEMLOCK , &mtdLockInfo)) +if (mtd_ioctl_lock (fd, &mtdLockInfo)) {fprintf (stderr,"Could not lock MTD device: %s\n" , argv[1 ]);close (fd);
flash_unlock.c +5 -4
@@ -15,12 +15,13 @@#include <string.h> #include <mtd/mtd-user.h> +#include "mtd_ioctl.h" int main (int argc,char *argv[]) {int fd; -struct mtd_info_user mtdInfo; -struct erase_info_user mtdLockInfo; +struct mtd_info_user64 mtdInfo; +struct erase_info_user64 mtdLockInfo;int count;/*
@@ -44,7 +45,7 @@ int main(int argc, char *argv[])exit (1 ); } -if (ioctl (fd,MEMGETINFO , &mtdInfo)) +if (mtd_ioctl_getinfo (fd, &mtdInfo)) {fprintf (stderr,"Could not get MTD device info from %s\n" , argv[1 ]);close (fd);
@@ -63,7 +64,7 @@ int main(int argc, char *argv[]) mtdLockInfo.length = mtdInfo.size - mtdInfo.erasesize; } -if (ioctl (fd,MEMUNLOCK , &mtdLockInfo)) +if (mtd_ioctl_unlock (fd, &mtdLockInfo)) {fprintf (stderr,"Could not unlock MTD device: %s\n" , argv[1 ]);close (fd);
flashcp.c +12 -10
@@ -40,6 +40,7 @@#include <unistd.h> #include <mtd/mtd-user.h> #include <getopt.h> +#include "mtd_ioctl.h" typedef int bool ;#define true 1
@@ -169,8 +170,8 @@ int main (int argc,char *argv[])int i,flags =FLAG_NONE ;ssize_t result;size_t size,written; -struct mtd_info_user mtd; -struct erase_info_user erase; +struct mtd_info_user64 mtd; +struct erase_info_user64 erase;struct stat filestat;unsigned char src[BUFSIZE ],dest[BUFSIZE ];
@@ -226,7 +227,7 @@ int main (int argc,char *argv[])/* get some info about the flash device */ dev_fd =safe_open (device,O_SYNC |O_RDWR ); -if (ioctl (dev_fd,MEMGETINFO ,&mtd) <0 ) +if (mtd_ioctl_getinfo (dev_fd,&mtd) <0 ) {DEBUG ("ioctl(): %m\n" );log_printf (LOG_ERROR ,"This doesn't seem to be a valid MTD flash device!\n" );
@@ -254,6 +255,7 @@ int main (int argc,char *argv[])#warning "Check for smaller erase regions" +memset (&erase,0 ,sizeof (erase)); erase.start =0 ; erase.length = (filestat.st_size + mtd.erasesize -1 ) / mtd.erasesize; erase.length *= mtd.erasesize;
@@ -261,18 +263,18 @@ int main (int argc,char *argv[])if (flags &FLAG_VERBOSE ) {/* if the user wants verbose output, erase 1 block at a time and show him/her what's going on */ -int blocks = erase.length / mtd.erasesize; +long long blocks = erase.length / mtd.erasesize; erase.length = mtd.erasesize;log_printf (LOG_NORMAL ,"Erasing blocks: 0/%d (0%%)" ,blocks);for (i =1 ; i <= blocks; i++) {log_printf (LOG_NORMAL ,"\rErasing blocks: %d/%d (%d%%)" ,i,blocks,PERCENTAGE (i,blocks)); -if (ioctl (dev_fd,MEMERASE ,&erase) <0 ) +if (mtd_ioctl_erase (dev_fd, &erase) <0 ) {log_printf (LOG_NORMAL ,"\n" );log_printf (LOG_ERROR , -"While erasing blocks 0x%.8x-0x%.8x on %s: %m\n" , - (unsigned int ) erase.start,(unsigned int ) (erase.start + erase.length),device); +"While erasing blocks 0x%.8llx-0x%.8llx on %s: %m\n" , + erase.start, (erase.start + erase.length),device);exit (EXIT_FAILURE ); } erase.start += mtd.erasesize;
@@ -282,11 +284,11 @@ int main (int argc,char *argv[])else {/* if not, erase the whole chunk in one shot */ -if (ioctl (dev_fd,MEMERASE ,&erase) <0 ) +if (mtd_ioctl_erase (dev_fd, &erase) <0 ) {log_printf (LOG_ERROR , -"While erasing blocks from 0x%.8x-0x%.8x on %s: %m\n" , - (unsigned int ) erase.start,(unsigned int ) (erase.start + erase.length),device); +"While erasing blocks from 0x%.8llx-0x%.8llx on %s: %m\n" , + erase.start, (erase.start + erase.length),device);exit (EXIT_FAILURE ); } }
mtd_debug.c +60 -54
265 lines not on this page · raw message
mtd_ioctl.c new file +307 -0
307 lines not on this page · raw message
mtd_ioctl.h new file +39 -0
@@ -0,0 +1,39 @@ +/* +* mtd_ioctl.h - backward compatibility wrappers for MTD ioctls +*/ + +#ifndef _MTD_IOCTL_H +#define _MTD_IOCTL_H + +#include <mtd/mtd-user.h> + +struct region_info_user64 { +uint64_t offset;/* At which this region starts, +* from the beginning of the MTD */ +uint32_t erasesize;/* For this region */ +uint32_t numblocks;/* Number of blocks in this region */ +uint32_t regionindex; +}; + +struct mtd_info_user64 { +uint32_t type; +uint32_t flags; +uint64_t size;/* Total size of the MTD */ +uint32_t erasesize; +uint32_t writesize; +uint32_t oobsize;/* OOB bytes per page (e.g. 16) */ +}; + +typedef struct mtd_info_user64 mtd_info64_t ; +typedef struct region_info_user64 region_info64_t ; +typedef struct erase_info_user64 erase_info64_t ; + +int mtd_ioctl_getinfo (int fd,struct mtd_info_user64 *arg); +int mtd_ioctl_erase (int fd,struct erase_info_user64 *arg); +int mtd_ioctl_writeoob (int fd,struct mtd_oob_buf64 *arg); +int mtd_ioctl_readoob (int fd,struct mtd_oob_buf64 *arg); +int mtd_ioctl_lock (int fd,struct erase_info_user64 *arg); +int mtd_ioctl_unlock (int fd,struct erase_info_user64 *arg); +int mtd_ioctl_getregioninfo (int fd,struct region_info_user64 *arg); + +#endif /* !_MTD_IOCTL_H */
nanddump.c +14 -9
@@ -29,6 +29,7 @@#include <asm/types.h> #include <mtd/mtd-user.h> +#include "mtd_ioctl.h" #define PROGRAM "nanddump"#define VERSION "$Revision: 1.29 $"
@@ -182,11 +183,15 @@ static unsigned char oobbuf[128];*/ int main (int argc,char *const argv[]) { -unsigned long ofs, end_addr =0 ; +unsigned long long ofs, end_addr =0 ;unsigned long long blockstart =1 ;int ret, i, fd, ofd, bs, badblock =0 ; -struct mtd_oob_buf oob = {0 ,16 , oobbuf}; -mtd_info_t meminfo; +struct mtd_oob_buf64 oob = { + .start =0 , + .length =16 , + .usr_ptr = (uintptr_t )oobbuf, + }; +mtd_info64_t meminfo;char pretty_buf[80 ];int oobinfochanged =0 ;struct nand_oobinfo old_oobinfo;
@@ -202,8 +207,8 @@ int main(int argc, char * const argv[]) }/* Fill in MTD device capability structure */ -if (ioctl (fd,MEMGETINFO , &meminfo) !=0 ) { -perror ("MEMGETINFO" ); +if (mtd_ioctl_getinfo (fd, &meminfo) !=0 ) { +perror ("MEMGETINFO64" );close (fd);exit (EXIT_FAILURE ); }
@@ -322,11 +327,11 @@ int main(int argc, char * const argv[]) }if (stat1.failed != stat2.failed)fprintf (stderr,"ECC: %d uncorrectable bitflip(s)" -" at offset 0x%08lx\n" , +" at offset 0x%08llx\n" , stat2.failed - stat1.failed, ofs);if (stat1.corrected != stat2.corrected)fprintf (stderr,"ECC: %d corrected bitflip(s) at" -" offset 0x%08lx\n" , +" offset 0x%08llx\n" , stat2.corrected - stat1.corrected, ofs); stat1 = stat2; }
@@ -361,8 +366,8 @@ int main(int argc, char * const argv[]) }else {/* Read OOB data and exit on failure */ oob.start = ofs; -if (ioctl (fd,MEMREADOOB , &oob) !=0 ) { -perror ("ioctl(MEMREADOOB)" ); +if (mtd_ioctl_readoob (fd, &oob) !=0 ) { +perror ("ioctl(MEMREADOOB64)" ); goto closeall; } }
nandtest.c +19 -16
@@ -14,6 +14,7 @@#include <asm/types.h> #include "mtd/mtd-user.h" +#include "mtd_ioctl.h" void usage (void ) {
@@ -28,7 +29,7 @@ void usage(void)exit (1 ); } -struct mtd_info_user meminfo; +struct mtd_info_user64 meminfo;struct mtd_ecc_stats oldstats, newstats;int fd;int markbad=0 ;
@@ -36,26 +37,28 @@ int seed;int erase_and_write (loff_t ofs,unsigned char *data,unsigned char *rbuf) { -struct erase_info_user er; +struct erase_info_user64 er;ssize_t len;int i; -printf ("\r%08x: erasing... " , (unsigned )ofs); +printf ("\r%08llx: erasing... " , ofs);fflush (stdout); +memset (&er,0 ,sizeof (er)); + er.start = ofs; er.length = meminfo.erasesize; -if (ioctl (fd,MEMERASE , &er)) { -perror ("MEMERASE" ); +if (mtd_ioctl_erase (fd, &er)) { +perror ("MEMERASE64" );if (markbad) { -printf ("Mark block bad at %08lx\n" , (long )ofs); +printf ("Mark block bad at %08llx\n" , ofs);ioctl (fd,MEMSETBADBLOCK , &ofs); }return 1 ; } -printf ("\r%08x: writing..." , (unsigned )ofs); +printf ("\r%08llx: writing..." , ofs);fflush (stdout); len =pwrite (fd, data, meminfo.erasesize, ofs);
@@ -132,8 +135,8 @@ int main(int argc, char **argv)int pass;int nr_passes =1 ;int keep_contents =0 ; -uint32_t offset =0 ; -uint32_t length =-1 ; +uint64_t offset =0 ; +uint64_t length =-1 ;for (;;) {static const char *short_options="hkl:mo:p:s:" ;
@@ -175,11 +178,11 @@ int main(int argc, char **argv)break ;case 'o' : - offset =atol (optarg); + offset =atoll (optarg);break ;case 'l' : - length =strtol (optarg,NULL ,0 ); + length =strtoll (optarg,NULL ,0 );break ; }
@@ -193,8 +196,8 @@ int main(int argc, char **argv)exit (1 ); } -if (ioctl (fd,MEMGETINFO , &meminfo)) { -perror ("MEMGETINFO" ); +if (mtd_ioctl_getinfo (fd, &meminfo)) { +perror ("MEMGETINFO64" );close (fd);exit (1 ); }
@@ -203,17 +206,17 @@ int main(int argc, char **argv) length = meminfo.size;if (offset % meminfo.erasesize) { -fprintf (stderr,"Offset %x not multiple of erase size %x\n" , +fprintf (stderr,"Offset %llx not multiple of erase size %x\n" , offset, meminfo.erasesize);exit (1 ); }if (length % meminfo.erasesize) { -fprintf (stderr,"Length %x not multiple of erase size %x\n" , +fprintf (stderr,"Length %llx not multiple of erase size %x\n" , length, meminfo.erasesize);exit (1 ); }if (length + offset > meminfo.size) { -fprintf (stderr,"Length %x + offset %x exceeds device size %x\n" , +fprintf (stderr,"Length %llx + offset %llx exceeds device size %llx\n" , length, offset, meminfo.size);exit (1 ); }
nandwrite.c +32 -28
151 lines not on this page · raw message
Signature · 1 line
1.6.5
Re: [PATCH v5 2/3] mtd-utils: support >4GiB devices
Quoted 25 lines · Kevin Cernekee
This patch updates the following programs to handle >4GiB flash devices:
flash_eraseflash_eraseall
flashcpmtd_debug
nanddump
nandtest
nandwriteIt also lays the groundwork for >4GiB support in:
flash_lockflash_unlockThe latter two utilities would require MEMLOCK64 / MEMUNLOCK64 functionality on the kernel side (currently unimplemented). For now they still use MEMLOCK / MEMUNLOCK and cannot access blocks above 4GiB.
By default, the compatibility layer (
mtd_ioctl.c) will attempt to use the MTD sysfs interface and MEM*64 ioctls in 2.6.31+. It will fall back to the older ABI if it determines that the running kernel does not support the new calls.Signed-off-by Kevin Cernekee <[email protected]>
Quoted 16 lines
--- Makefile | 19 +++- flash_erase.c | 59 ++++++---- flash_eraseall.c | 31 +++-- flash_lock.c | 21 ++-- flash_unlock.c | 9 +- flashcp.c | 22 ++-- mtd_debug.c | 114 ++++++++++--------- mtd_ioctl.c | 307 +++++++++++++++++++++++++++++++++++++++++++++++++ mtd_ioctl.h | 39 ++++++ nanddump.c | 23 +++-- nandtest.c | 35 +++--- nandwrite.c | 60 +++++----- 13 files changed, 570 insertions(+), 171 deletions(-) create mode 100644 mtd_ioctl.c create mode 100644 mtd_ioctl.h
Any chance to extend and use mtd-utils/ubi-utils/src/libmtd.c instead of mtd_ioctl.c?
Signature · 2 lines
Best Regards, Artem Bityutskiy (Артём Битюцкий)
Re: [PATCH v5 2/3] mtd-utils: support >4GiB devices
Quoted 7 lines · Artem Bityutskiy
Quoted 4 lines
nandwrite.c | 60 +++++----- 13 files changed, 570 insertions(+), 171 deletions(-) create mode 100644 mtd_ioctl.c create mode 100644 mtd_ioctl.hAny chance to extend and use
mtd-utils/ubi-utils/src/libmtd.cinstead ofmtd_ioctl.c?
Does silence mean that that answer is "no"? :-)
Signature · 2 lines
Best Regards, Artem Bityutskiy (Артём Битюцкий)
Re: [PATCH v5 2/3] mtd-utils: support >4GiB devices
Quoted 10 lines · Artem Bityutskiy
Quoted 7 lines · Artem Bityutskiy
Quoted 4 lines
nandwrite.c | 60 +++++----- 13 files changed, 570 insertions(+), 171 deletions(-) create mode 100644 mtd_ioctl.c create mode 100644 mtd_ioctl.hAny chance to extend and use
mtd-utils/ubi-utils/src/libmtd.cinstead ofmtd_ioctl.c?Does silence mean that that answer is "no"? :-)
I have a dilemma whether to take your patches as they are or not :-) On the one hand, they are needed, on the other hand, if we re-use libmtd.c, we do not have duplicated code. libmtd.c is tested and it distinguish beween old kernels (no sysfs support in mtd) and new kernels (expose stuff via sysfs). It would be nice to share more code...
I guess I do not take your patches so far.
Signature · 2 lines
Best Regards, Artem Bityutskiy (Артём Битюцкий)