Re: [U-Boot] PATCH mtd CFI flash: timeout calculation underflow if imprecise 1kHz timer: fix

2009-11-23 Thread Renato Andreola
Dear Wolfgang Denk,
I've sent the last patch regarding the CFI timeout underflow on 24th
August 2009 and then I Have done no more activity on U-Boot for Nios2.
I've done no more activity regarding the cache flush in
lib_nios2/bootm.c too.
As I remember, the problems with the 2 patches were related to
code white space formatting and a copyright note that can be deleted.

I hope I'll have time to go on with the activity on nios2
starting from the beginning of 2010.

Best regards,
Renato Andreola

Wolfgang Denk wrote:
 Dear Renato Andreola,

 In message 4a925011.9080...@imagos.it you wrote:
   
  From 21d84ab72266f118794233176bd356d8b1cfdf35 Mon Sep 17 00:00:00 2001
 From: Renato Andreola renato.andre...@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_HZ1000.

 Signed-off-by: Alessandro Rubini rub...@gnudd.com Renato Andreola 
 renato.andre...@imagos.it
 

 I think we are still waiting for your resubmit? Is this correct?

 Best regards,

 Wolfgang Denk

   




___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] PATCH mtd CFI flash: timeout calculation underflow if imprecise 1kHz timer: fix

2009-08-25 Thread Renato Andreola
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 8333Hz 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.andre...@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_HZ1000.

 Signed-off-by: Alessandro Rubini rub...@gnudd.com Renato Andreola 
 renato.andre...@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  10)
 +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,

   

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] PATCH mtd CFI flash: timeout calculation underflow if imprecise 1kHz timer: fix

2009-08-24 Thread Renato Andreola
 From 21d84ab72266f118794233176bd356d8b1cfdf35 Mon Sep 17 00:00:00 2001
From: Renato Andreola renato.andre...@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_HZ1000.

Signed-off-by: Alessandro Rubini rub...@gnudd.com Renato Andreola 
renato.andre...@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  10)
+   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)) {
-- 
1.5.5


___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] PATCH - Added support to YANU Nios2 uart

2009-08-24 Thread Renato Andreola
 From eae7788c435cfab344c9741c9501475e9ab2797a Mon Sep 17 00:00:00 2001
From: Renato Andreola renato.andre...@imagos.it
Date: Mon, 24 Aug 2009 11:10:44 +0200
Subject: [PATCH] Yanu Support for U-Boot

with this patch YANU uart (from opencores) support will be added to u-boot.
Remember to modify properly your board files for defining physical
address etc etc
---
  cpu/nios2/serial.c   |  170 +-
  include/nios2-yanu.h |  122 
  2 files changed, 291 insertions(+), 1 deletions(-)
  create mode 100644 include/nios2-yanu.h

diff --git a/cpu/nios2/serial.c b/cpu/nios2/serial.c
index 8bbb803..84be160 100644
--- a/cpu/nios2/serial.c
+++ b/cpu/nios2/serial.c
@@ -26,6 +26,7 @@
  #include watchdog.h
  #include asm/io.h
  #include nios2-io.h
+#include nios2-yanu.h

  DECLARE_GLOBAL_DATA_PTR;

@@ -74,10 +75,177 @@ int serial_getc (void)
return (c);
  }

