public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] Patch for Flash Configuration option
@ 2002-04-11 14:21 Paul Fine
  2002-04-20 16:32 ` Jonathan Larmour
       [not found] ` <4.2.2.20020422193009.018f69d0@postman.cwc.nus.edu.sg>
  0 siblings, 2 replies; 4+ messages in thread
From: Paul Fine @ 2002-04-11 14:21 UTC (permalink / raw)
  To: eCos discuss mailing list, eCos discuss mailing list

[-- Attachment #1: Type: text/plain, Size: 751 bytes --]

To follow up on my threat to submit a patch, here it is.

I found that on one of the two platforms I tested the configuration 
information stored in RAM was overwritten/cleared when I launched an eCos 
application from RedBoot, on the other platform, the configuration info was 
not overwritten (The platforms are 1) MPC8260 VADS    2) Custom board using 
the MPC8260).

This patch will allow an application to get the configuration item directly 
from flash, through the virtual vector table, if the RAM based 
configuration structure is destroyed.

Hopefully this patch is small enough that you do not need a copyright 
assignment.  I am sure you will tell me if I do.


Paul Fine
Senior Member of Technical Staff
Delphi Communication Systems, Inc.

[-- Attachment #2: diff.txt --]
[-- Type: text/plain, Size: 4781 bytes --]

Index: ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/redboot/current/ChangeLog,v
retrieving revision 1.53
diff -u -r1.53 ChangeLog
--- ChangeLog	11 Jan 2002 16:54:04 -0000	1.53
+++ ChangeLog	11 Apr 2002 21:04:49 -0000
@@ -1,3 +1,17 @@
+2002-04-11  Paul Fine  <pfine@delcomsys.com>
+
+	* src/flash.c (flash_get_config, load_flash_config): Save a
+	pointer to the configuration structure in FLASH.  If
+	flash_get_config fails to find a config item, check to make sure
+	that the config structure in RAM has not been trashed.  If it has
+	been trashed, set the pointer to the "readonly" version in FLASH
+	and try to read the config item again.
+	
+
+	* cdl/redboot.cdl (CYGSEM_REDBOOT_FLASH_CONFIG_READONLY_FALLBACK):
+	Added this flash config option to control the readonly fallback in
+	flash.c
+
 2002-01-10  Hugo Tyson  <hmt@redhat.com>
 
 	* src/syscall.c (sys_timer_ticks): Explicitly initialize this.
Index: cdl/redboot.cdl
===================================================================
RCS file: /cvs/ecos/ecos/packages/redboot/current/cdl/redboot.cdl,v
retrieving revision 1.35
diff -u -r1.35 redboot.cdl
--- cdl/redboot.cdl	11 Jan 2002 16:54:04 -0000	1.35
+++ cdl/redboot.cdl	11 Apr 2002 21:04:50 -0000
@@ -484,6 +484,21 @@
                   This option is used to control the amount of memory and FLASH
                   to be used for configuration options (persistent storage)."
             }
+
+            cdl_option CYGSEM_REDBOOT_FLASH_CONFIG_READONLY_FALLBACK {
+                display       "Fallback to a READONLY Flash Configuration"
+                flavor        bool
+                default_value 1
+                description "
+                  This option will cause the Configuration information to
+                  revert to the readonly information stored in the FLASH.
+		  The option only takes effect after 
+		    1) the config_ok flag has been set to be true,
+		       indicating that at one time the copy in RAM was valid
+		  and
+		    2) the information in RAM has been verified to be invalid"
+		  
+            }
         }
 
         cdl_option CYGSEM_REDBOOT_FLASH_LOCK_SPECIAL {
Index: src/flash.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/redboot/current/src/flash.c,v
retrieving revision 1.35
diff -u -r1.35 flash.c
--- src/flash.c	11 Jan 2002 16:54:04 -0000	1.35
+++ src/flash.c	11 Apr 2002 21:04:51 -0000
@@ -1209,6 +1209,10 @@
     unsigned long key2;
     unsigned long cksum;
 } *config, *backup_config;
