u-boot.lists.denx.de archive mirror
 help / color / mirror / Atom feed
From: Jae Hyun Yoo <quic_jaehyoo@quicinc.com>
To: "Michal Simek" <michal.simek@amd.com>,
	"Ovidiu Panait" <ovidiu.panait@windriver.com>,
	"Simon Glass" <sjg@chromium.org>,
	"Mario Six" <mario.six@gdsys.cc>,
	"Masahisa Kojima" <masahisa.kojima@linaro.org>,
	"Pali Rohár" <pali@kernel.org>,
	"Heinrich Schuchardt" <xypron.glpk@gmx.de>,
	"Ashok Reddy Soma" <ashok.reddy.soma@xilinx.com>,
	"Thomas Huth" <thuth@redhat.com>,
	"Huang Jianan" <jnhuang95@gmail.com>,
	"Chris Morgan" <macromorgan@hotmail.com>,
	"Roland Gaudig" <roland.gaudig@weidmueller.com>,
	"Patrick Delaunay" <patrick.delaunay@foss.st.com>,
	"Alexandru Gagniuc" <mr.nuke.me@gmail.com>
Cc: "Jamie Iles" <quic_jiles@quicinc.com>,
	"Graeme Gregory" <quic_ggregory@quicinc.com>,
	"Cédric Le Goater" <clg@kaod.org>,
	"Jae Hyun Yoo" <quic_jaehyoo@quicinc.com>,
	u-boot@lists.denx.de
Subject: [PATCH v3 3/7] cmd: fru: fix a sandbox segfault issue
Date: Tue, 23 Aug 2022 14:52:56 -0700	[thread overview]
Message-ID: <20220823215300.1485789-4-quic_jaehyoo@quicinc.com> (raw)
In-Reply-To: <20220823215300.1485789-1-quic_jaehyoo@quicinc.com>

This command doesn't work with sandbox because direct memory access
causes a segfault error. Fix it up using map_sysmem().

Signed-off-by: Jae Hyun Yoo <quic_jaehyoo@quicinc.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
---
Changes from v2:
 * Added a 'Reviewed-by' tag. (Simon)

Changes from v1:
 * Newly added in v2.

 board/xilinx/common/board.c |  2 +-
 cmd/fru.c                   | 19 ++++++++++++++++---
 include/fru.h               |  4 ++--
 lib/fru_ops.c               | 17 ++++++++---------
 4 files changed, 27 insertions(+), 15 deletions(-)

diff --git a/board/xilinx/common/board.c b/board/xilinx/common/board.c
index e58b11d7f757..3292083c5250 100644
--- a/board/xilinx/common/board.c
+++ b/board/xilinx/common/board.c
@@ -241,7 +241,7 @@ static int xilinx_read_eeprom_fru(struct udevice *dev, char *name,
 		goto end;
 	}
 
