From patchwork Wed Jan 25 17:31:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Poulain X-Patchwork-Id: 646561 Delivered-To: patch@linaro.org Received: by 2002:a17:522:b9de:b0:4b9:b062:db3b with SMTP id fj30csp401365pvb; Wed, 25 Jan 2023 09:32:02 -0800 (PST) X-Google-Smtp-Source: AK7set93U+n9Ly7Tr+odaVx28A30acd/oOeVkCs+Q96nI0zi3+30wc3wNGQScXmUTWltMxDALcpl X-Received: by 2002:aca:e144:0:b0:36f:f33:8cc with SMTP id y65-20020acae144000000b0036f0f3308ccmr1678844oig.35.1674667922579; Wed, 25 Jan 2023 09:32:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674667922; cv=none; d=google.com; s=arc-20160816; b=XSmS366vH6fPCFvBCNDNs9o8RJ28ZxH6nIwfxQ5d1FKcRyPiSm2zE9f6hW9oxXACvT EmHRu6EMHqtnVs7nmjYemIavrje1y0LMPyUFQbY/L+LQpLRx0lX7EWk4T/wcEXRdkFya DBlXSUtsunIl0jWYVd3+Mp/4vArjKQzobOGSJVwz11QNpm2lSJodijc6E1rswsRCKMma yl2Cf58cAvUsYOQuww612AKGFLl3mgPDjMbVANXpILsQkTjD5jWsBYBbPiLckDdejWrW Oc8Q9MY65OX+dsRoxrH1kOFob6SeDvNfMMMwW9fNg/YCauHUHeFlcpCExq+3dG+jGpiI Fb2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=UuMj28wdSwykFeEuiaFXWhIV25FoxxFITjuBsocL42s=; b=xHMqPaOvCF6OjJExyfvhzzP01A0m4FKmmzB02TxKZSvC7BWK08pYC+wqOPyqwUqQ9T GL6ckC4aVAJTfd2zLN91Sj/03ZWxmO4ZXVXc86N6hSDjIgbDRqtweiIVF59s0ssbAt/o b5b2X83whaRTIz5qt012Li7iL4uEBw0Fdxii4nYG/bJ6V6gOoc0ddtvKPVtZSINuZwra H7ys66KiC2zpCTljX1LiNBcnjYXONRnsj6Dbrvn/QOqux/PWLvxkzFsTsLOcnTuLuSX5 /nuaWirg53EkH/XbT80iZCzg7+rYMC26KB4PD/LTnYg/1O0IC5mvTlkETPl8GpRaLcc4 yGkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cCFMXU5n; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id s184-20020acac2c1000000b0035b70842962si4660278oif.22.2023.01.25.09.32.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jan 2023 09:32:02 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cCFMXU5n; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D33B7856C7; Wed, 25 Jan 2023 18:31:59 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org 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=linaro.org header.i=@linaro.org header.b="cCFMXU5n"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A23A3856C7; Wed, 25 Jan 2023 18:31:57 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) (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 E94D1856DD for ; Wed, 25 Jan 2023 18:31:52 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=loic.poulain@linaro.org Received: by mail-wm1-x334.google.com with SMTP id f19-20020a1c6a13000000b003db0ef4dedcso1748358wmc.4 for ; Wed, 25 Jan 2023 09:31:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=UuMj28wdSwykFeEuiaFXWhIV25FoxxFITjuBsocL42s=; b=cCFMXU5ntJRL37PBd8UztQYfKeSrQBOmRKYhCcR4e8/DB/8anw3OVaXfA/NR8v2Fpx sCMm2tD7jbGRNqZeOzg4Bf/gH0n6qBN/cGj46lSi9/KvizS3EdvJ+12gR1ye6FIjk5bD 2IluOA5+zKIq3pi1njqUxpH1nISYKwBb63jmnV1kxVGMkPw2hfOTDPGCJSn7bkGTpeId 9sWeCzfBEiV/5ZX5uipX0p5qoORngeaBkxxi8+U6U0rlGyD+eL/lOCV/u2d7sd4FDbmB 1qCQLrCXcOZpzo9omkaal2eIKr0z3mZ3zu1pAK/Ne7i40tJ80CblVNis2G9gyWJr/uAU YhKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=UuMj28wdSwykFeEuiaFXWhIV25FoxxFITjuBsocL42s=; b=l9qM8UStLpVHaVSy7UqNoKuN0dYD+qINxpLkOE0jqbQIiehEeZoUUE3rtpQYlm6zx6 Yj54/OZmg2W8Xs53d4dKCrUUjuXzlEeJ+PC7rp8BkEAFz4Ee4Fkp+klN/nbm0C0DYF4m M0oGEHMCeUHVWUfViHs+EDV73hY7J45NLjMZc/qFQCBg+CRK2s70Ijf9saT7s3xmS1ZV usY8HT+2jThRiw7uLmHHn4Uv6sDoHrgpnnu2ezQW6Rk/GqAKRwIWEsGRoXaPyQ0Jf9uA fqUQ3wynrDx8L8IbGsljIbC07vQbguNTVsrEM1o7nd7J8j8oV/gYd0rYbiEf+b5mSHaJ ghcA== X-Gm-Message-State: AFqh2kr0MAXgzOOQw9Wqeo2GodpLfvMIHmqVnPCDkaBN6PpKYxV1z6vx ZaPJlwen8u45xIf/Esw7ljH2vA== X-Received: by 2002:a05:600c:1e21:b0:3d0:7fee:8a70 with SMTP id ay33-20020a05600c1e2100b003d07fee8a70mr32855282wmb.19.1674667912423; Wed, 25 Jan 2023 09:31:52 -0800 (PST) Received: from loic-ThinkPad-T470p.. ([2a01:e0a:82c:5f0:bda1:2bc4:dac2:c66f]) by smtp.gmail.com with ESMTPSA id u36-20020a05600c4d2400b003daf681d05dsm2421533wmp.26.2023.01.25.09.31.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jan 2023 09:31:51 -0800 (PST) From: Loic Poulain To: peng.fan@nxp.com, sjg@chromium.org, jh80.chung@samsung.com Cc: u-boot@lists.denx.de, Loic Poulain Subject: [PATCH 1/2] mmc: Check support for TRIM operations Date: Wed, 25 Jan 2023 18:31:46 +0100 Message-Id: <20230125173147.477383-1-loic.poulain@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.6 at phobos.denx.de X-Virus-Status: Clean When secure/insecure TRIM operations are supported. When used as erase command argument it applies the erase operation to write blocks instead of erase groups. Signed-off-by: Loic Poulain --- drivers/mmc/mmc.c | 3 +++ include/mmc.h | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index 210703ea46..e5f5ccb5f4 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c @@ -2432,6 +2432,9 @@ static int mmc_startup_v4(struct mmc *mmc) mmc->wr_rel_set = ext_csd[EXT_CSD_WR_REL_SET]; + mmc->can_trim = + !!(ext_csd[EXT_CSD_SEC_FEATURE] & EXT_CSD_SEC_FEATURE_TRIM_EN); + return 0; error: if (mmc->ext_csd) { diff --git a/include/mmc.h b/include/mmc.h index 571fa625d0..f6e23625ca 100644 --- a/include/mmc.h +++ b/include/mmc.h @@ -241,6 +241,7 @@ static inline bool mmc_is_tuning_cmd(uint cmdidx) #define EXT_CSD_HC_WP_GRP_SIZE 221 /* RO */ #define EXT_CSD_HC_ERASE_GRP_SIZE 224 /* RO */ #define EXT_CSD_BOOT_MULT 226 /* RO */ +#define EXT_CSD_SEC_FEATURE 231 /* RO */ #define EXT_CSD_GENERIC_CMD6_TIME 248 /* RO */ #define EXT_CSD_BKOPS_SUPPORT 502 /* RO */ @@ -315,6 +316,8 @@ static inline bool mmc_is_tuning_cmd(uint cmdidx) #define EXT_CSD_WR_DATA_REL_USR (1 << 0) /* user data area WR_REL */ #define EXT_CSD_WR_DATA_REL_GP(x) (1 << ((x)+1)) /* GP part (x+1) WR_REL */ +#define EXT_CSD_SEC_FEATURE_TRIM_EN (1 << 4) /* Support secure & insecure trim */ + #define R1_ILLEGAL_COMMAND (1 << 22) #define R1_APP_CMD (1 << 5) @@ -687,6 +690,7 @@ struct mmc { uint tran_speed; uint legacy_speed; /* speed for the legacy mode provided by the card */ uint read_bl_len; + bool can_trim; #if CONFIG_IS_ENABLED(MMC_WRITE) uint write_bl_len; uint erase_grp_size; /* in 512-byte sectors */ From patchwork Wed Jan 25 17:31:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Poulain X-Patchwork-Id: 646562 Delivered-To: patch@linaro.org Received: by 2002:a17:522:b9de:b0:4b9:b062:db3b with SMTP id fj30csp401545pvb; Wed, 25 Jan 2023 09:32:21 -0800 (PST) X-Google-Smtp-Source: AMrXdXsSTVphiC8SdpK0TToh5ulddejDBHyAfwGv3Dq3b6mPL4QUt8TbxbjJtfOfDdnzYo+Y8kAB X-Received: by 2002:a05:6870:e9a:b0:15f:5713:6407 with SMTP id mm26-20020a0568700e9a00b0015f57136407mr16583739oab.1.1674667940850; Wed, 25 Jan 2023 09:32:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674667940; cv=none; d=google.com; s=arc-20160816; b=nfx8xzcbLXl/fQBl4bqhCYoWk1+y2T8Yp5Ko/88+9RukiBDfRrCeVwCuIFfVQeHPYm 9wsE7NEp8jdbSPskGe9GLO68aAhvLSQawXcPKZOPk9fDhZNSvIlmzemSVbj95Slrdl28 t5H6PoleYEHV/13ZEFtRgr5NX4cDdHbJ+EFaD/ALO8XSKmZgq69TdcfEutzK5G0Z3+2V bHIJciGyK5HOdEjim6NWMaVPlne/bRNWoFJnmngwXMb86QuAHKviky7PcEFWx+eesHt5 jSTT0lWcPkFLPtCE6ihsdRs5bikiUQk3G7Of2CGuBIdRtob6RvLFIcuKn4hntAWir4Iw 3SUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=lykCEayJRiZG1+5JbNN5UQvX8FOES4udJby3A5OW1Bw=; b=f9t+u/mm8COszlzzIIuKxmV9PxlhCz8OrscZo2qW6tiCug0MQoz/TY5NVNFIkg349n YQrCDMDqVERxwnx5huc8XW6ft6zs2gkLW4NPbo5XparZ6sMQriSVQwvELbL5bFdyuqRc WUndBFeIfLchhVl66XOWZGbC6hWvuxQ8X6XOMOh6eLhiNmdP+FdAJ85cMIhXYChh7tYx IRtxvcd0j8mhyW4bweF1KMnLRI8ue7XPiUyCQSz3wFcooX0BnD3HeNUUlURBoMbBXpv4 xM+humckHMXz2B44fPB/pMb8/ETUVmk/q0zSVOUpR6JIGIbZ1pOi/ans6CEqpPuuej4L djwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ARSomLLB; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id u66-20020a4a2145000000b004a4a373b6c0si6341711oou.27.2023.01.25.09.32.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jan 2023 09:32:20 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ARSomLLB; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4B0CC856CE; Wed, 25 Jan 2023 18:32:15 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org 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=linaro.org header.i=@linaro.org header.b="ARSomLLB"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E01648551E; Wed, 25 Jan 2023 18:32:05 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) (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 8791D85480 for ; Wed, 25 Jan 2023 18:31:56 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=loic.poulain@linaro.org Received: by mail-wr1-x429.google.com with SMTP id q10so865008wrm.4 for ; Wed, 25 Jan 2023 09:31:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lykCEayJRiZG1+5JbNN5UQvX8FOES4udJby3A5OW1Bw=; b=ARSomLLBBddujUq1O9hMU2kIkDN3+VltPzXFPhWgp/CQ8TAOkPbTG4nDcV8UvtMoCK kFJduq1IlcXlH3rf0tZmXjpuUUoZlBHTafQCoj3LeapMJIhtAYWLSr/6GsdV4PNHO76P q8lcVxD8rd8570N7nFnNhraxy6zOO0dkU/BGiFbtq/Crdv0LqVU2lWYmKfRd8DFmrAV+ 96iPdE41nDCdCt+p1hr9vXwK+LnpaT2TKv12M5MYYckLyevhvBnIRQ7WMIRspXuKp/op xAZGJlFIEXmypiA3UCpDJgyAqRnYxsc/O/CKi0AP6oBHsgi8MYf4R98VPot8IXspVjj4 tNAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lykCEayJRiZG1+5JbNN5UQvX8FOES4udJby3A5OW1Bw=; b=gBPWWfSZochNYffffXD1L6jhcw+IvTUuA1TmtEy1qZV09eYwm94uqX6cpLCaUlpa5v Lu0cNYxArJa0hmq6KtHAP548FihTKbRx1874GAVuIgP/gBl9iq45g0G4cFrvUrS3PtWk DINWQ8nCEhqgjwRzXwlLh98u051Fhj2dGysBZhJOtCOg69elAjr8vEN3AkXS10Wq+/7S 03r+9fBvVw0r28xCFJZhLmgzRu3eKhxa8lm9EiQhAARNF8CLZ2kplar6wP9bllPz5hKF T7Z+LDuAWU/kK3+WfFfHKDhokYyRLP6ERINVDPUp9NzLAt/j9LvnS2E7sJ6sWOE+Hqs1 JYng== X-Gm-Message-State: AFqh2kqIuuIL3Grx8FuC6ir75I0dW6WbEZqrwZ1HLw4G5YU03e37JS87 nHyuMh+7t6BGHBAZZ/WZU4TaAQ== X-Received: by 2002:adf:dc41:0:b0:2be:5c3b:9d28 with SMTP id m1-20020adfdc41000000b002be5c3b9d28mr18324718wrj.67.1674667915921; Wed, 25 Jan 2023 09:31:55 -0800 (PST) Received: from loic-ThinkPad-T470p.. ([2a01:e0a:82c:5f0:bda1:2bc4:dac2:c66f]) by smtp.gmail.com with ESMTPSA id u36-20020a05600c4d2400b003daf681d05dsm2421533wmp.26.2023.01.25.09.31.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jan 2023 09:31:55 -0800 (PST) From: Loic Poulain To: peng.fan@nxp.com, sjg@chromium.org, jh80.chung@samsung.com Cc: u-boot@lists.denx.de, Loic Poulain Subject: [PATCH 2/2] mmc: erase: Use TRIM erase when available Date: Wed, 25 Jan 2023 18:31:47 +0100 Message-Id: <20230125173147.477383-2-loic.poulain@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230125173147.477383-1-loic.poulain@linaro.org> References: <20230125173147.477383-1-loic.poulain@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.6 at phobos.denx.de X-Virus-Status: Clean The default erase command applies on erase group unit, and simply round down to erase group size. When the start block is not aligned to erase group size (e.g. erasing partition) it causes unwanted erasing of the previous blocks, part of the same erase group (e.g. owned by other logical partition, or by the partition table itself). To prevent this issue, a simple solution is to use TRIM as argument of the Erase command, which is usually supported with eMMC > 4.0, and allow to apply erase operation to write blocks instead of erase group Signed-off-by: Loic Poulain --- drivers/mmc/mmc_write.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/drivers/mmc/mmc_write.c b/drivers/mmc/mmc_write.c index 5b7aeeb012..a6f93380dd 100644 --- a/drivers/mmc/mmc_write.c +++ b/drivers/mmc/mmc_write.c @@ -15,7 +15,7 @@ #include #include "mmc_private.h" -static ulong mmc_erase_t(struct mmc *mmc, ulong start, lbaint_t blkcnt) +static ulong mmc_erase_t(struct mmc *mmc, ulong start, lbaint_t blkcnt, u32 args) { struct mmc_cmd cmd; ulong end; @@ -52,7 +52,7 @@ static ulong mmc_erase_t(struct mmc *mmc, ulong start, lbaint_t blkcnt) goto err_out; cmd.cmdidx = MMC_CMD_ERASE; - cmd.cmdarg = MMC_ERASE_ARG; + cmd.cmdarg = args ? args : MMC_ERASE_ARG; cmd.resp_type = MMC_RSP_R1b; err = mmc_send_cmd(mmc, &cmd, NULL); @@ -77,7 +77,7 @@ ulong mmc_berase(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt) #endif int dev_num = block_dev->devnum; int err = 0; - u32 start_rem, blkcnt_rem; + u32 start_rem, blkcnt_rem, erase_args = 0; struct mmc *mmc = find_mmc_device(dev_num); lbaint_t blk = 0, blk_r = 0; int timeout_ms = 1000; @@ -97,13 +97,25 @@ ulong mmc_berase(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt) */ err = div_u64_rem(start, mmc->erase_grp_size, &start_rem); err = div_u64_rem(blkcnt, mmc->erase_grp_size, &blkcnt_rem); - if (start_rem || blkcnt_rem) - printf("\n\nCaution! Your devices Erase group is 0x%x\n" - "The erase range would be change to " - "0x" LBAF "~0x" LBAF "\n\n", - mmc->erase_grp_size, start & ~(mmc->erase_grp_size - 1), - ((start + blkcnt + mmc->erase_grp_size - 1) - & ~(mmc->erase_grp_size - 1)) - 1); + if (start_rem || blkcnt_rem) { + if (mmc->can_trim) { + /* Trim function applies the erase operation to write + * blocks instead of erase groups. + */ + erase_args = MMC_TRIM_ARG; + } else { + /* The card ignores all LSB's below the erase group + * size, rounding down the addess to a erase group + * boundary. + */ + printf("\n\nCaution! Your devices Erase group is 0x%x\n" + "The erase range would be change to " + "0x" LBAF "~0x" LBAF "\n\n", + mmc->erase_grp_size, start & ~(mmc->erase_grp_size - 1), + ((start + blkcnt + mmc->erase_grp_size - 1) + & ~(mmc->erase_grp_size - 1)) - 1); + } + } while (blk < blkcnt) { if (IS_SD(mmc) && mmc->ssr.au) { @@ -113,7 +125,7 @@ ulong mmc_berase(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt) blk_r = ((blkcnt - blk) > mmc->erase_grp_size) ? mmc->erase_grp_size : (blkcnt - blk); } - err = mmc_erase_t(mmc, start + blk, blk_r); + err = mmc_erase_t(mmc, start + blk, blk_r, erase_args); if (err) break;