]>
Commit | Line | Data |
---|---|---|
fe57bb19 WD |
1 | /* |
2 | * (C) Copyright 2001 | |
3 | * Paolo Scaffardi, AIRVENT SAM s.p.a - RIMINI(ITALY), [email protected] | |
4 | * | |
1a459660 | 5 | * SPDX-License-Identifier: GPL-2.0+ |
fe57bb19 WD |
6 | */ |
7 | ||
f67066b6 | 8 | #include <errno.h> |
fe57bb19 | 9 | #include <stdio.h> |
89cdab78 | 10 | #include <stdint.h> |
fe57bb19 | 11 | #include <stdlib.h> |
837db3d8 | 12 | #include <string.h> |
fe57bb19 WD |
13 | #include <unistd.h> |
14 | ||
dc17fb6d WD |
15 | #ifndef __ASSEMBLY__ |
16 | #define __ASSEMBLY__ /* Dirty trick to get only #defines */ | |
17 | #endif | |
18 | #define __ASM_STUB_PROCESSOR_H__ /* don't include asm/processor. */ | |
fe57bb19 WD |
19 | #include <config.h> |
20 | #undef __ASSEMBLY__ | |
21 | ||
5a1aceb0 | 22 | #if defined(CONFIG_ENV_IS_IN_FLASH) |
0e8d1586 | 23 | # ifndef CONFIG_ENV_ADDR |
6d0f6bcf | 24 | # define CONFIG_ENV_ADDR (CONFIG_SYS_FLASH_BASE + CONFIG_ENV_OFFSET) |
fe57bb19 | 25 | # endif |
0e8d1586 | 26 | # ifndef CONFIG_ENV_OFFSET |
6d0f6bcf | 27 | # define CONFIG_ENV_OFFSET (CONFIG_ENV_ADDR - CONFIG_SYS_FLASH_BASE) |
fe57bb19 | 28 | # endif |
0e8d1586 | 29 | # if !defined(CONFIG_ENV_ADDR_REDUND) && defined(CONFIG_ENV_OFFSET_REDUND) |
6d0f6bcf | 30 | # define CONFIG_ENV_ADDR_REDUND (CONFIG_SYS_FLASH_BASE + CONFIG_ENV_OFFSET_REDUND) |
43d9616c | 31 | # endif |
0e8d1586 JCPV |
32 | # ifndef CONFIG_ENV_SIZE |
33 | # define CONFIG_ENV_SIZE CONFIG_ENV_SECT_SIZE | |
fe57bb19 | 34 | # endif |
0e8d1586 JCPV |
35 | # if defined(CONFIG_ENV_ADDR_REDUND) && !defined(CONFIG_ENV_SIZE_REDUND) |
36 | # define CONFIG_ENV_SIZE_REDUND CONFIG_ENV_SIZE | |
43d9616c | 37 | # endif |
a747a7f3 WD |
38 | # if (CONFIG_ENV_ADDR >= CONFIG_SYS_MONITOR_BASE) && \ |
39 | ((CONFIG_ENV_ADDR + CONFIG_ENV_SIZE) <= (CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN)) | |
6f403bad | 40 | # define ENV_IS_EMBEDDED |
a747a7f3 | 41 | # endif |
0e8d1586 | 42 | # if defined(CONFIG_ENV_ADDR_REDUND) || defined(CONFIG_ENV_OFFSET_REDUND) |
6f403bad | 43 | # define CONFIG_SYS_REDUNDAND_ENVIRONMENT |
fe57bb19 | 44 | # endif |
5a1aceb0 | 45 | #endif /* CONFIG_ENV_IS_IN_FLASH */ |
fe57bb19 | 46 | |
c3eb3fe4 | 47 | #if defined(ENV_IS_EMBEDDED) && !defined(CONFIG_BUILD_ENVCRC) |
6f403bad | 48 | # define CONFIG_BUILD_ENVCRC |
c3eb3fe4 MF |
49 | #endif |
50 | ||
6d0f6bcf | 51 | #ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT |
89cdab78 | 52 | # define ENV_HEADER_SIZE (sizeof(uint32_t) + 1) |
43d9616c | 53 | #else |
89cdab78 | 54 | # define ENV_HEADER_SIZE (sizeof(uint32_t)) |
43d9616c WD |
55 | #endif |
56 | ||
0e8d1586 | 57 | #define ENV_SIZE (CONFIG_ENV_SIZE - ENV_HEADER_SIZE) |
43d9616c WD |
58 | |
59 | ||
c3eb3fe4 | 60 | #ifdef CONFIG_BUILD_ENVCRC |
73f94ed4 | 61 | # include <environment.h> |
fe57bb19 | 62 | extern unsigned int env_size; |
994bc671 | 63 | extern env_t environment; |
c3eb3fe4 | 64 | #endif /* CONFIG_BUILD_ENVCRC */ |
fe57bb19 | 65 | |
73f94ed4 IG |
66 | extern uint32_t crc32 (uint32_t, const unsigned char *, unsigned int); |
67 | ||
fe57bb19 WD |
68 | int main (int argc, char **argv) |
69 | { | |
c3eb3fe4 | 70 | #ifdef CONFIG_BUILD_ENVCRC |
837db3d8 | 71 | unsigned char pad = 0x00; |
89cdab78 | 72 | uint32_t crc; |
994bc671 | 73 | unsigned char *envptr = (unsigned char *)&environment, |
dc17fb6d WD |
74 | *dataptr = envptr + ENV_HEADER_SIZE; |
75 | unsigned int datasize = ENV_SIZE; | |
837db3d8 MF |
76 | unsigned int eoe; |
77 | ||
78 | if (argv[1] && !strncmp(argv[1], "--binary", 8)) { | |
79 | int ipad = 0xff; | |
80 | if (argv[1][8] == '=') | |
81 | sscanf(argv[1] + 9, "%i", &ipad); | |
82 | pad = ipad; | |
83 | } | |
84 | ||
85 | if (pad) { | |
86 | /* find the end of env */ | |
87 | for (eoe = 0; eoe < datasize - 1; ++eoe) | |
88 | if (!dataptr[eoe] && !dataptr[eoe+1]) { | |
89 | eoe += 2; | |
90 | break; | |
91 | } | |
92 | if (eoe < datasize - 1) | |
93 | memset(dataptr + eoe, pad, datasize - eoe); | |
94 | } | |
fe57bb19 | 95 | |
dc17fb6d | 96 | crc = crc32 (0, dataptr, datasize); |
fe57bb19 | 97 | |
dc17fb6d WD |
98 | /* Check if verbose mode is activated passing a parameter to the program */ |
99 | if (argc > 1) { | |
837db3d8 MF |
100 | if (!strncmp(argv[1], "--binary", 8)) { |
101 | int le = (argc > 2 ? !strcmp(argv[2], "le") : 1); | |
102 | size_t i, start, end, step; | |
103 | if (le) { | |
104 | start = 0; | |
105 | end = ENV_HEADER_SIZE; | |
106 | step = 1; | |
107 | } else { | |
108 | start = ENV_HEADER_SIZE - 1; | |
109 | end = -1; | |
110 | step = -1; | |
111 | } | |
112 | for (i = start; i != end; i += step) | |
113 | printf("%c", (crc & (0xFF << (i * 8))) >> (i * 8)); | |
f67066b6 MF |
114 | if (fwrite(dataptr, 1, datasize, stdout) != datasize) |
115 | fprintf(stderr, "fwrite() failed: %s\n", strerror(errno)); | |
837db3d8 MF |
116 | } else { |
117 | printf("CRC32 from offset %08X to %08X of environment = %08X\n", | |
118 | (unsigned int) (dataptr - envptr), | |
119 | (unsigned int) (dataptr - envptr) + datasize, | |
120 | crc); | |
121 | } | |
dc17fb6d WD |
122 | } else { |
123 | printf ("0x%08X\n", crc); | |
124 | } | |
a747a7f3 WD |
125 | #else |
126 | printf ("0\n"); | |
127 | #endif | |
dc17fb6d | 128 | return EXIT_SUCCESS; |
fe57bb19 | 129 | } |