1 diff -urN at91bootstrap-2.3-0rig/driver/dataflash.c at91bootstrap-2.3.4/driver/dataflash.c
2 --- at91bootstrap-2.3-0rig/driver/dataflash.c 2007-04-22 13:56:29.000000000 +0200
3 +++ at91bootstrap-2.3.4/driver/dataflash.c 2007-09-24 20:56:18.000000000 +0200
5 #include "../include/part.h"
6 #include "../include/main.h"
7 #include "../include/dataflash.h"
8 +#include "../include/debug.h"
15 extern div_t udiv(unsigned int numerator, unsigned int denominator);
16 /* Write SPI register */
19 write_spi(SPI_CR, AT91C_SPI_SPIEN);
25 /*------------------------------------------------------------------------------*/
28 /* Try to get the dataflash semaphore */
29 if ((pDataFlash->bSemaphore) != UNLOCKED)
31 + return (char) FAILURE;
32 pDataFlash->bSemaphore = LOCKED;
34 /* Compute command pattern */
35 dInternalAdr = (result.quot << AT91C_PAGE_OFFSET(pDataFlash)) + result.rem;
37 if (AT91C_DF_NB_PAGE(pDataFlash) >= 16384)
39 pDataFlash->command[0] = (bCmd & 0x000000FF) | \
42 while (df_is_busy(pDataFlash) == LOCKED);
48 /*------------------------------------------------------------------------------*/
50 if (df_get_status(pDataFlash))
52 if (df_is_ready(pDataFlash))
63 /*------------------------------------------------------------------------------*/
65 /* \brief Read a block in dataflash */
69 unsigned int SizeToRead;
75 - SizeToRead = (size < AT91C_MAX_PDC_SIZE)? size : AT91C_MAX_PDC_SIZE;
77 + SizeToRead = (size < 0x8000)? size : 0x8000;
78 /* wait the dataflash ready status */
80 - df_continuous_read(pDf, (char *)buffer, SizeToRead, addr);
84 - buffer += SizeToRead;
85 + if(df_wait_ready(pDf) != 0) {
86 + df_continuous_read(pDf, (char *)buffer, SizeToRead, addr);
88 + if(--page_counter <= 0) {
94 + buffer += SizeToRead;
96 + /* We got a timeout */
97 + dbg_print("Timeout while waiting for dataflash ready\n");
106 /*----------------------------------------------------------------------*/
107 @@ -235,13 +246,19 @@
108 /*----------------------------------------------------------------------*/
109 static int df_download(AT91PS_DF pDf, unsigned int img_addr, unsigned int img_size, unsigned int img_dest)
111 + dbg_print(">Loading from Dataflash[");
112 + dbg_print_hex(img_addr);
113 + dbg_print("] to SDRAM[");
114 + dbg_print_hex(img_dest);
115 + dbg_print("]\r\n");
116 /* read bytes in the dataflash */
117 - df_read(pDf, img_addr,(unsigned char *)img_dest, img_size);
119 + if(df_read(pDf, img_addr,(unsigned char *)img_dest, img_size) == FAILURE)
121 + dbg_print("\r\n>Loading complete, [");
122 + dbg_print_hex(IMG_SIZE);
123 + dbg_print("] bytes\r\n");
124 /* wait the dataflash ready status */
125 - df_wait_ready(pDf);
128 + return df_wait_ready(pDf);
131 /*----------------------------------------------------------------------*/
133 static int df_init (AT91PS_DF pDf)
137 + int status = SUCCESS;
139 /* Default: AT45DB321B */
140 pDf->dfDescription.pages_number = 8192;
141 @@ -302,18 +319,21 @@
142 pDf->dfDescription.pages_number = 4096;
143 pDf->dfDescription.pages_size = 528;
144 pDf->dfDescription.page_offset = 10;
145 + dbg_print(">AT45DB161D detected\r\n");
149 pDf->dfDescription.pages_number = 8192;
150 pDf->dfDescription.pages_size = 528;
151 pDf->dfDescription.page_offset = 10;
152 + dbg_print(">AT45DB321D detected\r\n");
156 pDf->dfDescription.pages_number = 8192;
157 pDf->dfDescription.pages_size = 1056;
158 pDf->dfDescription.page_offset = 11;
159 + dbg_print(">AT45DB642D detected\r\n");
172 @@ -357,12 +377,12 @@
175 if ((buffer[i] != 0xEA) && (buffer[i] != 0xE5) )
186 /*------------------------------------------------------------------------------*/
187 @@ -374,13 +394,14 @@
189 AT91PS_DF pDf = (AT91PS_DF)&sDF;
190 unsigned int rxBuffer[128];
191 + unsigned int status;
193 pDf->bSemaphore = UNLOCKED;
195 df_spi_init(pcs, DF_CS_SETTINGS);
199 + if (df_init(pDf) == FAILURE)
203 /* Test if a button has been pressed or not */
204 @@ -391,10 +412,13 @@
205 df_continuous_read(pDf, (char *)rxBuffer, 32, img_addr);
208 - if (df_is_boot_valid((unsigned char*)rxBuffer))
210 + if (df_is_boot_valid((unsigned char*)rxBuffer) == FAILURE) {
211 + dbg_print(">Invalid Boot Area...\n\r");
215 - return df_download(pDf, img_addr, img_size, img_dest);
216 + status = df_download(pDf, img_addr, img_size, img_dest);
220 #endif /* CFG_DATAFLASH */
221 diff -urN at91bootstrap-2.3-0rig/driver/debug.c at91bootstrap-2.3.4/driver/debug.c
222 --- at91bootstrap-2.3-0rig/driver/debug.c 2006-12-05 11:27:24.000000000 +0100
223 +++ at91bootstrap-2.3.4/driver/debug.c 2007-09-24 20:38:01.000000000 +0200
228 +void dbg_print_hex(unsigned int data)
230 + unsigned char hex[11];
234 + for(i = 9 ;i >= 2;i--) {
235 + hex[i] = "0123456789ABCDEF"[data & 0xF];
239 + dbg_print((const char *) hex);
243 #endif /* CFG_DEBUG */
244 diff -urN at91bootstrap-2.3-0rig/include/debug.h at91bootstrap-2.3.4/include/debug.h
245 --- at91bootstrap-2.3-0rig/include/debug.h 2006-12-05 11:27:20.000000000 +0100
246 +++ at91bootstrap-2.3.4/include/debug.h 2007-09-24 18:26:37.000000000 +0200
248 /* Global functions */
249 extern void dbg_init(unsigned int);
250 extern void dbg_print(const char *ptr);
251 +extern void dbg_print_hex(unsigned int data);
254 diff -urN at91bootstrap-2.3-0rig/Makefile at91bootstrap-2.3.4/Makefile
255 --- at91bootstrap-2.3-0rig/Makefile 2007-09-24 18:26:10.000000000 +0200
256 +++ at91bootstrap-2.3.4/Makefile 2007-09-24 20:56:53.000000000 +0200
260 ifeq ($(CONFIG_SPI_CLK),)
261 -CONFIG_SPI_CLK=5000000
262 +CONFIG_SPI_CLK=33000000