bootcount: Fix potential clobbering issue

When storing the single word bootcount value, apply the bootcount count
mask to prevent clobbering the magic half of the value.

Signed-off-by: Niko Mauno <niko.mauno@vaisala.com>
This commit is contained in:
Niko Mauno
2026-02-04 15:17:36 +02:00
committed by Tom Rini
parent 27e1924ffa
commit 05b56599b5

View File

@@ -19,7 +19,8 @@ __weak void bootcount_store(ulong a)
uintptr_t flush_end;
#if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD)
raw_bootcount_store(reg, (CONFIG_SYS_BOOTCOUNT_MAGIC & BOOTCOUNT_MAGIC_MASK) | a);
raw_bootcount_store(reg, (CONFIG_SYS_BOOTCOUNT_MAGIC & BOOTCOUNT_MAGIC_MASK)
| (a & BOOTCOUNT_COUNT_MASK));
flush_end = roundup(CONFIG_SYS_BOOTCOUNT_ADDR + 4,
CONFIG_SYS_CACHELINE_SIZE);
@@ -98,7 +99,8 @@ static int bootcount_mem_set(struct udevice *dev, const u32 a)
uintptr_t flush_end;
if (priv->singleword) {
raw_bootcount_store(reg, (magic & BOOTCOUNT_MAGIC_MASK) | a);
raw_bootcount_store(reg, (magic & BOOTCOUNT_MAGIC_MASK)
| (a & BOOTCOUNT_COUNT_MASK));
flush_end = roundup(priv->base + 4,
CONFIG_SYS_CACHELINE_SIZE);
} else {