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

Hi all,
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.
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.
Regards,
Ivan

Hi,
Mari Ivan-AIM018 wrote:
Hi all,
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.
Maybe is a problem of mtd-layer or driver?
Regards Michael

On Wed, 10 Sep 2008, Mari Ivan-AIM018 wrote:
Hi all,
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.
Isn't this a bug in the respective MTD driver then? You should be able to open as many file-descriptors to different mtd devices as you like and be able to operate on them simultaneously. Or doesn't it work like that?
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.
Thanks Guennadi --- Guennadi Liakhovetski, Ph.D.
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-0 Fax: +49-8142-66989-80 Email: office@denx.de

Dear Ivan,
In message 7ADFACCCB37616458C4A346B2727D3360474A88A@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

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@denx.de [mailto:wd@denx.de] Sent: Wednesday, September 10, 2008 5:57 PM To: Mari Ivan-AIM018 Cc: u-boot@lists.denx.de Subject: Re: [U-Boot] [fw_printenv should open device as O_SYNC]
Dear Ivan,
In message 7ADFACCCB37616458C4A346B2727D3360474A88A@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

Hi
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.
This is a flaw in the IPMI software implementation, the IPMI controller should only switch banks when the payload power is off.
Regards, Martijn de Gouw
Disclaimer: The information contained in this email, including any attachments is confidential and is for the sole use of the intended recipient(s). Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please notify the sender immediately by replying to this message and destroy all copies of this message and any attachments.

Dear "Mari Ivan-AIM018",
In message 7ADFACCCB37616458C4A346B2727D3360474A9CE@ct11exm66.ds.mot.com you wrote:
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.
You mean, the IPMI actions are not synchronized with the Linux kernel's MTD layer? Then that's a serious bug in the IPMI implementation that needs to be fixed there.
Your suggested patch may serve as a temporary workaround for you, but it makes no sense in the general case.
I really recommend you to get the interface to the MTD layer fixed, because lots of other problems can happen in your system.
Best regards,
Wolfgang Denk
participants (5)
-
Guennadi Liakhovetski
-
Mari Ivan-AIM018
-
Martijn de Gouw
-
michael
-
Wolfgang Denk