Skip to contentSkip to conversation

arm: mvebu: nandpagesize support for kwbimage v1

PATCH In review Pali Rohár 2 participants 8 messages Oct 22, 2021 – Oct 28, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover arm: mvebu: nandpagesize support for kwbimage v1

This patch series updates mvebu code which handles nandpagesize in kwbimage v1.

Pali Rohár (3):
tools: kwbimage: Add support for NAND_PAGE_SIZE command also for v1
images
tools: kwboot: Patch nandpagesize to zero also for v1 image
arm: mvebu: Update name of kwbimage v1 field at offset 0x2-0x3

 arch/arm/mach-mvebu/spl.c |  2 +-
 cmd/mvebu/bubt.c          |  2 +-
 tools/kwbimage.c          |  3 +++
 tools/kwbimage.h          |  2 +-
 tools/kwboot.c            | 13 ++++++-------
 5 files changed, 12 insertions(+), 10 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/3 tools: kwbimage: Add support for NAND_PAGE_SIZE command also for v1 images

The NAND_PAGE_SIZE command is already supported by mkimage for v0 images, but not for v1 images.

A38x and A39x BootROM supports reading NAND flash page size from v1 image in the same way as Kirkwood BootROM from v0 image. It it documented in A38x and A39x Functional Specification.

---
 tools/kwbimage.c | 3 +++
 tools/kwbimage.h | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)
tools/kwbimage.c +3 -0
index e9324baddba4..67c0c628ae9f 100644
@@ -1231,6 +1231,9 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params,
 	e = image_find_option(IMAGE_CFG_NAND_BLKSZ);
 	if (e)
 		main_hdr->nandblocksize = e->nandblksz / (64 * 1024);
+	e = image_find_option(IMAGE_CFG_NAND_PAGESZ);
+	if (e)
+		main_hdr->nandpagesize = cpu_to_le16(e->nandpagesz);
 	e = image_find_option(IMAGE_CFG_NAND_BADBLK_LOCATION);
 	if (e)
 		main_hdr->nandbadblklocation = e->nandbadblklocation;
