public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] fw_env.c: use default env values if config file cannot be opened
@ 2011-12-28 19:01 Frans Meulenbroeks
  2012-01-05 15:16 ` Wolfgang Denk
  0 siblings, 1 reply; 4+ messages in thread
From: Frans Meulenbroeks @ 2011-12-28 19:01 UTC (permalink / raw)
  To: u-boot

If the config file cannot be opened currently one gets an error
even though the build in names/sizes are probably ok.
By setting the default values first and only exit if there
is a read error and not when the config file can be opened
the program will try the default settings.

In order to detect that the config file open fails get_config
returns -2 to signal this; all other errors return -1

Signed-off-by: Frans Meulenbroeks <fransmeulenbroeks@gmail.com>
---
 tools/env/fw_env.c |   18 +++++++++---------
 1 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c
index 996682e..992835f 100644
--- a/tools/env/fw_env.c
+++ b/tools/env/fw_env.c
@@ -1225,14 +1225,6 @@ static int parse_config ()
 {
 	struct stat st;
 
-#if defined(CONFIG_FILE)
-	/* Fills in DEVNAME(), ENVSIZE(), DEVESIZE(). Or don't. */
-	if (get_config (CONFIG_FILE)) {
-		fprintf (stderr,
-			"Cannot parse config file: %s\n", strerror (errno));
-		return -1;
-	}
-#else
 	strcpy (DEVNAME (0), DEVICE1_NAME);
 	DEVOFFSET (0) = DEVICE1_OFFSET;
 	ENVSIZE (0) = ENV1_SIZE;
@@ -1261,6 +1253,14 @@ static int parse_config ()
 #endif
 	HaveRedundEnv = 1;
 #endif
+
+#if defined(CONFIG_FILE)
+	/* Fills in DEVNAME(), ENVSIZE(), DEVESIZE(). Or don't. */
+	if (get_config (CONFIG_FILE) == -1) {
+		fprintf (stderr,
+			"Cannot parse config file: %s\n", strerror (errno));
+		return -1;
+	}
 #endif
 	if (stat (DEVNAME (0), &st)) {
 		fprintf (stderr,
@@ -1288,7 +1288,7 @@ static int get_config (char *fname)
 
 	fp = fopen (fname, "r");
 	if (fp == NULL)
-		return -1;
+		return -2;
 
 	while (i < 2 && fgets (dump, sizeof (dump), fp)) {
 		/* Skip incomplete conversions and comment strings */
-- 
1.7.8.1

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

end of thread, other threads:[~2012-02-12 20:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-28 19:01 [U-Boot] [PATCH] fw_env.c: use default env values if config file cannot be opened Frans Meulenbroeks
2012-01-05 15:16 ` Wolfgang Denk
2012-01-05 15:41   ` Frans Meulenbroeks
2012-02-12 20:58     ` Wolfgang Denk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox