From patchwork Wed Jun 15 19:26:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Dannenberg X-Patchwork-Id: 70128 Delivered-To: patch@linaro.org Received: by 10.140.106.246 with SMTP id e109csp17099qgf; Wed, 15 Jun 2016 12:28:33 -0700 (PDT) X-Received: by 10.194.175.231 with SMTP id cd7mr283261wjc.19.1466018913165; Wed, 15 Jun 2016 12:28:33 -0700 (PDT) Return-Path: Received: from theia.denx.de (theia.denx.de. [85.214.87.163]) by mx.google.com with ESMTP id u131si6751704wmu.109.2016.06.15.12.28.32; Wed, 15 Jun 2016 12:28:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 85.214.87.163 as permitted sender) client-ip=85.214.87.163; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 85.214.87.163 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id EC69BA7781; Wed, 15 Jun 2016 21:27:54 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id isDnJWAuFr4o; Wed, 15 Jun 2016 21:27:54 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 985D3A7783; Wed, 15 Jun 2016 21:27:19 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id E8CCCA756E for ; Wed, 15 Jun 2016 21:26:58 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id HYHrFh9tVo0N for ; Wed, 15 Jun 2016 21:26:58 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from bear.ext.ti.com (bear.ext.ti.com [198.47.19.11]) by theia.denx.de (Postfix) with ESMTPS id 4D84EA76A1 for ; Wed, 15 Jun 2016 21:26:53 +0200 (CEST) Received: from dflxv15.itg.ti.com ([128.247.5.124]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id u5FJQpRN026423; Wed, 15 Jun 2016 14:26:51 -0500 Received: from DFLE73.ent.ti.com (dfle73.ent.ti.com [128.247.5.110]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id u5FJQpAR016163; Wed, 15 Jun 2016 14:26:51 -0500 Received: from dflp32.itg.ti.com (10.64.6.15) by DFLE73.ent.ti.com (128.247.5.110) with Microsoft SMTP Server id 14.3.294.0; Wed, 15 Jun 2016 14:26:50 -0500 Received: from borg.dal.design.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id u5FJQnBX003642; Wed, 15 Jun 2016 14:26:50 -0500 From: Andreas Dannenberg To: , Tom Rini , Simon Glass Date: Wed, 15 Jun 2016 14:26:37 -0500 Message-ID: <1466018801-18044-6-git-send-email-dannenberg@ti.com> X-Mailer: git-send-email 2.7.2 In-Reply-To: <1466018801-18044-1-git-send-email-dannenberg@ti.com> References: <1466018801-18044-1-git-send-email-dannenberg@ti.com> MIME-Version: 1.0 Cc: Madan Srinivas , Daniel Allred Subject: [U-Boot] [RFC 5/9] arm: omap5: add secure ROM signature verify API X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" From: Daniel Allred Adds an API that verifies a signature attached to an image (binary blob). This API is basically a entry to a secure ROM service provided by the device and accessed via an SMC call, using a particular calling convention. Signed-off-by: Daniel Allred Signed-off-by: Andreas Dannenberg --- arch/arm/cpu/armv7/omap5/Makefile | 1 + arch/arm/cpu/armv7/omap5/sec_fxns.c | 70 +++++++++++++++++++++++++++++ arch/arm/include/asm/arch-omap5/sys_proto.h | 4 ++ 3 files changed, 75 insertions(+) create mode 100644 arch/arm/cpu/armv7/omap5/sec_fxns.c -- 2.6.4 _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot diff --git a/arch/arm/cpu/armv7/omap5/Makefile b/arch/arm/cpu/armv7/omap5/Makefile index 3caba86..d373bf4 100644 --- a/arch/arm/cpu/armv7/omap5/Makefile +++ b/arch/arm/cpu/armv7/omap5/Makefile @@ -14,3 +14,4 @@ obj-y += hw_data.o obj-y += abb.o obj-y += fdt.o obj-$(CONFIG_IODELAY_RECALIBRATION) += dra7xx_iodelay.o +obj-$(CONFIG_TI_SECURE_DEVICE) += sec_fxns.o diff --git a/arch/arm/cpu/armv7/omap5/sec_fxns.c b/arch/arm/cpu/armv7/omap5/sec_fxns.c new file mode 100644 index 0000000..766333a --- /dev/null +++ b/arch/arm/cpu/armv7/omap5/sec_fxns.c @@ -0,0 +1,70 @@ +/* + * + * Common security functions that rely on secure ROM services + * + * (C) Copyright 2016 + * Texas Instruments, + * + * Daniel Allred + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include +#include + +#define SIGNATURE_LENGTH (0x118) + +/* API Index for OMAP5, DRA7xx */ +#define API_HAL_KM_VERIFYCERTIFICATESIGNATURE_INDEX (0x0000000E) + +int secure_boot_verify_image(void **image, size_t *size) +{ + int result = 1; + u32 cert_addr, sig_addr; + size_t cert_size; + +#ifndef CONFIG_SYS_DCACHE_OFF + /* Perform cache writeback on input buffer */ + flush_dcache_range( + (u32)*image, + (u32)*image + roundup(*size, ARCH_DMA_MINALIGN)); +#endif + cert_addr = (uint32_t)*image; + *size -= SIGNATURE_LENGTH; /* Subtract out the signature size */ + cert_size = *size; + sig_addr = cert_addr + cert_size; + + /* Check if image load address is 32-bit aligned */ + if (0 != (0x3 & cert_addr)) { + puts("Image is not 4-byte aligned.\n"); + result = 1; + goto auth_exit; + } + + /* Image size also should be multiple of 4 */ + if (0 != (0x3 & cert_size)) { + puts("Image size is not 4-byte aligned.\n"); + result = 1; + goto auth_exit; + } + + /* Call ROM HAL API to verify certificate signature */ + debug("%s: load_addr = %x, size = %x, sig_addr = %x\n", __func__, + cert_addr, cert_size, sig_addr); + + result = secure_rom_call( + API_HAL_KM_VERIFYCERTIFICATESIGNATURE_INDEX, 0, 0, + 4, cert_addr, cert_size, sig_addr, 0xFFFFFFFF); +auth_exit: + if (result != 0) { + puts("Authentication failed!\n"); + printf("Return Value = %08X\n", result); + hang(); + } + + printf("Authentication passed: %s\n", (char *)sig_addr); + + return result; +} diff --git a/arch/arm/include/asm/arch-omap5/sys_proto.h b/arch/arm/include/asm/arch-omap5/sys_proto.h index ab0e7fa..b175124 100644 --- a/arch/arm/include/asm/arch-omap5/sys_proto.h +++ b/arch/arm/include/asm/arch-omap5/sys_proto.h @@ -84,4 +84,8 @@ static inline u32 usec_to_32k(u32 usec) #define OMAP5_SERVICE_L2ACTLR_SET 0x104 #define OMAP5_SERVICE_ACR_SET 0x107 +#ifdef CONFIG_TI_SECURE_DEVICE +int secure_boot_verify_image(void **p_image, size_t *p_size); +#endif + #endif