diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2014-09-30 10:59:35 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2014-09-30 11:01:27 +0200 |
commit | 130d511909673a8ab067163e85c0e69d94a66938 (patch) | |
tree | 4a845a3a354bc02bab56393b7edf6cc2c236a4c4 /arch/arm/mach-omap | |
parent | 0a2070b8fe51c93d640c96b29f09adcb001ecd77 (diff) | |
download | barebox-130d511909673a8ab067163e85c0e69d94a66938.tar.gz barebox-130d511909673a8ab067163e85c0e69d94a66938.tar.xz |
ARM: am33xx update SPI NOR: Check image size before flashing
Test if the image fits into the partition before flashing it. Makes
the update process more safe.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'arch/arm/mach-omap')
-rw-r--r-- | arch/arm/mach-omap/am33xx_bbu_spi_mlo.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/arch/arm/mach-omap/am33xx_bbu_spi_mlo.c b/arch/arm/mach-omap/am33xx_bbu_spi_mlo.c index 665a53baf7..c979302add 100644 --- a/arch/arm/mach-omap/am33xx_bbu_spi_mlo.c +++ b/arch/arm/mach-omap/am33xx_bbu_spi_mlo.c @@ -19,6 +19,7 @@ #include <bbu.h> #include <fs.h> #include <fcntl.h> +#include <linux/stat.h> /* * AM35xx, AM33xx chips use big endian MLO for SPI NOR flash @@ -34,6 +35,7 @@ static int spi_nor_mlo_handler(struct bbu_handler *handler, void *image = data->image; uint32_t *header; int swap = 0; + struct stat s; header = data->image; @@ -46,6 +48,17 @@ static int spi_nor_mlo_handler(struct bbu_handler *handler, return -EINVAL; } + ret = stat(data->devicefile, &s); + if (ret) { + printf("could not open %s: %s", data->devicefile, errno_str()); + return ret; + } + + if (size > s.st_size) { + printf("Image too big, need %d, have %lld\n", size, s.st_size); + return -ENOSPC; + } + dstfd = open(data->devicefile, O_WRONLY); if (dstfd < 0) { printf("could not open %s: %s", data->devicefile, errno_str()); |