[U-Boot] [fw_printenv should open device as O_SYNC]

Mari Ivan-AIM018 ivan.mari at motorola.com
Thu Sep 11 16:11:23 CEST 2008


>> What eactly do you mean by "I switch the banks" ? How exactly do you
do that? Can you please provide the exact >> set of commands you are
using?

Hello Wolfgang,

We are using ATCA equipment and those boards have redundant boot banks
and they are managed by IPMI controllers.
So while you are you are running Linux, you can change the boot banks
for next restart through set boot options IPMI command.
The problem arises when we write the U-Boot env variables using
fw_setenv and immediately send the IPMI command to switch the boot bank.
In this situation the variables are not written immediately by the
fw_setenv application but buffered to be written later when the OS
decides it is the time to write them to the mtd driver. But it is too
late because the IPMI command was quickly executed and the boot bank has
changed. This could yield to a corrupted flash boot bank.

Following is the change I've made:

-sh-3.00$ diff -uprN  a/tools/env/fw_env.c b/tools/env/fw_env.c
--- a/tools/env/fw_env.c        2008-09-10 17:52:17.362714000 -0200
+++ b/tools/env/fw_env.c        2008-09-10 17:57:54.168238000 -0200
@@ -434,7 +434,7 @@ int fw_setenv (int argc, char *argv[])
        *environment.crc = crc32 (0, (uint8_t *) environment.data,
ENV_SIZE);

        /* write environment back to flash */
-       if (flash_io (O_RDWR)) {
+       if (flash_io (O_RDWR | O_SYNC)) {
                fprintf (stderr, "Error: can't write fw_env to
flash\n");
                return -1;
        }



Regards,

Ivan 

-----Original Message-----
From: wd at denx.de [mailto:wd at denx.de] 
Sent: Wednesday, September 10, 2008 5:57 PM
To: Mari Ivan-AIM018
Cc: u-boot at lists.denx.de
Subject: Re: [U-Boot] [fw_printenv should open device as O_SYNC]

Dear Ivan,

In message
<7ADFACCCB37616458C4A346B2727D3360474A88A at ct11exm66.ds.mot.com> you
wrote:
> 
> We have hit the following issue in a board with 2 flash banks.

> First I set some env variable in U-boot, using fw_setenv, then 
> immediately I switch the banks. But as the buffers have not yet been 
> flushed to the mtd driver, the bank switching leaves the flash in 
> corrupted state.

What eactly do you mean by "I switch the banks" ? How exactly do you do
that? Can you please provide the exact set of commands you are using?

> I ve modified the fw_env.c file to open the mtd O_SYNC and it works 
> fine.
>  
> If it is OK I can submit a patch for this.

sure. Please submit it so we can see what you are talking about.

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
Keep your eyes wide open before marriage, half shut afterwards.
                                                 -- Benjamin Franklin


More information about the U-Boot mailing list