+#ifdef CYGSEM_REDBOOT_FLASH_CONFIG_READONLY_FALLBACK
+static struct _config  *readonly_config;
+#endif
+
 static bool config_ok;
 
 #define CONFIG_KEY1    0x0BADFACE
@@ -1889,9 +1893,13 @@
 {
     unsigned char *dp;
     void *val_ptr;
+#ifdef CYGSEM_REDBOOT_FLASH_CONFIG_READONLY_FALLBACK
+    struct _config *save_config = 0;
+#endif
 
     if (!config_ok) return false;
 
+
     if ((dp = flash_lookup_config(key)) != (unsigned char *)NULL) {
         if (CONFIG_OBJECT_TYPE(dp) == type) {
             val_ptr = (void *)CONFIG_OBJECT_VALUE(dp);
@@ -1922,6 +1930,30 @@
         }
         return true;
     }
+#ifdef CYGSEM_REDBOOT_FLASH_CONFIG_READONLY_FALLBACK
+    // Did not find key. Is configuration data valid?
+    // Check to see if the config data is valid, if not, revert to 
+    // readonly mode, by setting config to readonly_config.  We
+    // will set it back before we leave this function.
+    if ((crc32((unsigned char *)config, 
+               sizeof(struct _config)-sizeof(config->cksum)) != config->cksum) ||
+        (config->key1 != CONFIG_KEY1)|| (config->key2 != CONFIG_KEY2)) {
+        save_config = config;
+        config = readonly_config;
+        if ((crc32((unsigned char *)config, 
+                   sizeof(struct _config)-sizeof(config->cksum)) != config->cksum) ||
+            (config->key1 != CONFIG_KEY1)|| (config->key2 != CONFIG_KEY2)) {
+            diag_printf("FLASH configuration checksum error or invalid key\n");
+            config = save_config;
+            return false;
+        }
+        else{
+            diag_printf("Getting config information in READONLY mode\n");
+            return flash_get_config(key, val, type);
+
+        }        
+    }
+#endif
     return false;
 }
 
@@ -2065,6 +2097,9 @@
         cfg_base = (void *)((CYG_ADDRESS)flash_start + 
                             (CYGNUM_REDBOOT_FLASH_CONFIG_BLOCK*block_size));
     }
+#ifdef CYGSEM_REDBOOT_FLASH_CONFIG_READONLY_FALLBACK
+    readonly_config = cfg_base;
+#endif
     memcpy(config, cfg_base, sizeof(struct _config));
     if ((crc32((unsigned char *)config, 
                sizeof(struct _config)-sizeof(config->cksum)) != config->cksum) ||


[-- Attachment #3: Type: text/plain, Size: 146 bytes --]

-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [ECOS] Patch for Flash Configuration option
  2002-04-11 14:21 [ECOS] Patch for Flash Configuration option Paul Fine
@ 2002-04-20 16:32 ` Jonathan Larmour
       [not found] ` <4.2.2.20020422193009.018f69d0@postman.cwc.nus.edu.sg>
  1 sibling, 0 replies; 4+ messages in thread
From: Jonathan Larmour @ 2002-04-20 16:32 UTC (permalink / raw)
  To: Paul Fine; +Cc: eCos discuss mailing list, eCos discuss mailing list

Paul Fine wrote:
> 
> To follow up on my threat to submit a patch, here it is.

Thanks!

> I found that on one of the two platforms I tested the configuration
> information stored in RAM was overwritten/cleared when I launched an eCos
> application from RedBoot, on the other platform, the configuration info was
> not overwritten (The platforms are 1) MPC8260 VADS    2) Custom board using
> the MPC8260).
> 
> This patch will allow an application to get the configuration item directly
> from flash, through the virtual vector table, if the RAM based
> configuration structure is destroyed.
> 
> Hopefully this patch is small enough that you do not need a copyright
> assignment.  I am sure you will tell me if I do.

