From patchwork Tue Mar 13 16:50:35 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: 131519 Delivered-To: patch@linaro.org Received: by 10.46.84.17 with SMTP id i17csp974424ljb; Tue, 13 Mar 2018 09:56:57 -0700 (PDT) X-Google-Smtp-Source: AG47ELtWDMmn+HejemcSWKrK3x+dsqAjxqjnhFu8B9bEcJROf8bAjwaJFczW8TrZKoITvdvvw9hX X-Received: by 10.80.138.155 with SMTP id j27mr1642790edj.36.1520960217210; Tue, 13 Mar 2018 09:56:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520960217; cv=none; d=google.com; s=arc-20160816; b=CNhS1cxpA6q5xlLnhUEJm4nK5+xJMQnmwMRV1eoAx59/yXe76BMdqL8mIxz7kEUk4R UsxECYGshxI4eYghjSEm2gBVji93cNB/yWM9+PFB+ZQpjoW7ErxXlcY8TGaw6BwToNsc b/ewKc7d6+9EtBA+0BA8hfOX2WRFg7p5RalmMwVYfIcdAhl2kraJYCkz587IJvac5fmi BFCvAcqMH4A3wCqRjwULuhJ78R5nLIED64/luEBOxzNJnXloGvaLMHCiz8lF+yAP2rkk iEwFPpgqvA67ZyB4SjUov33uKVcZUFpNEnuRjePjLDr6VjTOvMknkV6noOfEjbACHonw fNhQ== 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=fPTKLzoS6d+MXJXsFc6bZq/8D/ph4CdX8KaKX82IBz7VEjLziLwyL8CflF6VKlCJVR TVjZxVcN3k6e2I8tHaTUazN5RGM5XAGEypdmrPhSZdz+Yon85HBu0ySNh1froVTN+euM ElGyuvBjjctsp8OjPYX8Am4NTuJE9pego98WuJlS9LAXzeIPWgAPobrKLS3kZ7TSmwK4 W2OPl6q6iiGbepl0U1DeWATNbBdMO8812pleTF8e0UvuyEvdnOhMuL/Gg3xEmGIP7cIL ytyituigqqwxAxdcxVf08acnRKBFKQD+fu84LFdyXT43TcunLYuPJEdfeQz667IoWwEy UTIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=G87Lyahf; 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 k4si401333ede.6.2018.03.13.09.56.56; Tue, 13 Mar 2018 09:56:57 -0700 (PDT) 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=G87Lyahf; 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 C1589C21E0B; Tue, 13 Mar 2018 16:53:42 +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_H2, 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 22A0BC21DB6; Tue, 13 Mar 2018 16:51:18 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 9BDAEC21E3B; Tue, 13 Mar 2018 16:50:58 +0000 (UTC) Received: from mail-wr0-f195.google.com (mail-wr0-f195.google.com [209.85.128.195]) by lists.denx.de (Postfix) with ESMTPS id 5BC33C21E02 for ; Tue, 13 Mar 2018 16:50:54 +0000 (UTC) Received: by mail-wr0-f195.google.com with SMTP id n12so812584wra.2 for ; Tue, 13 Mar 2018 09:50:54 -0700 (PDT) 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=G87LyahfHIAgVaEEUjlt8UfP6xSivkq+Q3Ij9PgQ/XyXXQhWiBiFs/XXrYwx2yDG3t 7Hs2fr8VBL3K4GpkuN2roGvTZk87zSCmNXqUEGSyTlcq5fXcS+WeJB/GVjkCrP+LL+di MWVJ2AGcBid364FKktEvuhf3JK1EFsWXKuMus= 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=Qk8V/gvPPtjGG3jXWEFO76QDzP/ktNUXyrCPtz9bRRqq6/sjbjICc48KRAvocoEThd Cm2rS8+cO5UNWuZc4tzLF/ltXup2vPZxox7PEO5qZa7ghnF/sRvoVHNHBEXGIOobsUTt o5tFZiX8u/p6ozl2IhXQV2Z9oI5L6Gc6RT+ZC3F8lvUc/oQakk86HFhp7FlsNEyk8Scn BsX5gjJPIVwTd3vFGEcZFw5ROioCjOMKezTvppMZBRtkzMKNrHHFVccip+m3RKC12kuS EV4D8Q8lKCXBciFXtSYAma2evooHvUw/RaIcvY1dJP2txzzcIkX++RbdU6RChF5C96hI lz5A== X-Gm-Message-State: AElRT7FkaHgeBfN8L0lBYT5gRUx4ks1e7tDtSvuPgkDf/PEWXCPULz4s IIQnvDpemBAhUA2CsLAltPcbsNipVBY= X-Received: by 10.80.154.130 with SMTP id p2mr1572288edb.211.1520959853769; Tue, 13 Mar 2018 09:50:53 -0700 (PDT) Received: from localhost.localdomain ([109.255.42.2]) by smtp.gmail.com with ESMTPSA id 33sm476671edz.37.2018.03.13.09.50.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 13 Mar 2018 09:50:53 -0700 (PDT) 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: Tue, 13 Mar 2018 16:50:35 +0000 Message-Id: <1520959836-16105-10-git-send-email-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1520959836-16105-1-git-send-email-bryan.odonoghue@linaro.org> References: <1520959836-16105-1-git-send-email-bryan.odonoghue@linaro.org> Cc: Harinarayan Bhatta Subject: [U-Boot] [PATCH v6 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);