wdenk | fe57bb1 | 2002-09-18 13:23:15 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2001 |
| 3 | * Paolo Scaffardi, AIRVENT SAM s.p.a - RIMINI(ITALY), arsenio@tin.it |
| 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 <stdio.h> |
| 25 | #include <stdlib.h> |
| 26 | #include <unistd.h> |
| 27 | |
Wolfgang Denk | db5f386 | 2005-08-03 22:32:02 +0200 | [diff] [blame] | 28 | #ifndef __ASSEMBLY__ |
| 29 | #define __ASSEMBLY__ /* Dirty trick to get only #defines */ |
| 30 | #endif |
| 31 | #define __ASM_STUB_PROCESSOR_H__ /* don't include asm/processor. */ |
wdenk | fe57bb1 | 2002-09-18 13:23:15 +0000 | [diff] [blame] | 32 | #include <config.h> |
| 33 | #undef __ASSEMBLY__ |
| 34 | |
| 35 | #if defined(CFG_ENV_IS_IN_FLASH) |
| 36 | # ifndef CFG_ENV_ADDR |
| 37 | # define CFG_ENV_ADDR (CFG_FLASH_BASE + CFG_ENV_OFFSET) |
| 38 | # endif |
| 39 | # ifndef CFG_ENV_OFFSET |
| 40 | # define CFG_ENV_OFFSET (CFG_ENV_ADDR - CFG_FLASH_BASE) |
| 41 | # endif |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 42 | # if !defined(CFG_ENV_ADDR_REDUND) && defined(CFG_ENV_OFFSET_REDUND) |
| 43 | # define CFG_ENV_ADDR_REDUND (CFG_FLASH_BASE + CFG_ENV_OFFSET_REDUND) |
| 44 | # endif |
wdenk | fe57bb1 | 2002-09-18 13:23:15 +0000 | [diff] [blame] | 45 | # ifndef CFG_ENV_SIZE |
| 46 | # define CFG_ENV_SIZE CFG_ENV_SECT_SIZE |
| 47 | # endif |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 48 | # if defined(CFG_ENV_ADDR_REDUND) && !defined(CFG_ENV_SIZE_REDUND) |
| 49 | # define CFG_ENV_SIZE_REDUND CFG_ENV_SIZE |
| 50 | # endif |
| 51 | # if (CFG_ENV_ADDR >= CFG_MONITOR_BASE) && \ |
| 52 | ((CFG_ENV_ADDR + CFG_ENV_SIZE) <= (CFG_MONITOR_BASE + CFG_MONITOR_LEN)) |
| 53 | # define ENV_IS_EMBEDDED 1 |
| 54 | # endif |
| 55 | # if defined(CFG_ENV_ADDR_REDUND) || defined(CFG_ENV_OFFSET_REDUND) |
| 56 | # define CFG_REDUNDAND_ENVIRONMENT 1 |
wdenk | fe57bb1 | 2002-09-18 13:23:15 +0000 | [diff] [blame] | 57 | # endif |
| 58 | #endif /* CFG_ENV_IS_IN_FLASH */ |
| 59 | |
wdenk | 4a5c8a7 | 2003-03-06 00:02:04 +0000 | [diff] [blame] | 60 | #ifdef CFG_REDUNDAND_ENVIRONMENT |
| 61 | # define ENV_HEADER_SIZE (sizeof(unsigned long) + 1) |
| 62 | #else |
| 63 | # define ENV_HEADER_SIZE (sizeof(unsigned long)) |
| 64 | #endif |
| 65 | |
| 66 | #define ENV_SIZE (CFG_ENV_SIZE - ENV_HEADER_SIZE) |
| 67 | |
| 68 | |
wdenk | fe57bb1 | 2002-09-18 13:23:15 +0000 | [diff] [blame] | 69 | extern unsigned long crc32 (unsigned long, const unsigned char *, unsigned int); |
| 70 | |
| 71 | #ifdef ENV_IS_EMBEDDED |
| 72 | extern unsigned int env_size; |
| 73 | extern unsigned char environment; |
| 74 | #endif /* ENV_IS_EMBEDDED */ |
| 75 | |
| 76 | int main (int argc, char **argv) |
| 77 | { |
| 78 | #ifdef ENV_IS_EMBEDDED |
Wolfgang Denk | db5f386 | 2005-08-03 22:32:02 +0200 | [diff] [blame] | 79 | int crc; |
| 80 | unsigned char *envptr = &environment, |
| 81 | *dataptr = envptr + ENV_HEADER_SIZE; |
| 82 | unsigned int datasize = ENV_SIZE; |
wdenk | fe57bb1 | 2002-09-18 13:23:15 +0000 | [diff] [blame] | 83 | |
Wolfgang Denk | db5f386 | 2005-08-03 22:32:02 +0200 | [diff] [blame] | 84 | crc = crc32 (0, dataptr, datasize); |
wdenk | fe57bb1 | 2002-09-18 13:23:15 +0000 | [diff] [blame] | 85 | |
Wolfgang Denk | db5f386 | 2005-08-03 22:32:02 +0200 | [diff] [blame] | 86 | /* Check if verbose mode is activated passing a parameter to the program */ |
| 87 | if (argc > 1) { |
| 88 | printf ("CRC32 from offset %08X to %08X of environment = %08X\n", |
| 89 | (unsigned int) (dataptr - envptr), |
| 90 | (unsigned int) (dataptr - envptr) + datasize, |
| 91 | crc); |
| 92 | } else { |
| 93 | printf ("0x%08X\n", crc); |
| 94 | } |
wdenk | fe57bb1 | 2002-09-18 13:23:15 +0000 | [diff] [blame] | 95 | #else |
Wolfgang Denk | db5f386 | 2005-08-03 22:32:02 +0200 | [diff] [blame] | 96 | printf ("0\n"); |
wdenk | fe57bb1 | 2002-09-18 13:23:15 +0000 | [diff] [blame] | 97 | #endif |
Wolfgang Denk | db5f386 | 2005-08-03 22:32:02 +0200 | [diff] [blame] | 98 | return EXIT_SUCCESS; |
wdenk | fe57bb1 | 2002-09-18 13:23:15 +0000 | [diff] [blame] | 99 | } |