From patchwork Thu Apr 24 10:47:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Balaji T K X-Patchwork-Id: 4049081 Return-Path: X-Original-To: patchwork-linux-mmc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 501A59F3E2 for ; Thu, 24 Apr 2014 10:48:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3AC39202E6 for ; Thu, 24 Apr 2014 10:48:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2B309202DD for ; Thu, 24 Apr 2014 10:48:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753113AbaDXKsI (ORCPT ); Thu, 24 Apr 2014 06:48:08 -0400 Received: from devils.ext.ti.com ([198.47.26.153]:33424 "EHLO devils.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753886AbaDXKsB (ORCPT ); Thu, 24 Apr 2014 06:48:01 -0400 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by devils.ext.ti.com (8.13.7/8.13.7) with ESMTP id s3OAlqKp026335; Thu, 24 Apr 2014 05:47:52 -0500 Received: from DLEE71.ent.ti.com (dlee71.ent.ti.com [157.170.170.114]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id s3OAlq1G006919; Thu, 24 Apr 2014 05:47:52 -0500 Received: from dflp33.itg.ti.com (10.64.6.16) by DLEE71.ent.ti.com (157.170.170.114) with Microsoft SMTP Server id 14.3.174.1; Thu, 24 Apr 2014 05:47:52 -0500 Received: from ulaa0393241.india.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id s3OAlmtP032113; Thu, 24 Apr 2014 05:47:51 -0500 From: Balaji T K To: , , CC: Balaji T K Subject: [PATCH 1/2] mmc-utils: add check for max enhanced user area. Date: Thu, 24 Apr 2014 16:17:51 +0530 Message-ID: <1398336472-16679-2-git-send-email-balajitk@ti.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1398336472-16679-1-git-send-email-balajitk@ti.com> References: <1398336472-16679-1-git-send-email-balajitk@ti.com> MIME-Version: 1.0 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In addition to user area, General purpose partition can be be marked with enhanced attribute, retain enhanced attributes of gp partition while creating enhanced user area and add check for max enhanced area of the device. Signed-off-by: Balaji T K --- mmc.h | 16 ++++++++++ mmc_cmds.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 105 insertions(+), 2 deletions(-) diff --git a/mmc.h b/mmc.h index 9871d62..e78dd54 100644 --- a/mmc.h +++ b/mmc.h @@ -57,6 +57,18 @@ #define EXT_CSD_MAX_ENH_SIZE_MULT_0 157 #define EXT_CSD_PARTITIONS_ATTRIBUTE 156 /* R/W */ #define EXT_CSD_PARTITION_SETTING_COMPLETED 155 /* R/W */ +#define EXT_CSD_GP_SIZE_MULT_4_2 154 +#define EXT_CSD_GP_SIZE_MULT_4_1 153 +#define EXT_CSD_GP_SIZE_MULT_4_0 152 +#define EXT_CSD_GP_SIZE_MULT_3_2 151 +#define EXT_CSD_GP_SIZE_MULT_3_1 150 +#define EXT_CSD_GP_SIZE_MULT_3_0 149 +#define EXT_CSD_GP_SIZE_MULT_2_2 148 +#define EXT_CSD_GP_SIZE_MULT_2_1 147 +#define EXT_CSD_GP_SIZE_MULT_2_0 146 +#define EXT_CSD_GP_SIZE_MULT_1_2 145 +#define EXT_CSD_GP_SIZE_MULT_1_1 144 +#define EXT_CSD_GP_SIZE_MULT_1_0 143 #define EXT_CSD_ENH_SIZE_MULT_2 142 #define EXT_CSD_ENH_SIZE_MULT_1 141 #define EXT_CSD_ENH_SIZE_MULT_0 140 @@ -105,6 +117,10 @@ #define EXT_CSD_PART_CONFIG_ACC_ACK (0x40) #define EXT_CSD_PARTITIONING_EN (1<<0) #define EXT_CSD_ENH_ATTRIBUTE_EN (1<<1) +#define EXT_CSD_ENH_4 (1<<4) +#define EXT_CSD_ENH_3 (1<<3) +#define EXT_CSD_ENH_2 (1<<2) +#define EXT_CSD_ENH_1 (1<<1) #define EXT_CSD_ENH_USR (1<<0) /* From kernel linux/mmc/core.h */ diff --git a/mmc_cmds.c b/mmc_cmds.c index b8afa74..941d29f 100644 --- a/mmc_cmds.c +++ b/mmc_cmds.c @@ -494,6 +494,89 @@ int set_partitioning_setting_completed(int dry_run, const char * const device, return 0; } +int check_enhanced_area_total_limit(const char * const device, int fd) +{ + __u8 ext_csd[512]; + __u32 regl; + unsigned long max_enh_area_sz, user_area_sz, enh_area_sz = 0; + unsigned long gp4_part_sz, gp3_part_sz, gp2_part_sz, gp1_part_sz; + unsigned int wp_sz, erase_sz; + int ret; + + ret = read_extcsd(fd, ext_csd); + if (ret) { + fprintf(stderr, "Could not read EXT_CSD from %s\n", device); + exit(1); + } + wp_sz = get_hc_wp_grp_size(ext_csd); + erase_sz = get_hc_erase_grp_size(ext_csd); + + regl = (ext_csd[EXT_CSD_GP_SIZE_MULT_4_2] << 16) | + (ext_csd[EXT_CSD_GP_SIZE_MULT_4_1] << 8) | + ext_csd[EXT_CSD_GP_SIZE_MULT_4_0]; + gp4_part_sz = 512l * regl * erase_sz * wp_sz; + if (ext_csd[EXT_CSD_PARTITIONS_ATTRIBUTE] & EXT_CSD_ENH_4) { + enh_area_sz += gp4_part_sz; + printf("Enhanced GP4 Partition Size [GP_SIZE_MULT_4]: 0x%06x\n", regl); + printf(" i.e. %lu KiB\n", gp4_part_sz); + } + + regl = (ext_csd[EXT_CSD_GP_SIZE_MULT_3_2] << 16) | + (ext_csd[EXT_CSD_GP_SIZE_MULT_3_1] << 8) | + ext_csd[EXT_CSD_GP_SIZE_MULT_3_0]; + gp3_part_sz = 512l * regl * erase_sz * wp_sz; + if (ext_csd[EXT_CSD_PARTITIONS_ATTRIBUTE] & EXT_CSD_ENH_3) { + enh_area_sz += gp3_part_sz; + printf("Enhanced GP3 Partition Size [GP_SIZE_MULT_3]: 0x%06x\n", regl); + printf(" i.e. %lu KiB\n", gp3_part_sz); + } + + regl = (ext_csd[EXT_CSD_GP_SIZE_MULT_2_2] << 16) | + (ext_csd[EXT_CSD_GP_SIZE_MULT_2_1] << 8) | + ext_csd[EXT_CSD_GP_SIZE_MULT_2_0]; + gp2_part_sz = 512l * regl * erase_sz * wp_sz; + if (ext_csd[EXT_CSD_PARTITIONS_ATTRIBUTE] & EXT_CSD_ENH_2) { + enh_area_sz += gp2_part_sz; + printf("Enhanced GP2 Partition Size [GP_SIZE_MULT_2]: 0x%06x\n", regl); + printf(" i.e. %lu KiB\n", gp2_part_sz); + } + + regl = (ext_csd[EXT_CSD_GP_SIZE_MULT_1_2] << 16) | + (ext_csd[EXT_CSD_GP_SIZE_MULT_1_1] << 8) | + ext_csd[EXT_CSD_GP_SIZE_MULT_1_0]; + gp1_part_sz = 512l * regl * erase_sz * wp_sz; + if (ext_csd[EXT_CSD_PARTITIONS_ATTRIBUTE] & EXT_CSD_ENH_1) { + enh_area_sz += gp1_part_sz; + printf("Enhanced GP1 Partition Size [GP_SIZE_MULT_1]: 0x%06x\n", regl); + printf(" i.e. %lu KiB\n", gp1_part_sz); + } + + regl = (ext_csd[EXT_CSD_ENH_SIZE_MULT_2] << 16) | + (ext_csd[EXT_CSD_ENH_SIZE_MULT_1] << 8) | + ext_csd[EXT_CSD_ENH_SIZE_MULT_0]; + user_area_sz = 512l * regl * erase_sz * wp_sz; + if (ext_csd[EXT_CSD_PARTITIONS_ATTRIBUTE] & EXT_CSD_ENH_USR) { + enh_area_sz += user_area_sz; + printf("Enhanced User Data Area Size [ENH_SIZE_MULT]: 0x%06x\n", regl); + printf(" i.e. %lu KiB\n", user_area_sz); + } + + regl = (ext_csd[EXT_CSD_MAX_ENH_SIZE_MULT_2] << 16) | + (ext_csd[EXT_CSD_MAX_ENH_SIZE_MULT_1] << 8) | + ext_csd[EXT_CSD_MAX_ENH_SIZE_MULT_0]; + max_enh_area_sz = 512l * regl * erase_sz * wp_sz; + printf("Max Enhanced Area Size [MAX_ENH_SIZE_MULT]: 0x%06x\n", regl); + printf(" i.e. %lu KiB\n", max_enh_area_sz); + if (enh_area_sz > max_enh_area_sz) { + fprintf(stderr, + "Programmed total enhanced size %lu KiB cannot exceed max enhanced area %lu KiB %s\n", + enh_area_sz, max_enh_area_sz, device); + return 1; + } + + return 0; +} + int do_enh_area_set(int nargs, char **argv) { __u8 value; @@ -615,8 +698,8 @@ int do_enh_area_set(int nargs, char **argv) EXT_CSD_ENH_SIZE_MULT_0, device); exit(1); } - - ret = write_extcsd_value(fd, EXT_CSD_PARTITIONS_ATTRIBUTE, EXT_CSD_ENH_USR); + 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", @@ -624,6 +707,10 @@ int do_enh_area_set(int nargs, char **argv) exit(1); } + ret = check_enhanced_area_total_limit(device, fd); + if (ret) + exit(1); + printf("Done setting ENH_USR area on %s\n", device); if (!set_partitioning_setting_completed(dry_run, device, fd))