changeset 1270:244c544171e7

* src/flash_lock_block.c (flash_lock_block): * src/flash_unlock_block.c (flash_unlock_block): * src/flash_erase_block.c (flash_erase_block): * src/flash_query.c (flash_query): * src/flash_program_buf.c (flash_program_buf): Put flash functions in RAM using section attributes instead of the old method. * src/iq80310_flash.c (flash_hwr_init): Use generic flash_query_dev.
author asl
date Sat, 04 Oct 2003 18:30:20 +0000
parents 46534b4d0054
children 8eb2d0d3c498
files packages/devs/flash/arm/iq80310/current/ChangeLog packages/devs/flash/arm/iq80310/current/cdl/flash_iq80310.cdl packages/devs/flash/arm/iq80310/current/src/flash_erase_block.c packages/devs/flash/arm/iq80310/current/src/flash_lock_block.c packages/devs/flash/arm/iq80310/current/src/flash_program_buf.c packages/devs/flash/arm/iq80310/current/src/flash_query.c packages/devs/flash/arm/iq80310/current/src/flash_unlock_block.c packages/devs/flash/arm/iq80310/current/src/iq80310_flash.c
diffstat 8 files changed, 40 insertions(+), 85 deletions(-) [+]
line wrap: on
line diff
--- a/packages/devs/flash/arm/iq80310/current/ChangeLog
+++ b/packages/devs/flash/arm/iq80310/current/ChangeLog
@@ -1,3 +1,13 @@
+2003-09-16  Jani Monoses <jani@iv.ro>
+
+	* src/flash_lock_block.c (flash_lock_block): 
+	* src/flash_unlock_block.c (flash_unlock_block): 
+	* src/flash_erase_block.c (flash_erase_block): 
+	* src/flash_query.c (flash_query): 
+	* src/flash_program_buf.c (flash_program_buf): Put flash functions
+	in RAM using section attributes instead of the old method.
+	* src/iq80310_flash.c (flash_hwr_init): Use generic flash_query_dev. 
+	
 2003-04-04  Jani Monoses <jani@iv.ro>
 
 	* src/flash_lock_block.c (flash_lock_block): 
--- a/packages/devs/flash/arm/iq80310/current/cdl/flash_iq80310.cdl
+++ b/packages/devs/flash/arm/iq80310/current/cdl/flash_iq80310.cdl
@@ -58,53 +58,18 @@ cdl_package CYGPKG_DEVS_FLASH_ARM_XSCALE
     requires	  CYGPKG_HAL_ARM_XSCALE_IOP310
 
     implements    CYGHWR_IO_FLASH_DEVICE
-    implements    CYGHWR_IO_FLASH_DEVICE_NOT_IN_RAM
     implements    CYGHWR_IO_FLASH_BLOCK_LOCKING
 
     include_dir   .
     include_files ; # none _exported_ whatsoever
     description   "FLASH memory device support for Cyclone IQ80310"
