]>
Commit | Line | Data |
---|---|---|
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 | 10 | |
0044c42e | 11 | /* Now implement the generic default functions */ |
0044c42e | 12 | __weak void bootcount_store(ulong a) |
e4a95d11 SR |
13 | { |
14 | void *reg = (void *)CONFIG_SYS_BOOTCOUNT_ADDR; | |
15 | ||
16 | #if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD) | |
0044c42e | 17 | raw_bootcount_store(reg, (BOOTCOUNT_MAGIC & 0xffff0000) | a); |
e4a95d11 | 18 | #else |
0044c42e SR |
19 | raw_bootcount_store(reg, a); |
20 | raw_bootcount_store(reg + 4, BOOTCOUNT_MAGIC); | |
76765375 | 21 | #endif /* defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD */ |
e4a95d11 SR |
22 | } |
23 | ||
0044c42e | 24 | __weak ulong bootcount_load(void) |
e4a95d11 SR |
25 | { |
26 | void *reg = (void *)CONFIG_SYS_BOOTCOUNT_ADDR; | |
27 | ||
28 | #if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD) | |
0044c42e | 29 | u32 tmp = raw_bootcount_load(reg); |
59dde44a MW |
30 | |
31 | if ((tmp & 0xffff0000) != (BOOTCOUNT_MAGIC & 0xffff0000)) | |
e4a95d11 SR |
32 | return 0; |
33 | else | |
59dde44a | 34 | return (tmp & 0x0000ffff); |
e4a95d11 | 35 | #else |
0044c42e | 36 | if (raw_bootcount_load(reg + 4) != BOOTCOUNT_MAGIC) |
e4a95d11 SR |
37 | return 0; |
38 | else | |
0044c42e | 39 | return raw_bootcount_load(reg); |
76765375 | 40 | #endif /* defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD) */ |
e4a95d11 | 41 | } |