diff options
Diffstat (limited to 'misc-utils')
| -rw-r--r-- | misc-utils/Makemodule.am | 5 | ||||
| -rw-r--r-- | misc-utils/fectest.c | 2 | ||||
| -rw-r--r-- | misc-utils/flash_erase.c | 37 | ||||
| -rw-r--r-- | misc-utils/flash_unlock.c | 9 | ||||
| -rw-r--r-- | misc-utils/flashcp.c | 78 | ||||
| -rw-r--r-- | misc-utils/ftl_check.c | 4 | ||||
| -rw-r--r-- | misc-utils/mtd_debug.c | 7 | ||||
| -rw-r--r-- | misc-utils/mtdpart.c | 7 | 
8 files changed, 120 insertions, 29 deletions
| diff --git a/misc-utils/Makemodule.am b/misc-utils/Makemodule.am index bc69b1c..1ce1a68 100644 --- a/misc-utils/Makemodule.am +++ b/misc-utils/Makemodule.am @@ -7,8 +7,10 @@ ftl_check_SOURCES = misc-utils/ftl_check.c include/mtd_swab.h  ftl_check_SOURCES += include/mtd/ftl-user.h  mtd_debug_SOURCES = misc-utils/mtd_debug.c +mtd_debug_LDADD = libmtd.a  mtdpart_SOURCES = misc-utils/mtdpart.c +mtdpart_LDADD = libmtd.a  docfdisk_SOURCES = misc-utils/docfdisk.c include/mtd_swab.h  docfdisk_SOURCES += include/mtd/inftl-user.h include/mtd/ftl-user.h @@ -23,8 +25,10 @@ fectest_SOURCES = misc-utils/fectest.c misc-utils/mcast_image.h  fectest_LDADD = libmtd.a  flash_lock_SOURCES = misc-utils/flash_lock.c +flash_lock_LDADD = libmtd.a  flash_unlock_SOURCES = misc-utils/flash_unlock.c +flash_unlock_LDADD = libmtd.a  flash_otp_info_SOURCES = misc-utils/flash_otp_info.c @@ -37,6 +41,7 @@ flash_otp_erase_SOURCES = misc-utils/flash_otp_erase.c  flash_otp_write_SOURCES = misc-utils/flash_otp_write.c  flashcp_SOURCES = misc-utils/flashcp.c +flashcp_LDADD = libmtd.a  flash_erase_SOURCES = misc-utils/flash_erase.c  flash_erase_LDADD = libmtd.a diff --git a/misc-utils/fectest.c b/misc-utils/fectest.c index eb1d33e..f560f2b 100644 --- a/misc-utils/fectest.c +++ b/misc-utils/fectest.c @@ -87,6 +87,6 @@ int main(void)  		exit(1);  	} -	printf("Decoded in %ld.%06lds\n", now.tv_sec, now.tv_usec); +	printf("Decoded in %ld.%06lds\n", (long)now.tv_sec, (long)now.tv_usec);  	return 0;  } diff --git a/misc-utils/flash_erase.c b/misc-utils/flash_erase.c index 49a880f..36f8d57 100644 --- a/misc-utils/flash_erase.c +++ b/misc-utils/flash_erase.c @@ -64,13 +64,16 @@ static void display_help (void)  			"Erase blocks of the specified MTD device.\n"  			"Specify a count of 0 to erase to end of device.\n"  			"\n" -			"  -j, --jffs2       format the device for jffs2\n" -			"  -N, --noskipbad   don't skip bad blocks\n" -			"  -u, --unlock      unlock sectors before erasing\n" -			"  -q, --quiet       do not display progress messages\n" -			"      --silent      same as --quiet\n" -			"      --help        display this help and exit\n" -			"      --version     output version information and exit\n", +			"  -j, --jffs2             format the device for jffs2\n" +			"  -c, --cleanmarker=SIZE  size of jffs2 cleanmarker (default 12)\n" +			"  -N, --noskipbad         don't skip bad blocks\n" +			"  -u, --unlock            unlock sectors before erasing\n" +			"  -q, --quiet             do not display progress messages\n" +			"      --silent            same as --quiet\n" +			"      --help              display this help and exit\n" +			"      --version           output version information and exit\n", +			"\n" +			"  MTD_DEVICE  MTD device node or 'mtd:<name>'\n"  			PROGRAM_NAME);  } @@ -113,7 +116,7 @@ int main(int argc, char *argv[])  {  	libmtd_t mtd_desc;  	struct mtd_dev_info mtd; -	int fd, cmlen = 8; +	int fd, cmlen = 8, cmsize = sizeof(cleanmarker);  	unsigned long long start;  	unsigned int eb, eb_start, eb_cnt;  	bool isNAND, erase_chip = false; @@ -125,11 +128,12 @@ int main(int argc, char *argv[])  	 */  	for (;;) {  		int option_index = 0; -		static const char *short_options = "jNquVh"; +		static const char *short_options = "jc:NquVh";  		static const struct option long_options[] = {  			{"help", no_argument, 0, 'h'},  			{"version", no_argument, 0, 'V'},  			{"jffs2", no_argument, 0, 'j'}, +			{"cleanmarker", required_argument, 0, 'c'},  			{"noskipbad", no_argument, 0, 'N'},  			{"quiet", no_argument, 0, 'q'},  			{"silent", no_argument, 0, 'q'}, @@ -153,6 +157,9 @@ int main(int argc, char *argv[])  		case 'j':  			jffs2 = 1;  			break; +		case 'c': +			cmsize = atoi(optarg); +			break;  		case 'N':  			noskipbad = 1;  			break; @@ -169,7 +176,9 @@ int main(int argc, char *argv[])  	}  	switch (argc - optind) {  	case 3: -		mtd_device = argv[optind]; +		mtd_device = mtd_find_dev_node(argv[optind]); +		if (!mtd_device) +			return errmsg("Can't find MTD device %s", argv[optind]);  		start = simple_strtoull(argv[optind + 1], &error);  		eb_cnt = simple_strtoul(argv[optind + 2], &error);  		break; @@ -203,6 +212,10 @@ int main(int argc, char *argv[])  	if (jffs2 && mtd.type == MTD_MLCNANDFLASH)  		return errmsg("JFFS2 cannot support MLC NAND."); +	if (jffs2 && cmsize < sizeof(cleanmarker)) +		return errmsg("cleanmarker size must be >= 12"); +	if (jffs2 && cmsize >= mtd.eb_size) +		return errmsg("cleanmarker size must be < eraseblock size");  	eb_start = start / mtd.eb_size; @@ -212,7 +225,7 @@ int main(int argc, char *argv[])  		cleanmarker.magic = cpu_to_je16 (JFFS2_MAGIC_BITMASK);  		cleanmarker.nodetype = cpu_to_je16 (JFFS2_NODETYPE_CLEANMARKER);  		if (!isNAND) { -			cleanmarker.totlen = cpu_to_je32(sizeof(cleanmarker)); +			cleanmarker.totlen = cpu_to_je32(cmsize);  		} else {  			cleanmarker.totlen = cpu_to_je32(8);  			cmlen = min(mtd.oobavail, 8); @@ -226,7 +239,7 @@ int main(int argc, char *argv[])  	if (eb_cnt == 0)  		eb_cnt = (mtd.size / mtd.eb_size) - eb_start; -	if (eb_start == 0 && mtd.size == eb_cnt * mtd.eb_size) +	if (eb_start == 0 && mtd.size == (long long)eb_cnt * mtd.eb_size)  		erase_chip = true;  	/* If MTD device may have bad eraseblocks, diff --git a/misc-utils/flash_unlock.c b/misc-utils/flash_unlock.c index fbbfa51..fa5decb 100644 --- a/misc-utils/flash_unlock.c +++ b/misc-utils/flash_unlock.c @@ -51,6 +51,8 @@ static NORETURN void usage(int status)  		" -l         --lock              Lock a region of flash\n"  		" -u         --unlock            Unlock a region of flash\n"  		"\n" +		" <mtd device>  MTD device node or 'mtd:<name>'\n" +		"\n"  		"If offset is not specified, it defaults to 0.\n"  		"If block count is not specified, it defaults to all blocks.\n"  		"A block count of -1 means all blocks.\n", @@ -125,7 +127,12 @@ static void process_args(int argc, char *argv[])  	}  	/* First non-option argument */ -	dev = argv[arg_idx++]; +	dev = mtd_find_dev_node(argv[arg_idx]); +	if (!dev) { +		errmsg("MTD device not found %s", argv[arg_idx]); +		usage(EXIT_FAILURE); +	} +	arg_idx++;  	/* Second non-option argument */  	if (arg_idx < argc) diff --git a/misc-utils/flashcp.c b/misc-utils/flashcp.c index 2e8d4c1..6065a8c 100644 --- a/misc-utils/flashcp.c +++ b/misc-utils/flashcp.c @@ -64,6 +64,7 @@  #define FLAG_DEVICE		0x08  #define FLAG_ERASE_ALL	0x10  #define FLAG_PARTITION	0x20 +#define FLAG_WR_LAST	0x40  /* error levels */  #define LOG_NORMAL	1 @@ -104,13 +105,14 @@ static NORETURN void showusage(bool error)  			"       %1$s -h | --help\n"  			"       %1$s -V | --version\n"  			"\n" -			"   -h | --help      Show this help message\n" -			"   -v | --verbose   Show progress reports\n" -			"   -p | --partition Only copy different block from file to device\n" -			"   -A | --erase-all Erases the whole device regardless of the image size\n" -			"   -V | --version   Show version information and exit\n" -			"   <filename>       File which you want to copy to flash\n" -			"   <device>         Flash device to write to (e.g. /dev/mtd0, /dev/mtd1, etc.)\n" +			"   -h | --help           Show this help message\n" +			"   -v | --verbose        Show progress reports\n" +			"   -p | --partition      Only copy different block from file to device\n" +			"   -A | --erase-all      Erases the whole device regardless of the image size\n" +			"   -l | --wr-last=bytes  Write the first [bytes] last\n" +			"   -V | --version        Show version information and exit\n" +			"   <filename>            File which you want to copy to flash\n" +			"   <device>              Flash device node or 'mtd:<name>' to write to (e.g. /dev/mtd0, /dev/mtd1, mtd:data, etc.)\n"  			"\n",  			PROGRAM_NAME); @@ -219,7 +221,9 @@ int main (int argc,char *argv[])  	struct mtd_info_user mtd;  	struct erase_info_user erase;  	struct stat filestat; -	unsigned char *src,*dest; +	unsigned char *src, *dest, *wrlast_buf = NULL; +	unsigned long long wrlast_len = 0; +	int error = 0;  	/*********************  	 * parse cmd-line @@ -227,12 +231,13 @@ int main (int argc,char *argv[])  	for (;;) {  		int option_index = 0; -		static const char *short_options = "hvpAV"; +		static const char *short_options = "hvpAl:V";  		static const struct option long_options[] = {  			{"help", no_argument, 0, 'h'},  			{"verbose", no_argument, 0, 'v'},  			{"partition", no_argument, 0, 'p'},  			{"erase-all", no_argument, 0, 'A'}, +			{"wr-last", required_argument, 0, 'l'},  			{"version", no_argument, 0, 'V'},  			{0, 0, 0, 0},  		}; @@ -260,6 +265,10 @@ int main (int argc,char *argv[])  				flags |= FLAG_ERASE_ALL;  				DEBUG("Got FLAG_ERASE_ALL\n");  				break; +			case 'l': +				flags |= FLAG_WR_LAST; +				wrlast_len = simple_strtoll(optarg, &error); +				break;  			case 'V':  				common_print_version();  				exit(EXIT_SUCCESS); @@ -275,7 +284,10 @@ int main (int argc,char *argv[])  		DEBUG("Got filename: %s\n",filename);  		flags |= FLAG_DEVICE; -		device = argv[optind+1]; +		device = mtd_find_dev_node(argv[optind+1]); +		if (!device) +			log_failure("Failed to find device %s\n", argv[optind+1]); +  		DEBUG("Got device: %s\n",device);  	} @@ -285,6 +297,10 @@ int main (int argc,char *argv[])  	if (flags & FLAG_PARTITION && flags & FLAG_ERASE_ALL)  		log_failure("Option --partition does not support --erase-all\n"); +	if (flags & FLAG_PARTITION && flags & FLAG_WR_LAST) { +		log_failure("Option --partition does not support --wr-last\n"); +	} +  	atexit (cleanup);  	/* get some info about the flash device */ @@ -361,17 +377,47 @@ int main (int argc,char *argv[])  	 * write the entire file to flash *  	 **********************************/ -	log_verbose ("Writing data: 0k/%lluk (0%%)",KB ((unsigned long long)filestat.st_size));  	size = filestat.st_size;  	i = mtd.erasesize;  	written = 0; + +	if ((flags & FLAG_WR_LAST) && (filestat.st_size > wrlast_len)) { +		if (wrlast_len > mtd.erasesize) +			log_failure("The wrlast (%lluk) is larger than erasesize (%lluk)\n", KB (wrlast_len), KB ((unsigned long long)mtd.erasesize)); + +		if (size < mtd.erasesize) i = size; + +		log_verbose ("Reading %lluk of data to write last.\n", KB ((unsigned long long)wrlast_len)); +		wrlast_buf = malloc(wrlast_len); +		if (!wrlast_buf) +			log_failure("Malloc failed"); +		safe_read (fil_fd, filename, wrlast_buf, wrlast_len); +		safe_lseek(dev_fd, wrlast_len, SEEK_SET, device); +		written += wrlast_len; +		size -= wrlast_len; +		i -= wrlast_len; + +		log_verbose ("Writing remaining erase block data: %dk/%lluk (%llu%%)\n", +				KB (written + i), +				KB ((unsigned long long)filestat.st_size), +				PERCENTAGE ((unsigned long long)written + i, (unsigned long long)filestat.st_size)); +		safe_read (fil_fd, filename, src, i); +		safe_write(dev_fd, src, i, written, (unsigned long long)filestat.st_size, device); + +		written += i; +		size -= i; +		i = mtd.erasesize; +	} else { +		log_verbose ("Writing data: 0k/%lluk (0%%)",KB ((unsigned long long)filestat.st_size)); +	} +  	while (size)  	{  		if (size < mtd.erasesize) i = size;  		log_verbose ("\rWriting data: %dk/%lluk (%llu%%)",  				KB (written + i),  				KB ((unsigned long long)filestat.st_size), -				PERCENTAGE (written + i,(unsigned long long)filestat.st_size)); +				PERCENTAGE ((unsigned long long)written + i,(unsigned long long)filestat.st_size));  		/* read from filename */  		safe_read (fil_fd,filename,src,i); @@ -387,6 +433,12 @@ int main (int argc,char *argv[])  			KB ((unsigned long long)filestat.st_size));  	DEBUG("Wrote %d / %lluk bytes\n",written,(unsigned long long)filestat.st_size); +	if ((flags & FLAG_WR_LAST) && (filestat.st_size > wrlast_len)) { +		log_verbose ("Writing %lluk of the write last data.\n", KB ((unsigned long long)wrlast_len)); +		safe_rewind (dev_fd, device); +		safe_write(dev_fd, wrlast_buf, wrlast_len, 0, wrlast_len, device); +	} +  	/**********************************  	 * verify that flash == file data *  	 **********************************/ @@ -403,7 +455,7 @@ int main (int argc,char *argv[])  		log_verbose ("\rVerifying data: %luk/%lluk (%llu%%)",  				KB (written + i),  				KB ((unsigned long long)filestat.st_size), -				PERCENTAGE (written + i,(unsigned long long)filestat.st_size)); +				PERCENTAGE ((unsigned long long)written + i,(unsigned long long)filestat.st_size));  		/* read from filename */  		safe_read (fil_fd,filename,src,i); diff --git a/misc-utils/ftl_check.c b/misc-utils/ftl_check.c index 5b2dae5..fe6a91a 100644 --- a/misc-utils/ftl_check.c +++ b/misc-utils/ftl_check.c @@ -121,6 +121,10 @@ static void check_partition(int fd)  	/* Create basic block allocation table for control blocks */  	nbam = (mtd.erasesize >> hdr.BlockSize);  	bam = malloc(nbam * sizeof(u_int)); +	if (!bam) { +		perror("malloc failed"); +		return; +	}  	for (i = 0; i < le16_to_cpu(hdr.NumEraseUnits); i++) {  		if (lseek(fd, (i << hdr.EraseUnitSize), SEEK_SET) == -1) { diff --git a/misc-utils/mtd_debug.c b/misc-utils/mtd_debug.c index c0b7109..abee5e3 100644 --- a/misc-utils/mtd_debug.c +++ b/misc-utils/mtd_debug.c @@ -348,6 +348,7 @@ int main(int argc, char *argv[])  {  	int err = 0, fd;  	int open_flag; +	char *dev;  	enum {  		OPT_INFO, @@ -369,8 +370,12 @@ int main(int argc, char *argv[])  		showusage();  	/* open device */ +	dev = mtd_find_dev_node(argv[2]); +	if (!dev) +		errmsg_die("Failed to find MTD device %s", argv[2]); +  	open_flag = (option == OPT_INFO || option == OPT_READ) ? O_RDONLY : O_RDWR; -	if ((fd = open(argv[2], O_SYNC | open_flag)) < 0) +	if ((fd = open(dev, O_SYNC | open_flag)) < 0)  		errmsg_die("open()");  	switch (option) { diff --git a/misc-utils/mtdpart.c b/misc-utils/mtdpart.c index c8cd79b..a341148 100644 --- a/misc-utils/mtdpart.c +++ b/misc-utils/mtdpart.c @@ -36,6 +36,8 @@ static void display_help(int status)  "  -h, --help    Display this help and exit\n"  "  -V, --version Output version information and exit\n"  "\n" +"  <MTD_DEVICE>  MTD device node or 'mtd:<name>'\n" +"\n"  "START location and SIZE of the partition are in bytes. They should align on\n"  "eraseblock size. If SIZE is 0 the partition will go to end of MTD device.\n",  	PROGRAM_NAME @@ -106,7 +108,10 @@ static void process_options(int argc, char * const argv[])  		display_help(EXIT_FAILURE);  	const char *s_command = argv[optind++]; -	mtddev = argv[optind++]; +	mtddev = mtd_find_dev_node(argv[optind]); +	if (!mtddev) +		errmsg_die("MTD device not found %s", argv[optind]); +	optind++;  	if (strcmp(s_command, "del") == 0 && (argc - optind) == 1) {  		const char *s_part_no = argv[optind++]; | 
