aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/u-boot/u-boot-1.1.4/u-boot-jerase-cmd.patch
blob: 698f7a2d78e1f421ca1f9ed6653d08811157a585 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
--- u-boot-orig/common/cmd_flash.c	2004-12-31 01:32:50.000000000 -0800
+++ u-boot-1.1.2/common/cmd_flash.c	2005-09-13 23:00:14.000000000 -0700
@@ -36,6 +36,11 @@
 
 extern flash_info_t flash_info[];	/* info for FLASH chips */
 
+static const unsigned int JFFS2_CLEAN_HEADER[] = {	0x20031985,
+							0x0000000c,
+							0xe41eb0b1
+						};
+
 /*
  * The user interface starts numbering for Flash banks with 1
  * for historical reasons.
@@ -206,29 +211,46 @@
 	flash_print_info (&flash_info[bank-1]);
 	return 0;
 }
 
+void jffs2_write_header(flash_info_t *info, unsigned int first, unsigned int last)
+{
+	unsigned int i;
+	for(i=first; i<=last; i++)
+	{
+		flash_write(JFFS2_CLEAN_HEADER, info->start[i], 12);
+	}
+}
+
 int do_flerase (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 {
 	flash_info_t *info;
 	ulong bank, addr_first, addr_last;
 	int n, sect_first, sect_last;
 #if (CONFIG_COMMANDS & CFG_CMD_JFFS2) && defined(CONFIG_JFFS2_CMDLINE)
 	struct mtd_device *dev;
 	struct part_info *part;
 	u8 dev_type, dev_num, pnum;
 #endif
 	int rcode = 0;
+	int jffs2erase = 0;
 
 	if (argc < 2) {
 		printf ("Usage:\n%s\n", cmdtp->usage);
 		return 1;
 	}
 
+	// Special JFFS2 erase which will write a JFFS2 "clean" header after the erase
+	if('j' == argv[0][0])
+	{
+		jffs2erase = 1;
+	}
+	
 	if (strcmp(argv[1], "all") == 0) {
 		for (bank=1; bank<=CFG_MAX_FLASH_BANKS; ++bank) {
 			printf ("Erase Flash Bank # %ld ", bank);
 			info = &flash_info[bank-1];
 			rcode = flash_erase (info, 0, info->sector_count-1);
+			if(jffs2erase) jffs2_write_header(info, 0, info->sector_count-1);
 		}
 		return rcode;
 	}
@@ -235,6 +257,7 @@
 		printf ("Erase Flash Sectors %d-%d in Bank # %d ",
 			sect_first, sect_last, (info-flash_info)+1);
 		rcode = flash_erase(info, sect_first, sect_last);
+		if(jffs2erase) jffs2_write_header(info, sect_first, sect_last);
 		return rcode;
 	}
 
@@ -253,6 +276,7 @@
 		printf ("Erase Flash Bank # %ld ", bank);
 		info = &flash_info[bank-1];
 		rcode = flash_erase (info, 0, info->sector_count-1);
+		if(jffs2erase) jffs2_write_header(info, 0, info->sector_count-1);
 		return rcode;
 	}
 
@@ -264,6 +288,12 @@
 		return 1;
 	}
 
+	if (jffs2erase)
+	{
+		printf ("Usage:\n%s\n", cmdtp->usage);
+		return 1;
+	}
+
 	rcode = flash_sect_erase(addr_first, addr_last);
 	return rcode;
 }
@@ -517,6 +547,16 @@
 );
 
 U_BOOT_CMD(
+	jerase,  3,   1,  do_flerase,
+	"jerase  - erase FLASH memory for JFFS2\n",
+	"jerase N:SF[-SL]\n   - erase sectors SF-SL in FLASH bank # N\n"
+	"jerase bank N\n   - erase FLASH bank # N\n"
+	"jerase all\n   - erase all FLASH banks\n"
+	" in each case, after erasing a flash sector, that sector\n"
+	" has a JFFS2 'clean' marker written to it\n"
+);
+
+U_BOOT_CMD(
 	protect,  4,  1,   do_protect,
 	"protect - enable or disable FLASH write protection\n",
 	"on  start end\n"