]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
dm: blk: Add 'erase' generic block device commands
authorVaradarajan Narayanan <quic_varada@quicinc.com>
Tue, 1 Apr 2025 10:09:58 +0000 (15:39 +0530)
committerTom Rini <trini@konsulko.com>
Fri, 11 Apr 2025 02:55:53 +0000 (20:55 -0600)
Add support for doing 'erase' using the generic block commands
framework.

Signed-off-by: Varadarajan Narayanan <quic_varada@quicinc.com>
cmd/blk_common.c

index 4c05a4e0610e0bf5c32c1105317bae274b3a7d96..56529702a47074f7a46b3f6b4e8ec2799eeaa60d 100644 (file)
@@ -107,6 +107,23 @@ int blk_common_cmd(int argc, char *const argv[], enum uclass_id uclass_id,
                        printf("%ld blocks written: %s\n", n,
                               n == cnt ? "OK" : "ERROR");
                        return n == cnt ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
+               } else if (strcmp(argv[1], "erase") == 0) {
+                       lbaint_t blk = hextoul(argv[2], NULL);
+                       ulong cnt = hextoul(argv[3], NULL);
+                       struct blk_desc *desc;
+                       ulong n;
+
+                       printf("\n%s erase: device %d block # "LBAFU", count %lu ... ",
+                              if_name, *cur_devnump, blk, cnt);
+
+                       if (blk_get_desc(uclass_id, *cur_devnump, &desc))
+                               return CMD_RET_FAILURE;
+
+                       n = blk_derase(desc, blk, cnt);
+
+                       printf("%ld blocks erased: %s\n", n,
+                              n == cnt ? "OK" : "ERROR");
+                       return n == cnt ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
                } else {
                        return CMD_RET_USAGE;
                }