* [ECOS] Problem found with flash driver
@ 2006-03-02 10:47 Retallack, Mark
0 siblings, 0 replies; 3+ messages in thread
From: Retallack, Mark @ 2006-03-02 10:47 UTC (permalink / raw)
To: ecos-discuss
Hello everyone, I think I have found a minor problem with the io layer
of the flash driver and before I continue with my fix, I just thought
that I would ask if anyone else has seen it.
I am using JFFS2 over a flash bank that I am not running code from, so
interrupts can be enabled during flash access. The processor is an
MPC850.
With the virgin eCos flash.c code (from CVS), the system crashes with a
random memory corruption, I have tracked it down to a context switch
within the flash_program function in flash.c. After looking through the
file and the eCos mailing list I found that the HAL_FLASH_CACHES_OFF
define states that interrupts must be disabled.
After modding the code to disable interrupts before flushing and
disabling the cache, the system works correctly with no problems.
I have not created a patch because the HAL_FLASH_CACHES_OFF define in
flash.h looks very generic and I cannot test the mod. But this is what I
have done:
// Note: the ucache code has not been tested yet on any target.
#define HAL_FLASH_CACHES_OFF(_d_, _i_) \
CYG_MACRO_START \
_i_ = 0; /* avoids warning */ \
unsigned long __state; \
HAL_DISABLE_INTERRUPTS(__state); \
HAL_UCACHE_IS_ENABLED(_d_); \
HAL_UCACHE_SYNC(); \
HAL_UCACHE_INVALIDATE_ALL(); \
HAL_UCACHE_DISABLE(); \
HAL_RESTORE_INTERRUPTS(__state); \
CYG_MACRO_END
#define HAL_FLASH_CACHES_ON(_d_, _i_) \
CYG_MACRO_START \
unsigned long __state; \
HAL_DISABLE_INTERRUPTS(__state); \
if (_d_) HAL_UCACHE_ENABLE(); \
HAL_RESTORE_INTERRUPTS(__state); \
CYG_MACRO_END
#else // HAL_CACHE_UNIFIED
#define HAL_FLASH_CACHES_OFF(_d_, _i_) \
CYG_MACRO_START \
_i_ = 0; /* avoids warning */ \
unsigned long __state; \
HAL_DISABLE_INTERRUPTS(__state); \
HAL_DCACHE_IS_ENABLED(_d_); \
HAL_DCACHE_SYNC(); \
HAL_DCACHE_INVALIDATE_ALL(); \
HAL_DCACHE_DISABLE(); \
HAL_ICACHE_INVALIDATE_ALL(); \
HAL_RESTORE_INTERRUPTS(__state); \
CYG_MACRO_END
#define HAL_FLASH_CACHES_ON(_d_, _i_) \
CYG_MACRO_START \
unsigned long __state; \
HAL_DISABLE_INTERRUPTS(__state); \
if (_d_) HAL_DCACHE_ENABLE(); \
HAL_RESTORE_INTERRUPTS(__state); \
CYG_MACRO_END
I know that someone else has already pointed out this potential problem,
but no fix was added, this makes me worry because I cannot be the only
persion who is using the jffs2 system on a powerpc 850, and this is a
very easy problem to reproduce.
Mark Retallack
Embedded Software Engineer
Siemens Traffic Controls
Sopers Lane, Poole, Dorset. BH17 7ER. UK.
Tel: 01202 782189
Fax: 01202 782545
www.siemenstraffic.com
Committed to quality traffic solutions and service excellence
Todays Quote:
I want the presidency so bad I can already taste the hors d'oeuvres.
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: [ECOS] Problem found with flash driver
@ 2006-03-02 16:43 Retallack, Mark
0 siblings, 0 replies; 3+ messages in thread
From: Retallack, Mark @ 2006-03-02 16:43 UTC (permalink / raw)
To: Neundorf, Alexander; +Cc: ecos-discuss
[-- Attachment #1: Type: text/plain, Size: 2188 bytes --]
After reading the flash.h file in more detail, it suggests placing
platform stuff in the correct file and not modifying the flash.h file. I
don't think this is a problem on all platforms so it does not make sence
to do a generic interrupt disable, so I have added it to the
mpc8xx/current/include/var_cache.h file instead. I placed it here and
not in the hal_cache.h because I don't know if it is a PowerPC issue or
just an MPC8xx issue.
I have attached the patch.
-----Original Message-----
From: Neundorf, Alexander [mailto:Alexander.Neundorf@jenoptik.com]
Sent: 02 March 2006 11:08
To: Retallack, Mark; ecos-discuss@ecos.sourceware.org
Subject: AW: [ECOS] Problem found with flash driver
Hi,
> Von: ecos-discuss-owner@ecos.sourceware.org
>
> Hello everyone, I think I have found a minor problem with the io layer
> of the flash driver and before I continue with my fix, I just thought
> that I would ask if anyone else has seen it.
>
> I am using JFFS2 over a flash bank that I am not running code from, so
> interrupts can be enabled during flash access. The processor is an
> MPC850.
>
> With the virgin eCos flash.c code (from CVS), the system
> crashes with a
> random memory corruption, I have tracked it down to a context switch
> within the flash_program function in flash.c. After looking
> through the
> file and the eCos mailing list I found that the HAL_FLASH_CACHES_OFF
> define states that interrupts must be disabled.
I had also crashes when interrupts occured during flash_program(). But
since we don't write often on the flash, I simply disabled interrupts
when calling flash_program(). This is not optimal, but was good enough
for our purpose.
> After modding the code to disable interrupts before flushing and
> disabling the cache, the system works correctly with no problems.
Sounds good :-)
There is also a different flash branch, maybe this is fixed there, I
don't know.
> I have not created a patch because the HAL_FLASH_CACHES_OFF define in
> flash.h looks very generic and I cannot test the mod. But this is what
> I have done:
Can you please send it as a patch ?
Bye
Alex
[-- Attachment #2: cache.patch --]
[-- Type: application/octet-stream, Size: 1831 bytes --]
diff -r -u5 -N -x CVS -x '*~' -x '.#*' clean/ecos/packages/hal/powerpc/mpc8xx/current/include/var_cache.h devo/ecos/packages/hal/powerpc/mpc8xx/current/include/var_cache.h
--- clean/ecos/packages/hal/powerpc/mpc8xx/current/include/var_cache.h 2006-03-02 15:02:45.180068800 +0000
+++ devo/ecos/packages/hal/powerpc/mpc8xx/current/include/var_cache.h 2006-03-02 15:02:08.176860800 +0000
@@ -427,7 +427,33 @@
// Invalidate cache lines in the given range without writing to memory.
//#define HAL_ICACHE_INVALIDATE( _base_ , _size_ )
//-----------------------------------------------------------------------------
+// This is used by the flash driver, we need a version that
+// disables the interrupts so that it cannot get interrupted
+
+#define HAL_FLASH_CACHES_OFF(_d_, _i_) \
+ CYG_MACRO_START \
+ _i_ = 0; /* avoids warning */ \
+ unsigned long __state; \
+ HAL_DISABLE_INTERRUPTS(__state); \
+ HAL_DCACHE_IS_ENABLED(_d_); \
+ HAL_DCACHE_SYNC(); \
+ HAL_DCACHE_INVALIDATE_ALL(); \
+ HAL_DCACHE_DISABLE(); \
+ HAL_ICACHE_INVALIDATE_ALL(); \
+ HAL_RESTORE_INTERRUPTS(__state); \
+ CYG_MACRO_END
+
+#define HAL_FLASH_CACHES_ON(_d_, _i_) \
+ CYG_MACRO_START \
+ unsigned long __state; \
+ HAL_DISABLE_INTERRUPTS(__state); \
+ if (_d_) HAL_DCACHE_ENABLE(); \
+ HAL_RESTORE_INTERRUPTS(__state); \
+ CYG_MACRO_END
+
+
+//-----------------------------------------------------------------------------
#endif // ifndef CYGONCE_VAR_CACHE_H
// End of var_cache.h
[-- Attachment #3: Type: text/plain, Size: 148 bytes --]
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: [ECOS] Problem found with flash driver
@ 2006-03-02 16:36 Jay Foster
0 siblings, 0 replies; 3+ messages in thread
From: Jay Foster @ 2006-03-02 16:36 UTC (permalink / raw)
To: 'Retallack, Mark', ecos-discuss
I ran into a similar problem with the Samsung S3C45xx HAL. However, I fixed
it by defining my own HAL_FLASH_CACHES_OFF(), HAL_FLASH_CACHES_ON() macros
in my platform HAL, which overrides that defined in flash.h.
The problem I had was that the HAL_FLASH_CACHES_OFF() macro in flash.h were
incorrect for my platform (probably all platforms). The problem was that
the HAL_FLASH_CACHES_OFF() macro was invalidating the cache tags before
disabling the cache, causing a race condition that would occasionally lead
to cache coherency problems and the code crashing. Disabling interrupts
would also plug the race condition, but I reordered the macro to achieve the
same thing without disabling interrupts.
Jay
-----Original Message-----
From: Retallack, Mark [mailto:mark.retallack@siemens.com]
Sent: Thursday, March 02, 2006 2:47 AM
To: ecos-discuss@ecos.sourceware.org
Subject: [ECOS] Problem found with flash driver
Hello everyone, I think I have found a minor problem with the io layer
of the flash driver and before I continue with my fix, I just thought
that I would ask if anyone else has seen it.
I am using JFFS2 over a flash bank that I am not running code from, so
interrupts can be enabled during flash access. The processor is an
MPC850.
With the virgin eCos flash.c code (from CVS), the system crashes with a
random memory corruption, I have tracked it down to a context switch
within the flash_program function in flash.c. After looking through the
file and the eCos mailing list I found that the HAL_FLASH_CACHES_OFF
define states that interrupts must be disabled.
After modding the code to disable interrupts before flushing and
disabling the cache, the system works correctly with no problems.
I have not created a patch because the HAL_FLASH_CACHES_OFF define in
flash.h looks very generic and I cannot test the mod. But this is what I
have done:
// Note: the ucache code has not been tested yet on any target.
#define HAL_FLASH_CACHES_OFF(_d_, _i_) \
CYG_MACRO_START \
_i_ = 0; /* avoids warning */ \
unsigned long __state; \
HAL_DISABLE_INTERRUPTS(__state); \
HAL_UCACHE_IS_ENABLED(_d_); \
HAL_UCACHE_SYNC(); \
HAL_UCACHE_INVALIDATE_ALL(); \
HAL_UCACHE_DISABLE(); \
HAL_RESTORE_INTERRUPTS(__state); \
CYG_MACRO_END
#define HAL_FLASH_CACHES_ON(_d_, _i_) \
CYG_MACRO_START \
unsigned long __state; \
HAL_DISABLE_INTERRUPTS(__state); \
if (_d_) HAL_UCACHE_ENABLE(); \
HAL_RESTORE_INTERRUPTS(__state); \
CYG_MACRO_END
#else // HAL_CACHE_UNIFIED
#define HAL_FLASH_CACHES_OFF(_d_, _i_) \
CYG_MACRO_START \
_i_ = 0; /* avoids warning */ \
unsigned long __state; \
HAL_DISABLE_INTERRUPTS(__state); \
HAL_DCACHE_IS_ENABLED(_d_); \
HAL_DCACHE_SYNC(); \
HAL_DCACHE_INVALIDATE_ALL(); \
HAL_DCACHE_DISABLE(); \
HAL_ICACHE_INVALIDATE_ALL(); \
HAL_RESTORE_INTERRUPTS(__state); \
CYG_MACRO_END
#define HAL_FLASH_CACHES_ON(_d_, _i_) \
CYG_MACRO_START \
unsigned long __state; \
HAL_DISABLE_INTERRUPTS(__state); \
if (_d_) HAL_DCACHE_ENABLE(); \
HAL_RESTORE_INTERRUPTS(__state); \
CYG_MACRO_END
I know that someone else has already pointed out this potential problem,
but no fix was added, this makes me worry because I cannot be the only
persion who is using the jffs2 system on a powerpc 850, and this is a
very easy problem to reproduce.
Mark Retallack
Embedded Software Engineer
Siemens Traffic Controls
Sopers Lane, Poole, Dorset. BH17 7ER. UK.
Tel: 01202 782189
Fax: 01202 782545
www.siemenstraffic.com
Committed to quality traffic solutions and service excellence
Todays Quote:
I want the presidency so bad I can already taste the hors d'oeuvres.
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2006-03-02 16:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-03-02 10:47 [ECOS] Problem found with flash driver Retallack, Mark
2006-03-02 16:36 Jay Foster
2006-03-02 16:43 Retallack, Mark
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).