blob: 7b7718324e13860f9167ffc0ebec600ff59ad9f8 [file] [log] [blame]
wdenkfe57bb12002-09-18 13:23:15 +00001/*
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 Denkdc17fb62005-08-03 22:32:02 +020028#ifndef __ASSEMBLY__
29#define __ASSEMBLY__ /* Dirty trick to get only #defines */
30#endif
31#define __ASM_STUB_PROCESSOR_H__ /* don't include asm/processor. */
wdenkfe57bb12002-09-18 13:23:15 +000032#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
wdenk43d96162003-03-06 00:02:04 +000042# 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
wdenkfe57bb12002-09-18 13:23:15 +000045# ifndef CFG_ENV_SIZE
46# define CFG_ENV_SIZE CFG_ENV_SECT_SIZE
47# endif
wdenk43d96162003-03-06 00:02:04 +000048# 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
wdenkfe57bb12002-09-18 13:23:15 +000057# endif
58#endif /* CFG_ENV_IS_IN_FLASH */
59
wdenk43d96162003-03-06 00:02:04 +000060#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
wdenkfe57bb12002-09-18 13:23:15 +000069extern unsigned long crc32 (unsigned long, const unsigned char *, unsigned int);
70
71#ifdef ENV_IS_EMBEDDED
72extern unsigned int env_size;
73extern unsigned char environment;
74#endif /* ENV_IS_EMBEDDED */
75
76int main (int argc, char **argv)
77{
78#ifdef ENV_IS_EMBEDDED
Wolfgang Denkdc17fb62005-08-03 22:32:02 +020079 int crc;
80 unsigned char *envptr = &environment,
81 *dataptr = envptr + ENV_HEADER_SIZE;
82 unsigned int datasize = ENV_SIZE;
wdenkfe57bb12002-09-18 13:23:15 +000083
Wolfgang Denkdc17fb62005-08-03 22:32:02 +020084 crc = crc32 (0, dataptr, datasize);
wdenkfe57bb12002-09-18 13:23:15 +000085
Wolfgang Denkdc17fb62005-08-03 22:32:02 +020086 /* 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 }
wdenkfe57bb12002-09-18 13:23:15 +000095#else
Wolfgang Denkdc17fb62005-08-03 22:32:02 +020096 printf ("0\n");
wdenkfe57bb12002-09-18 13:23:15 +000097#endif
Wolfgang Denkdc17fb62005-08-03 22:32:02 +020098 return EXIT_SUCCESS;
wdenkfe57bb12002-09-18 13:23:15 +000099}