+#elif defined(CONFIG_CONSOLE_YANU)
+/*-*/
+/* YANU Imagos serial port */
+/*-*/
+
+static yanu_uart_t *uart = (yanu_uart_t *)CONFIG_SYS_NIOS_CONSOLE;
+
+#if defined(CONFIG_NIOS_FIXEDBAUD)
+
+/* Everything's already setup for fixed-baud PTF assignment*/
+
+void serial_setbrg (void)
+{
+   int n, k;
+   const unsigned max_uns = 0x;
+   unsigned best_n, best_m, baud;
+
+   /* compute best N and M couple */
+   best_n = YANU_MAX_PRESCALER_N;
+   for (n = YANU_MAX_PRESCALER_N; n = 0; n--)
+   {
+   if ((unsigned)CONFIG_SYS_CLK_FREQ / (1  (n+4)) = 
(unsigned)CONFIG_BAUDRATE)
+   {
+   best_n = n;
+   break;
+   }
+   }
+   for (k=0; ; k++)
+   {
+   if ((unsigned)CONFIG_BAUDRATE = (max_uns  (15+n-k)))
+   break;
+   }
+   best_m = ((unsigned)CONFIG_BAUDRATE * (1  (15+n-k))) / 
((unsigned)CONFIG_SYS_CLK_FREQ  k);
+
+   baud = best_m + best_n * YANU_BAUDE;
+   writel(uart-baud, baud);
+
+   return;
+}
+
+#else
+
+void serial_setbrg (void)
+{
+   DECLARE_GLOBAL_DATA_PTR;
+   int n, k;
+   const unsigned max_uns = 0x;
+   unsigned best_n, best_m, baud;
+
+   /* compute best N and M couple */
+   best_n = YANU_MAX_PRESCALER_N;
+   for (n = YANU_MAX_PRESCALER_N; n = 0; n--)
+   {
+   if ((unsigned)CONFIG_SYS_CLK_FREQ / (1  (n+4)) = 
gd-baudrate)
+   {
+   best_n = n;
+   break;
+   }
+   }
+   for (k=0; ; k++)
+   {
+   if (gd-baudrate = (max_uns  (15+n-k)))
+   break;
+   }
+   best_m = (gd-baudrate * (1  (15+n-k))) / 
((unsigned)CONFIG_SYS_CLK_FREQ  k);
+
+   baud = best_m + best_n * YANU_BAUDE;
+   writel(uart-baud, baud);
+
+   return;
+}
+
+
+#endif /* CFG_NIOS_FIXEDBAUD */
+
+int serial_init (void)
+{
+   unsigned action,control;
+
+   /* status register cleanup */
+   action =  YANU_ACTION_RRRDY |
+   YANU_ACTION_RTRDY   |
+   YANU_ACTION_ROE |
+   YANU_ACTION_RBRK|
+   YANU_ACTION_RFE |
+   YANU_ACTION_RPE |
+   YANU_ACTION_RFE |
+   YANU_ACTION_RFIFO_CLEAR |
+   YANU_ACTION_TFIFO_CLEAR;
+
+   writel(uart-action, action);
+   
+   /*  control register cleanup */
+   /* no interrupts enabled */
+   /* one stop bit */
+   /* hardware flow control disabled */
+   /* 8 bits */
+   control = (0x7  YANU_CONTROL_BITS_POS);
+   /* enven parity just to be clean */
+   control |= YANU_CONTROL_PAREVEN;
+   /* we set threshold for fifo */
+   control |= YANU_CONTROL_RDYDLY * YANU_RXFIFO_DLY;
+   control |= YANU_CONTROL_TXTHR *  YANU_TXFIFO_THR;
+
+   writel(uart-control, control);
+
+   /* to set baud rate */
+   serial_setbrg();
+
+   return (0);
+}
+
+
+/*---
+ * YANU CONSOLE
+ *-*/
+void serial_putc (char c)
+{
+   int tx_chars;
+   unsigned status;
+
+   if (c == '\n')
+   serial_putc ('\r');
+   
+   while (1)
+   {
+   status = readl(uart-status);
+   tx_chars = (statusYANU_TFIFO_CHARS_POS)
+((1YANU_TFIFO_CHARS_N)-1);
+   if (tx_chars  YANU_TXFIFO_SIZE-1)
+   break;
+   WATCHDOG_RESET ();
+   }
+
+   writel(uart-data, (unsigned char)c);
+}
+
+void serial_puts (const char *s)
+{
+   while (*s != 0)
+   {
+   serial_putc (*s++);
+   }
+}
+
+
+int serial_tstc(void)
+{
+   unsigned status

[U-Boot] PATCH - Added support to YANU Nios2 uart (02)

2009-08-24 Thread Renato Andreola
 From d7a79fc4e5a3ebc6a1ca5c23500e3f2f1c3b33c2 Mon Sep 17 00:00:00 2001
From: Renato Andreola renato.andre...@imagos.it
Date: Mon, 24 Aug 2009 16:03:51 +0200
Subject: [PATCH] Yanu Support for U-Boot

with this patch YANU uart (from opencores) support will be added to u-boot.
Remember to modify properly your board files for defining physical address etc 
etc

Sign-off-by: Renato Andreola renato.andre...@imagos.it
---
  cpu/nios2/serial.c   |  165 +-
  include/nios2-yanu.h |  115 +++
  2 files changed, 279 insertions(+), 1 deletions(-)
  create mode 100644 include/nios2-yanu.h

diff --git a/cpu/nios2/serial.c b/cpu/nios2/serial.c
index 8bbb803..467df4c 100644
--- a/cpu/nios2/serial.c
+++ b/cpu/nios2/serial.c
@@ -26,6 +26,7 @@
  #include watchdog.h
  #include asm/io.h
  #include nios2-io.h
+#include nios2-yanu.h

  DECLARE_GLOBAL_DATA_PTR;

@@ -74,10 +75,172 @@ int serial_getc (void)
return (c);
  }

