mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Stefan Riedmueller <s.riedmueller@phytec.de>
To: barebox@lists.infradead.org
Subject: [PATCH 4/4] imx-bbu-nand-fcb: Inform user if the barebox partition is too small
Date: Tue, 30 Mar 2021 08:50:40 +0200	[thread overview]
Message-ID: <20210330065040.5030-4-s.riedmueller@phytec.de> (raw)
In-Reply-To: <20210330065040.5030-1-s.riedmueller@phytec.de>

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>
---
 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


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


  parent reply	other threads:[~2021-03-30  6:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-30  6:50 [PATCH 1/4] commands: Kconfig: Remove HW ECC dependency from nandtest Stefan Riedmueller
2021-03-30  6:50 ` [PATCH 2/4] nandtest: Fix status print for NAND which size exceeds 4 GB Stefan Riedmueller
2021-03-30  6:50 ` [PATCH 3/4] mtd: nand_msx: Implement ooblayout ops Stefan Riedmueller
2021-03-30  6:50 ` Stefan Riedmueller [this message]
2021-04-01  8:26 ` [PATCH 1/4] commands: Kconfig: Remove HW ECC dependency from nandtest Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210330065040.5030-4-s.riedmueller@phytec.de \
    --to=s.riedmueller@phytec.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox