1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2010-2012
4 * Stefan Roese, DENX Software Engineering, sr@denx.de.
8 #include <linux/compiler.h>
10 /* Now implement the generic default functions */
11 __weak void bootcount_store(ulong a)
13 void *reg = (void *)CONFIG_SYS_BOOTCOUNT_ADDR;
15 #if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD)
16 raw_bootcount_store(reg, (BOOTCOUNT_MAGIC & 0xffff0000) | a);
18 raw_bootcount_store(reg, a);
19 raw_bootcount_store(reg + 4, BOOTCOUNT_MAGIC);
20 #endif /* defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD */
21 flush_dcache_range(CONFIG_SYS_BOOTCOUNT_ADDR,
22 CONFIG_SYS_BOOTCOUNT_ADDR +
23 CONFIG_SYS_CACHELINE_SIZE);
26 __weak ulong bootcount_load(void)
28 void *reg = (void *)CONFIG_SYS_BOOTCOUNT_ADDR;
30 #if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD)
31 u32 tmp = raw_bootcount_load(reg);
33 if ((tmp & 0xffff0000) != (BOOTCOUNT_MAGIC & 0xffff0000))
36 return (tmp & 0x0000ffff);
38 if (raw_bootcount_load(reg + 4) != BOOTCOUNT_MAGIC)
41 return raw_bootcount_load(reg);
42 #endif /* defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD) */