From patchwork Tue Jan 2 16:43:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 123159 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp9170687qgn; Tue, 2 Jan 2018 08:46:43 -0800 (PST) X-Google-Smtp-Source: ACJfBouFVEEPZ8Kr6FLC8rMOEaLYnNeN93uANk4fQoN0LIxZJ0KbX8XczpUTNpDl0dbxdSE2NbOT X-Received: by 10.80.170.87 with SMTP id p23mr64758964edc.289.1514911602914; Tue, 02 Jan 2018 08:46:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514911602; cv=none; d=google.com; s=arc-20160816; b=t04Fb5XzrWX7cMLEGVyC0Ew/kBfZJQbnc9dLDnLl832uHjTvLTmY0b86rQq0TZ0Df+ 80UObHvlbrMBm7onsaZQ5+sbzumQxSi5KwToguxuHmFK8kICFuMIEb17uJKxlqwQWHTI tw+pu2zAvWF/WBXnWvt5kEMxZtlDV/9Ce7E68t5FWHX5cXlUBgFHR3tI1KB68JMMsBhV LUBrNnEozPbFPyLlrhhmDwI7niY1en0A657X4Xh8k8BCoc7BUbg+rfD+MGYmBwFvu0IX PSrWvDy7WGkfatZ2g+7zuKIitR9kFNJoWhdQs7GO1Zul/grn9CLBn3/kpmoj02M11j+0 JhgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:arc-authentication-results; bh=ltIxGxwbriNIdsJA8E5Tn2uUeswTayfs+quuAx+dYJY=; b=y49ItoXCvdykDkKT3lAy+vUsYC93qdAKeEV/M5HyEu0a+3gUi+fuCaDCPe+sTCnsER 7NZ/lZWV4fJNb87aZXvzBOw28G1TtL0I5BwGlHOuoSR8Pb+4IY7Un/dtBYuKpMy/lBei AQtmYg17NFrBjKoNWHBK2Tvep369tfaiJvZkr1OHksX+RNeJqyQ81V2bYpUW9UYaXp33 t30/c8dv8yr1W3IGPWp+vpdG4dBYwP3PQIqPWDto589AtpOdL0MUiM6NzosIaKtsG0U8 8STFrR7NqG0yiU8t2ocmN4aa2F0kjmNOIOc9/17zK/gUeVKixhxZn5/E/DfTGLE0qFCP aVHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=i6idi7gc; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id i59si4351795edd.106.2018.01.02.08.46.42; Tue, 02 Jan 2018 08:46:42 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=i6idi7gc; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.denx.de (Postfix, from userid 105) id 76A32C21E10; Tue, 2 Jan 2018 16:45:28 +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=RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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 0B32CC21DC8; Tue, 2 Jan 2018 16:44:42 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 935A1C21DF0; Tue, 2 Jan 2018 16:44:32 +0000 (UTC) Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) by lists.denx.de (Postfix) with ESMTPS id 76E93C21DD0 for ; Tue, 2 Jan 2018 16:44:28 +0000 (UTC) Received: by mail-wm0-f66.google.com with SMTP id i11so61727670wmf.4 for ; Tue, 02 Jan 2018 08:44:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=EH9nAsP2R6CcqdRJVaGDdlF3b/WA9xPFI4ki25Ui41g=; b=i6idi7gc0PhNHr1R/XVOaov9e2J/Zheg5ZlMhPZrzREge6d3SrsXkgH0T2NdorQMmy bwsK4IZQFjVK4AdQ3GGRyLp0JOpdvbNwJ+rhhC75KCgf9Sof7A42+pEVuIt1p7rrmGYL Fn9sJbehZ/JNZOzVX3Hq9yQVSitcXAqPdtKTE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=EH9nAsP2R6CcqdRJVaGDdlF3b/WA9xPFI4ki25Ui41g=; b=g6UkwCHFZG62I7xm+tx0PY4ZEGC/MOg4v/auIKqvp/ZTI4wia4FEvos9F6Aqajoik+ YM3SPj1WzFWPAVVPGpCOhEQC7+kE+P/U932IVF/OYQvDJ/H5Ebbh0fHYC7wYpVqH6ECF QD7+uj2pZKsrjEjq3OJuHGXEcKY2xWp1JZt+J/uEKlS3Dtnd8yotr+yYyrj77jHJJ0Zr IFekHKcGlkT42Kgp3iXsCc4BkfJ6AkuN6/LD6+zWHE9RqOQF81YAHvZ14lj9lnqiHMXF JyGPRIERwSIanR/mtzhgdlwXbbvbo7MMtK5tQrKzX6jCkRlVw0/gBh949aQhRhzbW9XU K4hg== X-Gm-Message-State: AKGB3mIwSxzUAjdgEagMO3dSAZ8BOhWBM4q0PfyoyfZPsBfnGv51Z4p/ SUoclDZ9IwdkomP3coi0F9N54j0F9Ok= X-Received: by 10.80.205.25 with SMTP id z25mr62153145edi.77.1514911467852; Tue, 02 Jan 2018 08:44:27 -0800 (PST) Received: from localhost.localdomain (D4CCACC7.cm-2.dynamic.ziggo.nl. [212.204.172.199]) by smtp.gmail.com with ESMTPSA id z5sm29850584edh.76.2018.01.02.08.44.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 02 Jan 2018 08:44:27 -0800 (PST) From: Bryan O'Donoghue To: u-boot@lists.denx.de, brenomatheus@gmail.com Date: Tue, 2 Jan 2018 16:43:50 +0000 Message-Id: <1514911451-4520-5-git-send-email-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1514911451-4520-1-git-send-email-bryan.odonoghue@linaro.org> References: <1514911451-4520-1-git-send-email-bryan.odonoghue@linaro.org> Cc: Fabio Estevam Subject: [U-Boot] [PATCH v4 04/25] arm: imx: hab: Optimise flow of authenticate_image on hab_entry fail 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: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" The current code disjoins an entire block of code on hab_entry pass/fail resulting in a large chunk of authenticate_image being offset to the right. Fix this by checking hab_entry() pass/failure and exiting the function directly if in an error state. Signed-off-by: Bryan O'Donoghue Cc: Stefano Babic Cc: Fabio Estevam Cc: Peng Fan Cc: Albert Aribaud Cc: Sven Ebenfeld Cc: George McCollister Cc: Breno Matheus Lima --- arch/arm/mach-imx/hab.c | 118 ++++++++++++++++++++++++------------------------ 1 file changed, 60 insertions(+), 58 deletions(-) diff --git a/arch/arm/mach-imx/hab.c b/arch/arm/mach-imx/hab.c index 6f86c02..f878b7b 100644 --- a/arch/arm/mach-imx/hab.c +++ b/arch/arm/mach-imx/hab.c @@ -438,75 +438,77 @@ int authenticate_image(uint32_t ddr_start, uint32_t image_size) hab_caam_clock_enable(1); - if (hab_rvt_entry() == HAB_SUCCESS) { - /* If not already aligned, Align to ALIGN_SIZE */ - ivt_offset = (image_size + ALIGN_SIZE - 1) & - ~(ALIGN_SIZE - 1); + if (hab_rvt_entry() != HAB_SUCCESS) { + puts("hab entry function fail\n"); + goto hab_caam_clock_disable; + } - start = ddr_start; - bytes = ivt_offset + IVT_SIZE + CSF_PAD_SIZE; + /* If not already aligned, Align to ALIGN_SIZE */ + ivt_offset = (image_size + ALIGN_SIZE - 1) & + ~(ALIGN_SIZE - 1); + + start = ddr_start; + bytes = ivt_offset + IVT_SIZE + CSF_PAD_SIZE; #ifdef DEBUG - printf("\nivt_offset = 0x%x, ivt addr = 0x%x\n", - ivt_offset, ddr_start + ivt_offset); - puts("Dumping IVT\n"); - print_buffer(ddr_start + ivt_offset, - (void *)(ddr_start + ivt_offset), - 4, 0x8, 0); - - puts("Dumping CSF Header\n"); - print_buffer(ddr_start + ivt_offset + IVT_SIZE, - (void *)(ddr_start + ivt_offset + IVT_SIZE), - 4, 0x10, 0); + printf("\nivt_offset = 0x%x, ivt addr = 0x%x\n", + ivt_offset, ddr_start + ivt_offset); + puts("Dumping IVT\n"); + print_buffer(ddr_start + ivt_offset, + (void *)(ddr_start + ivt_offset), + 4, 0x8, 0); + + puts("Dumping CSF Header\n"); + print_buffer(ddr_start + ivt_offset + IVT_SIZE, + (void *)(ddr_start + ivt_offset + IVT_SIZE), + 4, 0x10, 0); #if !defined(CONFIG_SPL_BUILD) - get_hab_status(); + get_hab_status(); #endif - puts("\nCalling authenticate_image in ROM\n"); - printf("\tivt_offset = 0x%x\n", ivt_offset); - printf("\tstart = 0x%08lx\n", start); - printf("\tbytes = 0x%x\n", bytes); + puts("\nCalling authenticate_image in ROM\n"); + printf("\tivt_offset = 0x%x\n", ivt_offset); + printf("\tstart = 0x%08lx\n", start); + printf("\tbytes = 0x%x\n", bytes); #endif - /* - * If the MMU is enabled, we have to notify the ROM - * code, or it won't flush the caches when needed. - * This is done, by setting the "pu_irom_mmu_enabled" - * word to 1. You can find its address by looking in - * the ROM map. This is critical for - * authenticate_image(). If MMU is enabled, without - * setting this bit, authentication will fail and may - * crash. - */ - /* Check MMU enabled */ - if (is_soc_type(MXC_SOC_MX6) && get_cr() & CR_M) { - if (is_mx6dq()) { - /* - * This won't work on Rev 1.0.0 of - * i.MX6Q/D, since their ROM doesn't - * do cache flushes. don't think any - * exist, so we ignore them. - */ - if (!is_mx6dqp()) - writel(1, MX6DQ_PU_IROM_MMU_EN_VAR); - } else if (is_mx6sdl()) { - writel(1, MX6DLS_PU_IROM_MMU_EN_VAR); - } else if (is_mx6sl()) { - writel(1, MX6SL_PU_IROM_MMU_EN_VAR); - } + /* + * If the MMU is enabled, we have to notify the ROM + * code, or it won't flush the caches when needed. + * This is done, by setting the "pu_irom_mmu_enabled" + * word to 1. You can find its address by looking in + * the ROM map. This is critical for + * authenticate_image(). If MMU is enabled, without + * setting this bit, authentication will fail and may + * crash. + */ + /* Check MMU enabled */ + if (is_soc_type(MXC_SOC_MX6) && get_cr() & CR_M) { + if (is_mx6dq()) { + /* + * This won't work on Rev 1.0.0 of + * i.MX6Q/D, since their ROM doesn't + * do cache flushes. don't think any + * exist, so we ignore them. + */ + if (!is_mx6dqp()) + writel(1, MX6DQ_PU_IROM_MMU_EN_VAR); + } else if (is_mx6sdl()) { + writel(1, MX6DLS_PU_IROM_MMU_EN_VAR); + } else if (is_mx6sl()) { + writel(1, MX6SL_PU_IROM_MMU_EN_VAR); } + } - load_addr = (uint32_t)hab_rvt_authenticate_image( - HAB_CID_UBOOT, - ivt_offset, (void **)&start, - (size_t *)&bytes, NULL); - if (hab_rvt_exit() != HAB_SUCCESS) { - puts("hab exit function fail\n"); - load_addr = 0; - } - } else { - puts("hab entry function fail\n"); + load_addr = (uint32_t)hab_rvt_authenticate_image( + HAB_CID_UBOOT, + ivt_offset, (void **)&start, + (size_t *)&bytes, NULL); + if (hab_rvt_exit() != HAB_SUCCESS) { + puts("hab exit function fail\n"); + load_addr = 0; } +hab_caam_clock_disable: hab_caam_clock_enable(0); #if !defined(CONFIG_SPL_BUILD)