From patchwork Thu Apr 28 22:10:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beniamino Galvani X-Patchwork-Id: 616491 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 3qwrdp3js1z9t7n for ; Fri, 29 Apr 2016 08:11:42 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=FUtfpbJL; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 23146A76CA; Fri, 29 Apr 2016 00:11:28 +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 3SxS8CWv8ie7; Fri, 29 Apr 2016 00:11:28 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 644F7A7770; Fri, 29 Apr 2016 00:11:22 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 35C79A7714 for ; Fri, 29 Apr 2016 00:11:07 +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 UQG1r9OSlAiw for ; Fri, 29 Apr 2016 00:11:07 +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 mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) by theia.denx.de (Postfix) with ESMTPS id 7D958A76CA for ; Fri, 29 Apr 2016 00:10:56 +0200 (CEST) Received: by mail-wm0-f66.google.com with SMTP id w143so1093761wmw.3 for ; Thu, 28 Apr 2016 15:10:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=haRRyjme91wAEnnWqsuTtevRcScCrVafI2toF1w7okU=; b=FUtfpbJLFdjvaiYcCguL5/gjJSPAWoW0slfXazIazBiDZkAgv8wa3GkV22e6cFkPbQ enza29DiqNM1r6PUMHBF9S5qpNQR87smJop2AxKG52vHw284HtOn5HgLU2wshsetRc5A 0ugz4fdBnNPrpNHHY+MiCl9Bydwr8vtL0UzeCbyFUZbGLNWCJk5STWcyq7F7C8OFxDlD s1ark5YRWQhHhIHipaMFMFbXTO4gOnN5BDB2uLaHYpuwvr5K4wg81w+AUJaSk3UjJ3we MCbVV0CMY0rbU1PoFslEfdS59L31ChkAXoDCODwcgs0fBo2Bta+7bMMHdrbm6rCal4UR RhzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=haRRyjme91wAEnnWqsuTtevRcScCrVafI2toF1w7okU=; b=EB/77c3aRz0AylNWJ91qiatzJkHGuE5OeKk6LN4czJ1h83w/bOpYbX7A5bVYMPQHsq onyKU886sebIl5sXgQy9v7azTujhEMAVH8A/MtEKVcUBnmmkBHpOOcARAGInI7li3G/b f+5zmLzLPJM0KwbEoSHYcdpvGtTkTvhsp72/ad4cMt5VnRrfuD9rM4bwckdLYzBrbdyv 03L7UDFkOX5Gfx30XvJaDVlIGQWwh4DpyuVngnzTt/tiYecCXg7jAEf4s5cyH8PTAmm2 ozZHi7P3bMd0VjBJvlBQEXHF5byZGPxI7j9kZBipx3FvHeaSwVIZjAAVglFd5dLckzen tZlA== X-Gm-Message-State: AOPr4FX9RSEn1CNrfE4duvbotN3IYrf00eN68Xrrp+DtjJTVv/R26fDcT87uvxIqktP1mQ== X-Received: by 10.28.26.78 with SMTP id a75mr189568wma.59.1461881456480; Thu, 28 Apr 2016 15:10:56 -0700 (PDT) Received: from shire.fritz.box ([2a01:2000:2001:94a4:92fb:a6ff:feae:db41]) by smtp.gmail.com with ESMTPSA id yr1sm11709055wjc.9.2016.04.28.15.10.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Apr 2016 15:10:55 -0700 (PDT) From: Beniamino Galvani To: u-boot@lists.denx.de Date: Fri, 29 Apr 2016 00:10:23 +0200 Message-Id: <1461881423-12373-5-git-send-email-b.galvani@gmail.com> X-Mailer: git-send-email 2.7.3 In-Reply-To: <1461881423-12373-1-git-send-email-b.galvani@gmail.com> References: <1461881423-12373-1-git-send-email-b.galvani@gmail.com> Cc: Marek Vasut , Tom Rini , linux-meson@googlegroups.com, Joe Hershberger , Carlo Caione Subject: [U-Boot] [PATCH v6 4/4] arm: meson: implement calls to secure monitor 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: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Implement calls to secure monitor to read the MAC address from e-fuse. Signed-off-by: Beniamino Galvani --- arch/arm/include/asm/arch-meson/sm.h | 12 +++++++ arch/arm/mach-meson/Makefile | 2 +- arch/arm/mach-meson/board.c | 1 + arch/arm/mach-meson/sm.c | 57 ++++++++++++++++++++++++++++++++++ board/hardkernel/odroid-c2/odroid-c2.c | 16 ++++++++++ 5 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 arch/arm/include/asm/arch-meson/sm.h create mode 100644 arch/arm/mach-meson/sm.c diff --git a/arch/arm/include/asm/arch-meson/sm.h b/arch/arm/include/asm/arch-meson/sm.h new file mode 100644 index 0000000..225438d --- /dev/null +++ b/arch/arm/include/asm/arch-meson/sm.h @@ -0,0 +1,12 @@ +/* + * (C) Copyright 2016 - Beniamino Galvani + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#ifndef __MESON_SM_H__ +#define __MESON_SM_H__ + +ssize_t meson_sm_read_efuse(uintptr_t offset, void *buffer, size_t size); + +#endif /* __MESON_SM_H__ */ diff --git a/arch/arm/mach-meson/Makefile b/arch/arm/mach-meson/Makefile index 44e3d63..bf49b8b 100644 --- a/arch/arm/mach-meson/Makefile +++ b/arch/arm/mach-meson/Makefile @@ -4,4 +4,4 @@ # SPDX-License-Identifier: GPL-2.0+ # -obj-y += board.o +obj-y += board.o sm.o diff --git a/arch/arm/mach-meson/board.c b/arch/arm/mach-meson/board.c index 782f86c..64fa3c1 100644 --- a/arch/arm/mach-meson/board.c +++ b/arch/arm/mach-meson/board.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include diff --git a/arch/arm/mach-meson/sm.c b/arch/arm/mach-meson/sm.c new file mode 100644 index 0000000..1b35a22 --- /dev/null +++ b/arch/arm/mach-meson/sm.c @@ -0,0 +1,57 @@ +/* + * (C) Copyright 2016 Beniamino Galvani + * + * SPDX-License-Identifier: GPL-2.0+ + * + * Secure monitor calls. + */ + +#include +#include +#include + +#define FN_GET_SHARE_MEM_INPUT_BASE 0x82000020 +#define FN_GET_SHARE_MEM_OUTPUT_BASE 0x82000021 +#define FN_EFUSE_READ 0x82000030 +#define FN_EFUSE_WRITE 0x82000031 + +static void *shmem_input; +static void *shmem_output; + +static void meson_init_shmem(void) +{ + struct pt_regs regs; + + if (shmem_input && shmem_output) + return; + + regs.regs[0] = FN_GET_SHARE_MEM_INPUT_BASE; + smc_call(®s); + shmem_input = (void *)regs.regs[0]; + + regs.regs[0] = FN_GET_SHARE_MEM_OUTPUT_BASE; + smc_call(®s); + shmem_output = (void *)regs.regs[0]; + + debug("Secure Monitor shmem: 0x%p 0x%p\n", shmem_input, shmem_output); +} + +ssize_t meson_sm_read_efuse(uintptr_t offset, void *buffer, size_t size) +{ + struct pt_regs regs; + + meson_init_shmem(); + + regs.regs[0] = FN_EFUSE_READ; + regs.regs[1] = offset; + regs.regs[2] = size; + + smc_call(®s); + + if (regs.regs[0] == 0) + return -1; + + memcpy(buffer, shmem_output, min(size, regs.regs[0])); + + return regs.regs[0]; +} diff --git a/board/hardkernel/odroid-c2/odroid-c2.c b/board/hardkernel/odroid-c2/odroid-c2.c index c258d4f..bd72100 100644 --- a/board/hardkernel/odroid-c2/odroid-c2.c +++ b/board/hardkernel/odroid-c2/odroid-c2.c @@ -7,9 +7,15 @@ #include #include #include +#include #include #include +#define EFUSE_SN_OFFSET 20 +#define EFUSE_SN_SIZE 16 +#define EFUSE_MAC_OFFSET 52 +#define EFUSE_MAC_SIZE 6 + int board_init(void) { return 0; @@ -27,6 +33,9 @@ U_BOOT_DEVICE(meson_eth) = { int misc_init_r(void) { + u8 mac_addr[EFUSE_MAC_SIZE]; + ssize_t len; + /* Select Ethernet function */ setbits_le32(GXBB_PINMUX(6), 0x3fff); @@ -47,5 +56,12 @@ int misc_init_r(void) mdelay(10); setbits_le32(GXBB_GPIO_OUT(3), BIT(14)); + if (!eth_getenv_enetaddr("ethaddr", mac_addr)) { + len = meson_sm_read_efuse(EFUSE_MAC_OFFSET, + mac_addr, EFUSE_MAC_SIZE); + if (len == EFUSE_MAC_SIZE && is_valid_ethaddr(mac_addr)) + eth_setenv_enetaddr("ethaddr", mac_addr); + } + return 0; }