From patchwork Fri Mar 9 16:55:30 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: 131169 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp1215516lja; Fri, 9 Mar 2018 08:59:32 -0800 (PST) X-Google-Smtp-Source: AG47ELtGki7JIiCdM9NwnWb4Lm8VsGK3KPg4qmiYiVYjkx3mTJK58fd/A4ZohXGN6UFpq1SEMfcn X-Received: by 10.80.132.5 with SMTP id 5mr25546343edp.139.1520614772633; Fri, 09 Mar 2018 08:59:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520614772; cv=none; d=google.com; s=arc-20160816; b=ThuRhA9IcyrCwnZhON3B95/fmOdQceQ7igsbSgqho/7CgmoQLcUSJjlLOJWpR+PgMu 4QOU4zI94EHPg51ujGNgKa9NZ79k9RTEBoCOU65pFa5Fixmtbgfne3RZXyzjzC+P34+b G3SJyYI/UUm9Xt/j0SCpvx8dIh9IdND9iKcHYcJGS9BgYB2yxwt3camSYWpoQsnE46QB JU0Y+y98v/Xtf8+0n2IyfnOQP45ShitUvPSSD1Ha7m3za8F+3U28CBOY/0NCaChV8X4r 1ZQN+cHkvejAT+mLnOnPSYiZZLMEF621YrbDpfhQbTAlLPZj0t+zq3HUpWGj2QpzQ+RL 6nCQ== 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=Nxpv16LWVEZoKd+RBY6AU4YSanVUUR5YuTIbpNNa33w=; b=Qo94qNCztsL6A5NO+A/imsoQKTloebrBmbIkyy+qcSxQWeCy+W2NHl9w79xqX07IPw ZxjKn2UNAr62pPnZPbhZBFfF9OzljT6tJNXza35uvJXY0QGdQq4R6cLc7I9SMSZyRaYI jEddxZ4tl7YN702Z7o5hWs71NQFaQwJ9vuvyi22np9mK/3FSPzs0JVLDYi+Mqz0gvt4P AaoxBIgukJEA4ftJ4IydWmF3ZPuTUWgbr7569r/ZU2SuilCUSseDHfCGO0FtFw8b5gIy SHECSmrSJA2cgQpY99dcV949iGuKntSdPhI5+tCsUuHEYRQUGICuFTbIAFj3hcc/kP/U w5+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=LIcxDRkW; 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 w10si328103edl.328.2018.03.09.08.59.32; Fri, 09 Mar 2018 08:59:32 -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=LIcxDRkW; 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 4339BC21DF3; Fri, 9 Mar 2018 16:58: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=RCVD_IN_DNSWL_BLOCKED, 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 DAB54C21DFF; Fri, 9 Mar 2018 16:56:16 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id B8BFBC21DD4; Fri, 9 Mar 2018 16:55:48 +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 80AF8C21D4A for ; Fri, 9 Mar 2018 16:55:44 +0000 (UTC) Received: by mail-wm0-f68.google.com with SMTP id q83so5108807wme.5 for ; Fri, 09 Mar 2018 08:55:44 -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=1Xeau/pafFYygWJPzlvvGX1TfjvwM2oL9f2/MJ5tLUQ=; b=LIcxDRkW7IJNFpHhYarqFyXUWGfjW5vctJ+iQiey2c+w6SIWYtnXBR5eRqSoo7c85W OX3MWfM1Ai/Wp4k49/TDLRLdiIctmCVZbkJXGozG/gj+XI1q8dX+kWvbiF+ROa54fH1c 99pJ7m1y/GkXkyfcPr7GbzYn+UOswAKu/slCg= 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=1Xeau/pafFYygWJPzlvvGX1TfjvwM2oL9f2/MJ5tLUQ=; b=kyAoWFNzSyOSEGj96NTjaA5bb9A/Ym1w/UvChMq4V+FxK+ny1I8xPN+L7obdt6PhbA YxZzxSC2ZikV31NEt8Nz7QtJfko597nFkhHDXEQMBS2CmxLZmoB3I/x+0XMkBagz0SeV CD3n7m1IzQnEre2f3yNGhzQRAe6jfUgHP3xl7n+ZSCfaxvWhACSifXVVxvjzR4wMMYO1 08JXsiyFo64R2KeQCwvdHLO8WHW42IV+LOVMitDV58JIaVAJbusiCK4n6LeE4qxQlRn5 PocZwxtUTgsPat5SNFqyIMq3sQDneLHoJB7pAKWKVncQU9oTVsHKMkLgCYcNZOLFrMVU Dqlg== X-Gm-Message-State: AElRT7FpAENxaPqCkNUPE7HQPyqD6XECXXj6RhsGrQPH33mTnFB0ELou mnn7tYTo46rf/oQiOV/yakP5gbe+Cuo= X-Received: by 10.80.149.132 with SMTP id w4mr12124156eda.229.1520614543814; Fri, 09 Mar 2018 08:55:43 -0800 (PST) Received: from localhost.localdomain ([109.255.42.2]) by smtp.gmail.com with ESMTPSA id e40sm960335ede.15.2018.03.09.08.55.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 09 Mar 2018 08:55:43 -0800 (PST) From: Bryan O'Donoghue To: U-Boot@lists.denx.de, trini@konsulko.com, afd@ti.com, kever.yang@rock-chips.com, philipp.tomsich@theobroma-systems.com, peng.fan@nxp.com Date: Fri, 9 Mar 2018 16:55:30 +0000 Message-Id: <1520614531-2164-10-git-send-email-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1520614531-2164-1-git-send-email-bryan.odonoghue@linaro.org> References: <1520614531-2164-1-git-send-email-bryan.odonoghue@linaro.org> Cc: Harinarayan Bhatta Subject: [U-Boot] [PATCH v5 09/10] image: Add IH_OS_TEE for TEE chain-load boot 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" This patch adds a new type IH_OS_TEE. This new OS type will be used for chain-loading to Linux via a TEE. With this patch in-place you can generate a bootable OPTEE image like this: mkimage -A arm -T kernel -O tee -C none -d tee.bin uTee.optee where "tee.bin" is the input binary prefixed with an OPTEE header and uTee.optee is the output prefixed with a u-boot wrapper header. This image type "-T kernel -O tee" is differentiated from the existing IH_TYPE_TEE "-T tee" in that the IH_TYPE is installed by u-boot (flow control returns to u-boot) whereas for the new IH_OS_TEE control passes to the OPTEE firmware and the firmware chainloads onto Linux. Andrew Davis gave the following ASCII diagram: IH_OS_TEE: (mkimage -T kernel -O tee) Non-Secure Secure BootROM | ------------- | v SPL | v U-Boot ------> <----- OP-TEE | V Linux IH_TYPE_TEE: (mkimage -T tee) Non-Secure Secure BootROM | ------------- | v SPL -------> <----- OP-TEE | v U-Boot | V Linux Signed-off-by: Bryan O'Donoghue Suggested-by: Andrew F. Davis Cc: Harinarayan Bhatta Cc: Andrew F. Davis Cc: Tom Rini Cc: Kever Yang Cc: Philipp Tomsich Cc: Peng Fan Link: http://mrvan.github.io/optee-imx6ul --- common/image.c | 1 + include/image.h | 1 + tools/default_image.c | 15 +++++++++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/common/image.c b/common/image.c index 14be3ca..61e3d25 100644 --- a/common/image.c +++ b/common/image.c @@ -100,6 +100,7 @@ static const table_entry_t uimage_os[] = { { IH_OS_OSE, "ose", "Enea OSE", }, { IH_OS_PLAN9, "plan9", "Plan 9", }, { IH_OS_RTEMS, "rtems", "RTEMS", }, + { IH_OS_TEE, "tee", "Trusted Execution Environment" }, { IH_OS_U_BOOT, "u-boot", "U-Boot", }, { IH_OS_VXWORKS, "vxworks", "VxWorks", }, #if defined(CONFIG_CMD_ELF) || defined(USE_HOSTCC) diff --git a/include/image.h b/include/image.h index dbdaecb..a0a530d 100644 --- a/include/image.h +++ b/include/image.h @@ -153,6 +153,7 @@ enum { IH_OS_PLAN9, /* Plan 9 */ IH_OS_OPENRTOS, /* OpenRTOS */ IH_OS_ARM_TRUSTED_FIRMWARE, /* ARM Trusted Firmware */ + IH_OS_TEE, /* Trusted Execution Environment */ IH_OS_COUNT, }; diff --git a/tools/default_image.c b/tools/default_image.c index 4e5568e..c67f66b 100644 --- a/tools/default_image.c +++ b/tools/default_image.c @@ -18,6 +18,7 @@ #include "mkimage.h" #include +#include #include static image_header_t header; @@ -90,6 +91,8 @@ static void image_set_header(void *ptr, struct stat *sbuf, int ifd, uint32_t checksum; time_t time; uint32_t imagesize; + uint32_t ep; + uint32_t addr; image_header_t * hdr = (image_header_t *)ptr; @@ -99,18 +102,26 @@ static void image_set_header(void *ptr, struct stat *sbuf, int ifd, sbuf->st_size - sizeof(image_header_t)); time = imagetool_get_source_date(params, sbuf->st_mtime); + ep = params->ep; + addr = params->addr; + if (params->type == IH_TYPE_FIRMWARE_IVT) /* Add size of CSF minus IVT */ imagesize = sbuf->st_size - sizeof(image_header_t) + 0x1FE0; else imagesize = sbuf->st_size - sizeof(image_header_t); + if (params->os == IH_OS_TEE) { + addr = optee_image_get_load_addr(hdr); + ep = optee_image_get_entry_point(hdr); + } + /* Build new header */ image_set_magic(hdr, IH_MAGIC); image_set_time(hdr, time); image_set_size(hdr, imagesize); - image_set_load(hdr, params->addr); - image_set_ep(hdr, params->ep); + image_set_load(hdr, addr); + image_set_ep(hdr, ep); image_set_dcrc(hdr, checksum); image_set_os(hdr, params->os); image_set_arch(hdr, params->arch);