From patchwork Fri Jan 12 12:39:58 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: 124320 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp2019532qgn; Fri, 12 Jan 2018 04:47:57 -0800 (PST) X-Google-Smtp-Source: ACJfBouduhp8nDRNG/gVe99Jz3r6NWS/45PaKi6T39YX3HSrg3HB+4CTOKVt8Q/WOIVaYVqHwcfp X-Received: by 10.80.179.14 with SMTP id q14mr36488989edd.251.1515761277757; Fri, 12 Jan 2018 04:47:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515761277; cv=none; d=google.com; s=arc-20160816; b=ZDISV98JD5ZerRg/ValVP+v6EjIHCLIA35xFcOAUMrxVwbzLkFWn8mHHhu8k1syR/F 95ZVAwxhY1fyDuJMBEGncx40pVpsChudvFH2IJv60IUGP1mLprzukbt57z/HjB4uuLY8 4AA/+1b65FIXTXCHGvcn0h8SGiRs1wlzSy+y8pN99RtgUhjqVLJEfFVbVCOeYzPzPt+I GD1W9JYrQAYZO4cy7E9MQJYwMy9xM0LlNax2dw6RSZm93hvuRbFSbHrJr/J3ywjRb2hn daIAoaEzKl7maX9VTojupSUiQK+4kPWr2jPxJwiBLQ6yIT5Z4WGJp5OlYolf09/x81Lo eGQw== 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=GxBDeVhbOuhFSqISpePv7pGbLjlmwPxGBxkmI06aSiE=; b=aMX2yfK19USorFSk8yj1ziI7eaLJLJR0/Ps256Dh4FtJhTvzsdGdXg64rt8OkzHjsQ iq1Q0FDlrA0uWCAWXqlLQ3zYs3Jy4fwriKvwXuXygHeD2I2SsFgu2HBGWmbYnmJ3DTNm e+dBl1HCRp0S/3xPseLPHuWsVI3xgaZesvFJE6X76jbKEWz8p7U0kDlNpsfc862IJcub wfNTjD4u/cT4jCVuPeb06eQfRs5nuxYUjUj1JTJonbM+QkEVVhDZqWzzEqMkKoTR6k+r 42i+J+KV99RnvhKdmWO5kPb4hD35Ds6N5+NdQ1V/bhUu0O9edxp/dz2j/y/CTOzc+4Vz r7Mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=ID/JNclH; 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 g45si3000275edb.218.2018.01.12.04.47.57; Fri, 12 Jan 2018 04:47:57 -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=ID/JNclH; 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 14039C220B3; Fri, 12 Jan 2018 12:42:12 +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 C2D4EC22135; Fri, 12 Jan 2018 12:40:47 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id B1E58C220AD; Fri, 12 Jan 2018 12:40:32 +0000 (UTC) Received: from mail-wm0-f67.google.com (mail-wm0-f67.google.com [74.125.82.67]) by lists.denx.de (Postfix) with ESMTPS id 337BAC22180 for ; Fri, 12 Jan 2018 12:40:28 +0000 (UTC) Received: by mail-wm0-f67.google.com with SMTP id b141so11924496wme.1 for ; Fri, 12 Jan 2018 04:40: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=u7vE7YWrpw+jBpx+sSS7j9qiOYEqTcirLMPHF0Jw0YQ=; b=ID/JNclHmXyL+Dxjnu+I8NQfM220uVZF1h0otIgr0vGW5qCbETn2HLhyxS4I3tGdRv SlK81c1AIQJ84C2i/0yoJkTqxfxtgL1EvyRmjs5vrYJafmXGuc6SKJ8WKhTucXfMLp6P A/88ux+GcctCujT8MpRH06SuU7fiFg27x7Nm4= 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=u7vE7YWrpw+jBpx+sSS7j9qiOYEqTcirLMPHF0Jw0YQ=; b=A+shIcR3gXfrEpZXmpZMZzqhz4pmBnQM+63IiTurCLWryYu4xRrrGMP0AnyP89CN4o BAM672JskWWHlL/16+CeqqFakGu0KPSY4t02UpkOwLw0MdL1X5P5Td/El9wbkJbsc1s8 UjyJ5SyFwEUXVlYRn4QxYBfcM7rQTaTiOEMoMsoBFt9kohw9yg41aTdqAQfT78P184lg P0/KlxzTw3IHhQfW5cTdphfPQkcwkfqkFbz1UIurlxu5+I3SDmYbDmJv4xtyqZfcgXrY io1b5E9lrmIFIbHr7sOpT2RfK8OdhHyHwvfrIlCkP8Guekwjjo3cOAV+R7miBqVYoUmT WUgQ== X-Gm-Message-State: AKwxytcEaxrBegCUdFTvq/iaYPIJGfhy5KJFLipthMrVtn1zbCqcASLF Wq4iVaecsoo104rZxqNNV5dtE2iO+2E= X-Received: by 10.80.245.116 with SMTP id w49mr6865690edm.73.1515760827510; Fri, 12 Jan 2018 04:40:27 -0800 (PST) Received: from localhost.localdomain ([109.255.42.2]) by smtp.gmail.com with ESMTPSA id w2sm13893585edb.4.2018.01.12.04.40.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Jan 2018 04:40:26 -0800 (PST) From: Bryan O'Donoghue To: u-boot@lists.denx.de, brenomatheus@gmail.com Date: Fri, 12 Jan 2018 12:39:58 +0000 Message-Id: <1515760819-15116-5-git-send-email-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1515760819-15116-1-git-send-email-bryan.odonoghue@linaro.org> References: <1515760819-15116-1-git-send-email-bryan.odonoghue@linaro.org> Cc: Fabio Estevam Subject: [U-Boot] [PATCH v6 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 Tested-by: Breno Lima Reviewed-by: Fabio Estevam --- 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)