From: Denis Mukhin <[email protected]> Introduce `flush` subcommand for all blk devices to allow committing dirty data explicitly to the given block device.
Signed-off-by: Denis Mukhin <[email protected]> --- Changes since v2: - addressed feedback: https://lore.kernel.org/u-boot/caflsztgo6gbg+trpswytffpvjd5pv8pw79eq7rg_gj0w-e2...@mail.gmail.com/ Changes since v1: - updated commit message - updated blk commands to enable flush --- cmd/blk_common.c | 17 +++++++++++++++++ cmd/blkmap.c | 2 ++ cmd/ide.c | 1 + cmd/nvme.c | 1 + cmd/pvblock.c | 1 + cmd/sata.c | 1 + cmd/scsi.c | 1 + cmd/usb.c | 1 + cmd/virtio.c | 1 + 9 files changed, 26 insertions(+) diff --git a/cmd/blk_common.c b/cmd/blk_common.c index 56529702a470..ea6c407eb222 100644 --- a/cmd/blk_common.c +++ b/cmd/blk_common.c @@ -37,6 +37,23 @@ int blk_common_cmd(int argc, char *const argv[], enum uclass_id uclass_id, printf("\nno %s partition table available\n", if_name); return CMD_RET_SUCCESS; + } else if (strncmp(argv[1], "flush", 5) == 0) { + struct blk_desc *desc; + int ret; + + ret = blk_get_desc(uclass_id, *cur_devnump, &desc); + if (ret) + return CMD_RET_FAILURE; + + ret = blk_dflush(desc); + if (ret) { + printf("\nfailed to flush device %d (%s): %d\n", + *cur_devnump, if_name, ret); + return CMD_RET_FAILURE; + } + printf("\nsuccess!\n"); + + return CMD_RET_SUCCESS; } return CMD_RET_USAGE; case 3: diff --git a/cmd/blkmap.c b/cmd/blkmap.c index 65edec899e2c..828754cf6ac8 100644 --- a/cmd/blkmap.c +++ b/cmd/blkmap.c @@ -220,6 +220,7 @@ U_BOOT_CMD_WITH_SUBCMDS( blkmap, "Composeable virtual block devices", "info - list configured devices\n" "blkmap part - list available partitions on current blkmap device\n" + "blkmap flush - commit all dirty data to current blkmap device\n" "blkmap dev [<dev>] - show or set current blkmap device\n" "blkmap read <addr> <blk#> <cnt>\n" "blkmap write <addr> <blk#> <cnt>\n" @@ -230,6 +231,7 @@ U_BOOT_CMD_WITH_SUBCMDS( "blkmap map <label> <blk#> <cnt> mem <addr> [preserve] - memory mapping\n", U_BOOT_SUBCMD_MKENT(info, 2, 1, do_blkmap_common), U_BOOT_SUBCMD_MKENT(part, 2, 1, do_blkmap_common), + U_BOOT_SUBCMD_MKENT(flush, 2, 1, do_blkmap_common), U_BOOT_SUBCMD_MKENT(dev, 4, 1, do_blkmap_common), U_BOOT_SUBCMD_MKENT(read, 5, 1, do_blkmap_common), U_BOOT_SUBCMD_MKENT(write, 5, 1, do_blkmap_common), diff --git a/cmd/ide.c b/cmd/ide.c index ed30f9468660..3f38c1e633fe 100644 --- a/cmd/ide.c +++ b/cmd/ide.c @@ -67,6 +67,7 @@ U_BOOT_CMD(ide, 5, 1, do_ide, "IDE sub-system", "reset - reset IDE controller\n" "ide info - show available IDE devices\n" + "ide flush - commit all dirty data to the current IDE device\n" "ide device [dev] - show or set current device\n" "ide part [dev] - print partition table of one or all IDE devices\n" "ide read addr blk# cnt\n" diff --git a/cmd/nvme.c b/cmd/nvme.c index f2c9acba5c32..dbccb69042bc 100644 --- a/cmd/nvme.c +++ b/cmd/nvme.c @@ -47,6 +47,7 @@ U_BOOT_CMD( "scan - scan NVMe devices\n" "nvme detail - show details of current NVMe device\n" "nvme info - show all available NVMe devices\n" + "nvme flush - commit all dirty data to the current NVMe device\n" "nvme device [dev] - show or set current NVMe device\n" "nvme part [dev] - print partition table of one or all NVMe devices\n" "nvme read addr blk# cnt - read `cnt' blocks starting at block\n" diff --git a/cmd/pvblock.c b/cmd/pvblock.c index 3a83ac9cd92c..5e4a98a6b13b 100644 --- a/cmd/pvblock.c +++ b/cmd/pvblock.c @@ -20,6 +20,7 @@ int do_pvblock(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) U_BOOT_CMD(pvblock, 5, 1, do_pvblock, "Xen para-virtualized block device", "info - show available block devices\n" + "pvblock flush - commit all dirty data to the current device\n" "pvblock device [dev] - show or set current device\n" "pvblock part [dev] - print partition table of one or all devices\n" "pvblock read addr blk# cnt\n" diff --git a/cmd/sata.c b/cmd/sata.c index 8b923f9378b2..417e027cba4f 100644 --- a/cmd/sata.c +++ b/cmd/sata.c @@ -119,6 +119,7 @@ U_BOOT_CMD( "init - init SATA sub system\n" "sata stop [dev] - disable SATA sub system or device\n" "sata info - show available SATA devices\n" + "sata flush - commit all dirty data to the current SATA device\n" "sata device [dev] - show or set current device\n" "sata part [dev] - print partition table\n" "sata read addr blk# cnt\n" diff --git a/cmd/scsi.c b/cmd/scsi.c index 9f7613424e59..05850726a87a 100644 --- a/cmd/scsi.c +++ b/cmd/scsi.c @@ -55,6 +55,7 @@ U_BOOT_CMD( "reset - reset SCSI controller\n" "scsi info - show available SCSI devices\n" "scsi scan - (re-)scan SCSI bus\n" + "scsi flush - commit all dirty data to the current SCSI device\n" "scsi device [dev] - show or set current device\n" "scsi part [dev] - print partition table of one or all SCSI devices\n" "scsi read addr blk# cnt - read `cnt' blocks starting at block `blk#'\n" diff --git a/cmd/usb.c b/cmd/usb.c index 13a2996c1f00..3e156f54c50b 100644 --- a/cmd/usb.c +++ b/cmd/usb.c @@ -706,6 +706,7 @@ U_BOOT_CMD( " Available modes: J, K, S[E0_NAK], P[acket], F[orce_Enable]\n" #ifdef CONFIG_USB_STORAGE "usb storage - show details of USB storage devices\n" + "usb flush - commit all dirty data to the current USB storage\n" "usb dev [dev] - show or set current USB storage device\n" "usb part [dev] - print partition table of one or all USB storage" " devices\n" diff --git a/cmd/virtio.c b/cmd/virtio.c index a42a563ab727..94f1e82cc902 100644 --- a/cmd/virtio.c +++ b/cmd/virtio.c @@ -44,6 +44,7 @@ U_BOOT_CMD( "virtio block devices sub-system", "scan - initialize virtio bus\n" "virtio info - show all available virtio block devices\n" + "virtio flush - commit all dirty data to the current virtio block device\n" "virtio device [dev] - show or set current virtio block device\n" "virtio part [dev] - print partition table of one or all virtio block devices\n" "virtio read addr blk# cnt - read `cnt' blocks starting at block\n" -- 2.54.0

