Blame view
drivers/bootcount/bootcount.c
1.36 KB
83d290c56
|
1 |
// SPDX-License-Identifier: GPL-2.0+ |
e4a95d112
|
2 |
/* |
0044c42e9
|
3 |
* (C) Copyright 2010-2012 |
e4a95d112
|
4 |
* Stefan Roese, DENX Software Engineering, sr@denx.de. |
e4a95d112
|
5 |
*/ |
0044c42e9
|
6 7 |
#include <bootcount.h> #include <linux/compiler.h> |
e4a95d112
|
8 |
|
0044c42e9
|
9 |
/* Now implement the generic default functions */ |
0044c42e9
|
10 |
__weak void bootcount_store(ulong a) |
e4a95d112
|
11 12 |
{ void *reg = (void *)CONFIG_SYS_BOOTCOUNT_ADDR; |
fe9805fc7
|
13 14 15 |
uintptr_t flush_start = rounddown(CONFIG_SYS_BOOTCOUNT_ADDR, CONFIG_SYS_CACHELINE_SIZE); uintptr_t flush_end; |
e4a95d112
|
16 17 |
#if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD) |
758694ff0
|
18 |
raw_bootcount_store(reg, (CONFIG_SYS_BOOTCOUNT_MAGIC & 0xffff0000) | a); |
fe9805fc7
|
19 20 21 |
flush_end = roundup(CONFIG_SYS_BOOTCOUNT_ADDR + 4, CONFIG_SYS_CACHELINE_SIZE); |
e4a95d112
|
22 |
#else |
0044c42e9
|
23 |
raw_bootcount_store(reg, a); |
758694ff0
|
24 |
raw_bootcount_store(reg + 4, CONFIG_SYS_BOOTCOUNT_MAGIC); |
fe9805fc7
|
25 26 27 |
flush_end = roundup(CONFIG_SYS_BOOTCOUNT_ADDR + 8, CONFIG_SYS_CACHELINE_SIZE); |
76765375d
|
28 |
#endif /* defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD */ |
fe9805fc7
|
29 |
flush_dcache_range(flush_start, flush_end); |
e4a95d112
|
30 |
} |
0044c42e9
|
31 |
__weak ulong bootcount_load(void) |
e4a95d112
|
32 33 34 35 |
{ void *reg = (void *)CONFIG_SYS_BOOTCOUNT_ADDR; #if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD) |
0044c42e9
|
36 |
u32 tmp = raw_bootcount_load(reg); |
59dde44ac
|
37 |
|
758694ff0
|
38 |
if ((tmp & 0xffff0000) != (CONFIG_SYS_BOOTCOUNT_MAGIC & 0xffff0000)) |
e4a95d112
|
39 40 |
return 0; else |
59dde44ac
|
41 |
return (tmp & 0x0000ffff); |
e4a95d112
|
42 |
#else |
758694ff0
|
43 |
if (raw_bootcount_load(reg + 4) != CONFIG_SYS_BOOTCOUNT_MAGIC) |
e4a95d112
|
44 45 |
return 0; else |
0044c42e9
|
46 |
return raw_bootcount_load(reg); |
76765375d
|
47 |
#endif /* defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD) */ |
e4a95d112
|
48 |
} |