From: Piotr Kubaj <[email protected]>
rkcommon_verify_header() and rkcommon_print_header() compare the first
four bytes of the image against RK_MAGIC_V2 using a raw host-endian read:
if ((*(uint32_t *)buf) == RK_MAGIC_V2)
The v2 header is written little-endian (rkcommon_set_header0_v2() uses
cpu_to_le32(RK_MAGIC_V2)) and rkcommon_parse_header() already reads it
back with le32_to_cpu(). On a big-endian build host the raw reads above
never match, so a valid v2 image (e.g. for RK3568) is not recognised as
v2: verification falls through to the v1 path and fails with
"Error: image verification failed".
Compare against cpu_to_le32(RK_MAGIC_V2) instead: this converts the
constant (folded at compile time) rather than byte-swapping the loaded
value, mirrors the write side, and is a no-op on little-endian hosts.
Suggested-by: Philipp Tomsich <[email protected]>
Signed-off-by: Piotr Kubaj <[email protected]>
---
tools/rkcommon.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/rkcommon.c b/tools/rkcommon.c
index b39777f..02e3fb6 100644
--- a/tools/rkcommon.c
+++ b/tools/rkcommon.c
@@ -473,7 +473,7 @@ int rkcommon_verify_header(unsigned char *buf, int size,
int ret;
/* spl_hdr is abandon on header_v2 */
- if ((*(uint32_t *)buf) == RK_MAGIC_V2)
+ if ((*(uint32_t *)buf) == cpu_to_le32(RK_MAGIC_V2))
return 0;
ret = rkcommon_parse_header(buf, &header0, &img_spl_info);
@@ -508,7 +508,7 @@ void rkcommon_print_header(const void *buf, struct
image_tool_params *params)
uint8_t image_type;
int ret, boot_size, init_size;
- if ((*(uint32_t *)buf) == RK_MAGIC_V2) {
+ if ((*(uint32_t *)buf) == cpu_to_le32(RK_MAGIC_V2)) {
ret = rkcommon_parse_header_v2(buf, &header0_v2);
if (ret < 0) {
--
2.52.0