From patchwork Tue Nov 6 16:39:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Parthiban Nallathambi X-Patchwork-Id: 993818 X-Patchwork-Delegate: sbabic@denx.de 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=none (p=none dis=none) header.from=denx.de Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 42qFhJ2X4Bz9s8T for ; Wed, 7 Nov 2018 03:42:24 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 4F934C22711; Tue, 6 Nov 2018 16:42:21 +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=none 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 CEDAAC223AA; Tue, 6 Nov 2018 16:42:18 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id C94B5C2237B; Tue, 6 Nov 2018 16:39:36 +0000 (UTC) Received: from mail-out.m-online.net (mail-out.m-online.net [212.18.0.9]) by lists.denx.de (Postfix) with ESMTPS id 72D1AC2236D for ; Tue, 6 Nov 2018 16:39:36 +0000 (UTC) Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 42qFd4285Xz1qxlD; Tue, 6 Nov 2018 17:39:36 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 42qFd41pn4z1qr28; Tue, 6 Nov 2018 17:39:36 +0100 (CET) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id ogUq4082vFJE; Tue, 6 Nov 2018 17:39:35 +0100 (CET) X-Auth-Info: yeqGtyV4JdW34kgdxRqerRYM1ABvAUZIw2obX8EoFXw= Received: from xpert.denx.de (unknown [62.91.23.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA; Tue, 6 Nov 2018 17:39:35 +0100 (CET) From: Parthiban Nallathambi To: sbabic@denx.de, fabio.estevam@nxp.com, albert.u.boot@aribaud.net Date: Tue, 6 Nov 2018 17:39:25 +0100 Message-Id: <20181106163925.4180994-1-pn@denx.de> X-Mailer: git-send-email 2.17.2 X-Mailman-Approved-At: Tue, 06 Nov 2018 16:42:18 +0000 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH] imx: hab: extend hab_auth_img to calculate ivt_offset 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" Current implementation of hab_auth_img command needs ivt_offset to authenticate the image. But ivt header is placed at the end of image date after padding. This leaves the usage of hab_auth_img command to fixed size or static offset for ivt header. New function "get_image_ivt_offset" is introduced to find the ivt offset during runtime. The case conditional check in this function is same as boot_get_kernel in common/bootm.c With this variable length image e.g. FIT image with any random size can have IVT at the end and ivt_offset option can be left optional Can be used as "hab_auth_img $loadaddr $filesize" from u-boot script Signed-off-by: Parthiban Nallathambi --- arch/arm/mach-imx/hab.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/arch/arm/mach-imx/hab.c b/arch/arm/mach-imx/hab.c index b88acd13da..060d0866b3 100644 --- a/arch/arm/mach-imx/hab.c +++ b/arch/arm/mach-imx/hab.c @@ -6,6 +6,8 @@ #include #include #include +#include +#include #include #include #include @@ -302,18 +304,41 @@ static int do_hab_status(cmd_tbl_t *cmdtp, int flag, int argc, return 0; } +static ulong get_image_ivt_offset(ulong img_addr, ulong length) +{ + const void *buf; + + buf = map_sysmem(img_addr, 0); + switch (genimg_get_format(buf)) { +#if defined(CONFIG_IMAGE_FORMAT_LEGACY) + case IMAGE_FORMAT_LEGACY: + return (image_get_image_size((image_header_t *)img_addr) + + 0x1000 - 1) & ~(0x1000 - 1); +#endif +#if IMAGE_ENABLE_FIT + case IMAGE_FORMAT_FIT: + return (fit_get_size(buf) + 0x1000 - 1) & ~(0x1000 - 1); +#endif + default: + return 0; + } +} + static int do_authenticate_image(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { ulong addr, length, ivt_offset; int rcode = 0; - if (argc < 4) + if (argc < 3) return CMD_RET_USAGE; addr = simple_strtoul(argv[1], NULL, 16); length = simple_strtoul(argv[2], NULL, 16); - ivt_offset = simple_strtoul(argv[3], NULL, 16); + if (argc == 3) + ivt_offset = get_image_ivt_offset(addr, length); + else + ivt_offset = simple_strtoul(argv[3], NULL, 16); rcode = imx_hab_authenticate_image(addr, length, ivt_offset); if (rcode == 0)