+#elif defined(CONFIG_CONSOLE_YANU)
+/*-*/
+/* YANU Imagos serial port */
+/*-*/
+
+static yanu_uart_t *uart = (yanu_uart_t *)CONFIG_SYS_NIOS_CONSOLE;
+
+#if defined(CONFIG_NIOS_FIXEDBAUD)
+
+/* Everything's already setup for fixed-baud PTF assignment*/
+
+void serial_setbrg (void)
+{
+   int n, k;
+   const unsigned max_uns = 0x;
+   unsigned best_n, best_m, baud;
+
+   /* compute best N and M couple */
+   best_n = YANU_MAX_PRESCALER_N;
+   for (n = YANU_MAX_PRESCALER_N; n = 0; n--) {
+   if ((unsigned)CONFIG_SYS_CLK_FREQ / (1  (n + 4)) =
+   (unsigned)CONFIG_BAUDRATE) {
+   best_n = n;
+   break;
+   }
+   }
+   for (k = 0;; k++) {
+   if ((unsigned)CONFIG_BAUDRATE = (max_uns  (15+n-k)))
+   break;
+   }
+   best_m =
+   ((unsigned)CONFIG_BAUDRATE * (1  (15 + n - k))) /
+   ((unsigned)CONFIG_SYS_CLK_FREQ  k);
+
+   baud = best_m + best_n * YANU_BAUDE;
+   writel(uart-baud, baud);
+
+   return;
+}
+
+#else
+
+void serial_setbrg (void)
+{  
+   int n, k;
+   const unsigned max_uns = 0x;
+   unsigned best_n, best_m, baud;
+
+   /* compute best N and M couple */
+   best_n = YANU_MAX_PRESCALER_N;
+   for (n = YANU_MAX_PRESCALER_N; n = 0; n--) {
+   if ((unsigned)CONFIG_SYS_CLK_FREQ / (1  (n + 4)) =
+   gd-baudrate) {
+   best_n = n;
+   break;
+   }
+   }
+   for (k = 0;; k++) {
+   if (gd-baudrate = (max_uns  (15+n-k)))
+   break;
+   }
+   best_m =
+   (gd-baudrate * (1  (15 + n - k))) /
+   ((unsigned)CONFIG_SYS_CLK_FREQ  k);
+
+   baud = best_m + best_n * YANU_BAUDE;
+   writel(uart-baud, baud);
+
+   return;
+}
+
+
+#endif /* CFG_NIOS_FIXEDBAUD */
+
+int serial_init (void)
+{
+   unsigned action,control;
+
+   /* status register cleanup */
+   action =  YANU_ACTION_RRRDY |
+   YANU_ACTION_RTRDY   |
+   YANU_ACTION_ROE |
+   YANU_ACTION_RBRK|
+   YANU_ACTION_RFE |
+   YANU_ACTION_RPE |
+   YANU_ACTION_RFE | YANU_ACTION_RFIFO_CLEAR | YANU_ACTION_TFIFO_CLEAR;
+
+   writel(uart-action, action);
+   
+   /*  control register cleanup */
+   /* no interrupts enabled */
+   /* one stop bit */
+   /* hardware flow control disabled */
+   /* 8 bits */
+   control = (0x7  YANU_CONTROL_BITS_POS);
+   /* enven parity just to be clean */
+   control |= YANU_CONTROL_PAREVEN;
+   /* we set threshold for fifo */
+   control |= YANU_CONTROL_RDYDLY * YANU_RXFIFO_DLY;
+   control |= YANU_CONTROL_TXTHR *  YANU_TXFIFO_THR;
+
+   writel(uart-control, control);
+
+   /* to set baud rate */
+   serial_setbrg();
+
+   return (0);
+}
+
+
+/*---
+ * YANU CONSOLE
+ *-*/
+void serial_putc (char c)
+{
+   int tx_chars;
+   unsigned status;
+
+   if (c == '\n')
+   serial_putc ('\r');
+   
+   while (1) {
+   status = readl(uart-status);
+   tx_chars = (statusYANU_TFIFO_CHARS_POS)
+((1YANU_TFIFO_CHARS_N)-1);
+   if (tx_chars  YANU_TXFIFO_SIZE-1)
+   break;
+   WATCHDOG_RESET ();
+   }
+
+   writel(uart-data, (unsigned char)c);
+}
+
+void serial_puts (const char *s)
+{
+   while (*s != 0) {
+   serial_putc (*s++);
+   }
+}
+
+
+int serial_tstc(void)
+{
+   unsigned status

Re: [U-Boot] PATCH mtd CFI flash: timeout calculation underflow if imprecise 1kHz timer: fix

2009-08-07 Thread Renato Andreola
Dear Wolfgang,
I'd like to clarify what is the problem with the timeout and the Intel 
flash (even if the following comments can be obvious or already well 
known) and to ask you an opinion on a small code change.

The flash has an internal busy flag that is polled in function 
flash_status_check() and that function is the only one in cfi_flash.c 
that uses the get_timer() func. and the CONFIG_SYS_HZ definition.
In many Altera/Nios boards the CONFIG_SYS_HZ constant evaluate to 999 
due to rounding errors.
With the current implementation 999 != 1000 evaluate to 1 so the 
CONFIG_SYS_HZ/1000 division is done and returns 0.
This lead to a (forced) 0 timeout in the flash_status_check() that 
corresponds to erroneous flash clear, program, etc..

I've proposed to change the code

from

#if CONFIG_SYS_HZ != 1000
tout *= CONFIG_SYS_HZ/1000;
#endif

to

 #if CONFIG_SYS_HZ != 1000
unsigned long long ull;
ull = tout*CONFIG_SYS_HZ + CONFIG_SYS_HZ/2;
tout = ull/1000; /* Compute: tout *= CONFIG_SYS_HZ/1000; */
 #endif

but this, as you told me and I agree, is too much architecture dependent 
(it uses a 64bit unsigned long).

The alternative I've proposed, suggested by A.Rubini, is as follow:

if (CONFIG_SYS_HZ  1)
tout *= CONFIG_SYS_HZ/1000;  /* for a big HZ, avoid overflow */
else
tout = (tout * CONFIG_SYS_HZ) / 1000 + 1;

that leads to an evaluation of the timeout in excess of 1 timer tick.

I think that an expression like this

#if CONFIG_SYS_HZ != 1000
if ((ulong)CONFIG_SYS_HZ  1)
tout *= ((ulong)CONFIG_SYS_HZ)/1000;  /* for a big HZ, avoid 
overflow */
else
tout = (tout * (ulong)CONFIG_SYS_HZ + 500) / 1000;
#endif

could be better because
- it forces the data type of the system dependent CONFIG_SYS_HZ value to 
ulong (no float!)
- it rounds tout to 0.5 timer tick and leaves tout unchanged if 
CONFIG_SYS_HZ == 1000

What do you think about?

Best regards,
Renato Andreola

The polling time is I've seen that the

Wolfgang Denk wrote:
 Dear Jean-Christophe PLAGNIOL-VILLARD,

 In message 20090806202615.gh13...@game.jcrosoft.org you wrote:
   
 as we are all supposed to have CONFIG_SYS_HZ at 1000 (mandtory)
 to have cfi, tftp  co working perfectly I do not thing this is a good idea
 

 Yes, this is the rule, and we would like to enforce it.

   
 as you will need to fix each part of u-boot that use CONFIG_SYS_HZ
 which make no sense

 the best will be to simply fix your timer
 

 However, the current situation is this: more than 60 boards (all of
 them ARM, it seems) use very different settings:

 include/configs/EB+MCF-EV123.h:   1000
 include/configs/EP1C20.h: 
 (CONFIG_SYS_CLK_FREQ/(CONFIG_SYS_NIOS_TMRCNT + 1))
 include/configs/EP1S10.h: 
 (CONFIG_SYS_CLK_FREQ/(CONFIG_SYS_NIOS_TMRCNT + 1))
 include/configs/EP1S40.h: 
 (CONFIG_SYS_CLK_FREQ/(CONFIG_SYS_NIOS_TMRCNT + 1))
 include/configs/KAREF.h:  100
 include/configs/M5271EVB.h:   100
 include/configs/METROBOX.h:   100
 include/configs/MVBLUE.h: 1
 include/configs/PCI5441.h:
 (CONFIG_SYS_CLK_FREQ/(CONFIG_SYS_NIOS_TMRCNT + 1))
 include/configs/PK1C20.h: 
 (CONFIG_SYS_CLK_FREQ/(CONFIG_SYS_NIOS_TMRCNT + 1))
 include/configs/SMN42.h:  2048
 include/configs/VCMA9.h:  1562500
 include/configs/actux1.h: 333
 include/configs/actux2.h: 333
 include/configs/actux3.h: 333
 include/configs/actux4.h: 333
 include/configs/apollon.h:((CONFIG_SYS_CLK_FREQ)/(2  
 CONFIG_SYS_PTV))
 include/configs/armadillo.h:  2000
 include/configs/assabet.h:3686400
 include/configs/at91rm9200dk.h:   AT91C_MASTER_CLOCK/2
 include/configs/at91rm9200ek.h:   (AT91C_MASTER_CLOCK / 2)
 include/configs/cmc_pu2.h:(AT91C_MASTER_CLOCK/2)
 include/configs/csb637.h: AT91C_MASTER_CLOCK/2
 include/configs/davinci_dm355evm.h:   2400
 include/configs/davinci_dvevm.h:  2700
 include/configs/davinci_schmoogie.h:  2700
 include/configs/davinci_sffsdr.h: 2700
 include/configs/davinci_sonata.h: 2700
 include/configs/dnp1110.h:3686400
 include/configs/eNET.h:   1024
 include/configs/ep7312.h: 2000
 include/configs/gcplus.h: 3686400
 include/configs/idmr.h:   (5000 / 64)
 include/configs/impa7.h:  2000
 include/configs/integratorap.h:   2400
 include/configs/integratorcp.h:   100
 include/configs/ixdp425.h:333
 include/configs/kb9202.h: AT91C_MASTER_CLOCK/2
 include/configs/lart.h:   3686400
 include/configs/lpc2292sodimm.h:  2048
 include/configs/lpd7a400-10.h:(508469)
 include/configs/lpd7a404-10.h:(508469)
 include/configs/m501sk.h

Re: [U-Boot] PATCH mtd CFI flash: timeout calculation underflow if imprecise 1kHz timer: fix

2009-08-07 Thread Renato Andreola
Ok, for the change.
What is the preferred way to proceed? have I got to resubmit a patch for 
the change with the DIV_ROUND_UP macro?

Best regards,
Renato Andreola

Wolfgang Denk wrote:
 Dear Renato Andreola,

 In message 4a7be28a.8080...@imagos.it you wrote:
   
 I'd like to clarify what is the problem with the timeout and the Intel 
 flash (even if the following comments can be obvious or already well 
 known) and to ask you an opinion on a small code change.
 

 Thanks.

 ...
   
 I think that an expression like this

 #if CONFIG_SYS_HZ != 1000
 if ((ulong)CONFIG_SYS_HZ  1)
 tout *= ((ulong)CONFIG_SYS_HZ)/1000;  /* for a big HZ, avoid 
 overflow */
 else
 tout = (tout * (ulong)CONFIG_SYS_HZ + 500) / 1000;
 #endif

 could be better because
 - it forces the data type of the system dependent CONFIG_SYS_HZ value to 
 ulong (no float!)
 - it rounds tout to 0.5 timer tick and leaves tout unchanged if 
 CONFIG_SYS_HZ == 1000

 What do you think about?
 

 I'd prefer tout = DIV_ROUND_UP(tout*CONFIG_SYS_HZ, 1000);


 Best regards,

 Wolfgang Denk

   

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] PATCH Nios2 kernel bootstrap error due to missing processor data cache flush: fix

