Skip to contentSkip to conversation

fastboot: fix CRC32 chunk size checking

PATCH In review Wojciech Nizinski 2 participants 3 messages Sep 25, 2023 – Oct 31, 2023 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fastboot: fix CRC32 chunk size checking

genimage create android-sparse file with CRC32 chunk at end. When U-Boot's fastboot receives this chunk it returns error message:
Fail Bogus chunk size for chunk type Dont Care

According to reference implementation of Android's sparse file format:

<https://android.googlesource.com/platform/system/core/+/refs/heads/main/
libsparse/output_file.cpp#513>

the chunk_header.total_sz is CHUNK_HEADER_LEN + 4 (CRC32 size).

---

 lib/image-sparse.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/image-sparse.c +2 -2
index 8f8a67e158..323aad981c 100644
@@ -289,8 +289,8 @@ int write_sparse_image(struct sparse_storage *info,
 
 		case CHUNK_TYPE_CRC32:
 			if (chunk_header->total_sz !=
-			    sparse_header->chunk_hdr_sz) {
-				info->mssg("Bogus chunk size for chunk type Dont Care",
+			    sparse_header->chunk_hdr_sz + sizeof(uint32_t)) {
+				info->mssg("Bogus chunk size for chunk type CRC32",
 					   response);
 				return -1;
 			}
Signature · 1 line
2.39.2
Reviewed-by Tested-by on v1 1/1
#1 lore raw

Hi Wojciech,

Thank you for your patch.

Quoted 3 lines · Wojciech Nizinski

genimage create android-sparse file with CRC32 chunk at end. When U-Boot's fastboot receives this chunk it returns error message:
Fail Bogus chunk size for chunk type Dont Care

I could not reproduce this, probably because my sparse images don't have crc32 chunks.

Quoted 9 lines

According to reference implementation of Android's sparse file format:

<https://android.googlesource.com/platform/system/core/+/refs/heads/main/
libsparse/output_file.cpp#513>

the chunk_header.total_sz is CHUNK_HEADER_LEN + 4 (CRC32 size).

However, the change looks fine to me.

I also tested by reflashing a super image from aosp/main on the vim3 board.
Base commit: 2173c4a99066 ("Merge tag 'u-boot-at91-fixes-2023.10-b' of https://source.denx.de/u-boot/custodians/u-boot-at91")

Quoted 22 lines

---

 lib/image-sparse.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/image-sparse.c +2 -2
index 8f8a67e158..323aad981c 100644
@@ -289,8 +289,8 @@ int write_sparse_image(struct sparse_storage *info,
 
 		case CHUNK_TYPE_CRC32:
 			if (chunk_header->total_sz !=
-			    sparse_header->chunk_hdr_sz) {
-				info->mssg("Bogus chunk size for chunk type Dont Care",
+			    sparse_header->chunk_hdr_sz + sizeof(uint32_t)) {
+				info->mssg("Bogus chunk size for chunk type CRC32",
 					   response);
 				return -1;
 			}
Signature · 1 line
2.39.2
#2 lore raw
In reply to Wojciech Nizinski

Hi,

Quoted 10 lines · Wojciech Nizinski

genimage create android-sparse file with CRC32 chunk at end. When U-Boot's fastboot receives this chunk it returns error message:
Fail Bogus chunk size for chunk type Dont Care

According to reference implementation of Android's sparse file format:

<https://android.googlesource.com/platform/system/core/+/refs/heads/main/
libsparse/output_file.cpp#513>

[...]

Thanks, Applied to https://source.denx.de/u-boot/custodians/u-boot-dfu (u-boot-dfu)

[1/1] fastboot: fix CRC32 chunk size checking

      https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/355aab94d1f675ec1118906e1f88dfdf6a3582eb
Signature · 1 line
Mattijs