diff options
| author | Takahiro Kuwano <Takahiro.Kuwano@infineon.com> | 2023-11-07 18:23:57 +0900 | 
|---|---|---|
| committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-11-13 09:03:00 +0100 | 
| commit | 71edfe3b5a51ea9a7fac9760804db328ea1ec8a0 (patch) | |
| tree | 62f9cb8815e5d72799e3b8a72a8d810d9b31e381 /misc-utils | |
| parent | aaa77f94ce6e03d9730f62004347ec2bbf11cfb1 (diff) | |
mtd-utils: flash_erase: Add an option for JFFS2 cleanmarker size
JFFS2 supports buffer mode for ECC'd NOR Flash that cleanmarker size
is rounded up to mtd->writesize, while the '-j' option in flash_erase
utility uses fixed 12 bytes. That makes flash program ops unaligned to
mtd->writesize and causes program error or disables ECC.
The mkfs.jffs2 utility supports '-c' option that allows users to specify
cleanmarker size. This patch implements '-c' option in the flash_erase
that can be used along with '-j' option.
Signed-off-by: Takahiro Kuwano <Takahiro.Kuwano@infineon.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'misc-utils')
| -rw-r--r-- | misc-utils/flash_erase.c | 29 | 
1 files changed, 19 insertions, 10 deletions
| diff --git a/misc-utils/flash_erase.c b/misc-utils/flash_erase.c index 000f94a..c6f6f66 100644 --- a/misc-utils/flash_erase.c +++ b/misc-utils/flash_erase.c @@ -64,13 +64,14 @@ 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); @@ -115,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; @@ -127,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'}, @@ -155,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; @@ -207,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; @@ -216,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); | 