2009-08-06 Thread Renato Andreola
 From caddbcecc99d7f96fdf7ca9c3d89ffac9cb999e1 Mon Sep 17 00:00:00 2001
From: Renato Andreola renato.andre...@imagos.it
Date: Thu, 6 Aug 2009 11:03:19 +0200
Subject: Nios2: do_boom_linux(): kernel gunzip input data integrity 
problem due to mi
ssing cache flush

Added instruction and data caches flush

Signed-off-by: Renato Andreola renato.andre...@imagos.it

---
  lib_nios2/bootm.c |5 +
  1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/lib_nios2/bootm.c b/lib_nios2/bootm.c
index 53fd569..65bb4cb 100644
--- a/lib_nios2/bootm.c
+++ b/lib_nios2/bootm.c
@@ -24,6 +24,7 @@
  #include common.h
  #include command.h
  #include asm/byteorder.h
+#include asm/cache.h

  int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t 
*images)
  {
@@ -32,6 +33,10 @@ int do_bootm_linux(int flag, int argc, char *argv[], 
bootm_headers_t *images)
if ((flag != 0)  (flag != BOOTM_STATE_OS_GO))
return 1;

+   /* flushes data and instruction caches before calling the kernel */
+   flush_dcache (0,CONFIG_SYS_DCACHE_SIZE );
+   flush_icache (0,CONFIG_SYS_ICACHE_SIZE);
+
/* For now we assume the Microtronix linux ... which only
 * needs to be called ;-)
 */
-- 
1.5.5



___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] PATCH mtd CFI flash: timeout calculation underflow if imprecise 1kHz timer: fix

