diff mbox series

[U-Boot] cmd: memio: Add support functions to read/write data

Message ID 20190930085106.25722-1-kameyama.eiji@fujitsu.com
State New
Delegated to: Tom Rini
Headers show
Series [U-Boot] cmd: memio: Add support functions to read/write data | expand

Commit Message

kameyama eiji Sept. 30, 2019, 8:51 a.m. UTC
The existing source code (binop.c) includes read/write function to
read/write data on DDR. To use these functions and avoid duplicate code,
based on the existing functions, move and update the read/write function
to a public file which is memio file.
- New memio includes support functions to read/write data from/to DDR.
- Update binop.c file to use read/write functions.

Signed-off-by: Dao Van Trung <trungdv@vn.fujitsu.com>
Signed-off-by: Pham Duc Tung <tungpd@vn.fujitsu.com>
Signed-off-by: kameyama eiji <kameyama.eiji@fujitsu.com>
---
 cmd/Makefile    |  1 +
 cmd/binop.c     | 24 +++---------------------
 cmd/memio.c     | 42 ++++++++++++++++++++++++++++++++++++++++++
 include/memio.h | 16 ++++++++++++++++
 4 files changed, 62 insertions(+), 21 deletions(-)
 create mode 100644 cmd/memio.c
 create mode 100644 include/memio.h
diff mbox series

Patch

diff --git a/cmd/Makefile b/cmd/Makefile
index ac843b4b16..8c241b256e 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -86,6 +86,7 @@  obj-$(CONFIG_CMD_LOG) += log.o
 obj-$(CONFIG_ID_EEPROM) += mac.o
 obj-$(CONFIG_CMD_MD5SUM) += md5sum.o
 obj-$(CONFIG_CMD_MEMORY) += mem.o
+obj-y += memio.o
 obj-$(CONFIG_CMD_IO) += io.o
 obj-$(CONFIG_CMD_MFSL) += mfsl.o
 obj-$(CONFIG_CMD_MII) += mii.o
diff --git a/cmd/binop.c b/cmd/binop.c
index 6d2df5f3dd..c14ca09fc3 100644
--- a/cmd/binop.c
+++ b/cmd/binop.c
@@ -7,6 +7,7 @@ 
 #include <malloc.h>
 #include <mapmem.h>
 #include <linux/ctype.h>
+#include <memio.h>
 
 enum {
 	OP_ID_XOR,
@@ -44,26 +45,6 @@  void read_from_env_var(char *varname, u8 *result)
 		hex2bin(result, varname, strlen(varname) / 2);
 }
 
-void read_from_mem(ulong addr, u8 *result, ulong len)
-{
-	u8 *src;
-
-	src = map_sysmem(addr, len);
-	memcpy(result, src, len);
-	unmap_sysmem(src);
-}
-
-void write_to_mem(char *varname, u8 *result, ulong len)
-{
-	ulong addr;
-	u8 *buf;
-
-	addr = simple_strtoul(varname, NULL, 16);
-	buf = map_sysmem(addr, len);
-	memcpy(buf, result, len);
-	unmap_sysmem(buf);
-}
-
 static int do_binop(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
 	ulong len;
@@ -134,7 +115,8 @@  static int do_binop(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	destarg = argv[5];
 
 	if (*destarg == '*')
-		write_to_mem(destarg + 1, result, len); /* Skip asterisk */
+		write_to_mem(simple_strtoul(destarg + 1, NULL, 16),
+			     result, len); /* Skip asterisk */
 	else
 		write_to_env_var(destarg, result, len);
 exit:
diff --git a/cmd/memio.c b/cmd/memio.c
new file mode 100644
index 0000000000..b9da5e5294
--- /dev/null
+++ b/cmd/memio.c
@@ -0,0 +1,42 @@ 
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * cmd/memio.c
+ *     Support functions to read/write data from/to DDR
+ *     physical address.
+ *
+ * Copyright (C) 2019 FUJITSU VIETNAM LIMITED and FUJITSU COMPUTER
+ * TECHNOLOGIES LIMITED. All rights reserved.
+ */
+#include <common.h>
+#include <mapmem.h>
+#include <memio.h>
+
+/**
+ * read_from_mem() - Read data from DDR
+ * @addr:	Physical address on DDR
+ * @result:	Buffer for read data
+ * @len:	Data length
+ */
+void read_from_mem(ulong addr, u8 *result, ulong len)
+{
+	u8 *src;
+
+	src = map_sysmem(addr, len);
+	memcpy(result, src, len);
+	unmap_sysmem(src);
+}
+
+/**
+ * write_to_mem() - Write data to DDR
+ * @addr:	Physical address on DDR
+ * @result:	Buffer of write data
+ * @len:	Data length
+ */
+void write_to_mem(ulong addr, u8 *result, ulong len)
+{
+	u8 *buf;
+
+	buf = map_sysmem(addr, len);
+	memcpy(buf, result, len);
+	unmap_sysmem(buf);
+}
diff --git a/include/memio.h b/include/memio.h
new file mode 100644
index 0000000000..c5f397393b
--- /dev/null
+++ b/include/memio.h
@@ -0,0 +1,16 @@ 
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * include/memio.h
+ *     This file declares support functions to read/write from/to
+ *     DDR physical address.
+ *
+ * Copyright (C) 2019 FUJITSU VIETNAM LIMITED and FUJITSU COMPUTER
+ * TECHNOLOGIES LIMITED. All rights reserved.
+ */
+#ifndef _MEMIO_H_
+#define _MEMIO_H_
+
+void read_from_mem(ulong addr, u8 *result, ulong len);
+void write_to_mem(ulong addr, u8 *result, ulong len);
+
+#endif /* _MEMIO_H_ */