From patchwork Wed Sep 4 10:31:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lokesh Vutla X-Patchwork-Id: 1157580 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=quarantine dis=none) header.from=ti.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ti.com header.i=@ti.com header.b="AS0LfRXw"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 46NgFg20n6z9sBF for ; Wed, 4 Sep 2019 20:35:35 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id F325BC21EB9; Wed, 4 Sep 2019 10:33:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 34AC7C21E1D; Wed, 4 Sep 2019 10:33:17 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 27E80C21DB5; Wed, 4 Sep 2019 10:32:50 +0000 (UTC) Received: from lelv0142.ext.ti.com (lelv0142.ext.ti.com [198.47.23.249]) by lists.denx.de (Postfix) with ESMTPS id 2A107C21E2F for ; Wed, 4 Sep 2019 10:32:47 +0000 (UTC) Received: from fllv0034.itg.ti.com ([10.64.40.246]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id x84AWjGg055749; Wed, 4 Sep 2019 05:32:45 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1567593165; bh=LyQTfuVH6zEx7yarDvkfytVHP6AEW25CfJpuy3i10kk=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=AS0LfRXwDMus4Y7N/jTCgeWPfIx81ujGlK6kX9WzKUzKqMFItdLx1DG2EMV+1lBpi qkRKOb9xKiXPh0YT/m+lBBN5kzobxdMbJ3Lvh2zWI8dv/xoDbhoo8jPNyVvNVR1O4b AjFxFBiUtBdPKxwwOlpoqz4BoLIeSFOzzLFdsUpU= Received: from DLEE104.ent.ti.com (dlee104.ent.ti.com [157.170.170.34]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id x84AWjDJ128113 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 4 Sep 2019 05:32:45 -0500 Received: from DLEE104.ent.ti.com (157.170.170.34) by DLEE104.ent.ti.com (157.170.170.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Wed, 4 Sep 2019 05:32:45 -0500 Received: from fllv0040.itg.ti.com (10.64.41.20) by DLEE104.ent.ti.com (157.170.170.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5 via Frontend Transport; Wed, 4 Sep 2019 05:32:45 -0500 Received: from uda0131933.india.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0040.itg.ti.com (8.15.2/8.15.2) with ESMTP id x84AWYUg122466; Wed, 4 Sep 2019 05:32:42 -0500 From: Lokesh Vutla To: Tom Rini , Date: Wed, 4 Sep 2019 16:01:28 +0530 Message-ID: <20190904103151.20121-4-lokeshvutla@ti.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190904103151.20121-1-lokeshvutla@ti.com> References: <20190904103151.20121-1-lokeshvutla@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Cc: fabien.dessenne@st.com, Tero Kristo Subject: [U-Boot] [PATCH v2 03/26] remoteproc: elf_loader: Always check the validity of the image before loading X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" rproc_elf32_load_image() rely on user to send a valid address for elf loading. Instead do a sanity check on the address passed by user. This will help all rproc elf users to not call sanity_check explicitly before calling elf_loading. Signed-off-by: Lokesh Vutla Reviewed-by: Fabien Dessenne --- drivers/remoteproc/rproc-elf-loader.c | 11 ++++++++--- drivers/remoteproc/stm32_copro.c | 9 +-------- include/remoteproc.h | 6 ++++-- test/dm/remoteproc.c | 5 +---- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/drivers/remoteproc/rproc-elf-loader.c b/drivers/remoteproc/rproc-elf-loader.c index 7574ba3fb3..238f51d3b5 100644 --- a/drivers/remoteproc/rproc-elf-loader.c +++ b/drivers/remoteproc/rproc-elf-loader.c @@ -64,13 +64,18 @@ int rproc_elf32_sanity_check(ulong addr, ulong size) return 0; } -/* A very simple elf loader, assumes the image is valid */ -int rproc_elf32_load_image(struct udevice *dev, unsigned long addr) +int rproc_elf32_load_image(struct udevice *dev, unsigned long addr, ulong size) { Elf32_Ehdr *ehdr; /* Elf header structure pointer */ Elf32_Phdr *phdr; /* Program header structure pointer */ const struct dm_rproc_ops *ops; - unsigned int i; + unsigned int i, ret; + + ret = rproc_elf32_sanity_check(addr, size); + if (ret) { + dev_err(dev, "Invalid ELF32 Image %d\n", ret); + return ret; + } ehdr = (Elf32_Ehdr *)addr; phdr = (Elf32_Phdr *)(addr + ehdr->e_phoff); diff --git a/drivers/remoteproc/stm32_copro.c b/drivers/remoteproc/stm32_copro.c index 71895daf9c..40bba37211 100644 --- a/drivers/remoteproc/stm32_copro.c +++ b/drivers/remoteproc/stm32_copro.c @@ -155,14 +155,7 @@ static int stm32_copro_load(struct udevice *dev, ulong addr, ulong size) return ret; } - /* Support only ELF32 image */ - ret = rproc_elf32_sanity_check(addr, size); - if (ret) { - dev_err(dev, "Invalid ELF32 image (%d)\n", ret); - return ret; - } - - return rproc_elf32_load_image(dev, addr); + return rproc_elf32_load_image(dev, addr, size); } /** diff --git a/include/remoteproc.h b/include/remoteproc.h index dbff1ce3cf..1ef88be7f7 100644 --- a/include/remoteproc.h +++ b/include/remoteproc.h @@ -218,9 +218,10 @@ int rproc_elf32_sanity_check(ulong addr, ulong size); * rproc_elf32_load_image() - load an ELF32 image * @dev: device loading the ELF32 image * @addr: valid ELF32 image address + * @size: size of the image * @return 0 if the image is successfully loaded, else appropriate error value. */ -int rproc_elf32_load_image(struct udevice *dev, unsigned long addr); +int rproc_elf32_load_image(struct udevice *dev, unsigned long addr, ulong size); #else static inline int rproc_init(void) { return -ENOSYS; } static inline int rproc_dev_init(int id) { return -ENOSYS; } @@ -234,7 +235,8 @@ static inline int rproc_is_running(int id) { return -ENOSYS; } static inline int rproc_elf32_sanity_check(ulong addr, ulong size) { return -ENOSYS; } static inline int rproc_elf32_load_image(struct udevice *dev, - unsigned long addr) { return -ENOSYS; } + unsigned long addr, ulong size) +{ return -ENOSYS; } #endif #endif /* _RPROC_H_ */ diff --git a/test/dm/remoteproc.c b/test/dm/remoteproc.c index a2c4be7c27..c77361c8f4 100644 --- a/test/dm/remoteproc.c +++ b/test/dm/remoteproc.c @@ -171,11 +171,8 @@ static int dm_test_remoteproc_elf(struct unit_test_state *uts) ut_assertnonnull(loaded_firmware); memset(loaded_firmware, 0, loaded_firmware_size); - /* Verify valid ELF format */ - ut_assertok(rproc_elf32_sanity_check((ulong)valid_elf32, size)); - /* Load firmware in loaded_firmware, and verify it */ - ut_assertok(rproc_elf32_load_image(dev, (unsigned long)valid_elf32)); + ut_assertok(rproc_elf32_load_image(dev, (ulong)valid_elf32, size)); ut_assertok(memcmp(loaded_firmware, valid_elf32, loaded_firmware_size)); unmap_physmem(loaded_firmware, MAP_NOCACHE);