From patchwork Tue Aug 23 21:52:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jae Hyun Yoo X-Patchwork-Id: 1669474 X-Patchwork-Delegate: monstr@monstr.eu Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=quicinc.com header.i=@quicinc.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=SinE5VnH; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MC30X3814z1ygc for ; Wed, 24 Aug 2022 07:54:20 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id CFCF38483F; Tue, 23 Aug 2022 23:53:54 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=quicinc.com header.i=@quicinc.com header.b="SinE5VnH"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3F6DB83FFF; Tue, 23 Aug 2022 23:53:46 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E183F83F69 for ; Tue, 23 Aug 2022 23:53:42 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=quic_jaehyoo@quicinc.com Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 27NLWQhK027250; Tue, 23 Aug 2022 21:53:19 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=qcppdkim1; bh=VrHJbPX3eyG2GKFkRoVsALnAJFiT+7n+7ePTqzABXGE=; b=SinE5VnHbnQHXhvVj5MN3yWMQ2jXlzitXonKf4EYJO8Ai2pEVtGhXIlAc2vQNqmEBYCz VYPc//x5UK7lc2YnfQu6sJWQjb1rScpzHQVkKTcsutX7wbFiv8fMnf3SsQGoX/tW7wg2 /YlF9DziXoJFofkxXr8qd6d6o+UFRUViCXsFoNm0KKfvoqBSoXv+mD73B8mYw5ueQqgv 6Lz/TpmD97rpfTYOmYG2hCFNDNrrZD3pdGsQ9Qom8SwEHQT4Kb1lVVSsbj5kJIb1oxBg ocEdlirdb22urJEFhHrwwBvsntM+iskcK/cGufUGo5YbnXsgC09QT4xmuGY06dAx/QX4 pA== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3j52pqgutw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 23 Aug 2022 21:53:19 +0000 Received: from pps.filterd (NALASPPMTA02.qualcomm.com [127.0.0.1]) by NALASPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTP id 27NLrIwY030551; Tue, 23 Aug 2022 21:53:18 GMT Received: from pps.reinject (localhost [127.0.0.1]) by NALASPPMTA02.qualcomm.com (PPS) with ESMTPS id 3j46u0y0v3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 23 Aug 2022 21:53:18 +0000 Received: from NALASPPMTA02.qualcomm.com (NALASPPMTA02.qualcomm.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 27NLrIPS030543; Tue, 23 Aug 2022 21:53:18 GMT Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA02.qualcomm.com (PPS) with ESMTPS id 27NLrIpm030542 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 23 Aug 2022 21:53:18 +0000 Received: from maru.qualcomm.com (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.29; Tue, 23 Aug 2022 14:53:16 -0700 From: Jae Hyun Yoo To: Michal Simek , Ovidiu Panait , Simon Glass , Mario Six , Masahisa Kojima , =?utf-8?q?Pali_Roh=C3=A1r?= , Heinrich Schuchardt , Ashok Reddy Soma , "Thomas Huth" , Huang Jianan , Chris Morgan , Roland Gaudig , Patrick Delaunay , Alexandru Gagniuc CC: Jamie Iles , Graeme Gregory , =?utf-8?q?C=C3=A9dric_Le_Goater?= , Jae Hyun Yoo , Subject: [PATCH v3 3/7] cmd: fru: fix a sandbox segfault issue Date: Tue, 23 Aug 2022 14:52:56 -0700 Message-ID: <20220823215300.1485789-4-quic_jaehyoo@quicinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220823215300.1485789-1-quic_jaehyoo@quicinc.com> References: <20220823215300.1485789-1-quic_jaehyoo@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nalasex01a.na.qualcomm.com (10.47.209.196) X-QCInternal: smtphost X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: LpNWwQCRAUubV0dcgjZ3hrzBXhe_OnhM X-Proofpoint-GUID: LpNWwQCRAUubV0dcgjZ3hrzBXhe_OnhM X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-08-23_09,2022-08-22_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 bulkscore=0 phishscore=0 mlxlogscore=954 clxscore=1015 malwarescore=0 lowpriorityscore=0 impostorscore=0 suspectscore=0 spamscore=0 mlxscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2208230082 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean 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 Reviewed-by: Simon Glass --- 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 #include #include +#include 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;