This is the mail archive of the ecos-patches@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

more changes to at91 flash driver


Hi,

I made some more changes to the at91 flash driver. Because
the AT29LV1024 flash chip implicitly erases blocks before
programming, the erase routine was implemented as a
dummy that just returned a success code without actually
erasing anything. However, the redboot FIS system relies
heavily on the fact that after erasing memory contains 0xffff.
So I implemented a real erase routine in the driver. The original
code also failed to re-enable the cache if programming the
flash was unsuccessful.



diff -ru -x CVS ecos/packages/devs/flash/arm/at91/current/src/at91_flash.c
ecos-work/packages/devs/flash/arm/at91/current/src/at91_flash.c
--- ecos/packages/devs/flash/arm/at91/current/src/at91_flash.c	2002-05-24
01:00:50.000000000 +0200
+++ ecos-work/packages/devs/flash/arm/at91/current/src/at91_flash.c
2002-06-13 11:45:42.000000000 +0200
@@ -89,8 +89,8 @@
     }
 
     if (data[1] == (unsigned short)FLASH_ATMEL_29LV1024) {
-        num_regions = 256;
-        region_size = 0x100;
+        num_regions = N_FLASH_SECTORS;
+        region_size = FLASH_PAGE_SIZE;
     } else {
         (*flash_info.pf)("Unknown device type: %x\n", data[1]);
         return FLASH_ERR_HWR;
@@ -99,8 +99,8 @@
     // Hard wired for now
     flash_info.block_size = region_size;
     flash_info.blocks = num_regions;
-    flash_info.start = (void *)0x01010000;
-    flash_info.end = (void *)(0x01010000+(num_regions*region_size));
+    flash_info.start = (void *) FLASH_BASE;
+    flash_info.end = (void *)(FLASH_BASE +(num_regions*region_size));
     return FLASH_ERR_OK;
 }
 
diff -ru -x CVS ecos/packages/devs/flash/arm/at91/current/src/flash.h
ecos-work/packages/devs/flash/arm/at91/current/src/flash.h
--- ecos/packages/devs/flash/arm/at91/current/src/flash.h	2002-05-24
01:00:50.000000000 +0200
+++ ecos-work/packages/devs/flash/arm/at91/current/src/flash.h	2002-06-13
11:45:53.000000000 +0200
@@ -75,4 +75,14 @@
 #define FLASH_PAGE_MASK   ~(FLASH_PAGE_SIZE-1)
 #define FLASH_PAGE_OFFSET  (FLASH_PAGE_SIZE-1)
 
+#define USE_FULL_FLASH 1
+
+#if USE_FULL_FLASH
+# define N_FLASH_SECTORS 512
+# define FLASH_BASE 0x01000000
+#else
+# define N_FLASH_SECTORS 256
+# define FLASH_BASE 0x01010000
+#endif
+
 #endif  // _FLASH_HWR_H_
diff -ru -x CVS
ecos/packages/devs/flash/arm/at91/current/src/flash_erase_block.c
ecos-work/packages/devs/flash/arm/at91/current/src/flash_erase_block.c
--- ecos/packages/devs/flash/arm/at91/current/src/flash_erase_block.c
2002-05-24 01:00:50.000000000 +0200
+++ ecos-work/packages/devs/flash/arm/at91/current/src/flash_erase_block.c
2002-06-14 18:12:58.000000000 +0200
@@ -41,7 +41,7 @@
 //#####DESCRIPTIONBEGIN####
 //
 // Author(s):    gthomas
-// Contributors: gthomas
+// Contributors: gthomas, tkoeller
 // Date:         2001-07-17
 // Purpose:      
 // Description:  
@@ -56,16 +56,43 @@
 #include <cyg/hal/hal_arch.h>
 #include <cyg/hal/hal_cache.h>
 
-//
+/*
 // CAUTION!  This code must be copied to RAM before execution.  Therefore,
 // it must not contain any code which might be position dependent!
-//
+*/
 
-int flash_erase_block(volatile unsigned long *block)
+int flash_erase_block(volatile unsigned short *block)
 {
+  int cache_on, i, timeout = 50000;
+  volatile unsigned short * ROM;
+
+  HAL_DCACHE_IS_ENABLED(cache_on);
+  if (cache_on)
+  {
+    HAL_DCACHE_SYNC();
+    HAL_DCACHE_DISABLE();
+  }
+
+  ROM = (volatile unsigned short *)((unsigned long)block & 0xFFFF0000);
+
+  /* Send lead-in sequence */
+  ROM[FLASH_Key_Addr0] = FLASH_Key0;
+  ROM[FLASH_Key_Addr1] = FLASH_Key1;
+
+  /* Send 'write' command */
+  ROM[FLASH_Key_Addr0] = FLASH_Program;
+
+  /* Clear block to 0xffff */
+  for (i = 0; i < FLASH_PAGE_SIZE/2; i++)
+    block[i] = 0xffff;
+
+  // Wait for data to be programmed
+  while (timeout-- > 0)
+    if (block[(FLASH_PAGE_SIZE/2) - 1] == 0xffff)
+      break;
 
-// This device is implicitly erased as each sector needs to be written
-// as a whole.  Thus, this is a NOP
+  if (cache_on)
+      HAL_DCACHE_ENABLE();
 
-    return 0;
+  return timeout > 0 ? FLASH_PROGRAM_OK : FLASH_PROGRAM_ERROR;
 }
diff -ru -x CVS
ecos/packages/devs/flash/arm/at91/current/src/flash_program_buf.c
ecos-work/packages/devs/flash/arm/at91/current/src/flash_program_buf.c
--- ecos/packages/devs/flash/arm/at91/current/src/flash_program_buf.c
2002-05-24 01:00:50.000000000 +0200
+++ ecos-work/packages/devs/flash/arm/at91/current/src/flash_program_buf.c
2002-06-14 17:24:31.000000000 +0200
@@ -123,5 +123,5 @@
         HAL_DCACHE_ENABLE();
     }
 
-    return FLASH_PROGRAM_OK;
+    return timeout > 0 ? FLASH_PROGRAM_OK : FLASH_PROGRAM_ERROR;
 }
diff -ru -x CVS ecos/packages/devs/flash/arm/at91/current/src/flash_query.c
ecos-work/packages/devs/flash/arm/at91/current/src/flash_query.c
--- ecos/packages/devs/flash/arm/at91/current/src/flash_query.c	2002-05-24
01:00:50.000000000 +0200
+++ ecos-work/packages/devs/flash/arm/at91/current/src/flash_query.c
2002-06-13 11:44:58.000000000 +0200
@@ -76,7 +76,7 @@
         HAL_DCACHE_DISABLE();
     }
 
-    ROM = (volatile unsigned short *)0x01010000;
+    ROM = (volatile unsigned short *) FLASH_BASE;
 
     // Send lead-in sequence
     ROM[FLASH_Key_Addr0] = FLASH_Key0;



----------------------------------------------- 
Thomas Koeller, Software Development 

Basler Vision Technologies 
An der Strusbek 60-62 
22926 Ahrensburg 
Germany 

Tel +49 (4102) 463-390 
Fax +49 (4102) 463-46390

mailto:Thomas.Koeller@baslerweb.com 
http://www.baslerweb.com 




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]