[PATCH 2/3] imx-bbu-nand-fcb: Save bootloader location into device parameters

Trent Piepho trent.piepho at igorinstitute.com
Mon Oct 11 18:53:58 PDT 2021

When updating the FCB, save the location and size of the Barebox images
into parameters on the NAND device.  Since the location and padding is
calculated based on net NAND partition size, with an unknown number of
bad blocks, these values aren't known beforehard.  Saving them will
allow extracting or checksumming the Barebox image in NAND.

For example:
sha256sum /dev/nand0.barebox ${nand0.barebox.firmware1_addr}+${nand0.barebox.firmware1_size}
memcpy -s /dev/nand0.barebox -d /mnt/mmc0.0/imagedump ${nand0.barebox.firmware2_addr} 0 ${nand0.barebox.firmware2_size}

Find sum of Barebox image file with NUL padding to NAND page size (4kB
here) in Linux:
dd if=barebox-myboard.img ibs=4k conv=sync | sha256sum

Signed-off-by: Trent Piepho <trent.piepho at igorinstitute.com>
 common/imx-bbu-nand-fcb.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/common/imx-bbu-nand-fcb.c b/common/imx-bbu-nand-fcb.c
index 7108a327a..76ac1d4f2 100644
--- a/common/imx-bbu-nand-fcb.c
+++ b/common/imx-bbu-nand-fcb.c
@@ -227,6 +227,15 @@ static uint32_t calc_chksum(void *buf, size_t size)
 	return ~chksum;
+/* Set parameters on the device with the firmware location and size */
+static void set_dev_params(struct cdev *cdev, const struct fcb_block *fcb)
+	dev_add_param_uint32_fixed(cdev->dev, "firmware1_addr", fcb->Firmware1_startingPage * fcb->PageDataSize, "0x%08x");
+	dev_add_param_uint32_fixed(cdev->dev, "firmware2_addr", fcb->Firmware2_startingPage * fcb->PageDataSize, "0x%08x");
+	dev_add_param_uint32_fixed(cdev->dev, "firmware1_size", fcb->PagesInFirmware1 * fcb->PageDataSize, "0x%08x");
+	dev_add_param_uint32_fixed(cdev->dev, "firmware2_size", fcb->PagesInFirmware2 * fcb->PageDataSize, "0x%08x");
 static struct fcb_block *read_fcb_hamming_13_8(void *rawpage)
 	int i;
@@ -1363,6 +1372,8 @@ static int imx_bbu_nand_update(struct bbu_handler *handler, struct bbu_data *dat
 			goto out;
+	set_dev_params(bcb_cdev, fcb);

More information about the barebox mailing list