summaryrefslogtreecommitdiffstats
path: root/common/imx-bbu-nand-fcb.c
diff options
context:
space:
mode:
authorStefan Riedmueller <s.riedmueller@phytec.de>2021-03-30 08:50:40 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2021-04-01 10:24:14 +0200
commit0a08cd09b36cacb58788dbc82b463126bc737a45 (patch)
treef993635f6e7e84ae571aca0f6e58305729c058de /common/imx-bbu-nand-fcb.c
parent0e18518c1548f22602a9a9e1a2a3d2ee1cb47724 (diff)
downloadbarebox-0a08cd09b36cacb58788dbc82b463126bc737a45.tar.gz
barebox-0a08cd09b36cacb58788dbc82b463126bc737a45.tar.xz
imx-bbu-nand-fcb: Inform user if the barebox partition is too small
Show an error message and return an error code if the barebox partition is too small. This can easily happen when having large erasoblocks since all four FCB copies need a separate eraseblock. Signed-off-by: Stefan Riedmueller <s.riedmueller@phytec.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/imx-bbu-nand-fcb.c')
-rw-r--r--common/imx-bbu-nand-fcb.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/common/imx-bbu-nand-fcb.c b/common/imx-bbu-nand-fcb.c
index 0e008c6bc2..4e680a0a51 100644
--- a/common/imx-bbu-nand-fcb.c
+++ b/common/imx-bbu-nand-fcb.c
@@ -501,7 +501,8 @@ static int imx_bbu_firmware_start_block(struct mtd_info *mtd, int num)
* @num: The slot number (0 or 1)
*
* This returns the start page for a firmware slot, to be written into the
- * Firmwaren_startingPage field in the FCB.
+ * Firmwaren_startingPage field in the FCB or a negative error code in case
+ * of a failure.
*/
static int imx_bbu_firmware_fcb_start_page(struct mtd_info *mtd, int num)
{
@@ -512,6 +513,11 @@ static int imx_bbu_firmware_fcb_start_page(struct mtd_info *mtd, int num)
blocksleft = imx_bbu_firmware_max_blocks(mtd);
+ if (blocksleft <= 0) {
+ pr_err("partition size too small for both firmwares\n");
+ return -ENOMEM;
+ }
+
/*
* The ROM only checks for a bad block when advancing the read position,
* but not if the initial block is good, hence we cannot directly point
@@ -1258,7 +1264,15 @@ static int imx_bbu_nand_update(struct bbu_handler *handler, struct bbu_data *dat
free(fcb);
fcb = xzalloc(sizeof(*fcb));
fcb->Firmware1_startingPage = imx_bbu_firmware_fcb_start_page(mtd, !used);
+ if (fcb->Firmware1_startingPage < 0) {
+ ret = fcb->Firmware1_startingPage;
+ goto out;
+ }
fcb->Firmware2_startingPage = imx_bbu_firmware_fcb_start_page(mtd, used);
+ if (fcb->Firmware2_startingPage < 0) {
+ ret = fcb->Firmware2_startingPage;
+ goto out;
+ }
fcb->PagesInFirmware1 = fw_size / mtd->writesize;
fcb->PagesInFirmware2 = fcb->PagesInFirmware1;