Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp5158736imm; Tue, 9 Oct 2018 10:32:13 -0700 (PDT) X-Google-Smtp-Source: ACcGV620G3y5jkM4dDhq8bs5yB1j0K8GRxCyvmnY6aQVOyfE5xGEUB5/8DhhRXdcKy5+wNK74229 X-Received: by 2002:a63:de46:: with SMTP id y6-v6mr26346121pgi.198.1539106333883; Tue, 09 Oct 2018 10:32:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539106333; cv=none; d=google.com; s=arc-20160816; b=ucTMNZXPCbehPHLanCmhE0AM5FCINQxjB+Gbj/J6iwOqVqA9hnnGdHUPtRoD8BY+mF upfpwgHkMM4q/7DU4RnQ+Zb49ycAmY3Ace1R7RrOdQNXFKsZlQvd0bxpIik2TlsyEvRu sCLMpKGKwJcF+b8dyQqUApwJPWIDVO8KEnBJC/rkhK0Il9uS0hJNqlDPiU90/n0ObSIB mBPepe+JgkQvVlUjF3l92qaO4NtXDxBnE2e2wRANVms2JyFfMF2KrVxdSNqHGbjkhORn lzALGZE+I89I3ovNSxQs1LrG2UoJ7HE9jrbA5tWmYalu5QUT19GelDdnBVzRFka6P0Sr Rzbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:mime-version :dkim-signature; bh=LsxidQGqg9D6Q/MsjzTFCuWHocGJG7qCsrhu+BRg8xE=; b=uKtXsvmWMacuKnrMwEQ171f7LuuLexeMW4qv8w4uU371PYTzPUJrVLAUIVdpyALKTd BQFyBEOA7KsfkJIP9fv/ykcPaoKmQEwdl8bxLs/qipFBaa67pD6nVPZkT0QH4vpq6b21 wtcThJwQ2i+AliAKW0St9TvV2sfXYYAgsAm/A2Cw1zjql3YSoQ2dlbBxGFS6NTCHnK+b W5DRTLGc2CebVAdiGv1BGQqaW5r3GJC3xgsuYjGUQoItQctLwVk/nxCa6vhveP8GYPDU qX0n3BWI0Bdr2G8EVX6yijyw3yVuKN8e8734Ff0y+UHDv5VSFiCWPMHdar4KkUz0WwpU mVAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nanometrics.ca header.s=google header.b=nPq2JYf6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=nanometrics.ca Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c21-v6si21577711plz.283.2018.10.09.10.31.57; Tue, 09 Oct 2018 10:32:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nanometrics.ca header.s=google header.b=nPq2JYf6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=nanometrics.ca Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727371AbeJJAta (ORCPT + 99 others); Tue, 9 Oct 2018 20:49:30 -0400 Received: from mail-it1-f194.google.com ([209.85.166.194]:55412 "EHLO mail-it1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727281AbeJJAt3 (ORCPT ); Tue, 9 Oct 2018 20:49:29 -0400 Received: by mail-it1-f194.google.com with SMTP id c23-v6so3883339itd.5 for ; Tue, 09 Oct 2018 10:31:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nanometrics.ca; s=google; h=mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=LsxidQGqg9D6Q/MsjzTFCuWHocGJG7qCsrhu+BRg8xE=; b=nPq2JYf68sRYye8XxsqH09FXDFv11xFS+hH4c76YkMK6PSie+fO0hXEO/y7D0xpiyD C9ZGLCKjS5c+eQCYFS6boOzpBrbbu86C4wtiPW13MQNFcsyBWBi/dV2BeHCKEDVX12eP Z8BcE65Upm0VKBrggLt3Zw0rZWH/TFXCL0/HI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:to:cc:subject:date:message-id :in-reply-to:references:in-reply-to:references; bh=LsxidQGqg9D6Q/MsjzTFCuWHocGJG7qCsrhu+BRg8xE=; b=lIXX81LRobD9f5EWMl6fLbzxal1uwEscB8V7Vojw/h980K3/AsSu2oHBE1Dnb5H9Mi OYDkyIO1CcWis0t9GOtxKxXszN1gih9E3Ti0gpD+MOBQdO4Em8GhLDWlu6Sy76Y+pI2g WxnoFJRXQlN/SuGRwLkG21HYc6sx/jSg1dPazsQUn/rpviCnDdKkAxzoFXhr8Bi+GuQd RY1WuUsp/jJ3xQdFgjOiSD6T8Y1LZeJcoGsVF0ymfJ36UUjsjQzCRYdxC2KmN0G8cXPL cQJ7un/nxSYhE68ArGE23L9METR2MZgC+eVVSFroHtA/am9/ZWvP0TkfdIsB2h/2/DYt w8mA== X-Gm-Message-State: ABuFfohz6Sxx9uq3t73nkueBdyOQU71HpTURTrtRAMegF8rtIxXedTp5 0LxSQtfDrLW0RgOnr+PrWXa0/UZDrKR0W7V8LKepf3OaC9nWJaTn2xVcy5Av2NXfpWbT9UnKjYd 7xPS8Tjauf0hcZfT9 MIME-Version: 1.0 X-Received: by 2002:a24:e08f:: with SMTP id c137-v6mr2658549ith.71.1539106286808; Tue, 09 Oct 2018 10:31:26 -0700 (PDT) Received: from jamesnuss-kubuntu.nanometrics.ca ([72.142.127.130]) by smtp.gmail.com with ESMTPSA id c24-v6sm6321018iod.44.2018.10.09.10.31.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 09 Oct 2018 10:31:25 -0700 (PDT) From: James Nuss To: linux-mmc@vger.kernel.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH 4/7] mmc-utils: Introduce write_reliability set_register command Date: Tue, 9 Oct 2018 13:31:08 -0400 Message-Id: <09cceeb5de497ac2abd19de93a364af747ce51b1.1539103468.git.jamesnuss@nanometrics.ca> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: Content-Type: text/plain; charset="US-ASCII" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org "write-reliability" setting must be performed on all required partitions in one command. Introduce new command "write_reliability set_register" to allow setting of write-reliability for all required partitions. This command is a one-time programmable action. It cannot not be undone by power-cycling the unit. Signed-off-by: James Nuss --- mmc.c | 9 +++++++++ mmc_cmds.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ mmc_cmds.h | 1 + 3 files changed, 69 insertions(+) diff --git a/mmc.c b/mmc.c index 50c9c9e..aaefd3d 100644 --- a/mmc.c +++ b/mmc.c @@ -102,6 +102,15 @@ static struct Command commands[] = { "Enable write reliability per partition for the .\nDry-run only unless -y or -c is passed.\nUse -c if more partitioning settings are still to come.\nNOTE! This is a one-time programmable (unreversible) change.", NULL }, + { do_write_reliability_set_register, -2, + "write_reliability set_register", " " "\n" + "Set the write-reliability register (WR_REL_SET) for the .\n" + "User area=bit0, GP1=bit1, GP2=bit2, GP3=bit3, GP4=bit4\n" + "e.g setting register to 0x03 will set 'User Area' and 'GP1' partitions \n" + "with write-reliability, and all others without write-reliability.\n" + "NOTE! This is a one-time programmable (irreversible) change.", + NULL + }, { do_status_get, -1, "status get", "\n" "Print the response to STATUS_SEND (CMD13).", diff --git a/mmc_cmds.c b/mmc_cmds.c index 756aa2f..68c73ef 100644 --- a/mmc_cmds.c +++ b/mmc_cmds.c @@ -1244,6 +1244,65 @@ int do_enh_area_set(int nargs, char **argv) return 0; } +int do_write_reliability_set_register(int nargs, char **argv) +{ + __u8 ext_csd[512]; + int fd, ret; + long partition_mask; + char *device; + char *endptr; + + if (nargs != 3) { + fprintf(stderr,"Usage: mmc write_reliability set_register \n"); + exit(1); + } + + errno = 0; + partition_mask = strtol(argv[1], &endptr, 0); + if (errno != 0 || endptr == argv[1] || *endptr != 0 || partition_mask < 0 || partition_mask > 0x1f) { + fprintf(stderr, "Partition mask invalid: %s\n", argv[1]); + exit(1); + } + + device = argv[2]; + fd = open(device, O_RDWR); + if (fd < 0) { + perror("open"); + exit(1); + } + + ret = read_extcsd(fd, ext_csd); + if (ret) { + fprintf(stderr, "Could not read EXT_CSD from %s\n", device); + exit(1); + } + + /* assert not PARTITION_SETTING_COMPLETED */ + if (ext_csd[EXT_CSD_PARTITION_SETTING_COMPLETED]) + { + fprintf(stderr, "Device is already partitioned\n"); + exit(1); + } + + /* assert HS_CTRL_REL */ + if (!(ext_csd[EXT_CSD_WR_REL_PARAM] & HS_CTRL_REL)) { + fprintf(stderr, "Cannot set write reliability parameters, WR_REL_SET is " + "read-only\n"); + exit(1); + } + + ret = write_extcsd_value(fd, EXT_CSD_WR_REL_SET, (__u8)partition_mask); + if (ret) { + fprintf(stderr, "Could not write 0x%02x to EXT_CSD[%d] in %s\n", + (__u8)partition_mask, EXT_CSD_WR_REL_SET, device); + exit(1); + } + fprintf(stderr, "Done setting EXT_CSD_WR_REL_SET to 0x%02x on %s\n", + (__u8)partition_mask, device); + + return 0; +} + int do_write_reliability_set(int nargs, char **argv) { __u8 value; diff --git a/mmc_cmds.h b/mmc_cmds.h index 9d3246c..8ca9ac9 100644 --- a/mmc_cmds.h +++ b/mmc_cmds.h @@ -35,6 +35,7 @@ int do_status_get(int nargs, char **argv); int do_create_gp_partition(int nargs, char **argv); int do_enh_area_set(int nargs, char **argv); int do_write_reliability_set(int nargs, char **argv); +int do_write_reliability_set_register(int nargs, char **argv); int do_rpmb_write_key(int nargs, char **argv); int do_rpmb_read_counter(int nargs, char **argv); int do_rpmb_read_block(int nargs, char **argv); -- 2.7.4 -- This message is intended exclusively for the individual or entity to which it is addressed. This communication may contain information that is proprietary, privileged, confidential or otherwise legally exempt from disclosure. If you are not the named addressee, or have been inadvertently and erroneously referenced in the address line, you are not authorized to read, print, retain, copy or disseminate this message or any part of it. If you have received this message in error, please notify the sender immediately by e-mail and delete all copies of the message.