This is the mail archive of the
ecos-patches@sourceware.org
mailing list for the eCos project.
flashv2 tweaks
- From: Jonathan Larmour <jifl at eCosCentric dot com>
- To: eCos Patches List <ecos-patches at ecos dot sourceware dot org>
- Date: Wed, 27 Sep 2006 15:23:47 +0100
- Subject: flashv2 tweaks
Another chunk to bring some eCosCentric changes in, this time to io/flash
in the flashv2 branch. While it's not all our changes by a long way, it
reduces some otherwise important divergence. Since the flashv2 branch isn't
mainstream, I think it's ok to just put the ChangeLogs in at the time the
changes were truly written, and reflects the copyright dates.
Jifl
--
eCosCentric http://www.eCosCentric.com/ The eCos and RedBoot experts
------["The best things in life aren't things."]------ Opinions==mine
Index: ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/io/flash/current/ChangeLog,v
retrieving revision 1.38.2.26
diff -u -5 -p -r1.38.2.26 ChangeLog
--- ChangeLog 22 Feb 2005 23:21:13 -0000 1.38.2.26
+++ ChangeLog 27 Sep 2006 14:20:15 -0000
@@ -6,10 +6,13 @@
(legacy_flash_program): The last argument to flash_program_buf()
is not the block size but the programming buffer size.
2005-01-19 Jonathan Larmour <jifl@eCosCentric.com>
+ * src/flash_legacy.h: Undef HAL_FLASH_CACHES_* macros if the HAL
+ supplied them and they're not needed.
+
* src/legacy_api.c (flash_errmsg): Was missing. Add.
2004-12-02 Bart Veer <bartv@ecoscentric.com>
* include/flash_dev.h: now provides everything needed by flash
@@ -44,10 +47,16 @@
failed to initialise onto the list. Don't bother sorting the
list if its empty or only has one entry.
* src/flash.c (find_dev): All devices on the list are initialised so
don't both checking the init flag.
+2004-11-24 Bart Veer <bartv@ecoscentric.com>
+
+ * cdl/io_flash.cdl, src/flash.c, src/flash_legacy.h,
+ src/legacy_dev.c: add support for V2 drivers which can take care
+ of the cache and interrupts themselves.
+
2004-11-22 Bart Veer <bartv@ecoscentric.com>
* src/legacy_dev.c: remove .2ram attributes. These functions do
not manipulate the hardware, there is no need for them to live in
ram rather than flash
@@ -457,10 +466,11 @@
//===========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
+// Copyright (C) 2005, 2006 eCosCentric Limited
//
// 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.
//
@@ -480,11 +490,8 @@
// 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####
//===========================================================================
Index: cdl/io_flash.cdl
===================================================================
RCS file: /cvs/ecos/ecos/packages/io/flash/current/cdl/io_flash.cdl,v
retrieving revision 1.17.2.4
diff -u -5 -p -r1.17.2.4 io_flash.cdl
--- cdl/io_flash.cdl 21 Nov 2004 23:39:01 -0000 1.17.2.4
+++ cdl/io_flash.cdl 27 Sep 2006 14:20:15 -0000
@@ -6,11 +6,11 @@
#
# ====================================================================
#####ECOSGPLCOPYRIGHTBEGIN####
## -------------------------------------------
## This file is part of eCos, the Embedded Configurable Operating System.
-## Copyright (C) 2004 eCosCentric Ltd
+## Copyright (C) 2004, 2006 eCosCentric Ltd
## Copyright (C) 2004 Andrew Lunn
## Copyright (C) 2003 Gary Thomas
## Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
##
## eCos is free software; you can redistribute it and/or modify it under
@@ -92,19 +92,35 @@ cdl_package CYGPKG_IO_FLASH {
involves extra code. If none of the flash devices on the
target hardware use indirect reads then the extra code
can be eliminated."
}
+ cdl_interface CYGHWR_IO_FLASH_DEVICE_NEEDS_CACHE_HANDLED {
+ display "Device driver needs cache handled centrally"
+ flavor booldata
+ description "
+ Managing flash often requires interacting with the flash.
+ Some device drivers do not require the generic flash code to
+ manipulate the flash, either because they do it themselves or
+ because the hardware does the right thing. Other drivers
+ require the generic code to disable/enable the flash before
+ calling into the driver."
+ }
+
cdl_interface CYGHWR_IO_FLASH_DEVICE_LEGACY {
display "Hardware driver uses the legacy interface"
flavor booldata
compile -library=libextras.a legacy_dev.c
description "
The generic flash code can work with either a legacy device
driver or with V2 drivers. If a legacy driver is used on the
current platform then this option will be implemented."
requires { CYGHWR_IO_FLASH_DEVICE_LEGACY <= 1 }
+
+ # For now assume all legacy devices need the cache handled by
+ # the central code
+ implements CYGHWR_IO_FLASH_DEVICE_NEEDS_CACHE_HANDLED
}
cdl_option CYGSEM_IO_FLASH_READ_INDIRECT {
display "Legacy device driver uses indirect reads."
active_if CYGHWR_IO_FLASH_DEVICE_LEGACY
Index: src/flash.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/io/flash/current/src/flash.c,v
retrieving revision 1.26.2.18
diff -u -5 -p -r1.26.2.18 flash.c
--- src/flash.c 22 Feb 2005 21:03:43 -0000 1.26.2.18
+++ src/flash.c 27 Sep 2006 14:20:15 -0000
@@ -7,11 +7,11 @@
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 2004 Andrew Lunn
-// Copyright (C) 2004 eCosCentric Ltd.
+// Copyright (C) 2004, 2005, 2006 eCosCentric Ltd.
// Copyright (C) 2003 Gary Thomas
// 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
@@ -160,12 +160,12 @@ static bool flash_sort_and_check(void)
dev->next = flash_head;
flash_head = dev;
}
}
- // If there are no devices, abort. This could happen because none
- // of the devices initialised.
+ // If there are no valid devices, abort. This might happen if
+ // all drivers failed to initialize.
if (flash_head == NULL) {
return false;
}
// Sort the linked list into ascending order of flash address. Use a
@@ -291,11 +291,11 @@ cyg_flash_verify_addr(const cyg_flashadd
// Return information about the Nth driver
__externC int
cyg_flash_get_info(cyg_uint32 Nth, cyg_flash_info_t * info)
{
struct cyg_flash_dev * dev;
-
+
if (!init) return CYG_FLASH_ERR_NOT_INIT;
#if (1 == CYGHWR_IO_FLASH_DEVICE)
if ((0 == Nth) && cyg_flashdevtab[0].init) {
dev = &(cyg_flashdevtab[0]);
@@ -437,11 +437,11 @@ cyg_flash_erase(cyg_flashaddr_t flash_ba
{
cyg_flashaddr_t block, end_addr;
struct cyg_flash_dev * dev;
size_t erase_count;
int stat = CYG_FLASH_ERR_OK;
- int d_cache, i_cache;
+ HAL_FLASH_CACHES_STATE(d_cache, i_cache);
dev = find_dev(flash_base, &stat);
if (!dev) return stat;
CHECK_SOFT_WRITE_PROTECT(flash_base, len);
@@ -527,11 +527,11 @@ cyg_flash_program(cyg_flashaddr_t flash_
struct cyg_flash_dev * dev;
cyg_flashaddr_t addr, end_addr, block;
const unsigned char * ram = ram_base;
size_t write_count, offset;
int stat = CYG_FLASH_ERR_OK;
- int d_cache, i_cache;
+ HAL_FLASH_CACHES_STATE(d_cache, i_cache);
dev = find_dev(flash_base, &stat);
if (!dev) return stat;
CHECK_SOFT_WRITE_PROTECT(flash_base, len);
@@ -641,13 +641,13 @@ cyg_flash_read(const cyg_flashaddr_t fla
}
#else
// We have to indirect through the device driver.
// The first read may be in the middle of a block. Do the necessary
// adjustment here rather than inside the loop.
- int d_cache, i_cache;
size_t offset;
cyg_flashaddr_t block = flash_block_begin(flash_base, dev);
+ HAL_FLASH_CACHES_STATE(d_cache, i_cache);
if (addr == block) {
offset = 0;
} else {
offset = addr - block;
}
@@ -699,11 +699,11 @@ cyg_flash_lock(const cyg_flashaddr_t fla
{
cyg_flashaddr_t block, end_addr;
struct cyg_flash_dev * dev;
size_t lock_count;
int stat = CYG_FLASH_ERR_OK;
- int d_cache, i_cache;
+ HAL_FLASH_CACHES_STATE(d_cache, i_cache);
dev = find_dev(flash_base, &stat);
if (!dev) return stat;
if (!dev->funs->flash_block_lock) return CYG_FLASH_ERR_INVALID;
@@ -762,11 +762,11 @@ cyg_flash_unlock(const cyg_flashaddr_t f
{
cyg_flashaddr_t block, end_addr;
struct cyg_flash_dev * dev;
size_t unlock_count;
int stat = CYG_FLASH_ERR_OK;
- int d_cache, i_cache;
+ HAL_FLASH_CACHES_STATE(d_cache, i_cache);
dev = find_dev(flash_base, &stat);
if (!dev) return stat;
if (!dev->funs->flash_block_unlock) return CYG_FLASH_ERR_INVALID;
Index: src/flash_legacy.h
===================================================================
RCS file: /cvs/ecos/ecos/packages/io/flash/current/src/Attic/flash_legacy.h,v
retrieving revision 1.1.2.1
diff -u -5 -p -r1.1.2.1 flash_legacy.h
--- src/flash_legacy.h 22 Nov 2004 13:25:23 -0000 1.1.2.1
+++ src/flash_legacy.h 27 Sep 2006 14:20:15 -0000
@@ -9,10 +9,11 @@
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// copyright (C) 2004 Andrew Lunn
// Copyright (C) 2003 Gary Thomas
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
+// Copyright (C) 2004 eCosCentric Limited
//
// 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.
//
@@ -81,10 +82,21 @@ extern void CYGIMP_FLASH_DISABLE(void *,
#ifdef CYGSEM_IO_FLASH_SOFT_WRITE_PROTECT
externC cyg_bool plf_flash_query_soft_wp(void *addr, int len);
#endif
//---------------------------------------------------------------------------
+// If all of the flash devices handle cache themselves, or do not need any
+// special cache treatment, then the flash macros can be no-ops.
+#ifndef CYGHWR_IO_FLASH_DEVICE_NEEDS_CACHE_HANDLED
+# undef HAL_FLASH_CACHES_OFF
+# undef HAL_FLASH_CACHES_ON
+# undef HAL_FLASH_CACHES_STATE
+# define HAL_FLASH_CACHES_OFF(_d_, _i_) CYG_EMPTY_STATEMENT
+# define HAL_FLASH_CACHES_ON(_d_, _i_) CYG_EMPTY_STATEMENT
+# define HAL_FLASH_CACHES_STATE(_d_, _i_) CYG_EMPTY_STATEMENT
+#endif
+
// Execution of flash code must be done inside a
// HAL_FLASH_CACHES_OFF/HAL_FLASH_CACHES_ON region - disabling the
// cache on unified cache systems is necessary to prevent burst access
// to the flash area being programmed. With Harvard style caches, only
// the data cache needs to be disabled, but the instruction cache is
@@ -166,5 +178,9 @@ externC cyg_bool plf_flash_query_soft_wp
HAL_ICACHE_ENABLE();
#endif // HAL_FLASH_CACHES_OLD_MACROS
#endif // HAL_FLASH_CACHES_OFF
+
+#ifndef HAL_FLASH_CACHES_STATE
+# define HAL_FLASH_CACHES_STATE(_d_, _i_) int _d_, _i_
+#endif
Index: src/legacy_dev.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/io/flash/current/src/Attic/legacy_dev.c,v
retrieving revision 1.1.2.13
diff -u -5 -p -r1.1.2.13 legacy_dev.c
--- src/legacy_dev.c 22 Feb 2005 23:21:12 -0000 1.1.2.13
+++ src/legacy_dev.c 27 Sep 2006 14:20:15 -0000
@@ -7,10 +7,11 @@
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 2004 Andrew Lunn
+// Copyright (C) 2004 eCosCentric Limited
//
// 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.
//
@@ -139,11 +140,11 @@ legacy_flash_program(struct cyg_flash_de
cyg_flashaddr_t base,
const void* data, size_t len)
{
typedef int code_fun(cyg_flashaddr_t, const void *, int, unsigned long, int);
code_fun *_flash_program_buf;
- size_t block_mask = ~(block_mask -1);
+ size_t block_mask = ~(block_size -1);
int stat;
_flash_program_buf = (code_fun*) cyg_flash_anonymizer(&flash_program_buf);
stat = (*_flash_program_buf)(base, data, len, block_mask, flash_info.buffer_size);
@@ -157,11 +158,11 @@ legacy_flash_read (struct cyg_flash_dev
void* data, size_t len)
{
typedef int code_fun(const cyg_flashaddr_t, void *, int, unsigned long, int);
code_fun *_flash_read_buf;
size_t block_size = dev->block_info[0].block_size;
- size_t block_mask = ~(block_mask -1);
+ size_t block_mask = ~(block_size -1);
int stat;
_flash_read_buf = (code_fun*) cyg_flash_anonymizer(&flash_read_buf);
stat = (*_flash_read_buf)(base, data, len, block_mask, block_size);
return flash_hwr_map_error(stat);
@@ -206,11 +207,11 @@ legacy_flash_block_unlock (struct cyg_fl
void
flash_dev_query(void* data)
{
typedef void code_fun(void*);
code_fun *_flash_query;
- int d_cache, i_cache;
+ HAL_FLASH_CACHES_STATE(d_cache, i_cache);
_flash_query = (code_fun*) cyg_flash_anonymizer(&flash_query);
HAL_FLASH_CACHES_OFF(d_cache, i_cache);
(*_flash_query)(data);