Mercurial > flash_v2
changeset 1709:57655b789e8a
* New version of the strata driver based on the old version. This
version uses the new flash device API.
| author | asl |
|---|---|
| date | Fri, 06 Aug 2004 11:15:15 +0000 |
| parents | e7f2b3b6c889 |
| children | d7584216347b |
| files | packages/devs/flash/intel/stratav2/current/ChangeLog packages/devs/flash/intel/stratav2/current/cdl/flash_strata_v2.cdl packages/devs/flash/intel/stratav2/current/include/flash_strata_v2.inl packages/devs/flash/intel/stratav2/current/include/strata_v2_priv.h |
| diffstat | 4 files changed, 1135 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
new file mode 100644 --- /dev/null +++ b/packages/devs/flash/intel/stratav2/current/ChangeLog @@ -0,0 +1,309 @@ +2004-08-05 Andrew Lunn <andrew.lunn@ascom.ch> + + * New version of the strata driver based on the old version. This + version uses the new flash device API. + +2005-01-26 Scott Wilkinson <scott@alliantnetworks.com> + * src/strata.h: + * src/strata.c: + Flash from STMicro is compatible with the Intel strata chips, + so detect them as well. Check for manuf id 0x20. + +2003-10-29 Jonathan Larmour <jifl@eCosCentric.com> + + * src/flash_unlock_block.c (flash_unlock_block): test lock bit + explicitly - newer flash parts use the reserved bits in the + returned data. + +2003-09-11 Jani Monoses <jani@iv.ro> + + * src/flash_erase_block.c (flash_erase_block): + * src/flash_program_buf.c (flash_program_buf): Fix bootblock handling + in erase. Fix erase and word-program for Synchronous Strata and later + chips where block address and word address are required in the first + cycle of the operation while for earlier parts any address was good. + +2003-09-10 Jani Monoses <jani@iv.ro> + + * cdl/flash_strata.cdl: + * src/flash_lock_block.c (flash_lock_block): + * src/flash_unlock_block.c (flash_unlock_block): + * src/flash_erase_block.c (flash_erase_block): + * src/flash_query.c (flash_query): + * src/flash_program_buf.c (flash_program_buf): Use .2ram sections + for putting flash functions to RAM instead of the old method. + +2003-05-02 Jani Monoses <jani@iv.ro> + + * src/strata.c: Switch to using generic flash_query_dev. + The previous cache related changes broke flash_query for + Strata because in the query case the generic flash driver was not + called to handle the caches but the internal handling was removed + nevertheless. + +2003-04-04 Jani Monoses <jani@iv.ro> + + * src/strata.h: + Use generic flash_dev.h for providing the FLASHWORD macro for + different widths and device numbers.No reason to duplicate that + here.This implicitely fixes the case when CYGNUM_FLASH_WIDTH is 16 + and CYGNUM_FLASH_DEVICES is 4. + +2003-04-03 Jani Monoses <jani@iv.ro> + + * src/flash_lock_block.c (flash_lock_block): + * src/flash_unlock_block.c (flash_unlock_block): + * src/flash_erase_block.c (flash_erase_block): + * src/flash_query.c (flash_query): + * src/flash_program_buf.c (flash_program_buf): + Cache enabling and disabling are already handled by generic flash + +2002-08-12 Mark Salter <msalter@redhat.com> + + * src/flash_unlock_block.c: Add synchronous strataflash support. + * src/strata.h: Add comments regarding synchronous strataflash. + +2002-04-30 Christoph Csebits <christoph.csebits@frequentis.com> + + * src/flash_unlock_block.c: Getting the current block lock + state for flashes in 8-Bit mode is now working correctly. + +2002-04-16 Jonathan Larmour <jlarmour@redhat.com> + + * cdl/flash_strata.cdl: Invoke $(CC) with $(CFLAGS) to ensure the + correct flags are passed. + +2002-04-12 Gary Thomas <gthomas@redhat.com> + + * src/strata.c: Clean up warnings. + +2002-01-22 Mark Salter <msalter@redhat.com> + + * cdl/flash_strata.cdl: Add ".text" before "_end" markers in .s files. + +2001-10-23 Hugo Tyson <hmt@redhat.com> + + * cdl/flash_strata.cdl: Provide an option so that RedBoot .ecm + files can turn off the functionality of copying flash driver code + to separate RAM for execution; it's not needed for RAM and ROMRAM + startup, and for some platforms it is required to *not* copy thus. + +2001-08-25 Gary Thomas <gthomas@redhat.com> + + * src/flash_program_buf.c (flash_program_buf): Allow configuration + specific code sequence for actual writing of data. Define by the + macro CYGHWR_FLASH_WRITE_ELEM. Note: this is required on some + hardware, like the Intel SA185, which handles flash writes in + strange/obscure fashion. + +2001-07-17 Jeroen Dobbelaere <jeroen.dobbelaere@acunia.com> + + * src/flash_query.c (flash_query): Query needs to be done on even + addresses for byte-enabled strata flash + + * src/flash_program_buf.c (flash_program_buf): Fix of conversion of + write buffer length (in bytes) to the length in 'flash_t' words. + +2001-06-22 Hugo Tyson <hmt@redhat.com> + + * src/strata.c (flash_hwr_init): Need to refer to the query code + as extern char flash_query[], flash_query_end[]; (with the []) or + MIPS code gen assumes these are short offsets and linking fails. + The generic flash code in io/flash already uses this idiom. + +2001-06-22 Hugo Tyson <hmt@redhat.com> + + * src/strata.c (flash_hwr_init): Warnings reduced. No arithmetic + on void *. + +2001-06-21 Hugo Tyson <hmt@redhat.com> + + * src/flash_program_buf.c (flash_program_buf): The buffered write + code didn't jump out if there was a write error, nor verify the + data by reading back. This isn't consistent with the slow case, + and made it take an age if the device is unhappy, and then report + a bizarre error code. Both issues fixed. + +2001-06-21 Hugo Tyson <hmt@redhat.com> + + * src/strata.c (flash_hwr_init): If shrinking to fit, must also + adjust the flash_info.blocks field, else unlock crashes trying to + get status of all those extra blocks that we cannot actually see. + +2001-06-11 Gary Thomas <gthomas@redhat.com> + + * src/strata.c: Remove dependency on printf() via user functions. + +2001-06-07 Hugo Tyson <hmt@redhat.com> + + * src/strata.c (flash_hwr_init): If we find a flash device that is + larger than is possible given the memory map, shrink to fit. + We know about the memory map from CYGNUM_FLASH_BASE_MASK (if + defined); it tells us the stride from one device to another. + + This is to cope with installing, say, a 28F640 in a slot designed + for a 28F320 because of supply issues - it all works fine so long + as A22 is grounded. + +2001-05-23 Jesper Skov <jskov@redhat.com> + + * cdl/flash_strata.cdl: Needs IO driver to copy functions to RAM. + +2001-04-26 Gary Thomas <gthomas@redhat.com> + + * src/strata.c: Be more careful when enable/flush/disable caches. + + * src/flash_erase_block.c (flash_erase_block): Boot block devices + may require additional erase commands to erase entire 'block'. + +2001-03-21 Hugo Tyson <hmt@redhat.com> + + * src/strata.h (FLASH_Write_Buffer): Do not define this if + CYGOPT_FLASH_IS_NOT_ADVANCED is defined; Advanced (xxxJ3) flash is + usual these days. Also added documentation of the options that + can be used to control this module. + + * src/flash_program_buf.c (flash_program_buf): Reduce warnings + about unused variables if no FLASH_Write_Buffer command available. + +2001-03-21 Gary Thomas <gthomas@redhat.com> + + * src/flash_program_buf.c (flash_program_buf): Buffered write code + fixups, only on platforms with it defined. + +2001-03-17 Gary Thomas <gthomas@redhat.com> + + * src/strata.h: + * src/strata.c: Support buffered writes. + + * src/flash_program_buf.c: Use buffered writes if possible. This + mode allows the chip to do parallelized writes which is much faster. + It does require additional information, now provided by upper layer. + +2001-02-15 Hugo Tyson <hmt@redhat.com> + + * src/flash_query.c (flash_query): Depending on whether + CYGOPT_FLASH_IS_BOOTBLOCK (just a #define from the instantiator, + not really a cdl_option) is set, do the full Read_Query or just + acquire two codes for manufacturer and device type using Read_ID. + + * src/strata.c (flash_hwr_init): Again depending on whether + CYGOPT_FLASH_IS_BOOTBLOCK, decode the device type into a size and + so on, or use the full Read_Query data as before. + + * src/strata.h (FLASH_Read_ID): Undefine those commands which we + do not use. Conditionally define those that we use depending on + CYGOPT_FLASH_IS_BOOTBLOCK. Thus we should be able to deal with + StrataFlash and BootBlock flash with the same code. + + * cdl/flash_strata.cdl: Do not implement (in the CDL sense) + CYGHWR_IO_FLASH_BLOCK_LOCKING leave it up to the instantiating + package instead. Also move the build of the two objects that do + locking and unlocking into a compenent which is only active if + CYGHWR_IO_FLASH_BLOCK_LOCKING is indeed (requested to be) + implemented somewhere. + +2001-02-14 Hugo Tyson <hmt@redhat.com> + + * devs/flash/intel/strata/...: New package, generic strataFlash + driver based on several others; a portion of its history + follows... + + flash.h -> strata.h + flash<platform>.c -> strata.c + +2001-02-06 Hugo Tyson <hmt@redhat.com> + + * src/flash.h: Much more generic again. Not yet separated into + generic component and invocation header, but the structure is + there. Also included support for a mapping from the physical + flash address we're thinking of to the virtual address we use to + access it. More documentation. Generalization to 8,16,32 and + 64-bit access, made up from 8,16 or 32-bit devices. Command and + status macros modified to accommodate these options. + + * src/flash_lock_block.c (flash_lock_block): + * src/flash_erase_block.c (flash_erase_block): + * src/flash_query.c (flash_query): + * src/flash_program_buf.c (flash_program_buf): + All now acquire when possible the ROM address from the block + address, and use the physical to virtual macro as needed. + + * src/flash_unlock_block.c (flash_unlock_block): + The same changes, but a little more complex because of the need to + clear-all then re-lock some semantics. Shadow pointer to virtual + address is used each time round the loop. + + * cdl/flash_strata.cdl: Add explicit dependencies on flash.h, for + there were none - or they were ignored - for the specially built + compilation units that get copied to RAM for execution. + +2001-02-01 Hugo Tyson <hmt@redhat.com> + + * all: copied from the assabet flash driver. + +2000-12-05 Jonathan Larmour <jlarmour@redhat.com> + + * src/assabet_flash.c (flash_code_overlaps): Define stext/etext + as array types so no assumptions can be made by the compiler about + location. + +2000-10-24 Gary Thomas <gthomas@redhat.com> + + * src/flash_unlock_block.c (flash_unlock_block): + * src/flash_lock_block.c (flash_lock_block): + * src/flash_program_buf.c (flash_program_buf): + * src/flash_erase_block.c (flash_erase_block): Support up to 32M FLASH. + +2000-09-10 Gary Thomas <gthomas@redhat.com> + + * src/flash_unlock_block.c: + * src/flash_lock_block.c: New file(s). + + * src/flash.h: + * cdl/flash_assabet.cdl: Add region locking functions. + +2000-08-29 Gary Thomas <gthomas@redhat.com> + + * src/assabet_flash.c: Improve error decoding. + +2000-08-24 Gary Thomas <gthomas@redhat.com> + + * src/flash_query.c: + * src/flash_erase_block.c: + * src/flash.h: FLASH support for Intel SA1110 Assabet. + +//=========================================================================== +//####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/intel/stratav2/current/cdl/flash_strata_v2.cdl @@ -0,0 +1,89 @@ +# ==================================================================== +# +# flash_strata_v2.cdl +# +# FLASH memory - Hardware support for Intel Strata Flash +# +# ==================================================================== +#####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): gthomas +# Original data: gthomas +# Contributors: Andrew Lunn +# Date: 2000-07-26 +# +#####DESCRIPTIONEND#### +# +# ==================================================================== + +cdl_package CYGPKG_DEVS_FLASH_STRATA_V2 { + display "Intel StrataFLASH memory support" + + parent CYGPKG_IO_FLASH + active_if CYGPKG_IO_FLASH + + implements CYGHWR_IO_FLASH_DEVICE + implements CYGHWR_IO_FLASH_DEVICE_V2 + + active_if CYGINT_DEVS_FLASH_STRATA_V2_REQUIRED + + include_dir cyg/io + + description "FLASH memory device support for Intel StrataFlash using + the V2 driver API" + + cdl_option CYGOPT_DEVS_FLASH_STRATA_V2_LOCKING { + display "Flash device implements locking" + default_value 1 + description " + This option controls whether the driver will include code + to allow locking and unlocking of blocks." + } + + cdl_option CYGOPT_DEV_FLASH_STATE_V2_DUMP_UNKNOWN { + display "Dump the identification string for unknown devices" + default_value 0 + description " + This option, when enabled, causes the device driver to + dump the identification string when it finds a device it cannot + identify. Seeing this information is useful for debugging when + the driver fails to recoginise the device. However in normal + operation you probably don't want to see this information + because it could acutally be another device some other driver + in the image can driver." + } +} +
new file mode 100644 --- /dev/null +++ b/packages/devs/flash/intel/stratav2/current/include/flash_strata_v2.inl @@ -0,0 +1,569 @@ +#ifndef CYGONCE_DEVS_FLASH_STRATA_V2_INL +#define CYGONCE_DEVS_FLASH_STRATA_V2_INL +//========================================================================== +// +// flash_strata.inl +// +// Flash programming for the Strata device +// +//========================================================================== +//####ECOSGPLCOPYRIGHTBEGIN#### +// ------------------------------------------- +// 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 +// +// 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): gthomas, hmt +// Contributors: gthomas, asl +// Date: 2001-02-14 +// Purpose: +// Description: +// +//####DESCRIPTIONEND#### +// +//========================================================================== + +#include <pkgconf/system.h> +#include <pkgconf/hal.h> +#include <cyg/hal/hal_arch.h> + +#define _FLASH_PRIVATE_ +#include <cyg/io/flash.h> +#include <cyg/io/strata_v2_priv.h> + +#define _si(p) ((p[1]<<8)|p[0]) + +#ifdef CYGOPT_DEV_FLASH_STATE_V2_DUMP_UNKNOWN +extern void diag_dump_buf(void *buf, CYG_ADDRWORD len); +#endif +extern int strncmp(const char *s1, const char *s2, size_t len); +extern void *memcpy( void *, const void *, size_t ); + +//---------------------------------------------------------------------------- +// Functions that put the flash device into non-read mode must reside +// in RAM. +static size_t +strata_query_hwr (struct cyg_flash_dev *dev, void * data, + const size_t len) + __attribute__ ((section (".2ram.flash_query"))); + +static int strata_erase_block (struct cyg_flash_dev *dev, + const cyg_flashaddr_t block) + __attribute__ ((section (".2ram.flash_erase_block"))); + +static int strata_program_buf (struct cyg_flash_dev *dev, + cyg_flashaddr_t base, + const void* data, + const size_t len) + __attribute__ ((section (".2ram.flash_program_buf"))); + +#ifdef CYGOPT_DEVS_FLASH_STRATA_LOCKING +static int strata_unlock_block(struct cyg_flash_dev *dev, + const cyg_flashaddr_t block_base) + __attribute__ ((section (".2ram.flash_unlock_block"))); + +static int strata_lock_block(struct cyg_flash_dev *dev, + const cyg_flashaddr_t block_base) + __attribute__ ((section (".2ram.flash_lock_block"))); +#endif + +//---------------------------------------------------------------------------- +// Private structure used by the device. +struct cyg_flash_strata_v2_priv { + cyg_block_info_t block_info [1]; + unsigned int buffer_size; // Size of write buffer +}; +//---------------------------------------------------------------------------- + +static int +strata_init (struct cyg_flash_dev *dev) +{ + struct FLASH_query data, *qp; + int num_regions, region_size, buffer_size; + struct cyg_flash_strata_v2_priv *priv = dev->priv; + + dev->funs->flash_query(dev, &data, sizeof(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_INTERLEAVE << _si(qp->buffer_size); + } else { + buffer_size = 0; + } +#endif // Not CYGOPT_FLASH_IS_BOOTBLOCK + + dev->end = dev->start + + (num_regions*region_size*CYGNUM_FLASH_INTERLEAVE); + priv->buffer_size = buffer_size; + priv->block_info[0].blocks = num_regions; + priv->block_info[0].block_size = region_size * CYGNUM_FLASH_INTERLEAVE; + dev->block_info = priv->block_info; + dev->num_block_infos = 1; + +#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 ( (dev->start & CYGNUM_FLASH_BASE_MASK) != + ((dev->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)dev->start; + if ( x < (unsigned int)dev->end ) { // 2nd sanity check + (dev->pf)("\nFLASH: Oversized device! End addr %p changed to %p\n", + dev->end, (void *)x ); + dev->end = x; + // Also adjust the block count else unlock crashes! + x = ((cyg_uint8 *)dev->end - (cyg_uint8 *)dev->start) + / priv->block_info[0].block_size; + priv->block_info[0].blocks = x; + } + } +#endif // CYGNUM_FLASH_BASE_MASK + + return FLASH_ERR_OK; + } +#ifdef CYGOPT_FLASH_IS_BOOTBLOCK + flash_type_unknown: +#endif +#ifdef CYGOPT_DEV_FLASH_STATE_V2_DUMP_UNKNOWN + (dev->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)); +#endif + return FLASH_ERR_HWR; +} + +//---------------------------------------------------------------------------- +// Map a hardware status to a package error +static int strata_hwr_map_error (struct cyg_flash_dev *dev, int err) +{ + if (err & FLASH_ErrorMask) { + (dev->pf)("Err = %x\n", err); + if (err & FLASH_ErrorProgram) + return CYG_FLASH_ERR_PROGRAM; + else if (err & FLASH_ErrorErase) + return CYG_FLASH_ERR_ERASE; + else + return CYG_FLASH_ERR_HWR; // FIXME + } else { + return CYG_FLASH_ERR_OK; + } +} + +//---------------------------------------------------------------------------- +#define CNT 20*1000*10 // Approx 20ms + +static size_t +strata_query_hwr (struct cyg_flash_dev *dev, void *data_dst, const size_t len) +{ + volatile flash_t *ROM; + int i, cnt; + unsigned char *data = (unsigned char *)data_dst; + + // Get base address and map addresses to virtual addresses + ROM = FLASH_P2V( dev->start ); +#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--) ; + for ( /* i */; i > 0; i-- ) { + // It is very deliberate that data is chars NOT flash_t: + // The info comes out in bytes regardless of device. + *data++ = (unsigned char) (*ROM++); +#ifndef CYGOPT_FLASH_IS_BOOTBLOCK +# if 8 == CYGNUM_FLASH_WIDTH + // strata flash with 'byte-enable' contains the configuration data + // at even addresses + ++ROM; +# endif +#endif + } + ROM[0] = FLASH_Reset; + + return 0; +} + + +//---------------------------------------------------------------------------- +static int strata_erase_block (struct cyg_flash_dev *dev, + const cyg_flashaddr_t block_base) +{ + volatile flash_t *ROM; + flash_t stat = 0; + int timeout = 50000; + int len, block_len, erase_block_size; + volatile flash_t *eb, *block; + + // Get base address and map addresses to virtual addresses + ROM = FLASH_P2V(dev->start); + eb = block = FLASH_P2V(block_base); + block_len = dev->block_info[0].block_size; + +#ifdef CYGOPT_FLASH_IS_BOOTBLOCK +#define BLOCKSIZE (0x10000*CYGNUM_FLASH_INTERLEAVE) +#define ERASE_BLOCKSIZE (0x2000*CYGNUM_FLASH_INTERLEAVE) + if ((eb - ROM) < BLOCKSIZE/(sizeof eb[0])) { + erase_block_size = ERASE_BLOCKSIZE; + } else { + erase_block_size = block_size; + } +#else + erase_block_size = dev->block_info[0].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 = dev->block_info[0].block_size; + while (len > 0) { + if (*block++ != FLASH_BlankValue ) break; + len -= sizeof(*block); + } + if (len == 0) stat = 0; + } + + return stat; +} + +//---------------------------------------------------------------------------- +static int +strata_program_buf (struct cyg_flash_dev *dev, + cyg_flashaddr_t base_addr, + const void* data_addr, + const size_t total_len) +{ + struct cyg_flash_strata_v2_priv *priv = dev->priv; + volatile flash_t *ROM; + volatile flash_t *BA, *addr; + flash_t * data = (flash_t *)data_addr; + flash_t stat = 0; + int timeout = 50000; + int len = total_len; + +#ifdef FLASH_Write_Buffer + int i, wc; +#endif + + // Get base address and map addresses to virtual addresses + ROM = FLASH_P2V( dev->start ); + BA = addr = FLASH_P2V(base_addr); + + // Clear any error conditions + ROM[0] = FLASH_Clear_Status; + +#ifdef FLASH_Write_Buffer + // Write any big chunks first + while (len >= priv->buffer_size) { + wc = priv->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 + *(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; +} + +#ifdef CYGPKG_DEVS_FLASH_STRATA_LOCKING +//---------------------------------------------------------------------------- +// +// 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 MAX_FLASH_BLOCKS 128 +#define FLASH_LOCK_MASK 0x1 // which bit of the read query has the lock bit + +static int +strata_unlock_block(struct cyg_flash_dev *dev, + const cyg_flashaddr_t block_base) +{ + 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[MAX_FLASH_BLOCKS]; +#endif + + // Get base address and map addresses to virtual addresses + ROM = FLASH_P2V( dev->start ); + block = FLASH_P2V(block_base); + + // 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; +} + +//---------------------------------------------------------------------------- +static int +strata_lock_block(struct cyg_flash_dev *dev, + const cyg_flashaddr_t block_base) +{ + volatile flash_t *ROM; + flash_t stat; + int timeout = 5000000; + + // Get base address and map addresses to virtual addresses + ROM = FLASH_P2V(dev->start); + block = FLASH_P2V(block_base); + + // 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; +} +#endif + +//---------------------------------------------------------------------------- + +#ifdef CYGOPT_DEVS_FLASH_STRATA_LOCKING +static CYG_FLASH_FUNS (cyg_flash_strata_v2_funs, + strata_init, + strata_query_hwr, + strata_erase_block, + strata_program_buf, + NULL, + strata_hwr_map_error, + strata_lock_block, + strata_unlock_block); +#else +static CYG_FLASH_FUNS (cyg_flash_strata_v2_funs, + strata_init, + strata_query_hwr, + strata_erase_block, + strata_program_buf, + NULL, + strata_hwr_map_error, + NULL, + NULL); +#endif +#endif //CYGONCE_DEVS_FLASH_STRATA_V2_INL +// EOF strata.c
new file mode 100644 --- /dev/null +++ b/packages/devs/flash/intel/stratav2/current/include/strata_v2_priv.h @@ -0,0 +1,168 @@ +#ifndef CYGONCE_DEVS_FLASH_INTEL_STRATA_V2_STRATA_PRIV_H +#define CYGONCE_DEVS_FLASH_INTEL_STRATA_V2_STRATA_PRIV_H +//========================================================================== +// +// strata_priv.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 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): gthomas, hmt +// Contributors: gthomas +// Date: 2001-02-14 +// Purpose: +// Description: +// +//####DESCRIPTIONEND#### +// +//========================================================================== + +// ------------------------------------------------------------------------ +// +// It is expected that the source file including flash_strata.inl +// 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 the source file, +// these symbols (not CDL options, just symbols) +// 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_INTERLEAVE 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_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_INTERLEAVE = 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_INTERLEAVE = 1 and +// CYGNUM_FLASH_WIDTH = 16, and the device is managed using only 16bit +// bus operations. + +#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_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_V2_STRATA_PRIV_H +// ------------------------------------------------------------------------ +// EOF strata.h
