From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 436B1C433EF for ; Wed, 20 Oct 2021 14:24:01 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2FA0360E05 for ; Wed, 20 Oct 2021 14:24:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2FA0360E05 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 33E138319B; Wed, 20 Oct 2021 16:23:58 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=baylibre-com.20210112.gappssmtp.com header.i=@baylibre-com.20210112.gappssmtp.com header.b="1nqFH9h+"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E9445831D3; Wed, 20 Oct 2021 16:23:55 +0200 (CEST) Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 482EC8203C for ; Wed, 20 Oct 2021 16:23:52 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=narmstrong@baylibre.com Received: by mail-wm1-x32c.google.com with SMTP id u8-20020a05600c440800b0030d90076dabso5213664wmn.1 for ; Wed, 20 Oct 2021 07:23:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=subject:to:cc:references:from:organization:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=PEVLl5jkdBSWqe64K6mWa8Euok0Pe5OB0F9PEUdYQ7M=; b=1nqFH9h+95KVV0ZMleZd2NM4+SEkYW8LVRbvTzctgMA/qhpqibexN3aTcJFLW7iiT5 XUFGGcevd6uhBi7vcowcJut6zbVrtIEskZsdIEOpYteJTyHLWS3a+SZWVYyM/Uftf8L2 6w6Nk5epT32XaUNpbhOUMpeHbXo29IQy4kvXIAswRajlBH8lvpDTE8gBOU73LFz0ETsU RoDY97EKpbbq4i6DUHjYNS4gd6dy77uQL4vIPTuQNoyju+7uvOQscwnaXNRQdwR/fHqc mRXVlxMO0hCSrVv+oF1/DkK2Y9HXdeOKQ8cKfwXTMO5uVZu0jHOH3frkUsFSK9+mt+XR nqcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=PEVLl5jkdBSWqe64K6mWa8Euok0Pe5OB0F9PEUdYQ7M=; b=NseB8LlDH30I6xvR9zIVtfD0gBqoi1KReKwMj1hMP9dB8Q+PaoZYmMILLC4EFCkD88 mu+S2FaJo7dBvzR6t6fk1E7QOVecsEo3LxxaFbbfWDme12pQj+nfmOcGX9yzlL/VeLYz 7rxTVIJZ0ZKUfgtGxZVYljRnCJgk0cr3aERDg8HOMgaQ9Kp8YKcB6PrOldt4pDlCXuEW zRuSRz1ufkQyuuQMjuQCAOEF4NhaD+EG7WIZaNk8DadQg361FcGmlo2Ay9+a7RdXJESt 489dj5Jm7wdHVnn2/G82VmIEgfHsUkhVKMLAW8gYPSJBqXNHIpm67/F37Bg2PeCOuSRx z9mg== X-Gm-Message-State: AOAM530LQTue8l47HFmDylDoWah0E5KWPaeWsaI21sQE7LcDqWIU/b9x jur9ZwmuWxBZpqUhnIr09/hU3g== X-Google-Smtp-Source: ABdhPJy4TsNpYul040IASwSM46N0Wa/21KuMd+4pz9DlvrAkCvsNKTFFXI7BzfH5PGV4iGQ8oKyRfQ== X-Received: by 2002:adf:ef4d:: with SMTP id c13mr29798wrp.17.1634739831610; Wed, 20 Oct 2021 07:23:51 -0700 (PDT) Received: from ?IPv6:2001:861:44c0:66c0:d31f:1512:8915:e439? ([2001:861:44c0:66c0:d31f:1512:8915:e439]) by smtp.gmail.com with ESMTPSA id o16sm2162483wrn.29.2021.10.20.07.23.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 20 Oct 2021 07:23:51 -0700 (PDT) Subject: Re: [PATCH] ARM: amlogic: add sm efuse write support and cmd for read/write efuse To: Vyacheslav Bocharov Cc: u-boot@lists.denx.de, u-boot-amlogic@groups.io References: <20211005120002.1147482-1-adeep@lexina.in> From: Neil Armstrong Organization: Baylibre Message-ID: <38d6e917-d367-ee5c-58a1-1e6201005e41@baylibre.com> Date: Wed, 20 Oct 2021 16:23:50 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <20211005120002.1147482-1-adeep@lexina.in> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean On 05/10/2021 14:00, Vyacheslav Bocharov wrote: > This adds support for amlogic efuse write and provides two subcommands > of "sm" command: "efuseread" and "efusewrite" to read/write bytes between > memory and efuse. > > Signed-off-by: Vyacheslav Bocharov > --- > arch/arm/mach-meson/sm.c | 68 +++++++++++++++++++++++++++++++++++++++- > 1 file changed, 67 insertions(+), 1 deletion(-) > > diff --git a/arch/arm/mach-meson/sm.c b/arch/arm/mach-meson/sm.c > index 1a8f23cb1fa..fb437b94d14 100644 > --- a/arch/arm/mach-meson/sm.c > +++ b/arch/arm/mach-meson/sm.c > @@ -68,6 +68,26 @@ ssize_t meson_sm_read_efuse(uintptr_t offset, void *buffer, size_t size) > return regs.regs[0]; > } > > +ssize_t meson_sm_write_efuse(uintptr_t offset, void *buffer, size_t size) > +{ > + struct pt_regs regs; > + > + meson_init_shmem(); > + > + memcpy(shmem_input, buffer, size); > + > + regs.regs[0] = FN_EFUSE_WRITE; > + regs.regs[1] = offset; > + regs.regs[2] = size; > + > + smc_call(®s); > + > + if (regs.regs[0] == 0) > + return -1; > + > + return 0; > +} > + > #define SM_CHIP_ID_LENGTH 119 > #define SM_CHIP_ID_OFFSET 4 > #define SM_CHIP_ID_SIZE 12 > @@ -187,9 +207,53 @@ static int do_sm_reboot_reason(struct cmd_tbl *cmdtp, int flag, int argc, > return CMD_RET_SUCCESS; > } > > +static int do_efuse_read(struct cmd_tbl *cmdtp, int flag, int argc, > + char *const argv[]) > +{ > + ulong address, offset, size; > + int ret; > + > + if (argc < 4) > + return CMD_RET_USAGE; > + > + offset = simple_strtoul(argv[1], NULL, 0); > + size = simple_strtoul(argv[2], NULL, 0); > + > + address = simple_strtoul(argv[3], NULL, 0); > + > + ret = meson_sm_read_efuse(offset, (void *)address, size); > + if (ret) > + return CMD_RET_FAILURE; > + > + return CMD_RET_SUCCESS; > +} > + > +static int do_efuse_write(struct cmd_tbl *cmdtp, int flag, int argc, > + char *const argv[]) > +{ > + ulong address, offset, size; > + int ret; > + > + if (argc < 4) > + return CMD_RET_USAGE; > + > + offset = simple_strtoul(argv[1], NULL, 0); > + size = simple_strtoul(argv[2], NULL, 0); > + > + address = simple_strtoul(argv[3], NULL, 0); > + > + ret = meson_sm_write_efuse(offset, (void *)address, size); > + if (ret) > + return CMD_RET_FAILURE; > + > + return CMD_RET_SUCCESS; > +} > + > static struct cmd_tbl cmd_sm_sub[] = { > U_BOOT_CMD_MKENT(serial, 2, 1, do_sm_serial, "", ""), > U_BOOT_CMD_MKENT(reboot_reason, 1, 1, do_sm_reboot_reason, "", ""), > + U_BOOT_CMD_MKENT(efuseread, 4, 1, do_efuse_read, "", ""), > + U_BOOT_CMD_MKENT(efusewrite, 4, 0, do_efuse_write, "", ""), These should be aligned with tabs > }; > > static int do_sm(struct cmd_tbl *cmdtp, int flag, int argc, > @@ -216,5 +280,7 @@ U_BOOT_CMD( > sm, 5, 0, do_sm, > "Secure Monitor Control", > "serial
- read chip unique id to memory address\n" > - "sm reboot_reason [name] - get reboot reason and store to to environment" > + "sm reboot_reason [name] - get reboot reason and store to to environment\n" > + "sm efuseread
- read efuse to memory address\n" > + "sm efusewrite
- write into efuse from memory address" Same here > ); > Applied to u-boot-amlogic while fixing indent Thanks, Neil