From patchwork Wed Dec 26 18:57:13 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [U-Boot,20/20] sandbox: Allow hash functions to work correctly Date: Wed, 26 Dec 2012 08:57:13 -0000 From: Simon Glass X-Patchwork-Id: 208191 Message-Id: <1356548233-5570-21-git-send-email-sjg@chromium.org> To: U-Boot Mailing List Cc: Tom Rini , Joe Hershberger , Kumar Gala Use map_sysmem() so that hashing is possible on sandbox. Signed-off-by: Simon Glass --- common/hash.c | 25 +++++++++++++++++-------- 1 files changed, 17 insertions(+), 8 deletions(-) diff --git a/common/hash.c b/common/hash.c index e92b4b1..2e0a67b 100644 --- a/common/hash.c +++ b/common/hash.c @@ -28,6 +28,7 @@ #include #include #include +#include /* * These are the hash algorithms we support. Chips which support accelerated @@ -72,10 +73,13 @@ static void store_result(struct hash_algo *algo, const u8 *sum, unsigned int i; if (*dest == '*') { - u8 *ptr; + ulong addr; + void *buf; - ptr = (u8 *)simple_strtoul(dest + 1, NULL, 16); - memcpy(ptr, sum, algo->digest_size); + addr = simple_strtoul(dest + 1, NULL, 16); + buf = map_sysmem(addr, algo->digest_size); + memcpy(buf, sum, algo->digest_size); + unmap_sysmem(buf); } else { char str_output[HASH_MAX_DIGEST_SIZE * 2 + 1]; char *str_ptr = str_output; @@ -105,10 +109,13 @@ static void store_result(struct hash_algo *algo, const u8 *sum, static int parse_verify_sum(struct hash_algo *algo, char *verify_str, u8 *vsum) { if (*verify_str == '*') { - u8 *ptr; + ulong addr; + void *buf; - ptr = (u8 *)simple_strtoul(verify_str + 1, NULL, 16); - memcpy(vsum, ptr, algo->digest_size); + addr = simple_strtoul(verify_str + 1, NULL, 16); + buf = map_sysmem(addr, algo->digest_size); + memcpy(vsum, buf, algo->digest_size); + unmap_sysmem(buf); } else { unsigned int i; char *vsum_str; @@ -169,6 +176,7 @@ int hash_command(const char *algo_name, int verify, cmd_tbl_t *cmdtp, int flag, { struct hash_algo *algo; ulong addr, len; + void *buf; u8 output[HASH_MAX_DIGEST_SIZE]; u8 vsum[HASH_MAX_DIGEST_SIZE]; @@ -189,8 +197,9 @@ int hash_command(const char *algo_name, int verify, cmd_tbl_t *cmdtp, int flag, return 1; } - algo->hash_func_ws((const unsigned char *)addr, len, output, - algo->chunk_size); + buf = map_sysmem(addr, len); + algo->hash_func_ws(buf, len, output, algo->chunk_size); + unmap_sysmem(buf); /* Try to avoid code bloat when verify is not needed */ #ifdef CONFIG_HASH_VERIFY