summaryrefslogtreecommitdiff
path: root/packages/at91bootstrap/files/at91bootstrap-2.3.4.patch
blob: 4b94f63d2f0ffaf5c0c8a19897edfcc77cc21661 (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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
diff -urN at91bootstrap-2.3-0rig/driver/dataflash.c at91bootstrap-2.3.4/driver/dataflash.c
--- at91bootstrap-2.3-0rig/driver/dataflash.c	2007-04-22 13:56:29.000000000 +0200
+++ at91bootstrap-2.3.4/driver/dataflash.c	2007-09-24 20:56:18.000000000 +0200
@@ -39,8 +39,12 @@
 #include "../include/part.h"
 #include "../include/main.h"
 #include "../include/dataflash.h"
+#include "../include/debug.h"
 #include <stdlib.h>
 
+#define	SUCCESS	1
+#define	FAILURE	0
+
 #ifdef CFG_DATAFLASH
 extern	div_t udiv(unsigned int numerator, unsigned int denominator);
 /* Write SPI register */
@@ -92,7 +96,7 @@
 	/* SPI_Enable */
 	write_spi(SPI_CR, AT91C_SPI_SPIEN);
 
-	return 0;
+	return SUCCESS;
 }
 
 /*------------------------------------------------------------------------------*/
@@ -134,12 +138,10 @@
 
  	/* Try to get the dataflash semaphore */
 	if ((pDataFlash->bSemaphore) != UNLOCKED)
-		return (char) 0;
+		return (char) FAILURE;
 	pDataFlash->bSemaphore = LOCKED;
-
 	/* Compute command pattern */
 	dInternalAdr = (result.quot << AT91C_PAGE_OFFSET(pDataFlash)) + result.rem;
-
  	if (AT91C_DF_NB_PAGE(pDataFlash) >= 16384)
 	{
 		pDataFlash->command[0] = (bCmd & 0x000000FF) | \
@@ -178,7 +180,7 @@
 
     	while (df_is_busy(pDataFlash) == LOCKED);
 
-	return 1;
+	return SUCCESS;
 }
 
 /*------------------------------------------------------------------------------*/
@@ -194,13 +196,13 @@
 		if (df_get_status(pDataFlash))
 		{
 			if (df_is_ready(pDataFlash))
-				return 1;
+				return SUCCESS;
 		}
 	}
 
-	return 0;
+	return FAILURE;
 }
-
+volatile	int loop;
 /*------------------------------------------------------------------------------*/
 /* \fn    df_read								*/
 /* \brief Read a block in dataflash						*/
@@ -212,21 +214,30 @@
 	unsigned int size)
 {
 	unsigned int SizeToRead;
+	int page_counter;
 
+	page_counter = 32;
 	while (size)
 	{
-		SizeToRead = (size < AT91C_MAX_PDC_SIZE)? size : AT91C_MAX_PDC_SIZE;
-
+		SizeToRead = (size < 0x8000)? size : 0x8000;
 		/* wait the dataflash ready status */
-		df_wait_ready(pDf);
-	    	df_continuous_read(pDf, (char *)buffer, SizeToRead, addr);
-
-		size -= SizeToRead;
-		addr += SizeToRead;
-		buffer += SizeToRead;
+		if(df_wait_ready(pDf) != 0) {
+		    	df_continuous_read(pDf, (char *)buffer, SizeToRead, addr);
+			dbg_print(".");
+			if(--page_counter <= 0) {
+				page_counter = 32;
+				dbg_print("\r\n");
+			}
+			size -= SizeToRead;
+			addr += SizeToRead;
+			buffer += SizeToRead;
+		} else {
+			/* We got a timeout */
+			dbg_print("Timeout while waiting for dataflash ready\n");
+			return FAILURE;
+		}
 	}
-
-   	return 0;
+   	return SUCCESS;
 }
 
 /*----------------------------------------------------------------------*/
@@ -235,13 +246,19 @@
 /*----------------------------------------------------------------------*/
 static int df_download(AT91PS_DF pDf, unsigned int img_addr, unsigned int img_size, unsigned int img_dest)
 {
+	dbg_print(">Loading from Dataflash[");
+	dbg_print_hex(img_addr);
+	dbg_print("] to SDRAM[");
+	dbg_print_hex(img_dest);
+	dbg_print("]\r\n");
 	/* read bytes in the dataflash */
-	df_read(pDf, img_addr,(unsigned char *)img_dest, img_size);
-
+	if(df_read(pDf, img_addr,(unsigned char *)img_dest, img_size) == FAILURE)
+		return FAILURE;
+	dbg_print("\r\n>Loading complete, [");
+	dbg_print_hex(IMG_SIZE);
+	dbg_print("] bytes\r\n");
 	/* wait the dataflash ready status */
-	df_wait_ready(pDf);
-
-    return 0;
+	return df_wait_ready(pDf);
 }
 
 /*----------------------------------------------------------------------*/
