blob: ff4986a6190269ed4659685fd9cb77d8c423fae2 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glassb8790452012-12-05 14:46:36 +00002/*
3 * Copyright (c) 2012 The Chromium OS Authors.
4 *
5 * (C) Copyright 2011
6 * Joe Hershberger, National Instruments, joe.hershberger@ni.com
7 *
8 * (C) Copyright 2000
9 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
Simon Glassb8790452012-12-05 14:46:36 +000010 */
11
Ruchika Guptac915ceb2015-01-23 16:01:58 +053012#ifndef USE_HOSTCC
Simon Glassb8790452012-12-05 14:46:36 +000013#include <common.h>
14#include <command.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060015#include <env.h>
Hung-ying Tyanf061b1a2014-03-03 12:19:28 +010016#include <malloc.h>
Joe Hershberger65b905b2015-03-22 17:08:59 -050017#include <mapmem.h>
Akshay Saraswatcbd8f2c2013-03-20 21:00:58 +000018#include <hw_sha.h>
Ruchika Guptac915ceb2015-01-23 16:01:58 +053019#include <asm/io.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090020#include <linux/errno.h>
Simon Glass48b6c6b2019-11-14 12:57:16 -070021#include <u-boot/crc.h>
Ruchika Guptac915ceb2015-01-23 16:01:58 +053022#else
23#include "mkimage.h"
24#include <time.h>
25#include <image.h>
26#endif /* !USE_HOSTCC*/
27
Simon Glassb8790452012-12-05 14:46:36 +000028#include <hash.h>
Ruchika Guptac915ceb2015-01-23 16:01:58 +053029#include <u-boot/crc.h>
Jeroen Hofsteebfe88fe2014-06-12 22:27:12 +020030#include <u-boot/sha1.h>
31#include <u-boot/sha256.h>
Ruchika Guptac915ceb2015-01-23 16:01:58 +053032#include <u-boot/md5.h>
Simon Glassb8790452012-12-05 14:46:36 +000033
T Karthik Reddya098b432019-03-16 15:23:01 +053034#if !defined(USE_HOSTCC) && defined(CONFIG_NEEDS_MANUAL_RELOC)
35DECLARE_GLOBAL_DATA_PTR;
36#endif
37
38static void reloc_update(void);
39
Tom Rini03361c72017-08-14 16:38:07 -040040#if defined(CONFIG_SHA1) && !defined(CONFIG_SHA_PROG_HW_ACCEL)
Hung-ying Tyanf061b1a2014-03-03 12:19:28 +010041static int hash_init_sha1(struct hash_algo *algo, void **ctxp)
42{
43 sha1_context *ctx = malloc(sizeof(sha1_context));
44 sha1_starts(ctx);
45 *ctxp = ctx;
46 return 0;
47}
48
49static int hash_update_sha1(struct hash_algo *algo, void *ctx, const void *buf,
50 unsigned int size, int is_last)
51{
52 sha1_update((sha1_context *)ctx, buf, size);
53 return 0;
54}
55
56static int hash_finish_sha1(struct hash_algo *algo, void *ctx, void *dest_buf,
57 int size)
58{
59 if (size < algo->digest_size)
60 return -1;
61
62 sha1_finish((sha1_context *)ctx, dest_buf);
63 free(ctx);
64 return 0;
65}
66#endif
67
Tom Rini03361c72017-08-14 16:38:07 -040068#if defined(CONFIG_SHA256) && !defined(CONFIG_SHA_PROG_HW_ACCEL)
Hung-ying Tyanf061b1a2014-03-03 12:19:28 +010069static int hash_init_sha256(struct hash_algo *algo, void **ctxp)
70{
71 sha256_context *ctx = malloc(sizeof(sha256_context));
72 sha256_starts(ctx);
73 *ctxp = ctx;
74 return 0;
75}
76
77static int hash_update_sha256(struct hash_algo *algo, void *ctx,
78 const void *buf, unsigned int size, int is_last)
79{
80 sha256_update((sha256_context *)ctx, buf, size);
81 return 0;
82}
83
84static int hash_finish_sha256(struct hash_algo *algo, void *ctx, void
85 *dest_buf, int size)
86{
87 if (size < algo->digest_size)
88 return -1;
89
90 sha256_finish((sha256_context *)ctx, dest_buf);
91 free(ctx);
92 return 0;
93}
94#endif
95
Philipp Tomsich6e2ac3e2018-11-25 19:22:19 +010096static int hash_init_crc16_ccitt(struct hash_algo *algo, void **ctxp)
97{
98 uint16_t *ctx = malloc(sizeof(uint16_t));
99 *ctx = 0;
100 *ctxp = ctx;
101 return 0;
102}
103
104static int hash_update_crc16_ccitt(struct hash_algo *algo, void *ctx,
105 const void *buf, unsigned int size,
106 int is_last)
107{
108 *((uint16_t *)ctx) = crc16_ccitt(*((uint16_t *)ctx), buf, size);
109 return 0;
110}
111
112static int hash_finish_crc16_ccitt(struct hash_algo *algo, void *ctx,
113 void *dest_buf, int size)
114{
115 if (size < algo->digest_size)
116 return -1;
117
118 *((uint16_t *)dest_buf) = *((uint16_t *)ctx);
119 free(ctx);
120 return 0;
121}
122
Hung-ying Tyanf061b1a2014-03-03 12:19:28 +0100123static int hash_init_crc32(struct hash_algo *algo, void **ctxp)
124{
125 uint32_t *ctx = malloc(sizeof(uint32_t));
126 *ctx = 0;
127 *ctxp = ctx;
128 return 0;
129}
130
131static int hash_update_crc32(struct hash_algo *algo, void *ctx,
132 const void *buf, unsigned int size, int is_last)
133{
134 *((uint32_t *)ctx) = crc32(*((uint32_t *)ctx), buf, size);
135 return 0;
136}
137
138static int hash_finish_crc32(struct hash_algo *algo, void *ctx, void *dest_buf,
139 int size)
140{
141 if (size < algo->digest_size)
142 return -1;
143
144 *((uint32_t *)dest_buf) = *((uint32_t *)ctx);
145 free(ctx);
146 return 0;
147}
148
Simon Glassb8790452012-12-05 14:46:36 +0000149/*
Tom Rini03361c72017-08-14 16:38:07 -0400150 * These are the hash algorithms we support. If we have hardware acceleration
151 * is enable we will use that, otherwise a software version of the algorithm.
152 * Note that algorithm names must be in lower case.
Simon Glassb8790452012-12-05 14:46:36 +0000153 */
154static struct hash_algo hash_algo[] = {
Tom Rini03361c72017-08-14 16:38:07 -0400155#ifdef CONFIG_SHA1
Akshay Saraswatcbd8f2c2013-03-20 21:00:58 +0000156 {
Tom Rini03361c72017-08-14 16:38:07 -0400157 .name = "sha1",
158 .digest_size = SHA1_SUM_LEN,
159 .chunk_size = CHUNKSZ_SHA1,
160#ifdef CONFIG_SHA_HW_ACCEL
161 .hash_func_ws = hw_sha1,
162#else
163 .hash_func_ws = sha1_csum_wd,
gaurav ranaef201592015-02-20 12:51:46 +0530164#endif
gaurav ranaef201592015-02-20 12:51:46 +0530165#ifdef CONFIG_SHA_PROG_HW_ACCEL
Tom Rini03361c72017-08-14 16:38:07 -0400166 .hash_init = hw_sha_init,
167 .hash_update = hw_sha_update,
168 .hash_finish = hw_sha_finish,
169#else
170 .hash_init = hash_init_sha1,
171 .hash_update = hash_update_sha1,
172 .hash_finish = hash_finish_sha1,
Akshay Saraswatcbd8f2c2013-03-20 21:00:58 +0000173#endif
Simon Glassb8790452012-12-05 14:46:36 +0000174 },
175#endif
176#ifdef CONFIG_SHA256
177 {
Tom Rini03361c72017-08-14 16:38:07 -0400178 .name = "sha256",
179 .digest_size = SHA256_SUM_LEN,
180 .chunk_size = CHUNKSZ_SHA256,
181#ifdef CONFIG_SHA_HW_ACCEL
182 .hash_func_ws = hw_sha256,
183#else
184 .hash_func_ws = sha256_csum_wd,
185#endif
186#ifdef CONFIG_SHA_PROG_HW_ACCEL
187 .hash_init = hw_sha_init,
188 .hash_update = hw_sha_update,
189 .hash_finish = hw_sha_finish,
190#else
191 .hash_init = hash_init_sha256,
192 .hash_update = hash_update_sha256,
193 .hash_finish = hash_finish_sha256,
194#endif
Simon Glassb8790452012-12-05 14:46:36 +0000195 },
196#endif
Simon Glass0bbd76f2013-02-24 20:30:22 +0000197 {
Philipp Tomsich6e2ac3e2018-11-25 19:22:19 +0100198 .name = "crc16-ccitt",
199 .digest_size = 2,
200 .chunk_size = CHUNKSZ,
201 .hash_func_ws = crc16_ccitt_wd_buf,
202 .hash_init = hash_init_crc16_ccitt,
203 .hash_update = hash_update_crc16_ccitt,
204 .hash_finish = hash_finish_crc16_ccitt,
205 },
206 {
Tom Rini03361c72017-08-14 16:38:07 -0400207 .name = "crc32",
208 .digest_size = 4,
209 .chunk_size = CHUNKSZ_CRC32,
210 .hash_func_ws = crc32_wd_buf,
211 .hash_init = hash_init_crc32,
212 .hash_update = hash_update_crc32,
213 .hash_finish = hash_finish_crc32,
Simon Glass0bbd76f2013-02-24 20:30:22 +0000214 },
Simon Glassb8790452012-12-05 14:46:36 +0000215};
216
Simon Glass0bbd76f2013-02-24 20:30:22 +0000217/* Try to minimize code size for boards that don't want much hashing */
Daniel Thompsona9e2c672017-05-19 17:26:58 +0100218#if defined(CONFIG_SHA256) || defined(CONFIG_CMD_SHA1SUM) || \
219 defined(CONFIG_CRC32_VERIFY) || defined(CONFIG_CMD_HASH)
Simon Glass0bbd76f2013-02-24 20:30:22 +0000220#define multi_hash() 1
221#else
222#define multi_hash() 0
223#endif
224
T Karthik Reddya098b432019-03-16 15:23:01 +0530225static void reloc_update(void)
226{
227#if !defined(USE_HOSTCC) && defined(CONFIG_NEEDS_MANUAL_RELOC)
228 int i;
229 static bool done;
230
231 if (!done) {
232 done = true;
233 for (i = 0; i < ARRAY_SIZE(hash_algo); i++) {
234 hash_algo[i].name += gd->reloc_off;
235 hash_algo[i].hash_func_ws += gd->reloc_off;
236 hash_algo[i].hash_init += gd->reloc_off;
237 hash_algo[i].hash_update += gd->reloc_off;
238 hash_algo[i].hash_finish += gd->reloc_off;
239 }
240 }
241#endif
242}
243
Ruchika Guptac915ceb2015-01-23 16:01:58 +0530244int hash_lookup_algo(const char *algo_name, struct hash_algo **algop)
245{
246 int i;
247
T Karthik Reddya098b432019-03-16 15:23:01 +0530248 reloc_update();
249
Ruchika Guptac915ceb2015-01-23 16:01:58 +0530250 for (i = 0; i < ARRAY_SIZE(hash_algo); i++) {
251 if (!strcmp(algo_name, hash_algo[i].name)) {
252 *algop = &hash_algo[i];
253 return 0;
254 }
255 }
256
257 debug("Unknown hash algorithm '%s'\n", algo_name);
258 return -EPROTONOSUPPORT;
259}
260
261int hash_progressive_lookup_algo(const char *algo_name,
262 struct hash_algo **algop)
263{
264 int i;
265
T Karthik Reddya098b432019-03-16 15:23:01 +0530266 reloc_update();
267
Ruchika Guptac915ceb2015-01-23 16:01:58 +0530268 for (i = 0; i < ARRAY_SIZE(hash_algo); i++) {
269 if (!strcmp(algo_name, hash_algo[i].name)) {
270 if (hash_algo[i].hash_init) {
271 *algop = &hash_algo[i];
272 return 0;
273 }
274 }
275 }
276
277 debug("Unknown hash algorithm '%s'\n", algo_name);
278 return -EPROTONOSUPPORT;
279}
280
281#ifndef USE_HOSTCC
Stefan Roese0ed2e462015-05-18 14:08:24 +0200282int hash_parse_string(const char *algo_name, const char *str, uint8_t *result)
283{
284 struct hash_algo *algo;
285 int ret;
286 int i;
287
288 ret = hash_lookup_algo(algo_name, &algo);
289 if (ret)
290 return ret;
291
292 for (i = 0; i < algo->digest_size; i++) {
293 char chr[3];
294
295 strncpy(chr, &str[i * 2], 2);
296 result[i] = simple_strtoul(chr, NULL, 16);
297 }
298
299 return 0;
300}
301
Tom Rini61738382016-01-05 08:47:48 -0500302int hash_block(const char *algo_name, const void *data, unsigned int len,
303 uint8_t *output, int *output_size)
304{
305 struct hash_algo *algo;
306 int ret;
307
308 ret = hash_lookup_algo(algo_name, &algo);
309 if (ret)
310 return ret;
311
312 if (output_size && *output_size < algo->digest_size) {
313 debug("Output buffer size %d too small (need %d bytes)",
314 *output_size, algo->digest_size);
315 return -ENOSPC;
316 }
317 if (output_size)
318 *output_size = algo->digest_size;
319 algo->hash_func_ws(data, len, output, algo->chunk_size);
320
321 return 0;
322}
323
324#if defined(CONFIG_CMD_HASH) || defined(CONFIG_CMD_SHA1SUM) || defined(CONFIG_CMD_CRC32)
Simon Glassb8790452012-12-05 14:46:36 +0000325/**
326 * store_result: Store the resulting sum to an address or variable
327 *
328 * @algo: Hash algorithm being used
329 * @sum: Hash digest (algo->digest_size bytes)
330 * @dest: Destination, interpreted as a hex address if it starts
Simon Glass80e345a2013-02-24 17:33:26 +0000331 * with * (or allow_env_vars is 0) or otherwise as an
332 * environment variable.
333 * @allow_env_vars: non-zero to permit storing the result to an
334 * variable environment
Simon Glassb8790452012-12-05 14:46:36 +0000335 */
Simon Glassa3b240b2014-06-12 07:24:41 -0600336static void store_result(struct hash_algo *algo, const uint8_t *sum,
Simon Glass80e345a2013-02-24 17:33:26 +0000337 const char *dest, int allow_env_vars)
Simon Glassb8790452012-12-05 14:46:36 +0000338{
339 unsigned int i;
Simon Glass80e345a2013-02-24 17:33:26 +0000340 int env_var = 0;
Simon Glassb8790452012-12-05 14:46:36 +0000341
Simon Glass80e345a2013-02-24 17:33:26 +0000342 /*
343 * If environment variables are allowed, then we assume that 'dest'
344 * is an environment variable, unless it starts with *, in which
345 * case we assume it is an address. If not allowed, it is always an
346 * address. This is to support the crc32 command.
347 */
348 if (allow_env_vars) {
349 if (*dest == '*')
350 dest++;
351 else
352 env_var = 1;
353 }
Simon Glassb8790452012-12-05 14:46:36 +0000354
Simon Glass80e345a2013-02-24 17:33:26 +0000355 if (env_var) {
Simon Glassb8790452012-12-05 14:46:36 +0000356 char str_output[HASH_MAX_DIGEST_SIZE * 2 + 1];
357 char *str_ptr = str_output;
358
359 for (i = 0; i < algo->digest_size; i++) {
360 sprintf(str_ptr, "%02x", sum[i]);
361 str_ptr += 2;
362 }
Jeroen Hofsteeb14c0522014-06-09 11:02:02 +0200363 *str_ptr = '\0';
Simon Glass6a38e412017-08-03 12:22:09 -0600364 env_set(dest, str_output);
Simon Glass80e345a2013-02-24 17:33:26 +0000365 } else {
Simon Glass68f15562013-02-24 17:33:31 +0000366 ulong addr;
367 void *buf;
Simon Glass80e345a2013-02-24 17:33:26 +0000368
Simon Glass68f15562013-02-24 17:33:31 +0000369 addr = simple_strtoul(dest, NULL, 16);
370 buf = map_sysmem(addr, algo->digest_size);
371 memcpy(buf, sum, algo->digest_size);
372 unmap_sysmem(buf);
Simon Glassb8790452012-12-05 14:46:36 +0000373 }
374}
375
376/**
377 * parse_verify_sum: Parse a hash verification parameter
378 *
379 * @algo: Hash algorithm being used
380 * @verify_str: Argument to parse. If it starts with * then it is
381 * interpreted as a hex address containing the hash.
382 * If the length is exactly the right number of hex digits
383 * for the digest size, then we assume it is a hex digest.
384 * Otherwise we assume it is an environment variable, and
385 * look up its value (it must contain a hex digest).
386 * @vsum: Returns binary digest value (algo->digest_size bytes)
Simon Glass80e345a2013-02-24 17:33:26 +0000387 * @allow_env_vars: non-zero to permit storing the result to an environment
388 * variable. If 0 then verify_str is assumed to be an
389 * address, and the * prefix is not expected.
Simon Glassb8790452012-12-05 14:46:36 +0000390 * @return 0 if ok, non-zero on error
391 */
Simon Glassa3b240b2014-06-12 07:24:41 -0600392static int parse_verify_sum(struct hash_algo *algo, char *verify_str,
393 uint8_t *vsum, int allow_env_vars)
Simon Glassb8790452012-12-05 14:46:36 +0000394{
Simon Glass80e345a2013-02-24 17:33:26 +0000395 int env_var = 0;
396
397 /* See comment above in store_result() */
398 if (allow_env_vars) {
399 if (*verify_str == '*')
400 verify_str++;
401 else
402 env_var = 1;
403 }
404
Nikolay Dimitrov810b84d2014-12-12 20:01:23 +0200405 if (!env_var) {
Simon Glass68f15562013-02-24 17:33:31 +0000406 ulong addr;
407 void *buf;
Simon Glassb8790452012-12-05 14:46:36 +0000408
Simon Glass68f15562013-02-24 17:33:31 +0000409 addr = simple_strtoul(verify_str, NULL, 16);
410 buf = map_sysmem(addr, algo->digest_size);
411 memcpy(vsum, buf, algo->digest_size);
Simon Glassb8790452012-12-05 14:46:36 +0000412 } else {
Simon Glassb8790452012-12-05 14:46:36 +0000413 char *vsum_str;
414 int digits = algo->digest_size * 2;
415
416 /*
417 * As with the original code from sha1sum.c, we assume that a
418 * string which matches the digest size exactly is a hex
419 * string and not an environment variable.
420 */
421 if (strlen(verify_str) == digits)
422 vsum_str = verify_str;
423 else {
Simon Glass64b723f2017-08-03 12:22:12 -0600424 vsum_str = env_get(verify_str);
Simon Glassb8790452012-12-05 14:46:36 +0000425 if (vsum_str == NULL || strlen(vsum_str) != digits) {
426 printf("Expected %d hex digits in env var\n",
427 digits);
428 return 1;
429 }
430 }
431
Stefan Roese0ed2e462015-05-18 14:08:24 +0200432 hash_parse_string(algo->name, vsum_str, vsum);
Simon Glassb8790452012-12-05 14:46:36 +0000433 }
434 return 0;
435}
436
Tom Rini61738382016-01-05 08:47:48 -0500437static void hash_show(struct hash_algo *algo, ulong addr, ulong len, uint8_t *output)
Simon Glassb8790452012-12-05 14:46:36 +0000438{
439 int i;
440
441 printf("%s for %08lx ... %08lx ==> ", algo->name, addr, addr + len - 1);
442 for (i = 0; i < algo->digest_size; i++)
443 printf("%02x", output[i]);
444}
445
Simon Glass80e345a2013-02-24 17:33:26 +0000446int hash_command(const char *algo_name, int flags, cmd_tbl_t *cmdtp, int flag,
Simon Glassb8790452012-12-05 14:46:36 +0000447 int argc, char * const argv[])
448{
Simon Glassb8790452012-12-05 14:46:36 +0000449 ulong addr, len;
Simon Glassb8790452012-12-05 14:46:36 +0000450
Nikolay Dimitrov810b84d2014-12-12 20:01:23 +0200451 if ((argc < 2) || ((flags & HASH_FLAG_VERIFY) && (argc < 3)))
Simon Glassb8790452012-12-05 14:46:36 +0000452 return CMD_RET_USAGE;
453
Simon Glass80e345a2013-02-24 17:33:26 +0000454 addr = simple_strtoul(*argv++, NULL, 16);
455 len = simple_strtoul(*argv++, NULL, 16);
456
Simon Glass0bbd76f2013-02-24 20:30:22 +0000457 if (multi_hash()) {
458 struct hash_algo *algo;
Breno Lima45e65122018-01-17 10:03:45 -0200459 u8 *output;
Simon Glassa3b240b2014-06-12 07:24:41 -0600460 uint8_t vsum[HASH_MAX_DIGEST_SIZE];
Simon Glass68f15562013-02-24 17:33:31 +0000461 void *buf;
Simon Glassb8790452012-12-05 14:46:36 +0000462
Hung-ying Tyanf061b1a2014-03-03 12:19:28 +0100463 if (hash_lookup_algo(algo_name, &algo)) {
Simon Glass0bbd76f2013-02-24 20:30:22 +0000464 printf("Unknown hash algorithm '%s'\n", algo_name);
465 return CMD_RET_USAGE;
466 }
467 argc -= 2;
468
469 if (algo->digest_size > HASH_MAX_DIGEST_SIZE) {
470 puts("HASH_MAX_DIGEST_SIZE exceeded\n");
471 return 1;
472 }
Simon Glassb8790452012-12-05 14:46:36 +0000473
Breno Lima45e65122018-01-17 10:03:45 -0200474 output = memalign(ARCH_DMA_MINALIGN,
475 sizeof(uint32_t) * HASH_MAX_DIGEST_SIZE);
476
Simon Glass68f15562013-02-24 17:33:31 +0000477 buf = map_sysmem(addr, len);
478 algo->hash_func_ws(buf, len, output, algo->chunk_size);
479 unmap_sysmem(buf);
Simon Glassb8790452012-12-05 14:46:36 +0000480
Simon Glass0bbd76f2013-02-24 20:30:22 +0000481 /* Try to avoid code bloat when verify is not needed */
Daniel Thompsona9e2c672017-05-19 17:26:58 +0100482#if defined(CONFIG_CRC32_VERIFY) || defined(CONFIG_SHA1SUM_VERIFY) || \
483 defined(CONFIG_HASH_VERIFY)
Simon Glass0bbd76f2013-02-24 20:30:22 +0000484 if (flags & HASH_FLAG_VERIFY) {
Simon Glassb8790452012-12-05 14:46:36 +0000485#else
Simon Glass0bbd76f2013-02-24 20:30:22 +0000486 if (0) {
Simon Glassb8790452012-12-05 14:46:36 +0000487#endif
Simon Glass0bbd76f2013-02-24 20:30:22 +0000488 if (parse_verify_sum(algo, *argv, vsum,
Simon Glass80e345a2013-02-24 17:33:26 +0000489 flags & HASH_FLAG_ENV)) {
Simon Glass0bbd76f2013-02-24 20:30:22 +0000490 printf("ERROR: %s does not contain a valid "
491 "%s sum\n", *argv, algo->name);
492 return 1;
493 }
494 if (memcmp(output, vsum, algo->digest_size) != 0) {
495 int i;
Simon Glassb8790452012-12-05 14:46:36 +0000496
Simon Glass7f3fa542014-06-02 22:04:49 -0600497 hash_show(algo, addr, len, output);
Simon Glass0bbd76f2013-02-24 20:30:22 +0000498 printf(" != ");
499 for (i = 0; i < algo->digest_size; i++)
500 printf("%02x", vsum[i]);
501 puts(" ** ERROR **\n");
502 return 1;
503 }
504 } else {
Simon Glass7f3fa542014-06-02 22:04:49 -0600505 hash_show(algo, addr, len, output);
Simon Glass0bbd76f2013-02-24 20:30:22 +0000506 printf("\n");
507
508 if (argc) {
509 store_result(algo, output, *argv,
510 flags & HASH_FLAG_ENV);
511 }
Breno Lima45e65122018-01-17 10:03:45 -0200512 unmap_sysmem(output);
513
Simon Glassb8790452012-12-05 14:46:36 +0000514 }
Simon Glass0bbd76f2013-02-24 20:30:22 +0000515
516 /* Horrible code size hack for boards that just want crc32 */
Simon Glassb8790452012-12-05 14:46:36 +0000517 } else {
Simon Glass0bbd76f2013-02-24 20:30:22 +0000518 ulong crc;
519 ulong *ptr;
520
521 crc = crc32_wd(0, (const uchar *)addr, len, CHUNKSZ_CRC32);
522
523 printf("CRC32 for %08lx ... %08lx ==> %08lx\n",
524 addr, addr + len - 1, crc);
Simon Glassb8790452012-12-05 14:46:36 +0000525
Tom Rini62780f02013-11-07 07:39:48 -0500526 if (argc >= 3) {
527 ptr = (ulong *)simple_strtoul(argv[0], NULL, 16);
Simon Glass0bbd76f2013-02-24 20:30:22 +0000528 *ptr = crc;
Simon Glass80e345a2013-02-24 17:33:26 +0000529 }
Simon Glassb8790452012-12-05 14:46:36 +0000530 }
531
532 return 0;
533}
Simon Glassb22ec7a2017-05-17 09:05:34 -0600534#endif /* CONFIG_CMD_HASH || CONFIG_CMD_SHA1SUM || CONFIG_CMD_CRC32) */
535#endif /* !USE_HOSTCC */