2 * (C) Copyright 2010-2012
3 * Stefan Roese, DENX Software Engineering, sr@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
9 #include <linux/compiler.h>
12 * Only override CONFIG_SYS_BOOTCOUNT_ADDR if not already defined. This
13 * way, some boards can define it directly in their config header.
15 #if !defined(CONFIG_SYS_BOOTCOUNT_ADDR)
17 #if defined(CONFIG_QE)
18 #include <linux/immap_qe.h>
19 #define CONFIG_SYS_BOOTCOUNT_ADDR (CONFIG_SYS_IMMR + 0x110000 + \
20 QE_MURAM_SIZE - 2 * sizeof(u32))
21 #endif /* defined(CONFIG_QE) */
23 #endif /* !defined(CONFIG_SYS_BOOTCOUNT_ADDR) */
25 /* Now implement the generic default functions */
26 #if defined(CONFIG_SYS_BOOTCOUNT_ADDR)
27 __weak void bootcount_store(ulong a)
29 void *reg = (void *)CONFIG_SYS_BOOTCOUNT_ADDR;
31 #if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD)
32 raw_bootcount_store(reg, (BOOTCOUNT_MAGIC & 0xffff0000) | a);
34 raw_bootcount_store(reg, a);
35 raw_bootcount_store(reg + 4, BOOTCOUNT_MAGIC);
36 #endif /* defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD */
39 __weak ulong bootcount_load(void)
41 void *reg = (void *)CONFIG_SYS_BOOTCOUNT_ADDR;
43 #if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD)
44 u32 tmp = raw_bootcount_load(reg);
46 if ((tmp & 0xffff0000) != (BOOTCOUNT_MAGIC & 0xffff0000))
49 return (tmp & 0x0000ffff);
51 if (raw_bootcount_load(reg + 4) != BOOTCOUNT_MAGIC)
54 return raw_bootcount_load(reg);
55 #endif /* defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD) */
57 #endif /* defined(CONFIG_SYS_BOOTCOUNT_ADDR) */