blob: e715c570a384abc5011254ce7da3691ae96bcf6f [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>
Simon Glasse6f6f9e2020-05-10 11:39:58 -06008#include <blk.h>
Zhikang Zhang0adc38b2017-08-03 02:30:59 -07009#include <command.h>
10#include <dm.h>
11#include <nvme.h>
Zhikang Zhang0adc38b2017-08-03 02:30:59 -070012
Bin Mengfceadc12017-08-22 08:15:17 -070013static int nvme_curr_dev;
Zhikang Zhang0adc38b2017-08-03 02:30:59 -070014
Simon Glass09140112020-05-10 11:40:03 -060015static int do_nvme(struct cmd_tbl *cmdtp, int flag, int argc,
16 char *const argv[])
Zhikang Zhang0adc38b2017-08-03 02:30:59 -070017{
18 int ret;
19
Bin Mengfceadc12017-08-22 08:15:17 -070020 if (argc == 2) {
21 if (strncmp(argv[1], "scan", 4) == 0) {
22 ret = nvme_scan_namespace();
23 if (ret)
24 return CMD_RET_FAILURE;
Zhikang Zhang0adc38b2017-08-03 02:30:59 -070025
Bin Mengfceadc12017-08-22 08:15:17 -070026 return ret;
Zhikang Zhang0adc38b2017-08-03 02:30:59 -070027 }
Bin Mengfceadc12017-08-22 08:15:17 -070028 if (strncmp(argv[1], "deta", 4) == 0) {
29 struct udevice *udev;
Zhikang Zhang0adc38b2017-08-03 02:30:59 -070030
Bin Mengfceadc12017-08-22 08:15:17 -070031 ret = blk_get_device(IF_TYPE_NVME, nvme_curr_dev,
32 &udev);
33 if (ret < 0)
34 return CMD_RET_FAILURE;
Zhikang Zhang0adc38b2017-08-03 02:30:59 -070035
Bin Mengfceadc12017-08-22 08:15:17 -070036 nvme_print_info(udev);
Zhikang Zhang0adc38b2017-08-03 02:30:59 -070037
Bin Mengfceadc12017-08-22 08:15:17 -070038 return ret;
Zhikang Zhang0adc38b2017-08-03 02:30:59 -070039 }
Zhikang Zhang0adc38b2017-08-03 02:30:59 -070040 }
41
Bin Mengfceadc12017-08-22 08:15:17 -070042 return blk_common_cmd(argc, argv, IF_TYPE_NVME, &nvme_curr_dev);
Zhikang Zhang0adc38b2017-08-03 02:30:59 -070043}
44
45U_BOOT_CMD(
Bin Mengfceadc12017-08-22 08:15:17 -070046 nvme, 8, 1, do_nvme,
Zhikang Zhang0adc38b2017-08-03 02:30:59 -070047 "NVM Express sub-system",
Bin Mengfceadc12017-08-22 08:15:17 -070048 "scan - scan NVMe devices\n"
49 "nvme detail - show details of current NVMe device\n"
50 "nvme info - show all available NVMe devices\n"
51 "nvme device [dev] - show or set current NVMe device\n"
52 "nvme part [dev] - print partition table of one or all NVMe devices\n"
53 "nvme read addr blk# cnt - read `cnt' blocks starting at block\n"
54 " `blk#' to memory address `addr'\n"
55 "nvme write addr blk# cnt - write `cnt' blocks starting at block\n"
56 " `blk#' from memory address `addr'"
Zhikang Zhang0adc38b2017-08-03 02:30:59 -070057);