From: Renato Andreola <renato.andreola@imagos.it>
To: u-boot@lists.denx.de
Subject: [U-Boot] PATCH mtd CFI flash: timeout calculation underflow if imprecise 1kHz timer: fix
Date: Tue, 25 Aug 2009 17:01:13 +0200 [thread overview]
Message-ID: <4A93FCB9.4070703@imagos.it> (raw)
In-Reply-To: <4A93E666.4080404@pobox.com>
This patch is necessary to fix the common case in which CONFIG_SYS_HZ is
just below 1000 (e.g. 999 that results from an integer division between
a system clock frequency like 83333333Hz and a divisor like 83334).
In that case the CONFIG_SYS_HZ/1000 expression returns 0 and the tout *=
CONFIG_SYS_HZ/1000 multiplication is always 0.
As you said, an incorrect Common Flash Interface interrogation of the
flash registers can lead to a tout of 0 but this misbehavior should have
been caught by the first stages of the flash interrogation code.
Note that the AMD/Spansion chips does not work correctly in a Nios2
environment due to "spurious" read cycles generated when flash bus width
is lower than 32.
If the flash chip you used is not an Intel/Numoyx than you should have
to do some work to make them behave correctly (e.g. add extra wait state
into the procedures or some other tricks).
Renato
Shinya Kuribayashi wrote:
> Renato Andreola wrote:
>
>> From 21d84ab72266f118794233176bd356d8b1cfdf35 Mon Sep 17 00:00:00 2001
>> From: Renato Andreola <renato.andreola@imagos.it>
>> Date: Fri, 21 Aug 2009 18:05:51 +0200
>> Subject: [PATCH] drivers/mtd/cfi_flash: precision and underflow problem in tout calculation
>>
>> With old configuration it could happen tout=0 if CONFIG_SYS_HZ<1000.
>>
>> Signed-off-by: Alessandro Rubini <rubini@gnudd.com> Renato Andreola <renato.andreola@imagos.it>
>> ---
>> drivers/mtd/cfi_flash.c | 8 +++++---
>> 1 files changed, 5 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c
>> index 81ac5d3..0d8fc54 100644
>> --- a/drivers/mtd/cfi_flash.c
>> +++ b/drivers/mtd/cfi_flash.c
>> @@ -660,9 +660,11 @@ static int flash_status_check (flash_info_t * info, flash_sect_t sector,
>> ulong start;
>>
>> #if CONFIG_SYS_HZ != 1000
>> - tout *= CONFIG_SYS_HZ/1000;
>> -#endif
>> -
>> + if ((ulong)CONFIG_SYS_HZ > 100000)
>> + tout *= (ulong)CONFIG_SYS_HZ/1000; /* for a big HZ, avoid overflow */
>> + else
>> + tout = DIV_ROUND_UP(tout*(ulong)CONFIG_SYS_HZ, 1000);
>> +#endif
>> /* Wait for command completion */
>> start = get_timer (0);
>> while (flash_is_busy (info, sector)) {
>>
>
> What should to be fixed first in this case, would be your CONFIG_SYS_HZ
> setting, that is NIOS2? timer implementation, yeah really. But I would
> also point out that there is another case flash_status_check() doensn't
> work as expected.
>
> One of my colleagues found that with some flash device(s) (I don't
> recall precisely, sorry), 'tout' would be probed to be zero. In that
> case, a workaround something like above still doesn't work.
>
> We have not sorted out where the problem is; it might be in cfi_flash.c,
> or in the flash device itself. This is observed with v2009.03 release,
> and we've been having a workaround for it for months. I'd like to have
> a look someday.
>
> Anyway, checking to see if 'tout' is zero or not would be sometimes
> worth a try, when you think cfi_flash.c doesn't work as expected.
>
> Just for your information,
>
>
next prev parent reply other threads:[~2009-08-25 15:01 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-24 8:32 [U-Boot] PATCH mtd CFI flash: timeout calculation underflow if imprecise 1kHz timer: fix Renato Andreola
2009-08-25 13:25 ` Shinya Kuribayashi
2009-08-25 15:01 ` Renato Andreola [this message]
2009-08-25 15:39 ` Stefan Roese
2009-08-25 15:44 ` Stefan Roese
2009-11-22 21:09 ` Wolfgang Denk
2009-11-23 8:51 ` Renato Andreola
2009-11-23 19:36 ` Wolfgang Denk
-- strict thread matches above, loose matches on Subject: below --
2009-08-06 16:08 Renato Andreola
2009-08-06 13:09 Renato Andreola
2009-08-06 13:22 ` Wolfgang Denk
2009-08-06 13:31 ` Alessandro Rubini
2009-08-06 14:19 ` Wolfgang Denk
2009-08-06 20:26 ` Jean-Christophe PLAGNIOL-VILLARD
2009-08-06 20:53 ` Wolfgang Denk
2009-08-06 21:01 ` Wolfgang Denk
2009-08-06 21:15 ` Jean-Christophe PLAGNIOL-VILLARD
2009-08-06 21:35 ` Wolfgang Denk
2009-08-07 8:15 ` Renato Andreola
2009-08-07 9:16 ` Wolfgang Denk
2009-08-07 12:14 ` Renato Andreola
2009-08-09 21:13 ` Wolfgang Denk
2009-08-06 9:49 Renato Andreola
2009-08-06 10:07 ` Wolfgang Denk
2009-08-06 10:12 ` Alessandro Rubini
[not found] ` <4A7AB614.2020509@imagos.it>
2009-08-06 11:40 ` Wolfgang Denk
2009-04-10 12:28 Renato Andreola
2009-04-13 22:09 ` Jean-Christophe PLAGNIOL-VILLARD
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4A93FCB9.4070703@imagos.it \
--to=renato.andreola@imagos.it \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.