]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
e4a95d11 | 2 | /* |
0044c42e | 3 | * (C) Copyright 2010-2012 |
e4a95d11 | 4 | * Stefan Roese, DENX Software Engineering, sr@denx.de. |
e4a95d11 SR |
5 | */ |
6 | ||
0044c42e SR |
7 | #include <bootcount.h> |
8 | #include <linux/compiler.h> | |
e4a95d11 | 9 | |
0044c42e | 10 | /* Now implement the generic default functions */ |
0044c42e | 11 | __weak void bootcount_store(ulong a) |
e4a95d11 SR |
12 | { |
13 | void *reg = (void *)CONFIG_SYS_BOOTCOUNT_ADDR; | |
14 | ||
15 | #if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD) | |
0044c42e | 16 | raw_bootcount_store(reg, (BOOTCOUNT_MAGIC & 0xffff0000) | a); |
e4a95d11 | 17 | #else |
0044c42e SR |
18 | raw_bootcount_store(reg, a); |
19 | raw_bootcount_store(reg + 4, BOOTCOUNT_MAGIC); | |
76765375 | 20 | #endif /* defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD */ |
e4a95d11 SR |
21 | } |
22 | ||
0044c42e | 23 | __weak ulong bootcount_load(void) |
e4a95d11 SR |
24 | { |
25 | void *reg = (void *)CONFIG_SYS_BOOTCOUNT_ADDR; | |
26 | ||
27 | #if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD) | |
0044c42e | 28 | u32 tmp = raw_bootcount_load(reg); |
59dde44a MW |
29 | |
30 | if ((tmp & 0xffff0000) != (BOOTCOUNT_MAGIC & 0xffff0000)) | |
e4a95d11 SR |
31 | return 0; |
32 | else | |
59dde44a | 33 | return (tmp & 0x0000ffff); |
e4a95d11 | 34 | #else |
0044c42e | 35 | if (raw_bootcount_load(reg + 4) != BOOTCOUNT_MAGIC) |
e4a95d11 SR |
36 | return 0; |
37 | else | |
0044c42e | 38 | return raw_bootcount_load(reg); |
76765375 | 39 | #endif /* defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD) */ |
e4a95d11 | 40 | } |