changeset 2629:50cf5ea58609

Merge flashv2 branch to trunk, with eCosCentric additions
author jlarmour
date Tue, 18 Nov 2008 01:12:35 +0000
parents 7e2abfce9b6c
children 3e8e26d3183a
files packages/devs/flash/sst/39vfxxx/current/ChangeLog packages/devs/flash/sst/39vfxxx/current/cdl/flash_sst_39vfxxx.cdl packages/devs/flash/sst/39vfxxx/current/include/flash_sst_39vfxxx.inl packages/devs/flash/synthv2/current/ChangeLog packages/devs/flash/synthv2/current/cdl/flash_synth.cdl packages/devs/flash/synthv2/current/include/synth.h packages/devs/flash/synthv2/current/src/synth.c packages/devs/flash/synthv2/current/tests/flash1.c packages/devs/flash/synthv2/current/tests/flash2.c packages/devs/flash/synthv2/current/tests/flash3.c
diffstat 10 files changed, 1350 insertions(+), 73 deletions(-) [+]
line wrap: on
line diff
--- a/packages/devs/flash/sst/39vfxxx/current/ChangeLog
+++ b/packages/devs/flash/sst/39vfxxx/current/ChangeLog
@@ -1,3 +1,43 @@
+2004-11-29  Bart Veer  <bartv@ecoscentric.com>
+
+	* include/flash_sst_39vfxxx.inl: eliminate hwr_map_error(), no
+	longer needed by the generic flash code.
+	* include/flash_sst_39vfxxx.inl: use the dummy lock/unlock
+	functions provided by the generic flash code.
+
+2004-11-25  Bart Veer  <bartv@ecoscentric.com>
+
+	* cdl/flash_sst_39vfxxx.cdl: this V2 driver relies on the generic
+	flash code to handle the cache
+
+2004-11-22  Bart Veer  <bartv@ecoscentric.com>
+	
+	* include/flash_sst_39vfxxx.inl: assume static initialization and
+	adjust const's in various parameters
+	* include/flash_sst_39vfxxx.inl: rename cyg_block_info to
+	cyg_flash_block_info
+
+2004-09-14  Andrew Lunn  <andrew.lunn@ascom.ch>
+
+	* include/flash_sst_39vfxxx.inl: Set the end address to the last
+	valid address in flash, not the first invalid address.
+
+2004-08-06  Andrew Lunn  <andrew.lunn@ascom.ch>
+
+	* include/flash_sst_39vfxxx.inl: The structure declared by
+	CYG_FLASH_FUNS should be static so we can instantiate the
+	driver multiple times.
+
+2004-08-04  Andrew Lunn  <andrew.lunn@ascom.ch>
+
+	* include/flash_sst_39vfxxx.inl: Added support for the SST39VF160
+	device.
+
+2004-07-16  Andrew Lunn  <andrew.lunn@ascom.ch>
+
+	* include/flash_sst_39vfxxx.inl: Modified the driver to make use
+	of the new flash device API.
+
 2006-12-21  Wang Cui <iucgnaw@msn.com>
 
 	* include/flash_sst_39vfxxx.inl: Add supported devices:
@@ -15,6 +55,7 @@ 2003-10-02  Roland Caßebohm <r.cassebohm@visionsystems.de>
 // -------------------------------------------
 // This file is part of eCos, the Embedded Configurable Operating System.
 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
+// Copyright (C) 2006 eCosCentric Ltd.
 //
 // eCos is free software; you can redistribute it and/or modify it under
 // the terms of the GNU General Public License as published by the Free
--- a/packages/devs/flash/sst/39vfxxx/current/cdl/flash_sst_39vfxxx.cdl
+++ b/packages/devs/flash/sst/39vfxxx/current/cdl/flash_sst_39vfxxx.cdl
@@ -57,6 +57,7 @@ cdl_package CYGPKG_DEVS_FLASH_SST_39VFXX
     active_if     CYGINT_DEVS_FLASH_SST_39VFXXX_REQUIRED
 
     implements    CYGHWR_IO_FLASH_DEVICE
+    implements    CYGHWR_IO_FLASH_DEVICE_NEEDS_CACHE_HANDLED
 
     include_dir   cyg/io
 }
--- a/packages/devs/flash/sst/39vfxxx/current/include/flash_sst_39vfxxx.inl
+++ b/packages/devs/flash/sst/39vfxxx/current/include/flash_sst_39vfxxx.inl
@@ -11,6 +11,8 @@
 // -------------------------------------------
 // This file is part of eCos, the Embedded Configurable Operating System.
 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
+// Copyright (C) 2004 Andrew Lunn
+// Copyright (C) 2006 eCosCentric Ltd.
 //
 // eCos is free software; you can redistribute it and/or modify it under
 // the terms of the GNU General Public License as published by the Free
@@ -43,7 +45,7 @@
 //#####DESCRIPTIONBEGIN####
 //
 // Author(s):    gthomas
-// Contributors: gthomas, jskov, rcassebohm
+// Contributors: gthomas, jskov, rcassebohm, Andrew Lunn
 // Date:         2001-02-21
 // Purpose:      
 // Description:  
@@ -57,12 +59,12 @@
 #include <pkgconf/hal.h>
 #include <cyg/hal/hal_arch.h>
 #include <cyg/hal/hal_cache.h>
+#include <cyg/infra/cyg_ass.h>
 #include CYGHWR_MEMORY_LAYOUT_H
 
 #define  _FLASH_PRIVATE_
 #include <cyg/io/flash.h>
 
-
 //----------------------------------------------------------------------------
 // Common device details.
 #define FLASH_Read_ID                   FLASHWORD( 0x90 )
@@ -85,7 +87,6 @@
 // Platform code must define the below
 // #define CYGNUM_FLASH_INTERLEAVE      : Number of interleaved devices (in parallel)
 // #define CYGNUM_FLASH_SERIES          : Number of devices in series
-// #define CYGNUM_FLASH_BASE            : Address of first device
 // And select one of the below device variants
 
 #ifdef CYGPKG_DEVS_FLASH_SST_39VF080
@@ -202,56 +203,30 @@
 //----------------------------------------------------------------------------
 // Functions that put the flash device into non-read mode must reside
 // in RAM.
-void flash_query(void* data) __attribute__ ((section (".2ram.flash_query")));
-int  flash_erase_block(void* block, unsigned int size) 
-    __attribute__ ((section (".2ram.flash_erase_block")));
-int  flash_program_buf(void* addr, void* data, int len)
-    __attribute__ ((section (".2ram.flash_program_buf")));
+static size_t sst_query(struct cyg_flash_dev *dev, void* data, size_t len)
+  __attribute__ ((section (".2ram.flash_query")));
+static int sst_erase_block(struct cyg_flash_dev *dev, cyg_flashaddr_t block_base)
+  __attribute__ ((section (".2ram.flash_erase_block")));
+static int sst_program(struct cyg_flash_dev *dev, cyg_flashaddr_t base, 
+            const void* data, size_t length)
+  __attribute__ ((section (".2ram.flash_program_buf")));
 
 
 //----------------------------------------------------------------------------
 // Initialize driver details
-int
-flash_hwr_init(void)
+static int
+sst_init(struct cyg_flash_dev *dev)
 {
-    flash_data_t id[2];
-
-    flash_dev_query(id);
+  flash_data_t id[2];
 
-    // Check that flash_id data is matching the one the driver was
-    // configured for.
-    if (id[0] != CYGNUM_FLASH_ID_MANUFACTURER
-        || id[1] != CYGNUM_FLASH_ID_DEVICE)
-        return FLASH_ERR_DRV_WRONG_PART;
-
-    // Hard wired for now
-    flash_info.block_size = FLASH_BLOCK_SIZE;
-    flash_info.blocks = FLASH_NUM_REGIONS;
-    flash_info.start = (void *)CYGNUM_FLASH_BASE;
-    flash_info.end = (void *)(CYGNUM_FLASH_BASE+ (FLASH_NUM_REGIONS * FLASH_BLOCK_SIZE * CYGNUM_FLASH_SERIES));
-    return FLASH_ERR_OK;
-}
+  dev->funs->flash_query(dev,id,sizeof(id));
 