I think it just about squeezes in, this time. I've added a few refinements
and checked it in. Thanks for contributing back to eCos!
 
And with a ChangeLog too - you're a star :).

Jifl
-- 
Red Hat, Rustat House, Clifton Road, Cambridge, UK. Tel: +44 (1223) 271062
--[ "You can complain because roses have thorns, or you ]--
--[  can rejoice because thorns have roses." -Lincoln   ]-- Opinions==mine

-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [ECOS] Re: Hi there!
       [not found] ` <4.2.2.20020422193009.018f69d0@postman.cwc.nus.edu.sg>
@ 2002-04-22  4:47   ` Jonathan Larmour
  2002-04-22 23:20     ` Jesper Skov
  0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Larmour @ 2002-04-22  4:47 UTC (permalink / raw)
  To: Andrew Lai, eCos discussion

Please CC the ecos-discuss list!

Andrew Lai wrote:
> 
> Hi there,
> 
> Have been having trouble with printf and diag_printf() subroutines, I've
> been using.  This occurs with the twothreads.c example that has been
> distributed with eCos.
> 
> The following code fragment in twothreads.c:
> 
>      cyg_mutex_lock(&cliblock); {
>        printf("\nThread %d: and now a delay of %d clock ticks(%d)\n",
>              message, delay,x);
>      }
>      cyg_mutex_unlock(&cliblock);
> 
> It produces the following output which is clearly wrong:
> 
> Thread 0 w and now a delay of
> now a delay of
> 
> Note how the characters are being dropped intermittently and not being
> displayed.  I think I need to change something in the printf
> routines......not sure what....

It looks like the varargs support in the *compiler* has gone wrong in some
way.

Jifl
-- 
Red Hat, Rustat House, Clifton Road, Cambridge, UK. Tel: +44 (1223) 271062
--[ "You can complain because roses have thorns, or you ]--
--[  can rejoice because thorns have roses." -Lincoln   ]-- Opinions==mine

-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [ECOS] Re: Hi there!
  2002-04-22  4:47   ` [ECOS] Re: Hi there! Jonathan Larmour
@ 2002-04-22 23:20     ` Jesper Skov
  0 siblings, 0 replies; 4+ messages in thread
From: Jesper Skov @ 2002-04-22 23:20 UTC (permalink / raw)
  To: Jonathan Larmour; +Cc: Andrew Lai, eCos discussion

On Mon, 2002-04-22 at 13:47, Jonathan Larmour wrote:
> Please CC the ecos-discuss list!
> 
> Andrew Lai wrote:
> > 
> > Hi there,
> > 
> > Have been having trouble with printf and diag_printf() subroutines, I've
> > been using.  This occurs with the twothreads.c example that has been
> > distributed with eCos.
> > 
> > The following code fragment in twothreads.c:
> > 
> >      cyg_mutex_lock(&cliblock); {
> >        printf("\nThread %d: and now a delay of %d clock ticks(%d)\n",
> >              message, delay,x);
> >      }
> >      cyg_mutex_unlock(&cliblock);
> > 
> > It produces the following output which is clearly wrong:
> > 
> > Thread 0 w and now a delay of
> > now a delay of
> > 
> > Note how the characters are being dropped intermittently and not being
> > displayed.  I think I need to change something in the printf
> > routines......not sure what....
> 
> It looks like the varargs support in the *compiler* has gone wrong in some
> way.

Sorry, no, IMO it looks like an unreliable serial connection is being
used, and characters are being dropped. I see something similar if I use
the CD drive under Linux while trying to use the serial connections.

Jesper


-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-04-23  6:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-11 14:21 [ECOS] Patch for Flash Configuration option Paul Fine
2002-04-20 16:32 ` Jonathan Larmour
     [not found] ` <4.2.2.20020422193009.018f69d0@postman.cwc.nus.edu.sg>
2002-04-22  4:47   ` [ECOS] Re: Hi there! Jonathan Larmour
2002-04-22 23:20     ` Jesper Skov

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).