-    compile       iq80310_flash.c
-
-    make -priority 1 {
-        flash_erase_block.o: $(REPOSITORY)/$(PACKAGE)/src/flash_erase_block.c
-        $(CC) -S $(INCLUDE_PATH) $(CFLAGS) -g0 -fno-function-sections $(REPOSITORY)/$(PACKAGE)/src/flash_erase_block.c
-        echo " .globl flash_erase_block_end" >>flash_erase_block.s
-        echo "flash_erase_block_end:" >>flash_erase_block.s
-        $(CC) $(CFLAGS) -c -o flash_erase_block.o flash_erase_block.s
-        $(AR) rcs $(PREFIX)/lib/libtarget.a flash_erase_block.o
-    }
-    make -priority 1 {
-        flash_program_buf.o: $(REPOSITORY)/$(PACKAGE)/src/flash_program_buf.c
-        $(CC) -S $(INCLUDE_PATH) $(CFLAGS) -g0 -fno-function-sections $(REPOSITORY)/$(PACKAGE)/src/flash_program_buf.c
-        echo " .globl flash_program_buf_end" >>flash_program_buf.s
-        echo "flash_program_buf_end:" >>flash_program_buf.s
-        $(CC) $(CFLAGS) -c -o flash_program_buf.o flash_program_buf.s
-        $(AR) rcs $(PREFIX)/lib/libtarget.a flash_program_buf.o
-    }
-    make -priority 1 {
-        flash_query.o: $(REPOSITORY)/$(PACKAGE)/src/flash_query.c
-        $(CC) -S $(INCLUDE_PATH) $(CFLAGS) -g0 -fno-function-sections $(REPOSITORY)/$(PACKAGE)/src/flash_query.c
-        echo " .globl flash_query_end" >>flash_query.s
-        echo "flash_query_end:" >>flash_query.s
-        $(CC) $(CFLAGS) -c -o flash_query.o flash_query.s
-        $(AR) rcs $(PREFIX)/lib/libtarget.a flash_query.o
-    }
-    make -priority 1 {
-        flash_lock_block.o: $(REPOSITORY)/$(PACKAGE)/src/flash_lock_block.c
-        $(CC) -S $(INCLUDE_PATH) $(CFLAGS) -g0 -fno-function-sections $(REPOSITORY)/$(PACKAGE)/src/flash_lock_block.c
-        echo " .globl flash_lock_block_end" >>flash_lock_block.s
-        echo "flash_lock_block_end:" >>flash_lock_block.s
-        $(CC) $(CFLAGS) -c -o flash_lock_block.o flash_lock_block.s
-        $(AR) rcs $(PREFIX)/lib/libtarget.a flash_lock_block.o
-    }
-    make -priority 1 {
-        flash_unlock_block.o: $(REPOSITORY)/$(PACKAGE)/src/flash_unlock_block.c
-        $(CC) -S $(INCLUDE_PATH) $(CFLAGS) -g0 -fno-function-sections $(REPOSITORY)/$(PACKAGE)/src/flash_unlock_block.c
-        echo " .globl flash_unlock_block_end" >>flash_unlock_block.s
-        echo "flash_unlock_block_end:" >>flash_unlock_block.s
-        $(CC) $(CFLAGS) -c -o flash_unlock_block.o flash_unlock_block.s
-        $(AR) rcs $(PREFIX)/lib/libtarget.a flash_unlock_block.o
+    compile       iq80310_flash.c flash_erase_block.c flash_program_buf.c flash_query.c
+    
+    cdl_component  CYGPKG_DEVS_FLASH_IQ80310_LOCKING {
+	display "Flash device implements locking"
+	active_if 0 < CYGHWR_IO_FLASH_BLOCK_LOCKING
+	calculated 1
+	compile flash_lock_block.c flash_unlock_block.c
     }
 }
 
--- a/packages/devs/flash/arm/iq80310/current/src/flash_erase_block.c
+++ b/packages/devs/flash/arm/iq80310/current/src/flash_erase_block.c
@@ -55,12 +55,10 @@
 #include <pkgconf/hal.h>
 #include <cyg/hal/hal_arch.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 char *block)
+	__attribute__ ((section (".2ram.flash_erase_block")));
+int flash_erase_block(volatile unsigned char *block)
 {
     volatile unsigned char *ROM;
     unsigned short stat;
--- a/packages/devs/flash/arm/iq80310/current/src/flash_lock_block.c
+++ b/packages/devs/flash/arm/iq80310/current/src/flash_lock_block.c
@@ -53,13 +53,12 @@
 #include "flash.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_lock_block(volatile unsigned char *block)
+	__attribute__ ((section (".2ram.flash_lock_block")));
+int
+flash_lock_block(volatile unsigned char *block)
 {
     volatile unsigned char *ROM;
     unsigned short stat;
--- a/packages/devs/flash/arm/iq80310/current/src/flash_program_buf.c
+++ b/packages/devs/flash/arm/iq80310/current/src/flash_program_buf.c
@@ -55,13 +55,12 @@
 #include <pkgconf/hal.h>
 #include <cyg/hal/hal_arch.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_program_buf(volatile unsigned char *addr, unsigned char *data, int len)
+ __attribute__ ((section (".2ram.flash_program_buf")));
+int
+flash_program_buf(volatile unsigned char *addr, unsigned char *data, int len)
 {
     volatile unsigned char *ROM;
     volatile unsigned char *BA;
--- a/packages/devs/flash/arm/iq80310/current/src/flash_query.c
+++ b/packages/devs/flash/arm/iq80310/current/src/flash_query.c
@@ -56,20 +56,18 @@
 #include <cyg/hal/hal_arch.h>
 #include CYGHWR_MEMORY_LAYOUT_H
 
-//
-// CAUTION!  This code must be copied to RAM before execution.  Therefore,
-// it must not contain any code which might be position dependent!
-//
 
 #define CNT 200*1000*10  // Approx 20ms
 
 int
+flash_query(unsigned char *data)  __attribute__ ((section (".2ram.flash_query")));
+int
 flash_query(unsigned char *data)
 {
     volatile unsigned short *ROM;
     int i, cnt;
 
-    ROM = FLASH_P2V(0);
+    ROM = (unsigned short *) FLASH_P2V(0);
     ROM[0] = FLASH_Read_Query;
     for (cnt = CNT;  cnt > 0;  cnt--) ;
     for (i = 0;  i < sizeof(struct FLASH_query);  i++) {
--- a/packages/devs/flash/arm/iq80310/current/src/flash_unlock_block.c
+++ b/packages/devs/flash/arm/iq80310/current/src/flash_unlock_block.c
@@ -53,10 +53,6 @@
 #include "flash.h"
 
 
-//
-// CAUTION!  This code must be copied to RAM before execution.  Therefore,
-// it must not contain any code which might be position dependent!
-//
 
 //
 // The difficulty with this operation is that the hardware does not support
@@ -70,6 +66,9 @@
 
 int
 flash_unlock_block(volatile unsigned char *block, int block_size, int blocks)
+	__attribute__ ((section (".2ram.flash_unlock_block")));
+int
+flash_unlock_block(volatile unsigned char *block, int block_size, int blocks)
 {
     volatile unsigned short *ROM, *bp;
     unsigned short stat;
@@ -77,7 +76,7 @@ flash_unlock_block(volatile unsigned cha
     unsigned short is_locked[MAX_FLASH_BLOCKS];
     int i;
 
-    ROM = FLASH_P2V((unsigned long)block & 0xFF800000);
+    ROM = (unsigned short *) FLASH_P2V((unsigned long)block & 0xFF800000);
 
     // Clear any error conditions
     ROM[0] = FLASH_Clear_Status;
@@ -86,7 +85,7 @@ flash_unlock_block(volatile unsigned cha
     // the device so currently locked blocks can be re-locked.
     bp = (unsigned short *)((unsigned long)block & 0xFF800000);
     for (i = 0;  i < blocks;  i++) {
-        if (bp == block) {
+        if (bp == (unsigned short *) block) {
             is_locked[i] = 0;
         } else {
 	    *(volatile unsigned short *)FLASH_P2V(bp) = FLASH_Read_Query;
@@ -104,7 +103,7 @@ flash_unlock_block(volatile unsigned cha
     }
 
     // Restore the lock state
-    bp = (unsigned char *)((unsigned long)block & 0xFF800000);
+    bp = (unsigned short *)((unsigned long)block & 0xFF800000);
     for (i = 0;  i < blocks;  i++) {
         if (is_locked[i]) {
             *FLASH_P2V(bp) = FLASH_Set_Lock;
--- a/packages/devs/flash/arm/iq80310/current/src/iq80310_flash.c
+++ b/packages/devs/flash/arm/iq80310/current/src/iq80310_flash.c
@@ -52,7 +52,7 @@
 
 #include <pkgconf/hal.h>
 #include <cyg/hal/hal_arch.h>
-#include <cyg/hal/hal_cache.h>
+#include <cyg/infra/diag.h>
 
 #define  _FLASH_PRIVATE_
 #include <cyg/io/flash.h>
@@ -61,28 +61,15 @@
 
 #define _si(p) ((p[1]<<8)|p[0])
 
+extern int strncmp(const char *s1, const char *s2, size_t len);
 int
 flash_hwr_init(void)
 {
     struct FLASH_query data, *qp;
-    extern char flash_query, flash_query_end;
-    typedef int code_fun(unsigned char *);
-    code_fun *_flash_query;
-    int code_len, stat, num_regions, region_size, icache_isenabled;
+    int num_regions, region_size;
 
-    // Copy 'program' code to RAM for execution
-    code_len = (unsigned long)&flash_query_end - (unsigned long)&flash_query;
-    _flash_query = (code_fun *)flash_info.work_space;
-    memcpy(_flash_query, &flash_query, code_len);
-    HAL_ICACHE_IS_ENABLED(icache_isenabled);
-    HAL_DCACHE_SYNC();  // Should guarantee this code will run
-    HAL_ICACHE_DISABLE(); // is also required to avoid old contents
-
-    memset(&data,0,sizeof(data));
-    stat = (*_flash_query)((void*)&data);
-    if (icache_isenabled)
-        HAL_ICACHE_ENABLE();
-
+    flash_dev_query((void*)&data);
+    
     qp = &data;
     if (/*(qp->manuf_code == FLASH_Intel_code) && */
         (strncmp(qp->id, "QRY", 3) == 0)) {
@@ -96,7 +83,7 @@ flash_hwr_init(void)
         return FLASH_ERR_OK;
     } else {
 	(*flash_info.pf)("Can't identify FLASH sorry\n");
-        diag_dump_buf(data, sizeof(data));
+        diag_dump_buf((void*)&data, sizeof(data));
         return FLASH_ERR_HWR;
     }
 }