diff options
Diffstat (limited to 'ecos/packages/devs/flash/arm/iq80310')
9 files changed, 920 insertions, 0 deletions
diff --git a/ecos/packages/devs/flash/arm/iq80310/current/ChangeLog b/ecos/packages/devs/flash/arm/iq80310/current/ChangeLog new file mode 100644 index 0000000..f7d6096 --- /dev/null +++ b/ecos/packages/devs/flash/arm/iq80310/current/ChangeLog @@ -0,0 +1,98 @@ +2008-11-17 Jonathan Larmour <jifl@eCosCentric.com> + + * src/iq80310_flash.c: Explicitly include <cyg/io/flash_dev.h> + rather than just defining _FLASH_PRIVATE_. + (From bartv in flash_v2 branch) + + * cdl/flash_iq80310.cdl: Indicate that this driver uses + the legacy flash device API. + +2003-09-16 Jani Monoses <jani@iv.ro> + + * src/flash_lock_block.c (flash_lock_block): + * src/flash_unlock_block.c (flash_unlock_block): + * src/flash_erase_block.c (flash_erase_block): + * src/flash_query.c (flash_query): + * src/flash_program_buf.c (flash_program_buf): Put flash functions + in RAM using section attributes instead of the old method. + * src/iq80310_flash.c (flash_hwr_init): Use generic flash_query_dev. + +2003-04-04 Jani Monoses <jani@iv.ro> + + * src/flash_lock_block.c (flash_lock_block): + * 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-11-12 Gary Thomas <gary@mlbassoc.com> + + * cdl/flash_iq80310.cdl: New Xscale platforms layout. + +2002-04-16 Jonathan Larmour <jlarmour@redhat.com> + + * cdl/flash_iq80310.cdl: Invoke $(CC) with $(CFLAGS) to ensure the + correct flags are passed. + +2001-09-28 Jonathan Larmour <jlarmour@redhat.com> + + * src/iq80310_flash.c (flash_hwr_init): Only re-enable icache if it + was enabled before. + +2001-08-04 Mark Salter <msalter@redhat.com> + + * src/flash.h (FLASH_P2V): First 4K of flash now mapped at 0xd0000000. + +2001-06-11 Gary Thomas <gthomas@redhat.com> + + * src/iq80310_flash.c: Remove dependency on printf() via user functions. + +2001-05-23 Jesper Skov <jskov@redhat.com> + + * cdl/flash_iq80310.cdl: Needs IO controller to copy functions to + RAM. + +2000-12-05 Jonathan Larmour <jlarmour@redhat.com> + + * src/iq80310_flash.c (flash_code_overlaps): Define stext/etext + as array types so no assumptions can be made by the compiler about + location. + +2000-11-22 Mark Salter <msalter@redhat.com> + + * src/flash_unlock_block.c (flash_unlock_block): Fix broken + read of lock bits. + +2000-11-19 Mark Salter <msalter@redhat.com> + + * src/flash_unlock_block.c (flash_unlock_block): Fix lock state + query to properly use FLASH_P2V macro. Don't issue lock state + query for block we are unlocking. + + * src/flash_program_buf.c (flash_program_buf): Fix code to skip + over Yavapai registers in flash memory space. + +//=========================================================================== +// ####GPLCOPYRIGHTBEGIN#### +// ------------------------------------------- +// This file is part of eCos, the Embedded Configurable Operating System. +// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. +// +// This program 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. +// +// This program 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 this program; if not, write to the +// Free Software Foundation, Inc., 51 Franklin Street, +// Fifth Floor, Boston, MA 02110-1301, USA. +// ------------------------------------------- +// ####GPLCOPYRIGHTEND#### +//=========================================================================== diff --git a/ecos/packages/devs/flash/arm/iq80310/current/cdl/flash_iq80310.cdl b/ecos/packages/devs/flash/arm/iq80310/current/cdl/flash_iq80310.cdl new file mode 100644 index 0000000..9262f7b --- /dev/null +++ b/ecos/packages/devs/flash/arm/iq80310/current/cdl/flash_iq80310.cdl @@ -0,0 +1,74 @@ +# ==================================================================== +# +# flash_iq80310.cdl +# +# FLASH memory - Hardware support on IQ80200/80310 +# +# ==================================================================== +## ####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): msalter +# Original data: msalter, gthomas +# Contributors: +# Date: 2000-10-10 +# +#####DESCRIPTIONEND#### +# +# ==================================================================== + +cdl_package CYGPKG_DEVS_FLASH_ARM_XSCALE_IQ80310 { + display "Cyclone IQ80310 FLASH memory support" + + parent CYGPKG_IO_FLASH + active_if CYGPKG_IO_FLASH + requires CYGPKG_HAL_ARM_XSCALE_IOP310 + + implements CYGHWR_IO_FLASH_DEVICE + implements CYGHWR_IO_FLASH_DEVICE_LEGACY + implements CYGHWR_IO_FLASH_BLOCK_LOCKING + + include_dir . + include_files ; # none _exported_ whatsoever + description "FLASH memory device support for Cyclone IQ80310" + compile iq80310_flash.c flash_erase_block.c flash_program_buf.c flash_query.c + + cdl_component CYGPKG_DEVS_FLASH_IQ80310_LOCKING { + display "Flash device implements locking" + active_if 0 < CYGHWR_IO_FLASH_BLOCK_LOCKING + calculated 1 + compile flash_lock_block.c flash_unlock_block.c + } +} + diff --git a/ecos/packages/devs/flash/arm/iq80310/current/src/flash.h b/ecos/packages/devs/flash/arm/iq80310/current/src/flash.h new file mode 100644 index 0000000..32059e8 --- /dev/null +++ b/ecos/packages/devs/flash/arm/iq80310/current/src/flash.h @@ -0,0 +1,105 @@ +//========================================================================== +// +// flash.h +// +// Flash 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 +// Contributors: gthomas, msalter +// Date: 2000-07-26 +// Purpose: +// Description: +// +//####DESCRIPTIONEND#### +// +//========================================================================== + +#ifndef _FLASH_HWR_H_ +#define _FLASH_HWR_H_ + +// First 4K page of flash at physical address zero is +// virtually mapped at address 0xa0000000. +#define FLASH_P2V(x) ((volatile unsigned char *)(((unsigned)(x) < 0x1000) ? \ + ((unsigned)(x) | 0xd0000000) : \ + (unsigned)(x))) + +#define FLASH_BOOT_BLOCK_SIZE 0x4000 + +#define FLASH_Intel_code 0x89 + +#define FLASH_Read_ID 0x90 +#define FLASH_Read_Query 0x98 +#define FLASH_Read_Status 0x70 +#define FLASH_Clear_Status 0x50 +#define FLASH_Status_Ready 0x80 +#define FLASH_Write_Buffer 0xE8 +#define FLASH_Program 0x10 +#define FLASH_Block_Erase 0x20 +#define FLASH_Set_Lock 0x60 +#define FLASH_Set_Lock_Confirm 0x01 +#define FLASH_Clear_Locks 0x60 +#define FLASH_Clear_Locks_Confirm 0xD0 +#define FLASH_Confirm 0xD0 +#define FLASH_Configure 0xB8 +#define FLASH_Configure_ReadyWait 0x00 +#define FLASH_Configure_PulseOnErase 0x01 +#define FLASH_Configure_PulseOnProgram 0x02 +#define FLASH_Configure_PulseOnBoth 0x03 +#define FLASH_Reset 0xFF + +#define FLASH_BLOCK_SIZE 0x10000 +#define FLASH_WBUF_SIZE 32 + +#define FLASH_Intel_code 0x89 + +// Extended query information +struct FLASH_query { + unsigned char manuf_code; + unsigned char device_code; + unsigned char _unused0[14]; + unsigned char id[3]; // Q Q R + 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 // _FLASH_HWR_H_ diff --git a/ecos/packages/devs/flash/arm/iq80310/current/src/flash_erase_block.c b/ecos/packages/devs/flash/arm/iq80310/current/src/flash_erase_block.c new file mode 100644 index 0000000..dfa1e33 --- /dev/null +++ b/ecos/packages/devs/flash/arm/iq80310/current/src/flash_erase_block.c @@ -0,0 +1,98 @@ +//========================================================================== +// +// 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 +// Contributors: gthomas, msalter +// Date: 2000-07-14 +// Purpose: +// Description: +// +//####DESCRIPTIONEND#### +// +//========================================================================== + +#include "flash.h" + +#include <pkgconf/hal.h> +#include <cyg/hal/hal_arch.h> + + +int flash_erase_block(volatile unsigned char *block) + __attribute__ ((section (".2ram.flash_erase_block"))); +int flash_erase_block(volatile unsigned char *block) +{ + volatile unsigned char *ROM; + unsigned short stat; + int timeout = 50000; + int len; + + // First 4K page of flash at physcial address zero is + // virtually mapped to address 0xa0000000. + ROM = FLASH_P2V((unsigned)block & 0xFF800000); + + // Clear any error conditions + ROM[0] = FLASH_Clear_Status; + + // Erase block + ROM[0] = FLASH_Block_Erase; + *FLASH_P2V(block) = FLASH_Confirm; + timeout = 5000000; + while(((stat = ROM[0]) & FLASH_Status_Ready) != FLASH_Status_Ready) { + if (--timeout == 0) break; + } + + // Restore ROM to "normal" mode + ROM[0] = FLASH_Reset; + + // If an error was reported, see if the block erased anyway + if (stat & 0x7E) { + len = FLASH_BLOCK_SIZE; + while (len > 0) { + if (*FLASH_P2V(block) != 0xFF) + break; + block++; + len -= sizeof(*block); + } + if (len == 0) stat = 0; + } + + return stat; +} diff --git a/ecos/packages/devs/flash/arm/iq80310/current/src/flash_lock_block.c b/ecos/packages/devs/flash/arm/iq80310/current/src/flash_lock_block.c new file mode 100644 index 0000000..49a7555 --- /dev/null +++ b/ecos/packages/devs/flash/arm/iq80310/current/src/flash_lock_block.c @@ -0,0 +1,82 @@ +//========================================================================== +// +// 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 +// Contributors: gthomas, msalter +// Date: 2000-09-10 +// Purpose: +// Description: +// +//####DESCRIPTIONEND#### +// +//========================================================================== + +#include "flash.h" + + + +int +flash_lock_block(volatile unsigned char *block) + __attribute__ ((section (".2ram.flash_lock_block"))); +int +flash_lock_block(volatile unsigned char *block) +{ + volatile unsigned char *ROM; + unsigned short stat; + int timeout = 5000000; + + ROM = FLASH_P2V((unsigned long)block & 0xFF800000); + + // Clear any error conditions + ROM[0] = FLASH_Clear_Status; + + // Set lock bit + FLASH_P2V(block)[0] = FLASH_Set_Lock; + FLASH_P2V(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/arm/iq80310/current/src/flash_program_buf.c b/ecos/packages/devs/flash/arm/iq80310/current/src/flash_program_buf.c new file mode 100644 index 0000000..d60ee84 --- /dev/null +++ b/ecos/packages/devs/flash/arm/iq80310/current/src/flash_program_buf.c @@ -0,0 +1,143 @@ +//========================================================================== +// +// 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 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 +// Contributors: gthomas, msalter +// Date: 2000-07-14 +// Purpose: +// Description: +// +//####DESCRIPTIONEND#### +// +//========================================================================== + +#include "flash.h" + +#include <pkgconf/hal.h> +#include <cyg/hal/hal_arch.h> + + +int +flash_program_buf(volatile unsigned char *addr, unsigned char *data, int len) + __attribute__ ((section (".2ram.flash_program_buf"))); +int +flash_program_buf(volatile unsigned char *addr, unsigned char *data, int len) +{ + volatile unsigned char *ROM; + volatile unsigned char *BA; + unsigned short stat; + int timeout = 5000000; + int i, wc; + + ROM = FLASH_P2V((unsigned long)addr & 0xFF800000); + BA = FLASH_P2V((unsigned long)addr & 0xFFFE0000); + + // Clear any error conditions + ROM[0] = FLASH_Clear_Status; + + wc = 32; + while (len >= wc) { + len -= wc; + + // The IQ803010 has a hole in flash which must be avoided. + if (((unsigned char *)0x1000) <= addr && addr < ((unsigned char *)0x2000)) { + addr += wc; + data += wc; + continue; + } + + *BA = FLASH_Write_Buffer; + timeout = 5000000; + while(((stat = ROM[0]) & FLASH_Status_Ready) != FLASH_Status_Ready) { + if (--timeout == 0) { + stat |= 0x0100; + goto bad; + } + *BA = FLASH_Write_Buffer; + } + *BA = wc-1; // Count is 0..N-1 + if (FLASH_P2V(addr) != addr) { + volatile unsigned char *tmp; + + tmp = FLASH_P2V(addr); + for (i = 0; i < wc; i++) + *tmp++ = *data++; + addr += wc; + } else { + for (i = 0; i < wc; i++) + *addr++ = *data++; + } + *BA = FLASH_Confirm; + stat = *BA; + } + + ROM[0] = FLASH_Read_Status; + timeout = 5000000; + while(((stat = ROM[0]) & FLASH_Status_Ready) != FLASH_Status_Ready) { + if (--timeout == 0) { + stat |= 0x0200; + goto bad; + } + } + + while (len > 0) { + ROM[0] = FLASH_Program; + + *FLASH_P2V(addr) = *data++; + addr++; + timeout = 5000000; + while(((stat = ROM[0]) & FLASH_Status_Ready) != FLASH_Status_Ready) { + if (--timeout == 0) { + stat |= 0x0300; + goto bad; + } + } + --len; + } + + // Restore ROM to "normal" mode + bad: + ROM[0] = FLASH_Reset; + + return stat; +} + + diff --git a/ecos/packages/devs/flash/arm/iq80310/current/src/flash_query.c b/ecos/packages/devs/flash/arm/iq80310/current/src/flash_query.c new file mode 100644 index 0000000..69fbcf6 --- /dev/null +++ b/ecos/packages/devs/flash/arm/iq80310/current/src/flash_query.c @@ -0,0 +1,79 @@ +//========================================================================== +// +// 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 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 +// Contributors: gthomas +// Date: 2000-07-26 +// Purpose: +// Description: +// +//####DESCRIPTIONEND#### +// +//========================================================================== + +#include "flash.h" + +#include <pkgconf/hal.h> +#include <cyg/hal/hal_arch.h> +#include CYGHWR_MEMORY_LAYOUT_H + + +#define CNT 200*1000*10 // Approx 20ms + +int +flash_query(unsigned char *data) __attribute__ ((section (".2ram.flash_query"))); +int +flash_query(unsigned char *data) +{ + volatile unsigned short *ROM; + int i, cnt; + + ROM = (unsigned short *) FLASH_P2V(0); + ROM[0] = FLASH_Read_Query; + for (cnt = CNT; cnt > 0; cnt--) ; + for (i = 0; i < sizeof(struct FLASH_query); i++) { + *data++ = ROM[i]; + } + + ROM[0] = FLASH_Reset; + + return 0; +} diff --git a/ecos/packages/devs/flash/arm/iq80310/current/src/flash_unlock_block.c b/ecos/packages/devs/flash/arm/iq80310/current/src/flash_unlock_block.c new file mode 100644 index 0000000..5f1bc41 --- /dev/null +++ b/ecos/packages/devs/flash/arm/iq80310/current/src/flash_unlock_block.c @@ -0,0 +1,123 @@ +//========================================================================== +// +// 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 +// Contributors: gthomas, msalter +// Date: 2000-09-10 +// Purpose: +// Description: +// +//####DESCRIPTIONEND#### +// +//========================================================================== + +#include "flash.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 MAX_FLASH_BLOCKS 128 + +int +flash_unlock_block(volatile unsigned char *block, int block_size, int blocks) + __attribute__ ((section (".2ram.flash_unlock_block"))); +int +flash_unlock_block(volatile unsigned char *block, int block_size, int blocks) +{ + volatile unsigned short *ROM, *bp; + unsigned short stat; + int timeout = 5000000; + unsigned short is_locked[MAX_FLASH_BLOCKS]; + int i; + + ROM = (unsigned short *) FLASH_P2V((unsigned long)block & 0xFF800000); + + // Clear any error conditions + ROM[0] = FLASH_Clear_Status; + + // Get current block lock state. This needs to access each block on + // the device so currently locked blocks can be re-locked. + bp = (unsigned short *)((unsigned long)block & 0xFF800000); + for (i = 0; i < blocks; i++) { + if (bp == (unsigned short *) block) { + is_locked[i] = 0; + } else { + *(volatile unsigned short *)FLASH_P2V(bp) = FLASH_Read_Query; + is_locked[i] = ((volatile unsigned short *)FLASH_P2V(bp))[2]; + } + bp += block_size / sizeof(*bp); + } + + // Clears all lock bits + FLASH_P2V(block)[0] = FLASH_Clear_Locks; + FLASH_P2V(block)[0] = FLASH_Clear_Locks_Confirm; // Confirmation + timeout = 5000000; + while(((stat = ROM[0]) & FLASH_Status_Ready) != FLASH_Status_Ready) { + if (--timeout == 0) goto done; + } + + // Restore the lock state + bp = (unsigned short *)((unsigned long)block & 0xFF800000); + for (i = 0; i < blocks; i++) { + if (is_locked[i]) { + *FLASH_P2V(bp) = FLASH_Set_Lock; + *FLASH_P2V(bp) = FLASH_Set_Lock_Confirm; // Confirmation + timeout = 5000000; + while(((stat = ROM[0]) & FLASH_Status_Ready) != FLASH_Status_Ready) { + if (--timeout == 0) goto done; + } + } + bp += block_size / sizeof(*bp); + } + + done: + // Restore ROM to "normal" mode + ROM[0] = FLASH_Reset; + + return stat; +} diff --git a/ecos/packages/devs/flash/arm/iq80310/current/src/iq80310_flash.c b/ecos/packages/devs/flash/arm/iq80310/current/src/iq80310_flash.c new file mode 100644 index 0000000..0cd7af6 --- /dev/null +++ b/ecos/packages/devs/flash/arm/iq80310/current/src/iq80310_flash.c @@ -0,0 +1,118 @@ +//========================================================================== +// +// iq80310_flash.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 +// Contributors: gthomas, msalter +// Date: 2000-07-26 +// Purpose: +// Description: +// +//####DESCRIPTIONEND#### +// +//========================================================================== + +#include <pkgconf/hal.h> +#include <cyg/hal/hal_arch.h> +#include <cyg/infra/diag.h> + +#include <cyg/io/flash.h> +#include <cyg/io/flash_dev.h> + +#include "flash.h" + +#define _si(p) ((p[1]<<8)|p[0]) + +extern int strncmp(const char *s1, const char *s2, size_t len); +int +flash_hwr_init(void) +{ + struct FLASH_query data, *qp; + int num_regions, region_size; + + flash_dev_query((void*)&data); + + qp = &data; + if (/*(qp->manuf_code == FLASH_Intel_code) && */ + (strncmp(qp->id, "QRY", 3) == 0)) { + num_regions = _si(qp->num_regions)+1; + region_size = _si(qp->region_size)*256; + + flash_info.block_size = region_size; + flash_info.blocks = num_regions; + flash_info.start = (void *)0x00000000; + flash_info.end = (void *)(0x00000000+(num_regions*region_size)); + return FLASH_ERR_OK; + } else { + (*flash_info.pf)("Can't identify FLASH sorry\n"); + diag_dump_buf((void*)&data, sizeof(data)); + return FLASH_ERR_HWR; + } +} + +// Map a hardware status to a package error +int +flash_hwr_map_error(int err) +{ + if (err & 0x7E) { + (*flash_info.pf)("Err = %x\n", err); + if (err & 0x10) { + return FLASH_ERR_PROGRAM; + } else + if (err & 0x20) { + 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))); +} |