Skip to content

Commit 94196a5

Browse files
committed
u-boot: v2026.04: helios64: fix OTP magic check (any-byte → all bytes)
Per CodeRabbit review on PR armbian#9675: is_valid_header() in board/sys_otp.c uses '||' between byte comparisons, returning 1 if *any* one byte of otp.magic matches the expected sequence. Practically every random byte pattern will trip at least one comparison, so the magic check is effectively meaningless — partially corrupt OTP data is treated as a valid Helios64 header. This is a pre-existing bug in the Kobol vendor code, carried forward unchanged through every U-Boot bump. We are migrating these board files to v2026.04, so the right place to fix it. Replace the chain with a single memcmp() against the expected magic: - removes the '||' vs '&&' confusion entirely; - reads as a normal magic-bytes check; - the constant lives in one place.
1 parent 4bf4dd9 commit 94196a5

1 file changed

Lines changed: 3 additions & 7 deletions

File tree

  • patch/u-boot/v2026.04/board_helios64/board

patch/u-boot/v2026.04/board_helios64/board/sys_otp.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <log.h>
55
#include <env.h>
66
#include <net.h>
7+
#include <string.h>
78
#include <u-boot/crc.h>
89

910
#include "sys_otp.h"
@@ -44,14 +45,9 @@ static inline int is_data_valid(void)
4445

4546
static inline int is_valid_header(void)
4647
{
47-
if ((otp.magic[0] == 'H') || (otp.magic[1] == '6') ||
48-
(otp.magic[2] == '4') || (otp.magic[3] == 'N') ||
49-
(otp.magic[4] == 'P') || (otp.magic[5] == 'V') ||
50-
(otp.magic[6] == '1') || (otp.magic[7] == 0))
48+
static const u8 expected_magic[8] = { 'H', '6', '4', 'N', 'P', 'V', '1', 0 };
5149

52-
return 1;
53-
54-
return 0;
50+
return memcmp(otp.magic, expected_magic, sizeof(expected_magic)) == 0;
5551
}
5652

5753
static int init_system_otp(int bus, int cs)

0 commit comments

Comments
 (0)