Stefan Roese | e4a95d1 | 2010-04-28 10:47:36 +0200 | [diff] [blame] | 1 | /* |
Stefan Roese | 0044c42 | 2012-08-16 17:55:41 +0000 | [diff] [blame] | 2 | * (C) Copyright 2010-2012 |
Stefan Roese | e4a95d1 | 2010-04-28 10:47:36 +0200 | [diff] [blame] | 3 | * Stefan Roese, DENX Software Engineering, sr@denx.de. |
| 4 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Stefan Roese | e4a95d1 | 2010-04-28 10:47:36 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
Stefan Roese | 0044c42 | 2012-08-16 17:55:41 +0000 | [diff] [blame] | 8 | #include <bootcount.h> |
| 9 | #include <linux/compiler.h> |
Stefan Roese | e4a95d1 | 2010-04-28 10:47:36 +0200 | [diff] [blame] | 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 | |
Heiko Schocher | 62ddcf0 | 2010-02-18 08:08:25 +0100 | [diff] [blame] | 17 | #if defined(CONFIG_QE) |
Zhao Qiang | 38d67a4e | 2014-06-03 16:27:07 +0800 | [diff] [blame] | 18 | #include <linux/immap_qe.h> |
Stefan Roese | e4a95d1 | 2010-04-28 10:47:36 +0200 | [diff] [blame] | 19 | #define CONFIG_SYS_BOOTCOUNT_ADDR (CONFIG_SYS_IMMR + 0x110000 + \ |
| 20 | QE_MURAM_SIZE - 2 * sizeof(u32)) |
Robert P. J. Day | 7676537 | 2015-12-22 07:15:14 -0500 | [diff] [blame] | 21 | #endif /* defined(CONFIG_QE) */ |
Stefan Roese | e4a95d1 | 2010-04-28 10:47:36 +0200 | [diff] [blame] | 22 | |
Stefan Roese | e4a95d1 | 2010-04-28 10:47:36 +0200 | [diff] [blame] | 23 | #endif /* !defined(CONFIG_SYS_BOOTCOUNT_ADDR) */ |
| 24 | |
Stefan Roese | 0044c42 | 2012-08-16 17:55:41 +0000 | [diff] [blame] | 25 | /* Now implement the generic default functions */ |
| 26 | #if defined(CONFIG_SYS_BOOTCOUNT_ADDR) |
| 27 | __weak void bootcount_store(ulong a) |
Stefan Roese | e4a95d1 | 2010-04-28 10:47:36 +0200 | [diff] [blame] | 28 | { |
| 29 | void *reg = (void *)CONFIG_SYS_BOOTCOUNT_ADDR; |
| 30 | |
| 31 | #if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD) |
Stefan Roese | 0044c42 | 2012-08-16 17:55:41 +0000 | [diff] [blame] | 32 | raw_bootcount_store(reg, (BOOTCOUNT_MAGIC & 0xffff0000) | a); |
Stefan Roese | e4a95d1 | 2010-04-28 10:47:36 +0200 | [diff] [blame] | 33 | #else |
Stefan Roese | 0044c42 | 2012-08-16 17:55:41 +0000 | [diff] [blame] | 34 | raw_bootcount_store(reg, a); |
| 35 | raw_bootcount_store(reg + 4, BOOTCOUNT_MAGIC); |
Robert P. J. Day | 7676537 | 2015-12-22 07:15:14 -0500 | [diff] [blame] | 36 | #endif /* defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD */ |
Stefan Roese | e4a95d1 | 2010-04-28 10:47:36 +0200 | [diff] [blame] | 37 | } |
| 38 | |
Stefan Roese | 0044c42 | 2012-08-16 17:55:41 +0000 | [diff] [blame] | 39 | __weak ulong bootcount_load(void) |
Stefan Roese | e4a95d1 | 2010-04-28 10:47:36 +0200 | [diff] [blame] | 40 | { |
| 41 | void *reg = (void *)CONFIG_SYS_BOOTCOUNT_ADDR; |
| 42 | |
| 43 | #if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD) |
Stefan Roese | 0044c42 | 2012-08-16 17:55:41 +0000 | [diff] [blame] | 44 | u32 tmp = raw_bootcount_load(reg); |
Michael Weiss | 59dde44 | 2010-05-20 16:09:35 +0200 | [diff] [blame] | 45 | |
| 46 | if ((tmp & 0xffff0000) != (BOOTCOUNT_MAGIC & 0xffff0000)) |
Stefan Roese | e4a95d1 | 2010-04-28 10:47:36 +0200 | [diff] [blame] | 47 | return 0; |
| 48 | else |
Michael Weiss | 59dde44 | 2010-05-20 16:09:35 +0200 | [diff] [blame] | 49 | return (tmp & 0x0000ffff); |
Stefan Roese | e4a95d1 | 2010-04-28 10:47:36 +0200 | [diff] [blame] | 50 | #else |
Stefan Roese | 0044c42 | 2012-08-16 17:55:41 +0000 | [diff] [blame] | 51 | if (raw_bootcount_load(reg + 4) != BOOTCOUNT_MAGIC) |
Stefan Roese | e4a95d1 | 2010-04-28 10:47:36 +0200 | [diff] [blame] | 52 | return 0; |
| 53 | else |
Stefan Roese | 0044c42 | 2012-08-16 17:55:41 +0000 | [diff] [blame] | 54 | return raw_bootcount_load(reg); |
Robert P. J. Day | 7676537 | 2015-12-22 07:15:14 -0500 | [diff] [blame] | 55 | #endif /* defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD) */ |
Stefan Roese | e4a95d1 | 2010-04-28 10:47:36 +0200 | [diff] [blame] | 56 | } |
Robert P. J. Day | 7676537 | 2015-12-22 07:15:14 -0500 | [diff] [blame] | 57 | #endif /* defined(CONFIG_SYS_BOOTCOUNT_ADDR) */ |