]>
git.ipfire.org Git - people/ms/u-boot.git/blob - tools/envcrc.c
3 * Paolo Scaffardi, AIRVENT SAM s.p.a - RIMINI(ITALY), arsenio@tin.it
5 * SPDX-License-Identifier: GPL-2.0+
16 #define __ASSEMBLY__ /* Dirty trick to get only #defines */
18 #define __ASM_STUB_PROCESSOR_H__ /* don't include asm/processor. */
22 #if defined(CONFIG_ENV_IS_IN_FLASH)
23 # ifndef CONFIG_ENV_ADDR
24 # define CONFIG_ENV_ADDR (CONFIG_SYS_FLASH_BASE + CONFIG_ENV_OFFSET)
26 # ifndef CONFIG_ENV_OFFSET
27 # define CONFIG_ENV_OFFSET (CONFIG_ENV_ADDR - CONFIG_SYS_FLASH_BASE)
29 # if !defined(CONFIG_ENV_ADDR_REDUND) && defined(CONFIG_ENV_OFFSET_REDUND)
30 # define CONFIG_ENV_ADDR_REDUND (CONFIG_SYS_FLASH_BASE + CONFIG_ENV_OFFSET_REDUND)
32 # ifndef CONFIG_ENV_SIZE
33 # define CONFIG_ENV_SIZE CONFIG_ENV_SECT_SIZE
35 # if defined(CONFIG_ENV_ADDR_REDUND) && !defined(CONFIG_ENV_SIZE_REDUND)
36 # define CONFIG_ENV_SIZE_REDUND CONFIG_ENV_SIZE
38 # if (CONFIG_ENV_ADDR >= CONFIG_SYS_MONITOR_BASE) && \
39 ((CONFIG_ENV_ADDR + CONFIG_ENV_SIZE) <= (CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN))
40 # define ENV_IS_EMBEDDED
42 # if defined(CONFIG_ENV_ADDR_REDUND) || defined(CONFIG_ENV_OFFSET_REDUND)
43 # define CONFIG_SYS_REDUNDAND_ENVIRONMENT
45 #endif /* CONFIG_ENV_IS_IN_FLASH */
47 #if defined(ENV_IS_EMBEDDED) && !defined(CONFIG_BUILD_ENVCRC)
48 # define CONFIG_BUILD_ENVCRC
51 #ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT
52 # define ENV_HEADER_SIZE (sizeof(uint32_t) + 1)
54 # define ENV_HEADER_SIZE (sizeof(uint32_t))
57 #define ENV_SIZE (CONFIG_ENV_SIZE - ENV_HEADER_SIZE)
60 #ifdef CONFIG_BUILD_ENVCRC
61 # include <environment.h>
62 extern unsigned int env_size
;
63 extern env_t environment
;
64 #endif /* CONFIG_BUILD_ENVCRC */
66 extern uint32_t crc32 (uint32_t, const unsigned char *, unsigned int);
68 int main (int argc
, char **argv
)
70 #ifdef CONFIG_BUILD_ENVCRC
71 unsigned char pad
= 0x00;
73 unsigned char *envptr
= (unsigned char *)&environment
,
74 *dataptr
= envptr
+ ENV_HEADER_SIZE
;
75 unsigned int datasize
= ENV_SIZE
;
78 if (argv
[1] && !strncmp(argv
[1], "--binary", 8)) {
80 if (argv
[1][8] == '=')
81 sscanf(argv
[1] + 9, "%i", &ipad
);
86 /* find the end of env */
87 for (eoe
= 0; eoe
< datasize
- 1; ++eoe
)
88 if (!dataptr
[eoe
] && !dataptr
[eoe
+1]) {
92 if (eoe
< datasize
- 1)
93 memset(dataptr
+ eoe
, pad
, datasize
- eoe
);
96 crc
= crc32 (0, dataptr
, datasize
);
98 /* Check if verbose mode is activated passing a parameter to the program */
100 if (!strncmp(argv
[1], "--binary", 8)) {
101 int le
= (argc
> 2 ? !strcmp(argv
[2], "le") : 1);
102 size_t i
, start
, end
, step
;
105 end
= ENV_HEADER_SIZE
;
108 start
= ENV_HEADER_SIZE
- 1;
112 for (i
= start
; i
!= end
; i
+= step
)
113 printf("%c", (crc
& (0xFF << (i
* 8))) >> (i
* 8));
114 if (fwrite(dataptr
, 1, datasize
, stdout
) != datasize
)
115 fprintf(stderr
, "fwrite() failed: %s\n", strerror(errno
));
117 printf("CRC32 from offset %08X to %08X of environment = %08X\n",
118 (unsigned int) (dataptr
- envptr
),
119 (unsigned int) (dataptr
- envptr
) + datasize
,
123 printf ("0x%08X\n", crc
);