@@ -263,7 +280,7 @@
 static int df_init (AT91PS_DF pDf)
 {
 	int dfcode = 0;
-	int status = 1;
+	int status = SUCCESS;
 
 	/* Default: AT45DB321B */
 	pDf->dfDescription.pages_number = 8192;
@@ -302,18 +319,21 @@
 			pDf->dfDescription.pages_number = 4096;
 			pDf->dfDescription.pages_size = 528;
 			pDf->dfDescription.page_offset = 10;
+			dbg_print(">AT45DB161D detected\r\n");
 			break;
 
 		case AT45DB321B:
 			pDf->dfDescription.pages_number = 8192;
 			pDf->dfDescription.pages_size = 528;
 			pDf->dfDescription.page_offset = 10;
+			dbg_print(">AT45DB321D detected\r\n");
 			break;
 
 		case AT45DB642:
 			pDf->dfDescription.pages_number = 8192;
 			pDf->dfDescription.pages_size = 1056;
 			pDf->dfDescription.page_offset = 11;
+			dbg_print(">AT45DB642D detected\r\n");
 			break;
 /*
 		case AT45DB1282:
@@ -335,7 +355,7 @@
 			break;
 */
 		default:
-		        status = 0;
+		        status = FAILURE;
 			break;
 	}
 
@@ -357,12 +377,12 @@
 		if (i != 23)
 		{
 			if ((buffer[i] != 0xEA) && (buffer[i] != 0xE5) )
-				return -1;
+				return FAILURE;
 		}
 		i+=4;
     	}
 
-    	return 0;
+    	return SUCCESS;
 }
 
 /*------------------------------------------------------------------------------*/
@@ -374,13 +394,14 @@
     	AT91S_DF sDF;
     	AT91PS_DF pDf = (AT91PS_DF)&sDF;
     	unsigned int rxBuffer[128];
+	unsigned int status;
 
     	pDf->bSemaphore = UNLOCKED;
 
     	df_spi_init(pcs, DF_CS_SETTINGS);
 
-    	if (!df_init(pDf))
-        	return -1;
+    	if (df_init(pDf) == FAILURE)
+        	return FAILURE;
 
 #ifdef AT91SAM9260
 	/* Test if a button has been pressed or not */
@@ -391,10 +412,13 @@
     	df_continuous_read(pDf, (char *)rxBuffer, 32, img_addr);
 	df_wait_ready(pDf);
 
-	if (df_is_boot_valid((unsigned char*)rxBuffer))
-		return -1;
+	if (df_is_boot_valid((unsigned char*)rxBuffer) == FAILURE) {
+		dbg_print(">Invalid Boot Area...\n\r");
+		return FAILURE;
+	}
 
-	return df_download(pDf, img_addr, img_size, img_dest);
+	status = df_download(pDf, img_addr, img_size, img_dest);
+	return status;
 }
 
 #endif /* CFG_DATAFLASH */
diff -urN at91bootstrap-2.3-0rig/driver/debug.c at91bootstrap-2.3.4/driver/debug.c
--- at91bootstrap-2.3-0rig/driver/debug.c	2006-12-05 11:27:24.000000000 +0100
+++ at91bootstrap-2.3.4/driver/debug.c	2007-09-24 20:38:01.000000000 +0200
@@ -85,4 +85,19 @@
 	}
 }
 
+void dbg_print_hex(unsigned int data)
+{
+	unsigned char hex[11];
+	int i=0;
+	hex[0]='0';
+	hex[1]='x';
+	for(i = 9 ;i >= 2;i--) {
+		hex[i] = "0123456789ABCDEF"[data & 0xF];
+		data >>= 4;
+	}
+	hex[10]='\0';	
+	dbg_print((const char *) hex);
+}
+
+
 #endif /* CFG_DEBUG */
diff -urN at91bootstrap-2.3-0rig/include/debug.h at91bootstrap-2.3.4/include/debug.h
--- at91bootstrap-2.3-0rig/include/debug.h	2006-12-05 11:27:20.000000000 +0100
+++ at91bootstrap-2.3.4/include/debug.h	2007-09-24 18:26:37.000000000 +0200
@@ -45,5 +45,6 @@
 /* Global functions */
 extern void dbg_init(unsigned int);
 extern void dbg_print(const char *ptr);
+extern void dbg_print_hex(unsigned int data);
 
 #endif /*_DEBUG_H_*/
diff -urN at91bootstrap-2.3-0rig/Makefile at91bootstrap-2.3.4/Makefile
--- at91bootstrap-2.3-0rig/Makefile	2007-09-24 18:26:10.000000000 +0200
+++ at91bootstrap-2.3.4/Makefile	2007-09-24 20:56:53.000000000 +0200
@@ -17,7 +17,7 @@
 endif
 
 ifeq	($(CONFIG_SPI_CLK),)
-CONFIG_SPI_CLK=5000000
+CONFIG_SPI_CLK=33000000
 endif
 
 ifndef	MEMORY