1 // SPDX-License-Identifier: GPL-2.0+
3 * Handling of common block commands
5 * Copyright (c) 2017 Google, Inc
7 * (C) Copyright 2000-2011
8 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
14 int blk_common_cmd(int argc, char * const argv[], enum if_type if_type,
17 const char *if_name = blk_get_if_type_name(if_type);
24 if (strncmp(argv[1], "inf", 3) == 0) {
25 blk_list_devices(if_type);
27 } else if (strncmp(argv[1], "dev", 3) == 0) {
28 if (blk_print_device_num(if_type, *cur_devnump)) {
29 printf("\nno %s devices available\n", if_name);
30 return CMD_RET_FAILURE;
33 } else if (strncmp(argv[1], "part", 4) == 0) {
34 if (blk_list_part(if_type))
35 printf("\nno %s devices available\n", if_name);
40 if (strncmp(argv[1], "dev", 3) == 0) {
41 int dev = (int)simple_strtoul(argv[2], NULL, 10);
43 if (!blk_show_device(if_type, dev)) {
45 printf("... is now current device\n");
47 return CMD_RET_FAILURE;
50 } else if (strncmp(argv[1], "part", 4) == 0) {
51 int dev = (int)simple_strtoul(argv[2], NULL, 10);
53 if (blk_print_part_devnum(if_type, dev)) {
54 printf("\n%s device %d not available\n",
56 return CMD_RET_FAILURE;
62 default: /* at least 4 args */
63 if (strcmp(argv[1], "read") == 0) {
64 ulong addr = simple_strtoul(argv[2], NULL, 16);
65 lbaint_t blk = simple_strtoul(argv[3], NULL, 16);
66 ulong cnt = simple_strtoul(argv[4], NULL, 16);
69 printf("\n%s read: device %d block # "LBAFU", count %lu ... ",
70 if_name, *cur_devnump, blk, cnt);
72 n = blk_read_devnum(if_type, *cur_devnump, blk, cnt,
75 printf("%ld blocks read: %s\n", n,
76 n == cnt ? "OK" : "ERROR");
77 return n == cnt ? 0 : 1;
78 } else if (strcmp(argv[1], "write") == 0) {
79 ulong addr = simple_strtoul(argv[2], NULL, 16);
80 lbaint_t blk = simple_strtoul(argv[3], NULL, 16);
81 ulong cnt = simple_strtoul(argv[4], NULL, 16);
84 printf("\n%s write: device %d block # "LBAFU", count %lu ... ",
85 if_name, *cur_devnump, blk, cnt);
87 n = blk_write_devnum(if_type, *cur_devnump, blk, cnt,
90 printf("%ld blocks written: %s\n", n,
91 n == cnt ? "OK" : "ERROR");
92 return n == cnt ? 0 : 1;