blob: 5da903bd524dc924b2b8284ef723c0062bfa15e0 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Zhikang Zhang0adc38b2017-08-03 02:30:59 -07002/*
3 * Copyright (C) 2017 NXP Semiconductors
4 * Copyright (C) 2017 Bin Meng <bmeng.cn@gmail.com>
Zhikang Zhang0adc38b2017-08-03 02:30:59 -07005 */
6
7#include <common.h>
8#include <command.h>
9#include <dm.h>
10#include <nvme.h>
Zhikang Zhang0adc38b2017-08-03 02:30:59 -070011
Bin Mengfceadc12017-08-22 08:15:17 -070012static int nvme_curr_dev;
Zhikang Zhang0adc38b2017-08-03 02:30:59 -070013
Bin Mengfceadc12017-08-22 08:15:17 -070014static int do_nvme(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Zhikang Zhang0adc38b2017-08-03 02:30:59 -070015{
16 int ret;
17
Bin Mengfceadc12017-08-22 08:15:17 -070018 if (argc == 2) {
19 if (strncmp(argv[1], "scan", 4) == 0) {
20 ret = nvme_scan_namespace();
21 if (ret)
22 return CMD_RET_FAILURE;
Zhikang Zhang0adc38b2017-08-03 02:30:59 -070023
Bin Mengfceadc12017-08-22 08:15:17 -070024 return ret;
Zhikang Zhang0adc38b2017-08-03 02:30:59 -070025 }
Bin Mengfceadc12017-08-22 08:15:17 -070026 if (strncmp(argv[1], "deta", 4) == 0) {
27 struct udevice *udev;
Zhikang Zhang0adc38b2017-08-03 02:30:59 -070028
Bin Mengfceadc12017-08-22 08:15:17 -070029 ret = blk_get_device(IF_TYPE_NVME, nvme_curr_dev,
30 &udev);
31 if (ret < 0)
32 return CMD_RET_FAILURE;
Zhikang Zhang0adc38b2017-08-03 02:30:59 -070033
Bin Mengfceadc12017-08-22 08:15:17 -070034 nvme_print_info(udev);
Zhikang Zhang0adc38b2017-08-03 02:30:59 -070035
Bin Mengfceadc12017-08-22 08:15:17 -070036 return ret;
Zhikang Zhang0adc38b2017-08-03 02:30:59 -070037 }
Zhikang Zhang0adc38b2017-08-03 02:30:59 -070038 }
39
Bin Mengfceadc12017-08-22 08:15:17 -070040 return blk_common_cmd(argc, argv, IF_TYPE_NVME, &nvme_curr_dev);
Zhikang Zhang0adc38b2017-08-03 02:30:59 -070041}
42
43U_BOOT_CMD(
Bin Mengfceadc12017-08-22 08:15:17 -070044 nvme, 8, 1, do_nvme,
Zhikang Zhang0adc38b2017-08-03 02:30:59 -070045 "NVM Express sub-system",
Bin Mengfceadc12017-08-22 08:15:17 -070046 "scan - scan NVMe devices\n"
47 "nvme detail - show details of current NVMe device\n"
48 "nvme info - show all available NVMe devices\n"
49 "nvme device [dev] - show or set current NVMe device\n"
50 "nvme part [dev] - print partition table of one or all NVMe devices\n"
51 "nvme read addr blk# cnt - read `cnt' blocks starting at block\n"
52 " `blk#' to memory address `addr'\n"
53 "nvme write addr blk# cnt - write `cnt' blocks starting at block\n"
54 " `blk#' from memory address `addr'"
Zhikang Zhang0adc38b2017-08-03 02:30:59 -070055);