summaryrefslogtreecommitdiff
path: root/tools/kwbimage.c
diff options
context:
space:
mode:
authorPali Rohár <pali@kernel.org>2023-01-21 15:34:55 +0300
committerStefan Roese <sr@denx.de>2023-03-01 08:39:17 +0300
commit954c94aaccf825d0142b3a36ff65f46721f4c733 (patch)
tree2a1c5054ba9524822329afc8276eb734828eef7b /tools/kwbimage.c
parenteb2c8f3805082955a95485911962b2baa8ab54ce (diff)
downloadu-boot-954c94aaccf825d0142b3a36ff65f46721f4c733.tar.xz
tools: kwbimage: Fix generating, verifying and extracting SATA kwbimage
Despite the official specification, Marvell BootROM does not interpret srcaddr from SATA image as number of sectors the beginning of the hard drive, but as number of sectors relative to the main header. The main header is stored at absolute sector number 1. So do not add or subtract it when calculating with relative offsets to the main header. Fixes: 501a54a29cc2 ("tools: kwbimage: Fix generation of SATA, SDIO and PCIe images") Fixes: 5c61710c9880 ("tools: kwbimage: Properly set srcaddr in kwbimage v0") Fixes: e0c243c398a7 ("tools: kwbimage: Validate data checksum of v1 images") Fixes: aa6943ca3122 ("kwbimage: Add support for extracting images via dumpimage tool") Signed-off-by: Pali Rohár <pali@kernel.org>
Diffstat (limited to 'tools/kwbimage.c')
-rw-r--r--tools/kwbimage.c24
1 files changed, 7 insertions, 17 deletions
diff --git a/tools/kwbimage.c b/tools/kwbimage.c
index 09d52d4765..67b45503e4 100644
--- a/tools/kwbimage.c
+++ b/tools/kwbimage.c
@@ -1013,13 +1013,12 @@ static void *image_create_v0(size_t *imagesz, struct image_tool_params *params,
sizeof(struct main_hdr_v0));
/*
- * For SATA srcaddr is specified in number of sectors starting from
- * sector 0. The main header is stored at sector number 1.
+ * For SATA srcaddr is specified in number of sectors.
* This expects the sector size to be 512 bytes.
* Header size is already aligned.
*/
if (main_hdr->blockid == IBR_HDR_SATA_ID)
- main_hdr->srcaddr = cpu_to_le32(headersz / 512 + 1);
+ main_hdr->srcaddr = cpu_to_le32(headersz / 512);
/* For PCIe srcaddr is not used and must be set to 0xFFFFFFFF. */
if (main_hdr->blockid == IBR_HDR_PEX_ID)
@@ -1461,13 +1460,12 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params,
main_hdr->flags = e->debug ? 0x1 : 0;
/*
- * For SATA srcaddr is specified in number of sectors starting from
- * sector 0. The main header is stored at sector number 1.
+ * For SATA srcaddr is specified in number of sectors.
* This expects the sector size to be 512 bytes.
* Header size is already aligned.
*/
if (main_hdr->blockid == IBR_HDR_SATA_ID)
- main_hdr->srcaddr = cpu_to_le32(headersz / 512 + 1);
+ main_hdr->srcaddr = cpu_to_le32(headersz / 512);
/* For PCIe srcaddr is not used and must be set to 0xFFFFFFFF. */
if (main_hdr->blockid == IBR_HDR_PEX_ID)
@@ -2010,16 +2008,10 @@ static int kwbimage_verify_header(unsigned char *ptr, int image_size,
/*
* For SATA srcaddr is specified in number of sectors.
- * The main header is must be stored at sector number 1.
- * This expects that sector size is 512 bytes and recalculates
- * data offset to bytes relative to the main header.
+ * This expects that sector size is 512 bytes.
*/
- if (blockid == IBR_HDR_SATA_ID) {
- if (offset < 1)
- return -FDT_ERR_BADSTRUCTURE;
- offset -= 1;
+ if (blockid == IBR_HDR_SATA_ID)
offset *= 512;
- }
/*
* For PCIe srcaddr is always set to 0xFFFFFFFF.
@@ -2377,10 +2369,8 @@ static int kwbimage_extract_subimage(void *ptr, struct image_tool_params *params
/* Extract data image when -p is not specified or when '-p 0' is specified */
offset = le32_to_cpu(mhdr->srcaddr);
- if (mhdr->blockid == IBR_HDR_SATA_ID) {
- offset -= 1;
+ if (mhdr->blockid == IBR_HDR_SATA_ID)
offset *= 512;
- }
if (mhdr->blockid == IBR_HDR_PEX_ID && offset == 0xFFFFFFFF)
offset = header_size;