2009-08-06 Thread Renato Andreola
 From be54cb97ca26bcbbc1a908d1f2a5447b6639dc59 Mon Sep 17 00:00:00 2001
From: Renato Andreola renato.andre...@imagos.it
Date: Thu, 6 Aug 2009 11:40:52 +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_HZ1000
solved using an unsigned long long

Signed-off-by: Renato Andreola renato.andre...@imagos.it
---
  drivers/mtd/cfi_flash.c |6 --
  1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c
index 81ac5d3..6bcd102 100644
--- a/drivers/mtd/cfi_flash.c
+++ b/drivers/mtd/cfi_flash.c
@@ -659,8 +659,10 @@ 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;
+#if CONFIG_SYS_HZ != 1000  
+   unsigned long long ull;
+   ull = tout*CONFIG_SYS_HZ + CONFIG_SYS_HZ/2;
+   tout = ull/1000; /* Compute: tout *= CONFIG_SYS_HZ/1000; */
  #endif

/* Wait for command completion */
-- 
1.5.5




___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] PATCH mtd CFI flash: timeout calculation underflow if imprecise 1kHz timer: fix

2009-08-06 Thread Renato Andreola
 From 3723c8437d8c3d2e04bc3bc1de9c21b33072ab08 Mon Sep 17 00:00:00 2001
From: Renato Andreola renato.andre...@imagos.it
Date: Thu, 6 Aug 2009 14:49:59 +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_HZ1000
solved avoiding the preprocessor conditional and introducing a compile 
time branch between a high freq case and a slow freq case.

Signed-off-by: Renato Andreola renato.andre...@imagos.it
---
  drivers/mtd/cfi_flash.c |7 ---
  1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c
