[U-Boot] [PATCH] tools/env: check that redundant environments have equal size

For double buffering to work, the target buffer must always be big enough to hold all data. This can only be ensured if buffers are of equal size, otherwise one must be smaller and we risk data loss when copying from the bigger to the smaller.
Signed-off-by: Andreas Fenkart andreas.fenkart@digitalstrom.com --- tools/env/fw_env.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c index 06cf63d..60a7394 100644 --- a/tools/env/fw_env.c +++ b/tools/env/fw_env.c @@ -1373,12 +1373,21 @@ static int parse_config () return -1; }
- if (HaveRedundEnv && stat (DEVNAME (1), &st)) { - fprintf (stderr, - "Cannot access MTD device %s: %s\n", - DEVNAME (1), strerror (errno)); - return -1; + if (HaveRedundEnv) { + if (stat(DEVNAME(1), &st)) { + fprintf(stderr, + "Cannot access MTD device %s: %s\n", + DEVNAME(1), strerror(errno)); + return -1; + } + + if (ENVSIZE(0) != ENVSIZE(1)) { + fprintf(stderr, + "Redundant environments are not of equal size"); + return -1; + } } + return 0; }

On Thu, May 19, 2016 at 12:43:51PM +0200, Andreas Fenkart wrote:
For double buffering to work, the target buffer must always be big enough to hold all data. This can only be ensured if buffers are of equal size, otherwise one must be smaller and we risk data loss when copying from the bigger to the smaller.
Signed-off-by: Andreas Fenkart andreas.fenkart@digitalstrom.com
Applied to u-boot/master, thanks!

On Mon, May 30, 2016 at 01:59:51PM -0400, Tom Rini wrote:
On Thu, May 19, 2016 at 12:43:51PM +0200, Andreas Fenkart wrote:
For double buffering to work, the target buffer must always be big enough to hold all data. This can only be ensured if buffers are of equal size, otherwise one must be smaller and we risk data loss when copying from the bigger to the smaller.
Signed-off-by: Andreas Fenkart andreas.fenkart@digitalstrom.com
Applied to u-boot/master, thanks!
Actually, wait, no, this one isn't, with your other series now applied, this doesn't apply cleanly, thanks!

Hi Tom
I thought there was something wrong with my april patches, so I started reworking them. This patch is part of the rework. I broke it out of the series to make it stand out of the other patches since it might break behaviour. You can ignore it, it's part of the v2 series. I will rebase my cleaned up patches when I have time. One problem though is that the env-tools on master now have a compile error. I will fix that and send out a patch soon...
Andreas
2016-05-30 20:01 GMT+02:00 Tom Rini trini@konsulko.com:
On Mon, May 30, 2016 at 01:59:51PM -0400, Tom Rini wrote:
On Thu, May 19, 2016 at 12:43:51PM +0200, Andreas Fenkart wrote:
For double buffering to work, the target buffer must always be big enough to hold all data. This can only be ensured if buffers are of equal size, otherwise one must be smaller and we risk data loss when copying from the bigger to the smaller.
Signed-off-by: Andreas Fenkart andreas.fenkart@digitalstrom.com
Applied to u-boot/master, thanks!
Actually, wait, no, this one isn't, with your other series now applied, this doesn't apply cleanly, thanks!
-- Tom
participants (3)
-
Andreas Fenkart
-
Andreas Fenkart
-
Tom Rini