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