tools/kwbimage.h +1 -1
index 126d482fe722..f1ba95c2fa5b 100644
@@ -73,7 +73,7 @@ struct ext_hdr_v0 {
 struct main_hdr_v1 {
 	uint8_t  blockid;               /* 0x0       */
 	uint8_t  flags;                 /* 0x1       */
-	uint16_t reserved2;             /* 0x2-0x3   */
+	uint16_t nandpagesize;          /* 0x2-0x3   */
 	uint32_t blocksize;             /* 0x4-0x7   */
 	uint8_t  version;               /* 0x8       */
 	uint8_t  headersz_msb;          /* 0x9       */
Signature · 1 line
2.20.1
#5 lore raw

PATCH 3/3 arm: mvebu: Update name of kwbimage v1 field at offset 0x2-0x3

In reply to Pali Rohár

At this offset is stored nand page size.

---
 arch/arm/mach-mvebu/spl.c | 2 +-
 cmd/mvebu/bubt.c          | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/arm/mach-mvebu/spl.c +1 -1
index 04d9640b142d..cad3f0a48893 100644
@@ -76,7 +76,7 @@
 struct kwbimage_main_hdr_v1 {
 	uint8_t  blockid;               /* 0x0       */
 	uint8_t  flags;                 /* 0x1       */
-	uint16_t reserved2;             /* 0x2-0x3   */
+	uint16_t nandpagesize;          /* 0x2-0x3   */
 	uint32_t blocksize;             /* 0x4-0x7   */
 	uint8_t  version;               /* 0x8       */
 	uint8_t  headersz_msb;          /* 0x9       */
cmd/mvebu/bubt.c +1 -1
index 470fb0e92097..a7f3ff3c6fc0 100644
@@ -89,7 +89,7 @@ struct mvebu_image_info {
 struct a38x_main_hdr_v1 {
 	u8  blockid;               /* 0x0       */
 	u8  flags;                 /* 0x1       */
-	u16 reserved2;             /* 0x2-0x3   */
+	u16 nandpagesize;          /* 0x2-0x3   */
 	u32 blocksize;             /* 0x4-0x7   */
 	u8  version;               /* 0x8       */
 	u8  headersz_msb;          /* 0x9       */
Signature · 1 line
2.20.1
#3 lore raw

PATCH 2/3 tools: kwboot: Patch nandpagesize to zero also for v1 image

In reply to Pali Rohár

kwbimage v1 has also nandpagesize field. So set it to zero for both image versions when image is not signed.

---
 tools/kwboot.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
tools/kwboot.c +6 -7
index eb4f5ab87917..7e1be2962302 100644
@@ -1428,13 +1428,6 @@ kwboot_img_patch(void *img, size_t *size, int baudrate)
 	if (csum != hdr->checksum)
 		goto err;
 
-	if (image_ver == 0) {
-		struct main_hdr_v0 *hdr_v0 = img;
-
-		hdr_v0->nandeccmode = IBR_HDR_ECC_DISABLED;
-		hdr_v0->nandpagesize = 0;
-	}
-
 	srcaddr = le32_to_cpu(hdr->srcaddr);
 
 	switch (hdr->blockid) {
@@ -1480,6 +1473,12 @@ kwboot_img_patch(void *img, size_t *size, int baudrate)
 		hdr->blockid = IBR_HDR_UART_ID;
 	}
 
+	if (!is_secure) {
+		if (image_ver == 0)
+			((struct main_hdr_v0 *)img)->nandeccmode = IBR_HDR_ECC_DISABLED;
+		hdr->nandpagesize = 0;
+	}
+
 	if (baudrate) {
 		uint32_t codesz = sizeof(kwboot_baud_code);
 		void *code;
Signature · 1 line
2.20.1
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] tools: kwbimage: Add support for NAND_PAGE_SIZE command also for v1 images

In reply to Pali Rohár
Quoted 8 lines · Pali Rohár

The NAND_PAGE_SIZE command is already supported by mkimage for v0 images, but not for v1 images.

A38x and A39x BootROM supports reading NAND flash page size from v1 image in the same way as Kirkwood BootROM from v0 image. It it documented in A38x and A39x Functional Specification.

Thanks,
Stefan

Quoted 25 lines
---
  tools/kwbimage.c | 3 +++
  tools/kwbimage.h | 2 +-
  2 files changed, 4 insertions(+), 1 deletion(-)
tools/kwbimage.c +3 -0
index e9324baddba4..67c0c628ae9f 100644
@@ -1231,6 +1231,9 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params,
  	e = image_find_option(IMAGE_CFG_NAND_BLKSZ);
  	if (e)
  		main_hdr->nandblocksize = e->nandblksz / (64 * 1024);
+	e = image_find_option(IMAGE_CFG_NAND_PAGESZ);
+	if (e)
+		main_hdr->nandpagesize = cpu_to_le16(e->nandpagesz);
  	e = image_find_option(IMAGE_CFG_NAND_BADBLK_LOCATION);
  	if (e)
  		main_hdr->nandbadblklocation = e->nandbadblklocation;
tools/kwbimage.h +0 -0
index 126d482fe722..f1ba95c2fa5b 100644

tools/kwbimage.h struct ext_hdr_v0 { · line 79

Quoted 8 lines
tools/kwbimage.h +1 -1
@@ -73,7 +73,7 @@ struct ext_hdr_v0 {
  struct main_hdr_v1 {
  	uint8_t  blockid;               /* 0x0       */
  	uint8_t  flags;                 /* 0x1       */
-	uint16_t reserved2;             /* 0x2-0x3   */
+	uint16_t nandpagesize;          /* 0x2-0x3   */
  	uint32_t blocksize;             /* 0x4-0x7   */
  	uint8_t  version;               /* 0x8       */
  	uint8_t  headersz_msb;          /* 0x9       */

Viele Grüße,
Stefan

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]
Reviewed-by on v1 2/3
#4 lore raw

Re: [PATCH 2/3] tools: kwboot: Patch nandpagesize to zero also for v1 image

In reply to Pali Rohár
Quoted 4 lines · Pali Rohár

kwbimage v1 has also nandpagesize field. So set it to zero for both image versions when image is not signed.

Thanks,
Stefan

Quoted 26 lines
---
  tools/kwboot.c | 13 ++++++-------
  1 file changed, 6 insertions(+), 7 deletions(-)
tools/kwboot.c +0 -7
index eb4f5ab87917..7e1be2962302 100644
@@ -1428,13 +1428,6 @@ kwboot_img_patch(void *img, size_t *size, int baudrate)
  	if (csum != hdr->checksum)
  		goto err;
 
-	if (image_ver == 0) {
-		struct main_hdr_v0 *hdr_v0 = img;
-
-		hdr_v0->nandeccmode = IBR_HDR_ECC_DISABLED;
-		hdr_v0->nandpagesize = 0;
-	}
-
  	srcaddr = le32_to_cpu(hdr->srcaddr);
 
  	switch (hdr->blockid) {
@@ -1480,6 +1473,12 @@ kwboot_img_patch(void *img, size_t *size, int baudrate)
  		hdr->blockid = IBR_HDR_UART_ID;
  	}

tools/kwboot.c kwboot_img_patch(void *img, size_t *size, int baudrate) · line 1484

Quoted 10 lines
tools/kwboot.c +6 -0
 
+	if (!is_secure) {
+		if (image_ver == 0)
+			((struct main_hdr_v0 *)img)->nandeccmode = IBR_HDR_ECC_DISABLED;
+		hdr->nandpagesize = 0;
+	}
+
  	if (baudrate) {
  		uint32_t codesz = sizeof(kwboot_baud_code);
  		void *code;

Viele Grüße,
Stefan

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]
Reviewed-by on v1 3/3
#6 lore raw

Re: [PATCH 3/3] arm: mvebu: Update name of kwbimage v1 field at offset 0x2-0x3

In reply to Pali Rohár
Quoted 3 lines · Pali Rohár

At this offset is stored nand page size.

Thanks,
Stefan

Quoted 24 lines
---
  arch/arm/mach-mvebu/spl.c | 2 +-
  cmd/mvebu/bubt.c          | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)
arch/arm/mach-mvebu/spl.c +1 -1
index 04d9640b142d..cad3f0a48893 100644
@@ -76,7 +76,7 @@
  struct kwbimage_main_hdr_v1 {
  	uint8_t  blockid;               /* 0x0       */
  	uint8_t  flags;                 /* 0x1       */
-	uint16_t reserved2;             /* 0x2-0x3   */
+	uint16_t nandpagesize;          /* 0x2-0x3   */
  	uint32_t blocksize;             /* 0x4-0x7   */
  	uint8_t  version;               /* 0x8       */
  	uint8_t  headersz_msb;          /* 0x9       */
cmd/mvebu/bubt.c +0 -0
index 470fb0e92097..a7f3ff3c6fc0 100644

cmd/mvebu/bubt.c struct mvebu_image_info { · line 95

Quoted 8 lines
cmd/mvebu/bubt.c +1 -1
@@ -89,7 +89,7 @@ struct mvebu_image_info {
  struct a38x_main_hdr_v1 {
  	u8  blockid;               /* 0x0       */
  	u8  flags;                 /* 0x1       */
-	u16 reserved2;             /* 0x2-0x3   */
+	u16 nandpagesize;          /* 0x2-0x3   */
  	u32 blocksize;             /* 0x4-0x7   */
  	u8  version;               /* 0x8       */
  	u8  headersz_msb;          /* 0x9       */

Viele Grüße,
Stefan

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]
#7 lore raw
In reply to Pali Rohár
Quoted 8 lines · Pali Rohár

This patch series updates mvebu code which handles nandpagesize in kwbimage v1.

Pali Rohár (3):
tools: kwbimage: Add support for NAND_PAGE_SIZE command also for v1
images
tools: kwboot: Patch nandpagesize to zero also for v1 image
arm: mvebu: Update name of kwbimage v1 field at offset 0x2-0x3

Quoted 7 lines
  arch/arm/mach-mvebu/spl.c |  2 +-
  cmd/mvebu/bubt.c          |  2 +-
  tools/kwbimage.c          |  3 +++
  tools/kwbimage.h          |  2 +-
  tools/kwboot.c            | 13 ++++++-------
  5 files changed, 12 insertions(+), 10 deletions(-)

Applied to u-boot-marvell/master

Thanks,
Stefan