From patchwork Sun May 8 06:30:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beniamino Galvani X-Patchwork-Id: 619629 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 3r2bJj6sPYz9sdg for ; Sun, 8 May 2016 16:31:49 +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=glqpwklt; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 31F7AA76B0; Sun, 8 May 2016 08:31:42 +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 DB11gt5gqPIR; Sun, 8 May 2016 08:31:42 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id E25F0A7616; Sun, 8 May 2016 08:31:13 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 9AC95A74E9 for ; Sun, 8 May 2016 08:30: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 sK7uTwF8FKf0 for ; Sun, 8 May 2016 08:30:51 +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 14F2BA74D6 for ; Sun, 8 May 2016 08:30:45 +0200 (CEST) Received: by mail-wm0-f67.google.com with SMTP id n129so15380051wmn.1 for ; Sat, 07 May 2016 23:30:45 -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=glqpwklt2sL0TjWMvO9wIfPETTfEW0CrYwFTPCTHerTGhimgqEayRIA0ldvCQff18A FYoxYIQZMXjgb3EMyWcR+CKqiZAKbzTzj8G4uf5f6tEDDHoPQUvpQP/2kF82rStnpS6P gNMB+AtG0JYU3LKYVIy58ADirCU4DSc+m3cC2Q2Fwy1ZV37AtGA/9owzxr4tMYMe9ehN EDXAsrWo787+NvDc72z8rozwWCsohTEWgOzfCAqcT55Sle9byX3JmvZeS0Y8DR/IfDur 8ZWmsHrkIwkvutF4LDbbqKQAhv9YLpP92pyObRAz8gPWZErJRaO9MsmeCgR4PgbopaC2 RB8Q== 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=bDakT4nrbyNshcXVghjPYOIoCAFFWW2sxjB4Q2xdmqo+NajSgw3MJySa3WeYRKW2Q8 /Fz7gsyMTaRbzJNqCVJ+1lYpMGXqxz4D5tgVc6UnGm/arpiD+KVmXxyc5lms3AA5Ufdv FSmsG6gyE5FpQw/QxNiZt3QEreQdoYMuvhuFoNNkjKDr/hLqUgbuWImJ7uN7eKVSTrka x86yaoRjHAEC4zU80abG5vMQuAQ7/VGEpaRRGHn2d0Ul3HEsVTeTOSR3LSWIXCvZC5y/ bQEC/efvlj8V+kxb5xfSea/qooZj3fce9kFv+vhSKzu36OtzE+lODLjZqvUFkhOz5dJs Sv9w== X-Gm-Message-State: AOPr4FVSinQTrAWplDq/oKtS73++Nn8jvdGfT3LKlwoJYZpeMziUgwaBLcxYQvn7gjNXfg== X-Received: by 10.28.24.82 with SMTP id 79mr5386013wmy.42.1462689045340; Sat, 07 May 2016 23:30:45 -0700 (PDT) Received: from shire.fritz.box (host197-92-dynamic.8-87-r.retail.telecomitalia.it. [87.8.92.197]) by smtp.gmail.com with ESMTPSA id jq1sm23814824wjc.28.2016.05.07.23.30.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 07 May 2016 23:30:44 -0700 (PDT) From: Beniamino Galvani To: u-boot@lists.denx.de Date: Sun, 8 May 2016 08:30:17 +0200 Message-Id: <1462689017-3160-5-git-send-email-b.galvani@gmail.com> X-Mailer: git-send-email 2.7.3 In-Reply-To: <1462689017-3160-1-git-send-email-b.galvani@gmail.com> References: <1462689017-3160-1-git-send-email-b.galvani@gmail.com> Cc: Marek Vasut , Tom Rini , Joe Hershberger , Carlo Caione , linux-amlogic@lists.infradead.org Subject: [U-Boot] [PATCH v7 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; }