Stefan Roese | ed7aaf8 | 2010-04-28 10:47:36 +0200 | [diff] [blame] | 1 | /* |
Stefan Roese | 033848e | 2012-08-16 17:55:41 +0000 | [diff] [blame^] | 2 | * (C) Copyright 2010-2012 |
Stefan Roese | ed7aaf8 | 2010-04-28 10:47:36 +0200 | [diff] [blame] | 3 | * Stefan Roese, DENX Software Engineering, sr@denx.de. |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
Stefan Roese | 033848e | 2012-08-16 17:55:41 +0000 | [diff] [blame^] | 24 | #include <bootcount.h> |
| 25 | #include <linux/compiler.h> |
Stefan Roese | ed7aaf8 | 2010-04-28 10:47:36 +0200 | [diff] [blame] | 26 | |
| 27 | /* |
| 28 | * Only override CONFIG_SYS_BOOTCOUNT_ADDR if not already defined. This |
| 29 | * way, some boards can define it directly in their config header. |
| 30 | */ |
| 31 | #if !defined(CONFIG_SYS_BOOTCOUNT_ADDR) |
| 32 | |
| 33 | #if defined(CONFIG_MPC5xxx) |
| 34 | #define CONFIG_SYS_BOOTCOUNT_ADDR (MPC5XXX_CDM_BRDCRMB) |
| 35 | #define CONFIG_SYS_BOOTCOUNT_SINGLEWORD |
| 36 | #endif /* defined(CONFIG_MPC5xxx) */ |
| 37 | |
Michael Weiss | 7362571 | 2010-05-20 16:09:34 +0200 | [diff] [blame] | 38 | #if defined(CONFIG_MPC512X) |
| 39 | #define CONFIG_SYS_BOOTCOUNT_ADDR (&((immap_t *)CONFIG_SYS_IMMR)->clk.bcr) |
| 40 | #define CONFIG_SYS_BOOTCOUNT_SINGLEWORD |
| 41 | #endif /* defined(CONFIG_MPC512X) */ |
| 42 | |
Stefan Roese | ed7aaf8 | 2010-04-28 10:47:36 +0200 | [diff] [blame] | 43 | #if defined(CONFIG_8xx) |
| 44 | #define CONFIG_SYS_BOOTCOUNT_ADDR (((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_dpmem + \ |
| 45 | CPM_BOOTCOUNT_ADDR) |
| 46 | #endif /* defined(CONFIG_8xx) */ |
| 47 | |
| 48 | #if defined(CONFIG_MPC8260) |
| 49 | #include <asm/cpm_8260.h> |
| 50 | |
| 51 | #define CONFIG_SYS_BOOTCOUNT_ADDR (CONFIG_SYS_IMMR + CPM_BOOTCOUNT_ADDR) |
| 52 | #endif /* defined(CONFIG_MPC8260) */ |
| 53 | |
Heiko Schocher | 466924f | 2010-02-18 08:08:25 +0100 | [diff] [blame] | 54 | #if defined(CONFIG_QE) |
Stefan Roese | ed7aaf8 | 2010-04-28 10:47:36 +0200 | [diff] [blame] | 55 | #include <asm/immap_qe.h> |
| 56 | |
| 57 | #define CONFIG_SYS_BOOTCOUNT_ADDR (CONFIG_SYS_IMMR + 0x110000 + \ |
| 58 | QE_MURAM_SIZE - 2 * sizeof(u32)) |
| 59 | #endif /* defined(CONFIG_MPC8360) */ |
| 60 | |
| 61 | #if defined(CONFIG_4xx) |
| 62 | #define CONFIG_SYS_BOOTCOUNT_ADDR (CONFIG_SYS_OCM_DATA_ADDR + \ |
| 63 | CONFIG_SYS_BOOTCOUNT_ADDR) |
| 64 | #endif /* defined(CONFIG_4xx) */ |
| 65 | |
| 66 | #endif /* !defined(CONFIG_SYS_BOOTCOUNT_ADDR) */ |
| 67 | |
Stefan Roese | 033848e | 2012-08-16 17:55:41 +0000 | [diff] [blame^] | 68 | /* Now implement the generic default functions */ |
| 69 | #if defined(CONFIG_SYS_BOOTCOUNT_ADDR) |
| 70 | __weak void bootcount_store(ulong a) |
Stefan Roese | ed7aaf8 | 2010-04-28 10:47:36 +0200 | [diff] [blame] | 71 | { |
| 72 | void *reg = (void *)CONFIG_SYS_BOOTCOUNT_ADDR; |
| 73 | |
| 74 | #if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD) |
Stefan Roese | 033848e | 2012-08-16 17:55:41 +0000 | [diff] [blame^] | 75 | raw_bootcount_store(reg, (BOOTCOUNT_MAGIC & 0xffff0000) | a); |
Stefan Roese | ed7aaf8 | 2010-04-28 10:47:36 +0200 | [diff] [blame] | 76 | #else |
Stefan Roese | 033848e | 2012-08-16 17:55:41 +0000 | [diff] [blame^] | 77 | raw_bootcount_store(reg, a); |
| 78 | raw_bootcount_store(reg + 4, BOOTCOUNT_MAGIC); |
Stefan Roese | ed7aaf8 | 2010-04-28 10:47:36 +0200 | [diff] [blame] | 79 | #endif |
| 80 | } |
| 81 | |
Stefan Roese | 033848e | 2012-08-16 17:55:41 +0000 | [diff] [blame^] | 82 | __weak ulong bootcount_load(void) |
Stefan Roese | ed7aaf8 | 2010-04-28 10:47:36 +0200 | [diff] [blame] | 83 | { |
| 84 | void *reg = (void *)CONFIG_SYS_BOOTCOUNT_ADDR; |
| 85 | |
| 86 | #if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD) |
Stefan Roese | 033848e | 2012-08-16 17:55:41 +0000 | [diff] [blame^] | 87 | u32 tmp = raw_bootcount_load(reg); |
Michael Weiss | 8eed66d | 2010-05-20 16:09:35 +0200 | [diff] [blame] | 88 | |
| 89 | if ((tmp & 0xffff0000) != (BOOTCOUNT_MAGIC & 0xffff0000)) |
Stefan Roese | ed7aaf8 | 2010-04-28 10:47:36 +0200 | [diff] [blame] | 90 | return 0; |
| 91 | else |
Michael Weiss | 8eed66d | 2010-05-20 16:09:35 +0200 | [diff] [blame] | 92 | return (tmp & 0x0000ffff); |
Stefan Roese | ed7aaf8 | 2010-04-28 10:47:36 +0200 | [diff] [blame] | 93 | #else |
Stefan Roese | 033848e | 2012-08-16 17:55:41 +0000 | [diff] [blame^] | 94 | if (raw_bootcount_load(reg + 4) != BOOTCOUNT_MAGIC) |
Stefan Roese | ed7aaf8 | 2010-04-28 10:47:36 +0200 | [diff] [blame] | 95 | return 0; |
| 96 | else |
Stefan Roese | 033848e | 2012-08-16 17:55:41 +0000 | [diff] [blame^] | 97 | return raw_bootcount_load(reg); |
Stefan Roese | ed7aaf8 | 2010-04-28 10:47:36 +0200 | [diff] [blame] | 98 | #endif |
| 99 | } |
Stefan Roese | 033848e | 2012-08-16 17:55:41 +0000 | [diff] [blame^] | 100 | #endif |