aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/u-boot/u-boot-1.1.4/at32stk1000/avr32-boards-fix-flash-read.patch
blob: a1e9fe89e5def38b83d12187560dba6f9f3794dc (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
108
109
110
111
112
113
114
115
116
117
118
119
120
Index: u-boot-orig/board/atmel/ngw/flash.c
===================================================================
--- u-boot-orig.orig/board/atmel/ngw/flash.c	2007-01-03 11:31:44.000000000 +0100
+++ u-boot-orig/board/atmel/ngw/flash.c	2007-01-03 11:33:13.000000000 +0100
@@ -161,7 +161,7 @@
 {
 	unsigned long flags;
 	uint16_t *base, *p, *s, *end;
-	uint16_t word, status;
+	uint16_t word, status,status1;
 	int ret = ERR_OK;
 
 	if (addr < info->start[0]
@@ -196,20 +196,36 @@
 		sync_write_buffer();
 
 		/* Wait for completion */
-		do {
+        status1 = readw(p);
+        do {
 			/* TODO: Timeout */
-			status = readw(p);
-		} while ((status != word) && !(status & 0x28));
-
+            status = status1;
+            status1=readw(p);
+        } while ( ((status ^ status1) & 0x40) && // toggle bit has toggled
+                 !(status1 & 0x28) // status is "working"
+                );
+
+        // We'll need to check once again for toggle bit because the toggle bit
+        // may stop toggling as I/O5 changes to "1" (ref at49bv642.pdf p9)
+        status1=readw(p);
+        status=readw(p);
+        if ((status ^ status1) & 0x40)
+        {
+			printf("Flash write error at address 0x%p: 0x%02x != 0x%02x\n",
+			       p, status,word);
+            ret = ERR_PROG_ERROR;
+            writew(0xf0, base);
+            readw(base);
+            break;
+        }
+        // we can now verify status==word if we want to.
+
+        // is this Product ID Exit command really required??
+        // --If configuration is 00 (the default) the device is allready in read mode,
+        // and the instruction is not required!
 		writew(0xf0, base);
 		readw(base);
 
-		if (status != word) {
-			printf("Flash write error at address 0x%p: 0x%02x\n",
-			       p, status);
-			ret = ERR_PROG_ERROR;
-			break;
-		}
 	}
 
 	local_irq_restore(flags);
Index: u-boot-orig/board/atstk1000/flash.c
===================================================================
--- u-boot-orig.orig/board/atstk1000/flash.c	2007-01-03 11:31:44.000000000 +0100
+++ u-boot-orig/board/atstk1000/flash.c	2007-01-03 11:33:13.000000000 +0100
@@ -160,7 +160,7 @@
 {
 	unsigned long flags;
 	uint16_t *base, *p, *s, *end;
-	uint16_t word, status;
+	uint16_t word, status,status1;
 	int ret = ERR_OK;
 
 	if (addr < info->start[0]
@@ -195,20 +195,36 @@
 		sync_write_buffer();
 
 		/* Wait for completion */
-		do {
+        status1 = readw(p);
+        do {
 			/* TODO: Timeout */
-			status = readw(p);
-		} while ((status != word) && !(status & 0x28));
-
+            status = status1;
+            status1=readw(p);
+        } while ( ((status ^ status1) & 0x40) && // toggle bit has toggled
+                 !(status1 & 0x28) // status is "working"
+                );
+
+        // We'll need to check once again for toggle bit because the toggle bit
+        // may stop toggling as I/O5 changes to "1" (ref at49bv642.pdf p9)
+        status1=readw(p);
+        status=readw(p);
+        if ((status ^ status1) & 0x40)
+        {
+			printf("Flash write error at address 0x%p: 0x%02x != 0x%02x\n",
+			       p, status,word);
+            ret = ERR_PROG_ERROR;
+            writew(0xf0, base);
+            readw(base);
+            break;
+        }
+        // we can now verify status==word if we want to.
+
+        // is this Product ID Exit command really required??
+        // --If configuration is 00 (the default) the device is allready in read mode,
+        // and the instruction is not required!
 		writew(0xf0, base);
 		readw(base);
 
-		if (status != word) {
-			printf("Flash write error at address 0x%p: 0x%02x\n",
-			       p, status);
-			ret = ERR_PROG_ERROR;
-			break;
-		}
 	}
 
 	local_irq_restore(flags);