index 81ac5d3..b118f71 100644
--- a/drivers/mtd/cfi_flash.c
+++ b/drivers/mtd/cfi_flash.c
@@ -659,9 +659,10 @@ 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 (CONFIG_SYS_HZ  1)
+tout *= CONFIG_SYS_HZ/1000;  /* for a big HZ, avoid 
overflow */
+else
+tout = tout * CONFIG_SYS_HZ / 1000 + 1;

/* Wait for command completion */
start = get_timer (0);
-- 
1.5.5



___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] PATCH - Added support to YANU Nios2 uart

2009-08-06 Thread Renato Andreola
 From 6e15ffc680ca75d5bd3a01fc9010c34637c6ab32 Mon Sep 17 00:00:00 2001
From: Renato Andreola renato.andre...@imagos.it
Date: Thu, 6 Aug 2009 12:28:51 +0200
Subject: [PATCH] Yanu Support for U-Boot

with this patch YANU uart support will be added to u-boot.
Remember to modify properly your board files for defining physical 
address etc etc

Signed-off-by: Renato Andreola renato.andre...@imagos.it
---
  cpu/nios2/serial.c   |  158 
+-
  include/nios2-yanu.h |  119 +
  2 files changed, 276 insertions(+), 1 deletions(-)
  create mode 100644 include/nios2-yanu.h

diff --git a/cpu/nios2/serial.c b/cpu/nios2/serial.c
index 8bbb803..e77b2c6 100644
--- a/cpu/nios2/serial.c
+++ b/cpu/nios2/serial.c
@@ -26,6 +26,8 @@
  #include watchdog.h
  #include asm/io.h
  #include nios2-io.h
+#include nios2-yanu.h
+

  DECLARE_GLOBAL_DATA_PTR;

@@ -73,11 +75,165 @@ int serial_getc (void)
c = val  0x0ff;
return (c);
  }
