summaryrefslogtreecommitdiff
path: root/ecos/packages/devs/flash/synth
diff options
context:
space:
mode:
authorMichael Gielda <mgielda@antmicro.com>2014-04-03 14:53:04 +0200
committerMichael Gielda <mgielda@antmicro.com>2014-04-03 14:53:04 +0200
commitae1e4e08a1005a0c487f03ba189d7536e7fdcba6 (patch)
treef1c296f8a966a9a39876b0e98e16d9c5da1776dd /ecos/packages/devs/flash/synth
parentf157da5337118d3c5cd464266796de4262ac9dbd (diff)
Added the OS files
Diffstat (limited to 'ecos/packages/devs/flash/synth')
-rw-r--r--ecos/packages/devs/flash/synth/current/ChangeLog122
-rw-r--r--ecos/packages/devs/flash/synth/current/cdl/flash_synth.cdl130
-rw-r--r--ecos/packages/devs/flash/synth/current/src/flash_erase_block.c94
-rw-r--r--ecos/packages/devs/flash/synth/current/src/flash_program_buf.c93
-rw-r--r--ecos/packages/devs/flash/synth/current/src/flash_query.c61
-rw-r--r--ecos/packages/devs/flash/synth/current/src/synth.c157
-rw-r--r--ecos/packages/devs/flash/synth/current/src/synth.h63
-rw-r--r--ecos/packages/devs/flash/synth/current/tests/flash1.c190
-rw-r--r--ecos/packages/devs/flash/synth/current/tests/flash2.c209
9 files changed, 1119 insertions, 0 deletions
diff --git a/ecos/packages/devs/flash/synth/current/ChangeLog b/ecos/packages/devs/flash/synth/current/ChangeLog
new file mode 100644
index 0000000..e8f364d
--- /dev/null
+++ b/ecos/packages/devs/flash/synth/current/ChangeLog
@@ -0,0 +1,122 @@
+2009-02-26 Bart Veer <bartv@ecoscentric.com>
+
+ * tests/flash1.c, tests/flash2.c: fix breakage caused by banner
+ change.
+
+2009-02-20 Jonathan Larmour <jifl@eCosCentric.com>
+
+ * tests/flash2.c (cyg_user_start): Call cyg_flash_init with
+ NULL arg.
+
+2009-02-18 Jonathan Larmour <jifl@eCosCentric.com>
+
+ * tests/flash2.c (cyg_user_start): Update for minor flash API
+ mod to call cyg_flash_set_global_printf() to set printf
+ function.
+
+2008-12-23 Simon Kallweit <simon.kallweit@intefo.ch>
+
+ * src/flash_erase_block.c:
+ * src/flash_program_buf.c:
+ Implemented simulation of proper NOR flash writes. General cleanup.
+
+2008-12-18 Simon Kallweit <simon.kallweit@intefo.ch>
+
+ * src/synth.c: Fixed error check of mmap call.
+
+2008-11-19 Simon Kallweit <simon.kallweit@intefo.ch>
+
+ * tests/flash2.c: Fixed a few warnings.
+
+2008-11-17 Jonathan Larmour <jifl@eCosCentric.com>
+
+ * Merge from flash_v2 branch:
+
+ 2004-12-02 Bart Veer <bartv@ecoscentric.com>
+
+ * src/synth.c: explicitly include <cyg/io/flash_dev.h> rather than
+ just defining _FLASH_PRIVATE_
+ * tests/flash2.c (cyg_user_start): update as per the v2 testcase
+
+ 2004-11-22 Bart Veer <bartv@ecoscentric.com>
+
+ * cdl/flash_synth.cdl: fix testcase definitions
+
+ 2004-08-03 Andrew Lunn <andrew.lunn@ascom.ch>
+
+ * cdl/flash_synth.cdl: Indicate we need the legacy device API.
+ * cdl/flash_synth.cdl:
+ * tests/flash2.c: Added a second test case for the new API.
+
+2005-08-02 Andrew Lunn <andrew.lunn@ascom.ch>
+
+ * tests/flash1.c (cyg_user_start): Fix a compiler warning about
+ signedness of pointers.
+
+2005-07-30 Andrew Lunn <andrew.lunn@ascom.ch>
+
+ * src/synth.c (flash_hwr_init): Cast to keep the compiler happy.
+
+2005-03-27 Andrew Lunn <andrew.lunn@ascom.ch>
+
+ * tests/flash1.c: gcc 3.x does not like string continuing
+ over lines with the " open.
+
+2004-12-15 Andrew Lunn <andrew.lunn@ascom.ch>
+
+ * src/synth.c: Moved cyg_hal_sys_mmap into the HAL.
+
+2003-11-20 Jani Monoses <jani@iv.ro>
+
+ * tests/flash1.c: Update flash_init() call to reflect
+ new prototype.
+
+2002-01-23 Jonathan Larmour <jlarmour@redhat.com>
+
+ * cdl/flash_synth.cdl: Add CYGMEM_FLASH_SYNTH_BASE to allow
+ imposition of base address.
+ Add CYGSEM_FLASH_SYNTH_FILE_WRITEBACK to allow changes to be
+ reflected in the underlying file.
+ * src/synth.c (flash_hwr_init): Implement CYGMEM_FLASH_SYNTH_BASE and
+ CYGSEM_FLASH_SYNTH_FILE_WRITEBACK using appropriate args to mmap().
+ Include <string.h> to avoid warning.
+
+2002-01-11 Jonathan Larmour <jlarmour@redhat.com>
+
+ * src/synth.c (flash_hwr_init): Initialize to 0xff if the file
+ needs creating.
+ * cdl/flash_synth.cdl: requires errno codes.
+
+2002-01-08 Jonathan Larmour <jlarmour@redhat.com>
+2001-11-1 Andrew Lunn <andrew.lunn@ascom.ch>
+
+ * First version. Implements synthetic flash for the synthetic
+ target.
+
+//===========================================================================
+// ####GPLCOPYRIGHTBEGIN####
+// -------------------------------------------
+// This file is part of eCos, the Embedded Configurable Operating System.
+// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2009 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/synth/current/cdl/flash_synth.cdl b/ecos/packages/devs/flash/synth/current/cdl/flash_synth.cdl
new file mode 100644
index 0000000..0351b89
--- /dev/null
+++ b/ecos/packages/devs/flash/synth/current/cdl/flash_synth.cdl
@@ -0,0 +1,130 @@
+# ====================================================================
+#
+# flash_synth.cdl
+#
+# FLASH memory - Synthetic flash driver for Synthetic target
+#
+# ====================================================================
+## ####ECOSGPLCOPYRIGHTBEGIN####
+## -------------------------------------------
+## This file is part of eCos, the Embedded Configurable Operating System.
+## Copyright (C) 1998, 1999, 2000, 2001, 2002 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): andrew.lunn@ascom.ch
+# Contributors: jlarmour
+# Date: 2000-10-30
+#
+#####DESCRIPTIONEND####
+#
+# ====================================================================
+
+cdl_package CYGPKG_DEVS_FLASH_SYNTH {
+ display "Synthetic FLASH memory support"
+
+ parent CYGPKG_IO_FLASH
+ active_if CYGPKG_IO_FLASH
+ requires CYGINT_ISO_ERRNO_CODES
+
+ implements CYGHWR_IO_FLASH_DEVICE
+ implements CYGHWR_IO_FLASH_DEVICE_LEGACY
+
+ include_dir .
+ include_files ; # none _exported_ whatsoever
+ description "FLASH memory device support for Synthetic target"
+ compile synth.c flash_erase_block.c flash_program_buf.c flash_query.c
+
+ cdl_option CYGMEM_FLASH_SYNTH_BASE {
+ display "Base address of flash"
+ flavor booldata
+ default_value 0
+ description "
+ If enabled, controls where in the synth target memory map the
+ flash is mapped. WARNING: This must be somewhere
+ the host Linux kernel is prepaired to mmap a file. It
+ must be page aligned. For hosts with recent x86 Linux kernels,
+ a value of 0x40000000 is likely appropriate. When disabled,
+ the driver will automatically use whatever address the kernel
+ provides it with."
+ }
+
+ cdl_option CYGSEM_FLASH_SYNTH_FILE_WRITEBACK {
+ display "FLASH changes modify the underlying file"
+ flavor booldata
+ default_value 0
+ description "
+ If enabled, changes made to the contents of the emulated
+ FLASH are reflected in the underlying file. Otherwise,
+ the file will be left unaffected by any changes the program
+ makes to FLASH contents."
+ }
+
+ cdl_option CYGNUM_FLASH_SYNTH_BLOCKSIZE {
+ display "Size of one block of synth flash"
+ flavor data
+ default_value 65536
+ legal_values 4096 to 999999
+ requires { (CYGNUM_FLASH_SYNTH_BLOCKSIZE % 4096) == 0 }
+ description "
+ This controls the size of one block of flash. This is
+ the minimum size that can be erased."
+ }
+
+ cdl_option CYGNUM_FLASH_SYNTH_NUMBLOCKS {
+ display "Number of blocks in the synth flash"
+ flavor data
+ default_value 16
+ description "
+ This controls how many blocks there are in the flash"
+ }
+
+ cdl_option CYGDAT_FLASH_SYNTH_FILENAME {
+ display "Name of file emulating synth flash"
+ flavor data
+ default_value { "\"synth.flash\"" }
+ description "
+ This is the name of the file which holds the contents of
+ the flash. It is mmap'ed into memory and written for flash
+ program & erase operations. It will be created if it does
+ not exist."
+ }
+
+ cdl_option CYGPKG_DEVS_FLASH_SYNTH_TESTS {
+ display "Synth flash tests"
+ flavor data
+ no_define
+ calculated { "tests/flash1 tests/flash2"}
+ description "
+ This option specifies the set of tests for the synth flash package."
+ }
+}
+
+# EOF flash_synth.cdl
diff --git a/ecos/packages/devs/flash/synth/current/src/flash_erase_block.c b/ecos/packages/devs/flash/synth/current/src/flash_erase_block.c
new file mode 100644
index 0000000..34ad907
--- /dev/null
+++ b/ecos/packages/devs/flash/synth/current/src/flash_erase_block.c
@@ -0,0 +1,94 @@
+//==========================================================================
+//
+// 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): andrew.lunn@ascom.ch
+// Contributors: andrew.lunn
+// Date: 2001-10-30
+// Purpose:
+// Description:
+//
+//####DESCRIPTIONEND####
+//
+//==========================================================================
+
+#include "synth.h"
+
+#include <cyg/hal/hal_io.h>
+#include <pkgconf/devs_flash_synth.h>
+#include <cyg/infra/cyg_ass.h>
+#include <cyg/io/flash.h>
+#include <cyg/io/flash_dev.h>
+#include <string.h> // memset
+
+#ifndef MIN
+#define MIN(x,y) ((x)<(y) ? (x) : (y))
+#endif
+
+int flash_erase_block(volatile flash_t *block, unsigned int block_size)
+{
+ unsigned int offset = (unsigned int) block;
+ size_t remaining;
+ int write_size;
+
+ // This helps speed up the erasing
+ static cyg_uint8 empty[4096];
+ static cyg_bool empty_inited;
+
+ offset -= (unsigned int) cyg_dev_flash_synth_base;
+
+ cyg_hal_sys_lseek(cyg_dev_flash_synth_flashfd, offset,
+ CYG_HAL_SYS_SEEK_SET);
+
+ if (!empty_inited) {
+ memset(empty, 0xff, sizeof(empty));
+ empty_inited = true;
+ }
+
+ remaining = flash_info.block_size;
+
+ while (remaining) {
+ write_size = MIN(remaining, sizeof(empty));
+ cyg_hal_sys_write(cyg_dev_flash_synth_flashfd, empty, write_size);
+ remaining -= write_size;
+ }
+
+ return FLASH_ERR_OK;
+}
diff --git a/ecos/packages/devs/flash/synth/current/src/flash_program_buf.c b/ecos/packages/devs/flash/synth/current/src/flash_program_buf.c
new file mode 100644
index 0000000..6eb50f9
--- /dev/null
+++ b/ecos/packages/devs/flash/synth/current/src/flash_program_buf.c
@@ -0,0 +1,93 @@
+//==========================================================================
+//
+// 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): Andrew.Lunn@ascom.ch
+// Contributors: andrew.lunn
+// Date: 2001-10-30
+// Purpose:
+// Description:
+//
+//####DESCRIPTIONEND####
+//
+//==========================================================================
+
+#include "synth.h"
+
+#include <pkgconf/devs_flash_synth.h>
+#include <cyg/hal/hal_io.h>
+#include <cyg/io/flash.h>
+
+#ifndef MIN
+#define MIN(x,y) ((x)<(y) ? (x) : (y))
+#endif
+
+int
+flash_program_buf(volatile flash_t *addr, flash_t *data, int len,
+ unsigned long block_mask, int buffer_size)
+{
+ unsigned int offset = (unsigned int) addr;
+ cyg_uint8 *buf = (cyg_uint8 *) data;
+
+ // This helps speed up the programming
+ static cyg_uint8 tmp[4096];
+
+ offset -= (unsigned int) cyg_dev_flash_synth_base;
+
+ while (len > 0) {
+ int i;
+ int write_size = MIN(len, sizeof(tmp));
+ // Writing to NOR flash only sets bits from 1 to 0, not vice-versa
+ cyg_hal_sys_lseek(cyg_dev_flash_synth_flashfd, offset,
+ CYG_HAL_SYS_SEEK_SET);
+ cyg_hal_sys_read(cyg_dev_flash_synth_flashfd, tmp, write_size);
+ for (i = 0; i < write_size; i++)
+ tmp[i] = tmp[i] & buf[i];
+ cyg_hal_sys_lseek(cyg_dev_flash_synth_flashfd, offset,
+ CYG_HAL_SYS_SEEK_SET);
+ cyg_hal_sys_write(cyg_dev_flash_synth_flashfd, tmp, write_size);
+ // Process next chunk
+ buf += write_size;
+ offset += write_size;
+ len -= write_size;
+ }
+
+ return FLASH_ERR_OK;
+}
diff --git a/ecos/packages/devs/flash/synth/current/src/flash_query.c b/ecos/packages/devs/flash/synth/current/src/flash_query.c
new file mode 100644
index 0000000..8d7d510
--- /dev/null
+++ b/ecos/packages/devs/flash/synth/current/src/flash_query.c
@@ -0,0 +1,61 @@
+//==========================================================================
+//
+// 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): andrew.lunn@ascom.ch
+// Contributors: andrew.lunn
+// Date: 2001-10-30
+// Purpose:
+// Description:
+//
+//####DESCRIPTIONEND####
+//
+//==========================================================================
+
+#define QUERY "Linux Synthetic Flash"
+
+#include <string.h> // memcpy
+
+int
+flash_query(unsigned char *data)
+{
+ memcpy(data,QUERY,sizeof(QUERY));
+ return 0;
+}
diff --git a/ecos/packages/devs/flash/synth/current/src/synth.c b/ecos/packages/devs/flash/synth/current/src/synth.c
new file mode 100644
index 0000000..e4ef6ee
--- /dev/null
+++ b/ecos/packages/devs/flash/synth/current/src/synth.c
@@ -0,0 +1,157 @@
+//==========================================================================
+//
+// synth.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): andrew.lunn@ascom.ch
+// Contributors: jlarmour
+// Date: 2001-10-30
+// Purpose:
+// Description:
+//
+//####DESCRIPTIONEND####
+//
+//==========================================================================
+
+#include <pkgconf/devs_flash_synth.h>
+
+#include <cyg/hal/hal_io.h>
+#include <cyg/infra/cyg_ass.h>
+#include <errno.h>
+#include <string.h>
+
+#include <cyg/io/flash.h>
+#include <cyg/io/flash_dev.h>
+
+#include "synth.h"
+
+/* Holds the fd for the flash file */
+int cyg_dev_flash_synth_flashfd;
+
+/* Holds the base address of the mmap'd region */
+flash_t *cyg_dev_flash_synth_base;
+
+int
+flash_hwr_init(void)
+{
+ flash_info.block_size = CYGNUM_FLASH_SYNTH_BLOCKSIZE;
+ flash_info.buffer_size = 0;
+ flash_info.blocks = CYGNUM_FLASH_SYNTH_NUMBLOCKS;
+
+ cyg_dev_flash_synth_flashfd = cyg_hal_sys_open(CYGDAT_FLASH_SYNTH_FILENAME,
+ CYG_HAL_SYS_O_RDWR,
+ CYG_HAL_SYS_S_IRWXU|CYG_HAL_SYS_S_IRWXG|CYG_HAL_SYS_S_IRWXO);
+ if (cyg_dev_flash_synth_flashfd == -ENOENT) {
+ long w, bytesleft;
+ char buf[128];
+
+ cyg_dev_flash_synth_flashfd = cyg_hal_sys_open(
+ CYGDAT_FLASH_SYNTH_FILENAME,
+ CYG_HAL_SYS_O_RDWR|CYG_HAL_SYS_O_CREAT,
+ CYG_HAL_SYS_S_IRWXU|CYG_HAL_SYS_S_IRWXG|CYG_HAL_SYS_S_IRWXO);
+ CYG_ASSERT( cyg_dev_flash_synth_flashfd >= 0,
+ "Opening of the file for the synth flash failed!");
+ // fill with 0xff
+ memset( buf, 0xff, sizeof(buf) );
+ bytesleft = CYGNUM_FLASH_SYNTH_BLOCKSIZE * CYGNUM_FLASH_SYNTH_NUMBLOCKS;
+ while (bytesleft > 0)
+ {
+ int bytesneeded;
+ bytesneeded = bytesleft < sizeof(buf) ? bytesleft : sizeof(buf);
+
+ w = cyg_hal_sys_write( cyg_dev_flash_synth_flashfd, buf,
+ bytesneeded );
+ CYG_ASSERT(w == bytesneeded, "initialization of flash file failed");
+ bytesleft -= bytesneeded;
+ } // while
+ }
+ CYG_ASSERT( cyg_dev_flash_synth_flashfd >= 0,
+ "Opening of the file for the synth flash failed!");
+ if ( cyg_dev_flash_synth_flashfd <= 0 ) {
+ return FLASH_ERR_HWR;
+ }
+ cyg_dev_flash_synth_base = (flash_t *)cyg_hal_sys_mmap(
+#ifdef CYGMEM_FLASH_SYNTH_BASE
+ (void *)CYGMEM_FLASH_SYNTH_BASE,
+#else
+ NULL,
+#endif
+ (CYGNUM_FLASH_SYNTH_BLOCKSIZE * CYGNUM_FLASH_SYNTH_NUMBLOCKS),
+ CYG_HAL_SYS_PROT_READ,
+#ifdef CYGSEM_FLASH_SYNTH_FILE_WRITEBACK
+ CYG_HAL_SYS_MAP_SHARED
+#else
+ CYG_HAL_SYS_MAP_PRIVATE
+#endif
+#ifdef CYGMEM_FLASH_SYNTH_BASE
+ |CYG_HAL_SYS_MAP_FIXED
+#endif
+ , cyg_dev_flash_synth_flashfd, 0 );
+ CYG_ASSERT( cyg_dev_flash_synth_base != (void *) -1, "mmap of flash file failed!" );
+
+ if (cyg_dev_flash_synth_base == (void *) -1) {
+ return FLASH_ERR_HWR;
+ }
+ flash_info.start = cyg_dev_flash_synth_base;
+ flash_info.end = (void *)(((char *)cyg_dev_flash_synth_base) -1 +
+ (CYGNUM_FLASH_SYNTH_BLOCKSIZE * CYGNUM_FLASH_SYNTH_NUMBLOCKS));
+
+ return FLASH_ERR_OK;
+}
+
+// Map a hardware status to a package error
+int
+flash_hwr_map_error(int err)
+{
+ return err;
+}
+
+// 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 synth.c
diff --git a/ecos/packages/devs/flash/synth/current/src/synth.h b/ecos/packages/devs/flash/synth/current/src/synth.h
new file mode 100644
index 0000000..3f9993b
--- /dev/null
+++ b/ecos/packages/devs/flash/synth/current/src/synth.h
@@ -0,0 +1,63 @@
+#ifndef CYGONCE_DEVS_FLASH_SYNTH_SYNTH_H
+#define CYGONCE_DEVS_FLASH_SYNTH_SYNTH_H
+//==========================================================================
+//
+// synth.h
+//
+// synth 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): andrew.lunn@ascom.ch
+// Contributors: andrew.lunn
+// Date: 2001-10-30
+// Purpose:
+// Description:
+//
+//####DESCRIPTIONEND####
+//
+//==========================================================================
+
+#include <pkgconf/system.h>
+#include <cyg/infra/cyg_type.h>
+
+typedef unsigned long flash_t;
+__externC int cyg_dev_flash_synth_flashfd;
+__externC flash_t *cyg_dev_flash_synth_base;
+
+#endif // CYGONCE_DEVS_FLASH_SYNTH_SYNTH_H
+// ------------------------------------------------------------------------
+// EOF synth.h
diff --git a/ecos/packages/devs/flash/synth/current/tests/flash1.c b/ecos/packages/devs/flash/synth/current/tests/flash1.c
new file mode 100644
index 0000000..779e6c8
--- /dev/null
+++ b/ecos/packages/devs/flash/synth/current/tests/flash1.c
@@ -0,0 +1,190 @@
+/* Hey, the copyright is useful for something! */
+
+static char copyright[] =
+"//=========================================================================="
+"//"
+"// flash1.c"
+"//"
+"// Test flash operations for the synth target synth flash driver"
+"//"
+"//=========================================================================="
+"// ####ECOSGPLCOPYRIGHTBEGIN#### "
+"// ------------------------------------------- "
+"// This file is part of eCos, the Embedded Configurable Operating System. "
+"// Copyright (C) 1998, 1999, 2000, 2001, 2002 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): andrew.lunn@ascom.ch"
+"// Contributors: andrew.lunn"
+"// Date: 2000-10-31"
+"// Purpose: Test a flash driver"
+"// Description: Try out a number of flash operations and make sure"
+"// what is in the flash is what we expeect."
+"// "
+"//####DESCRIPTIONEND####"
+"//"
+"//=========================================================================="
+;
+
+#include <cyg/io/flash.h>
+#include <cyg/infra/testcase.h>
+#include <cyg/infra/diag.h>
+
+#include <string.h>
+
+#ifndef CYGINT_ISO_STRING_STRFUNCS
+# define NA_MSG "Need string functions for test"
+#endif
+#ifndef CYGSEM_IO_FLASH_LEGACY_API
+# define NA_MSG "Need legacy IO FLASH API for test"
+#endif
+
+#ifdef NA_MSG
+void cyg_user_start(void)
+{
+ CYG_TEST_INIT();
+ CYG_TEST_NA( NA_MSG );
+}
+#else
+
+//==========================================================================
+// main
+
+void cyg_user_start(void)
+{
+ int ret;
+ char data[1024];
+ void *flash_start, *flash_end;
+ int block_size, blocks;
+ char *prog_start;
+ unsigned char * ptr;
+
+ CYG_TEST_INIT();
+
+ ret=flash_init((_printf *)diag_printf);
+
+ CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_init");
+
+ flash_dev_query(data);
+ CYG_TEST_PASS_FAIL(!strncmp(data,"Linux Synthetic Flash",sizeof(data)),
+ "flash_query");
+
+ ret = flash_get_limits(NULL,&flash_start,&flash_end);
+ CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_get_limits");
+
+ ret = flash_get_block_info(&block_size, &blocks);
+ CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_get_block_info");
+
+ /* Erase the whole flash. Not recommended on real hardware since this
+ will probably erase the bootloader etc!!! */
+ ret=flash_erase(flash_start,block_size * blocks,NULL);
+ CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_erase1");
+
+ /* check that its actually been erased, and test the mmap area */
+ for (ptr=flash_start,ret=0; ptr < (unsigned char *)flash_end; ptr++) {
+ if (*ptr != 0xff) {
+ ret++;
+ }
+ }
+
+ CYG_TEST_PASS_FAIL((ret == 0),"flash empty check");
+
+ ret = flash_program(flash_start,&copyright,sizeof(copyright),NULL);
+ CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_program1");
+
+ /* Check the contents made it into the flash */
+ CYG_TEST_PASS_FAIL(!strncmp(flash_start,copyright,sizeof(copyright)),
+ "flash program contents");
+
+ /* .. and check nothing else changed */
+ for (ptr=(unsigned char *)flash_start+sizeof(copyright),ret=0;
+ ptr < (unsigned char *)flash_end; ptr++) {
+ if (*ptr != 0xff) {
+ ret++;
+ }
+ }
+
+ CYG_TEST_PASS_FAIL((ret == 0),"flash program overrun check");
+
+ /* Program over a block boundary */
+ prog_start = (char *)flash_start + block_size - sizeof(copyright)/2;
+ ret = flash_program(prog_start,&copyright,sizeof(copyright),NULL);
+ CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_program2");
+
+ /* Check the first version is still OK */
+ CYG_TEST_PASS_FAIL(!strncmp(flash_start,copyright,sizeof(copyright)),
+ "Original contents");
+
+ CYG_TEST_PASS_FAIL(!strncmp(prog_start,copyright,sizeof(copyright)),
+ "New program contents");
+
+ /* Check the bit in between is still erased */
+ for (ptr=(unsigned char *)flash_start+sizeof(copyright),ret=0;
+ ptr < (unsigned char *)prog_start; ptr++) {
+ if (*ptr != 0xff) {
+ ret++;
+ }
+ }
+ CYG_TEST_PASS_FAIL((ret == 0),"flash erase check1");
+
+ /* Erase the second block and make sure the first is not erased */
+ ret=flash_erase((void *)((unsigned)flash_start+block_size),
+ block_size,NULL);
+ CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_erase2");
+
+ /* Check the erase worked */
+ for (ptr=(unsigned char *)flash_start+block_size,ret=0;
+ ptr < (unsigned char *)flash_start+block_size*2; ptr++) {
+ if (*ptr != 0xff) {
+ ret++;
+ }
+ }
+
+ CYG_TEST_PASS_FAIL((ret == 0), "flash erase check2");
+
+ /* Lastly check the first half of the copyright message is still there */
+ CYG_TEST_PASS_FAIL(!strncmp(prog_start,copyright,sizeof(copyright)/2),
+ "Block 1 OK");
+
+#if 0
+ /* This test it fatal! Its not run by default!
+ Check the flash is read only, by trying to write to it. We expect
+ to get an exception */
+
+ *(char *)flash_start = 'a';
+#endif
+
+ CYG_TEST_PASS_FINISH("flash1");
+}
+
+#endif /* ifndef NA_MSG */
+
+/* EOF flash1.c */
diff --git a/ecos/packages/devs/flash/synth/current/tests/flash2.c b/ecos/packages/devs/flash/synth/current/tests/flash2.c
new file mode 100644
index 0000000..21681ba
--- /dev/null
+++ b/ecos/packages/devs/flash/synth/current/tests/flash2.c
@@ -0,0 +1,209 @@
+/* Hey, the copyright is useful for something! */
+
+static char copyright[] =
+"//=========================================================================="
+"//"
+"// flash1.c"
+"//"
+"// Test flash operations for the synth target synth flash driver"
+"//"
+"//=========================================================================="
+"// ####ECOSGPLCOPYRIGHTBEGIN#### "
+"// ------------------------------------------- "
+"// This file is part of eCos, the Embedded Configurable Operating System. "
+"// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2009 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): andrew.lunn@ascom.ch"
+"// Contributors: andrew.lunn"
+"// Date: 2000-10-31"
+"// Purpose: Test a flash driver"
+"// Description: Try out a number of flash operations and make sure"
+"// what is in the flash is what we expeect."
+"// "
+"//####DESCRIPTIONEND####"
+"//"
+"//==========================================================================&"
+;
+
+#include <pkgconf/devs_flash_synth.h>
+#include <cyg/io/flash.h>
+#include <cyg/infra/testcase.h>
+#include <cyg/infra/diag.h>
+
+#include <string.h>
+
+#ifndef CYGINT_ISO_STRING_STRFUNCS
+# define NA_MSG "Need string functions for test"
+#endif
+
+#ifdef NA_MSG
+void cyg_user_start(void)
+{
+ CYG_TEST_INIT();
+ CYG_TEST_NA( NA_MSG );
+}
+#else
+
+//==========================================================================
+// main
+
+void cyg_user_start(void)
+{
+ int ret;
+ cyg_flashaddr_t flash_start=0, flash_end=0;
+ cyg_flash_info_t info;
+ int block_size=0, blocks=0;
+ cyg_flashaddr_t prog_start;
+ unsigned char * ptr;
+ cyg_uint32 i=0;
+ cyg_uint32 j;
+
+ CYG_TEST_INIT();
+
+ cyg_flash_set_global_printf((cyg_flash_printf *)&diag_printf);
+ ret=cyg_flash_init(NULL);
+
+ CYG_TEST_PASS_FAIL((ret == CYG_FLASH_ERR_OK),"flash_init");
+
+ do {
+ ret = cyg_flash_get_info(i, &info);
+ if (ret == CYG_FLASH_ERR_OK) {
+ diag_printf("INFO: Nth=%d, start=%p, end=%p\n",
+ i, (void *) info.start, (void *) info.end);
+ if (i == 0) {
+ flash_start = info.start;
+ flash_end = info.end;
+ block_size = info.block_info[0].block_size;
+ blocks = info.block_info[0].blocks;
+ }
+ for (j=0;j < info.num_block_infos; j++) {
+ diag_printf("INFO:\t block_size %zd, blocks %u\n",
+ info.block_info[j].block_size,
+ info.block_info[j].blocks);
+ }
+ }
+ i++;
+ } while (ret != CYG_FLASH_ERR_INVALID);
+
+ /* Erase the whole flash. Not recommended on real hardware since this
+ will probably erase the bootloader etc!!! */
+ ret=cyg_flash_erase(flash_start,block_size * blocks,NULL);
+ CYG_TEST_PASS_FAIL((ret == CYG_FLASH_ERR_OK),"flash_erase1");
+
+ /* check that its actually been erased, and test the mmap area */
+ for (ptr=(unsigned char *)flash_start,ret=0;
+ ptr <= (unsigned char *)flash_end; ptr++) {
+ if (*ptr != 0xff) {
+ ret++;
+ }
+ }
+
+ CYG_TEST_PASS_FAIL((ret == 0),"flash empty check");
+
+ ret = cyg_flash_program(flash_start,&copyright,sizeof(copyright),NULL);
+ CYG_TEST_PASS_FAIL((ret == CYG_FLASH_ERR_OK),"flash_program1");
+
+ /* Check the contents made it into the flash */
+ CYG_TEST_PASS_FAIL(!strncmp((void *)flash_start,
+ copyright,sizeof(copyright)),
+ "flash program contents");
+
+ /* .. and check nothing else changed */
+ for (ptr=(unsigned char *)flash_start+sizeof(copyright),ret=0;
+ ptr < (unsigned char *)flash_end; ptr++) {
+ if (*ptr != 0xff) {
+ ret++;
+ }
+ }
+
+ CYG_TEST_PASS_FAIL((ret == 0),"flash program overrun check");
+
+ /* Program over a block boundary */
+ prog_start = flash_start + block_size - sizeof(copyright)/2;
+ ret = cyg_flash_program(prog_start,&copyright,sizeof(copyright),NULL);
+ CYG_TEST_PASS_FAIL((ret == CYG_FLASH_ERR_OK),"flash_program2");
+
+ /* Check the first version is still OK */
+ CYG_TEST_PASS_FAIL(!strncmp((void *)flash_start,
+ copyright,
+ sizeof(copyright)),
+ "Original contents");
+
+ CYG_TEST_PASS_FAIL(!strncmp((void *)prog_start,
+ copyright,
+ sizeof(copyright)),
+ "New program contents");
+
+ /* Check the bit in between is still erased */
+ for (ptr=(unsigned char *)flash_start+sizeof(copyright),ret=0;
+ ptr < (unsigned char *)prog_start; ptr++) {
+ if (*ptr != 0xff) {
+ ret++;
+ }
+ }
+ CYG_TEST_PASS_FAIL((ret == 0),"flash erase check1");
+
+ /* Erase the second block and make sure the first is not erased */
+ ret=cyg_flash_erase(flash_start+block_size,block_size,NULL);
+ CYG_TEST_PASS_FAIL((ret == CYG_FLASH_ERR_OK),"flash_erase2");
+
+ /* Check the erase worked */
+ for (ptr=(unsigned char *)flash_start+block_size,ret=0;
+ ptr < (unsigned char *)flash_start+block_size*2;
+ ptr++) {
+ if (*ptr != 0xff) {
+ ret++;
+ }
+ }
+
+ CYG_TEST_PASS_FAIL((ret == 0), "flash erase check2");
+
+ /* Lastly check the first half of the copyright message is still there */
+ CYG_TEST_PASS_FAIL(!strncmp((void *)prog_start,
+ copyright,
+ sizeof(copyright)/2),
+ "Block 1 OK");
+
+#if 0
+ /* This test is be fatal! Its not run by default!
+ Check the flash is read only, by trying to write to it. We expect
+ to get an exception */
+
+ *(char *)flash_start = 'a';
+#endif
+
+ CYG_TEST_PASS_FINISH("flash1");
+}
+
+#endif /* ifndef NA_MSG */
+
+/* EOF flash2.c */