]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
tools: kwbimage: Fix dumping NAND_BLKSZ
authorPali Rohár <pali@kernel.org>
Sat, 14 Jan 2023 12:42:14 +0000 (13:42 +0100)
committerStefan Roese <sr@denx.de>
Wed, 1 Mar 2023 05:39:17 +0000 (06:39 +0100)
kwbimage nandblocksize field is in 64 kB unit, but NAND_BLKSZ command
expects it in bytes. So do required unit conversion.

Also zero value in nandblocksize field has special meaning. When this field
is set to zero, the default block size is used. This default size is
defined by the NAND flash page size (16 KB for a 512B page or small page
NAND and 64 KB for a large page NAND flash).

Fixes: 1a8e6b63e24f ("tools: kwbimage: Dump kwbimage config file on '-p -1' option")
Signed-off-by: Pali Rohár <pali@kernel.org>
tools/kwbimage.c

index 4e9ba5ddfae2dec6384862a24fa4b27a59473f4e..b6deb978f611b1b0b1886564cfab076030e7c1b4 100644 (file)
@@ -2184,8 +2184,14 @@ static int kwbimage_generate_config(void *ptr, struct image_tool_params *params)
        if (mhdr->blockid == IBR_HDR_NAND_ID)
                fprintf(f, "NAND_PAGE_SIZE 0x%x\n", (unsigned)le16_to_cpu(mhdr->nandpagesize));
 
-       if (version != 0 && mhdr->blockid == IBR_HDR_NAND_ID)
-               fprintf(f, "NAND_BLKSZ 0x%x\n", (unsigned)mhdr->nandblocksize);
+       if (version != 0 && mhdr->blockid == IBR_HDR_NAND_ID) {
+               if (mhdr->nandblocksize != 0) /* block size explicitly set in 64 kB unit */
+                       fprintf(f, "NAND_BLKSZ 0x%x\n", (unsigned)mhdr->nandblocksize * 64*1024);
+               else if (le16_to_cpu(mhdr->nandpagesize) > 512)
+                       fprintf(f, "NAND_BLKSZ 0x10000\n"); /* large page NAND flash = 64 kB block size */
+               else
+                       fprintf(f, "NAND_BLKSZ 0x4000\n"); /* small page NAND flash = 16 kB block size */
+       }
 
        if (mhdr->blockid == IBR_HDR_NAND_ID && (version != 0 || is_v0_ext))
                fprintf(f, "NAND_BADBLK_LOCATION 0x%x\n", (unsigned)mhdr->nandbadblklocation);