Commit 8607c4f127d0f2a6d2572960821443563f4eca51

Authored by Paul Kocialkowski
Committed by Tom Rini
1 parent a78f78ebeb

common: cmd_part: start and size sub-commands introduction

This introduces the part start and part size sub-commands. The purpose of these
is to store the start block and size of a partition in a variable, given the
device and partition number.

This allows reading raw data that fits a single partition more easily.
For instance, this could be used to figure out the start block and size of a
kernel partition when a partition table is present, given the partition number.

Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Acked-by: Stephen Warren <swarren@nvidia.com>
[trini: Change "%lx" to LBAF]
Signed-off-by: Tom Rini <trini@konsulko.com>

Showing 1 changed file with 77 additions and 1 deletions Side-by-side Diff

... ... @@ -112,6 +112,74 @@
112 112 return 0;
113 113 }
114 114  
  115 +static int do_part_start(int argc, char * const argv[])
  116 +{
  117 + block_dev_desc_t *desc;
  118 + disk_partition_t info;
  119 + char buf[512] = { 0 };
  120 + int part;
  121 + int err;
  122 + int ret;
  123 +
  124 + if (argc < 3)
  125 + return CMD_RET_USAGE;
  126 + if (argc > 4)
  127 + return CMD_RET_USAGE;
  128 +
  129 + part = simple_strtoul(argv[2], NULL, 0);
  130 +
  131 + ret = get_device(argv[0], argv[1], &desc);
  132 + if (ret < 0)
  133 + return 1;
  134 +
  135 + err = get_partition_info(desc, part, &info);
  136 + if (err)
  137 + return 1;
  138 +
  139 + snprintf(buf, sizeof(buf), LBAF, info.start);
  140 +
  141 + if (argc > 3)
  142 + setenv(argv[3], buf);
  143 + else
  144 + printf("%s\n", buf);
  145 +
  146 + return 0;
  147 +}
  148 +
  149 +static int do_part_size(int argc, char * const argv[])
  150 +{
  151 + block_dev_desc_t *desc;
  152 + disk_partition_t info;
  153 + char buf[512] = { 0 };
  154 + int part;
  155 + int err;
  156 + int ret;
  157 +
  158 + if (argc < 3)
  159 + return CMD_RET_USAGE;
  160 + if (argc > 4)
  161 + return CMD_RET_USAGE;
  162 +
  163 + part = simple_strtoul(argv[2], NULL, 0);
  164 +
  165 + ret = get_device(argv[0], argv[1], &desc);
  166 + if (ret < 0)
  167 + return 1;
  168 +
  169 + err = get_partition_info(desc, part, &info);
  170 + if (err)
  171 + return 1;
  172 +
  173 + snprintf(buf, sizeof(buf), LBAF, info.size);
  174 +
  175 + if (argc > 3)
  176 + setenv(argv[3], buf);
  177 + else
  178 + printf("%s\n", buf);
  179 +
  180 + return 0;
  181 +}
  182 +
115 183 static int do_part(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
116 184 {
117 185 if (argc < 2)
... ... @@ -121,6 +189,10 @@
121 189 return do_part_uuid(argc - 2, argv + 2);
122 190 else if (!strcmp(argv[1], "list"))
123 191 return do_part_list(argc - 2, argv + 2);
  192 + else if (!strcmp(argv[1], "start"))
  193 + return do_part_start(argc - 2, argv + 2);
  194 + else if (!strcmp(argv[1], "size"))
  195 + return do_part_size(argc - 2, argv + 2);
124 196  
125 197 return CMD_RET_USAGE;
126 198 }
... ... @@ -136,6 +208,10 @@
136 208 " - print a device's partition table\n"
137 209 "part list <interface> <dev> [flags] <varname>\n"
138 210 " - set environment variable to the list of partitions\n"
139   - " flags can be -bootable (list only bootable partitions)"
  211 + " flags can be -bootable (list only bootable partitions)\n"
  212 + "part start <interface> <dev> <part> <varname>\n"
  213 + " - set environment variable to the start of the partition (in blocks)\n"
  214 + "part size <interface> <dev> <part> <varname>\n"
  215 + " - set environment variable to the size of the partition (in blocks)"
140 216 );