Stefan Roese | e4a95d1 | 2010-04-28 10:47:36 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2010 |
| 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 | |
| 24 | #include <common.h> |
| 25 | #include <asm/io.h> |
| 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 | |
| 38 | #if defined(CONFIG_8xx) |
| 39 | #define CONFIG_SYS_BOOTCOUNT_ADDR (((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_dpmem + \ |
| 40 | CPM_BOOTCOUNT_ADDR) |
| 41 | #endif /* defined(CONFIG_8xx) */ |
| 42 | |
| 43 | #if defined(CONFIG_MPC8260) |
| 44 | #include <asm/cpm_8260.h> |
| 45 | |
| 46 | #define CONFIG_SYS_BOOTCOUNT_ADDR (CONFIG_SYS_IMMR + CPM_BOOTCOUNT_ADDR) |
| 47 | #endif /* defined(CONFIG_MPC8260) */ |
| 48 | |
| 49 | #if defined(CONFIG_MPC8360) |
| 50 | #include <asm/immap_qe.h> |
| 51 | |
| 52 | #define CONFIG_SYS_BOOTCOUNT_ADDR (CONFIG_SYS_IMMR + 0x110000 + \ |
| 53 | QE_MURAM_SIZE - 2 * sizeof(u32)) |
| 54 | #endif /* defined(CONFIG_MPC8360) */ |
| 55 | |
| 56 | #if defined(CONFIG_4xx) |
| 57 | #define CONFIG_SYS_BOOTCOUNT_ADDR (CONFIG_SYS_OCM_DATA_ADDR + \ |
| 58 | CONFIG_SYS_BOOTCOUNT_ADDR) |
| 59 | #endif /* defined(CONFIG_4xx) */ |
| 60 | |
| 61 | #endif /* !defined(CONFIG_SYS_BOOTCOUNT_ADDR) */ |
| 62 | |
| 63 | void bootcount_store(ulong a) |
| 64 | { |
| 65 | void *reg = (void *)CONFIG_SYS_BOOTCOUNT_ADDR; |
| 66 | |
| 67 | #if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD) |
| 68 | out_be32(reg, (BOOTCOUNT_MAGIC & 0xffff0000) | a); |
| 69 | #else |
| 70 | out_be32(reg, a); |
| 71 | out_be32(reg + 4, BOOTCOUNT_MAGIC); |
| 72 | #endif |
| 73 | } |
| 74 | |
| 75 | ulong bootcount_load(void) |
| 76 | { |
| 77 | void *reg = (void *)CONFIG_SYS_BOOTCOUNT_ADDR; |
| 78 | |
| 79 | #if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD) |
| 80 | if (in_be16(reg + 2) != (BOOTCOUNT_MAGIC & 0xffff)) |
| 81 | return 0; |
| 82 | else |
| 83 | return in_be16(reg); |
| 84 | #else |
| 85 | if (in_be32(reg + 4) != BOOTCOUNT_MAGIC) |
| 86 | return 0; |
| 87 | else |
| 88 | return in_be32(reg); |
| 89 | #endif |
| 90 | } |