+/*--
+ * YANU Imagos serial port
+ *-*/
+#elif defined(CONFIG_CONSOLE_YANU)
+
+static yanu_uart_t *uart = (yanu_uart_t *)CONFIG_SYS_NIOS_CONSOLE;
+
+#if defined(CONFIG_NIOS_FIXEDBAUD)
+
+/* Everything's already setup for fixed-baud PTF
+ * assignment
+ */
+void serial_setbrg (void) {
+   int n, k;
+   const unsigned max_uns = 0x;
+   unsigned best_n, best_m, baud;
+
+   /* compute best N and M couple */
+   best_n = YANU_MAX_PRESCALER_N;
+   for (n = YANU_MAX_PRESCALER_N; n = 0; n--)
+   if ((unsigned)CONFIG_SYS_CLK_FREQ / (1  (n+4)) = 
(unsigned)CONFIG_BAUDRATE) {
+   best_n = n;
+   break;
+   }
+   for (k=0; ; k++)
+   if ((unsigned)CONFIG_BAUDRATE = (max_uns  (15+n-k)))
+   break;
+   best_m = ((unsigned)CONFIG_BAUDRATE * (1  (15+n-k))) / 
((unsigned)CONFIG_SYS_CLK_FREQ  k);
+
+   baud = best_m + best_n * YANU_BAUDE;
+   writel(uart-baud, baud);
+
+   return;
+}
+
+#else
+
+void serial_setbrg (void)
+{
+   DECLARE_GLOBAL_DATA_PTR;
+   int n, k;
+   const unsigned max_uns = 0x;
+   unsigned best_n, best_m, baud;
+
+   /* compute best N and M couple */
+   best_n = YANU_MAX_PRESCALER_N;
+   for (n = YANU_MAX_PRESCALER_N; n = 0; n--)
+   if ((unsigned)CONFIG_SYS_CLK_FREQ / (1  (n+4)) = 
gd-baudrate) {
+   best_n = n;
+   break;
+   }
+   for (k=0; ; k++)
+   if (gd-baudrate = (max_uns  (15+n-k)))
+   break;
+   best_m = (gd-baudrate * (1  (15+n-k))) / 
((unsigned)CONFIG_SYS_CLK_FREQ  k);
+
+   baud = best_m + best_n * YANU_BAUDE;
+   writel(uart-baud, baud);
+
+   return;
+}
+
+
+#endif /* CFG_NIOS_FIXEDBAUD */
+
+int serial_init (void)
+{
+   unsigned action,control;
+
+   /* status register cleanup */
+   action =  YANU_ACTION_RRRDY |
+   YANU_ACTION_RTRDY   |
+   YANU_ACTION_ROE |
+   YANU_ACTION_RBRK|
+   YANU_ACTION_RFE |
+   YANU_ACTION_RPE |
+   YANU_ACTION_RFE |
+   YANU_ACTION_RFIFO_CLEAR |
+   YANU_ACTION_TFIFO_CLEAR;
+
+   writel(uart-action, action);
+   
+   /*  control register cleanup */
+   /* no interrupts enabled */
+   /* one stop bit */
+   /* hardware flow control disabled */
+   /* 8 bits */
+   control = (0x7  YANU_CONTROL_BITS_POS);
+   /* enven parity just to be clean */
+   control |= YANU_CONTROL_PAREVEN;
+   /* we set threshold for fifo */
+   control |= YANU_CONTROL_RDYDLY * YANU_RXFIFO_DLY;
+   control |= YANU_CONTROL_TXTHR *  YANU_TXFIFO_THR;
+
+   writel(uart-control, control);
+
+   /* to set baud rate */
+   serial_setbrg();
+
+   return (0);
+}
+
+
+/*---
+ * YANU CONSOLE
+ *-*/
+void serial_putc (char c)
+{
+   int tx_chars;
+   unsigned status;
+
+   if (c == '\n')
+   serial_putc ('\r');
+   
+   while (1)
+   {
+   status = readl(uart-status);
+   tx_chars = (statusYANU_TFIFO_CHARS_POS)  
((1YANU_TFIFO_CHARS_N)-1);
+   if (tx_chars  YANU_TXFIFO_SIZE-1)
+   break;
+   WATCHDOG_RESET ();
+   }
+
+   writel(uart-data, (unsigned char)c);
+}
+
+void serial_puts (const char *s)
+{
+   while (*s != 0) {
+   serial_putc (*s++);
+   }
+}
+
+
+int serial_tstc(void)
+{
+   unsigned status ;
+
+   status = readl(uart-status);
+   return(((statusYANU_RFIFO_CHARS_POS

[U-Boot] PATCH mtd CFI flash: timeout calculation underflow if imprecise 1kHz timer: fix

2009-08-06 Thread Renato Andreola
 From 341dbd88695d3514699aae612d640ed93feb8821 Mon Sep 17 00:00:00 2001
From: Renato Andreola renato.andre...@imagos.it
Date: Thu, 6 Aug 2009 18:05:00 +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_HZ1000
solved avoiding the preprocessor conditional and introducing a compile time 
branch between a high freq case and a slow freq case.

Signed-off-by: Alessandro Rubini rub...@gnudd.com Renato Andreola 
renato.andre...@imagos.it
---
  drivers/mtd/cfi_flash.c |7 ---
  1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c
index 81ac5d3..499044f 100644
--- a/drivers/mtd/cfi_flash.c
+++ b/drivers/mtd/cfi_flash.c
@@ -659,9 +659,10 @@ 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 (CONFIG_SYS_HZ  1)
+   tout *= CONFIG_SYS_HZ/1000;  /* for a big HZ, avoid overflow */
+else
+   tout = (tout * CONFIG_SYS_HZ) / 1000 + 1;

/* Wait for command completion */
start = get_timer (0);
-- 
1.5.5





___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] Rejected: PATCH Nios2 kernel bootstrap error due to missing processor data cache flush: fix

2009-07-22 Thread Renato Andreola
Ok, please update the file with the correct bug fix with no more copyright.
My intent is only to fix the bug that caused random boot failures and to 
keep free the good work on Nios2.

I was warried about that the official main UBoot distribution contained 
a bug that has a big impact on the ability of someone to test a linux 
distribution on Nios2 with UBoot.

We have spent two weeks with low level prints to find that the bug was 
related to the missing data cache flush and not to the kernel or the 
pre-kernel trampoline code.

Please note that the other bug related to incorrect flash timeout into 
the CFI flash code has not been applied into the last Uboot release yet.
That bug was related to an integer division that leads to a zero timeout 
in case of a less that 1000Hz timer (e.g: if the calculated timer 
frequency is 999.99Hz, due to a truncation into the macro definition, 
the resulting time to sleep is Zero: this brings to non reliable 
clear/program cycles in Intel/Numonyx flash chips that works with the 
status flag polling algorithm).


Regards,
Renato

Scott McNutt wrote:
 See comments.

 diff --git a/lib_nios2/bootm.c b/lib_nios2/bootm.c
 index 53fd569..1e8034b 100644
 --- a/lib_nios2/bootm.c
 +++ b/lib_nios2/bootm.c
 @@ -2,6 +2,9 @@
   * (C) Copyright 2003, Psyent Corporation www.psyent.com
   * Scott McNutt smcn...@psyent.com
   *
 + * (C) Copyright 2009, Imagos sas www.imagos.it
 + * Renato Andreola renato.andre...@imagos.it
 + *

 Claiming a copyright ...

 +/* flushes data and instruction caches before calling the kernel */
 +flush_dcache (0,CONFIG_SYS_DCACHE_SIZE );
 +flush_icache (0,CONFIG_SYS_ICACHE_SIZE);

 ... for a two line bug fix?

 This is hardly a valid reason to claim copyright on the module.

 This practice will only discourage the contribution of original work
 to the project. Nobody wants to have their work hijacked in such a
 manner.

 Please resubmit.

 Regards,
 --Scott



___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] PATCH Nios2 kernel bootstrap error due to missing processor data cache flush: fix

2009-04-10 Thread Renato Andreola
 From b75bd27f89ac6c105cebb6507cf082b6f5fffc7d Mon Sep 17 00:00:00 2001
From: Renato Andreola renato.andre...@imagos.it
Date: Fri, 10 Apr 2009 12:32:29 +0200
Subject: Nios2: do_boom_linux(): kernel gunzip input data integrity 
problem due to mi
 ssing cache flush

Added instruction and data caches flush

Signed-off-by: Renato Andreola renato.andre...@imagos.it
---
 lib_nios2/bootm.c |8 +++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/lib_nios2/bootm.c b/lib_nios2/bootm.c
index 53fd569..1e8034b 100644
--- a/lib_nios2/bootm.c
+++ b/lib_nios2/bootm.c
@@ -2,6 +2,9 @@
  * (C) Copyright 2003, Psyent Corporation www.psyent.com
  * Scott McNutt smcn...@psyent.com
  *
+ * (C) Copyright 2009, Imagos sas www.imagos.it
+ * Renato Andreola renato.andre...@imagos.it
+ *
  * See file CREDITS for list of people who contributed to this
  * project.
  *
@@ -24,6 +27,7 @@
 #include common.h
 #include command.h
 #include asm/byteorder.h
+#include asm/cache.h
 
 int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t 
*images)
 {
@@ -31,7 +35,9 @@ int do_bootm_linux(int flag, int argc, char *argv[], 
bootm_headers_t *images)
 
 if ((flag != 0)  (flag != BOOTM_STATE_OS_GO))
 return 1;
-
+/* flushes data and instruction caches before calling the kernel */
+flush_dcache (0,CONFIG_SYS_DCACHE_SIZE );
+flush_icache (0,CONFIG_SYS_ICACHE_SIZE);
 /* For now we assume the Microtronix linux ... which only
  * needs to be called ;-)
  */
-- 
1.5.5



___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] PATCH mtd CFI flash: timeout calculation underflow if imprecise 1kHz timer: fix

2009-04-10 Thread Renato Andreola
 From 6cc63851e5e4c16012d9afad70cedb41b7340de7 Mon Sep 17 00:00:00 2001
From: Renato Andreola renato.andre...@imagos.it
Date: Fri, 10 Apr 2009 12:52:55 +0200
Subject: drivers/mtd/cfi_flash: precision and underflow problem in tout 
calculation

With old configuration it could happen tout=0 if CONFIG_SYS_HZ1000
solved using an unsigned long long
---
  drivers/mtd/cfi_flash.c |4 +++-
  1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c
index 175d82a..0aa42a2 100644
--- a/drivers/mtd/cfi_flash.c
+++ b/drivers/mtd/cfi_flash.c
@@ -660,7 +660,9 @@ 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;
+   unsigned long long ull;
+   ull = tout*CONFIG_SYS_HZ + CONFIG_SYS_HZ/2;
+   tout = ull/1000; /* Compute: tout *= CONFIG_SYS_HZ/1000; */
  #endif

/* Wait for command completion */
-- 
1.5.5


___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] Nios2: bootm command bugs (lead to Kernel guzip crc error or ran out of input data) and cfi_flash timeout error