-//----------------------------------------------------------------------------
-// Map a hardware status to a package error
-int
-flash_hwr_map_error(int e)
-{
-    return e;
-}
-
-
-//----------------------------------------------------------------------------
-// See if a range of FLASH addresses overlaps currently running code
-bool
-flash_code_overlaps(void *start, void *end)
-{
-    extern unsigned char _stext[], _etext[];
-
-    return ((((unsigned long)&_stext >= (unsigned long)start) &&
-             ((unsigned long)&_stext < (unsigned long)end)) ||
-            (((unsigned long)&_etext >= (unsigned long)start) &&
-             ((unsigned long)&_etext < (unsigned long)end)));
+  // Check that flash_id data is matching the one the driver was
+  // configured for.
+  if (id[0] != CYGNUM_FLASH_ID_MANUFACTURER
+      || id[1] != CYGNUM_FLASH_ID_DEVICE)
+    return CYG_FLASH_ERR_DRV_WRONG_PART;
+  return CYG_FLASH_ERR_OK;
 }
 
 //----------------------------------------------------------------------------
@@ -261,14 +236,16 @@ flash_code_overlaps(void *start, void *e
 // device(s) in series. It is assumed that any devices in series
 // will be of the same type.
 
-void
-flash_query(void* data)
+static size_t
+sst_query(struct cyg_flash_dev *dev, void* data, size_t len)
 {
     volatile flash_data_t *ROM;
     flash_data_t* id = (flash_data_t*) data;
     int i;
+    
+    CYG_ASSERT(len == 2, "Invalid length");
 
-    ROM = (volatile flash_data_t*) CYGNUM_FLASH_BASE;
+    ROM = (volatile flash_data_t*) dev->start;
 
     ROM[FLASH_Setup_Addr1] = FLASH_Setup_Code1;
     ROM[FLASH_Setup_Addr2] = FLASH_Setup_Code2;
@@ -288,24 +265,26 @@ flash_query(void* data)
 
     // FIXME: 10ms delay
     for (i = 10000; i > 0; i--);
+    
+    return len;
 }
 
 //----------------------------------------------------------------------------
 // Erase Block
-int
-flash_erase_block(void* block, unsigned int len)
+static int
+sst_erase_block(struct cyg_flash_dev *dev, cyg_flashaddr_t block_base)
 {
     volatile flash_data_t* ROM;
-    volatile flash_data_t* addr_ptr = (volatile flash_data_t*) block;
+    volatile flash_data_t* addr_ptr = (volatile flash_data_t*) block_base;
+    int len = dev->block_info[0].block_size;
+    int res = CYG_FLASH_ERR_OK;
 
-    int res = FLASH_ERR_OK;
-
-    while ((FLASH_ERR_OK == res) && (len > 0)) {
+    while ((CYG_FLASH_ERR_OK == res) && (len > 0)) {
 	int timeout;
         flash_data_t state, prev_state;
 
         // Base address of device(s) being programmed. 
-        ROM = (volatile flash_data_t*)((unsigned long)block & ~(FLASH_DEVICE_SIZE-1));
+        ROM = (volatile flash_data_t*)((unsigned long)block_base & ~(FLASH_DEVICE_SIZE-1));
 
         // Program data [byte] - 6 step sequence
         ROM[FLASH_Setup_Addr1] = FLASH_Setup_Code1;
@@ -324,37 +303,36 @@ flash_erase_block(void* block, unsigned 
                 break;
             }
             if (--timeout == 0) {
-                res = FLASH_ERR_DRV_TIMEOUT;
+                res = CYG_FLASH_ERR_DRV_TIMEOUT;
                 break;
             }
             prev_state = state;
         }
-
         // Verify loaded data bytes
         while (len > 0) {
             if (*addr_ptr != FLASH_BlankValue) {
                 // Only update return value if erase operation was OK
-                if (FLASH_ERR_OK == res) res = FLASH_ERR_DRV_VERIFY;
+                if (CYG_FLASH_ERR_OK == res) res = CYG_FLASH_ERR_DRV_VERIFY;
                 break;
             }
             addr_ptr++;
             len -= sizeof(*addr_ptr);
         }
     }
-
-    return FLASH_ERR_OK;
+    return CYG_FLASH_ERR_OK;
 }
 
 //----------------------------------------------------------------------------
 // Program Buffer
-int
-flash_program_buf(void* addr, void* data, int len)
+static int
+sst_program(struct cyg_flash_dev *dev, cyg_flashaddr_t base, 
+            const void* data, size_t length)
 {
     volatile flash_data_t* ROM;
-    volatile flash_data_t* addr_ptr = (volatile flash_data_t*) addr;
+    volatile flash_data_t* addr_ptr = (volatile flash_data_t*) base;
     volatile flash_data_t* data_ptr = (volatile flash_data_t*) data;
-
-    int res = FLASH_ERR_OK;
+    size_t len = length;
+    int res = CYG_FLASH_ERR_OK;
 
 #if 0
     CYG_ASSERT((unsigned long)data_ptr & (sizeof(flash_data_t)-1) == 0, 
@@ -362,13 +340,12 @@ flash_program_buf(void* addr, void* data
     CYG_ASSERT((unsigned long)addr_ptr & (CYGNUM_FLASH_INTERLEAVE*sizeof(flash_data_t)-1) == 0, 
                "Addr not properly aligned (to first interleaved device)");
 #endif
-
-    while ((FLASH_ERR_OK == res) && (len > 0)) {
+    while ((CYG_FLASH_ERR_OK == res) && (len > 0)) {
 	int timeout;
         flash_data_t state, prev_state;
 
         // Base address of device(s) being programmed. 
-        ROM = (volatile flash_data_t*)((unsigned long)addr & ~(FLASH_DEVICE_SIZE-1));
+        ROM = (volatile flash_data_t*)((unsigned long)base & ~(FLASH_DEVICE_SIZE-1));
 
         // Program data [byte] - 4 step sequence
         ROM[FLASH_Setup_Addr1] = FLASH_Setup_Code1;
@@ -385,7 +362,7 @@ flash_program_buf(void* addr, void* data
                 break;
             }
             if (--timeout == 0) {
-                res = FLASH_ERR_DRV_TIMEOUT;
+                res = CYG_FLASH_ERR_DRV_TIMEOUT;
                 break;
             }
             prev_state = state;
@@ -394,18 +371,26 @@ flash_program_buf(void* addr, void* data
         // Verify loaded data bytes
         if (*addr_ptr != *data_ptr) {
             // Only update return value if program operation was OK
-            if (FLASH_ERR_OK == res) res = FLASH_ERR_DRV_VERIFY;
-                break;
+            if (CYG_FLASH_ERR_OK == res) res = CYG_FLASH_ERR_DRV_VERIFY;
+            break;
         }
         addr_ptr++;
         data_ptr++;
         len -= sizeof(*data_ptr);
     }
 
-
     // Ideally, we'd want to return not only the failure code, but also
     // the address/device that reported the error.
     return res;
 }
 
+static const CYG_FLASH_FUNS(cyg_sst_funs,
+	               sst_init,
+	               sst_query,
+	               sst_erase_block,
+	               sst_program,
+	               NULL,              // read
+	               cyg_flash_devfn_lock_nop,
+	               cyg_flash_devfn_unlock_nop);
+
 #endif // CYGONCE_DEVS_FLASH_SST_39VFXXX_INL
new file mode 100644
--- /dev/null
+++ b/packages/devs/flash/synthv2/current/ChangeLog
@@ -0,0 +1,91 @@
+2004-12-02  Bart Veer  <bartv@ecoscentric.com>
+
+	* include/synth.h, src/synth.c: explicitly include
+	<cyg/io/flash_dev.h> rather than just defining _FLASH_PRIVATE_
+
+2004-11-29  Bart Veer  <bartv@ecoscentric.com>
+
+	* src/synth.c: eliminate hwr_map_error() support, no longer needed
+	
+	* src/synth.c: use the dummy lock/unlock functions provided by the
+	generic flash package.
+
+2004-11-22  Bart Veer  <bartv@ecoscentric.com>
+
+	* include/synth.h, src/synth.c, tests/flash3.c: merge the config
+	and priv structures. Adjust device driver API as per changes to
+	the generic flash code.
+	* tests/flash2.c, tests/flash3.c: do not depend on both synthetic
+	flash drivers being loaded.
+	* include/synth.h (struct cyg_flash_synth_priv): rename
+	cyg_block_info to cyg_flash_block_info
+
+2004-11-21  Bart Veer  <bartv@ecoscentric.com>
+
+	* tests/flash1.c (cyg_user_start):
+	CYGSEM_IO_FLASH_LEGACY_DEVICE_API has been removed, use
+	CYGHWR_IO_FLASH_DEVICE_LEGACY instead
+	* cdl/flash_synth.cdl: CYGHWR_IO_FLASH_DEVICE_V2 is now implicit
+
+2004-09-14  Andrew Lunn  <andrew.lunn@ascom.ch>
+
+	* src/synth.c (synth_flash_erase_block): Remove asserts which are
+	no longer true.
+
+2004-09-09  Andrew Lunn  <andrew.lunn@ascom.ch>
+
+	* src/flash_synth.c: Allow the use of arbitary sized block.
+	* test/flash3.c: Allow the use of small blocks
+
+2004-08-21  Andrew Lunn  <andrew.lunn@ascom.ch>
+
+	* tests/flash[23].c: Removed calls to cyg_flash_get_block_info()
+	and cyg_flash_get_limits() which have been removed. 
+
+2004-08-03  Andrew Lunn  <andrew.lunn@ascom.ch>
+
+	* cdl/flash_synth.cdl: Indicate we use the V2 device API.
+
+2004-07-17  Andrew Lunn  <andrew.lunn@ascom.ch>
+
+	* First version. Implements synthetic flash using the new flash
+	API.
+ 	
+//===========================================================================
+//####ECOSGPLCOPYRIGHTBEGIN####
+// -------------------------------------------
+// This file is part of eCos, the Embedded Configurable Operating System.
+// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
+//
+// eCos is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 2 or (at your option) any later version.
+//
+// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+// for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with eCos; if not, write to the Free Software Foundation, Inc.,
+// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+//
+// As a special exception, if other files instantiate templates or use macros
+// or inline functions from this file, or you compile this file and link it
+// with other works to produce a work based on this file, this file does not
+// by itself cause the resulting work to be covered by the GNU General Public
+// License. However the source code for this file must still be made available
+// in accordance with section (3) of the GNU General Public License.
+//
+// This exception does not invalidate any other reasons why a work based on
+// this file might be covered by the GNU General Public License.
+//
+// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
+// at http://sources.redhat.com/ecos/ecos-license/
+// -------------------------------------------
+//####ECOSGPLCOPYRIGHTEND####
+//===========================================================================
+	
+	
+
+
new file mode 100644
--- /dev/null
+++ b/packages/devs/flash/synthv2/current/cdl/flash_synth.cdl
@@ -0,0 +1,145 @@
+# ====================================================================
+#
+#      flash_synth.cdl
+#
+#      FLASH memory - Synthetic flash driver for Synthetic target
+#
+# ====================================================================
+#####ECOSGPLCOPYRIGHTBEGIN####
+## -------------------------------------------
+## This file is part of eCos, the Embedded Configurable Operating System.
+## Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
+##
+## eCos is free software; you can redistribute it and/or modify it under
+## the terms of the GNU General Public License as published by the Free
+## Software Foundation; either version 2 or (at your option) any later version.
+##
+## eCos is distributed in the hope that it will be useful, but WITHOUT ANY
+## WARRANTY; without even the implied warranty of MERCHANTABILITY or
+## FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+## for more details.
+##
+## You should have received a copy of the GNU General Public License along
+## with eCos; if not, write to the Free Software Foundation, Inc.,
+## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+##
+## As a special exception, if other files instantiate templates or use macros
+## or inline functions from this file, or you compile this file and link it
+## with other works to produce a work based on this file, this file does not
+## by itself cause the resulting work to be covered by the GNU General Public
+## License. However the source code for this file must still be made available
+## in accordance with section (3) of the GNU General Public License.
+##
+## This exception does not invalidate any other reasons why a work based on
+## this file might be covered by the GNU General Public License.
+##
+## Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
+## at http://sources.redhat.com/ecos/ecos-license/
+## -------------------------------------------
+#####ECOSGPLCOPYRIGHTEND####
+# ====================================================================
+######DESCRIPTIONBEGIN####
+#
+# Author(s):      andrew.lunn@ascom.ch
+# Contributors:   jlarmour
+# Date:           2000-10-30
+#
+#####DESCRIPTIONEND####
+#
+# ====================================================================
+
+cdl_package CYGPKG_DEVS_FLASH_SYNTH_V2 {
+    display       "Synthetic FLASH memory support"
+
+    parent        CYGPKG_IO_FLASH
+    active_if	  CYGPKG_IO_FLASH
+    requires      CYGINT_ISO_ERRNO_CODES
+
+    implements    CYGHWR_IO_FLASH_DEVICE
+
+    include_dir   cyg/flash
+    description   "FLASH memory device support for Synthetic target"
+    compile       -library=libextras.a synth.c 
+	
+    cdl_option CYGMEM_FLASH_SYNTH_V2_BASE {
+      display       "Base address of flash"
+      flavor        data
+      default_value 0
+      description  "
+              Controls where in the synth target memory map the 
+              flash is mapped. WARNING: This must be somewhere 
+              the host Linux kernel is prepaired to mmap a file. It
+              must be page aligned. For hosts with recent x86 Linux kernels,
+              a value of 0x40000000 is likely appropriate. When 0
+              the driver will automatically use whatever address the kernel
+              provides it with."
+    }
+
+    cdl_option CYGNUM_FLASH_SYNTH_V2_BLOCKSIZE {
+	display        "Size of one block of synth flash"
+	flavor	       data
+	default_value  65536
+        legal_values   512 to 999999
+	description    "
+	        This controls the size of one block of flash. This is 
+		the minimum size that can be erased."
+    }		
+
+    cdl_option CYGNUM_FLASH_SYNTH_V2_NUMBLOCKS {
+	display        "Number of blocks in the synth flash"
+	flavor	       data
+	default_value  15
+	description    "
+	        This controls how many main blocks there are in the flash"
+    }
+
+    cdl_option CYGNUM_FLASH_SYNTH_V2_NUMBOOT_BLOCKS {
+        display        "Number of boot blocks in the synth flash"
+        flavor         data
+        default_value  8
+        description    "
+                This controls the number of boot blocks the synthetic
+                device has. A value of zero disables the support of boot blocks"
+    }
+
+    cdl_option CYGNUM_FLASH_SYNTH_V2_BOOT_BLOCKSIZE {
+        display        "Size of the boot blocks in the synth flash"
+        flavor         data
+        default_value  8192
+        description    "
+                This controls the size of boot blocks the synthetic
+                device has"
+    }
+        
+    cdl_option CYGNUM_FLASH_SYNTH_V2_BOOT_BLOCK_BOTTOM {
+        display        "Is the boot blocks at the bottom of the flash"
+        flavor         bool
+        default_value  1
+        description    "
+                This controls where the boot blocks are. If true the boot
+                blocks are at the bottom of the memory space, otherwise
+                they are at the top of the memory space."
+    }       
+        
+    cdl_option CYGDAT_FLASH_SYNTH_V2_FILENAME {
+	display        "Name of file emulating synth flash"
+	flavor	       data
+	default_value  { "\"synthv2.flash\"" }
+	description    "
+	        This is the name of the file which holds the contents of
+		the flash. It is mmap'ed into memory and written for flash
+		program & erase operations. It will be created if it does
+                not exist."
+    }
+
+    cdl_option CYGPKG_DEVS_FLASH_SYNTH_V2_TESTS {
+        display "Synth flash tests"
+        flavor  data
+        no_define
+        calculated { "tests/flash1.c tests/flash2.c tests/flash3.c"}
+            description   "
+                This option specifies the set of tests for the synth flash package."
+    }
+}
+
+# EOF flash_synth.cdl
new file mode 100644
--- /dev/null
+++ b/packages/devs/flash/synthv2/current/include/synth.h
@@ -0,0 +1,78 @@
+#ifndef DEV_FLASH_SYNTHV2_SYNTH_H
+#define DEV_FLASH_SYNTHV2_SYNTH_H
+//==========================================================================
+//
+//      synth.h
+//
+//      Synthetic Flash driver header
+//
+//==========================================================================
+//####ECOSGPLCOPYRIGHTBEGIN####
+// -------------------------------------------
+// This file is part of eCos, the Embedded Configurable Operating System.
+// Copyright (C) 2004 Andrew Lunn
+//
+// eCos is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 2 or (at your option) any later version.
+//
+// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+// for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with eCos; if not, write to the Free Software Foundation, Inc.,
+// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+//
+// As a special exception, if other files instantiate templates or use macros
+// or inline functions from this file, or you compile this file and link it
+// with other works to produce a work based on this file, this file does not
+// by itself cause the resulting work to be covered by the GNU General Public
+// License. However the source code for this file must still be made available
+// in accordance with section (3) of the GNU General Public License.
+//
+// This exception does not invalidate any other reasons why a work based on
+// this file might be covered by the GNU General Public License.
+//
+// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
+// at http://sources.redhat.com/ecos/ecos-license/
+// -------------------------------------------
+//####ECOSGPLCOPYRIGHTEND####
+//==========================================================================
+//#####DESCRIPTIONBEGIN####
+//
+// Author(s):    Andrew Lunn
+// Contributors: Andrew Lunn
+// Date:         2004-07-03
+// Purpose:      Header file for the synthetic flash device
+// Description:  
+//              
+//####DESCRIPTIONEND####
+//
+//==========================================================================
+
+#include <cyg/io/flash.h>
+#include <cyg/io/flash_dev.h>
+
+// Structure of data private to each flash device
+struct cyg_flash_synth_priv 
+{
+    // Configuration parameters,
+    size_t                      block_size;
+    cyg_uint32                  blocks;
+    size_t                      boot_block_size;
+    cyg_uint32                  boot_blocks;
+    cyg_bool                    boot_block_bottom;
+    char *                      filename;
+    // Run-time data
+    int                         flashfd;
+    // Space for the block layout
+    struct cyg_flash_block_info block_info[2];
+};
+
+extern const struct cyg_flash_dev_funs cyg_flash_synth_funs;
+
+#endif
+
+  
new file mode 100644
--- /dev/null
+++ b/packages/devs/flash/synthv2/current/src/synth.c
@@ -0,0 +1,280 @@
+//==========================================================================
+//
+//      synth.c
+//
+//      Flash programming
+//
+//==========================================================================
+//####ECOSGPLCOPYRIGHTBEGIN####
+// -------------------------------------------
+// This file is part of eCos, the Embedded Configurable Operating System.
+// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
+//
+// eCos is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 2 or (at your option) any later version.
+//
+// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+// for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with eCos; if not, write to the Free Software Foundation, Inc.,
+// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+//
+// As a special exception, if other files instantiate templates or use macros
+// or inline functions from this file, or you compile this file and link it
+// with other works to produce a work based on this file, this file does not
+// by itself cause the resulting work to be covered by the GNU General Public
+// License. However the source code for this file must still be made available
+// in accordance with section (3) of the GNU General Public License.
+//
+// This exception does not invalidate any other reasons why a work based on
+// this file might be covered by the GNU General Public License.
+//
+// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
+// at http://sources.redhat.com/ecos/ecos-license/
+// -------------------------------------------
+//####ECOSGPLCOPYRIGHTEND####
+//==========================================================================
+//#####DESCRIPTIONBEGIN####
+//
+// Author(s):    andrew.lunn@ascom.ch
+// Contributors: jlarmour
+// Date:         2001-10-30
+// Purpose:      
+// Description:  
+//              
+//####DESCRIPTIONEND####
+//
+//==========================================================================
+
+#include <pkgconf/devs_flash_synth_v2.h>
+
+#include <cyg/hal/hal_io.h>
+#include <cyg/infra/cyg_ass.h>
+#include <string.h>
+
+#include <cyg/io/flash.h>
+#include <cyg/io/flash_dev.h>
+#include <cyg/flash/synth.h>
+
+#ifndef MIN
+#define MIN(x,y) ((x)<(y) ? (x) : (y))
+#endif
+
+/* Helper function. The Linux system call cannot pass 6 parameters. Instead
+   a structure is filled in and passed as one parameter */
+static int 
+cyg_hal_sys_do_mmap(void *addr, unsigned long length, unsigned long prot, 
+                    unsigned long flags, unsigned long fd, unsigned long off)
+{
+
+    struct cyg_hal_sys_mmap_args args;
+  
+    args.addr = (unsigned long) addr;
+    args.len = length;
+    args.prot = prot = prot;
+    args.flags = flags;
+    args.fd = fd;
+    args.offset = off;
+
+    return (cyg_hal_sys_mmap(&args));
+}           
+
+static int
+synth_flash_init(struct cyg_flash_dev *dev)
+{
+    struct cyg_flash_synth_priv *priv = (struct cyg_flash_synth_priv*)dev->priv;
+    cyg_flashaddr_t base;
+    int flags=CYG_HAL_SYS_MAP_SHARED;
+    
+    priv->flashfd = 
+        cyg_hal_sys_open(priv->filename,
+                         CYG_HAL_SYS_O_RDWR, 
+                         CYG_HAL_SYS_S_IRWXU|CYG_HAL_SYS_S_IRWXG|
+                         CYG_HAL_SYS_S_IRWXO);
+    if (priv->flashfd == -ENOENT) {
+        long w, bytesleft;
+        char buf[128];
+        
+        priv->flashfd = cyg_hal_sys_open(
+            priv->filename, 
+            CYG_HAL_SYS_O_RDWR|CYG_HAL_SYS_O_CREAT, 
+            CYG_HAL_SYS_S_IRWXU|CYG_HAL_SYS_S_IRWXG|CYG_HAL_SYS_S_IRWXO);
+        CYG_ASSERT( priv->flashfd >= 0, 
+                    "Opening of the file for the synth flash failed!");
+        // fill with 0xff
+        memset( buf, 0xff, sizeof(buf) );
+        bytesleft = priv->block_size * priv->blocks +
+            priv->boot_block_size * priv->boot_blocks;
+
+        while (bytesleft > 0) {
+            int bytesneeded;
+            bytesneeded = bytesleft < sizeof(buf) ?  
+                bytesleft : sizeof(buf);
+            
+            w = cyg_hal_sys_write( priv->flashfd, buf,
+                                   bytesneeded );
+            CYG_ASSERT(w == bytesneeded, 
+                       "initialization of flash file failed");
+            bytesleft -= bytesneeded;
+        } // while
+    }
+    CYG_ASSERT( priv->flashfd >= 0, 
+                "Opening of the file for the synth flash failed!");
+    if ( priv->flashfd <= 0 ) {
+        return CYG_FLASH_ERR_HWR;
+    }
+
+    if (dev->start != 0) {
+        flags |= CYG_HAL_SYS_MAP_FIXED;
+    }
+    base = (cyg_flashaddr_t)cyg_hal_sys_do_mmap( 
+        (void *)dev->start,
+        priv->blocks * priv->block_size + 
+        priv->boot_block_size * priv->boot_blocks,
+        CYG_HAL_SYS_PROT_READ, 
+        flags,
+        priv->flashfd, 
+        0l);
+    CYG_ASSERT( (int) base > 0, "mmap of flash file failed!" );
+    if (base <= 0) {
+        return CYG_FLASH_ERR_HWR;
+    }
+    dev->start = base;
+    dev->end = base + (priv->blocks * priv->block_size) +
+        (priv->boot_blocks * priv->boot_block_size) - 1;
+    if (priv->boot_blocks) {
+        if (priv->boot_block_bottom) {
+            priv->block_info[0].block_size = priv->boot_block_size;
+            priv->block_info[0].blocks = priv->boot_blocks;
+            priv->block_info[1].block_size = priv->block_size;
+            priv->block_info[1].blocks = priv->blocks;
+        } else {
+            priv->block_info[0].block_size = priv->block_size;
+            priv->block_info[0].blocks = priv->blocks;
+            priv->block_info[1].block_size = priv->boot_block_size;
+            priv->block_info[1].blocks = priv->boot_blocks;
+        }
+        dev->num_block_infos = 2;
+    } else {
+        priv->block_info[0].block_size = priv->block_size;
+        priv->block_info[0].blocks = priv->blocks;
+        dev->num_block_infos = 1;
+    }
+    dev->block_info = &priv->block_info[0];
+
+    return CYG_FLASH_ERR_OK;
+}
+
+/* This helps speed up the erase. */
+static char empty[4096];
+static cyg_bool empty_inited = false;
+
+// Return the size of the block which is at the given address.
+// __inline__ so that we know it will be in RAM, not ROM.
+static __inline__ size_t 
+flash_block_size(struct cyg_flash_dev *dev, const cyg_flashaddr_t addr)
+{
+  int i;
+  size_t offset;
+  
+  
+  CYG_ASSERT((addr >= dev->start) && (addr <= dev->end), "Not inside device");
+  
+  offset = addr - dev->start;
+  for (i=0; i < dev->num_block_infos; i++) {
+    if (offset < (dev->block_info[i].blocks * dev->block_info[i].block_size))
+      return dev->block_info[i].block_size;
+    offset = offset - 
+      (dev->block_info[i].blocks * dev->block_info[i].block_size);
+  }
+  CYG_FAIL("Programming error");
+  return 0;
+}
+
+static int 
+synth_flash_erase_block(struct cyg_flash_dev *dev, 
+                        cyg_flashaddr_t block_base)
+{
+    const struct cyg_flash_synth_priv *priv = dev->priv;
+    int offset = (int)block_base;
+    size_t remaining;
+    int write_size;
+
+    offset -= dev->start;
+    
+    cyg_hal_sys_lseek(priv->flashfd, offset,
+                      CYG_HAL_SYS_SEEK_SET);
+    
+    if (!empty_inited) {
+        memset(empty, 0xff, sizeof(empty));
+        empty_inited = true;
+    }
+
+    remaining = flash_block_size(dev, block_base);
+
+    while (remaining) {
+      write_size = MIN(remaining, sizeof(empty));
+      cyg_hal_sys_write(priv->flashfd, empty, write_size);
+      remaining -= write_size;
+    }
+    return CYG_FLASH_ERR_OK;
+}
+
+static int
+synth_flash_program (struct cyg_flash_dev *dev, 
+                     cyg_flashaddr_t base, 
+                     const void* data, size_t len)
+{
+    const struct cyg_flash_synth_priv *priv = dev->priv;
+    int offset = base;
+    offset -= dev->start;
+    
+    cyg_hal_sys_lseek(priv->flashfd, offset, CYG_HAL_SYS_SEEK_SET);
+    cyg_hal_sys_write(priv->flashfd, data, len);
+  
+    return CYG_FLASH_ERR_OK;
+}
+
+#define QUERY "Linux Synthetic Flash" 
+
+static size_t
+synth_flash_query(struct cyg_flash_dev *dev, void * data, 
+                  size_t len)
+{
+    memcpy(data,QUERY,sizeof(QUERY));
+    return sizeof(QUERY);
+}
+
+const CYG_FLASH_FUNS(cyg_flash_synth_funs,
+                     synth_flash_init,
+                     synth_flash_query,
+                     synth_flash_erase_block,
+                     synth_flash_program,
+                     NULL,                 // read
+                     cyg_flash_devfn_lock_nop,
+                     cyg_flash_devfn_unlock_nop);
+
+static struct cyg_flash_synth_priv synth_flash_priv = {
+    .block_size         = CYGNUM_FLASH_SYNTH_V2_BLOCKSIZE,
+    .blocks             = CYGNUM_FLASH_SYNTH_V2_NUMBLOCKS,
+    .boot_block_size    = CYGNUM_FLASH_SYNTH_V2_BOOT_BLOCKSIZE,
+    .boot_blocks        = CYGNUM_FLASH_SYNTH_V2_NUMBOOT_BLOCKS,
+    .boot_block_bottom  = CYGNUM_FLASH_SYNTH_V2_BOOT_BLOCK_BOTTOM,
+    .filename           = CYGDAT_FLASH_SYNTH_V2_FILENAME,
+    .flashfd            = -1
+};
+
+CYG_FLASH_DRIVER(cyg_flash_synth_flashdev,
+                 &cyg_flash_synth_funs,
+                 0,                             // flags
+                 CYGMEM_FLASH_SYNTH_V2_BASE,    // Start, if 0 will be updated by init
+                 0,                             // end, filled in by init
+                 0,                             // number of block_info's, filled in by init
+                 synth_flash_priv.block_info,
+                 &synth_flash_priv);
+
+// EOF synth.c
new file mode 100644
--- /dev/null
+++ b/packages/devs/flash/synthv2/current/tests/flash1.c
@@ -0,0 +1,193 @@
+/* Hey, the copyright is usefull for something! */
+
+static char copyright[] = 
+"//=========================================================================="
+"//"
+"//      flash1.c"
+"//"
+"//      Test flash operations for the synth target synth flash driver"
+"//"
+"//=========================================================================="
+"//####ECOSGPLCOPYRIGHTBEGIN####"
+"// -------------------------------------------"
+"// This file is part of eCos, the Embedded Configurable Operating System."
+"// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc."
+"//"
+"// eCos is free software; you can redistribute it and/or modify it under"
+"// the terms of the GNU General Public License as published by the Free"
+"// Software Foundation; either version 2 or (at your option) any later version."
+"//"
+"// eCos is distributed in the hope that it will be useful, but WITHOUT ANY"
+"// WARRANTY; without even the implied warranty of MERCHANTABILITY or"
+"// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License"
+"// for more details."
+"//"
+"// You should have received a copy of the GNU General Public License along"
+"// with eCos; if not, write to the Free Software Foundation, Inc.,"
+"// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA."
+"//"
+"// As a special exception, if other files instantiate templates or use macros"
+"// or inline functions from this file, or you compile this file and link it"
+"// with other works to produce a work based on this file, this file does not"
+"// by itself cause the resulting work to be covered by the GNU General Public"
+"// License. However the source code for this file must still be made available"
+"// in accordance with section (3) of the GNU General Public License."
+"//"
+"// This exception does not invalidate any other reasons why a work based on"
+"// this file might be covered by the GNU General Public License."
+"//"
+"// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc."
+"// at http://sources.redhat.com/ecos/ecos-license/"
+"// -------------------------------------------"
+"//####ECOSGPLCOPYRIGHTEND####"
+"//=========================================================================="
+"//#####DESCRIPTIONBEGIN####"
+"//"
+"// Author(s):           andrew.lunn@ascom.ch"
+"// Contributors:        andrew.lunn"
+"// Date:                2000-10-31"
+"// Purpose:             Test a flash driver"
+"// Description:         Try out a number of flash operations and make sure"
+"//                      what is in the flash is what we expeect."
+"//                      "
+"//####DESCRIPTIONEND####"
+"//"
+"//=========================================================================="
+;
+
+#include <cyg/io/flash.h>
+#include <cyg/infra/testcase.h>
+#include <cyg/infra/diag.h>
+
+#include <string.h>
+
+#ifndef CYGINT_ISO_STRING_STRFUNCS
+# define NA_MSG "Need string functions for test"
+#endif
+#ifndef CYGSEM_IO_FLASH_LEGACY_API
+# define NA_MSG "Need legacy IO FLASH API for test"
+#endif
+
+#ifdef NA_MSG
+void cyg_user_start(void)
+{
+    CYG_TEST_INIT();
+    CYG_TEST_NA( NA_MSG );
+}
+#else
+
+//==========================================================================
+// main
+
+void cyg_user_start(void)
+{
+    int ret;
+    char data[1024];
+    void *flash_start, *flash_end;
+    int block_size, blocks;
+    char *prog_start;
+    unsigned char * ptr;
+
+    CYG_TEST_INIT();
+  
+    ret=flash_init((_printf *)diag_printf);
+  
+    CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_init");
+
+#ifdef CYGHWR_IO_FLASH_DEVICE_LEGACY
+    //Strictly speaking, this is a device driver call, not a user API call.
+    flash_dev_query(data);
+    CYG_TEST_PASS_FAIL(!strncmp(data,"Linux Synthetic Flash",sizeof(data)),
+                       "flash_query"); 
+#endif
+    ret = flash_get_limits(NULL,&flash_start,&flash_end);
+    CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_get_limits");
+
+    ret = flash_get_block_info(&block_size, &blocks);
+    CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_get_block_info");
+
+    /* Erase the whole flash. Not recommended on real hardware since this
+     will probably erase the bootloader etc!!! */
+    ret=flash_erase(flash_start,block_size * blocks,NULL);
+    CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_erase1");
+
+    /* check that its actually been erased, and test the mmap area */
+    for (ptr=flash_start,ret=0; ptr < (unsigned char *)flash_end; ptr++) {
+        if (*ptr != 0xff) {
+            ret++;
+        }
+    }
+  
+    CYG_TEST_PASS_FAIL((ret == 0),"flash empty check");
+
+    ret = flash_program(flash_start,&copyright,sizeof(copyright),NULL);
+    CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_program1");
+  
+    /* Check the contents made it into the flash */
+    CYG_TEST_PASS_FAIL(!strncmp(flash_start,copyright,sizeof(copyright)),
+                       "flash program contents");
+
+    /* .. and check nothing else changed */
+    for (ptr=(unsigned char *)flash_start+sizeof(copyright),ret=0; 
+         ptr < (unsigned char *)flash_end; ptr++) {
+        if (*ptr != 0xff) {
+            ret++;
+        }
+    }
+  
+    CYG_TEST_PASS_FAIL((ret == 0),"flash program overrun check");
+
+    /* Program over a block boundary */
+    prog_start = (unsigned char *)flash_start + block_size - sizeof(copyright)/2;
+    ret = flash_program(prog_start,&copyright,sizeof(copyright),NULL);
+    CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_program2");
+  
+    /* Check the first version is still OK */
+    CYG_TEST_PASS_FAIL(!strncmp(flash_start,copyright,sizeof(copyright)),
+                       "Original contents");
+  
+    CYG_TEST_PASS_FAIL(!strncmp(prog_start,copyright,sizeof(copyright)),
+                       "New program contents");
+
+    /* Check the bit in between is still erased */
+    for (ptr=(unsigned char *)flash_start+sizeof(copyright),ret=0; 
+         ptr < (unsigned char *)prog_start; ptr++) {
+        if (*ptr != 0xff) {
+            ret++;
+        }
+    }
+    CYG_TEST_PASS_FAIL((ret == 0),"flash erase check1");
+  
+    /* Erase the second block and make sure the first is not erased */
+    ret=flash_erase((void *)((unsigned)flash_start+block_size),
+                    block_size,NULL);
+    CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_erase2");
+
+    /* Check the erase worked */
+    for (ptr=(unsigned char *)flash_start+block_size,ret=0; 
+         ptr < (unsigned char *)flash_start+block_size*2; ptr++) {
+        if (*ptr != 0xff) {
+            ret++;
+        }
+    }
+
+    CYG_TEST_PASS_FAIL((ret == 0), "flash erase check2");
+  
+    /* Lastly check the first half of the copyright message is still there */
+    CYG_TEST_PASS_FAIL(!strncmp(prog_start,copyright,sizeof(copyright)/2),
+                       "Block 1 OK");
+
+#if 0
+    /* This test it fatal! Its not run by default!
+     Check the flash is read only, by trying to write to it. We expect
+     to get an exception */
+
+    *(char *)flash_start = 'a';
+#endif
+
+    CYG_TEST_PASS_FINISH("flash1");
+}
+
+#endif /* ifndef NA_MSG */
+
+/* EOF flash1.c */
new file mode 100644
--- /dev/null
+++ b/packages/devs/flash/synthv2/current/tests/flash2.c
@@ -0,0 +1,215 @@
+/* Hay, the copyright is usefull for something! */
+
+static char copyright[] = 
+"//=========================================================================="
+"//"
+"//      flash1.c"
+"//"
+"//      Test flash operations for the synth target synth flash driver"
+"//"
+"//=========================================================================="
+"//####ECOSGPLCOPYRIGHTBEGIN####"
+"// -------------------------------------------"
+"// This file is part of eCos, the Embedded Configurable Operating System."
+"// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc."
+"//"
+"// eCos is free software; you can redistribute it and/or modify it under"
+"// the terms of the GNU General Public License as published by the Free"
+"// Software Foundation; either version 2 or (at your option) any later version."
+"//"
+"// eCos is distributed in the hope that it will be useful, but WITHOUT ANY"
+"// WARRANTY; without even the implied warranty of MERCHANTABILITY or"
+"// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License"
+"// for more details."
+"//"
+"// You should have received a copy of the GNU General Public License along"
+"// with eCos; if not, write to the Free Software Foundation, Inc.,"
+"// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA."
+"//"
+"// As a special exception, if other files instantiate templates or use macros"
+"// or inline functions from this file, or you compile this file and link it"
+"// with other works to produce a work based on this file, this file does not"
+"// by itself cause the resulting work to be covered by the GNU General Public"
+"// License. However the source code for this file must still be made available"
+"// in accordance with section (3) of the GNU General Public License."
+"//"
+"// This exception does not invalidate any other reasons why a work based on"
+"// this file might be covered by the GNU General Public License."
+"//"
+"// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc."
+"// at http://sources.redhat.com/ecos/ecos-license/"
+"// -------------------------------------------"
+"//####ECOSGPLCOPYRIGHTEND####"
+"//=========================================================================="
+"//#####DESCRIPTIONBEGIN####"
+"//"
+"// Author(s):           andrew.lunn@ascom.ch"
+"// Contributors:        andrew.lunn"
+"// Date:                2000-10-31"
+"// Purpose:             Test a flash driver"
+"// Description:         Try out a number of flash operations and make sure"
+"//                      what is in the flash is what we expeect."
+"//                      "
+"//####DESCRIPTIONEND####"
+"//"
+"//==========================================================================&"
+;
+
+#include <pkgconf/system.h>
+#ifdef CYGPKG_DEVS_FLASH_SYNTH_V2
+#include <pkgconf/devs_flash_synth_v2.h>
+#endif
+#ifdef CYGPKG_DEVS_FLASH_SYNTH
+#include <pkgconf/devs_flash_synth.h>
+#endif
+#include <cyg/io/flash.h>
+#include <cyg/infra/testcase.h>
+#include <cyg/infra/diag.h>
+
+#include <string.h>
+
+#ifndef CYGINT_ISO_STRING_STRFUNCS
+# define NA_MSG "Need string functions for test"
+#endif
+
+#ifdef NA_MSG
+void cyg_user_start(void)
+{
+    CYG_TEST_INIT();
+    CYG_TEST_NA( NA_MSG );
+}
+#else
+
+//==========================================================================
+// main
+
+void cyg_user_start(void)
+{
+    int ret;
+    cyg_flashaddr_t flash_start=0, flash_end=0;
+    cyg_flash_info_t info;
+    cyg_uint32 i=0;
+    cyg_uint32 j;
+    int block_size=0, blocks=0;
+    cyg_flashaddr_t prog_start;
+    unsigned char * ptr;
+
+    CYG_TEST_INIT();
+  
+    ret=cyg_flash_init((cyg_flash_printf *)diag_printf);
+    
+    CYG_TEST_PASS_FAIL((ret == CYG_FLASH_ERR_OK),"flash_init");
+
+    do {
+      ret = cyg_flash_get_info(i, &info);
+      if (ret == CYG_FLASH_ERR_OK) {
+        diag_printf("INFO: Nth=%d, start=%p, end=%p\n",
+                    i, info.start, info.end);
+        if (i == 0) {
+          flash_start = info.start;
+          flash_end = info.end;
+          block_size = info.block_info[0].block_size;
+          blocks = info.block_info[0].blocks;
+        }
+        for (j=0;j < info.num_block_infos; j++) {
+          diag_printf("INFO:\t block_size %d, blocks %d\n",
+                      info.block_info[j].block_size,
+                      info.block_info[j].blocks);
+        }
+      }
+      i++;
+    } while (ret != CYG_FLASH_ERR_INVALID);
+    
+    /* Erase the whole flash. Not recommended on real hardware since this
+     will probably erase the bootloader etc!!! */
+    ret=cyg_flash_erase(flash_start,block_size * blocks,NULL);
+    CYG_TEST_PASS_FAIL((ret == CYG_FLASH_ERR_OK),"flash_erase1");
+
+    /* check that its actually been erased, and test the mmap area */
+    for (ptr=(unsigned char *)flash_start,ret=0; 
+         ptr <= (unsigned char *)flash_end; ptr++) {
+        if (*ptr != 0xff) {
+            ret++;
+        }
+    }
+  
+    CYG_TEST_PASS_FAIL((ret == 0),"flash empty check");
+
+    ret = cyg_flash_program(flash_start,&copyright,sizeof(copyright),NULL);
+    CYG_TEST_PASS_FAIL((ret == CYG_FLASH_ERR_OK),"flash_program1");
+  
+    /* Check the contents made it into the flash */
+    CYG_TEST_PASS_FAIL(!strncmp((void *)flash_start,
+                                copyright,sizeof(copyright)),
+                       "flash program contents");
+
+    /* .. and check nothing else changed */
+    for (ptr=(unsigned char *)flash_start+sizeof(copyright),ret=0; 
+         ptr < (unsigned char *)flash_end; ptr++) {
+        if (*ptr != 0xff) {
+            ret++;
+        }
+    }
+  
+    CYG_TEST_PASS_FAIL((ret == 0),"flash program overrun check");
+
+    /* Program over a block boundary */
+    prog_start = flash_start + block_size - sizeof(copyright)/2;
+    ret = cyg_flash_program(prog_start,&copyright,sizeof(copyright),NULL);
+    CYG_TEST_PASS_FAIL((ret == CYG_FLASH_ERR_OK),"flash_program2");
+  
+    /* Check the first version is still OK */
+    CYG_TEST_PASS_FAIL(!strncmp((void *)flash_start,
+                                copyright,
+                                sizeof(copyright)),
+                       "Original contents");
+  
+    CYG_TEST_PASS_FAIL(!strncmp((void *)prog_start,
+                                copyright,
+                                sizeof(copyright)),
+                       "New program contents");
+
+    /* Check the bit in between is still erased */
+    for (ptr=(unsigned char *)flash_start+sizeof(copyright),ret=0; 
+         ptr < (unsigned char *)prog_start; ptr++) {
+        if (*ptr != 0xff) {
+            ret++;
+        }
+    }
+    CYG_TEST_PASS_FAIL((ret == 0),"flash erase check1");
+  
+    /* Erase the second block and make sure the first is not erased */
+    ret=cyg_flash_erase(flash_start+block_size,block_size,NULL);
+    CYG_TEST_PASS_FAIL((ret == CYG_FLASH_ERR_OK),"flash_erase2");
+
+    /* Check the erase worked */
+    for (ptr=(unsigned char *)flash_start+block_size,ret=0; 
+         ptr < (unsigned char *)flash_start+block_size*2; 
+         ptr++) {
+        if (*ptr != 0xff) {
+            ret++;
+        }
+    }
+
+    CYG_TEST_PASS_FAIL((ret == 0), "flash erase check2");
+  
+    /* Lastly check the first half of the copyright message is still there */
+    CYG_TEST_PASS_FAIL(!strncmp((void *)prog_start,
+                                copyright,
+                                sizeof(copyright)/2),
+                       "Block 1 OK");
+
+#if 0
+    /* This test is be fatal! Its not run by default!
+     Check the flash is read only, by trying to write to it. We expect
+     to get an exception */
+
+    *(char *)flash_start = 'a';
+#endif
+
+    CYG_TEST_PASS_FINISH("flash1");
+}
+
+#endif /* ifndef NA_MSG */
+
+/* EOF flash1.c */
new file mode 100644
--- /dev/null
+++ b/packages/devs/flash/synthv2/current/tests/flash3.c
@@ -0,0 +1,248 @@
+/* Hay, the copyright is usefull for something! */
+
+static char copyright[] = 
+"//=========================================================================="
+"//"
+"//      flash1.c"
+"//"
+"//      Test flash operations for the synth target synth flash driver"
+"//"
+"//=========================================================================="
+"//####ECOSGPLCOPYRIGHTBEGIN####"
+"// -------------------------------------------"
+"// This file is part of eCos, the Embedded Configurable Operating System."
+"// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc."
+"//"
+"// eCos is free software; you can redistribute it and/or modify it under"
+"// the terms of the GNU General Public License as published by the Free"
+"// Software Foundation; either version 2 or (at your option) any later version."
+"//"
+"// eCos is distributed in the hope that it will be useful, but WITHOUT ANY"
+"// WARRANTY; without even the implied warranty of MERCHANTABILITY or"
+"// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License"
+"// for more details."
+"//"
+"// You should have received a copy of the GNU General Public License along"
+"// with eCos; if not, write to the Free Software Foundation, Inc.,"
+"// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA."
+"//"
+"// As a special exception, if other files instantiate templates or use macros"
+"// or inline functions from this file, or you compile this file and link it"
+"// with other works to produce a work based on this file, this file does not"
+"// by itself cause the resulting work to be covered by the GNU General Public"
+"// License. However the source code for this file must still be made available"
+"// in accordance with section (3) of the GNU General Public License."
+"//"
+"// This exception does not invalidate any other reasons why a work based on"
+"// this file might be covered by the GNU General Public License."
+"//"
+"// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc."
+"// at http://sources.redhat.com/ecos/ecos-license/"
+"// -------------------------------------------"
+"//####ECOSGPLCOPYRIGHTEND####"
+"//=========================================================================="
+"//#####DESCRIPTIONBEGIN####"
+"//"
+"// Author(s):           andrew.lunn@ascom.ch"
+"// Contributors:        andrew.lunn"
+"// Date:                2000-10-31"
+"// Purpose:             Test a flash driver"
+"// Description:         Try out a number of flash operations and make sure"
+"//                      what is in the flash is what we expeect."
+"//                      "
+"//####DESCRIPTIONEND####"
+"//"
+"//==========================================================================&"
+;
+
+#include <pkgconf/system.h>
+#ifdef CYGPKG_DEVS_FLASH_SYNTH_V2
+#include <pkgconf/devs_flash_synth_v2.h>
+#endif
+#ifdef CYGPKG_DEVS_FLASH_SYNTH
+#include <pkgconf/devs_flash_synth.h>
+#endif
+#include <cyg/io/flash.h>
+#include <cyg/infra/testcase.h>
+#include <cyg/infra/diag.h>
+#include <cyg/flash/synth.h>
+
+#include <string.h>
+
+#ifndef CYGINT_ISO_STRING_STRFUNCS
+# define NA_MSG "Need string functions for test"
+#endif
+
+#ifdef NA_MSG
+void cyg_user_start(void)
+{
+    CYG_TEST_INIT();
+    CYG_TEST_NA( NA_MSG );
+}
+#else
+
+static struct cyg_flash_synth_priv synth_flash_priv3 = {
+    .block_size         = CYGNUM_FLASH_SYNTH_V2_BLOCKSIZE,
+    .blocks             = CYGNUM_FLASH_SYNTH_V2_NUMBLOCKS,
+    .boot_block_size    = CYGNUM_FLASH_SYNTH_V2_BOOT_BLOCKSIZE,
+    .boot_blocks        = CYGNUM_FLASH_SYNTH_V2_NUMBOOT_BLOCKS,
+    .boot_block_bottom  = CYGNUM_FLASH_SYNTH_V2_BOOT_BLOCK_BOTTOM,
+    .filename           = "synth.flash3",
+    .flashfd            = -1
+};
+
+CYG_FLASH_DRIVER(cyg_flash_synth_flashdev_flash3,
+                 &cyg_flash_synth_funs,
+                 0,             // flags
+                 0x40020000,    // start
+                 0,             // end, filled in by init
+                 0,             // number of block_info's, filled in by init
+                 synth_flash_priv3.block_info,
+                 &synth_flash_priv3);
+
+//==========================================================================
+// main
+
+void cyg_user_start(void)
+{
+    int ret;
+    cyg_flashaddr_t flash_start=0, flash_end=0;
+    cyg_flash_info_t info;
+    cyg_uint32 i=0;
+    cyg_uint32 j;
+    int block_size=0, blocks=0;
+    cyg_flashaddr_t prog_start;
+    unsigned char * ptr;
+    size_t copyright_len;
+    
+    CYG_TEST_INIT();
+
+    // Reference the flash dev so the linker does not throw it away
+    CYG_REFERENCE_OBJECT(cyg_flash_synth_flashdev_flash3);  
+
+    ret=cyg_flash_init((cyg_flash_printf *)diag_printf);
+    
+    CYG_TEST_PASS_FAIL((ret == CYG_FLASH_ERR_OK),"flash_init");
+
+    do {
+      ret = cyg_flash_get_info(i, &info);
+      if (ret == CYG_FLASH_ERR_OK) {
+        diag_printf("INFO: Nth=%d, start=%p, end=%p\n",
+                    i, info.start, info.end);
+        if (i == 0) {
+          flash_start = info.start;
+          flash_end = info.end;
+          block_size = info.block_info[0].block_size;
+          blocks = info.block_info[0].blocks;
+        }
+        
+        for (j=0;j < info.num_block_infos; j++) {
+          diag_printf("INFO:\t block_size %d, blocks %d\n",
+                      info.block_info[j].block_size,
+                      info.block_info[j].blocks);
+        }
+      }
+      i++;
+    } while (ret != CYG_FLASH_ERR_INVALID);
+    
+    /* Erase the whole flash. Not recommended on real hardware since this
+     will probably erase the bootloader etc!!! */
+    ret=cyg_flash_erase(flash_start,block_size * blocks,NULL);
+    CYG_TEST_PASS_FAIL((ret == CYG_FLASH_ERR_OK),"flash_erase1");
+
+    /* check that its actually been erased, and test the mmap area */
+    for (ptr=(unsigned char *)flash_start,ret=0; 
+         ptr <= (unsigned char *)flash_end; ptr++) {
+        if (*ptr != 0xff) {
+            ret++;
+        }
+    }
+  
+    CYG_TEST_PASS_FAIL((ret == 0),"flash empty check");
+
+    // With small blocks we have to use less of the copyright messages
+    // Since we make assumptions about fitting the message into a
+    // block.
+    if (block_size < sizeof(copyright)*2/3) {
+      copyright_len = block_size / 3;
+    } else {
+      copyright_len = sizeof(copyright);
+    }
+    
+    ret = cyg_flash_program(flash_start,&copyright,copyright_len,NULL);
+    CYG_TEST_PASS_FAIL((ret == CYG_FLASH_ERR_OK),"flash_program1");
+  
+    /* Check the contents made it into the flash */
+    CYG_TEST_PASS_FAIL(!strncmp((void *)flash_start,
+                                copyright,copyright_len),
+                       "flash program contents");
+
+    /* .. and check nothing else changed */
+    for (ptr=(unsigned char *)flash_start+copyright_len,ret=0; 
+         ptr < (unsigned char *)flash_end; ptr++) {
+        if (*ptr != 0xff) {
+            ret++;
+        }
+    }
+  
+    CYG_TEST_PASS_FAIL((ret == 0),"flash program overrun check");
+
+    prog_start = flash_start + block_size - copyright_len/2;
+    ret = cyg_flash_program(prog_start,&copyright,copyright_len,NULL);
+    CYG_TEST_PASS_FAIL((ret == CYG_FLASH_ERR_OK),"flash_program2");
+  
+    /* Check the first version is still OK */
+    CYG_TEST_PASS_FAIL(!strncmp((void *)flash_start,
+                                copyright,
+                                copyright_len),
+                       "Original contents");
+  
+    CYG_TEST_PASS_FAIL(!strncmp((void *)prog_start,
+                                copyright,
+                                copyright_len),
+                       "New program contents");
+
+    /* Check the bit in between is still erased */
+    for (ptr=(unsigned char *)flash_start+copyright_len,ret=0; 
+         ptr < (unsigned char *)prog_start; ptr++) {
+        if (*ptr != 0xff) {
+            ret++;
+        }
+    }
+    CYG_TEST_PASS_FAIL((ret == 0),"flash erase check1");
+  
+    /* Erase the second block and make sure the first is not erased */
+    ret=cyg_flash_erase(flash_start+block_size,block_size,NULL);
+    CYG_TEST_PASS_FAIL((ret == CYG_FLASH_ERR_OK),"flash_erase2");
+
+    /* Check the erase worked */
+    for (ptr=(unsigned char *)flash_start+block_size,ret=0; 
+         ptr < (unsigned char *)flash_start+block_size*2; 
+         ptr++) {
+        if (*ptr != 0xff) {
+            ret++;
+        }
+    }
+
+    CYG_TEST_PASS_FAIL((ret == 0), "flash erase check2");
+  
+    /* Lastly check the first half of the copyright message is still there */
+    CYG_TEST_PASS_FAIL(!strncmp((void *)prog_start,
+                                copyright,
+                                copyright_len/2),
+                       "Block 1 OK");
+
+#if 0
+    /* This test is be fatal! Its not run by default!
+     Check the flash is read only, by trying to write to it. We expect
+     to get an exception */
+
+    *(char *)flash_start = 'a';
+#endif
+
+    CYG_TEST_PASS_FINISH("flash3");
+}
+
+#endif /* ifndef NA_MSG */
+
+/* EOF flash1.c */