-	fru_capture((unsigned long)fru_content);
+	fru_capture(fru_content);
 	if (gd->flags & GD_FLG_RELOC || (_DEBUG && CONFIG_IS_ENABLED(DTB_RESELECT))) {
 		printf("Xilinx I2C FRU format at %s:\n", name);
 		ret = fru_display(0);
diff --git a/cmd/fru.c b/cmd/fru.c
index 2ec5012af5ac..b2cadbec9780 100644
--- a/cmd/fru.c
+++ b/cmd/fru.c
@@ -9,12 +9,15 @@
 #include <fdtdec.h>
 #include <fru.h>
 #include <malloc.h>
+#include <mapmem.h>
 
 static int do_fru_capture(struct cmd_tbl *cmdtp, int flag, int argc,
 			  char *const argv[])
 {
 	unsigned long addr;
+	const void *buf;
 	char *endp;
+	int ret;
 
 	if (argc < cmdtp->maxargs)
 		return CMD_RET_USAGE;
@@ -23,7 +26,11 @@ static int do_fru_capture(struct cmd_tbl *cmdtp, int flag, int argc,
 	if (*argv[1] == 0 || *endp != 0)
 		return -1;
 
-	return fru_capture(addr);
+	buf = map_sysmem(addr, 0);
+	ret = fru_capture(buf);
+	unmap_sysmem(buf);
+
+	return ret;
 }
 
 static int do_fru_display(struct cmd_tbl *cmdtp, int flag, int argc,
@@ -37,13 +44,19 @@ static int do_fru_generate(struct cmd_tbl *cmdtp, int flag, int argc,
 			   char *const argv[])
 {
 	unsigned long addr;
+	const void *buf;
+	int ret;
 
 	if (argc < cmdtp->maxargs)
 		return CMD_RET_USAGE;
 
-	addr = hextoul(argv[2], NULL);
+	addr = hextoul(argv[3], NULL);
+
+	buf = map_sysmem(addr, 0);
+	ret = fru_generate(buf, argc - 3, argv + 3);
+	unmap_sysmem(buf);
 
-	return fru_generate(addr, argc - 3, argv + 3);
+	return ret;
 }
 
 static struct cmd_tbl cmd_fru_sub[] = {
diff --git a/include/fru.h b/include/fru.h
index 41655864dbf5..b158b80b5866 100644
--- a/include/fru.h
+++ b/include/fru.h
@@ -107,8 +107,8 @@ struct fru_table {
 #define FRU_TYPELEN_TYPE_ASCII8		3
 
 int fru_display(int verbose);
-int fru_capture(unsigned long addr);
-int fru_generate(unsigned long addr, int argc, char *const argv[]);
+int fru_capture(const void *addr);
+int fru_generate(const void *addr, int argc, char *const argv[]);
 u8 fru_checksum(u8 *addr, u8 len);
 int fru_check_type_len(u8 type_len, u8 language, u8 *type);
 const struct fru_table *fru_get_fru_data(void);
diff --git a/lib/fru_ops.c b/lib/fru_ops.c
index c0360f219c37..6ed1388b2fc8 100644
--- a/lib/fru_ops.c
+++ b/lib/fru_ops.c
@@ -91,7 +91,7 @@ static u8 fru_gen_type_len(u8 *addr, char *name)
 	return 1 + len;
 }
 
-int fru_generate(unsigned long addr, int argc, char *const argv[])
+int fru_generate(const void *addr, int argc, char *const argv[])
 {
 	struct fru_common_hdr *header = (struct fru_common_hdr *)addr;
 	struct fru_board_info_header *board_info;
@@ -155,8 +155,8 @@ int fru_generate(unsigned long addr, int argc, char *const argv[])
 
 	debug("checksum %x(addr %x)\n", *member, len);
 
-	env_set_hex("fru_addr", addr);
-	env_set_hex("filesize", (unsigned long)member - addr + 1);
+	env_set_hex("fru_addr", (ulong)addr);
+	env_set_hex("filesize", (ulong)member - (ulong)addr + 1);
 
 	return 0;
 }
@@ -171,7 +171,7 @@ static void fru_delete_custom_fields(struct list_head *custom_fields)
 	}
 }
 
-static int fru_append_custom_info(unsigned long addr,
+static int fru_append_custom_info(const void *addr,
 				  struct list_head *custom_fields)
 {
 	struct fru_custom_info *info = (struct fru_custom_info *)addr;
@@ -190,7 +190,7 @@ static int fru_append_custom_info(unsigned long addr,
 	return 0;
 }
 
-static int fru_parse_board(unsigned long addr)
+static int fru_parse_board(const void *addr)
 {
 	u8 i, type;
 	int len;
@@ -268,8 +268,7 @@ static void fru_delete_multirecs(struct list_head *multi_recs)
 	}
 }
 
-static int fru_append_multirec(unsigned long addr,
-			       struct list_head *multi_recs)
+static int fru_append_multirec(const void *addr, struct list_head *multi_recs)
 {
 	struct fru_multirec_info *mr_src = (struct fru_multirec_info *)addr;
 	struct fru_multirec_node *mr_new;
@@ -286,7 +285,7 @@ static int fru_append_multirec(unsigned long addr,
 	return 0;
 }
 
-static int fru_parse_multirec(unsigned long addr)
+static int fru_parse_multirec(const void *addr)
 {
 	u8 hdr_len = sizeof(struct fru_multirec_hdr);
 	struct fru_multirec_hdr *mr_hdr;
@@ -308,7 +307,7 @@ static int fru_parse_multirec(unsigned long addr)
 	return 0;
 }
 
-int fru_capture(unsigned long addr)
+int fru_capture(const void *addr)
 {
 	struct fru_common_hdr *hdr;
 	u8 checksum = 0;
-- 
2.25.1


  parent reply	other threads:[~2022-08-23 21:54 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-23 21:52 [PATCH v3 0/7] cmd/fru: move FRU handling support to common region Jae Hyun Yoo
2022-08-23 21:52 ` [PATCH v3 1/7] xilinx: common: refactor FRU handling support Jae Hyun Yoo
2022-08-23 21:52 ` [PATCH v3 2/7] cmd: fru: move FRU handling support to common region Jae Hyun Yoo
2022-08-23 21:52 ` Jae Hyun Yoo [this message]
2022-08-23 21:52 ` [PATCH v3 4/7] cmd: fru: add product info area parsing support Jae Hyun Yoo
2022-08-25  1:25   ` Simon Glass
2022-08-25 14:33     ` Jae Hyun Yoo
2022-08-25 15:08       ` Simon Glass
2022-08-23 21:52 ` [PATCH v3 5/7] doc: fru: add documentation for the fru command and APIs Jae Hyun Yoo
2022-08-23 21:52 ` [PATCH v3 6/7] test: py: fru: add a test for the fru command Jae Hyun Yoo
2022-08-25  1:25   ` Simon Glass
2022-08-25 14:35     ` Jae Hyun Yoo
2022-08-23 21:53 ` [PATCH v3 7/7] test: cmd: fru: add unit " Jae Hyun Yoo
2022-08-25  1:25   ` Simon Glass
2022-08-25 14:34     ` Jae Hyun Yoo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220823215300.1485789-4-quic_jaehyoo@quicinc.com \
    --to=quic_jaehyoo@quicinc.com \
    --cc=ashok.reddy.soma@xilinx.com \
    --cc=clg@kaod.org \
    --cc=jnhuang95@gmail.com \
    --cc=macromorgan@hotmail.com \
    --cc=mario.six@gdsys.cc \
    --cc=masahisa.kojima@linaro.org \
    --cc=michal.simek@amd.com \
    --cc=mr.nuke.me@gmail.com \
    --cc=ovidiu.panait@windriver.com \
    --cc=pali@kernel.org \
    --cc=patrick.delaunay@foss.st.com \
    --cc=quic_ggregory@quicinc.com \
    --cc=quic_jiles@quicinc.com \
    --cc=roland.gaudig@weidmueller.com \
    --cc=sjg@chromium.org \
    --cc=thuth@redhat.com \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).