blob: 8c00659d252891b631f6299bdae9c789a72cab5d [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>
Simon Glass0f2af882020-05-10 11:40:05 -060016#include <log.h>
Hung-ying Tyanf061b1a2014-03-03 12:19:28 +010017#include <malloc.h>
Joe Hershberger65b905b2015-03-22 17:08:59 -050018#include <mapmem.h>
Akshay Saraswatcbd8f2c2013-03-20 21:00:58 +000019#include <hw_sha.h>
Simon Glass274e0b02020-05-10 11:39:56 -060020#include <asm/cache.h>
Ruchika Guptac915ceb2015-01-23 16:01:58 +053021#include <asm/io.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090022#include <linux/errno.h>
Simon Glass48b6c6b2019-11-14 12:57:16 -070023#include <u-boot/crc.h>
Ruchika Guptac915ceb2015-01-23 16:01:58 +053024#else
25#include "mkimage.h"
26#include <time.h>
Ruchika Guptac915ceb2015-01-23 16:01:58 +053027#endif /* !USE_HOSTCC*/
28
Simon Glassb8790452012-12-05 14:46:36 +000029#include <hash.h>
Simon Glass2dc9c342020-05-10 11:40:01 -060030#include <image.h>
Ruchika Guptac915ceb2015-01-23 16:01:58 +053031#include <u-boot/crc.h>
Jeroen Hofsteebfe88fe2014-06-12 22:27:12 +020032#include <u-boot/sha1.h>
33#include <u-boot/sha256.h>
Ruchika Guptac915ceb2015-01-23 16:01:58 +053034#include <u-boot/md5.h>
Simon Glassb8790452012-12-05 14:46:36 +000035
T Karthik Reddya098b432019-03-16 15:23:01 +053036#if !defined(USE_HOSTCC) && defined(CONFIG_NEEDS_MANUAL_RELOC)
37DECLARE_GLOBAL_DATA_PTR;
38#endif
39
40static void reloc_update(void);
41
Tom Rini03361c72017-08-14 16:38:07 -040042#if defined(CONFIG_SHA1) && !defined(CONFIG_SHA_PROG_HW_ACCEL)
Hung-ying Tyanf061b1a2014-03-03 12:19:28 +010043static int hash_init_sha1(struct hash_algo *algo, void **ctxp)
44{
45 sha1_context *ctx = malloc(sizeof(sha1_context));
46 sha1_starts(ctx);
47 *ctxp = ctx;
48 return 0;
49}
50
51static int hash_update_sha1(struct hash_algo *algo, void *ctx, const void *buf,
52 unsigned int size, int is_last)
53{
54 sha1_update((sha1_context *)ctx, buf, size);
55 return 0;
56}
57
58static int hash_finish_sha1(struct hash_algo *algo, void *ctx, void *dest_buf,
59 int size)
60{
61 if (size < algo->digest_size)
62 return -1;
63
64 sha1_finish((sha1_context *)ctx, dest_buf);
65 free(ctx);
66 return 0;
67}
68#endif
69
Tom Rini03361c72017-08-14 16:38:07 -040070#if defined(CONFIG_SHA256) && !defined(CONFIG_SHA_PROG_HW_ACCEL)
Hung-ying Tyanf061b1a2014-03-03 12:19:28 +010071static int hash_init_sha256(struct hash_algo *algo, void **ctxp)
72{
73 sha256_context *ctx = malloc(sizeof(sha256_context));
74 sha256_starts(ctx);
75 *ctxp = ctx;
76 return 0;
77}
78
79static int hash_update_sha256(struct hash_algo *algo, void *ctx,
80 const void *buf, unsigned int size, int is_last)
81{
82 sha256_update((sha256_context *)ctx, buf, size);
83 return 0;
84}
85
86static int hash_finish_sha256(struct hash_algo *algo, void *ctx, void
87 *dest_buf, int size)
88{
89 if (size < algo->digest_size)
90 return -1;
91
92 sha256_finish((sha256_context *)ctx, dest_buf);
93 free(ctx);
94 return 0;
95}
96#endif
97
Philipp Tomsich6e2ac3e2018-11-25 19:22:19 +010098static int hash_init_crc16_ccitt(struct hash_algo *algo, void **ctxp)
99{
100 uint16_t *ctx = malloc(sizeof(uint16_t));
101 *ctx = 0;
102 *ctxp = ctx;
103 return 0;
104}
105
106static int hash_update_crc16_ccitt(struct hash_algo *algo, void *ctx,
107 const void *buf, unsigned int size,
108 int is_last)
109{
110 *((uint16_t *)ctx) = crc16_ccitt(*((uint16_t *)ctx), buf, size);
111 return 0;
112}
113
114static int hash_finish_crc16_ccitt(struct hash_algo *algo, void *ctx,
115 void *dest_buf, int size)
116{
117 if (size < algo->digest_size)
118 return -1;
119
120 *((uint16_t *)dest_buf) = *((uint16_t *)ctx);
121 free(ctx);
122 return 0;
123}
124
Hung-ying Tyanf061b1a2014-03-03 12:19:28 +0100125static int hash_init_crc32(struct hash_algo *algo, void **ctxp)
126{
127 uint32_t *ctx = malloc(sizeof(uint32_t));
128 *ctx = 0;
129 *ctxp = ctx;
130 return 0;
131}
132
133static int hash_update_crc32(struct hash_algo *algo, void *ctx,
134 const void *buf, unsigned int size, int is_last)
135{
136 *((uint32_t *)ctx) = crc32(*((uint32_t *)ctx), buf, size);
137 return 0;
138}
139
140static int hash_finish_crc32(struct hash_algo *algo, void *ctx, void *dest_buf,
141 int size)
142{
143 if (size < algo->digest_size)
144 return -1;
145
146 *((uint32_t *)dest_buf) = *((uint32_t *)ctx);
147 free(ctx);
148 return 0;
149}
150
Simon Glassb8790452012-12-05 14:46:36 +0000151/*
Tom Rini03361c72017-08-14 16:38:07 -0400152 * These are the hash algorithms we support. If we have hardware acceleration
153 * is enable we will use that, otherwise a software version of the algorithm.
154 * Note that algorithm names must be in lower case.
Simon Glassb8790452012-12-05 14:46:36 +0000155 */
156static struct hash_algo hash_algo[] = {
Tom Rini03361c72017-08-14 16:38:07 -0400157#ifdef CONFIG_SHA1
Akshay Saraswatcbd8f2c2013-03-20 21:00:58 +0000158 {
Tom Rini03361c72017-08-14 16:38:07 -0400159 .name = "sha1",
160 .digest_size = SHA1_SUM_LEN,
161 .chunk_size = CHUNKSZ_SHA1,
162#ifdef CONFIG_SHA_HW_ACCEL
163 .hash_func_ws = hw_sha1,
164#else
165 .hash_func_ws = sha1_csum_wd,
gaurav ranaef201592015-02-20 12:51:46 +0530166#endif
gaurav ranaef201592015-02-20 12:51:46 +0530167#ifdef CONFIG_SHA_PROG_HW_ACCEL
Tom Rini03361c72017-08-14 16:38:07 -0400168 .hash_init = hw_sha_init,
169 .hash_update = hw_sha_update,
170 .hash_finish = hw_sha_finish,
171#else
172 .hash_init = hash_init_sha1,
173 .hash_update = hash_update_sha1,
174 .hash_finish = hash_finish_sha1,
Akshay Saraswatcbd8f2c2013-03-20 21:00:58 +0000175#endif
Simon Glassb8790452012-12-05 14:46:36 +0000176 },
177#endif
178#ifdef CONFIG_SHA256
179 {
Tom Rini03361c72017-08-14 16:38:07 -0400180 .name = "sha256",
181 .digest_size = SHA256_SUM_LEN,
182 .chunk_size = CHUNKSZ_SHA256,
183#ifdef CONFIG_SHA_HW_ACCEL
184 .hash_func_ws = hw_sha256,
185#else
186 .hash_func_ws = sha256_csum_wd,
187#endif
188#ifdef CONFIG_SHA_PROG_HW_ACCEL
189 .hash_init = hw_sha_init,
190 .hash_update = hw_sha_update,
191 .hash_finish = hw_sha_finish,
192#else
193 .hash_init = hash_init_sha256,
194 .hash_update = hash_update_sha256,
195 .hash_finish = hash_finish_sha256,
196#endif
Simon Glassb8790452012-12-05 14:46:36 +0000197 },
198#endif
Simon Glass0bbd76f2013-02-24 20:30:22 +0000199 {
Philipp Tomsich6e2ac3e2018-11-25 19:22:19 +0100200 .name = "crc16-ccitt",
201 .digest_size = 2,
202 .chunk_size = CHUNKSZ,
203 .hash_func_ws = crc16_ccitt_wd_buf,
204 .hash_init = hash_init_crc16_ccitt,
205 .hash_update = hash_update_crc16_ccitt,
206 .hash_finish = hash_finish_crc16_ccitt,
207 },
208 {
Tom Rini03361c72017-08-14 16:38:07 -0400209 .name = "crc32",
210 .digest_size = 4,
211 .chunk_size = CHUNKSZ_CRC32,
212 .hash_func_ws = crc32_wd_buf,
213 .hash_init = hash_init_crc32,
214 .hash_update = hash_update_crc32,
215 .hash_finish = hash_finish_crc32,
Simon Glass0bbd76f2013-02-24 20:30:22 +0000216 },
Simon Glassb8790452012-12-05 14:46:36 +0000217};
218
Simon Glass0bbd76f2013-02-24 20:30:22 +0000219/* Try to minimize code size for boards that don't want much hashing */
Daniel Thompsona9e2c672017-05-19 17:26:58 +0100220#if defined(CONFIG_SHA256) || defined(CONFIG_CMD_SHA1SUM) || \
221 defined(CONFIG_CRC32_VERIFY) || defined(CONFIG_CMD_HASH)
Simon Glass0bbd76f2013-02-24 20:30:22 +0000222#define multi_hash() 1
223#else
224#define multi_hash() 0
225#endif
226
T Karthik Reddya098b432019-03-16 15:23:01 +0530227static void reloc_update(void)
228{
229#if !defined(USE_HOSTCC) && defined(CONFIG_NEEDS_MANUAL_RELOC)
230 int i;
231 static bool done;
232
233 if (!done) {
234 done = true;
235 for (i = 0; i < ARRAY_SIZE(hash_algo); i++) {
236 hash_algo[i].name += gd->reloc_off;
237 hash_algo[i].hash_func_ws += gd->reloc_off;
238 hash_algo[i].hash_init += gd->reloc_off;
239 hash_algo[i].hash_update += gd->reloc_off;
240 hash_algo[i].hash_finish += gd->reloc_off;
241 }
242 }
243#endif
244}
245
Ruchika Guptac915ceb2015-01-23 16:01:58 +0530246int hash_lookup_algo(const char *algo_name, struct hash_algo **algop)
247{
248 int i;
249
T Karthik Reddya098b432019-03-16 15:23:01 +0530250 reloc_update();
251
Ruchika Guptac915ceb2015-01-23 16:01:58 +0530252 for (i = 0; i < ARRAY_SIZE(hash_algo); i++) {
253 if (!strcmp(algo_name, hash_algo[i].name)) {
254 *algop = &hash_algo[i];
255 return 0;
256 }
257 }
258
259 debug("Unknown hash algorithm '%s'\n", algo_name);
260 return -EPROTONOSUPPORT;
261}
262
263int hash_progressive_lookup_algo(const char *algo_name,
264 struct hash_algo **algop)
265{
266 int i;
267
T Karthik Reddya098b432019-03-16 15:23:01 +0530268 reloc_update();
269
Ruchika Guptac915ceb2015-01-23 16:01:58 +0530270 for (i = 0; i < ARRAY_SIZE(hash_algo); i++) {
271 if (!strcmp(algo_name, hash_algo[i].name)) {
272 if (hash_algo[i].hash_init) {
273 *algop = &hash_algo[i];
274 return 0;
275 }
276 }
277 }
278
279 debug("Unknown hash algorithm '%s'\n", algo_name);
280 return -EPROTONOSUPPORT;
281}
282
283#ifndef USE_HOSTCC
Stefan Roese0ed2e462015-05-18 14:08:24 +0200284int hash_parse_string(const char *algo_name, const char *str, uint8_t *result)
285{
286 struct hash_algo *algo;
287 int ret;
288 int i;
289
290 ret = hash_lookup_algo(algo_name, &algo);
291 if (ret)
292 return ret;
293
294 for (i = 0; i < algo->digest_size; i++) {
295 char chr[3];
296
297 strncpy(chr, &str[i * 2], 2);
298 result[i] = simple_strtoul(chr, NULL, 16);
299 }
300
301 return 0;
302}
303
Tom Rini61738382016-01-05 08:47:48 -0500304int hash_block(const char *algo_name, const void *data, unsigned int len,
305 uint8_t *output, int *output_size)
306{
307 struct hash_algo *algo;
308 int ret;
309
310 ret = hash_lookup_algo(algo_name, &algo);
311 if (ret)
312 return ret;
313
314 if (output_size && *output_size < algo->digest_size) {
315 debug("Output buffer size %d too small (need %d bytes)",
316 *output_size, algo->digest_size);
317 return -ENOSPC;
318 }
319 if (output_size)
320 *output_size = algo->digest_size;
321 algo->hash_func_ws(data, len, output, algo->chunk_size);
322
323 return 0;
324}
325
326#if defined(CONFIG_CMD_HASH) || defined(CONFIG_CMD_SHA1SUM) || defined(CONFIG_CMD_CRC32)
Simon Glassb8790452012-12-05 14:46:36 +0000327/**
328 * store_result: Store the resulting sum to an address or variable
329 *
330 * @algo: Hash algorithm being used
331 * @sum: Hash digest (algo->digest_size bytes)
332 * @dest: Destination, interpreted as a hex address if it starts
Simon Glass80e345a2013-02-24 17:33:26 +0000333 * with * (or allow_env_vars is 0) or otherwise as an
334 * environment variable.
335 * @allow_env_vars: non-zero to permit storing the result to an
336 * variable environment
Simon Glassb8790452012-12-05 14:46:36 +0000337 */
Simon Glassa3b240b2014-06-12 07:24:41 -0600338static void store_result(struct hash_algo *algo, const uint8_t *sum,
Simon Glass80e345a2013-02-24 17:33:26 +0000339 const char *dest, int allow_env_vars)
Simon Glassb8790452012-12-05 14:46:36 +0000340{
341 unsigned int i;
Simon Glass80e345a2013-02-24 17:33:26 +0000342 int env_var = 0;
Simon Glassb8790452012-12-05 14:46:36 +0000343
Simon Glass80e345a2013-02-24 17:33:26 +0000344 /*
345 * If environment variables are allowed, then we assume that 'dest'
346 * is an environment variable, unless it starts with *, in which
347 * case we assume it is an address. If not allowed, it is always an
348 * address. This is to support the crc32 command.
349 */
350 if (allow_env_vars) {
351 if (*dest == '*')
352 dest++;
353 else
354 env_var = 1;
355 }
Simon Glassb8790452012-12-05 14:46:36 +0000356
Simon Glass80e345a2013-02-24 17:33:26 +0000357 if (env_var) {
Simon Glassb8790452012-12-05 14:46:36 +0000358 char str_output[HASH_MAX_DIGEST_SIZE * 2 + 1];
359 char *str_ptr = str_output;
360
361 for (i = 0; i < algo->digest_size; i++) {
362 sprintf(str_ptr, "%02x", sum[i]);
363 str_ptr += 2;
364 }
Jeroen Hofsteeb14c0522014-06-09 11:02:02 +0200365 *str_ptr = '\0';
Simon Glass6a38e412017-08-03 12:22:09 -0600366 env_set(dest, str_output);
Simon Glass80e345a2013-02-24 17:33:26 +0000367 } else {
Simon Glass68f15562013-02-24 17:33:31 +0000368 ulong addr;
369 void *buf;
Simon Glass80e345a2013-02-24 17:33:26 +0000370
Simon Glass68f15562013-02-24 17:33:31 +0000371 addr = simple_strtoul(dest, NULL, 16);
372 buf = map_sysmem(addr, algo->digest_size);
373 memcpy(buf, sum, algo->digest_size);
374 unmap_sysmem(buf);
Simon Glassb8790452012-12-05 14:46:36 +0000375 }
376}
377
378/**
379 * parse_verify_sum: Parse a hash verification parameter
380 *
381 * @algo: Hash algorithm being used
382 * @verify_str: Argument to parse. If it starts with * then it is
383 * interpreted as a hex address containing the hash.
384 * If the length is exactly the right number of hex digits
385 * for the digest size, then we assume it is a hex digest.
386 * Otherwise we assume it is an environment variable, and
387 * look up its value (it must contain a hex digest).
388 * @vsum: Returns binary digest value (algo->digest_size bytes)
Simon Glass80e345a2013-02-24 17:33:26 +0000389 * @allow_env_vars: non-zero to permit storing the result to an environment
390 * variable. If 0 then verify_str is assumed to be an
391 * address, and the * prefix is not expected.
Simon Glassb8790452012-12-05 14:46:36 +0000392 * @return 0 if ok, non-zero on error
393 */
Simon Glassa3b240b2014-06-12 07:24:41 -0600394static int parse_verify_sum(struct hash_algo *algo, char *verify_str,
395 uint8_t *vsum, int allow_env_vars)
Simon Glassb8790452012-12-05 14:46:36 +0000396{
Simon Glass80e345a2013-02-24 17:33:26 +0000397 int env_var = 0;
398
399 /* See comment above in store_result() */
400 if (allow_env_vars) {
401 if (*verify_str == '*')
402 verify_str++;
403 else
404 env_var = 1;
405 }
406
Nikolay Dimitrov810b84d2014-12-12 20:01:23 +0200407 if (!env_var) {
Simon Glass68f15562013-02-24 17:33:31 +0000408 ulong addr;
409 void *buf;
Simon Glassb8790452012-12-05 14:46:36 +0000410
Simon Glass68f15562013-02-24 17:33:31 +0000411 addr = simple_strtoul(verify_str, NULL, 16);
412 buf = map_sysmem(addr, algo->digest_size);
413 memcpy(vsum, buf, algo->digest_size);
Simon Glassb8790452012-12-05 14:46:36 +0000414 } else {
Simon Glassb8790452012-12-05 14:46:36 +0000415 char *vsum_str;
416 int digits = algo->digest_size * 2;
417
418 /*
419 * As with the original code from sha1sum.c, we assume that a
420 * string which matches the digest size exactly is a hex
421 * string and not an environment variable.
422 */
423 if (strlen(verify_str) == digits)
424 vsum_str = verify_str;
425 else {
Simon Glass64b723f2017-08-03 12:22:12 -0600426 vsum_str = env_get(verify_str);
Simon Glassb8790452012-12-05 14:46:36 +0000427 if (vsum_str == NULL || strlen(vsum_str) != digits) {
428 printf("Expected %d hex digits in env var\n",
429 digits);
430 return 1;
431 }
432 }
433
Stefan Roese0ed2e462015-05-18 14:08:24 +0200434 hash_parse_string(algo->name, vsum_str, vsum);
Simon Glassb8790452012-12-05 14:46:36 +0000435 }
436 return 0;
437}
438
Tom Rini61738382016-01-05 08:47:48 -0500439static void hash_show(struct hash_algo *algo, ulong addr, ulong len, uint8_t *output)
Simon Glassb8790452012-12-05 14:46:36 +0000440{
441 int i;
442
443 printf("%s for %08lx ... %08lx ==> ", algo->name, addr, addr + len - 1);
444 for (i = 0; i < algo->digest_size; i++)
445 printf("%02x", output[i]);
446}
447
Simon Glassed38aef2020-05-10 11:40:03 -0600448int hash_command(const char *algo_name, int flags, struct cmd_tbl *cmdtp,
449 int flag, int argc, char *const argv[])
Simon Glassb8790452012-12-05 14:46:36 +0000450{
Simon Glassb8790452012-12-05 14:46:36 +0000451 ulong addr, len;
Simon Glassb8790452012-12-05 14:46:36 +0000452
Nikolay Dimitrov810b84d2014-12-12 20:01:23 +0200453 if ((argc < 2) || ((flags & HASH_FLAG_VERIFY) && (argc < 3)))
Simon Glassb8790452012-12-05 14:46:36 +0000454 return CMD_RET_USAGE;
455
Simon Glass80e345a2013-02-24 17:33:26 +0000456 addr = simple_strtoul(*argv++, NULL, 16);
457 len = simple_strtoul(*argv++, NULL, 16);
458
Simon Glass0bbd76f2013-02-24 20:30:22 +0000459 if (multi_hash()) {
460 struct hash_algo *algo;
Breno Lima45e65122018-01-17 10:03:45 -0200461 u8 *output;
Simon Glassa3b240b2014-06-12 07:24:41 -0600462 uint8_t vsum[HASH_MAX_DIGEST_SIZE];
Simon Glass68f15562013-02-24 17:33:31 +0000463 void *buf;
Simon Glassb8790452012-12-05 14:46:36 +0000464
Hung-ying Tyanf061b1a2014-03-03 12:19:28 +0100465 if (hash_lookup_algo(algo_name, &algo)) {
Simon Glass0bbd76f2013-02-24 20:30:22 +0000466 printf("Unknown hash algorithm '%s'\n", algo_name);
467 return CMD_RET_USAGE;
468 }
469 argc -= 2;
470
471 if (algo->digest_size > HASH_MAX_DIGEST_SIZE) {
472 puts("HASH_MAX_DIGEST_SIZE exceeded\n");
473 return 1;
474 }
Simon Glassb8790452012-12-05 14:46:36 +0000475
Breno Lima45e65122018-01-17 10:03:45 -0200476 output = memalign(ARCH_DMA_MINALIGN,
477 sizeof(uint32_t) * HASH_MAX_DIGEST_SIZE);
478
Simon Glass68f15562013-02-24 17:33:31 +0000479 buf = map_sysmem(addr, len);
480 algo->hash_func_ws(buf, len, output, algo->chunk_size);
481 unmap_sysmem(buf);
Simon Glassb8790452012-12-05 14:46:36 +0000482
Simon Glass0bbd76f2013-02-24 20:30:22 +0000483 /* Try to avoid code bloat when verify is not needed */
Daniel Thompsona9e2c672017-05-19 17:26:58 +0100484#if defined(CONFIG_CRC32_VERIFY) || defined(CONFIG_SHA1SUM_VERIFY) || \
485 defined(CONFIG_HASH_VERIFY)
Simon Glass0bbd76f2013-02-24 20:30:22 +0000486 if (flags & HASH_FLAG_VERIFY) {
Simon Glassb8790452012-12-05 14:46:36 +0000487#else
Simon Glass0bbd76f2013-02-24 20:30:22 +0000488 if (0) {
Simon Glassb8790452012-12-05 14:46:36 +0000489#endif
Simon Glass0bbd76f2013-02-24 20:30:22 +0000490 if (parse_verify_sum(algo, *argv, vsum,
Simon Glass80e345a2013-02-24 17:33:26 +0000491 flags & HASH_FLAG_ENV)) {
Simon Glass0bbd76f2013-02-24 20:30:22 +0000492 printf("ERROR: %s does not contain a valid "
493 "%s sum\n", *argv, algo->name);
494 return 1;
495 }
496 if (memcmp(output, vsum, algo->digest_size) != 0) {
497 int i;
Simon Glassb8790452012-12-05 14:46:36 +0000498
Simon Glass7f3fa542014-06-02 22:04:49 -0600499 hash_show(algo, addr, len, output);
Simon Glass0bbd76f2013-02-24 20:30:22 +0000500 printf(" != ");
501 for (i = 0; i < algo->digest_size; i++)
502 printf("%02x", vsum[i]);
503 puts(" ** ERROR **\n");
504 return 1;
505 }
506 } else {
Simon Glass7f3fa542014-06-02 22:04:49 -0600507 hash_show(algo, addr, len, output);
Simon Glass0bbd76f2013-02-24 20:30:22 +0000508 printf("\n");
509
510 if (argc) {
511 store_result(algo, output, *argv,
512 flags & HASH_FLAG_ENV);
513 }
Breno Lima45e65122018-01-17 10:03:45 -0200514 unmap_sysmem(output);
515
Simon Glassb8790452012-12-05 14:46:36 +0000516 }
Simon Glass0bbd76f2013-02-24 20:30:22 +0000517
518 /* Horrible code size hack for boards that just want crc32 */
Simon Glassb8790452012-12-05 14:46:36 +0000519 } else {
Simon Glass0bbd76f2013-02-24 20:30:22 +0000520 ulong crc;
521 ulong *ptr;
522
523 crc = crc32_wd(0, (const uchar *)addr, len, CHUNKSZ_CRC32);
524
525 printf("CRC32 for %08lx ... %08lx ==> %08lx\n",
526 addr, addr + len - 1, crc);
Simon Glassb8790452012-12-05 14:46:36 +0000527
Tom Rini62780f02013-11-07 07:39:48 -0500528 if (argc >= 3) {
529 ptr = (ulong *)simple_strtoul(argv[0], NULL, 16);
Simon Glass0bbd76f2013-02-24 20:30:22 +0000530 *ptr = crc;
Simon Glass80e345a2013-02-24 17:33:26 +0000531 }
Simon Glassb8790452012-12-05 14:46:36 +0000532 }
533
534 return 0;
535}
Simon Glassb22ec7a2017-05-17 09:05:34 -0600536#endif /* CONFIG_CMD_HASH || CONFIG_CMD_SHA1SUM || CONFIG_CMD_CRC32) */
537#endif /* !USE_HOSTCC */