]> git.ipfire.org Git - people/ms/u-boot.git/blame - drivers/bootcount/bootcount.c
powerpc: remove 4xx support
[people/ms/u-boot.git] / drivers / bootcount / bootcount.c
CommitLineData
e4a95d11 1/*
0044c42e 2 * (C) Copyright 2010-2012
e4a95d11
SR
3 * Stefan Roese, DENX Software Engineering, sr@denx.de.
4 *
1a459660 5 * SPDX-License-Identifier: GPL-2.0+
e4a95d11
SR
6 */
7
0044c42e
SR
8#include <bootcount.h>
9#include <linux/compiler.h>
e4a95d11
SR
10
11/*
12 * Only override CONFIG_SYS_BOOTCOUNT_ADDR if not already defined. This
13 * way, some boards can define it directly in their config header.
14 */
15#if !defined(CONFIG_SYS_BOOTCOUNT_ADDR)
16
62ddcf05 17#if defined(CONFIG_QE)
38d67a4e 18#include <linux/immap_qe.h>
e4a95d11
SR
19#define CONFIG_SYS_BOOTCOUNT_ADDR (CONFIG_SYS_IMMR + 0x110000 + \
20 QE_MURAM_SIZE - 2 * sizeof(u32))
76765375 21#endif /* defined(CONFIG_QE) */
e4a95d11 22
e4a95d11
SR
23#endif /* !defined(CONFIG_SYS_BOOTCOUNT_ADDR) */
24
0044c42e
SR
25/* Now implement the generic default functions */
26#if defined(CONFIG_SYS_BOOTCOUNT_ADDR)
27__weak void bootcount_store(ulong a)
e4a95d11
SR
28{
29 void *reg = (void *)CONFIG_SYS_BOOTCOUNT_ADDR;
30
31#if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD)
0044c42e 32 raw_bootcount_store(reg, (BOOTCOUNT_MAGIC & 0xffff0000) | a);
e4a95d11 33#else
0044c42e
SR
34 raw_bootcount_store(reg, a);
35 raw_bootcount_store(reg + 4, BOOTCOUNT_MAGIC);
76765375 36#endif /* defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD */
e4a95d11
SR
37}
38
0044c42e 39__weak ulong bootcount_load(void)
e4a95d11
SR
40{
41 void *reg = (void *)CONFIG_SYS_BOOTCOUNT_ADDR;
42
43#if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD)
0044c42e 44 u32 tmp = raw_bootcount_load(reg);
59dde44a
MW
45
46 if ((tmp & 0xffff0000) != (BOOTCOUNT_MAGIC & 0xffff0000))
e4a95d11
SR
47 return 0;
48 else
59dde44a 49 return (tmp & 0x0000ffff);
e4a95d11 50#else
0044c42e 51 if (raw_bootcount_load(reg + 4) != BOOTCOUNT_MAGIC)
e4a95d11
SR
52 return 0;
53 else
0044c42e 54 return raw_bootcount_load(reg);
76765375 55#endif /* defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD) */
e4a95d11 56}
76765375 57#endif /* defined(CONFIG_SYS_BOOTCOUNT_ADDR) */