summaryrefslogtreecommitdiff
path: root/ecos/packages/devs/flash/intel/strata/current/src
diff options
context:
space:
mode:
Diffstat (limited to 'ecos/packages/devs/flash/intel/strata/current/src')
-rw-r--r--ecos/packages/devs/flash/intel/strata/current/src/flash_erase_block.c115
-rw-r--r--ecos/packages/devs/flash/intel/strata/current/src/flash_lock_block.c83
-rw-r--r--ecos/packages/devs/flash/intel/strata/current/src/flash_program_buf.c162
-rw-r--r--ecos/packages/devs/flash/intel/strata/current/src/flash_query.c107
-rw-r--r--ecos/packages/devs/flash/intel/strata/current/src/flash_unlock_block.c141
-rw-r--r--ecos/packages/devs/flash/intel/strata/current/src/strata.c185
-rw-r--r--ecos/packages/devs/flash/intel/strata/current/src/strata.h177
7 files changed, 970 insertions, 0 deletions
diff --git a/ecos/packages/devs/flash/intel/strata/current/src/flash_erase_block.c b/ecos/packages/devs/flash/intel/strata/current/src/flash_erase_block.c
new file mode 100644
index 0000000..c5414fc
--- /dev/null
+++ b/ecos/packages/devs/flash/intel/strata/current/src/flash_erase_block.c
@@ -0,0 +1,115 @@
+//==========================================================================
+//
+// flash_erase_block.c
+//
+// Flash programming
+//
+//==========================================================================
+// ####ECOSGPLCOPYRIGHTBEGIN####
+// -------------------------------------------
+// This file is part of eCos, the Embedded Configurable Operating System.
+// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, 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.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 v2.
+//
+// This exception does not invalidate any other reasons why a work based
+// on this file might be covered by the GNU General Public License.
+// -------------------------------------------
+// ####ECOSGPLCOPYRIGHTEND####
+//==========================================================================
+//#####DESCRIPTIONBEGIN####
+//
+// Author(s): gthomas, hmt
+// Contributors: gthomas
+// Date: 2001-02-14
+// Purpose:
+// Description:
+//
+//####DESCRIPTIONEND####
+//
+//==========================================================================
+
+#include "strata.h"
+
+#include <pkgconf/hal.h>
+#include <cyg/hal/hal_arch.h>
+
+int flash_erase_block(volatile flash_t *block, unsigned int block_size)
+ __attribute__ ((section (".2ram.flash_erase_block")));
+int flash_erase_block(volatile flash_t *block, unsigned int block_size)
+{
+ volatile flash_t *ROM;
+ flash_t stat = 0;
+ int timeout = 50000;
+ int len, block_len, erase_block_size;
+ volatile flash_t *eb;
+
+ // Get base address and map addresses to virtual addresses
+ ROM = FLASH_P2V(CYGNUM_FLASH_BASE_MASK & (unsigned int)block);
+ eb = block = FLASH_P2V(block);
+ block_len = block_size;
+
+#ifdef CYGOPT_FLASH_IS_BOOTBLOCK
+#define BLOCKSIZE (0x10000*CYGNUM_FLASH_DEVICES)
+#define ERASE_BLOCKSIZE (0x2000*CYGNUM_FLASH_DEVICES)
+ if ((eb - ROM) < BLOCKSIZE/(sizeof eb[0])) {
+ erase_block_size = ERASE_BLOCKSIZE;
+ } else {
+ erase_block_size = block_size;
+ }
+#else
+ erase_block_size = block_size;
+#endif
+
+ // Clear any error conditions
+ ROM[0] = FLASH_Clear_Status;
+
+ // Erase block
+ while (block_len > 0) {
+ eb[0] = FLASH_Block_Erase;
+ eb[0] = FLASH_Confirm;
+
+ timeout = 5000000;
+ while(((stat = eb[0]) & FLASH_Status_Ready) != FLASH_Status_Ready) {
+ if (--timeout == 0) break;
+ }
+
+ block_len -= erase_block_size;
+ eb = FLASH_P2V((unsigned int)eb + erase_block_size);
+ }
+
+ // Restore ROM to "normal" mode
+ ROM[0] = FLASH_Reset;
+
+ // If an error was reported, see if the block erased anyway
+ if (stat & FLASH_ErrorMask ) {
+ len = block_size;
+ while (len > 0) {
+ if (*block++ != FLASH_BlankValue ) break;
+ len -= sizeof(*block);
+ }
+ if (len == 0) stat = 0;
+ }
+
+ return stat;
+}
diff --git a/ecos/packages/devs/flash/intel/strata/current/src/flash_lock_block.c b/ecos/packages/devs/flash/intel/strata/current/src/flash_lock_block.c
new file mode 100644
index 0000000..d39ebba
--- /dev/null
+++ b/ecos/packages/devs/flash/intel/strata/current/src/flash_lock_block.c
@@ -0,0 +1,83 @@
+//==========================================================================
+//
+// flash_lock_block.c
+//
+// Flash programming
+//
+//==========================================================================
+// ####ECOSGPLCOPYRIGHTBEGIN####
+// -------------------------------------------
+// This file is part of eCos, the Embedded Configurable Operating System.
+// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, 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.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 v2.
+//
+// This exception does not invalidate any other reasons why a work based
+// on this file might be covered by the GNU General Public License.
+// -------------------------------------------
+// ####ECOSGPLCOPYRIGHTEND####
+//==========================================================================
+//#####DESCRIPTIONBEGIN####
+//
+// Author(s): gthomas, hmt
+// Contributors: gthomas
+// Date: 2001-02-14
+// Purpose:
+// Description:
+//
+//####DESCRIPTIONEND####
+//
+//==========================================================================
+
+#include "strata.h"
+
+
+int
+flash_lock_block(volatile flash_t *block)
+ __attribute__ ((section (".2ram.flash_lock_block")));
+int
+flash_lock_block(volatile flash_t *block)
+{
+ volatile flash_t *ROM;
+ flash_t stat;
+ int timeout = 5000000;
+
+ // Get base address and map addresses to virtual addresses
+ ROM = FLASH_P2V(CYGNUM_FLASH_BASE_MASK & (unsigned int)block);
+ block = FLASH_P2V(block);
+
+ // Clear any error conditions
+ ROM[0] = FLASH_Clear_Status;
+
+ // Set lock bit
+ block[0] = FLASH_Set_Lock;
+ block[0] = FLASH_Set_Lock_Confirm; // Confirmation
+ while(((stat = ROM[0]) & FLASH_Status_Ready) != FLASH_Status_Ready) {
+ if (--timeout == 0) break;
+ }
+
+ // Restore ROM to "normal" mode
+ ROM[0] = FLASH_Reset;
+
+ return stat;
+}
diff --git a/ecos/packages/devs/flash/intel/strata/current/src/flash_program_buf.c b/ecos/packages/devs/flash/intel/strata/current/src/flash_program_buf.c
new file mode 100644
index 0000000..b0645b2
--- /dev/null
+++ b/ecos/packages/devs/flash/intel/strata/current/src/flash_program_buf.c
@@ -0,0 +1,162 @@
+//==========================================================================
+//
+// flash_program_buf.c
+//
+// Flash programming
+//
+//==========================================================================
+// ####ECOSGPLCOPYRIGHTBEGIN####
+// -------------------------------------------
+// This file is part of eCos, the Embedded Configurable Operating System.
+// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004 Free Software Foundation, 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.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 v2.
+//
+// This exception does not invalidate any other reasons why a work based
+// on this file might be covered by the GNU General Public License.
+// -------------------------------------------
+// ####ECOSGPLCOPYRIGHTEND####
+//==========================================================================
+//#####DESCRIPTIONBEGIN####
+//
+// Author(s): gthomas, hmt
+// Contributors: gthomas
+// Date: 2001-02-14
+// Purpose:
+// Description:
+//
+//####DESCRIPTIONEND####
+//
+//==========================================================================
+
+#include "strata.h"
+
+#include <pkgconf/hal.h>
+#include <cyg/hal/hal_arch.h>
+
+// Platforms may define this for special handling when accessing the write buffer.
+#ifndef CYGHWR_FLASH_WRITE_BUF
+#define CYGHWR_FLASH_WRITE_BUF(a,b) (*(a) = *(b))
+#endif
+
+int
+flash_program_buf(volatile flash_t *addr, flash_t *data, int len,
+ unsigned long block_mask, int buffer_size)
+ __attribute__ ((section (".2ram.flash_program_buf")));
+int
+flash_program_buf(volatile flash_t *addr, flash_t *data, int len,
+ unsigned long block_mask, int buffer_size)
+{
+ volatile flash_t *ROM;
+ volatile flash_t *BA;
+ flash_t stat = 0;
+ int timeout = 50000;
+#ifdef FLASH_Write_Buffer
+ int i, wc;
+#endif
+
+ // Get base address and map addresses to virtual addresses
+ ROM = FLASH_P2V( CYGNUM_FLASH_BASE_MASK & (unsigned int)addr );
+ BA = addr = FLASH_P2V(addr);
+
+ // Clear any error conditions
+ ROM[0] = FLASH_Clear_Status;
+
+#ifdef FLASH_Write_Buffer
+ // Write any big chunks first
+ while (len >= buffer_size) {
+ wc = buffer_size;
+ if (wc > len) wc = len;
+ len -= wc;
+ // convert 'wc' in bytes to 'wc' in 'flash_t'
+ wc = wc / sizeof(flash_t); // Word count
+ *BA = FLASH_Write_Buffer;
+ timeout = 5000000;
+ while(((stat = ROM[0]) & FLASH_Status_Ready) != FLASH_Status_Ready) {
+ if (--timeout == 0) {
+ goto bad;
+ }
+ *BA = FLASH_Write_Buffer;
+ }
+ *BA = FLASHWORD(wc-1); // Count is 0..N-1
+ for (i = 0; i < wc; i++) {
+#ifdef CYGHWR_FLASH_WRITE_ELEM
+ CYGHWR_FLASH_WRITE_ELEM(addr+i, data+i);
+#else
+ CYGHWR_FLASH_WRITE_BUF(addr+i, data+i);
+#endif
+ }
+ *BA = FLASH_Confirm;
+
+ ROM[0] = FLASH_Read_Status;
+ timeout = 5000000;
+ while(((stat = ROM[0]) & FLASH_Status_Ready) != FLASH_Status_Ready) {
+ if (--timeout == 0) {
+ goto bad;
+ }
+ }
+ // Jump out if there was an error
+ if (stat & FLASH_ErrorMask) {
+ goto bad;
+ }
+ // And verify the data - also increments the pointers.
+ *BA = FLASH_Reset;
+ for (i = 0; i < wc; i++) {
+ if ( *addr++ != *data++ ) {
+ stat = FLASH_ErrorNotVerified;
+ goto bad;
+ }
+ }
+ }
+#endif
+
+ while (len > 0) {
+ BA[0] = FLASH_Program;
+#ifdef CYGHWR_FLASH_WRITE_ELEM
+ CYGHWR_FLASH_WRITE_ELEM(addr, data);
+#else
+ *addr = *data;
+#endif
+ timeout = 5000000;
+ while(((stat = BA[0]) & FLASH_Status_Ready) != FLASH_Status_Ready) {
+ if (--timeout == 0) {
+ goto bad;
+ }
+ }
+ if (stat & FLASH_ErrorMask) {
+ break;
+ }
+ BA[0] = FLASH_Reset;
+ if (*addr++ != *data++) {
+ stat = FLASH_ErrorNotVerified;
+ break;
+ }
+ len -= sizeof( flash_t );
+ }
+
+ // Restore ROM to "normal" mode
+ bad:
+ BA[0] = FLASH_Reset;
+
+ return stat;
+}
diff --git a/ecos/packages/devs/flash/intel/strata/current/src/flash_query.c b/ecos/packages/devs/flash/intel/strata/current/src/flash_query.c
new file mode 100644
index 0000000..8c3aef5
--- /dev/null
+++ b/ecos/packages/devs/flash/intel/strata/current/src/flash_query.c
@@ -0,0 +1,107 @@
+//==========================================================================
+//
+// flash_query.c
+//
+// Flash programming - query device
+//
+//==========================================================================
+// ####ECOSGPLCOPYRIGHTBEGIN####
+// -------------------------------------------
+// This file is part of eCos, the Embedded Configurable Operating System.
+// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004 Free Software Foundation, 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.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 v2.
+//
+// This exception does not invalidate any other reasons why a work based
+// on this file might be covered by the GNU General Public License.
+// -------------------------------------------
+// ####ECOSGPLCOPYRIGHTEND####
+//==========================================================================
+//#####DESCRIPTIONBEGIN####
+//
+// Author(s): gthomas, hmt
+// Contributors: gthomas
+// Date: 2001-02-14
+// Purpose:
+// Description:
+//
+//####DESCRIPTIONEND####
+//
+//==========================================================================
+
+#include "strata.h"
+
+#include <pkgconf/hal.h>
+#include <cyg/hal/hal_arch.h>
+#include CYGHWR_MEMORY_LAYOUT_H
+
+// Platforms may define this for special handling when accessing the query data.
+#ifndef CYGHWR_FLASH_READ_QUERY
+#define CYGHWR_FLASH_READ_QUERY(a) (*(a))
+#endif
+
+#define CNT 20*1000*10 // Approx 20ms
+
+int
+flash_query(unsigned char *data) __attribute__ ((section (".2ram.flash_query")));
+int
+flash_query(unsigned char *data)
+{
+ volatile flash_t *ROM, *p, dummy;
+ int i, cnt;
+
+ // Get base address and map addresses to virtual addresses
+ ROM = FLASH_P2V( CYGNUM_FLASH_BASE );
+#ifdef CYGOPT_FLASH_IS_BOOTBLOCK
+ // BootBlock flash does not support full Read_Query - we have do a
+ // table oriented thing above, after getting just two bytes of results:
+ ROM[0] = FLASH_Read_ID;
+ i = 2;
+#else
+ // StrataFlash supports the full Read_Query op:
+ ROM[0] = FLASH_Read_Query;
+ i = sizeof(struct FLASH_query);
+#endif // Not CYGOPT_FLASH_IS_BOOTBLOCK
+
+ for (cnt = CNT; cnt > 0; cnt--) ;
+ p = ROM;
+ while ( i--) {
+ // It is very deliberate that data is chars NOT flash_t:
+ // The info comes out in bytes regardless of device.
+ *data++ = (unsigned char) CYGHWR_FLASH_READ_QUERY(p++);
+#ifndef CYGOPT_FLASH_IS_BOOTBLOCK
+# if 8 == CYGNUM_FLASH_WIDTH
+ // strata flash with 'byte-enable' contains the configuration data
+ // at even addresses
+ ++p;
+# endif
+#endif
+ }
+ // Reset the flash to array mode. The dummy read is required on MIPS
+ // platforms (don't know about others) to force the write out. Should
+ // there be direct HAL support for this kind of operation?
+ ROM[0] = FLASH_Reset;
+ dummy = ROM[0];
+
+ return 0;
+}
diff --git a/ecos/packages/devs/flash/intel/strata/current/src/flash_unlock_block.c b/ecos/packages/devs/flash/intel/strata/current/src/flash_unlock_block.c
new file mode 100644
index 0000000..4d8cd4a
--- /dev/null
+++ b/ecos/packages/devs/flash/intel/strata/current/src/flash_unlock_block.c
@@ -0,0 +1,141 @@
+//==========================================================================
+//
+// flash_unlock_block.c
+//
+// Flash programming
+//
+//==========================================================================
+// ####ECOSGPLCOPYRIGHTBEGIN####
+// -------------------------------------------
+// This file is part of eCos, the Embedded Configurable Operating System.
+// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, 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.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 v2.
+//
+// This exception does not invalidate any other reasons why a work based
+// on this file might be covered by the GNU General Public License.
+// -------------------------------------------
+// ####ECOSGPLCOPYRIGHTEND####
+//==========================================================================
+//#####DESCRIPTIONBEGIN####
+//
+// Author(s): gthomas, hmt
+// Contributors: gthomas
+// Date: 2001-02-14
+// Purpose:
+// Description:
+//
+//####DESCRIPTIONEND####
+//
+//==========================================================================
+
+#include "strata.h"
+
+
+//
+// The difficulty with this operation is that the hardware does not support
+// unlocking single blocks. However, the logical layer would like this to
+// be the case, so this routine emulates it. The hardware can clear all of
+// the locks in the device at once. This routine will use that approach and
+// then reset the regions which are known to be locked.
+//
+
+#define FLASH_LOCK_MASK 0x1 // which bit of the read query has the lock bit
+
+int
+flash_unlock_block(volatile flash_t *block, int block_size, int blocks)
+ __attribute__ ((section (".2ram.flash_unlock_block")));
+int
+flash_unlock_block(volatile flash_t *block, int block_size, int blocks)
+{
+ volatile flash_t *ROM;
+ flash_t stat;
+ int timeout = 5000000;
+#ifndef CYGOPT_FLASH_IS_SYNCHRONOUS
+ int i;
+ volatile flash_t *bp, *bpv;
+ unsigned char is_locked[CYGNUM_DEVS_FLASH_STRATA_MAX_BLOCKS];
+#endif
+
+ // Get base address and map addresses to virtual addresses
+ ROM = FLASH_P2V( CYGNUM_FLASH_BASE_MASK & (unsigned int)block );
+ block = FLASH_P2V(block);
+
+ // Clear any error conditions
+ ROM[0] = FLASH_Clear_Status;
+
+#ifdef CYGOPT_FLASH_IS_SYNCHRONOUS
+ // Clear lock bit
+ block[0] = FLASH_Clear_Locks;
+ block[0] = FLASH_Clear_Locks_Confirm; // Confirmation
+ while(((stat = ROM[0]) & FLASH_Status_Ready) != FLASH_Status_Ready) {
+ if (--timeout == 0) break;
+ }
+#else
+ // Get current block lock state. This needs to access each block on
+ // the device so currently locked blocks can be re-locked.
+ bp = ROM;
+ for (i = 0; i < blocks; i++) {
+ bpv = FLASH_P2V( bp );
+ *bpv = FLASH_Read_Query;
+ if (bpv == block) {
+ is_locked[i] = 0;
+ } else {
+#if 8 == CYGNUM_FLASH_WIDTH
+ is_locked[i] = bpv[4] & FLASH_LOCK_MASK;
+#else
+ is_locked[i] = bpv[2] & FLASH_LOCK_MASK;
+# endif
+ }
+ bp += block_size / sizeof(*bp);
+ }
+
+ // Clears all lock bits
+ ROM[0] = FLASH_Clear_Locks;
+ ROM[0] = FLASH_Clear_Locks_Confirm; // Confirmation
+ timeout = 5000000;
+ while(((stat = ROM[0]) & FLASH_Status_Ready) != FLASH_Status_Ready) {
+ if (--timeout == 0) break;
+ }
+
+ // Restore the lock state
+ bp = ROM;
+ for (i = 0; i < blocks; i++) {
+ bpv = FLASH_P2V( bp );
+ if (is_locked[i]) {
+ *bpv = FLASH_Set_Lock;
+ *bpv = FLASH_Set_Lock_Confirm; // Confirmation
+ timeout = 5000000;
+ while(((stat = ROM[0]) & FLASH_Status_Ready) != FLASH_Status_Ready) {
+ if (--timeout == 0) break;
+ }
+ }
+ bp += block_size / sizeof(*bp);
+ }
+#endif // CYGOPT_FLASH_IS_SYNCHRONOUS
+
+ // Restore ROM to "normal" mode
+ ROM[0] = FLASH_Reset;
+
+ return stat;
+}
diff --git a/ecos/packages/devs/flash/intel/strata/current/src/strata.c b/ecos/packages/devs/flash/intel/strata/current/src/strata.c
new file mode 100644
index 0000000..53f4a87
--- /dev/null
+++ b/ecos/packages/devs/flash/intel/strata/current/src/strata.c
@@ -0,0 +1,185 @@
+//==========================================================================
+//
+// strata.c
+//
+// Flash programming
+//
+//==========================================================================
+// ####ECOSGPLCOPYRIGHTBEGIN####
+// -------------------------------------------
+// This file is part of eCos, the Embedded Configurable Operating System.
+// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, 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.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 v2.
+//
+// This exception does not invalidate any other reasons why a work based
+// on this file might be covered by the GNU General Public License.
+// -------------------------------------------
+// ####ECOSGPLCOPYRIGHTEND####
+//==========================================================================
+//#####DESCRIPTIONBEGIN####
+//
+// Author(s): gthomas, hmt
+// Contributors: gthomas
+// Date: 2001-02-14
+// Purpose:
+// Description:
+//
+//####DESCRIPTIONEND####
+//
+//==========================================================================
+
+#include <pkgconf/system.h>
+#include <pkgconf/hal.h>
+#include <cyg/hal/hal_arch.h>
+
+#include <cyg/io/flash.h>
+
+#include "strata.h"
+
+#define _si(p) ((p[1]<<8)|p[0])
+
+extern void diag_dump_buf(void *buf, CYG_ADDRWORD len);
+
+extern int strncmp(const char *s1, const char *s2, size_t len);
+extern void *memcpy( void *, const void *, size_t );
+
+int
+flash_hwr_init(void)
+{
+ struct FLASH_query data, *qp;
+ int num_regions, region_size, buffer_size;
+
+ flash_dev_query(&data);
+ qp = &data;
+ if ( ((qp->manuf_code == FLASH_Intel_code) ||
+ (qp->manuf_code == FLASH_STMicro_code))
+#ifdef CYGOPT_FLASH_IS_BOOTBLOCK
+ // device types go as follows: 0x90 for 16-bits, 0xD0 for 8-bits,
+ // plus 0 or 1 for -T (Top Boot) or -B (Bottom Boot)
+ // [FIXME: whatever that means :FIXME]
+ // [I think it means the boot blocks are top/bottom of addr space]
+ // plus the following size codes:
+ // 0: 16Mbit 2: 8Mbit 4: 4Mbit
+ // 6: 32Mbit 8: 64Mbit
+#if 16 == CYGNUM_FLASH_WIDTH
+ && (0x90 == (0xF0 & qp->device_code)) // 16-bit devices
+#elif 8 == CYGNUM_FLASH_WIDTH
+ && (0xD0 == (0xF0 & qp->device_code)) // 8-bit devices
+#else
+ && 0
+#error Only understand 16 and 8-bit bootblock flash types
+#endif
+ ) {
+ int lookup[] = { 16, 8, 4, 32, 64 };
+#define BLOCKSIZE (0x10000)
+ region_size = BLOCKSIZE;
+ num_regions = qp->device_code & 0x0F;
+ num_regions >>= 1;
+ if ( num_regions > 4 )
+ goto flash_type_unknown;
+ num_regions = lookup[num_regions];
+ num_regions *= 1024 * 1024; // to bits
+ num_regions /= 8; // to bytes
+ num_regions /= BLOCKSIZE; // to blocks
+ buffer_size = 0;
+#else // CYGOPT_FLASH_IS_BOOTBLOCK
+ && (strncmp(qp->id, "QRY", 3) == 0)) {
+ num_regions = _si(qp->num_regions)+1;
+ region_size = _si(qp->region_size)*256;
+ if (_si(qp->buffer_size)) {
+ buffer_size = CYGNUM_FLASH_DEVICES << _si(qp->buffer_size);
+ } else {
+ buffer_size = 0;
+ }
+#endif // Not CYGOPT_FLASH_IS_BOOTBLOCK
+
+ flash_info.block_size = region_size*CYGNUM_FLASH_DEVICES;
+ flash_info.buffer_size = buffer_size;
+ flash_info.blocks = num_regions;
+ flash_info.start = (void *)CYGNUM_FLASH_BASE;
+ flash_info.end = (void *)(CYGNUM_FLASH_BASE +
+ (num_regions*region_size*CYGNUM_FLASH_DEVICES));
+#ifdef CYGNUM_FLASH_BASE_MASK
+ // Then this gives us a maximum size for the (visible) device.
+ // This is to cope with oversize devices fitted, with some high
+ // address lines ignored.
+ if ( ((unsigned int)flash_info.start & CYGNUM_FLASH_BASE_MASK) !=
+ (((unsigned int)flash_info.end - 1) & CYGNUM_FLASH_BASE_MASK ) ) {
+ // then the size of the device appears to span >1 device-worth!
+ unsigned int x;
+ x = (~(CYGNUM_FLASH_BASE_MASK)) + 1; // expected device size
+ x += (unsigned int)flash_info.start;
+ if ( x < (unsigned int)flash_info.end ) { // 2nd sanity check
+ (*flash_info.pf)("\nFLASH: Oversized device! End addr %p changed to %p\n",
+ flash_info.end, (void *)x );
+ flash_info.end = (void *)x;
+ // Also adjust the block count else unlock crashes!
+ x = ((cyg_uint8 *)flash_info.end - (cyg_uint8 *)flash_info.start)
+ / flash_info.block_size;
+ flash_info.blocks = x;
+ }
+ }
+#endif // CYGNUM_FLASH_BASE_MASK
+
+ return FLASH_ERR_OK;
+ }
+#ifdef CYGOPT_FLASH_IS_BOOTBLOCK
+ flash_type_unknown:
+#endif
+ (*flash_info.pf)("Can't identify FLASH, sorry, man %x, dev %x, id [%4s] \n",
+ qp->manuf_code, qp->device_code, qp->id );
+ diag_dump_buf(qp, sizeof(data));
+ return FLASH_ERR_HWR;
+}
+
+// Map a hardware status to a package error
+int
+flash_hwr_map_error(int err)
+{
+ if (err & FLASH_ErrorMask) {
+ (*flash_info.pf)("Err = %x\n", err);
+ if (err & FLASH_ErrorProgram)
+ return FLASH_ERR_PROGRAM;
+ else if (err & FLASH_ErrorErase)
+ return FLASH_ERR_ERASE;
+ else
+ return FLASH_ERR_HWR; // FIXME
+ } else {
+ return FLASH_ERR_OK;
+ }
+}
+
+// See if a range of FLASH addresses overlaps currently running code
+bool
+flash_code_overlaps(void *start, void *end)
+{
+ extern 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)));
+}
+
+// EOF strata.c
diff --git a/ecos/packages/devs/flash/intel/strata/current/src/strata.h b/ecos/packages/devs/flash/intel/strata/current/src/strata.h
new file mode 100644
index 0000000..e1fbdc4
--- /dev/null
+++ b/ecos/packages/devs/flash/intel/strata/current/src/strata.h
@@ -0,0 +1,177 @@
+#ifndef CYGONCE_DEVS_FLASH_INTEL_STRATA_FLASH_H
+#define CYGONCE_DEVS_FLASH_INTEL_STRATA_FLASH_H
+//==========================================================================
+//
+// strata.h
+//
+// strataFlash programming - device constants, etc.
+//
+//==========================================================================
+// ####ECOSGPLCOPYRIGHTBEGIN####
+// -------------------------------------------
+// This file is part of eCos, the Embedded Configurable Operating System.
+// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, 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.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 v2.
+//
+// This exception does not invalidate any other reasons why a work based
+// on this file might be covered by the GNU General Public License.
+// -------------------------------------------
+// ####ECOSGPLCOPYRIGHTEND####
+//==========================================================================
+//#####DESCRIPTIONBEGIN####
+//
+// Author(s): gthomas, hmt
+// Contributors: gthomas
+// Date: 2001-02-14
+// Purpose:
+// Description:
+//
+//####DESCRIPTIONEND####
+//
+//==========================================================================
+
+#include <pkgconf/system.h>
+#include <pkgconf/devs_flash_strata.h>
+#include CYGDAT_DEVS_FLASH_STRATA_INL
+
+// ------------------------------------------------------------------------
+//
+// It is expected that the above include defined all the properties of the
+// device we want to drive: the choices this module supports include:
+//
+// Buffered Read Block
+// write query locking
+// 28FxxxB3 - Bootblock - no no no
+// 28FxxxC3 - StrataFlash - no yes yes
+// 28FxxxJ3 - Advanced StrataFlash - yes yes yes
+// 28FxxxK3 - Synchronous StrataFlash - yes yes yes
+//
+// These options are controlled by defining or not, in that include file,
+// these symbols (not CDL options, just symbols - though they could be CDL
+// in future)
+// CYGOPT_FLASH_IS_BOOTBLOCK - for xxxB3 devices.
+// CYGOPT_FLASH_IS_NOT_ADVANCED - for xxxC3 devices.
+// CYGOPT_FLASH_IS_SYNCHRONOUS - for xxxK3 devices.
+// none of the above - for xxxJ3 devices.
+// (Advanced seems to be usual these days hence the sense of that opt)
+//
+// Other properties are controlled by these symbols:
+// CYGNUM_FLASH_DEVICES number of devices across the databus
+// CYGNUM_FLASH_WIDTH number of bits in each device
+// CYGNUM_FLASH_BLANK 1 if blank is allones, 0 if 0
+// CYGNUM_FLASH_BASE base address
+// CYGNUM_FLASH_BASE_MASK a mask to get base address from any
+//
+// for example, a 32-bit memory could be made from 1x32bit, 2x16bit or
+// 4x8bit devices; usually 16bit ones are chosen in practice, so we would
+// have CYGNUM_FLASH_DEVICES = 2, and CYGNUM_FLASH_WIDTH = 16. Both
+// devices would be handled simulataneously, via 32bit bus operations.
+// Some CPUs can handle a single 16bit device as 32bit memory "by magic".
+// In that case, CYGNUM_FLASH_DEVICES = 1 and CYGNUM_FLASH_WIDTH = 16, and
+// the device is managed using only 16bit bus operations.
+
+#define CYGNUM_FLASH_INTERLEAVE CYGNUM_FLASH_DEVICES
+#define _FLASH_PRIVATE_
+#include <cyg/io/flash_dev.h>
+
+#define flash_t flash_data_t
+// ------------------------------------------------------------------------
+//
+// This generic code is intended to deal with all shapes and orientations
+// of Intel StrataFlash. Trademarks &c belong to their respective owners.
+//
+// It therefore needs some trickery to define the constants and accessor
+// types that we use to interact with the device or devices.
+//
+// The assumptions are that
+// o Parallel devices, we write to, with the "opcode" replicated per
+// device
+// o The "opcode" and status returns exist only in the low byte of the
+// device's interface regardless of its width.
+// o Hence opcodes and status are only one byte.
+// An exception is the test for succesfully erased data.
+//
+// ------------------------------------------------------------------------
+// ------------------------------------------------------------------------
+
+#define FLASH_Read_ID FLASHWORD( 0x90 )
+#ifndef CYGOPT_FLASH_IS_BOOTBLOCK
+#define FLASH_Read_Query FLASHWORD( 0x98 ) // Strata only
+#endif
+#define FLASH_Read_Status FLASHWORD( 0x70 )
+#define FLASH_Clear_Status FLASHWORD( 0x50 )
+#define FLASH_Status_Ready FLASHWORD( 0x80 )
+#ifdef CYGOPT_FLASH_IS_BOOTBLOCK
+#define FLASH_Program FLASHWORD( 0x40 ) // BootBlock only
+#else
+#define FLASH_Program FLASHWORD( 0x10 )
+#endif
+#define FLASH_Block_Erase FLASHWORD( 0x20 )
+#ifndef CYGOPT_FLASH_IS_BOOTBLOCK
+#ifndef CYGOPT_FLASH_IS_NOT_ADVANCED
+#define FLASH_Write_Buffer FLASHWORD( 0xE8 ) // *Advanced* Strata only
+#endif // flash is advanced ie. has Write Buffer command
+#define FLASH_Set_Lock FLASHWORD( 0x60 ) // Strata only
+#define FLASH_Set_Lock_Confirm FLASHWORD( 0x01 ) // Strata only
+#define FLASH_Clear_Locks FLASHWORD( 0x60 ) // Strata only
+#define FLASH_Clear_Locks_Confirm FLASHWORD( 0xD0 ) // Strata only
+#endif
+#define FLASH_Confirm FLASHWORD( 0xD0 )
+//#define FLASH_Configure FLASHWORD( 0xB8 )
+//#define FLASH_Configure_ReadyWait FLASHWORD( 0x00 )
+//#define FLASH_Configure_PulseOnErase FLASHWORD( 0x01 )
+//#define FLASH_Configure_PulseOnProgram FLASHWORD( 0x02 )
+//#define FLASH_Configure_PulseOnBoth FLASHWORD( 0x03 )
+#define FLASH_Reset FLASHWORD( 0xFF )
+
+// Status that we read back:
+#define FLASH_ErrorMask FLASHWORD( 0x7E )
+#define FLASH_ErrorProgram FLASHWORD( 0x10 )
+#define FLASH_ErrorErase FLASHWORD( 0x20 )
+
+#define FLASH_ErrorNotVerified FLASHWORD( 0x9910 ) // made-up number
+
+// ------------------------------------------------------------------------
+
+#define FLASH_Intel_code 0x89 // NOT mapped to 16+16
+#define FLASH_STMicro_code 0x20 // NOT mapped to 16+16
+
+// Extended query information
+struct FLASH_query {
+ unsigned char manuf_code; // FLASH_Intel_code
+ unsigned char device_code;
+ unsigned char _unused0[14];
+ unsigned char id[3]; // Q R Y
+ unsigned char _unused1[20];
+ unsigned char device_size;
+ unsigned char device_interface[2];
+ unsigned char buffer_size[2];
+ unsigned char is_block_oriented;
+ unsigned char num_regions[2];
+ unsigned char region_size[2];
+};
+
+#endif // CYGONCE_DEVS_FLASH_INTEL_STRATA_FLASH_H
+// ------------------------------------------------------------------------
+// EOF strata.h