From patchwork Tue Oct 9 17:31:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Nuss X-Patchwork-Id: 10633025 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8DA7816B1 for ; Tue, 9 Oct 2018 17:31:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 76AA9294A0 for ; Tue, 9 Oct 2018 17:31:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6AF7D294BA; Tue, 9 Oct 2018 17:31:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EC8B9294A0 for ; Tue, 9 Oct 2018 17:31:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727182AbeJJAt0 (ORCPT ); Tue, 9 Oct 2018 20:49:26 -0400 Received: from mail-it1-f170.google.com ([209.85.166.170]:52696 "EHLO mail-it1-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727151AbeJJAtZ (ORCPT ); Tue, 9 Oct 2018 20:49:25 -0400 Received: by mail-it1-f170.google.com with SMTP id 134-v6so3911713itz.2 for ; Tue, 09 Oct 2018 10:31:23 -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=zBWkjNzk11427+WOtJ7+ZWiA+nYFUEXDOZ1d8kfXQLU=; b=l91QPysWTLf/MWgXCMChIdMqPjui8kU9g1RH49lnT569AyRBzfrnyGa0mootRdfhnM +DLj3+xz5zljEsm1OZcIOEvG3ancXsDT0qiPWAEdNP1R2lJFabu8BqCK0KeZgGVqzXgD QbenUXhojdykvnqIkDioZtT4FoSyRXluBwDGY= 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=zBWkjNzk11427+WOtJ7+ZWiA+nYFUEXDOZ1d8kfXQLU=; b=nZGyK5zif3yLOSgdhSEf9MblTEOnOm7ueLhkRcpYbflEjnmdYJhc2FtlFOmxJeQnMU 4PDTWOOlke7H+goL36Vxo3KnZBijuE6tTvAFvtStAvzw5j41G6AjAJ1awBdXEPRG9uG7 UpBOCzv/kTrqDhHNhlNbSQA50mmFzbW/Kgr+N0VDoCG0uNF0xZCeIVhFVujMZ53i9bGi 2i8r7ymOgl3nUgNMU0xojVar11uPOnvFTalslZLkt0wfghqVLwXF7oXM9PginbHnFlcc bFCGOEqhE3S86Ayqd4oML6rYa7jYZgGhdH2aIDNZb3vCNBaNDFvQ6eToUUwYuJxL2Xuy XbrA== X-Gm-Message-State: ABuFfojVQl80xlX2X2fyuAX8jZU1OBY+NheTBFCEoxLeX19PnKfUSCUj iCDftooh97PVv8A+LGShaIZ7y+lp7V9TXzJM09rvoHyaZrPwuNLjWG6TlcGIML/V+jN1kCG/xFf 3kmVSEC2XCv39MNbWGg== MIME-Version: 1.0 X-Google-Smtp-Source: ACcGV63VgDlbg9UGfze9Jl+qfXnZZ4XGn895Azyo4+O/yyEaarBj/AnfMdEkPJpA4otY9b72dn1G8g== X-Received: by 2002:a02:31d:: with SMTP id y29-v6mr23302372jad.98.1539106282589; Tue, 09 Oct 2018 10:31:22 -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.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 09 Oct 2018 10:31:21 -0700 (PDT) From: James Nuss To: linux-mmc@vger.kernel.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH 1/7] mmc-utils: interpret OPTIMAL_*_SIZE fields in extcsd Date: Tue, 9 Oct 2018 13:31:05 -0400 Message-Id: <4a016f761d388a989059467507f2bc948ba26c6c.1539103468.git.jamesnuss@nanometrics.ca> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP eMMC 5.0 introduced OPTIMAL_READ_SIZE, OPTIMAL_WRITE_SIZE and OPTIMAL TRIM_UNIT_SIZE fields in the extcsd Interpret these fields when reading out the extcsd with human-readable results Signed-off-by: James Nuss Reviewed-by: Avri Altman --- mmc.h | 3 +++ mmc_cmds.c | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/mmc.h b/mmc.h index 285c1f1..5d8a7e3 100644 --- a/mmc.h +++ b/mmc.h @@ -56,6 +56,9 @@ #define EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_B 269 /* RO */ #define EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_A 268 /* RO */ #define EXT_CSD_PRE_EOL_INFO 267 /* RO */ +#define EXT_CSD_OPTIMAL_READ_SIZE 266 /* RO */ +#define EXT_CSD_OPTIMAL_WRITE_SIZE 265 /* RO */ +#define EXT_CSD_OPTIMAL_TRIM_UNIT_SIZE 264 /* RO */ #define EXT_CSD_FIRMWARE_VERSION 254 /* RO */ #define EXT_CSD_CACHE_SIZE_3 252 #define EXT_CSD_CACHE_SIZE_2 251 diff --git a/mmc_cmds.c b/mmc_cmds.c index 44623fe..97ea111 100644 --- a/mmc_cmds.c +++ b/mmc_cmds.c @@ -1766,6 +1766,24 @@ int do_read_extcsd(int nargs, char **argv) ext_csd[EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_B]); printf("eMMC Pre EOL information [EXT_CSD_PRE_EOL_INFO]: 0x%02x\n", ext_csd[EXT_CSD_PRE_EOL_INFO]); + + reg = ext_csd[EXT_CSD_OPTIMAL_READ_SIZE]; + printf("Minimum optimal read unit size (for the device) " + "[OPTIMAL_READ_SIZE]: 0x%02x\n", reg); + printf(" i.e. %lu KiB\n", reg * 4UL); + + reg = ext_csd[EXT_CSD_OPTIMAL_WRITE_SIZE]; + printf("Minimum optimal write unit size (for the device) " + "[OPTIMAL_WRITE_SIZE]: 0x%02x\n", reg); + printf(" i.e. %lu KiB\n", reg * 4UL); + + reg = ext_csd[EXT_CSD_OPTIMAL_TRIM_UNIT_SIZE]; + printf("Minimum optimal trim unit size (for the device) " + "[OPTIMAL_TRIM_UNIT_SIZE]: 0x%02x\n", reg); + if (reg == 0 || reg > 21) + printf("error: invalid OPTIMAL_TRIM_UNIT_SIZE\n"); + else + printf(" i.e. %lu KiB\n", (1UL << (reg - 1)) * 4); } if (ext_csd_rev >= 8) { From patchwork Tue Oct 9 17:31:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Nuss X-Patchwork-Id: 10633013 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 003E3112B for ; Tue, 9 Oct 2018 17:31:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DA4772949A for ; Tue, 9 Oct 2018 17:31:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CD254294B9; Tue, 9 Oct 2018 17:31:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4DFE12949A for ; Tue, 9 Oct 2018 17:31:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727279AbeJJAt1 (ORCPT ); Tue, 9 Oct 2018 20:49:27 -0400 Received: from mail-it1-f178.google.com ([209.85.166.178]:52170 "EHLO mail-it1-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727180AbeJJAt0 (ORCPT ); Tue, 9 Oct 2018 20:49:26 -0400 Received: by mail-it1-f178.google.com with SMTP id 74-v6so3912723itw.1 for ; Tue, 09 Oct 2018 10:31:24 -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=syHuYulLxBme0vmwa314TMLha7/Hw7uICCzj802OzdI=; b=XxOcowjD9fnUFTBJX0K8ex8PQxTqsfI25Q4IoWuhfxUjKC1gsMPrJhN8crX6y+vRXk TqFCEH/QKILe0lYDh5VZH0wYBuiv0U9i53hwlJ9v/zHLzs81KJRzhxgdDYmn2rpSF9x7 rQGEAzdH0E2w8juajUjutTA279PzYNmA34iOc= 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=syHuYulLxBme0vmwa314TMLha7/Hw7uICCzj802OzdI=; b=IIxqu4M1ejV+x5fBqvtwWl8gqvtx8W1cyarx7eiQ8k9csLj7BSsJwYehFVy/C+lVKA 2zt/SXH3fsUCcBnF76vWPPl9WoWja+RIiNHrBtAbFmekYkyiS86lO2gd6ZAGcw4JHrhZ lWSWeQgDtaVbIGExwaD/sRx6QTBct3YId6uj7u2y4JquwqOhZw4ClzTZSK+5JdobYMh7 wtrDP8prWdeDpJwmWMYGztDfKQWJHuH8RYMbVGJndLgCqRl5HMUlDSzp+5xMdLkrXLH9 zLioChxh5t5uF6SU2etZi7fx9CtchpjNakkYcZ3Gd/GUpnT4gUUeJVJAFrL0mrKkftdu v8eQ== X-Gm-Message-State: ABuFfohMH9oGZB4HTGk1xtAMTazjX4bxFpL0x+BDjzYLlAoWINCTDxrS q73FLU7FfQEGBIhhQZHzPDUVW7WG8rih5lOSWpnz/Tl6WBkyQbIxswHeKNldHzR9OFhaA0P9BYg wrvPistOdcFBOCb5jCw== MIME-Version: 1.0 X-Google-Smtp-Source: ACcGV60+vmQi17SX+s/VMyYOWueMAYtxmCb7F63hziTwxjWy2K9hYjFE9XLcaqqVqXA52z2iSHi1Gw== X-Received: by 2002:a24:1dd8:: with SMTP id 207-v6mr2567405itj.126.1539106283979; Tue, 09 Oct 2018 10:31:23 -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.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 09 Oct 2018 10:31:23 -0700 (PDT) From: James Nuss To: linux-mmc@vger.kernel.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH 2/7] mmc-utils: treat FIRMWARE_VERSION as binary field instead of string Date: Tue, 9 Oct 2018 13:31:06 -0400 Message-Id: X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The FIRMWARE_VERSION field is 8-bytes in size and contains non-printable characters. Treat this field as binary and print individual byte values in hex Signed-off-by: James Nuss --- mmc.h | 9 ++++++++- mmc_cmds.c | 11 +++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/mmc.h b/mmc.h index 5d8a7e3..86e209a 100644 --- a/mmc.h +++ b/mmc.h @@ -59,7 +59,14 @@ #define EXT_CSD_OPTIMAL_READ_SIZE 266 /* RO */ #define EXT_CSD_OPTIMAL_WRITE_SIZE 265 /* RO */ #define EXT_CSD_OPTIMAL_TRIM_UNIT_SIZE 264 /* RO */ -#define EXT_CSD_FIRMWARE_VERSION 254 /* RO */ +#define EXT_CSD_FIRMWARE_VERSION_7 261 /* RO */ +#define EXT_CSD_FIRMWARE_VERSION_6 260 /* RO */ +#define EXT_CSD_FIRMWARE_VERSION_5 259 /* RO */ +#define EXT_CSD_FIRMWARE_VERSION_4 258 /* RO */ +#define EXT_CSD_FIRMWARE_VERSION_3 257 /* RO */ +#define EXT_CSD_FIRMWARE_VERSION_2 256 /* RO */ +#define EXT_CSD_FIRMWARE_VERSION_1 255 /* RO */ +#define EXT_CSD_FIRMWARE_VERSION_0 254 /* RO */ #define EXT_CSD_CACHE_SIZE_3 252 #define EXT_CSD_CACHE_SIZE_2 251 #define EXT_CSD_CACHE_SIZE_1 250 diff --git a/mmc_cmds.c b/mmc_cmds.c index 97ea111..45aa4c0 100644 --- a/mmc_cmds.c +++ b/mmc_cmds.c @@ -1758,8 +1758,15 @@ int do_read_extcsd(int nargs, char **argv) } if (ext_csd_rev >= 7) { - printf("eMMC Firmware Version: %s\n", - (char*)&ext_csd[EXT_CSD_FIRMWARE_VERSION]); + printf("Firmware Version: 0x%02x%02x%02x%02x%02x%02x%02x%02x\n", + ext_csd[EXT_CSD_FIRMWARE_VERSION_7], + ext_csd[EXT_CSD_FIRMWARE_VERSION_6], + ext_csd[EXT_CSD_FIRMWARE_VERSION_5], + ext_csd[EXT_CSD_FIRMWARE_VERSION_4], + ext_csd[EXT_CSD_FIRMWARE_VERSION_3], + ext_csd[EXT_CSD_FIRMWARE_VERSION_2], + ext_csd[EXT_CSD_FIRMWARE_VERSION_1], + ext_csd[EXT_CSD_FIRMWARE_VERSION_0]); printf("eMMC Life Time Estimation A [EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_A]: 0x%02x\n", ext_csd[EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_A]); printf("eMMC Life Time Estimation B [EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_B]: 0x%02x\n", From patchwork Tue Oct 9 17:31:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Nuss X-Patchwork-Id: 10633023 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 046F516B1 for ; Tue, 9 Oct 2018 17:31:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E1259294A0 for ; Tue, 9 Oct 2018 17:31:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D4AE9294BA; Tue, 9 Oct 2018 17:31:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7BCB4294A0 for ; Tue, 9 Oct 2018 17:31:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727291AbeJJAt3 (ORCPT ); Tue, 9 Oct 2018 20:49:29 -0400 Received: from mail-it1-f169.google.com ([209.85.166.169]:35452 "EHLO mail-it1-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727180AbeJJAt2 (ORCPT ); Tue, 9 Oct 2018 20:49:28 -0400 Received: by mail-it1-f169.google.com with SMTP id p64-v6so3951824itp.0 for ; Tue, 09 Oct 2018 10:31:26 -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=46CS8BnLz44Na4ecEMVYlapes34LPL9XvwCGT1TI3xE=; b=MtsFXtl9PSeUy28cAGp7qjbtAadZ8/F9bZlYFhuZhyyNOYj0BWbz+XBJGLPzpvyaYr Fm161/V4Idfo+Kx8sMn5bNATJH4mbR58SFRqukwcaJQktlkUvduseVoSBd5ca6RluUrb X3fumUlQwSS2yJeEK0YRJu3Nx7TQKHhFKE6XI= 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=46CS8BnLz44Na4ecEMVYlapes34LPL9XvwCGT1TI3xE=; b=EC8r1MPs0YmPaZCnhnak8gD/wMltFa+TDXpUJagyizma/n08RUXkav48UEJnDmql9o qCOLMm5wQDplNEbFV+Cj4+0E8nkvIXiWXlvZq/Yp36++HNpdizprK9qNcmvO5QfMz9Ea YdkvrTj72Elc7IOjYzkVWK/77Vvb1L9UeImtzaNDAW7wPaDjyz0Ib4Tx170sbFaTu+cU Ei8wl89ILuVszHQhAfH81OXIMJLxjJEy5A4vYt5MRMSIqvQFJh9tWxhq7hBRm+V6hLEv ce89gcABALC+0lgzTxGN3KxC4QiW00qA/ftTsg5RDhUi2m4ifdXx1+7Ht4z5NOFEm0bm lIaA== X-Gm-Message-State: ABuFfoiMkhtwqKbZ2P8Q0Krayz9MRs7m2KCfQpE2lrJRsDldBsQq7NFA j5HKYS37cY6egHkrazX9rTu+ppHpAAS7hje0Ya+XTIkw4dgSNRYNln/E3RqMzQpa9KQdc0FDAh4 8dRtC3cAmKXIPKmIXdg== MIME-Version: 1.0 X-Google-Smtp-Source: ACcGV61VLVvah/KMPMDi11j3RlEvzPHQovlU+iNZHhVfJ1h1NvUdUMk1W0Ro5oIJjZZvqbRFK5Qjvw== X-Received: by 2002:a24:448:: with SMTP id 69-v6mr2222440itb.156.1539106285410; Tue, 09 Oct 2018 10:31:25 -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.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 09 Oct 2018 10:31:24 -0700 (PDT) From: James Nuss To: linux-mmc@vger.kernel.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH 3/7] mmc-utils: interpret DEVICE_VERSION when printing extcsd Date: Tue, 9 Oct 2018 13:31:07 -0400 Message-Id: X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The DEVICE_VERSION is a 2-byte field Print the individual byte values in hex Signed-off-by: James Nuss --- mmc.h | 2 ++ mmc_cmds.c | 3 +++ 2 files changed, 5 insertions(+) diff --git a/mmc.h b/mmc.h index 86e209a..f25869e 100644 --- a/mmc.h +++ b/mmc.h @@ -59,6 +59,8 @@ #define EXT_CSD_OPTIMAL_READ_SIZE 266 /* RO */ #define EXT_CSD_OPTIMAL_WRITE_SIZE 265 /* RO */ #define EXT_CSD_OPTIMAL_TRIM_UNIT_SIZE 264 /* RO */ +#define EXT_CSD_DEVICE_VERSION_1 263 /* RO */ +#define EXT_CSD_DEVICE_VERSION_0 262 /* RO */ #define EXT_CSD_FIRMWARE_VERSION_7 261 /* RO */ #define EXT_CSD_FIRMWARE_VERSION_6 260 /* RO */ #define EXT_CSD_FIRMWARE_VERSION_5 259 /* RO */ diff --git a/mmc_cmds.c b/mmc_cmds.c index 45aa4c0..756aa2f 100644 --- a/mmc_cmds.c +++ b/mmc_cmds.c @@ -1758,6 +1758,9 @@ int do_read_extcsd(int nargs, char **argv) } if (ext_csd_rev >= 7) { + printf("Device Version: 0x%02x%02x\n", + ext_csd[EXT_CSD_DEVICE_VERSION_1], + ext_csd[EXT_CSD_DEVICE_VERSION_0]); printf("Firmware Version: 0x%02x%02x%02x%02x%02x%02x%02x%02x\n", ext_csd[EXT_CSD_FIRMWARE_VERSION_7], ext_csd[EXT_CSD_FIRMWARE_VERSION_6], From patchwork Tue Oct 9 17:31:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Nuss X-Patchwork-Id: 10633021 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7E0F3112B for ; Tue, 9 Oct 2018 17:31:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 62C7E294A0 for ; Tue, 9 Oct 2018 17:31:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 54A56294BA; Tue, 9 Oct 2018 17:31:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C86CA294A0 for ; Tue, 9 Oct 2018 17:31:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727351AbeJJAta (ORCPT ); Tue, 9 Oct 2018 20:49:30 -0400 Received: from mail-it1-f195.google.com ([209.85.166.195]:51918 "EHLO mail-it1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727285AbeJJAt3 (ORCPT ); Tue, 9 Oct 2018 20:49:29 -0400 Received: by mail-it1-f195.google.com with SMTP id 74-v6so3912917itw.1 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=qFkRIFvNYAlllw64V3bMLj2B2EdPHyx9WrHWmul79hMJkIPhz1PjTBMjrm2gKqL4Wo 1qrBceV+17gKbrTrs2rIqFD5/EYlHkge/SdiTEQKY6CrzWjd2WvDpdb7tEkUm25APJHq FBXrmqToIPY60qN6+kIPYlItS/6zChrhdFcIVDKUKnO0JV+CnKU8MP6cP7UaUfl2+TRp Y1U2S3CHHoH6YoJoApjeuxU3Pf6hSjyUxA57jze5Undp6/BqKS11dKU3wm+cyv5xSzoG FioBManHbl4JhRq6Wkqb3QQBGnjq07Z9xWTjLsjH+vF4Ye5W/ChIHv7jOxDoauS9B3wV kjPQ== X-Gm-Message-State: ABuFfognlF7oB06HwitQ2Pw4HyQwX3syt/PUeGCtCjY8qObZU9E7lJsA CPPqEYsQVkfCrqYy7Y7bzdXydy4i+GAahYGoLro6UhVrwH5g9yVvJIa3OM1DlEtyOmGb8ETcGrD O/zBt2xGLI+5uPg/Glg== MIME-Version: 1.0 X-Google-Smtp-Source: ACcGV62m64izao7wWPhXgnN5rhIIa/D4g7js8tN2rTiPBjsXOQTkd9FI4mm+kHGP42hYWMeh+RFW7w== 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: Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP "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); From patchwork Tue Oct 9 17:31:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Nuss X-Patchwork-Id: 10633015 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A66F216B1 for ; Tue, 9 Oct 2018 17:31:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E1BC2949A for ; Tue, 9 Oct 2018 17:31:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 822DB294B9; Tue, 9 Oct 2018 17:31:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 075BF2949A for ; Tue, 9 Oct 2018 17:31:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727391AbeJJAtd (ORCPT ); Tue, 9 Oct 2018 20:49:33 -0400 Received: from mail-it1-f196.google.com ([209.85.166.196]:38984 "EHLO mail-it1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727281AbeJJAtb (ORCPT ); Tue, 9 Oct 2018 20:49:31 -0400 Received: by mail-it1-f196.google.com with SMTP id w200-v6so3918269itc.4 for ; Tue, 09 Oct 2018 10:31:29 -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=WZfKZ9mFsu/vTwKnPT3eAzz4AisFJiTsIBVv1y3D8mI=; b=iEUX2VIxr9Pju08ZhQ97lwRt5s/z4g1dKSKNKSR0AGNW4v2qO5ZskBbGAhNG0nMLn3 nYw+1TuItf7LEORjaQa3Ly9GR8j9tiopYxV5oY9smfSWxb0ZbrG97do1B5D+ScWcnW9I Ov8viMASBDD+Az3vF/M5CVH9Z+fJoDa693TLY= 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=WZfKZ9mFsu/vTwKnPT3eAzz4AisFJiTsIBVv1y3D8mI=; b=d5D6cFFr03pU1A4fzVpDRrkg8KNfW/HGkzZV/iAyR47QC2/ROuxh+ILnWHYKmdqPCn vlaPLGnPv8E16f2JTrdaHiyZ0qUKN4If4/0oIc3fHL4/vYLucsfQv0R4t2SF7IQW75jL 16Ul/q/OkD2nDBnMvsySRrZgm488yWjbVEwTXWMBnUfrkhE2pmZVnNXmpw6psuyJmp3h Q+qGCWzeUhzANoXKYpOL9oxQpFQVXiItzXrHqqJR81yzJ0N9t8ILOvO3mUWmzARiKeZm yavWRUi9e2d4K3ni+E9uD/geNlTdv819HeoKJ5wO84R39oeOP80+jshMLokqjQMqq1/D 87PA== X-Gm-Message-State: ABuFfoj7XsVakB4x/57ArsNxkL8Ue5xVJbI4i3YHyvuSQ9C822V4+PKV /CIen9uCG5JtfxfZi32NyWo6iGi8mYzEwQN6GhpDTOlKNIkiCKVjNXaCgwL1kO4Gle4+9FuYXlb /dNkde20nDPK24tQTng== MIME-Version: 1.0 X-Google-Smtp-Source: ACcGV60x+M2GO3PwEruzH0zWaqVBJ8fvrffm6an2DzvhMqmdtRLyI1LtM59PNcKjjkbRq4VqwS7GwA== X-Received: by 2002:a24:76c6:: with SMTP id z189-v6mr2804214itb.5.1539106288287; Tue, 09 Oct 2018 10:31:28 -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.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 09 Oct 2018 10:31:27 -0700 (PDT) From: James Nuss To: linux-mmc@vger.kernel.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH 5/7] mmc-utils: remove write_reliability set command Date: Tue, 9 Oct 2018 13:31:09 -0400 Message-Id: <212d6c6557b21584f9e3254ff72d57ca2682e2b2.1539103468.git.jamesnuss@nanometrics.ca> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The "write_reliability set" command is dangerous since it will only set write-reliability on one partition per command and this command is a one-time programmable action. This makes it impossible to set write-reliability on multiple partitions. Remove the command so it cannot be used in the future. Use "write_reliability set_register" instead. Signed-off-by: James Nuss --- mmc.c | 5 ----- mmc_cmds.c | 67 -------------------------------------------------------------- mmc_cmds.h | 1 - 3 files changed, 73 deletions(-) diff --git a/mmc.c b/mmc.c index aaefd3d..655546b 100644 --- a/mmc.c +++ b/mmc.c @@ -97,11 +97,6 @@ static struct Command commands[] = { "Enable the enhanced user area 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, -2, - "write_reliability set", "<-y|-n|-c> " " " "\n" - "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" diff --git a/mmc_cmds.c b/mmc_cmds.c index 68c73ef..9565bc9 100644 --- a/mmc_cmds.c +++ b/mmc_cmds.c @@ -1303,73 +1303,6 @@ int do_write_reliability_set_register(int nargs, char **argv) return 0; } -int do_write_reliability_set(int nargs, char **argv) -{ - __u8 value; - __u8 ext_csd[512]; - int fd, ret; - - int dry_run = 1; - int partition; - char *device; - - if (nargs != 4) { - fprintf(stderr,"Usage: mmc write_reliability set <-y|-n|-c> \n"); - exit(1); - } - - if (!strcmp("-y", argv[1])) { - dry_run = 0; - } else if (!strcmp("-c", argv[1])) { - dry_run = 2; - } - - partition = strtol(argv[2], NULL, 10); - device = argv[3]; - - 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]) - { - printf(" Device is already partitioned\n"); - exit(1); - } - - /* assert HS_CTRL_REL */ - if (!(ext_csd[EXT_CSD_WR_REL_PARAM] & HS_CTRL_REL)) { - printf("Cannot set write reliability parameters, WR_REL_SET is " - "read-only\n"); - exit(1); - } - - value = ext_csd[EXT_CSD_WR_REL_SET] | (1< X-Patchwork-Id: 10633019 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2A513112B for ; Tue, 9 Oct 2018 17:31:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 121FF2949A for ; Tue, 9 Oct 2018 17:31:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 06604294B9; Tue, 9 Oct 2018 17:31:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 151462949A for ; Tue, 9 Oct 2018 17:31:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726418AbeJJAtd (ORCPT ); Tue, 9 Oct 2018 20:49:33 -0400 Received: from mail-it1-f193.google.com ([209.85.166.193]:52338 "EHLO mail-it1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727278AbeJJAtd (ORCPT ); Tue, 9 Oct 2018 20:49:33 -0400 Received: by mail-it1-f193.google.com with SMTP id 134-v6so3912361itz.2 for ; Tue, 09 Oct 2018 10:31:30 -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:content-transfer-encoding; bh=VCa5SPCzpimPbRTbr97Ofz4DkAmiTWvAD/fEyiB+m7A=; b=MOwKMzqGfYJtmKjxNjBx34yTHLbouxdY01uB+PGmpm+OmRI88yjoMyk0T30iMBQt2/ F6lZ47N2LNRtmT0fNtsORX8o7Lxar1U0Yomqv67AWRgh0lTVR6Z+FHKMzkierFrODNVf SGbaTZV2usuZvTy/wD8+HDeOG8gWC8Ufqpb4s= 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 :content-transfer-encoding; bh=VCa5SPCzpimPbRTbr97Ofz4DkAmiTWvAD/fEyiB+m7A=; b=K02jxeUR/faH1hcQogfuGT6ugpjNl27ay3Brj0CKYe+xqYvcO1ODteOz+ZIQ4awqLn i7fcyo12wsT+3SGOcoKyFsc+zTtgjgd5mbzP+G0dABFFeqSEPrs3MKCOIw1edT0Wv60n rIbyK6qOUTZuDI159rLdrEvAwBcaVP4e/cdd1NAFfqAFO8KMcfXUAx0Xyy6GVUa5hqC6 oK98yzyXBlzqbySXszY0C4FeeEp4SqUqcnwM/sQNYhrITZh883J0RQUS4CYfNd8TLb5t c2pYP/TMSOr5h+dhCYfCaObUeRDhCW2xRH5ZcwAPqP5WMmbjEEmxgx5nCjLi48UagQMR pwLA== X-Gm-Message-State: ABuFfojeBkgHsU5SHecCLI3xek1lJMd7I176lFvdGVt33TdSWhmpJui/ Mq/Sywpgf03prLB6bwLFJDGC0n1reMtO4mx5PfZo3JrFbmrtv/NkYhE1R1PmSj804iqlBfYjOjk 6S+bIPiALwu1E/Eguuw== MIME-Version: 1.0 X-Google-Smtp-Source: ACcGV63BaILlseUNJBMQ4mnqc1bFNOL9DsF+qsjFoSy9YKefw2VK/7NuGRl6HKhED5F00LhTLdKe6Q== X-Received: by 2002:a05:660c:487:: with SMTP id a7mr2527459itk.90.1539106289768; Tue, 09 Oct 2018 10:31:29 -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.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 09 Oct 2018 10:31:28 -0700 (PDT) From: James Nuss To: linux-mmc@vger.kernel.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH 6/7] mmc-utils: discrete commands for enhanced and extended attribute setting Date: Tue, 9 Oct 2018 13:31:10 -0400 Message-Id: <0d4f799fa7347b6733a263ef83cbcd8c1bdd2cfe.1539103468.git.jamesnuss@nanometrics.ca> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The enhanced and extended attributes must be set on all required partitions in a single command instead of one command per partition. Remove the enhanced and extended attribute setting parameters from the "gp create" and "enh_area set" commands and create new commands: * "enh_area set_partitions" * "enh_area set_user_data" * "gp set_extended" Signed-off-by: James Nuss --- mmc.c | 42 ++++++++++++--- mmc_cmds.c | 169 ++++++++++++++++++++++++++++++++++++++++++++++--------------- mmc_cmds.h | 4 +- 3 files changed, 167 insertions(+), 48 deletions(-) diff --git a/mmc.c b/mmc.c index 655546b..f2c714c 100644 --- a/mmc.c +++ b/mmc.c @@ -87,14 +87,42 @@ static struct Command commands[] = { "Set the eMMC data sector size to 4KB by disabling emulation on\n.", NULL }, - { do_create_gp_partition, -6, - "gp create", "<-y|-n|-c> " " " " " " " " " "\n" - "Create general purpose 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.\nTo set enhanced attribute to general partition being created set\n to 1 else set it to 0.\nTo set extended attribute to general partition\n set to 1,2 else set it to 0", + { do_create_gp_partition, 4, + "gp create", "<-y|-n|-c> " " " " " "\n" + "Create general purpose partition for the .\n" + "Dry-run only unless -y or -c is passed.\n" + "Use -c if more partitioning settings are still to come.\n" + "NOTE! This is a one-time programmable (unreversible) change.", NULL }, - { do_enh_area_set, -4, - "enh_area set", "<-y|-n|-c> " " " " " "\n" - "Enable the enhanced user area 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.", + { do_gp_set_extended, 3, + "gp set_extended", "<-y|-n|-c> " " " "\n" + "Set extended attribute on specified general purpose partitions for the .\n" + "GP4=bit[15:12], GP3=bit[11:8], GP2=bit[7:4], GP1=bit[3:0]\n" + "e.g setting to 0x0120 will set extended attribute 0x02 on 'GP2'\n" + " partition and extended attribute 0x01 on 'GP3' partition\n" + "Dry-run only unless -y or -c is passed.\n" + "Use -c if more partitioning settings are still to come.\n" + "NOTE! This is a one-time programmable (unreversible) change.", + NULL + }, + { do_enh_area_set_user_data, -4, + "enh_area set_user_data", "<-y|-n|-c> " " " " " "\n" + "Set the size and offset of the enhanced user data area for the .\n" + "Dry-run only unless -y or -c is passed.\n" + "Use -c if more partitioning settings are still to come.\n" + "NOTE! This is a one-time programmable (unreversible) change.", + NULL + }, + { do_enh_area_set_partitions, 3, + "enh_area set_partitions", "<-y|-n|-c> " " " "\n" + "Enable enhanced attribute on specified partitions for the .\n" + "User area=bit[0], GP1=bit[1], GP2=bit[2], GP3=bit[3], GP4=bit[4]\n" + "e.g setting to 0x03 will set 'User Area' and 'GP1' partitions \n" + " with enhanced attribute, and all others without enhanced attribute.\n" + "Dry-run only unless -y or -c is passed.\n" + "Use -c if more partitioning settings are still to come.\n" + "NOTE! This is a one-time programmable (unreversible) change.", NULL }, { do_write_reliability_set_register, -2, @@ -102,7 +130,7 @@ static struct Command commands[] = { "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" + " with write-reliability, and all others without write-reliability.\n" "NOTE! This is a one-time programmable (irreversible) change.", NULL }, diff --git a/mmc_cmds.c b/mmc_cmds.c index 9565bc9..793b7fa 100644 --- a/mmc_cmds.c +++ b/mmc_cmds.c @@ -967,6 +967,81 @@ int check_enhanced_area_total_limit(const char * const device, int fd) return 0; } +// TODO: check if enhanced attributes set on GP partitions (only allowed either enhanced or extended attribute) +int do_gp_set_extended(int nargs, char **argv) +{ + __u8 value; + __u8 ext_csd[512]; + __u8 address; + int fd, ret; + char *device; + int dry_run = 1; + long partition_mask; + char *endptr; + + if (nargs != 4) { + fprintf(stderr, "Usage: mmc gp set_extended <-y|-n|-c> \n"); + exit(1); + } + + if (!strcmp("-y", argv[1])) { + dry_run = 0; + } else if (!strcmp("-c", argv[1])) { + dry_run = 2; + } + + errno = 0; + partition_mask = strtol(argv[2], &endptr, 0); + if (errno != 0 || endptr == argv[2] || *endptr != 0 || partition_mask < 0 || partition_mask > 0xffff) { + fprintf(stderr, "Partition mask invalid: %s\n", argv[2]); + exit(1); + } + + device = argv[3]; + 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]) { + printf(" Device is already partitioned\n"); + exit(1); + } + + value = (__u8)partition_mask; + address = EXT_CSD_EXT_PARTITIONS_ATTRIBUTE_0; + ret = write_extcsd_value(fd, address, value); + fprintf(stderr, "Writing 0x%02x to EXT_CSD[%d]\n", value, address); + if (ret) { + fprintf(stderr, "Could not write 0x%x to EXT_CSD[%d] in %s\n", + value, address, device); + exit(1); + } + + value = (__u8)(partition_mask >> 8); + address = EXT_CSD_EXT_PARTITIONS_ATTRIBUTE_1; + ret = write_extcsd_value(fd, address, value); + fprintf(stderr, "Writing 0x%02x to EXT_CSD[%d]\n", value, address); + if (ret) { + fprintf(stderr, "Could not write 0x%x to EXT_CSD[%d] in %s\n", + value, address, device); + exit(1); + } + + if (set_partitioning_setting_completed(dry_run, device, fd)) + exit(1); + + return 0; +} + int do_create_gp_partition(int nargs, char **argv) { __u8 value; @@ -975,12 +1050,12 @@ int do_create_gp_partition(int nargs, char **argv) int fd, ret; char *device; int dry_run = 1; - int partition, enh_attr, ext_attr; + int partition; unsigned int length_kib, gp_size_mult; unsigned long align; - if (nargs != 7) { - fprintf(stderr, "Usage: mmc gp create <-y|-n|-c> \n"); + if (nargs != 5) { + fprintf(stderr, "Usage: mmc gp create <-y|-n|-c> \n"); exit(1); } @@ -992,20 +1067,13 @@ int do_create_gp_partition(int nargs, char **argv) length_kib = strtol(argv[2], NULL, 10); partition = strtol(argv[3], NULL, 10); - enh_attr = strtol(argv[4], NULL, 10); - ext_attr = strtol(argv[5], NULL, 10); - device = argv[6]; + device = argv[4]; if (partition < 1 || partition > 4) { printf("Invalid gp partition number; valid range [1-4].\n"); exit(1); } - if (enh_attr && ext_attr) { - printf("Not allowed to set both enhanced attribute and extended attribute\n"); - exit(1); - } - fd = open(device, O_RDWR); if (fd < 0) { perror("open"); @@ -1060,30 +1128,52 @@ int do_create_gp_partition(int nargs, char **argv) exit(1); } - value = ext_csd[EXT_CSD_PARTITIONS_ATTRIBUTE]; - if (enh_attr) - value |= (1 << partition); - else - value &= ~(1 << partition); + if (set_partitioning_setting_completed(dry_run, device, fd)) + exit(1); - ret = write_extcsd_value(fd, EXT_CSD_PARTITIONS_ATTRIBUTE, value); - if (ret) { - fprintf(stderr, "Could not write EXT_CSD_ENH_%x to EXT_CSD[%d] in %s\n", - partition, EXT_CSD_PARTITIONS_ATTRIBUTE, device); + return 0; +} + +// TODO: check if extended attributes set on GP partitions (only allowed either enhanced or extended attribute) +int do_enh_area_set_partitions(int nargs, char **argv) +{ + int fd, ret; + char *device; + int dry_run = 1; + long partition_mask; + char *endptr; + + if (nargs != 4) { + fprintf(stderr, "Usage: mmc enh_area set_partitions <-y|-n|-c> \n"); exit(1); } - address = EXT_CSD_EXT_PARTITIONS_ATTRIBUTE_0 + (partition - 1) / 2; - value = ext_csd[address]; - if (ext_attr) - value |= (ext_attr << (4 * ((partition - 1) % 2))); - else - value &= (0xF << (4 * ((partition % 2)))); + if (!strcmp("-y", argv[1])) { + dry_run = 0; + } else if (!strcmp("-c", argv[1])) { + dry_run = 2; + } - ret = write_extcsd_value(fd, address, value); + errno = 0; + partition_mask = strtol(argv[2], &endptr, 0); + if (errno != 0 || endptr == argv[2] || *endptr != 0 || partition_mask < 0 || partition_mask > 0x1f) { + fprintf(stderr, "Partition mask invalid: %s\n", argv[2]); + exit(1); + } + + device = argv[3]; + fd = open(device, O_RDWR); + if (fd < 0) { + perror("open"); + exit(1); + } + + ret = write_extcsd_value(fd, EXT_CSD_PARTITIONS_ATTRIBUTE, (__u8)partition_mask); if (ret) { - fprintf(stderr, "Could not write 0x%x to EXT_CSD[%d] in %s\n", - value, address, device); + fprintf(stderr, "Could not write 0x%02x to " + "EXT_CSD[%d] in %s\n", + (__u8)partition_mask, + EXT_CSD_PARTITIONS_ATTRIBUTE, device); exit(1); } @@ -1097,7 +1187,7 @@ int do_create_gp_partition(int nargs, char **argv) return 0; } -int do_enh_area_set(int nargs, char **argv) +int do_enh_area_set_user_data(int nargs, char **argv) { __u8 value; __u8 ext_csd[512]; @@ -1108,7 +1198,7 @@ int do_enh_area_set(int nargs, char **argv) unsigned long align; if (nargs != 5) { - fprintf(stderr, "Usage: mmc enh_area set <-y|-n|-c> \n"); + fprintf(stderr, "Usage: mmc enh_area set_user_data <-y|-n|-c> \n"); exit(1); } @@ -1148,6 +1238,13 @@ int do_enh_area_set(int nargs, char **argv) exit(1); } + /* assert enhanced attribute is set on user partition */ + if (!(ext_csd[EXT_CSD_PARTITIONS_ATTRIBUTE] & EXT_CSD_ENH_USR)) + { + fprintf(stderr, "error: User partition must be set with enhanced attribute first\n"); + exit(1); + } + align = 512l * get_hc_wp_grp_size(ext_csd) * get_hc_erase_grp_size(ext_csd); enh_size_mult = (length_kib + align/2l) / align; @@ -1165,7 +1262,7 @@ int do_enh_area_set(int nargs, char **argv) exit(1); } - /* write to ENH_START_ADDR and ENH_SIZE_MULT and PARTITIONS_ATTRIBUTE's ENH_USR bit */ + /* write to ENH_START_ADDR and ENH_SIZE_MULT */ value = (enh_start_addr >> 24) & 0xff; ret = write_extcsd_value(fd, EXT_CSD_ENH_START_ADDR_3, value); if (ret) { @@ -1223,14 +1320,6 @@ int do_enh_area_set(int nargs, char **argv) EXT_CSD_ENH_SIZE_MULT_0, device); exit(1); } - value = ext_csd[EXT_CSD_PARTITIONS_ATTRIBUTE] | EXT_CSD_ENH_USR; - ret = write_extcsd_value(fd, EXT_CSD_PARTITIONS_ATTRIBUTE, value); - if (ret) { - fprintf(stderr, "Could not write EXT_CSD_ENH_USR to " - "EXT_CSD[%d] in %s\n", - EXT_CSD_PARTITIONS_ATTRIBUTE, device); - exit(1); - } ret = check_enhanced_area_total_limit(device, fd); if (ret) diff --git a/mmc_cmds.h b/mmc_cmds.h index cf6c6fb..a8a90c2 100644 --- a/mmc_cmds.h +++ b/mmc_cmds.h @@ -33,7 +33,9 @@ int do_hwreset_dis(int nargs, char **argv); int do_sanitize(int nargs, char **argv); 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_gp_set_extended(int nargs, char **argv); +int do_enh_area_set_user_data(int nargs, char **argv); +int do_enh_area_set_partitions(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); From patchwork Tue Oct 9 17:31:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Nuss X-Patchwork-Id: 10633017 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 169AD16B1 for ; Tue, 9 Oct 2018 17:31:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F2F4B2949A for ; Tue, 9 Oct 2018 17:31:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DC4D5294B9; Tue, 9 Oct 2018 17:31:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 930B52949A for ; Tue, 9 Oct 2018 17:31:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727392AbeJJAtg (ORCPT ); Tue, 9 Oct 2018 20:49:36 -0400 Received: from mail-io1-f49.google.com ([209.85.166.49]:43813 "EHLO mail-io1-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727438AbeJJAte (ORCPT ); Tue, 9 Oct 2018 20:49:34 -0400 Received: by mail-io1-f49.google.com with SMTP id y10-v6so1790880ioa.10 for ; Tue, 09 Oct 2018 10:31:32 -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=vZSeOx2Q9Ui+kq8iX3OPdKa7b/GGe9nX6s8iZnEDncA=; b=dqPAxg4UxrEzKXljLBMYP2ybFjG2S42Z0KdqVcL6kVhXVkc4juPZ7A9tOUOmz2xUtC BLcsfBM+ujkX24ccMO7Je1YW+3m2wkGo/14WzgYI18NvwtC5nJ2lmuxIy6Yo/I/EE39x 9JA3BxWrZvKeG25KlqOniEYlR7h8wZ28RKJSY= 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=vZSeOx2Q9Ui+kq8iX3OPdKa7b/GGe9nX6s8iZnEDncA=; b=hQWA8j5sY2o7W1X09R99BA+1eusKOI0A4n1Y/A62rFpT8OVoTN5BFVSe2FX1b/UUqp tm6zJ7I049fWYic2vz7M05vYfDzIVeY0RYzK/2zqzJRbVAIF3i69wYQ4UFoR7hCzdgmk 8fB7Np221BpylqOurth8xp2/1ja5RmrE9Yf01+ueyn63hJ1ecmu1YVP+urbr/tVdEbKp UqxK4Q6umTgINsPPoNWAhtGXCZJ2qKRwqxqI+dVgK1mSvq1WA+0cbwp08m6izzk+SN3B fJsGHwPiF+UgW2BcdbPu3IWkPnYnZSs9qLIaaDKewl8qTPuLSXo/xjD8Tvl85jN19ICv WavA== X-Gm-Message-State: ABuFfog8jxZkbfwj4i4CWhmicNsxUfZrirL5mCUNP5dkWdn6DKeGSkuf tPVLM0mfgjrivfE74zd7Ec7hmqHwclfhkydqdr5iVF1vXg1h3Tg0o6ccrA6JabHvCAAQoC0DP3w qSsGWpKW0ld1Bho4wXg== MIME-Version: 1.0 X-Google-Smtp-Source: ACcGV61OsBwTugqIqetgES1ZfQ0vrJm1SS/Md/PAJAFBar4o0Vj5Zjcp3eGcmOJhwDRczShW3dBnMw== X-Received: by 2002:a6b:310d:: with SMTP id j13-v6mr20443904ioa.250.1539106291528; Tue, 09 Oct 2018 10:31:31 -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.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 09 Oct 2018 10:31:30 -0700 (PDT) From: James Nuss To: linux-mmc@vger.kernel.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH 7/7] mmc-utils: update version number to 0.2 Date: Tue, 9 Oct 2018 13:31:11 -0400 Message-Id: <56075121aed5797c838824a541d896a083b4fd30.1539103468.git.jamesnuss@nanometrics.ca> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP --- mmc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mmc.c b/mmc.c index f2c714c..660b62e 100644 --- a/mmc.c +++ b/mmc.c @@ -26,7 +26,7 @@ #include "mmc_cmds.h" -#define MMC_VERSION "0.1" +#define MMC_VERSION "0.2" #define BASIC_HELP 0 #define ADVANCED_HELP 1