summaryrefslogtreecommitdiff
path: root/cleopatre/u-boot-1.1.6/net
diff options
context:
space:
mode:
authordraskovic2009-05-15 17:05:06 +0000
committerdraskovic2009-05-15 17:05:06 +0000
commit9867b2984fdaa98a7c4645beec0ea1f3f5fcb18a (patch)
treeb44fc35ab191058925a248e58ee9d5d113da415c /cleopatre/u-boot-1.1.6/net
parenta505444632a724b995d1e9eb3ba2f0aa01b1eb9a (diff)
[CLEO][U-BOOT]Implemeted erase function in spidupd.
git-svn-id: svn+ssh://pessac/svn/cesar/trunk@4666 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'cleopatre/u-boot-1.1.6/net')
-rw-r--r--cleopatre/u-boot-1.1.6/net/spidupd.c67
1 files changed, 50 insertions, 17 deletions
diff --git a/cleopatre/u-boot-1.1.6/net/spidupd.c b/cleopatre/u-boot-1.1.6/net/spidupd.c
index 340846befc..f42d7dbc31 100644
--- a/cleopatre/u-boot-1.1.6/net/spidupd.c
+++ b/cleopatre/u-boot-1.1.6/net/spidupd.c
@@ -39,6 +39,7 @@ static unsigned char *upd_addr; /* addr on which we will load ne
#define IMG_0_ADDR (unsigned char *)0x00140000
#define IMG_1_ADDR (unsigned char *)0x004a0000
+#define IMG_FLASH_SIZE 0x360000
#define DUAL_BOOT
@@ -207,33 +208,65 @@ static __inline__ int
store_img (void)
{
int rc = 0;
+ flash_info_t * flinfo = &( flash_info[0] ); /* we expect HW to have only one flash, thus only one flinfo */
+ int i = 0;
+
+ /* Erase the flash */
+ /* In order to erase flash, we will use function flash_sect_erase (ulong addr_first, ulong addr_last),
+ * which demands first parameter to be on sector boundary, and the second actually last addr in some sector.
+ * We have to find last adress of the last sector that holds our image.
+ * Note: if we write 0x360000 bytes long image to address 0x140000
+ * last addr will be 49ffff (0x14000 + 0x35ffff), not 0x4a0000 (0x14000 + 0x360000)
+ */
+
+ while( flinfo->start[i] < upd_addr + IMG_FLASH_SIZE )
+ {
+ i++;
+ }
+
+ /* now i holds the number of the first sector after our image end address */
+ printf("Erasing the flash from the addr %#x to the addr %#x...\n", upd_addr, flinfo->start[i] - 1);
-#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
- size_t l = upd_img_len;
- void *to = (void *)upd_addr;
- void *from = (void *)UPD_IMG_RAM_ADDR;
+ rc = flash_sect_erase( upd_addr, flinfo->start[i] - 1 );
+ if (rc!=ERR_OK)
+ {
+ printf ("\n ");
+ flash_perror (rc);
+ return rc;
+ }
+ else
+ {
+ printf (" done.\n");
+ }
- while (l > 0)
+#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
{
- size_t tail = (l > CHUNKSZ) ? CHUNKSZ : l;
- WATCHDOG_RESET();
-
- rc = flash_write (from, to, tail);
+ size_t l = upd_img_len;
+ void *to = (void *)upd_addr;
+ void *from = (void *)UPD_IMG_RAM_ADDR;
- to += tail;
- from += tail;
- l -= tail;
+ while (l > 0)
+ {
+ size_t tail = (l > CHUNKSZ) ? CHUNKSZ : l;
+ WATCHDOG_RESET();
+
+ rc = flash_write (from, to, tail);
+
+ to += tail;
+ from += tail;
+ l -= tail;
+ }
}
#else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
-
- rc = flash_write ( (char *)UPD_IMG_RAM_ADDR, (ulong)upd_addr, upd_img_len);
- putc ('\n');
-
+ {
+ rc = flash_write ( (char *)UPD_IMG_RAM_ADDR, (ulong)upd_addr, upd_img_len);
+ putc ('\n');
+ }
#endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
if (rc) {
flash_perror (rc);
- NetState = NETLOOP_FAIL;
+ printf ("\n ");
}
return rc;
}