1 /* 2 * Copyright (C) Copyright 2022 Rockchip Electronics Co., Ltd 3 * 4 * SPDX-License-Identifier: GPL-2.0+ 5 */ 6 7 #include <common.h> 8 #include <dm.h> 9 10 static int blk_curr_iftype; /* 0: IF_TYPE_UNKNOWN */ 11 static int blk_curr_dev = -1; 12 13 static int do_blk(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 14 { 15 int curr_iftype; 16 int curr_dev; 17 18 if (argc < 4) 19 return CMD_RET_USAGE; 20 21 if (!strcmp(argv[1], "dev") && argc == 4) { 22 curr_iftype = if_typename_to_iftype(argv[2]); 23 curr_dev = simple_strtoul(argv[3], NULL, 16); 24 if (!blk_show_device(curr_iftype, curr_dev)) { 25 blk_curr_iftype = curr_iftype; 26 blk_curr_dev = curr_dev; 27 printf("... is now current device\n"); 28 return CMD_RET_SUCCESS; 29 } else { 30 return CMD_RET_FAILURE; 31 } 32 } 33 34 if (!blk_curr_iftype || blk_curr_dev == -1) { 35 printf("Set the `blk dev <interface> <devnum>` before other command\n\n"); 36 return CMD_RET_USAGE; 37 } 38 39 return blk_common_cmd(argc, argv, blk_curr_iftype, &blk_curr_dev); 40 } 41 42 U_BOOT_CMD( 43 blk, 5, 1, do_blk, 44 "Block device sub-system", 45 "dev <interface> <devnum>\n" 46 "blk read <addr> <blk#> cnt\n" 47 "blk write <addr> <blk#> cnt\n" 48 "blk erase <blk#> cnt\n" 49 ); 50 51