summaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorBin Meng <bmeng.cn@gmail.com>2017-08-22 08:15:17 -0700
committerTom Rini <trini@konsulko.com>2017-08-28 07:17:15 -0400
commitfceadc1459c099303f1e0cdd1937bb561b5ce288 (patch)
tree8cc6ae4a27ffa812d792fa1aed947e1ee7c91e95 /cmd
parent18aa5a4134e8179c7c3e38675822284a2718a3d8 (diff)
downloadu-boot-fceadc1459c099303f1e0cdd1937bb561b5ce288.tar.gz
u-boot-fceadc1459c099303f1e0cdd1937bb561b5ce288.tar.xz
u-boot-fceadc1459c099303f1e0cdd1937bb561b5ce288.zip
nvme: Adjust the 'nvme' command to use blk_common_cmd()
Instead of having separate code in the 'nvme' command, adjust it to use the common function. Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/nvme.c195
1 files changed, 27 insertions, 168 deletions
diff --git a/cmd/nvme.c b/cmd/nvme.c
index e1ef95fdf3..63a8e5a0c2 100644
--- a/cmd/nvme.c
+++ b/cmd/nvme.c
@@ -9,189 +9,48 @@
#include <command.h>
#include <dm.h>
#include <nvme.h>
-#include <part.h>
-#include <linux/math64.h>
-static int nvme_curr_device;
+static int nvme_curr_dev;
-static int do_nvme_scan(cmd_tbl_t *cmdtp, int flag,
- int argc, char * const argv[])
+static int do_nvme(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
int ret;
- ret = nvme_scan_namespace();
- if (ret)
- return CMD_RET_FAILURE;
+ if (argc == 2) {
+ if (strncmp(argv[1], "scan", 4) == 0) {
+ ret = nvme_scan_namespace();
+ if (ret)
+ return CMD_RET_FAILURE;
- return CMD_RET_SUCCESS;
-}
-
-static int do_nvme_list(cmd_tbl_t *cmdtp, int flag,
- int argc, char * const argv[])
-{
- blk_list_devices(IF_TYPE_NVME);
-
- return CMD_RET_SUCCESS;
-}
-
-static int do_nvme_info(cmd_tbl_t *cmdtp, int flag,
- int argc, char * const argv[])
-{
- int devnum;
- struct udevice *udev;
- int ret;
-
- if (argc > 1)
- devnum = (int)simple_strtoul(argv[1], NULL, 10);
- else
- devnum = nvme_curr_device;
-
- ret = blk_get_device(IF_TYPE_NVME, devnum, &udev);
- if (ret < 0)
- return CMD_RET_FAILURE;
-
- nvme_print_info(udev);
-
- return CMD_RET_SUCCESS;
-}
-
-static int do_nvme_device(cmd_tbl_t *cmdtp, int flag,
- int argc, char * const argv[])
-{
- if (argc > 1) {
- int devnum = (int)simple_strtoul(argv[1], NULL, 10);
-
- if (!blk_show_device(IF_TYPE_NVME, devnum)) {
- nvme_curr_device = devnum;
- printf("... is now current device\n");
- } else {
- return CMD_RET_FAILURE;
+ return ret;
}
- } else {
- blk_show_device(IF_TYPE_NVME, nvme_curr_device);
- }
+ if (strncmp(argv[1], "deta", 4) == 0) {
+ struct udevice *udev;
- return CMD_RET_SUCCESS;
-}
+ ret = blk_get_device(IF_TYPE_NVME, nvme_curr_dev,
+ &udev);
+ if (ret < 0)
+ return CMD_RET_FAILURE;
-static int do_nvme_part(cmd_tbl_t *cmdtp, int flag,
- int argc, char * const argv[])
-{
- if (argc > 1) {
- int devnum = (int)simple_strtoul(argv[2], NULL, 10);
+ nvme_print_info(udev);
- if (blk_print_part_devnum(IF_TYPE_NVME, devnum)) {
- printf("\nNVMe device %d not available\n", devnum);
- return CMD_RET_FAILURE;
+ return ret;
}
- } else {
- blk_print_part_devnum(IF_TYPE_NVME, nvme_curr_device);
- }
-
- return CMD_RET_SUCCESS;
-}
-
-static int do_nvme_read(cmd_tbl_t *cmdtp, int flag, int argc,
- char * const argv[])
-{
- unsigned long time;
- if (argc != 4)
- return CMD_RET_USAGE;
-
- ulong addr = simple_strtoul(argv[1], NULL, 16);
- ulong cnt = simple_strtoul(argv[3], NULL, 16);
- ulong n;
- lbaint_t blk = simple_strtoul(argv[2], NULL, 16);
-
- printf("\nNVMe read: device %d block # " LBAFU " count %ld ... ",
- nvme_curr_device, blk, cnt);
-
- time = get_timer(0);
- n = blk_read_devnum(IF_TYPE_NVME, nvme_curr_device, blk,
- cnt, (ulong *)addr);
- time = get_timer(time);
-
- printf("read: %s\n", (n == cnt) ? "OK" : "ERROR");
- printf("%lu bytes read in %lu ms", cnt * 512, time);
- if (time > 0) {
- puts(" (");
- print_size(div_u64(cnt * 512, time) * 1000, "/s");
- puts(")");
}
- puts("\n");
-
- return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
-}
-
-static int do_nvme_write(cmd_tbl_t *cmdtp, int flag, int argc,
- char * const argv[])
-{
- unsigned long time;
- if (argc != 4)
- return CMD_RET_USAGE;
-
- ulong addr = simple_strtoul(argv[1], NULL, 16);
- ulong cnt = simple_strtoul(argv[3], NULL, 16);
- ulong n;
- lbaint_t blk = simple_strtoul(argv[2], NULL, 16);
-
- printf("\nNVMe write: device %d block # " LBAFU " count %ld ... ",
- nvme_curr_device, blk, cnt);
-
- time = get_timer(0);
- n = blk_write_devnum(IF_TYPE_NVME, nvme_curr_device, blk,
- cnt, (ulong *)addr);
- time = get_timer(time);
-
- printf("write: %s\n", (n == cnt) ? "OK" : "ERROR");
- printf("%lu bytes write in %lu ms", cnt * 512, time);
- if (time > 0) {
- puts(" (");
- print_size(div_u64(cnt * 512, time) * 1000, "/s");
- puts(")");
- }
- puts("\n");
-
- return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
-}
-
-static cmd_tbl_t cmd_nvme[] = {
- U_BOOT_CMD_MKENT(scan, 1, 1, do_nvme_scan, "", ""),
- U_BOOT_CMD_MKENT(list, 1, 1, do_nvme_list, "", ""),
- U_BOOT_CMD_MKENT(info, 2, 1, do_nvme_info, "", ""),
- U_BOOT_CMD_MKENT(device, 2, 1, do_nvme_device, "", ""),
- U_BOOT_CMD_MKENT(part, 2, 1, do_nvme_part, "", ""),
- U_BOOT_CMD_MKENT(write, 4, 0, do_nvme_write, "", ""),
- U_BOOT_CMD_MKENT(read, 4, 0, do_nvme_read, "", "")
-};
-
-static int do_nvmecops(cmd_tbl_t *cmdtp, int flag, int argc,
- char * const argv[])
-{
- cmd_tbl_t *cp;
-
- cp = find_cmd_tbl(argv[1], cmd_nvme, ARRAY_SIZE(cmd_nvme));
-
- argc--;
- argv++;
-
- if (cp == NULL || argc > cp->maxargs)
- return CMD_RET_USAGE;
-
- if (flag == CMD_FLAG_REPEAT && !cp->repeatable)
- return CMD_RET_SUCCESS;
- return cp->cmd(cmdtp, flag, argc, argv);
+ return blk_common_cmd(argc, argv, IF_TYPE_NVME, &nvme_curr_dev);
}
U_BOOT_CMD(
- nvme, 8, 1, do_nvmecops,
+ nvme, 8, 1, do_nvme,
"NVM Express sub-system",
- "\nnvme scan - scan NVMe blk devices\n"
- "nvme list - show all available NVMe blk devices\n"
- "nvme info [dev]- show current or a specific NVMe blk device\n"
- "nvme device [dev] - show or set current device\n"
- "nvme part [dev] - print partition table\n"
- "nvme read addr blk# cnt\n"
- "nvme write addr blk# cnt"
+ "scan - scan NVMe devices\n"
+ "nvme detail - show details of current NVMe device\n"
+ "nvme info - show all available NVMe devices\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"
+ " `blk#' to memory address `addr'\n"
+ "nvme write addr blk# cnt - write `cnt' blocks starting at block\n"
+ " `blk#' from memory address `addr'"
);