blob: 2cf763575f9d5fa94e0d4a0a057cb5029afd3819 [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>
Simon Glass274e0b02020-05-10 11:39:56 -060019#include <asm/cache.h>
Ruchika Guptac915ceb2015-01-23 16:01:58 +053020#include <asm/io.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090021#include <linux/errno.h>
Simon Glass48b6c6b2019-11-14 12:57:16 -070022#include <u-boot/crc.h>
Ruchika Guptac915ceb2015-01-23 16:01:58 +053023#else
24#include "mkimage.h"
25#include <time.h>
26#include <image.h>
27#endif /* !USE_HOSTCC*/
28
Simon Glassb8790452012-12-05 14:46:36 +000029#include <hash.h>
Ruchika Guptac915ceb2015-01-23 16:01:58 +053030#include <u-boot/crc.h>
Jeroen Hofsteebfe88fe2014-06-12 22:27:12 +020031#include <u-boot/sha1.h>
32#include <u-boot/sha256.h>
Ruchika Guptac915ceb2015-01-23 16:01:58 +053033#include <u-boot/md5.h>
Simon Glassb8790452012-12-05 14:46:36 +000034
T Karthik Reddya098b432019-03-16 15:23:01 +053035#if !defined(USE_HOSTCC) && defined(CONFIG_NEEDS_MANUAL_RELOC)
36DECLARE_GLOBAL_DATA_PTR;
37#endif
38
39static void reloc_update(void);
40
Tom Rini03361c72017-08-14 16:38:07 -040041#if defined(CONFIG_SHA1) && !defined(CONFIG_SHA_PROG_HW_ACCEL)
Hung-ying Tyanf061b1a2014-03-03 12:19:28 +010042static int hash_init_sha1(struct hash_algo *algo, void **ctxp)
43{
44 sha1_context *ctx = malloc(sizeof(sha1_context));
45 sha1_starts(ctx);
46 *ctxp = ctx;
47 return 0;
48}
49
50static int hash_update_sha1(struct hash_algo *algo, void *ctx, const void *buf,
51 unsigned int size, int is_last)
52{
53 sha1_update((sha1_context *)ctx, buf, size);
54 return 0;
55}
56
57static int hash_finish_sha1(struct hash_algo *algo, void *ctx, void *dest_buf,
58 int size)
59{
60 if (size < algo->digest_size)
61 return -1;
62
63 sha1_finish((sha1_context *)ctx, dest_buf);
64 free(ctx);
65 return 0;
66}
67#endif
68
Tom Rini03361c72017-08-14 16:38:07 -040069#if defined(CONFIG_SHA256) && !defined(CONFIG_SHA_PROG_HW_ACCEL)
Hung-ying Tyanf061b1a2014-03-03 12:19:28 +010070static int hash_init_sha256(struct hash_algo *algo, void **ctxp)
71{
72 sha256_context *ctx = malloc(sizeof(sha256_context));
73 sha256_starts(ctx);
74 *ctxp = ctx;
75 return 0;
76}
77
78static int hash_update_sha256(struct hash_algo *algo, void *ctx,
79 const void *buf, unsigned int size, int is_last)
80{
81 sha256_update((sha256_context *)ctx, buf, size);
82 return 0;
83}
84
85static int hash_finish_sha256(struct hash_algo *algo, void *ctx, void
86 *dest_buf, int size)
87{
88 if (size < algo->digest_size)
89 return -1;
90
91 sha256_finish((sha256_context *)ctx, dest_buf);
92 free(ctx);
93 return 0;
94}
95#endif
96
Philipp Tomsich6e2ac3e2018-11-25 19:22:19 +010097static int hash_init_crc16_ccitt(struct hash_algo *algo, void **ctxp)
98{
99 uint16_t *ctx = malloc(sizeof(uint16_t));
100 *ctx = 0;
101 *ctxp = ctx;
102 return 0;
103}
104
105static int hash_update_crc16_ccitt(struct hash_algo *algo, void *ctx,
106 const void *buf, unsigned int size,
107 int is_last)
108{
109 *((uint16_t *)ctx) = crc16_ccitt(*((uint16_t *)ctx), buf, size);
110 return 0;
111}
112
113static int hash_finish_crc16_ccitt(struct hash_algo *algo, void *ctx,
114 void *dest_buf, int size)
115{
116 if (size < algo->digest_size)
117 return -1;
118
119 *((uint16_t *)dest_buf) = *((uint16_t *)ctx);
120 free(ctx);
121 return 0;
122}
123
Hung-ying Tyanf061b1a2014-03-03 12:19:28 +0100124static int hash_init_crc32(struct hash_algo *algo, void **ctxp)
125{
126 uint32_t *ctx = malloc(sizeof(uint32_t));
127 *ctx = 0;
128 *ctxp = ctx;
129 return 0;
130}
131
132static int hash_update_crc32(struct hash_algo *algo, void *ctx,
133 const void *buf, unsigned int size, int is_last)
134{
135 *((uint32_t *)ctx) = crc32(*((uint32_t *)ctx), buf, size);
136 return 0;
137}
138
139static int hash_finish_crc32(struct hash_algo *algo, void *ctx, void *dest_buf,
140 int size)
141{
142 if (size < algo->digest_size)
143 return -1;
144
145 *((uint32_t *)dest_buf) = *((uint32_t *)ctx);
146 free(ctx);
147 return 0;
148}
149
Simon Glassb8790452012-12-05 14:46:36 +0000150/*
Tom Rini03361c72017-08-14 16:38:07 -0400151 * These are the hash algorithms we support. If we have hardware acceleration
152 * is enable we will use that, otherwise a software version of the algorithm.
153 * Note that algorithm names must be in lower case.
Simon Glassb8790452012-12-05 14:46:36 +0000154 */
155static struct hash_algo hash_algo[] = {
Tom Rini03361c72017-08-14 16:38:07 -0400156#ifdef CONFIG_SHA1
Akshay Saraswatcbd8f2c2013-03-20 21:00:58 +0000157 {
Tom Rini03361c72017-08-14 16:38:07 -0400158 .name = "sha1",
159 .digest_size = SHA1_SUM_LEN,
160 .chunk_size = CHUNKSZ_SHA1,
161#ifdef CONFIG_SHA_HW_ACCEL
162 .hash_func_ws = hw_sha1,
163#else
164 .hash_func_ws = sha1_csum_wd,
gaurav ranaef201592015-02-20 12:51:46 +0530165#endif
gaurav ranaef201592015-02-20 12:51:46 +0530166#ifdef CONFIG_SHA_PROG_HW_ACCEL
Tom Rini03361c72017-08-14 16:38:07 -0400167 .hash_init = hw_sha_init,
168 .hash_update = hw_sha_update,
169 .hash_finish = hw_sha_finish,
170#else
171 .hash_init = hash_init_sha1,
172 .hash_update = hash_update_sha1,
173 .hash_finish = hash_finish_sha1,
Akshay Saraswatcbd8f2c2013-03-20 21:00:58 +0000174#endif
Simon Glassb8790452012-12-05 14:46:36 +0000175 },
176#endif
177#ifdef CONFIG_SHA256
178 {
Tom Rini03361c72017-08-14 16:38:07 -0400179 .name = "sha256",
180 .digest_size = SHA256_SUM_LEN,
181 .chunk_size = CHUNKSZ_SHA256,
182#ifdef CONFIG_SHA_HW_ACCEL
183 .hash_func_ws = hw_sha256,
184#else
185 .hash_func_ws = sha256_csum_wd,
186#endif
187#ifdef CONFIG_SHA_PROG_HW_ACCEL
188 .hash_init = hw_sha_init,
189 .hash_update = hw_sha_update,
190 .hash_finish = hw_sha_finish,
191#else
192 .hash_init = hash_init_sha256,
193 .hash_update = hash_update_sha256,
194 .hash_finish = hash_finish_sha256,
195#endif
Simon Glassb8790452012-12-05 14:46:36 +0000196 },
197#endif
Simon Glass0bbd76f2013-02-24 20:30:22 +0000198 {
Philipp Tomsich6e2ac3e2018-11-25 19:22:19 +0100199 .name = "crc16-ccitt",
200 .digest_size = 2,
201 .chunk_size = CHUNKSZ,
202 .hash_func_ws = crc16_ccitt_wd_buf,
203 .hash_init = hash_init_crc16_ccitt,
204 .hash_update = hash_update_crc16_ccitt,
205 .hash_finish = hash_finish_crc16_ccitt,
206 },
207 {
Tom Rini03361c72017-08-14 16:38:07 -0400208 .name = "crc32",
209 .digest_size = 4,
210 .chunk_size = CHUNKSZ_CRC32,
211 .hash_func_ws = crc32_wd_buf,
212 .hash_init = hash_init_crc32,
213 .hash_update = hash_update_crc32,
214 .hash_finish = hash_finish_crc32,
Simon Glass0bbd76f2013-02-24 20:30:22 +0000215 },
Simon Glassb8790452012-12-05 14:46:36 +0000216};
217
Simon Glass0bbd76f2013-02-24 20:30:22 +0000218/* Try to minimize code size for boards that don't want much hashing */
Daniel Thompsona9e2c672017-05-19 17:26:58 +0100219#if defined(CONFIG_SHA256) || defined(CONFIG_CMD_SHA1SUM) || \
220 defined(CONFIG_CRC32_VERIFY) || defined(CONFIG_CMD_HASH)
Simon Glass0bbd76f2013-02-24 20:30:22 +0000221#define multi_hash() 1
222#else
223#define multi_hash() 0
224#endif
225
T Karthik Reddya098b432019-03-16 15:23:01 +0530226static void reloc_update(void)
227{
228#if !defined(USE_HOSTCC) && defined(CONFIG_NEEDS_MANUAL_RELOC)
229 int i;
230 static bool done;
231
232 if (!done) {
233 done = true;
234 for (i = 0; i < ARRAY_SIZE(hash_algo); i++) {
235 hash_algo[i].name += gd->reloc_off;
236 hash_algo[i].hash_func_ws += gd->reloc_off;
237 hash_algo[i].hash_init += gd->reloc_off;
238 hash_algo[i].hash_update += gd->reloc_off;
239 hash_algo[i].hash_finish += gd->reloc_off;
240 }
241 }
242#endif
243}
244
Ruchika Guptac915ceb2015-01-23 16:01:58 +0530245int hash_lookup_algo(const char *algo_name, struct hash_algo **algop)
246{
247 int i;
248
T Karthik Reddya098b432019-03-16 15:23:01 +0530249 reloc_update();
250
Ruchika Guptac915ceb2015-01-23 16:01:58 +0530251 for (i = 0; i < ARRAY_SIZE(hash_algo); i++) {
252 if (!strcmp(algo_name, hash_algo[i].name)) {
253 *algop = &hash_algo[i];
254 return 0;
255 }
256 }
257
258 debug("Unknown hash algorithm '%s'\n", algo_name);
259 return -EPROTONOSUPPORT;
260}
261
262int hash_progressive_lookup_algo(const char *algo_name,
263 struct hash_algo **algop)
264{
265 int i;
266
T Karthik Reddya098b432019-03-16 15:23:01 +0530267 reloc_update();
268
Ruchika Guptac915ceb2015-01-23 16:01:58 +0530269 for (i = 0; i < ARRAY_SIZE(hash_algo); i++) {
270 if (!strcmp(algo_name, hash_algo[i].name)) {
271 if (hash_algo[i].hash_init) {
272 *algop = &hash_algo[i];
273 return 0;
274 }
275 }
276 }
277
278 debug("Unknown hash algorithm '%s'\n", algo_name);
279 return -EPROTONOSUPPORT;
280}
281
282#ifndef USE_HOSTCC
Stefan Roese0ed2e462015-05-18 14:08:24 +0200283int hash_parse_string(const char *algo_name, const char *str, uint8_t *result)
284{
285 struct hash_algo *algo;
286 int ret;
287 int i;
288
289 ret = hash_lookup_algo(algo_name, &algo);
290 if (ret)
291 return ret;
292
293 for (i = 0; i < algo->digest_size; i++) {
294 char chr[3];
295
296 strncpy(chr, &str[i * 2], 2);
297 result[i] = simple_strtoul(chr, NULL, 16);
298 }
299
300 return 0;
301}
302
Tom Rini61738382016-01-05 08:47:48 -0500303int hash_block(const char *algo_name, const void *data, unsigned int len,
304 uint8_t *output, int *output_size)
305{
306 struct hash_algo *algo;
307 int ret;
308
309 ret = hash_lookup_algo(algo_name, &algo);
310 if (ret)
311 return ret;
312
313 if (output_size && *output_size < algo->digest_size) {
314 debug("Output buffer size %d too small (need %d bytes)",
315 *output_size, algo->digest_size);
316 return -ENOSPC;
317 }
318 if (output_size)
319 *output_size = algo->digest_size;
320 algo->hash_func_ws(data, len, output, algo->chunk_size);
321
322 return 0;
323}
324
325#if defined(CONFIG_CMD_HASH) || defined(CONFIG_CMD_SHA1SUM) || defined(CONFIG_CMD_CRC32)
Simon Glassb8790452012-12-05 14:46:36 +0000326/**
327 * store_result: Store the resulting sum to an address or variable
328 *
329 * @algo: Hash algorithm being used
330 * @sum: Hash digest (algo->digest_size bytes)
331 * @dest: Destination, interpreted as a hex address if it starts
Simon Glass80e345a2013-02-24 17:33:26 +0000332 * with * (or allow_env_vars is 0) or otherwise as an
333 * environment variable.
334 * @allow_env_vars: non-zero to permit storing the result to an
335 * variable environment
Simon Glassb8790452012-12-05 14:46:36 +0000336 */
Simon Glassa3b240b2014-06-12 07:24:41 -0600337static void store_result(struct hash_algo *algo, const uint8_t *sum,
Simon Glass80e345a2013-02-24 17:33:26 +0000338 const char *dest, int allow_env_vars)
Simon Glassb8790452012-12-05 14:46:36 +0000339{
340 unsigned int i;
Simon Glass80e345a2013-02-24 17:33:26 +0000341 int env_var = 0;
Simon Glassb8790452012-12-05 14:46:36 +0000342
Simon Glass80e345a2013-02-24 17:33:26 +0000343 /*
344 * If environment variables are allowed, then we assume that 'dest'
345 * is an environment variable, unless it starts with *, in which
346 * case we assume it is an address. If not allowed, it is always an
347 * address. This is to support the crc32 command.
348 */
349 if (allow_env_vars) {
350 if (*dest == '*')
351 dest++;
352 else
353 env_var = 1;
354 }
Simon Glassb8790452012-12-05 14:46:36 +0000355
Simon Glass80e345a2013-02-24 17:33:26 +0000356 if (env_var) {
Simon Glassb8790452012-12-05 14:46:36 +0000357 char str_output[HASH_MAX_DIGEST_SIZE * 2 + 1];
358 char *str_ptr = str_output;
359
360 for (i = 0; i < algo->digest_size; i++) {
361 sprintf(str_ptr, "%02x", sum[i]);
362 str_ptr += 2;
363 }
Jeroen Hofsteeb14c0522014-06-09 11:02:02 +0200364 *str_ptr = '\0';
Simon Glass6a38e412017-08-03 12:22:09 -0600365 env_set(dest, str_output);
Simon Glass80e345a2013-02-24 17:33:26 +0000366 } else {
Simon Glass68f15562013-02-24 17:33:31 +0000367 ulong addr;
368 void *buf;
Simon Glass80e345a2013-02-24 17:33:26 +0000369
Simon Glass68f15562013-02-24 17:33:31 +0000370 addr = simple_strtoul(dest, NULL, 16);
371 buf = map_sysmem(addr, algo->digest_size);
372 memcpy(buf, sum, algo->digest_size);
373 unmap_sysmem(buf);
Simon Glassb8790452012-12-05 14:46:36 +0000374 }
375}
376
377/**
378 * parse_verify_sum: Parse a hash verification parameter
379 *
380 * @algo: Hash algorithm being used
381 * @verify_str: Argument to parse. If it starts with * then it is
382 * interpreted as a hex address containing the hash.
383 * If the length is exactly the right number of hex digits
384 * for the digest size, then we assume it is a hex digest.
385 * Otherwise we assume it is an environment variable, and
386 * look up its value (it must contain a hex digest).
387 * @vsum: Returns binary digest value (algo->digest_size bytes)
Simon Glass80e345a2013-02-24 17:33:26 +0000388 * @allow_env_vars: non-zero to permit storing the result to an environment
389 * variable. If 0 then verify_str is assumed to be an
390 * address, and the * prefix is not expected.
Simon Glassb8790452012-12-05 14:46:36 +0000391 * @return 0 if ok, non-zero on error
392 */
Simon Glassa3b240b2014-06-12 07:24:41 -0600393static int parse_verify_sum(struct hash_algo *algo, char *verify_str,
394 uint8_t *vsum, int allow_env_vars)
Simon Glassb8790452012-12-05 14:46:36 +0000395{
Simon Glass80e345a2013-02-24 17:33:26 +0000396 int env_var = 0;
397
398 /* See comment above in store_result() */
399 if (allow_env_vars) {
400 if (*verify_str == '*')
401 verify_str++;
402 else
403 env_var = 1;
404 }
405
Nikolay Dimitrov810b84d2014-12-12 20:01:23 +0200406 if (!env_var) {
Simon Glass68f15562013-02-24 17:33:31 +0000407 ulong addr;
408 void *buf;
Simon Glassb8790452012-12-05 14:46:36 +0000409
Simon Glass68f15562013-02-24 17:33:31 +0000410 addr = simple_strtoul(verify_str, NULL, 16);
411 buf = map_sysmem(addr, algo->digest_size);
412 memcpy(vsum, buf, algo->digest_size);
Simon Glassb8790452012-12-05 14:46:36 +0000413 } else {
Simon Glassb8790452012-12-05 14:46:36 +0000414 char *vsum_str;
415 int digits = algo->digest_size * 2;
416
417 /*
418 * As with the original code from sha1sum.c, we assume that a
419 * string which matches the digest size exactly is a hex
420 * string and not an environment variable.
421 */
422 if (strlen(verify_str) == digits)
423 vsum_str = verify_str;
424 else {
Simon Glass64b723f2017-08-03 12:22:12 -0600425 vsum_str = env_get(verify_str);
Simon Glassb8790452012-12-05 14:46:36 +0000426 if (vsum_str == NULL || strlen(vsum_str) != digits) {
427 printf("Expected %d hex digits in env var\n",
428 digits);
429 return 1;
430 }
431 }
432
Stefan Roese0ed2e462015-05-18 14:08:24 +0200433 hash_parse_string(algo->name, vsum_str, vsum);
Simon Glassb8790452012-12-05 14:46:36 +0000434 }
435 return 0;
436}
437
Tom Rini61738382016-01-05 08:47:48 -0500438static void hash_show(struct hash_algo *algo, ulong addr, ulong len, uint8_t *output)
Simon Glassb8790452012-12-05 14:46:36 +0000439{
440 int i;
441
442 printf("%s for %08lx ... %08lx ==> ", algo->name, addr, addr + len - 1);
443 for (i = 0; i < algo->digest_size; i++)
444 printf("%02x", output[i]);
445}
446
Simon Glass80e345a2013-02-24 17:33:26 +0000447int hash_command(const char *algo_name, int flags, cmd_tbl_t *cmdtp, int flag,
Simon Glassb8790452012-12-05 14:46:36 +0000448 int argc, char * const argv[])
449{
Simon Glassb8790452012-12-05 14:46:36 +0000450 ulong addr, len;
Simon Glassb8790452012-12-05 14:46:36 +0000451
Nikolay Dimitrov810b84d2014-12-12 20:01:23 +0200452 if ((argc < 2) || ((flags & HASH_FLAG_VERIFY) && (argc < 3)))
Simon Glassb8790452012-12-05 14:46:36 +0000453 return CMD_RET_USAGE;
454
Simon Glass80e345a2013-02-24 17:33:26 +0000455 addr = simple_strtoul(*argv++, NULL, 16);
456 len = simple_strtoul(*argv++, NULL, 16);
457
Simon Glass0bbd76f2013-02-24 20:30:22 +0000458 if (multi_hash()) {
459 struct hash_algo *algo;
Breno Lima45e65122018-01-17 10:03:45 -0200460 u8 *output;
Simon Glassa3b240b2014-06-12 07:24:41 -0600461 uint8_t vsum[HASH_MAX_DIGEST_SIZE];
Simon Glass68f15562013-02-24 17:33:31 +0000462 void *buf;
Simon Glassb8790452012-12-05 14:46:36 +0000463
Hung-ying Tyanf061b1a2014-03-03 12:19:28 +0100464 if (hash_lookup_algo(algo_name, &algo)) {
Simon Glass0bbd76f2013-02-24 20:30:22 +0000465 printf("Unknown hash algorithm '%s'\n", algo_name);
466 return CMD_RET_USAGE;
467 }
468 argc -= 2;
469
470 if (algo->digest_size > HASH_MAX_DIGEST_SIZE) {
471 puts("HASH_MAX_DIGEST_SIZE exceeded\n");
472 return 1;
473 }
Simon Glassb8790452012-12-05 14:46:36 +0000474
Breno Lima45e65122018-01-17 10:03:45 -0200475 output = memalign(ARCH_DMA_MINALIGN,
476 sizeof(uint32_t) * HASH_MAX_DIGEST_SIZE);
477
Simon Glass68f15562013-02-24 17:33:31 +0000478 buf = map_sysmem(addr, len);
479 algo->hash_func_ws(buf, len, output, algo->chunk_size);
480 unmap_sysmem(buf);
Simon Glassb8790452012-12-05 14:46:36 +0000481
Simon Glass0bbd76f2013-02-24 20:30:22 +0000482 /* Try to avoid code bloat when verify is not needed */
Daniel Thompsona9e2c672017-05-19 17:26:58 +0100483#if defined(CONFIG_CRC32_VERIFY) || defined(CONFIG_SHA1SUM_VERIFY) || \
484 defined(CONFIG_HASH_VERIFY)
Simon Glass0bbd76f2013-02-24 20:30:22 +0000485 if (flags & HASH_FLAG_VERIFY) {
Simon Glassb8790452012-12-05 14:46:36 +0000486#else
Simon Glass0bbd76f2013-02-24 20:30:22 +0000487 if (0) {
Simon Glassb8790452012-12-05 14:46:36 +0000488#endif
Simon Glass0bbd76f2013-02-24 20:30:22 +0000489 if (parse_verify_sum(algo, *argv, vsum,
Simon Glass80e345a2013-02-24 17:33:26 +0000490 flags & HASH_FLAG_ENV)) {
Simon Glass0bbd76f2013-02-24 20:30:22 +0000491 printf("ERROR: %s does not contain a valid "
492 "%s sum\n", *argv, algo->name);
493 return 1;
494 }
495 if (memcmp(output, vsum, algo->digest_size) != 0) {
496 int i;
Simon Glassb8790452012-12-05 14:46:36 +0000497
Simon Glass7f3fa542014-06-02 22:04:49 -0600498 hash_show(algo, addr, len, output);
Simon Glass0bbd76f2013-02-24 20:30:22 +0000499 printf(" != ");
500 for (i = 0; i < algo->digest_size; i++)
501 printf("%02x", vsum[i]);
502 puts(" ** ERROR **\n");
503 return 1;
504 }
505 } else {
Simon Glass7f3fa542014-06-02 22:04:49 -0600506 hash_show(algo, addr, len, output);
Simon Glass0bbd76f2013-02-24 20:30:22 +0000507 printf("\n");
508
509 if (argc) {
510 store_result(algo, output, *argv,
511 flags & HASH_FLAG_ENV);
512 }
Breno Lima45e65122018-01-17 10:03:45 -0200513 unmap_sysmem(output);
514
Simon Glassb8790452012-12-05 14:46:36 +0000515 }
Simon Glass0bbd76f2013-02-24 20:30:22 +0000516
517 /* Horrible code size hack for boards that just want crc32 */
Simon Glassb8790452012-12-05 14:46:36 +0000518 } else {
Simon Glass0bbd76f2013-02-24 20:30:22 +0000519 ulong crc;
520 ulong *ptr;
521
522 crc = crc32_wd(0, (const uchar *)addr, len, CHUNKSZ_CRC32);
523
524 printf("CRC32 for %08lx ... %08lx ==> %08lx\n",
525 addr, addr + len - 1, crc);
Simon Glassb8790452012-12-05 14:46:36 +0000526
Tom Rini62780f02013-11-07 07:39:48 -0500527 if (argc >= 3) {
528 ptr = (ulong *)simple_strtoul(argv[0], NULL, 16);
Simon Glass0bbd76f2013-02-24 20:30:22 +0000529 *ptr = crc;
Simon Glass80e345a2013-02-24 17:33:26 +0000530 }
Simon Glassb8790452012-12-05 14:46:36 +0000531 }
532
533 return 0;
534}
Simon Glassb22ec7a2017-05-17 09:05:34 -0600535#endif /* CONFIG_CMD_HASH || CONFIG_CMD_SHA1SUM || CONFIG_CMD_CRC32) */
536#endif /* !USE_HOSTCC */