* [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
* [U-Boot] [PATCH] fw_env.c: use default env values if config file cannot be opened
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
0 siblings, 1 reply; 4+ messages in thread
From: Wolfgang Denk @ 2012-01-05 15:16 UTC (permalink / raw)
To: u-boot
Dear Frans Meulenbroeks,
In message <1325098913-29909-1-git-send-email-fransmeulenbroeks@gmail.com> you wrote:
> 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.
I have to admit that I don't like this change of behaviour. When
configured for use with a config file, all errors should be treated
the same.
But that's just my $ 0.02.
Are there any other opinions / votes how to proceed here?
Best regards,
Wolfgang Denk
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Artificial Intelligence is no match for natural stupidity.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [U-Boot] [PATCH] fw_env.c: use default env values if config file cannot be opened
2012-01-05 15:16 ` Wolfgang Denk
@ 2012-01-05 15:41 ` Frans Meulenbroeks
2012-02-12 20:58 ` Wolfgang Denk
0 siblings, 1 reply; 4+ messages in thread
From: Frans Meulenbroeks @ 2012-01-05 15:41 UTC (permalink / raw)
To: u-boot
2012/1/5 Wolfgang Denk <wd@denx.de>
> Dear Frans Meulenbroeks,
>
> In message <1325098913-29909-1-git-send-email-fransmeulenbroeks@gmail.com>
> you wrote:
> > 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.
>
> I have to admit that I don't like this change of behaviour. When
> configured for use with a config file, all errors should be treated
> the same.
>
> But that's just my $ 0.02.
>
>
> Are there any other opinions / votes how to proceed here?
>
> Best regards,
>
> Wolfgang Denk
>
>
> As you mentioned in another reply the common practice nowadays seems to be
to use a conf file.
This has the disadvantage that the conf file can get lost or misplaced.
For embedded systems I would prefer compiled-in values (or maybe an
autosensing version that just seeks into /dev/mtd0 or so to find the actual
location of the environment, if the sector size is known it would not be
too hard.
BTW: it could also be argued that the specification of the config file
should be in the board config, not in fw_env.h.
Frans
^ permalink raw reply [flat|nested] 4+ messages in thread
* [U-Boot] [PATCH] fw_env.c: use default env values if config file cannot be opened
2012-01-05 15:41 ` Frans Meulenbroeks
@ 2012-02-12 20:58 ` Wolfgang Denk
0 siblings, 0 replies; 4+ messages in thread
From: Wolfgang Denk @ 2012-02-12 20:58 UTC (permalink / raw)
To: u-boot
Dear Frans,
In message <CACW_hTY4oqT8bBGTkTopiX=rNpCmG50rNXWY0AfydAX3wZj5Rg@mail.gmail.com> you wrote:
>
> > As you mentioned in another reply the common practice nowadays seems to be
> to use a conf file.
> This has the disadvantage that the conf file can get lost or misplaced.
True. And this is an error situation, for wich a proper error message
should be issued, and execution terminated.
Paperingover such a bug is IMHO a very bad idea.
> BTW: it could also be argued that the specification of the config file
> should be in the board config, not in fw_env.h.
Yes, that could be argued. But this is unrelated tot his patch.
I still tend to reject it.
Best regards,
Wolfgang Denk
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
That was the thing about deserts. They had their own gravity. They
sucked you into the centre. - Terry Pratchett, _Small Gods_
^ permalink raw reply [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