[U-Boot] [PATCH] fw_env.c: use default env values if config file cannot be opened

Frans Meulenbroeks fransmeulenbroeks at gmail.com
Wed Dec 28 20:01:53 CET 2011


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 at 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



More information about the U-Boot mailing list