From patchwork Tue Jan 2 16:43:49 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: 123173 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp9180153qgn; Tue, 2 Jan 2018 08:57:07 -0800 (PST) X-Google-Smtp-Source: ACJfBosJ2bly2tqFoeWOGrAdqV494pYrvrUgZmsfPMLjVE24nTNpt87qE3E+/9AVDbagH8Q/Viwn X-Received: by 10.80.176.194 with SMTP id j60mr63813306edd.254.1514912227626; Tue, 02 Jan 2018 08:57:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514912227; cv=none; d=google.com; s=arc-20160816; b=HZRdc/V2TZgrHKZrXVw0EaTaVHUs0R7ieQkl35nBYuZmL38XFb++eZxcG8HhlmO9cb E+Om7XH2rr4D8DRpkh08BKPGZNLoNSzjGeiOMxCvZgVXI44X7yV0+L+i1Zn1lOnIbykj 5yxrxs19zxzQG9HaDz5zEhZ1tKcxheLhFg1grgFeqfqTZx7ydc7b/VCYXf38kq8ng+Tw 4eAot0A5kzMxPpr8oORrWHNujt6Hdib2PZiF3gW97Xi3BF6BhuDdnyxumHpQIVpgUKrK 4t9aZg+3wJMKvKjYOJZAjP72hBgeTYDJG0hF3mHgrluumXV03ZA3IbATQ9yjS8tT508U ffvA== 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=/WitLXfEnpiCLqcc5cbQcLmodoRowOstK7tA67Wctsk=; b=SEM8BsZQYipTsyFG+m+GyMNd3F7a88eA5thNbXqZlPBIAT/prqCKb8xJhAQerwOFcK RLVEsi6q5pocgp9haowXMRBbrloS7cLDm5tJhL+eUhH2shDOz1jM9wi8z2poTkYXTEV0 qsiE+Kqen2toRFGkeCyJn/U8BVyRZML3f2WXtzkHBsOZ6tjxeytFe61CFcEz9e7oo7Np lvzey3XcYqLV/idgpw5XvrED33KE4OwLjMy09uwk4Zw3B7zA5yEuPgfNZNsF0VCyDzDS Yl/AZX7Y0J/xrU0frcBzgyCK7n+Rdpj8f67UJ7AOdp/ST4fbMC0+KV0D6+H/iqkNNhzk nVRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=LuHJ52FF; 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 o15si4630574edk.480.2018.01.02.08.57.07; Tue, 02 Jan 2018 08:57:07 -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=LuHJ52FF; 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 28596C21DE7; Tue, 2 Jan 2018 16:45:52 +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 2A6CBC21DF4; Tue, 2 Jan 2018 16:44:48 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id F2C44C21C2B; Tue, 2 Jan 2018 16:44:31 +0000 (UTC) Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) by lists.denx.de (Postfix) with ESMTPS id 46DB4C21DD9 for ; Tue, 2 Jan 2018 16:44:27 +0000 (UTC) Received: by mail-wm0-f68.google.com with SMTP id 9so62082307wme.4 for ; Tue, 02 Jan 2018 08:44:27 -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=tEb+zxvqiXfooPFKqTTt4TM4oFUuaaywnnCJUJSankY=; b=LuHJ52FF7jNb3l6ECeqIXD7zaiePmyNUGO/mr63zVzdZwjROFxxsg5Iq669wbAC3v2 eb3FM2TsLw4XGI2laZIMQDfWAgt55kbBvv2JSsGszU2ghJPGLuSQCCSeDQJug7SVo3cd CmWOuMlGgH+y7SF2riZ4LOk9Xp5EUkQOi/vO0= 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=tEb+zxvqiXfooPFKqTTt4TM4oFUuaaywnnCJUJSankY=; b=rxt1hr+/EZ2xTbmYy/veKbNP3pCj9WxVwMR6GpzgiYqnLcNV0BWUVBIVY+qmWvRGcl mQWKXBcUZE7hTPiIYLNbnVZmHxHRYD/Kp3S8Cui9C6ayMCVZuCIRy2onCshgNQ8iBuNf FPbjywHp+7s6ZWVLEQMbFxoc6npEaQD53ud/WGCd0o6LBe49HcIUtvs1tfCq619/hY3R ToSGFEIODZhAuj8YMhXPeccNEbZDwFXs3180TILzxtL82NGTzjLx9C6DSOpPbr597yMG bGyYK9vaZr6hEYgVT7YfH0qgJJTsPZX4+wWWgKi2smmrZ3iO9kHqxkDvm5OW42nFFds1 3MxA== X-Gm-Message-State: AKGB3mIcL5ENOW1lsWOm+yVlrn1fFSle6la2dTfmD5OVk88J63XajwLz MVgOBF9MioRBTQfyd4RLR3JSZn+w55o= X-Received: by 10.80.170.207 with SMTP id r15mr65667626edc.220.1514911466663; Tue, 02 Jan 2018 08:44:26 -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.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 02 Jan 2018 08:44:25 -0800 (PST) From: Bryan O'Donoghue To: u-boot@lists.denx.de, brenomatheus@gmail.com Date: Tue, 2 Jan 2018 16:43:49 +0000 Message-Id: <1514911451-4520-4-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 03/25] arm: imx: hab: Optimise flow of authenticate_image on is_enabled 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" There is no need to call is_enabled() twice in authenticate_image - it does nothing but add an additional layer of indentation. We can check for is_enabled() at the start of the function and return the result code directly. 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 | 138 ++++++++++++++++++++++++------------------------ 1 file changed, 69 insertions(+), 69 deletions(-) diff --git a/arch/arm/mach-imx/hab.c b/arch/arm/mach-imx/hab.c index 9fe6d43..6f86c02 100644 --- a/arch/arm/mach-imx/hab.c +++ b/arch/arm/mach-imx/hab.c @@ -428,91 +428,91 @@ int authenticate_image(uint32_t ddr_start, uint32_t image_size) hab_rvt_entry = hab_rvt_entry_p; hab_rvt_exit = hab_rvt_exit_p; - if (is_hab_enabled()) { - printf("\nAuthenticate image from DDR location 0x%x...\n", - ddr_start); + if (!is_hab_enabled()) { + puts("hab fuse not enabled\n"); + return result; + } - hab_caam_clock_enable(1); + printf("\nAuthenticate image from DDR location 0x%x...\n", + ddr_start); - if (hab_rvt_entry() == HAB_SUCCESS) { - /* If not already aligned, Align to ALIGN_SIZE */ - ivt_offset = (image_size + ALIGN_SIZE - 1) & - ~(ALIGN_SIZE - 1); + hab_caam_clock_enable(1); - start = ddr_start; - bytes = ivt_offset + IVT_SIZE + CSF_PAD_SIZE; + if (hab_rvt_entry() == HAB_SUCCESS) { + /* 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; } + } else { + puts("hab entry function fail\n"); + } - hab_caam_clock_enable(0); + hab_caam_clock_enable(0); #if !defined(CONFIG_SPL_BUILD) - get_hab_status(); + get_hab_status(); #endif - } else { - puts("hab fuse not enabled\n"); - } - - if ((!is_hab_enabled()) || (load_addr != 0)) + if (load_addr != 0) result = 0; return result;