diff mbox

[U-Boot,20/20] sandbox: Allow hash functions to work correctly

Message ID 1356548233-5570-21-git-send-email-sjg@chromium.org
State Superseded, archived
Delegated to: Simon Glass
Headers show

Commit Message

Simon Glass Dec. 26, 2012, 6:57 p.m. UTC
Use map_sysmem() so that hashing is possible on sandbox.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
 common/hash.c |   25 +++++++++++++++++--------
 1 files changed, 17 insertions(+), 8 deletions(-)

Comments

Simon Glass Feb. 15, 2013, 11:58 p.m. UTC | #1
On Wed, Dec 26, 2012 at 10:57 AM, Simon Glass <sjg@chromium.org> wrote:
> Use map_sysmem() so that hashing is possible on sandbox.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>

Applied to x86/master.

> ---
>  common/hash.c |   25 +++++++++++++++++--------
>  1 files changed, 17 insertions(+), 8 deletions(-)
diff mbox

Patch

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 <hash.h>
 #include <sha1.h>
 #include <sha256.h>
+#include <asm/io.h>
 
 /*
  * 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