2009-04-09 Thread Renato Andreola
I've tested u-boot 2009/03 with the last nios2 uClinux kernel and I've 
found 2 bugs (or things that can be changed to improve performance).

= CFI bug

The first bug is related to the Common Flash Interface handling code: 
the write/clear/etc.. timeout is calculated assuming a 1kHz timer tick 
freq. and the expression used to scale the timeout leads to an incorrect 
timeou in case the tick frequency (integer) is less than 1kHz (e.g. 
999Hz due to rounding like in our case with 83.3Mhz clock).
The integer division used in the cfi_flash.c routine can be improved 
like this:

662,663c662,665
 #if CONFIG_SYS_HZ != 1000
 tout *= CONFIG_SYS_HZ/1000;
---
  #if CONFIG_SYS_HZ != 1000
  unsigned long long ull;
  ull = tout*CONFIG_SYS_HZ + CONFIG_SYS_HZ/2;
  tout = ull/1000; /* Compute: tout *= CONFIG_SYS_HZ/1000; */


The new expression uses a long and an integer round trick to function 
properly even in case of CONFIG_SYS_HZ = 999.




= Kernel decompression bug

The u-boot copies (sometime and in my test board!) the kernel image from 
somewhere  to the execution address specified into the image header. 
After the copy, and some more work, the Nios2 bootm() procedure jumps to 
the entry point.
The problem is that the bootm() procedure does not flush the data cache 
before jumping to the newly copied code, so the execution of the kernel 
head.S routine (that invalidates the cache and calls guzip) finds some 
invalid data into the dram memory (some data cache lines have been lost).
The following code diff (just to flush data cache) fixes the problem in 
lib_nios2/bootm.c:

26a27
  #include asm/cache.h
34c35,36

---
  flush_dcache (0,CONFIG_SYS_DCACHE_SIZE );
  flush_icache (0,CONFIG_SYS_ICACHE_SIZE);

Renato



___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot