[PATCH 4/4] imx-bbu-nand-fcb: Inform user if the barebox partition is too small

Stefan Riedmueller s.riedmueller at phytec.de
Tue Mar 30 07:50:40 BST 2021


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 at phytec.de>
---
 common/imx-bbu-nand-fcb.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/common/imx-bbu-nand-fcb.c b/common/imx-bbu-nand-fcb.c
index 0e008c6bc2c0..4e680a0a51e7 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;
 
-- 
2.25.1




More information about the barebox mailing list