From patchwork Thu Jan 26 09:24:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Poulain X-Patchwork-Id: 647080 Delivered-To: patch@linaro.org Received: by 2002:a17:522:b9de:b0:4b9:b062:db3b with SMTP id fj30csp143650pvb; Thu, 26 Jan 2023 01:24:40 -0800 (PST) X-Google-Smtp-Source: AK7set9BR0QoqhpwQXqxyP8z0BlPmQvbTog1q2um+kOfbXfjvKn+n0YOsEQrH8bOSPFsLi1nJBIU X-Received: by 2002:aca:6187:0:b0:371:fe1:8943 with SMTP id v129-20020aca6187000000b003710fe18943mr692417oib.6.1674725080765; Thu, 26 Jan 2023 01:24:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674725080; cv=none; d=google.com; s=arc-20160816; b=U3jVkJ6rYL+zb/P1rgvKtBYwonFJ3Uj0MWj+a3jgJCHNAhXze/juhOJsvIexqNIjD7 ltjqGC2Cumg5Ni+0pvHRjW/ubxJIDmAl25bgi9m8oukNGFzcXiqNj7dYCnRykuw5cTBF 3KOIMpQ72jDLaN5+w6hCknkEbqkPhwcnCHEA6eRS3ksE/MF0OTOrCwespJUVaghBU9Bc ssMYjE8mCWZ+aZ6tKeSHI+4IdHB4F++EEaHhhWaAqvTDEdVRM9DzLUszHO7LlbhnFhfB Iv1y1mK3KxyUYhH55F4OvkggzWsA5p+W96kd97B55i1kN97TJGyic0pHF54dU9Y9rYfO /wyw== 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=VUS1u747ImeKRA0A3IH2qi7kYUS6TVyQnGNriHEDudE=; b=SbSzPHKg2dO87ZI+DKa6E37r9tNRpQ+09MJPFyG4XnmkVYABk8pqgevl2ZLSgYPAl/ FSfeoqmdwmw+LTkqGsGFAJRiDe8cBV/KaA6QokF/colx1JChzx4g6GmQMhJULgddpUME c1LhWlKT1MBOSXKj0qHgYuYIsxtbBRXV6VK847VEptP0dpZXzNDqIbkvWLZp/v45v6RN ZOIApNDv7CiIgZrvOEQ1Ya/12UEXCUZMfxK5TF+4wTnDpMyGLfOPOoP8K1JnwTAVc3Fb eX2TrVBQjn2GJrumAvw4YKV88+dlgUtHBcJSIlnfA32YfEoFhvIUX2TckS9FmgpBie89 52GA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aFZHzYHa; 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 b133-20020acab28b000000b00363ea5fe235si767601oif.89.2023.01.26.01.24.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jan 2023 01:24:40 -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=aFZHzYHa; 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 3D86184E8B; Thu, 26 Jan 2023 10:24:37 +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="aFZHzYHa"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C563F855B4; Thu, 26 Jan 2023 10:24:34 +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-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) (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 7EF1684954 for ; Thu, 26 Jan 2023 10:24:27 +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-x32a.google.com with SMTP id l8so692064wms.3 for ; Thu, 26 Jan 2023 01:24:27 -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=VUS1u747ImeKRA0A3IH2qi7kYUS6TVyQnGNriHEDudE=; b=aFZHzYHaiaib1UMBerk+iRBvfQLWgnrQoCvjlJa8+y80CZG9MQqXkaQqGzPpByysKq jMaAY28VMmko+bV5ZrzXHq2KbjO6lDQDG17JuPf4PQ0uRpF0h3kAO2vpfeRcGDE2QC9Z LW224N3tbgL5NBCHwLiWR7DfTxKMFSD5IuKC8HlD/II0ZFm04HD7iVSS0cgQq59COLFc /QaHYh+12To9LvVx+9zBxAAc8/LCfQxmQH5MZ+sRVvb427q1/MFb5OQKE0NryhJICZ/c /yInA8+L19Cb8w3hQD5CsogSwY0t7Eld7/rVoTJGLYN0h/zIRSwLb6Uz5scf1YF5IfWi EfMw== 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=VUS1u747ImeKRA0A3IH2qi7kYUS6TVyQnGNriHEDudE=; b=ZrkqePjGL2RYy0QZU/qtZxaIhLAbCyTSAyfqc35Pums8C7CvyC0MdiC758R4KGQcyk wcRXarZYfZnzvBy2YCWRoMmE5cjuRBjCvAR8IfXXP9LDkjIQmEcKEkQICF9IxGTF7QlQ 0YfLJMop3S8jHLWW1jEekTen5ss7wT9/x3MEXi9SibhPTa095FI1j64yiLIj0PtEXwMf X2TEVSW7ObrrltaLkIJ58LON7NlZDiTh20BZ9FyKnU5jGB5xrdcrsqmf4bIv+0itgtfQ 5GpNRV8liic6NZWYaz1xL7a/XTbkPL0NEa/jQo8hC9zD0D3nDYoJFL9OqKK8VThoJCTO 1g+w== X-Gm-Message-State: AFqh2kopFeGmtF6IfAV1a4y7y/ixbNjvH/LFuTQQKFl7ENIMnXZkb+J4 VMb4DGai14CQEV50v2kp0a2MFA== X-Received: by 2002:a05:600c:35d0:b0:3db:c4c:9224 with SMTP id r16-20020a05600c35d000b003db0c4c9224mr33337975wmq.3.1674725066847; Thu, 26 Jan 2023 01:24:26 -0800 (PST) Received: from loic-ThinkPad-T470p.. ([2a01:e0a:82c:5f0:352b:2cb1:8983:9f55]) by smtp.gmail.com with ESMTPSA id y34-20020a05600c342200b003dc16dee9b1sm920026wmp.15.2023.01.26.01.24.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jan 2023 01:24:26 -0800 (PST) From: Loic Poulain To: sjg@chromium.org, peng.fan@nxp.com, jh80.chung@samsung.com Cc: u-boot@lists.denx.de, Loic Poulain Subject: [PATCH v2 1/3] mmc: Check support for TRIM operations Date: Thu, 26 Jan 2023 10:24:17 +0100 Message-Id: <20230126092419.534514-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 Reviewed-by: Simon Glass Reviewed-by: Jaehoon Chung --- v2: Add mmc unit test change to the series 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 Thu Jan 26 09:24:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Poulain X-Patchwork-Id: 647081 Delivered-To: patch@linaro.org Received: by 2002:a17:522:b9de:b0:4b9:b062:db3b with SMTP id fj30csp143710pvb; Thu, 26 Jan 2023 01:24:51 -0800 (PST) X-Google-Smtp-Source: AK7set9O3usI4CbKq/ovuS08pIh6R4pI/RWD5PryVqxiWbbufeKwaC3ZWc5fy6O32jJG5XMY3K/b X-Received: by 2002:a05:6870:582a:b0:163:3814:5b73 with SMTP id r42-20020a056870582a00b0016338145b73mr866166oap.38.1674725090917; Thu, 26 Jan 2023 01:24:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674725090; cv=none; d=google.com; s=arc-20160816; b=ARlneJ72ITVvyR0f8nPGQGkLfz+w6ymbDQ+0lwLIbeImcB8dZdoSJu1V6fKGy5SAGc y4MCWbxW/xRVrFAKY+5mPOx48yNRiPoVMSiFv02ROXjj4kOY3iOSw+YXb4pb7vrWxrqL uskyrsr021DnUQYD+GjaLTvkpRDWkzIDSbIYTW0ROH15fiX0K51qhWbxmFspPoaQUixT ubg2b4rl2bLU+4GJ1b3EclvkCR9NyWrewh4s/KQa7k58UOsYKrt/XDCGUXXp6BZjrKD7 h4vg7cV7px58XU87SblmMVS1OEZHDTcexECOECJdmLAoQmM4aqcjsBj27prN/JG0nZrY 7orA== 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=+LnBWj5DLWyNHt/X++e5tEl0oxwm7DTmEQw+hc+sHX4=; b=A64w9U5cGPQhCftK+sUYwiakJ8tEFzz7Svarht96cGzUA2MRmG4mQ9jDObDHJwFoyG Xwp6s7pW6BzdarGYAtlDmw/cqzRa8vAgi880NVZy2OVNxc44npDElyU8fwwzvDuHWq+8 D1sRxym+MPnr6RmQXOELVRZLrupsjJhLZB1oMI05uwODmFkNBcdCQJfE/EvcGwA8aaXH tKFjS59HoyWaZOJ3MItzOEUDCP12eKNC5S7UWBH2Rfg13l7E8j8rQxM0Lxs+zrz+Eie1 h079dfYPHQCiLEQc2i5lRPEuufpb0O71HzZBudFC83YP6KVgKk6vJTRlASZmSiOLOlrS t0aQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cEUNwRCb; 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 pn9-20020a0568704d0900b0014c64b2654fsi900058oab.301.2023.01.26.01.24.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jan 2023 01:24:50 -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=cEUNwRCb; 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 92DCA855B4; Thu, 26 Jan 2023 10:24:39 +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="cEUNwRCb"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0656284954; Thu, 26 Jan 2023 10:24:35 +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-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) (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 0568084E8B for ; Thu, 26 Jan 2023 10:24:29 +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-x335.google.com with SMTP id f19-20020a1c6a13000000b003db0ef4dedcso2846828wmc.4 for ; Thu, 26 Jan 2023 01:24:28 -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=+LnBWj5DLWyNHt/X++e5tEl0oxwm7DTmEQw+hc+sHX4=; b=cEUNwRCbqy+kUQRtktvELcpH6csdI52CNptWm5JLkdKk3vsWLTLpkOvxtFwAcLsfXp LXE8ch2+PqRV9KE11OpAaJ8r4mxNzNxr3qy2vNZ3w3p3FXkVcKg2l0Sh1q2uUIpF69hC U4GBoqdmhD77PND85DysZOvBLqLAOMVDlWONsFz4PijAKawlmVLKecy6/febsoqW5dSr LXrQuf1z19vBfVvHOvLf3PgslBym0T6WFDKh0O71tgDhMeCcGzVft2F7S2HVrPui1jHw yd3yH9LZJSN41Do1WFUUUNIVtbMZEwV1zSmUfS7TFnkR4xsJNlrXBmceqt68kYKcxvyd px7A== 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=+LnBWj5DLWyNHt/X++e5tEl0oxwm7DTmEQw+hc+sHX4=; b=BBsC+k9gh+bVrAvI867Fg9L08LE2qSsYVYOeYNBee4HF1JFAIupsBG9LdWL+Hftdx8 Xevamqw4Eo1ctLCoR+NQey0jiDmmlYCP05IDnG7pVna5xZfM24b62sL4syMo1k/YMK/C 2JaujEHUY+nrKVnviHMESBGZWlwHglQa629LCNgNRsrvwEKoJ32IGu6tDnG88mVL7Tcw ZisOh7OjMM7quWpaKMJinIhOIJVOkfQ+jXWqhZNpTxS66OMxel87Tewm37j++5PBDksW XNtOuk8ZFQPa/7ch8jIXzoA0e+zwvupmgyF5wP46dSEClnTGHTVnawkplYmOPZywu2Qw 3csw== X-Gm-Message-State: AFqh2krI8FA8FtS9251YtIEjWOr+Glj6bbM3BqGyodSSCQs2C046+S0T 1XIMsD3HQoSA+T4sDLDYVfyY0w== X-Received: by 2002:a05:600c:4f4a:b0:3db:5f1:53a5 with SMTP id m10-20020a05600c4f4a00b003db05f153a5mr36004775wmq.20.1674725068489; Thu, 26 Jan 2023 01:24:28 -0800 (PST) Received: from loic-ThinkPad-T470p.. ([2a01:e0a:82c:5f0:352b:2cb1:8983:9f55]) by smtp.gmail.com with ESMTPSA id y34-20020a05600c342200b003dc16dee9b1sm920026wmp.15.2023.01.26.01.24.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jan 2023 01:24:27 -0800 (PST) From: Loic Poulain To: sjg@chromium.org, peng.fan@nxp.com, jh80.chung@samsung.com Cc: u-boot@lists.denx.de, Loic Poulain Subject: [PATCH v2 2/3] mmc: erase: Use TRIM erase when available Date: Thu, 26 Jan 2023 10:24:18 +0100 Message-Id: <20230126092419.534514-2-loic.poulain@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230126092419.534514-1-loic.poulain@linaro.org> References: <20230126092419.534514-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 Reviewed-by: Simon Glass --- v2: Add mmc unit test change to the series 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; From patchwork Thu Jan 26 09:24:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Poulain X-Patchwork-Id: 647082 Delivered-To: patch@linaro.org Received: by 2002:a17:522:b9de:b0:4b9:b062:db3b with SMTP id fj30csp143758pvb; Thu, 26 Jan 2023 01:25:01 -0800 (PST) X-Google-Smtp-Source: AK7set/jxbxtJHvnHuFIerOuzWcIl5b8RptpcInJ9Ja0tRGsI9ecHld3ySDuWJETq9N6L7wQ9rGb X-Received: by 2002:a05:6870:5606:b0:15f:8e58:f000 with SMTP id m6-20020a056870560600b0015f8e58f000mr1009926oao.15.1674725101250; Thu, 26 Jan 2023 01:25:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674725101; cv=none; d=google.com; s=arc-20160816; b=ShNAe8+tqwDGoMURnrHaBjxwbN3t5V2OxfvLcWL0bH22VrJNTQsLiWv9qAEXTReBqS mOoX5lE99UdnPJZjMxnXvVw9T3siEMKWwglRg6j0KfOOh3adTAc9U2JCQl0BhB7o9x1r H8oqa1p+MmzyTW7pmKtpIJBYR9l9tnQ63rVe8EQNfOgYrGkJ+nZqeCpJ2FI0UzopKq7S uaogrNLRqghR+UZRMkNs3hsUz67SQVkzom7mjc6iGJwLP+XDyUMuYjUFahCVnJ8oqsh9 v23jFvVuzg6DZrdRi5mo4zmSskEbex7nfURvrIGHJ3meRhPwjnz2P6b0urGsd8T5Sy28 rqtw== 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=ZvA0pG790coGtk2tNKGToQlVaYz8Lm59UmsFAaerlto=; b=rdKhE0B0bJLzUc3GgnGw9WfmlRNe8pPJRbTcVt/DzuM5OCViF11NL6vnts4+2dP7Y/ 3UMu+Y49SvBEASWKrVVlICEgY6gAKC6fVQx0BIgmAc99gv2MEXffWIMSL7vd3klgHxBF dvaDK+ecMJlwJ4n2No03QTOtEB2X81FmPdPsmAm89IjbzbE/T1u3w7ni4RksGEV6zKku WCaZjd9b6xVUOgPKbJAlS5jISS8JrVlfBxp/K1t8hMcHR19B3HmyXffGNO7MGvz2zwsA nT7UahIkNTiMv9oEcAjelipb3ZW8MGDTdrSvZ7ynEpRoABeTF4fDjZG+r69Pag7uOEWJ SU6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kSn1B7IU; 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 nl26-20020a056871459a00b0015edf025626si936411oab.153.2023.01.26.01.25.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jan 2023 01:25:01 -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=kSn1B7IU; 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 2A1AA856DD; Thu, 26 Jan 2023 10:24:47 +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="kSn1B7IU"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 32E0B84DDE; Thu, 26 Jan 2023 10:24:37 +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-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) (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 BFC7B854F1 for ; Thu, 26 Jan 2023 10:24:30 +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-x32a.google.com with SMTP id e19-20020a05600c439300b003db1cac0c1fso2840975wmn.5 for ; Thu, 26 Jan 2023 01:24:30 -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=ZvA0pG790coGtk2tNKGToQlVaYz8Lm59UmsFAaerlto=; b=kSn1B7IUexvMyZA8UEdmW3qL/yVZ/5DN8k/MFqH1E2qovuyOfxI+ukluP7w4M3n089 lX4UcgVYIHp60ixyjUIRpeeDfafbjSoM8uOF0q+GMAyaR0DKUOL/GNSxrtNEe8bALYrD mQUBwW5tQ/85ODol2/yZW7elbVpPgtgsjftZy+argD5TdyPUer+Ygw4r4vJXfmXgO8D4 Ry0pD8jTVjVK+u8CMAbQX1loceprggRZE2WF2K+r4RfrUUzC8Knv0LvwgU8ODImnjjix gW3vlP4QY8ssBNcgzA4edNPsKOVxwO6yi5OEcCaeGgoABtUy7vT+30ss16BMOISmaj7O MmOw== 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=ZvA0pG790coGtk2tNKGToQlVaYz8Lm59UmsFAaerlto=; b=0xx48H0+KIBsLRa7v24uQDnO+qxT0lqcD7bqFerDmG5t5pZMHEGERPxCl13lUxqEWD BVm18zjnehPtOPN4dI3FFdldsp7CfbGGew71au0XaTOYB9y4drVnxAd1EMHlQs3Gm9xs Ysld1AFx2kk0nePew/AAjtRa8LNIIgZ/dScSLdL9GnO3JAmsQFzkhnXuGv+mk4XUz4LK cl6tzg7aO0PcFPV1FDkWA9a3jRgU0XHe+iWP6Y34nimmQvvZyqzsTmtZFtZM71bedSqH FBb8D29QeNvGqrh1jZKvrsQ4XvFW0kYUTw7yiIggv1nWdr3wo01n//jKL0Hrgma3blOM L5Bg== X-Gm-Message-State: AFqh2ko15LzscJB7eEll9gVIMLAkYeQplZudkJdGIG2VNh6APGLuTKvZ 6eVwybJLhidqdOhiQZWW2kvkHsQbgd9dlBEu X-Received: by 2002:a05:600c:1d92:b0:3da:1145:2196 with SMTP id p18-20020a05600c1d9200b003da11452196mr42019110wms.39.1674725070222; Thu, 26 Jan 2023 01:24:30 -0800 (PST) Received: from loic-ThinkPad-T470p.. ([2a01:e0a:82c:5f0:352b:2cb1:8983:9f55]) by smtp.gmail.com with ESMTPSA id y34-20020a05600c342200b003dc16dee9b1sm920026wmp.15.2023.01.26.01.24.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jan 2023 01:24:29 -0800 (PST) From: Loic Poulain To: sjg@chromium.org, peng.fan@nxp.com, jh80.chung@samsung.com Cc: u-boot@lists.denx.de, Loic Poulain Subject: [PATCH v2 3/3] test: dm: mmc: Check block erasing boundaries Date: Thu, 26 Jan 2023 10:24:19 +0100 Message-Id: <20230126092419.534514-3-loic.poulain@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230126092419.534514-1-loic.poulain@linaro.org> References: <20230126092419.534514-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 Verify that erasing blocks does not impact adjacent ones. - Write four blocks [0 1 2 3] - Erase two blocks [ 1 2 ] - Verify [0 1 2 3 ] Signed-off-by: Loic Poulain --- v2: Add this change to the series test/dm/mmc.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/dm/mmc.c b/test/dm/mmc.c index f744452ff2..b1eb8bee2f 100644 --- a/test/dm/mmc.c +++ b/test/dm/mmc.c @@ -30,7 +30,7 @@ static int dm_test_mmc_blk(struct unit_test_state *uts) struct udevice *dev; struct blk_desc *dev_desc; int i; - char write[1024], read[1024]; + char write[4 * 512], read[4 * 512]; ut_assertok(uclass_get_device(UCLASS_MMC, 0, &dev)); ut_assertok(blk_get_device_by_str("mmc", "0", &dev_desc)); @@ -39,14 +39,14 @@ static int dm_test_mmc_blk(struct unit_test_state *uts) ut_asserteq(512, dev_desc->blksz); for (i = 0; i < sizeof(write); i++) write[i] = i; - ut_asserteq(2, blk_dwrite(dev_desc, 0, 2, write)); - ut_asserteq(2, blk_dread(dev_desc, 0, 2, read)); + ut_asserteq(4, blk_dwrite(dev_desc, 0, 4, write)); + ut_asserteq(4, blk_dread(dev_desc, 0, 4, read)); ut_asserteq_mem(write, read, sizeof(write)); - /* Now erase them */ - memset(write, '\0', sizeof(write)); - ut_asserteq(2, blk_derase(dev_desc, 0, 2)); - ut_asserteq(2, blk_dread(dev_desc, 0, 2, read)); + /* Now erase two of them [1 - 2] and verify all blocks */ + memset(&write[512], '\0', 2 * 512); + ut_asserteq(2, blk_derase(dev_desc, 1, 2)); + ut_asserteq(4, blk_dread(dev_desc, 0, 4, read)); ut_asserteq_mem(write, read, sizeof(write)); return 0;