1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2010-2012
4 * Stefan Roese, DENX Software Engineering, sr@denx.de.
9 #include <linux/compiler.h>
11 /* Now implement the generic default functions */
12 __weak void bootcount_store(ulong a)
14 void *reg = (void *)CONFIG_SYS_BOOTCOUNT_ADDR;
15 uintptr_t flush_start = rounddown(CONFIG_SYS_BOOTCOUNT_ADDR,
16 CONFIG_SYS_CACHELINE_SIZE);
19 #if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD)
20 raw_bootcount_store(reg, (CONFIG_SYS_BOOTCOUNT_MAGIC & 0xffff0000) | a);
22 flush_end = roundup(CONFIG_SYS_BOOTCOUNT_ADDR + 4,
23 CONFIG_SYS_CACHELINE_SIZE);
25 raw_bootcount_store(reg, a);
26 raw_bootcount_store(reg + 4, CONFIG_SYS_BOOTCOUNT_MAGIC);
28 flush_end = roundup(CONFIG_SYS_BOOTCOUNT_ADDR + 8,
29 CONFIG_SYS_CACHELINE_SIZE);
30 #endif /* defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD */
31 flush_dcache_range(flush_start, flush_end);
34 __weak ulong bootcount_load(void)
36 void *reg = (void *)CONFIG_SYS_BOOTCOUNT_ADDR;
38 #if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD)
39 u32 tmp = raw_bootcount_load(reg);
41 if ((tmp & 0xffff0000) != (CONFIG_SYS_BOOTCOUNT_MAGIC & 0xffff0000))
44 return (tmp & 0x0000ffff);
46 if (raw_bootcount_load(reg + 4) != CONFIG_SYS_BOOTCOUNT_MAGIC)
49 return raw_bootcount_load(reg);
50 #endif /* defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD) */