Commit b59ae73c authored by Mathew McBride's avatar Mathew McBride Committed by Tom Rini
Browse files

image: fit: fix byte order for crc32 hash check

In 92055e13 ("image: Drop if/elseif hash selection in calculate_hash()")
the FIT image hash verification code was simplified to use the hash API.

This broke verification of CRC32 hash FIT images (e.g NXP MC firmware)
as the hash API crc32 calculates in big endian (refer commit
74a18ee8, "crc32: Correct endianness of crc32 result"), whereas
the previous call directly to crc32_wd does not do a byteswap.

Example:
dumpimage -l qoriq-mc-binary/ls1088a/mc_ls1088a_10.29.1.itb
FIT description: MC Firmware
Created:         Fri Aug 27 14:14:32 2021
...
  Hash algo:    crc32
  Hash value:   c09d959c
Was returning FB9D3710 to fit_image_check_hash instead of C09D959C

Correct the byte order in the crc32_uimage_fixup so the little endian
values are returned.

Fixes: 92055e13

 "image: Drop if/elseif hash selection in calculate_hash()"
Signed-off-by: default avatarMathew McBride <matt@traverse.com.au>
parent 5c257573
......@@ -1195,6 +1195,11 @@ int fit_set_timestamp(void *fit, int noffset, time_t timestamp)
static void crc32_uimage_fixup(void *value)
{
/* In the CRC32 case, value will be byte swapped by the hash library
* function, but the FIT is specified (and checked) in little-endian
*/
*((uint32_t *)value) = ntohl(*((uint32_t *)value));
/* TODO: In C, this type punning is undefined behavior: */
*((uint32_t *)value) = cpu_to_uimage(*((uint32_t *)value));
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment