[PATCH u-boot-marvell 09/11] tools: kwbimage: Fill the real header size into the main header

Pali Rohár pali at kernel.org
Sat Dec 25 20:11:39 CET 2021


On Saturday 25 December 2021 19:18:05 Pierre Bourdon wrote:
> On Sat, Dec 25, 2021 at 7:10 PM Pali Rohár <pali at kernel.org> wrote:
> > csum32 is checksum of data, not including header. If generated image
> > does not pass kwboot verification then it is invalid.
> 
> Agreed, but this is how it gets computed later in the caller function:
> 
> /* Build and add image data checksum */
> checksum = cpu_to_le32(image_checksum32((uint8_t *)ptr + headersz,
> datasz));
> 
> Since headersz is now different (headersz += opt_hdr_v1_size(ohdr); in
> this patch), presumably different (and maybe wrong?) data is now
> getting checksummed.

headersz is not different. See:

static void *image_create_v1(size_t *imagesz, struct image_tool_params *params,
			     uint8_t *ptr, int payloadsz)
{
...
	*imagesz = headersz;
...
	headersz = sizeof(*main_hdr);
...
}

static void kwbimage_set_header(void *ptr, struct stat *sbuf, int ifd,
				struct image_tool_params *params)
{
...
	case 1:
		image = image_create_v1(&headersz, params, ptr, datasz + 4);
		break;
...
	/* Build and add image data checksum */
	checksum = cpu_to_le32(image_checksum32((uint8_t *)ptr + headersz,
						datasz));
}

"headersz" in kwbimage_set_header() should not be affected by this patch
as first argument of image_create_v1() is not modified by this patch.

I do not see here logical error. Any idea?

> > Has it worked with some previous version? If yes, can you bisect git
> > commit which broke it?
> 
> Just reverting this one specific commit is enough to fix the issue.

Ah :-(

> After revert:
> 
> $ tools/mkimage -n ./board/qnap/qsw-98dx3236/kwbimage.cfg -T kwbimage

You you send a link to this kwbimage.cfg file?

And ideally, could you send me "broken" u-boot.kwb file (with this
patch) and "working" u-boot.kwb (without this patch)?

> -a 0x00800000 -e 0x00800000 -d u-boot.bin u-boot.kwb
> Image Type:   MVEBU Boot from nand Image
> Image version:1
> BIN Hdr Size: 76224 Bytes = 74.44 KiB = 0.07 MiB
> Data Size:    735764 Bytes = 718.52 KiB = 0.70 MiB
> Load Address: 00800000
> Entry Point:  00800000
> 
> $ sudo tools/kwboot -a -b u-boot.kwb -t -B 115200 /dev/ttyUSB0
> kwboot version 2022.01-rc4-00076-g34df634003-dirty
> Patching image boot signature to UART
> Sending boot message. Please reboot the target...-
> Waiting 2s and flushing tty
> Sending boot image header (76288 bytes)...
>   <snip>
> Done
> 
> General initialization - Version: 1.0.0
> Serdes initialization - Version: 1.0.2
> DDR3 Training Sequence - Ver TIP-1.55.0
> DDR3 Training Sequence - Switching XBAR Window to FastPath Window
> DDR3 Training Sequence - Ended Successfully
> 
> Sending boot image data (735768 bytes)...
>   <snip>
> Done
> Finishing transfer
> [Type Ctrl-\ + c to quit]
> 
> U-Boot 2022.01-rc4-00076-g34df634003-dirty (Jan 01 1980 - 00:00:00 +0000)
> 
> SoC:   98DX3236-A1 at 800 MHz
> Model: QNAP QSW-M408S
> Board: qsw-98dx3236
> DRAM:  512 MiB (800 MHz, 16-bit, ECC not enabled)
> NAND:  512 MiB
> 
> Best,
> 
> -- 
> Pierre Bourdon <delroth at gmail.com>
> Software Engineer @ Zürich, Switzerland
> https://delroth.net/


More information about the U-Boot mailing list