From patchwork Sun Apr 24 06:50:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beniamino Galvani X-Patchwork-Id: 614120 X-Patchwork-Delegate: promsoft@gmail.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 3qt0PD3g7fz9t3t for ; Sun, 24 Apr 2016 16:50:56 +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=1G/pN/I/; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id D04ADA767A; Sun, 24 Apr 2016 08:50:51 +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 3yOPBLYIx6ST; Sun, 24 Apr 2016 08:50:51 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 09BBEA767D; Sun, 24 Apr 2016 08:50:30 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 3188AA74DB for ; Sun, 24 Apr 2016 08:50:24 +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 ejSQgKQqanOK for ; Sun, 24 Apr 2016 08:50:24 +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-f67.google.com (mail-wm0-f67.google.com [74.125.82.67]) by theia.denx.de (Postfix) with ESMTPS id 2B495A7534 for ; Sun, 24 Apr 2016 08:50:22 +0200 (CEST) Received: by mail-wm0-f67.google.com with SMTP id r12so14134354wme.0 for ; Sat, 23 Apr 2016 23:50:22 -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=1G/pN/I/wAPkRukdplECBXn1mHBluBznsZ3BYfqCS9UlE3LOWB9p/HyPY5zhKG/YP+ A/el07gyBeAKuJ48Yi2ebz4pXU5IvgiSeDDepsOzPYmaXLx3StVWKl9+7ubmeisYzB2/ G2Py+muo5Ki6aqzlxOdukCpgcAn/52X/s+rDktJUGN1iPd3VIzqHZfYtWeeTMnZaYFOg NsEJ7ye0ZbUpC3OiEpLFliEsAQtyvFYVmCuR8NJJ/X6AQnirE5pauWGU+mvWGigK3UPB 7bD2gmyhh2GOemnVT/V1yS32GzNm6UR/toibfNE+XYC3JWOZhigQyYouOG4nd0b9ZUHY s46Q== 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=f6uhAVC1QzrfJgmb2xepamoGyj50hT3mcwRtAsXBUVolShQWnH8XYmhDFBimsF2KE2 avFLRJ2t6Gxep5E+LWqtF1+qDJPfotccVVSOZueRzaU8xVdv3z9+J1spnl5e2v+rNSAv 5A3YtgdZ/b/YXwGjuyd5owsj6UA5+o7LzVjLe92rRoVOPDcxVL8h8GQKfjR1M/yiWvWq nR7g+FtfqqOOR+gE4HaiHVHTTipk8tkO47Lo1yc93aAsw4r3uZuMJK5MF+gX4PrrPQYi 6xTYnyecy5msf9SkOJXsBqXc6hV6khkfy1BAGpNWqoGFVFW1GjzqzOnYFQWPMWA0kJLw IlQg== X-Gm-Message-State: AOPr4FU9i+mI1ykXkYeP1Z7thqHIoa8w8PrOXxVg6SyQOtXcCCil0hg1uxzrc+SpTb6ZEg== X-Received: by 10.28.97.213 with SMTP id v204mr5820245wmb.50.1461480622149; Sat, 23 Apr 2016 23:50:22 -0700 (PDT) Received: from shire.fritz.box (host240-93-dynamic.21-79-r.retail.telecomitalia.it. [79.21.93.240]) by smtp.gmail.com with ESMTPSA id 188sm12090868wmk.6.2016.04.23.23.50.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 23 Apr 2016 23:50:21 -0700 (PDT) From: Beniamino Galvani To: u-boot@lists.denx.de Date: Sun, 24 Apr 2016 08:50:02 +0200 Message-Id: <1461480602-2932-5-git-send-email-b.galvani@gmail.com> X-Mailer: git-send-email 2.7.3 In-Reply-To: <1461480602-2932-1-git-send-email-b.galvani@gmail.com> References: <1461480602-2932-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 v5 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; }