Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | b879045 | 2012-12-05 14:46:36 +0000 | [diff] [blame] | 2 | /* |
| 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 Glass | b879045 | 2012-12-05 14:46:36 +0000 | [diff] [blame] | 10 | */ |
| 11 | |
Ruchika Gupta | c915ceb | 2015-01-23 16:01:58 +0530 | [diff] [blame] | 12 | #ifndef USE_HOSTCC |
Simon Glass | b879045 | 2012-12-05 14:46:36 +0000 | [diff] [blame] | 13 | #include <command.h> |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 14 | #include <env.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 15 | #include <log.h> |
Hung-ying Tyan | f061b1a | 2014-03-03 12:19:28 +0100 | [diff] [blame] | 16 | #include <malloc.h> |
Joe Hershberger | 65b905b | 2015-03-22 17:08:59 -0500 | [diff] [blame] | 17 | #include <mapmem.h> |
Akshay Saraswat | cbd8f2c | 2013-03-20 21:00:58 +0000 | [diff] [blame] | 18 | #include <hw_sha.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 19 | #include <asm/cache.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 20 | #include <asm/global_data.h> |
Ruchika Gupta | c915ceb | 2015-01-23 16:01:58 +0530 | [diff] [blame] | 21 | #include <asm/io.h> |
Masahiro Yamada | 56a931c | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 22 | #include <linux/errno.h> |
Ruchika Gupta | c915ceb | 2015-01-23 16:01:58 +0530 | [diff] [blame] | 23 | #else |
| 24 | #include "mkimage.h" |
Simon Glass | 866178e | 2021-09-25 19:43:19 -0600 | [diff] [blame] | 25 | #include <linux/compiler_attributes.h> |
Ruchika Gupta | c915ceb | 2015-01-23 16:01:58 +0530 | [diff] [blame] | 26 | #include <time.h> |
Simon Glass | 383dd57 | 2021-09-25 19:43:18 -0600 | [diff] [blame] | 27 | #include <linux/kconfig.h> |
Ruchika Gupta | c915ceb | 2015-01-23 16:01:58 +0530 | [diff] [blame] | 28 | #endif /* !USE_HOSTCC*/ |
| 29 | |
Simon Glass | b879045 | 2012-12-05 14:46:36 +0000 | [diff] [blame] | 30 | #include <hash.h> |
Simon Glass | 2dc9c34 | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 31 | #include <image.h> |
Ruchika Gupta | c915ceb | 2015-01-23 16:01:58 +0530 | [diff] [blame] | 32 | #include <u-boot/crc.h> |
Jeroen Hofstee | bfe88fe | 2014-06-12 22:27:12 +0200 | [diff] [blame] | 33 | #include <u-boot/sha1.h> |
| 34 | #include <u-boot/sha256.h> |
Reuben Dowle | 1908fd9 | 2020-04-16 17:36:52 +1200 | [diff] [blame] | 35 | #include <u-boot/sha512.h> |
Ruchika Gupta | c915ceb | 2015-01-23 16:01:58 +0530 | [diff] [blame] | 36 | #include <u-boot/md5.h> |
Simon Glass | b879045 | 2012-12-05 14:46:36 +0000 | [diff] [blame] | 37 | |
Simon Glass | 866178e | 2021-09-25 19:43:19 -0600 | [diff] [blame] | 38 | static int __maybe_unused hash_init_sha1(struct hash_algo *algo, void **ctxp) |
Hung-ying Tyan | f061b1a | 2014-03-03 12:19:28 +0100 | [diff] [blame] | 39 | { |
| 40 | sha1_context *ctx = malloc(sizeof(sha1_context)); |
| 41 | sha1_starts(ctx); |
| 42 | *ctxp = ctx; |
| 43 | return 0; |
| 44 | } |
| 45 | |
Simon Glass | 866178e | 2021-09-25 19:43:19 -0600 | [diff] [blame] | 46 | static int __maybe_unused hash_update_sha1(struct hash_algo *algo, void *ctx, |
| 47 | const void *buf, unsigned int size, |
| 48 | int is_last) |
Hung-ying Tyan | f061b1a | 2014-03-03 12:19:28 +0100 | [diff] [blame] | 49 | { |
| 50 | sha1_update((sha1_context *)ctx, buf, size); |
| 51 | return 0; |
| 52 | } |
| 53 | |
Simon Glass | 866178e | 2021-09-25 19:43:19 -0600 | [diff] [blame] | 54 | static int __maybe_unused hash_finish_sha1(struct hash_algo *algo, void *ctx, |
| 55 | void *dest_buf, int size) |
Hung-ying Tyan | f061b1a | 2014-03-03 12:19:28 +0100 | [diff] [blame] | 56 | { |
| 57 | if (size < algo->digest_size) |
| 58 | return -1; |
| 59 | |
| 60 | sha1_finish((sha1_context *)ctx, dest_buf); |
| 61 | free(ctx); |
| 62 | return 0; |
| 63 | } |
Hung-ying Tyan | f061b1a | 2014-03-03 12:19:28 +0100 | [diff] [blame] | 64 | |
Simon Glass | 866178e | 2021-09-25 19:43:19 -0600 | [diff] [blame] | 65 | static int __maybe_unused hash_init_sha256(struct hash_algo *algo, void **ctxp) |
Hung-ying Tyan | f061b1a | 2014-03-03 12:19:28 +0100 | [diff] [blame] | 66 | { |
| 67 | sha256_context *ctx = malloc(sizeof(sha256_context)); |
| 68 | sha256_starts(ctx); |
| 69 | *ctxp = ctx; |
| 70 | return 0; |
| 71 | } |
| 72 | |
Simon Glass | 866178e | 2021-09-25 19:43:19 -0600 | [diff] [blame] | 73 | static int __maybe_unused hash_update_sha256(struct hash_algo *algo, void *ctx, |
| 74 | const void *buf, uint size, |
| 75 | int is_last) |
Hung-ying Tyan | f061b1a | 2014-03-03 12:19:28 +0100 | [diff] [blame] | 76 | { |
| 77 | sha256_update((sha256_context *)ctx, buf, size); |
| 78 | return 0; |
| 79 | } |
| 80 | |
Simon Glass | 866178e | 2021-09-25 19:43:19 -0600 | [diff] [blame] | 81 | static int __maybe_unused hash_finish_sha256(struct hash_algo *algo, void *ctx, |
| 82 | void *dest_buf, int size) |
Hung-ying Tyan | f061b1a | 2014-03-03 12:19:28 +0100 | [diff] [blame] | 83 | { |
| 84 | if (size < algo->digest_size) |
| 85 | return -1; |
| 86 | |
| 87 | sha256_finish((sha256_context *)ctx, dest_buf); |
| 88 | free(ctx); |
| 89 | return 0; |
| 90 | } |
Hung-ying Tyan | f061b1a | 2014-03-03 12:19:28 +0100 | [diff] [blame] | 91 | |
Simon Glass | 866178e | 2021-09-25 19:43:19 -0600 | [diff] [blame] | 92 | static int __maybe_unused hash_init_sha384(struct hash_algo *algo, void **ctxp) |
Reuben Dowle | 1908fd9 | 2020-04-16 17:36:52 +1200 | [diff] [blame] | 93 | { |
| 94 | sha512_context *ctx = malloc(sizeof(sha512_context)); |
| 95 | sha384_starts(ctx); |
| 96 | *ctxp = ctx; |
| 97 | return 0; |
| 98 | } |
| 99 | |
Simon Glass | 866178e | 2021-09-25 19:43:19 -0600 | [diff] [blame] | 100 | static int __maybe_unused hash_update_sha384(struct hash_algo *algo, void *ctx, |
| 101 | const void *buf, uint size, |
| 102 | int is_last) |
Reuben Dowle | 1908fd9 | 2020-04-16 17:36:52 +1200 | [diff] [blame] | 103 | { |
| 104 | sha384_update((sha512_context *)ctx, buf, size); |
| 105 | return 0; |
| 106 | } |
| 107 | |
Simon Glass | 866178e | 2021-09-25 19:43:19 -0600 | [diff] [blame] | 108 | static int __maybe_unused hash_finish_sha384(struct hash_algo *algo, void *ctx, |
| 109 | void *dest_buf, int size) |
Reuben Dowle | 1908fd9 | 2020-04-16 17:36:52 +1200 | [diff] [blame] | 110 | { |
| 111 | if (size < algo->digest_size) |
| 112 | return -1; |
| 113 | |
| 114 | sha384_finish((sha512_context *)ctx, dest_buf); |
| 115 | free(ctx); |
| 116 | return 0; |
| 117 | } |
Reuben Dowle | 1908fd9 | 2020-04-16 17:36:52 +1200 | [diff] [blame] | 118 | |
Simon Glass | 866178e | 2021-09-25 19:43:19 -0600 | [diff] [blame] | 119 | static int __maybe_unused hash_init_sha512(struct hash_algo *algo, void **ctxp) |
Reuben Dowle | 1908fd9 | 2020-04-16 17:36:52 +1200 | [diff] [blame] | 120 | { |
| 121 | sha512_context *ctx = malloc(sizeof(sha512_context)); |
| 122 | sha512_starts(ctx); |
| 123 | *ctxp = ctx; |
| 124 | return 0; |
| 125 | } |
| 126 | |
Simon Glass | 866178e | 2021-09-25 19:43:19 -0600 | [diff] [blame] | 127 | static int __maybe_unused hash_update_sha512(struct hash_algo *algo, void *ctx, |
| 128 | const void *buf, uint size, |
| 129 | int is_last) |
Reuben Dowle | 1908fd9 | 2020-04-16 17:36:52 +1200 | [diff] [blame] | 130 | { |
| 131 | sha512_update((sha512_context *)ctx, buf, size); |
| 132 | return 0; |
| 133 | } |
| 134 | |
Simon Glass | 866178e | 2021-09-25 19:43:19 -0600 | [diff] [blame] | 135 | static int __maybe_unused hash_finish_sha512(struct hash_algo *algo, void *ctx, |
| 136 | void *dest_buf, int size) |
Reuben Dowle | 1908fd9 | 2020-04-16 17:36:52 +1200 | [diff] [blame] | 137 | { |
| 138 | if (size < algo->digest_size) |
| 139 | return -1; |
| 140 | |
Reuben Dowle | 1908fd9 | 2020-04-16 17:36:52 +1200 | [diff] [blame] | 141 | sha512_finish((sha512_context *)ctx, dest_buf); |
| 142 | free(ctx); |
| 143 | return 0; |
| 144 | } |
Reuben Dowle | 1908fd9 | 2020-04-16 17:36:52 +1200 | [diff] [blame] | 145 | |
Simon Glass | 52b51ab | 2025-01-26 11:43:14 -0700 | [diff] [blame] | 146 | static int __maybe_unused hash_init_crc16_ccitt(struct hash_algo *algo, |
| 147 | void **ctxp) |
Philipp Tomsich | 6e2ac3e | 2018-11-25 19:22:19 +0100 | [diff] [blame] | 148 | { |
| 149 | uint16_t *ctx = malloc(sizeof(uint16_t)); |
| 150 | *ctx = 0; |
| 151 | *ctxp = ctx; |
| 152 | return 0; |
| 153 | } |
| 154 | |
Simon Glass | 52b51ab | 2025-01-26 11:43:14 -0700 | [diff] [blame] | 155 | static int __maybe_unused hash_update_crc16_ccitt(struct hash_algo *algo, |
| 156 | void *ctx, const void *buf, |
| 157 | unsigned int size, |
| 158 | int is_last) |
Philipp Tomsich | 6e2ac3e | 2018-11-25 19:22:19 +0100 | [diff] [blame] | 159 | { |
| 160 | *((uint16_t *)ctx) = crc16_ccitt(*((uint16_t *)ctx), buf, size); |
| 161 | return 0; |
| 162 | } |
| 163 | |
Simon Glass | 52b51ab | 2025-01-26 11:43:14 -0700 | [diff] [blame] | 164 | static int __maybe_unused hash_finish_crc16_ccitt(struct hash_algo *algo, |
| 165 | void *ctx, void *dest_buf, |
| 166 | int size) |
Philipp Tomsich | 6e2ac3e | 2018-11-25 19:22:19 +0100 | [diff] [blame] | 167 | { |
| 168 | if (size < algo->digest_size) |
| 169 | return -1; |
| 170 | |
| 171 | *((uint16_t *)dest_buf) = *((uint16_t *)ctx); |
| 172 | free(ctx); |
| 173 | return 0; |
| 174 | } |
| 175 | |
Simon Glass | 577226c | 2021-09-25 19:43:24 -0600 | [diff] [blame] | 176 | static int __maybe_unused hash_init_crc32(struct hash_algo *algo, void **ctxp) |
Hung-ying Tyan | f061b1a | 2014-03-03 12:19:28 +0100 | [diff] [blame] | 177 | { |
| 178 | uint32_t *ctx = malloc(sizeof(uint32_t)); |
| 179 | *ctx = 0; |
| 180 | *ctxp = ctx; |
| 181 | return 0; |
| 182 | } |
| 183 | |
Simon Glass | 577226c | 2021-09-25 19:43:24 -0600 | [diff] [blame] | 184 | static int __maybe_unused hash_update_crc32(struct hash_algo *algo, void *ctx, |
| 185 | const void *buf, unsigned int size, |
| 186 | int is_last) |
Hung-ying Tyan | f061b1a | 2014-03-03 12:19:28 +0100 | [diff] [blame] | 187 | { |
| 188 | *((uint32_t *)ctx) = crc32(*((uint32_t *)ctx), buf, size); |
| 189 | return 0; |
| 190 | } |
| 191 | |
Simon Glass | 577226c | 2021-09-25 19:43:24 -0600 | [diff] [blame] | 192 | static int __maybe_unused hash_finish_crc32(struct hash_algo *algo, void *ctx, |
| 193 | void *dest_buf, int size) |
Hung-ying Tyan | f061b1a | 2014-03-03 12:19:28 +0100 | [diff] [blame] | 194 | { |
| 195 | if (size < algo->digest_size) |
| 196 | return -1; |
| 197 | |
| 198 | *((uint32_t *)dest_buf) = *((uint32_t *)ctx); |
| 199 | free(ctx); |
| 200 | return 0; |
| 201 | } |
| 202 | |
Simon Glass | b879045 | 2012-12-05 14:46:36 +0000 | [diff] [blame] | 203 | /* |
Tom Rini | 03361c7 | 2017-08-14 16:38:07 -0400 | [diff] [blame] | 204 | * These are the hash algorithms we support. If we have hardware acceleration |
| 205 | * is enable we will use that, otherwise a software version of the algorithm. |
| 206 | * Note that algorithm names must be in lower case. |
Simon Glass | b879045 | 2012-12-05 14:46:36 +0000 | [diff] [blame] | 207 | */ |
| 208 | static struct hash_algo hash_algo[] = { |
Simon Glass | 383dd57 | 2021-09-25 19:43:18 -0600 | [diff] [blame] | 209 | #if CONFIG_IS_ENABLED(MD5) |
Alexandru Gagniuc | f301658 | 2021-09-02 19:54:20 -0500 | [diff] [blame] | 210 | { |
| 211 | .name = "md5", |
| 212 | .digest_size = MD5_SUM_LEN, |
| 213 | .chunk_size = CHUNKSZ_MD5, |
| 214 | .hash_func_ws = md5_wd, |
| 215 | }, |
| 216 | #endif |
Simon Glass | 383dd57 | 2021-09-25 19:43:18 -0600 | [diff] [blame] | 217 | #if CONFIG_IS_ENABLED(SHA1) |
Akshay Saraswat | cbd8f2c | 2013-03-20 21:00:58 +0000 | [diff] [blame] | 218 | { |
Wolfgang Denk | 62fb2b4 | 2021-09-27 17:42:39 +0200 | [diff] [blame] | 219 | .name = "sha1", |
Tom Rini | 03361c7 | 2017-08-14 16:38:07 -0400 | [diff] [blame] | 220 | .digest_size = SHA1_SUM_LEN, |
| 221 | .chunk_size = CHUNKSZ_SHA1, |
Simon Glass | 383dd57 | 2021-09-25 19:43:18 -0600 | [diff] [blame] | 222 | #if CONFIG_IS_ENABLED(SHA_HW_ACCEL) |
Tom Rini | 03361c7 | 2017-08-14 16:38:07 -0400 | [diff] [blame] | 223 | .hash_func_ws = hw_sha1, |
| 224 | #else |
| 225 | .hash_func_ws = sha1_csum_wd, |
gaurav rana | ef20159 | 2015-02-20 12:51:46 +0530 | [diff] [blame] | 226 | #endif |
Simon Glass | 383dd57 | 2021-09-25 19:43:18 -0600 | [diff] [blame] | 227 | #if CONFIG_IS_ENABLED(SHA_PROG_HW_ACCEL) |
Tom Rini | 03361c7 | 2017-08-14 16:38:07 -0400 | [diff] [blame] | 228 | .hash_init = hw_sha_init, |
| 229 | .hash_update = hw_sha_update, |
| 230 | .hash_finish = hw_sha_finish, |
| 231 | #else |
| 232 | .hash_init = hash_init_sha1, |
| 233 | .hash_update = hash_update_sha1, |
| 234 | .hash_finish = hash_finish_sha1, |
Akshay Saraswat | cbd8f2c | 2013-03-20 21:00:58 +0000 | [diff] [blame] | 235 | #endif |
Simon Glass | b879045 | 2012-12-05 14:46:36 +0000 | [diff] [blame] | 236 | }, |
| 237 | #endif |
Simon Glass | 383dd57 | 2021-09-25 19:43:18 -0600 | [diff] [blame] | 238 | #if CONFIG_IS_ENABLED(SHA256) |
Simon Glass | b879045 | 2012-12-05 14:46:36 +0000 | [diff] [blame] | 239 | { |
Tom Rini | 03361c7 | 2017-08-14 16:38:07 -0400 | [diff] [blame] | 240 | .name = "sha256", |
| 241 | .digest_size = SHA256_SUM_LEN, |
| 242 | .chunk_size = CHUNKSZ_SHA256, |
Simon Glass | 383dd57 | 2021-09-25 19:43:18 -0600 | [diff] [blame] | 243 | #if CONFIG_IS_ENABLED(SHA_HW_ACCEL) |
Tom Rini | 03361c7 | 2017-08-14 16:38:07 -0400 | [diff] [blame] | 244 | .hash_func_ws = hw_sha256, |
| 245 | #else |
| 246 | .hash_func_ws = sha256_csum_wd, |
| 247 | #endif |
Simon Glass | 383dd57 | 2021-09-25 19:43:18 -0600 | [diff] [blame] | 248 | #if CONFIG_IS_ENABLED(SHA_PROG_HW_ACCEL) |
Tom Rini | 03361c7 | 2017-08-14 16:38:07 -0400 | [diff] [blame] | 249 | .hash_init = hw_sha_init, |
| 250 | .hash_update = hw_sha_update, |
| 251 | .hash_finish = hw_sha_finish, |
| 252 | #else |
| 253 | .hash_init = hash_init_sha256, |
| 254 | .hash_update = hash_update_sha256, |
| 255 | .hash_finish = hash_finish_sha256, |
| 256 | #endif |
Simon Glass | b879045 | 2012-12-05 14:46:36 +0000 | [diff] [blame] | 257 | }, |
| 258 | #endif |
Simon Glass | 383dd57 | 2021-09-25 19:43:18 -0600 | [diff] [blame] | 259 | #if CONFIG_IS_ENABLED(SHA384) |
Reuben Dowle | 1908fd9 | 2020-04-16 17:36:52 +1200 | [diff] [blame] | 260 | { |
| 261 | .name = "sha384", |
| 262 | .digest_size = SHA384_SUM_LEN, |
| 263 | .chunk_size = CHUNKSZ_SHA384, |
Simon Glass | 383dd57 | 2021-09-25 19:43:18 -0600 | [diff] [blame] | 264 | #if CONFIG_IS_ENABLED(SHA512_HW_ACCEL) |
Joel Stanley | 92efc1f | 2021-02-17 13:50:42 +1030 | [diff] [blame] | 265 | .hash_func_ws = hw_sha384, |
| 266 | #else |
Reuben Dowle | 1908fd9 | 2020-04-16 17:36:52 +1200 | [diff] [blame] | 267 | .hash_func_ws = sha384_csum_wd, |
Joel Stanley | 92efc1f | 2021-02-17 13:50:42 +1030 | [diff] [blame] | 268 | #endif |
Simon Glass | 383dd57 | 2021-09-25 19:43:18 -0600 | [diff] [blame] | 269 | #if CONFIG_IS_ENABLED(SHA512_HW_ACCEL) && CONFIG_IS_ENABLED(SHA_PROG_HW_ACCEL) |
Joel Stanley | 92efc1f | 2021-02-17 13:50:42 +1030 | [diff] [blame] | 270 | .hash_init = hw_sha_init, |
| 271 | .hash_update = hw_sha_update, |
| 272 | .hash_finish = hw_sha_finish, |
| 273 | #else |
Reuben Dowle | 1908fd9 | 2020-04-16 17:36:52 +1200 | [diff] [blame] | 274 | .hash_init = hash_init_sha384, |
| 275 | .hash_update = hash_update_sha384, |
| 276 | .hash_finish = hash_finish_sha384, |
Joel Stanley | 92efc1f | 2021-02-17 13:50:42 +1030 | [diff] [blame] | 277 | #endif |
Reuben Dowle | 1908fd9 | 2020-04-16 17:36:52 +1200 | [diff] [blame] | 278 | }, |
| 279 | #endif |
Simon Glass | 383dd57 | 2021-09-25 19:43:18 -0600 | [diff] [blame] | 280 | #if CONFIG_IS_ENABLED(SHA512) |
Reuben Dowle | 1908fd9 | 2020-04-16 17:36:52 +1200 | [diff] [blame] | 281 | { |
| 282 | .name = "sha512", |
| 283 | .digest_size = SHA512_SUM_LEN, |
| 284 | .chunk_size = CHUNKSZ_SHA512, |
Simon Glass | 383dd57 | 2021-09-25 19:43:18 -0600 | [diff] [blame] | 285 | #if CONFIG_IS_ENABLED(SHA512_HW_ACCEL) |
Joel Stanley | 92efc1f | 2021-02-17 13:50:42 +1030 | [diff] [blame] | 286 | .hash_func_ws = hw_sha512, |
| 287 | #else |
Reuben Dowle | 1908fd9 | 2020-04-16 17:36:52 +1200 | [diff] [blame] | 288 | .hash_func_ws = sha512_csum_wd, |
Joel Stanley | 92efc1f | 2021-02-17 13:50:42 +1030 | [diff] [blame] | 289 | #endif |
Simon Glass | 383dd57 | 2021-09-25 19:43:18 -0600 | [diff] [blame] | 290 | #if CONFIG_IS_ENABLED(SHA512_HW_ACCEL) && CONFIG_IS_ENABLED(SHA_PROG_HW_ACCEL) |
Joel Stanley | 92efc1f | 2021-02-17 13:50:42 +1030 | [diff] [blame] | 291 | .hash_init = hw_sha_init, |
| 292 | .hash_update = hw_sha_update, |
| 293 | .hash_finish = hw_sha_finish, |
| 294 | #else |
Reuben Dowle | 1908fd9 | 2020-04-16 17:36:52 +1200 | [diff] [blame] | 295 | .hash_init = hash_init_sha512, |
| 296 | .hash_update = hash_update_sha512, |
| 297 | .hash_finish = hash_finish_sha512, |
Joel Stanley | 92efc1f | 2021-02-17 13:50:42 +1030 | [diff] [blame] | 298 | #endif |
Reuben Dowle | 1908fd9 | 2020-04-16 17:36:52 +1200 | [diff] [blame] | 299 | }, |
| 300 | #endif |
Simon Glass | 52b51ab | 2025-01-26 11:43:14 -0700 | [diff] [blame] | 301 | #if CONFIG_IS_ENABLED(CRC16) |
Simon Glass | 0bbd76f | 2013-02-24 20:30:22 +0000 | [diff] [blame] | 302 | { |
Philipp Tomsich | 6e2ac3e | 2018-11-25 19:22:19 +0100 | [diff] [blame] | 303 | .name = "crc16-ccitt", |
| 304 | .digest_size = 2, |
| 305 | .chunk_size = CHUNKSZ, |
| 306 | .hash_func_ws = crc16_ccitt_wd_buf, |
| 307 | .hash_init = hash_init_crc16_ccitt, |
| 308 | .hash_update = hash_update_crc16_ccitt, |
| 309 | .hash_finish = hash_finish_crc16_ccitt, |
| 310 | }, |
Simon Glass | 52b51ab | 2025-01-26 11:43:14 -0700 | [diff] [blame] | 311 | #endif |
Simon Glass | dc020a2 | 2024-12-19 11:29:07 -0700 | [diff] [blame] | 312 | #if CONFIG_IS_ENABLED(CRC8) && IS_ENABLED(CONFIG_HASH_CRC8) |
| 313 | { |
| 314 | .name = "crc8", |
| 315 | .digest_size = 1, |
| 316 | .chunk_size = CHUNKSZ_CRC32, |
| 317 | .hash_func_ws = crc8_wd_buf, |
| 318 | }, |
| 319 | #endif |
Simon Glass | 577226c | 2021-09-25 19:43:24 -0600 | [diff] [blame] | 320 | #if CONFIG_IS_ENABLED(CRC32) |
Philipp Tomsich | 6e2ac3e | 2018-11-25 19:22:19 +0100 | [diff] [blame] | 321 | { |
Tom Rini | 03361c7 | 2017-08-14 16:38:07 -0400 | [diff] [blame] | 322 | .name = "crc32", |
| 323 | .digest_size = 4, |
| 324 | .chunk_size = CHUNKSZ_CRC32, |
| 325 | .hash_func_ws = crc32_wd_buf, |
| 326 | .hash_init = hash_init_crc32, |
| 327 | .hash_update = hash_update_crc32, |
| 328 | .hash_finish = hash_finish_crc32, |
Simon Glass | 0bbd76f | 2013-02-24 20:30:22 +0000 | [diff] [blame] | 329 | }, |
Simon Glass | 577226c | 2021-09-25 19:43:24 -0600 | [diff] [blame] | 330 | #endif |
Simon Glass | b879045 | 2012-12-05 14:46:36 +0000 | [diff] [blame] | 331 | }; |
| 332 | |
Simon Glass | 0bbd76f | 2013-02-24 20:30:22 +0000 | [diff] [blame] | 333 | /* Try to minimize code size for boards that don't want much hashing */ |
Simon Glass | 905ea88 | 2023-02-05 15:36:42 -0700 | [diff] [blame] | 334 | #if CONFIG_IS_ENABLED(SHA256) || IS_ENABLED(CONFIG_CMD_SHA1SUM) || \ |
Simon Glass | 778451e | 2023-02-05 15:36:32 -0700 | [diff] [blame] | 335 | CONFIG_IS_ENABLED(CRC32_VERIFY) || IS_ENABLED(CONFIG_CMD_HASH) || \ |
Igor Opaniuk | 489a578 | 2024-03-02 16:05:48 +0100 | [diff] [blame] | 336 | CONFIG_IS_ENABLED(SHA384) || CONFIG_IS_ENABLED(SHA512) || \ |
| 337 | IS_ENABLED(CONFIG_CMD_MD5SUM) |
Simon Glass | 0bbd76f | 2013-02-24 20:30:22 +0000 | [diff] [blame] | 338 | #define multi_hash() 1 |
| 339 | #else |
| 340 | #define multi_hash() 0 |
| 341 | #endif |
| 342 | |
Ruchika Gupta | c915ceb | 2015-01-23 16:01:58 +0530 | [diff] [blame] | 343 | int hash_lookup_algo(const char *algo_name, struct hash_algo **algop) |
| 344 | { |
| 345 | int i; |
| 346 | |
| 347 | for (i = 0; i < ARRAY_SIZE(hash_algo); i++) { |
| 348 | if (!strcmp(algo_name, hash_algo[i].name)) { |
| 349 | *algop = &hash_algo[i]; |
| 350 | return 0; |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | debug("Unknown hash algorithm '%s'\n", algo_name); |
| 355 | return -EPROTONOSUPPORT; |
| 356 | } |
| 357 | |
| 358 | int hash_progressive_lookup_algo(const char *algo_name, |
| 359 | struct hash_algo **algop) |
| 360 | { |
| 361 | int i; |
| 362 | |
| 363 | for (i = 0; i < ARRAY_SIZE(hash_algo); i++) { |
| 364 | if (!strcmp(algo_name, hash_algo[i].name)) { |
| 365 | if (hash_algo[i].hash_init) { |
| 366 | *algop = &hash_algo[i]; |
| 367 | return 0; |
| 368 | } |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | debug("Unknown hash algorithm '%s'\n", algo_name); |
| 373 | return -EPROTONOSUPPORT; |
| 374 | } |
| 375 | |
| 376 | #ifndef USE_HOSTCC |
Stefan Roese | 0ed2e46 | 2015-05-18 14:08:24 +0200 | [diff] [blame] | 377 | int hash_parse_string(const char *algo_name, const char *str, uint8_t *result) |
| 378 | { |
| 379 | struct hash_algo *algo; |
| 380 | int ret; |
| 381 | int i; |
| 382 | |
| 383 | ret = hash_lookup_algo(algo_name, &algo); |
| 384 | if (ret) |
| 385 | return ret; |
| 386 | |
| 387 | for (i = 0; i < algo->digest_size; i++) { |
| 388 | char chr[3]; |
| 389 | |
Simon Glass | b827f39 | 2021-07-24 09:03:28 -0600 | [diff] [blame] | 390 | strlcpy(chr, &str[i * 2], 3); |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 391 | result[i] = hextoul(chr, NULL); |
Stefan Roese | 0ed2e46 | 2015-05-18 14:08:24 +0200 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | return 0; |
| 395 | } |
| 396 | |
Tom Rini | 6173838 | 2016-01-05 08:47:48 -0500 | [diff] [blame] | 397 | int hash_block(const char *algo_name, const void *data, unsigned int len, |
| 398 | uint8_t *output, int *output_size) |
| 399 | { |
| 400 | struct hash_algo *algo; |
| 401 | int ret; |
| 402 | |
| 403 | ret = hash_lookup_algo(algo_name, &algo); |
| 404 | if (ret) |
| 405 | return ret; |
| 406 | |
| 407 | if (output_size && *output_size < algo->digest_size) { |
| 408 | debug("Output buffer size %d too small (need %d bytes)", |
| 409 | *output_size, algo->digest_size); |
| 410 | return -ENOSPC; |
| 411 | } |
| 412 | if (output_size) |
| 413 | *output_size = algo->digest_size; |
| 414 | algo->hash_func_ws(data, len, output, algo->chunk_size); |
| 415 | |
| 416 | return 0; |
| 417 | } |
| 418 | |
Simon Glass | 0e84d96 | 2024-09-29 19:49:50 -0600 | [diff] [blame] | 419 | #if !defined(CONFIG_XPL_BUILD) && (defined(CONFIG_CMD_HASH) || \ |
Igor Opaniuk | 489a578 | 2024-03-02 16:05:48 +0100 | [diff] [blame] | 420 | defined(CONFIG_CMD_SHA1SUM) || defined(CONFIG_CMD_CRC32)) || \ |
| 421 | defined(CONFIG_CMD_MD5SUM) |
Simon Glass | b879045 | 2012-12-05 14:46:36 +0000 | [diff] [blame] | 422 | /** |
| 423 | * store_result: Store the resulting sum to an address or variable |
| 424 | * |
| 425 | * @algo: Hash algorithm being used |
| 426 | * @sum: Hash digest (algo->digest_size bytes) |
| 427 | * @dest: Destination, interpreted as a hex address if it starts |
Simon Glass | 80e345a | 2013-02-24 17:33:26 +0000 | [diff] [blame] | 428 | * with * (or allow_env_vars is 0) or otherwise as an |
| 429 | * environment variable. |
| 430 | * @allow_env_vars: non-zero to permit storing the result to an |
| 431 | * variable environment |
Simon Glass | b879045 | 2012-12-05 14:46:36 +0000 | [diff] [blame] | 432 | */ |
Simon Glass | a3b240b | 2014-06-12 07:24:41 -0600 | [diff] [blame] | 433 | static void store_result(struct hash_algo *algo, const uint8_t *sum, |
Simon Glass | 80e345a | 2013-02-24 17:33:26 +0000 | [diff] [blame] | 434 | const char *dest, int allow_env_vars) |
Simon Glass | b879045 | 2012-12-05 14:46:36 +0000 | [diff] [blame] | 435 | { |
| 436 | unsigned int i; |
Simon Glass | 80e345a | 2013-02-24 17:33:26 +0000 | [diff] [blame] | 437 | int env_var = 0; |
Simon Glass | b879045 | 2012-12-05 14:46:36 +0000 | [diff] [blame] | 438 | |
Simon Glass | 80e345a | 2013-02-24 17:33:26 +0000 | [diff] [blame] | 439 | /* |
| 440 | * If environment variables are allowed, then we assume that 'dest' |
| 441 | * is an environment variable, unless it starts with *, in which |
| 442 | * case we assume it is an address. If not allowed, it is always an |
| 443 | * address. This is to support the crc32 command. |
| 444 | */ |
| 445 | if (allow_env_vars) { |
| 446 | if (*dest == '*') |
| 447 | dest++; |
| 448 | else |
| 449 | env_var = 1; |
| 450 | } |
Simon Glass | b879045 | 2012-12-05 14:46:36 +0000 | [diff] [blame] | 451 | |
Simon Glass | 80e345a | 2013-02-24 17:33:26 +0000 | [diff] [blame] | 452 | if (env_var) { |
Simon Glass | b879045 | 2012-12-05 14:46:36 +0000 | [diff] [blame] | 453 | char str_output[HASH_MAX_DIGEST_SIZE * 2 + 1]; |
| 454 | char *str_ptr = str_output; |
| 455 | |
| 456 | for (i = 0; i < algo->digest_size; i++) { |
| 457 | sprintf(str_ptr, "%02x", sum[i]); |
| 458 | str_ptr += 2; |
| 459 | } |
Jeroen Hofstee | b14c052 | 2014-06-09 11:02:02 +0200 | [diff] [blame] | 460 | *str_ptr = '\0'; |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 461 | env_set(dest, str_output); |
Simon Glass | 80e345a | 2013-02-24 17:33:26 +0000 | [diff] [blame] | 462 | } else { |
Simon Glass | 68f1556 | 2013-02-24 17:33:31 +0000 | [diff] [blame] | 463 | ulong addr; |
| 464 | void *buf; |
Simon Glass | 80e345a | 2013-02-24 17:33:26 +0000 | [diff] [blame] | 465 | |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 466 | addr = hextoul(dest, NULL); |
Simon Glass | 68f1556 | 2013-02-24 17:33:31 +0000 | [diff] [blame] | 467 | buf = map_sysmem(addr, algo->digest_size); |
| 468 | memcpy(buf, sum, algo->digest_size); |
| 469 | unmap_sysmem(buf); |
Simon Glass | b879045 | 2012-12-05 14:46:36 +0000 | [diff] [blame] | 470 | } |
| 471 | } |
| 472 | |
| 473 | /** |
| 474 | * parse_verify_sum: Parse a hash verification parameter |
| 475 | * |
| 476 | * @algo: Hash algorithm being used |
| 477 | * @verify_str: Argument to parse. If it starts with * then it is |
| 478 | * interpreted as a hex address containing the hash. |
| 479 | * If the length is exactly the right number of hex digits |
| 480 | * for the digest size, then we assume it is a hex digest. |
| 481 | * Otherwise we assume it is an environment variable, and |
| 482 | * look up its value (it must contain a hex digest). |
| 483 | * @vsum: Returns binary digest value (algo->digest_size bytes) |
Simon Glass | 80e345a | 2013-02-24 17:33:26 +0000 | [diff] [blame] | 484 | * @allow_env_vars: non-zero to permit storing the result to an environment |
| 485 | * variable. If 0 then verify_str is assumed to be an |
| 486 | * address, and the * prefix is not expected. |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 487 | * Return: 0 if ok, non-zero on error |
Simon Glass | b879045 | 2012-12-05 14:46:36 +0000 | [diff] [blame] | 488 | */ |
Simon Glass | a3b240b | 2014-06-12 07:24:41 -0600 | [diff] [blame] | 489 | static int parse_verify_sum(struct hash_algo *algo, char *verify_str, |
| 490 | uint8_t *vsum, int allow_env_vars) |
Simon Glass | b879045 | 2012-12-05 14:46:36 +0000 | [diff] [blame] | 491 | { |
Simon Glass | 80e345a | 2013-02-24 17:33:26 +0000 | [diff] [blame] | 492 | int env_var = 0; |
| 493 | |
| 494 | /* See comment above in store_result() */ |
| 495 | if (allow_env_vars) { |
| 496 | if (*verify_str == '*') |
| 497 | verify_str++; |
| 498 | else |
| 499 | env_var = 1; |
| 500 | } |
| 501 | |
Nikolay Dimitrov | 810b84d | 2014-12-12 20:01:23 +0200 | [diff] [blame] | 502 | if (!env_var) { |
Simon Glass | 68f1556 | 2013-02-24 17:33:31 +0000 | [diff] [blame] | 503 | ulong addr; |
| 504 | void *buf; |
Simon Glass | b879045 | 2012-12-05 14:46:36 +0000 | [diff] [blame] | 505 | |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 506 | addr = hextoul(verify_str, NULL); |
Simon Glass | 68f1556 | 2013-02-24 17:33:31 +0000 | [diff] [blame] | 507 | buf = map_sysmem(addr, algo->digest_size); |
| 508 | memcpy(vsum, buf, algo->digest_size); |
Simon Glass | b879045 | 2012-12-05 14:46:36 +0000 | [diff] [blame] | 509 | } else { |
Simon Glass | b879045 | 2012-12-05 14:46:36 +0000 | [diff] [blame] | 510 | char *vsum_str; |
| 511 | int digits = algo->digest_size * 2; |
| 512 | |
| 513 | /* |
| 514 | * As with the original code from sha1sum.c, we assume that a |
| 515 | * string which matches the digest size exactly is a hex |
| 516 | * string and not an environment variable. |
| 517 | */ |
| 518 | if (strlen(verify_str) == digits) |
| 519 | vsum_str = verify_str; |
| 520 | else { |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 521 | vsum_str = env_get(verify_str); |
Simon Glass | b879045 | 2012-12-05 14:46:36 +0000 | [diff] [blame] | 522 | if (vsum_str == NULL || strlen(vsum_str) != digits) { |
| 523 | printf("Expected %d hex digits in env var\n", |
| 524 | digits); |
| 525 | return 1; |
| 526 | } |
| 527 | } |
| 528 | |
Stefan Roese | 0ed2e46 | 2015-05-18 14:08:24 +0200 | [diff] [blame] | 529 | hash_parse_string(algo->name, vsum_str, vsum); |
Simon Glass | b879045 | 2012-12-05 14:46:36 +0000 | [diff] [blame] | 530 | } |
| 531 | return 0; |
| 532 | } |
| 533 | |
Tom Rini | 6173838 | 2016-01-05 08:47:48 -0500 | [diff] [blame] | 534 | static void hash_show(struct hash_algo *algo, ulong addr, ulong len, uint8_t *output) |
Simon Glass | b879045 | 2012-12-05 14:46:36 +0000 | [diff] [blame] | 535 | { |
| 536 | int i; |
| 537 | |
| 538 | printf("%s for %08lx ... %08lx ==> ", algo->name, addr, addr + len - 1); |
| 539 | for (i = 0; i < algo->digest_size; i++) |
| 540 | printf("%02x", output[i]); |
| 541 | } |
| 542 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 543 | int hash_command(const char *algo_name, int flags, struct cmd_tbl *cmdtp, |
| 544 | int flag, int argc, char *const argv[]) |
Simon Glass | b879045 | 2012-12-05 14:46:36 +0000 | [diff] [blame] | 545 | { |
Simon Glass | b879045 | 2012-12-05 14:46:36 +0000 | [diff] [blame] | 546 | ulong addr, len; |
Simon Glass | b879045 | 2012-12-05 14:46:36 +0000 | [diff] [blame] | 547 | |
Nikolay Dimitrov | 810b84d | 2014-12-12 20:01:23 +0200 | [diff] [blame] | 548 | if ((argc < 2) || ((flags & HASH_FLAG_VERIFY) && (argc < 3))) |
Simon Glass | b879045 | 2012-12-05 14:46:36 +0000 | [diff] [blame] | 549 | return CMD_RET_USAGE; |
| 550 | |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 551 | addr = hextoul(*argv++, NULL); |
| 552 | len = hextoul(*argv++, NULL); |
Simon Glass | 80e345a | 2013-02-24 17:33:26 +0000 | [diff] [blame] | 553 | |
Simon Glass | 0bbd76f | 2013-02-24 20:30:22 +0000 | [diff] [blame] | 554 | if (multi_hash()) { |
| 555 | struct hash_algo *algo; |
Breno Lima | 45e6512 | 2018-01-17 10:03:45 -0200 | [diff] [blame] | 556 | u8 *output; |
Simon Glass | a3b240b | 2014-06-12 07:24:41 -0600 | [diff] [blame] | 557 | uint8_t vsum[HASH_MAX_DIGEST_SIZE]; |
Simon Glass | 68f1556 | 2013-02-24 17:33:31 +0000 | [diff] [blame] | 558 | void *buf; |
Simon Glass | b879045 | 2012-12-05 14:46:36 +0000 | [diff] [blame] | 559 | |
Hung-ying Tyan | f061b1a | 2014-03-03 12:19:28 +0100 | [diff] [blame] | 560 | if (hash_lookup_algo(algo_name, &algo)) { |
Simon Glass | 0bbd76f | 2013-02-24 20:30:22 +0000 | [diff] [blame] | 561 | printf("Unknown hash algorithm '%s'\n", algo_name); |
| 562 | return CMD_RET_USAGE; |
| 563 | } |
| 564 | argc -= 2; |
| 565 | |
| 566 | if (algo->digest_size > HASH_MAX_DIGEST_SIZE) { |
| 567 | puts("HASH_MAX_DIGEST_SIZE exceeded\n"); |
| 568 | return 1; |
| 569 | } |
Simon Glass | b879045 | 2012-12-05 14:46:36 +0000 | [diff] [blame] | 570 | |
Breno Lima | 45e6512 | 2018-01-17 10:03:45 -0200 | [diff] [blame] | 571 | output = memalign(ARCH_DMA_MINALIGN, |
| 572 | sizeof(uint32_t) * HASH_MAX_DIGEST_SIZE); |
Sergei Antonov | 1ddd8a6 | 2023-06-12 22:59:10 +0300 | [diff] [blame] | 573 | if (!output) |
| 574 | return CMD_RET_FAILURE; |
Breno Lima | 45e6512 | 2018-01-17 10:03:45 -0200 | [diff] [blame] | 575 | |
Simon Glass | 68f1556 | 2013-02-24 17:33:31 +0000 | [diff] [blame] | 576 | buf = map_sysmem(addr, len); |
| 577 | algo->hash_func_ws(buf, len, output, algo->chunk_size); |
| 578 | unmap_sysmem(buf); |
Simon Glass | b879045 | 2012-12-05 14:46:36 +0000 | [diff] [blame] | 579 | |
Simon Glass | 0bbd76f | 2013-02-24 20:30:22 +0000 | [diff] [blame] | 580 | /* Try to avoid code bloat when verify is not needed */ |
Daniel Thompson | a9e2c67 | 2017-05-19 17:26:58 +0100 | [diff] [blame] | 581 | #if defined(CONFIG_CRC32_VERIFY) || defined(CONFIG_SHA1SUM_VERIFY) || \ |
Igor Opaniuk | 489a578 | 2024-03-02 16:05:48 +0100 | [diff] [blame] | 582 | defined(CONFIG_MD5SUM_VERIFY) || defined(CONFIG_HASH_VERIFY) |
Simon Glass | 0bbd76f | 2013-02-24 20:30:22 +0000 | [diff] [blame] | 583 | if (flags & HASH_FLAG_VERIFY) { |
Simon Glass | b879045 | 2012-12-05 14:46:36 +0000 | [diff] [blame] | 584 | #else |
Simon Glass | 0bbd76f | 2013-02-24 20:30:22 +0000 | [diff] [blame] | 585 | if (0) { |
Simon Glass | b879045 | 2012-12-05 14:46:36 +0000 | [diff] [blame] | 586 | #endif |
Simon Glass | 0bbd76f | 2013-02-24 20:30:22 +0000 | [diff] [blame] | 587 | if (parse_verify_sum(algo, *argv, vsum, |
Simon Glass | 80e345a | 2013-02-24 17:33:26 +0000 | [diff] [blame] | 588 | flags & HASH_FLAG_ENV)) { |
Simon Glass | 0bbd76f | 2013-02-24 20:30:22 +0000 | [diff] [blame] | 589 | printf("ERROR: %s does not contain a valid " |
| 590 | "%s sum\n", *argv, algo->name); |
Sergei Antonov | 1ddd8a6 | 2023-06-12 22:59:10 +0300 | [diff] [blame] | 591 | free(output); |
Simon Glass | 0bbd76f | 2013-02-24 20:30:22 +0000 | [diff] [blame] | 592 | return 1; |
| 593 | } |
| 594 | if (memcmp(output, vsum, algo->digest_size) != 0) { |
| 595 | int i; |
Simon Glass | b879045 | 2012-12-05 14:46:36 +0000 | [diff] [blame] | 596 | |
Simon Glass | 7f3fa54 | 2014-06-02 22:04:49 -0600 | [diff] [blame] | 597 | hash_show(algo, addr, len, output); |
Simon Glass | 0bbd76f | 2013-02-24 20:30:22 +0000 | [diff] [blame] | 598 | printf(" != "); |
| 599 | for (i = 0; i < algo->digest_size; i++) |
| 600 | printf("%02x", vsum[i]); |
| 601 | puts(" ** ERROR **\n"); |
Sergei Antonov | 1ddd8a6 | 2023-06-12 22:59:10 +0300 | [diff] [blame] | 602 | free(output); |
Simon Glass | 0bbd76f | 2013-02-24 20:30:22 +0000 | [diff] [blame] | 603 | return 1; |
| 604 | } |
| 605 | } else { |
Simon Glass | 7f3fa54 | 2014-06-02 22:04:49 -0600 | [diff] [blame] | 606 | hash_show(algo, addr, len, output); |
Simon Glass | 0bbd76f | 2013-02-24 20:30:22 +0000 | [diff] [blame] | 607 | printf("\n"); |
| 608 | |
| 609 | if (argc) { |
| 610 | store_result(algo, output, *argv, |
| 611 | flags & HASH_FLAG_ENV); |
| 612 | } |
Simon Glass | b879045 | 2012-12-05 14:46:36 +0000 | [diff] [blame] | 613 | } |
Simon Glass | 0bbd76f | 2013-02-24 20:30:22 +0000 | [diff] [blame] | 614 | |
Sergei Antonov | 1ddd8a6 | 2023-06-12 22:59:10 +0300 | [diff] [blame] | 615 | free(output); |
| 616 | |
Simon Glass | 0bbd76f | 2013-02-24 20:30:22 +0000 | [diff] [blame] | 617 | /* Horrible code size hack for boards that just want crc32 */ |
Simon Glass | b879045 | 2012-12-05 14:46:36 +0000 | [diff] [blame] | 618 | } else { |
Simon Glass | 0bbd76f | 2013-02-24 20:30:22 +0000 | [diff] [blame] | 619 | ulong crc; |
| 620 | ulong *ptr; |
| 621 | |
| 622 | crc = crc32_wd(0, (const uchar *)addr, len, CHUNKSZ_CRC32); |
| 623 | |
| 624 | printf("CRC32 for %08lx ... %08lx ==> %08lx\n", |
| 625 | addr, addr + len - 1, crc); |
Simon Glass | b879045 | 2012-12-05 14:46:36 +0000 | [diff] [blame] | 626 | |
Tom Rini | 62780f0 | 2013-11-07 07:39:48 -0500 | [diff] [blame] | 627 | if (argc >= 3) { |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 628 | ptr = (ulong *)hextoul(argv[0], NULL); |
Simon Glass | 0bbd76f | 2013-02-24 20:30:22 +0000 | [diff] [blame] | 629 | *ptr = crc; |
Simon Glass | 80e345a | 2013-02-24 17:33:26 +0000 | [diff] [blame] | 630 | } |
Simon Glass | b879045 | 2012-12-05 14:46:36 +0000 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | return 0; |
| 634 | } |
Simon Glass | b22ec7a | 2017-05-17 09:05:34 -0600 | [diff] [blame] | 635 | #endif /* CONFIG_CMD_HASH || CONFIG_CMD_SHA1SUM || CONFIG_CMD_CRC32) */ |
| 636 | #endif /* !USE_HOSTCC */ |