blob: 16eabfe00f5a443f710e5084d187e374f89f6d3a [file] [log] [blame]
Eugeniu Rosca35c34be2019-05-23 17:32:22 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2019 Eugeniu Rosca <rosca.eugeniu@gmail.com>
4 *
5 * Command to read/modify/write Android BCB fields
6 */
7
8#include <android_bootloader_message.h>
Eugeniu Rosca54a55482020-10-23 11:52:22 +03009#include <bcb.h>
Eugeniu Rosca35c34be2019-05-23 17:32:22 +020010#include <command.h>
Dmitry Rokosovea143cb2024-10-17 17:12:08 +030011#include <android_ab.h>
Simon Glass1ab16922022-07-31 12:28:48 -060012#include <display_options.h>
Simon Glass0f2af882020-05-10 11:40:05 -060013#include <log.h>
Simon Glass655306c2020-05-10 11:39:58 -060014#include <part.h>
Eugeniu Rosca6005e932020-10-23 11:52:23 +030015#include <malloc.h>
Gary Bissonf3f2c7b2022-01-11 18:06:06 +010016#include <memalign.h>
Tom Rinidec7ea02024-05-20 13:35:03 -060017#include <vsprintf.h>
Mattijs Korpershoekcb254102022-10-13 14:25:59 +020018#include <linux/err.h>
Eugeniu Rosca35c34be2019-05-23 17:32:22 +020019
Dmitrii Merkurevacb22812023-11-10 05:59:55 +000020static const char * const fields[] = {
21 "command",
22 "status",
23 "recovery",
24 "stage"
25};
26
Gary Bissonf3f2c7b2022-01-11 18:06:06 +010027static struct bootloader_message bcb __aligned(ARCH_DMA_MINALIGN) = { { 0 } };
Dmitrii Merkurevacb22812023-11-10 05:59:55 +000028static struct disk_partition partition_data;
29
30static struct blk_desc *block;
31static struct disk_partition *partition = &partition_data;
Eugeniu Rosca35c34be2019-05-23 17:32:22 +020032
Dmitry Rokosov4adb34e2024-10-17 17:12:07 +030033static int bcb_not_loaded(void)
Eugeniu Rosca35c34be2019-05-23 17:32:22 +020034{
Dmitry Rokosov4adb34e2024-10-17 17:12:07 +030035 printf("Error: Please, load BCB first!\n");
Eugeniu Rosca35c34be2019-05-23 17:32:22 +020036 return -1;
37}
38
Dmitrii Merkurevacb22812023-11-10 05:59:55 +000039static int bcb_field_get(const char *name, char **fieldp, int *sizep)
Eugeniu Rosca35c34be2019-05-23 17:32:22 +020040{
Eugeniu Rosca9bb62832019-07-19 23:26:13 +020041 if (!strcmp(name, "command")) {
Eugeniu Roscacb10fc92019-07-19 23:26:14 +020042 *fieldp = bcb.command;
43 *sizep = sizeof(bcb.command);
Eugeniu Rosca9bb62832019-07-19 23:26:13 +020044 } else if (!strcmp(name, "status")) {
Eugeniu Roscacb10fc92019-07-19 23:26:14 +020045 *fieldp = bcb.status;
46 *sizep = sizeof(bcb.status);
Eugeniu Rosca9bb62832019-07-19 23:26:13 +020047 } else if (!strcmp(name, "recovery")) {
Eugeniu Roscacb10fc92019-07-19 23:26:14 +020048 *fieldp = bcb.recovery;
49 *sizep = sizeof(bcb.recovery);
Eugeniu Rosca9bb62832019-07-19 23:26:13 +020050 } else if (!strcmp(name, "stage")) {
Eugeniu Roscacb10fc92019-07-19 23:26:14 +020051 *fieldp = bcb.stage;
52 *sizep = sizeof(bcb.stage);
Eugeniu Rosca9bb62832019-07-19 23:26:13 +020053 } else if (!strcmp(name, "reserved")) {
Eugeniu Roscacb10fc92019-07-19 23:26:14 +020054 *fieldp = bcb.reserved;
55 *sizep = sizeof(bcb.reserved);
Eugeniu Rosca35c34be2019-05-23 17:32:22 +020056 } else {
57 printf("Error: Unknown bcb field '%s'\n", name);
58 return -1;
59 }
60
61 return 0;
62}
63
Dmitrii Merkurevacb22812023-11-10 05:59:55 +000064static void __bcb_reset(void)
Eugeniu Rosca35c34be2019-05-23 17:32:22 +020065{
Dmitrii Merkurevacb22812023-11-10 05:59:55 +000066 block = NULL;
67 partition = &partition_data;
68 memset(&partition_data, 0, sizeof(struct disk_partition));
69 memset(&bcb, 0, sizeof(struct bootloader_message));
70}
71
72static int __bcb_initialize(const char *iface, int devnum, const char *partp)
73{
Eugeniu Rosca35c34be2019-05-23 17:32:22 +020074 char *endp;
75 int part, ret;
76
Dmitrii Merkurevacb22812023-11-10 05:59:55 +000077 block = blk_get_dev(iface, devnum);
78 if (!block) {
Eugeniu Roscaf308af52020-10-23 11:52:19 +030079 ret = -ENODEV;
Eugeniu Roscacb10fc92019-07-19 23:26:14 +020080 goto err_read_fail;
Eugeniu Roscaf308af52020-10-23 11:52:19 +030081 }
Eugeniu Rosca35c34be2019-05-23 17:32:22 +020082
Mattijs Korpershoekcb254102022-10-13 14:25:59 +020083 /*
Dmitrii Merkurev927e2102023-11-10 05:59:54 +000084 * always select the first hwpart in case another
Mattijs Korpershoekcb254102022-10-13 14:25:59 +020085 * blk operation selected a different hwpart
86 */
Dmitrii Merkurevacb22812023-11-10 05:59:55 +000087 ret = blk_dselect_hwpart(block, 0);
Mattijs Korpershoekcb254102022-10-13 14:25:59 +020088 if (IS_ERR_VALUE(ret)) {
89 ret = -ENODEV;
90 goto err_read_fail;
91 }
92
Eugeniu Roscaf308af52020-10-23 11:52:19 +030093 part = simple_strtoul(partp, &endp, 0);
Eugeniu Rosca35c34be2019-05-23 17:32:22 +020094 if (*endp == '\0') {
Dmitrii Merkurevacb22812023-11-10 05:59:55 +000095 ret = part_get_info(block, part, partition);
Eugeniu Rosca35c34be2019-05-23 17:32:22 +020096 if (ret)
Eugeniu Roscacb10fc92019-07-19 23:26:14 +020097 goto err_read_fail;
Eugeniu Rosca35c34be2019-05-23 17:32:22 +020098 } else {
Dmitrii Merkurevacb22812023-11-10 05:59:55 +000099 part = part_get_info_by_name(block, partp, partition);
Eugeniu Rosca35c34be2019-05-23 17:32:22 +0200100 if (part < 0) {
101 ret = part;
Eugeniu Roscacb10fc92019-07-19 23:26:14 +0200102 goto err_read_fail;
Eugeniu Rosca35c34be2019-05-23 17:32:22 +0200103 }
104 }
105
Dmitrii Merkurevacb22812023-11-10 05:59:55 +0000106 return CMD_RET_SUCCESS;
107
108err_read_fail:
Mattijs Korpershoek35ec2972024-07-24 11:51:06 +0200109 printf("Error: %s %d:%s read failed (%d)\n", iface, devnum,
110 partition->name, ret);
Dmitrii Merkurevacb22812023-11-10 05:59:55 +0000111 __bcb_reset();
112 return CMD_RET_FAILURE;
113}
114
115static int __bcb_load(void)
116{
117 u64 cnt;
118 int ret;
119
120 cnt = DIV_ROUND_UP(sizeof(struct bootloader_message), partition->blksz);
121 if (cnt > partition->size)
Eugeniu Roscacb10fc92019-07-19 23:26:14 +0200122 goto err_too_small;
Eugeniu Rosca35c34be2019-05-23 17:32:22 +0200123
Dmitrii Merkurevacb22812023-11-10 05:59:55 +0000124 if (blk_dread(block, partition->start, cnt, &bcb) != cnt) {
Eugeniu Rosca35c34be2019-05-23 17:32:22 +0200125 ret = -EIO;
Eugeniu Roscacb10fc92019-07-19 23:26:14 +0200126 goto err_read_fail;
Eugeniu Rosca35c34be2019-05-23 17:32:22 +0200127 }
128
Dmitrii Merkurevacb22812023-11-10 05:59:55 +0000129 debug("%s: Loaded from %d %d:%s\n", __func__, block->uclass_id,
130 block->devnum, partition->name);
Eugeniu Rosca35c34be2019-05-23 17:32:22 +0200131
132 return CMD_RET_SUCCESS;
Eugeniu Roscacb10fc92019-07-19 23:26:14 +0200133err_read_fail:
Dmitrii Merkurevacb22812023-11-10 05:59:55 +0000134 printf("Error: %d %d:%s read failed (%d)\n", block->uclass_id,
135 block->devnum, partition->name, ret);
Eugeniu Rosca35c34be2019-05-23 17:32:22 +0200136 goto err;
Eugeniu Roscacb10fc92019-07-19 23:26:14 +0200137err_too_small:
Dmitrii Merkurevacb22812023-11-10 05:59:55 +0000138 printf("Error: %d %d:%s too small!", block->uclass_id,
139 block->devnum, partition->name);
Eugeniu Rosca35c34be2019-05-23 17:32:22 +0200140err:
Dmitrii Merkurevacb22812023-11-10 05:59:55 +0000141 __bcb_reset();
Eugeniu Rosca35c34be2019-05-23 17:32:22 +0200142 return CMD_RET_FAILURE;
143}
144
Eugeniu Roscaf308af52020-10-23 11:52:19 +0300145static int do_bcb_load(struct cmd_tbl *cmdtp, int flag, int argc,
146 char * const argv[])
147{
Dmitrii Merkurevacb22812023-11-10 05:59:55 +0000148 int ret;
Dmitrii Merkurev927e2102023-11-10 05:59:54 +0000149 int devnum;
Eugeniu Roscaf308af52020-10-23 11:52:19 +0300150 char *endp;
Dmitrii Merkurev927e2102023-11-10 05:59:54 +0000151 char *iface = "mmc";
Eugeniu Roscaf308af52020-10-23 11:52:19 +0300152
Dmitry Rokosov4adb34e2024-10-17 17:12:07 +0300153 if (argc < 3)
154 return CMD_RET_USAGE;
155
Dmitrii Merkurev927e2102023-11-10 05:59:54 +0000156 if (argc == 4) {
157 iface = argv[1];
158 argc--;
159 argv++;
160 }
161
162 devnum = simple_strtoul(argv[1], &endp, 0);
Eugeniu Roscaf308af52020-10-23 11:52:19 +0300163 if (*endp != '\0') {
164 printf("Error: Device id '%s' not a number\n", argv[1]);
165 return CMD_RET_FAILURE;
166 }
167
Dmitrii Merkurevacb22812023-11-10 05:59:55 +0000168 ret = __bcb_initialize(iface, devnum, argv[2]);
169 if (ret != CMD_RET_SUCCESS)
170 return ret;
171
172 return __bcb_load();
Eugeniu Roscaf308af52020-10-23 11:52:19 +0300173}
174
Dmitrii Merkurevacb22812023-11-10 05:59:55 +0000175static int __bcb_set(const char *fieldp, const char *valp)
Eugeniu Rosca35c34be2019-05-23 17:32:22 +0200176{
177 int size, len;
Eugeniu Rosca6005e932020-10-23 11:52:23 +0300178 char *field, *str, *found, *tmp;
Eugeniu Rosca35c34be2019-05-23 17:32:22 +0200179
Eugeniu Rosca92be5442020-10-23 11:52:20 +0300180 if (bcb_field_get(fieldp, &field, &size))
Eugeniu Rosca35c34be2019-05-23 17:32:22 +0200181 return CMD_RET_FAILURE;
182
Eugeniu Rosca92be5442020-10-23 11:52:20 +0300183 len = strlen(valp);
Eugeniu Rosca35c34be2019-05-23 17:32:22 +0200184 if (len >= size) {
185 printf("Error: sizeof('%s') = %d >= %d = sizeof(bcb.%s)\n",
Eugeniu Rosca92be5442020-10-23 11:52:20 +0300186 valp, len, size, fieldp);
Eugeniu Rosca35c34be2019-05-23 17:32:22 +0200187 return CMD_RET_FAILURE;
188 }
Eugeniu Rosca6005e932020-10-23 11:52:23 +0300189 str = strdup(valp);
190 if (!str) {
191 printf("Error: Out of memory while strdup\n");
192 return CMD_RET_FAILURE;
193 }
Eugeniu Rosca35c34be2019-05-23 17:32:22 +0200194
Eugeniu Rosca6005e932020-10-23 11:52:23 +0300195 tmp = str;
Eugeniu Rosca35c34be2019-05-23 17:32:22 +0200196 field[0] = '\0';
Eugeniu Rosca6005e932020-10-23 11:52:23 +0300197 while ((found = strsep(&tmp, ":"))) {
Eugeniu Rosca35c34be2019-05-23 17:32:22 +0200198 if (field[0] != '\0')
199 strcat(field, "\n");
200 strcat(field, found);
201 }
Eugeniu Rosca6005e932020-10-23 11:52:23 +0300202 free(str);
Eugeniu Rosca35c34be2019-05-23 17:32:22 +0200203
204 return CMD_RET_SUCCESS;
205}
206
Eugeniu Rosca92be5442020-10-23 11:52:20 +0300207static int do_bcb_set(struct cmd_tbl *cmdtp, int flag, int argc,
208 char * const argv[])
209{
Dmitry Rokosov4adb34e2024-10-17 17:12:07 +0300210 if (argc < 3)
211 return CMD_RET_USAGE;
212
213 if (!block)
214 return bcb_not_loaded();
215
Eugeniu Rosca92be5442020-10-23 11:52:20 +0300216 return __bcb_set(argv[1], argv[2]);
217}
218
Simon Glassed38aef2020-05-10 11:40:03 -0600219static int do_bcb_clear(struct cmd_tbl *cmdtp, int flag, int argc,
220 char *const argv[])
Eugeniu Rosca35c34be2019-05-23 17:32:22 +0200221{
222 int size;
223 char *field;
224
Dmitry Rokosov4adb34e2024-10-17 17:12:07 +0300225 if (!block)
226 return bcb_not_loaded();
227
Eugeniu Rosca35c34be2019-05-23 17:32:22 +0200228 if (argc == 1) {
229 memset(&bcb, 0, sizeof(bcb));
230 return CMD_RET_SUCCESS;
231 }
232
233 if (bcb_field_get(argv[1], &field, &size))
234 return CMD_RET_FAILURE;
235
236 memset(field, 0, size);
237
238 return CMD_RET_SUCCESS;
239}
240
Simon Glassed38aef2020-05-10 11:40:03 -0600241static int do_bcb_test(struct cmd_tbl *cmdtp, int flag, int argc,
242 char *const argv[])
Eugeniu Rosca35c34be2019-05-23 17:32:22 +0200243{
244 int size;
245 char *field;
Dmitry Rokosov4adb34e2024-10-17 17:12:07 +0300246 char *op;
247
248 if (argc < 4)
249 return CMD_RET_USAGE;
250
251 if (!block)
252 return bcb_not_loaded();
253
254 op = argv[2];
Eugeniu Rosca35c34be2019-05-23 17:32:22 +0200255
256 if (bcb_field_get(argv[1], &field, &size))
257 return CMD_RET_FAILURE;
258
259 if (*op == '=' && *(op + 1) == '\0') {
260 if (!strncmp(argv[3], field, size))
261 return CMD_RET_SUCCESS;
262 else
263 return CMD_RET_FAILURE;
264 } else if (*op == '~' && *(op + 1) == '\0') {
265 if (!strstr(field, argv[3]))
266 return CMD_RET_FAILURE;
267 else
268 return CMD_RET_SUCCESS;
269 } else {
270 printf("Error: Unknown operator '%s'\n", op);
271 }
272
273 return CMD_RET_FAILURE;
274}
275
Simon Glassed38aef2020-05-10 11:40:03 -0600276static int do_bcb_dump(struct cmd_tbl *cmdtp, int flag, int argc,
277 char *const argv[])
Eugeniu Rosca35c34be2019-05-23 17:32:22 +0200278{
279 int size;
280 char *field;
281
Dmitry Rokosov4adb34e2024-10-17 17:12:07 +0300282 if (argc < 2)
283 return CMD_RET_USAGE;
284
285 if (!block)
286 return bcb_not_loaded();
287
Eugeniu Rosca35c34be2019-05-23 17:32:22 +0200288 if (bcb_field_get(argv[1], &field, &size))
289 return CMD_RET_FAILURE;
290
291 print_buffer((ulong)field - (ulong)&bcb, (void *)field, 1, size, 16);
292
293 return CMD_RET_SUCCESS;
294}
295
Eugeniu Roscaf6155bd2020-10-23 11:52:21 +0300296static int __bcb_store(void)
Eugeniu Rosca35c34be2019-05-23 17:32:22 +0200297{
Eugeniu Rosca35c34be2019-05-23 17:32:22 +0200298 u64 cnt;
299 int ret;
300
Dmitrii Merkurevacb22812023-11-10 05:59:55 +0000301 cnt = DIV_ROUND_UP(sizeof(struct bootloader_message), partition->blksz);
Eugeniu Rosca35c34be2019-05-23 17:32:22 +0200302
Dmitrii Merkurevacb22812023-11-10 05:59:55 +0000303 if (blk_dwrite(block, partition->start, cnt, &bcb) != cnt) {
Eugeniu Rosca35c34be2019-05-23 17:32:22 +0200304 ret = -EIO;
305 goto err;
306 }
307
308 return CMD_RET_SUCCESS;
309err:
Dmitrii Merkurevacb22812023-11-10 05:59:55 +0000310 printf("Error: %d %d:%s write failed (%d)\n", block->uclass_id,
311 block->devnum, partition->name, ret);
Eugeniu Rosca35c34be2019-05-23 17:32:22 +0200312
313 return CMD_RET_FAILURE;
314}
315
Eugeniu Roscaf6155bd2020-10-23 11:52:21 +0300316static int do_bcb_store(struct cmd_tbl *cmdtp, int flag, int argc,
317 char * const argv[])
318{
Dmitry Rokosov4adb34e2024-10-17 17:12:07 +0300319 if (!block)
320 return bcb_not_loaded();
321
Eugeniu Roscaf6155bd2020-10-23 11:52:21 +0300322 return __bcb_store();
323}
324
Dmitrii Merkurevacb22812023-11-10 05:59:55 +0000325int bcb_find_partition_and_load(const char *iface, int devnum, char *partp)
Eugeniu Rosca54a55482020-10-23 11:52:22 +0300326{
327 int ret;
328
Dmitrii Merkurevacb22812023-11-10 05:59:55 +0000329 __bcb_reset();
Eugeniu Rosca54a55482020-10-23 11:52:22 +0300330
Dmitrii Merkurevacb22812023-11-10 05:59:55 +0000331 ret = __bcb_initialize(iface, devnum, partp);
Eugeniu Rosca54a55482020-10-23 11:52:22 +0300332 if (ret != CMD_RET_SUCCESS)
333 return ret;
334
Dmitrii Merkurevacb22812023-11-10 05:59:55 +0000335 return __bcb_load();
336}
Eugeniu Rosca54a55482020-10-23 11:52:22 +0300337
Dmitrii Merkurevacb22812023-11-10 05:59:55 +0000338int bcb_load(struct blk_desc *block_description, struct disk_partition *disk_partition)
339{
340 __bcb_reset();
341
342 block = block_description;
343 partition = disk_partition;
344
345 return __bcb_load();
346}
347
348int bcb_set(enum bcb_field field, const char *value)
349{
350 if (field > BCB_FIELD_STAGE)
351 return CMD_RET_FAILURE;
352 return __bcb_set(fields[field], value);
353}
354
355int bcb_get(enum bcb_field field, char *value_out, size_t value_size)
356{
357 int size;
358 char *field_value;
359
360 if (field > BCB_FIELD_STAGE)
361 return CMD_RET_FAILURE;
362 if (bcb_field_get(fields[field], &field_value, &size))
363 return CMD_RET_FAILURE;
364
365 strlcpy(value_out, field_value, value_size);
366
367 return CMD_RET_SUCCESS;
368}
369
370int bcb_store(void)
371{
372 return __bcb_store();
373}
374
375void bcb_reset(void)
376{
377 __bcb_reset();
Eugeniu Rosca54a55482020-10-23 11:52:22 +0300378}
379
Dmitry Rokosovea143cb2024-10-17 17:12:08 +0300380__maybe_unused static int do_bcb_ab_select(struct cmd_tbl *cmdtp,
381 int flag, int argc,
382 char * const argv[])
383{
384 int ret;
385 struct blk_desc *dev_desc;
386 struct disk_partition part_info;
387 char slot[2];
388 bool dec_tries = true;
389
390 if (argc < 4)
391 return CMD_RET_USAGE;
392
393 for (int i = 4; i < argc; i++) {
Dmitry Rokosov8cc305e2024-10-17 17:12:09 +0300394 if (!strcmp(argv[i], "--no-dec"))
Dmitry Rokosovea143cb2024-10-17 17:12:08 +0300395 dec_tries = false;
396 else
397 return CMD_RET_USAGE;
398 }
399
400 /* Lookup the "misc" partition from argv[2] and argv[3] */
401 if (part_get_info_by_dev_and_name_or_num(argv[2], argv[3],
402 &dev_desc, &part_info,
403 false) < 0) {
404 return CMD_RET_FAILURE;
405 }
406
407 ret = ab_select_slot(dev_desc, &part_info, dec_tries);
408 if (ret < 0) {
409 printf("Android boot failed, error %d.\n", ret);
410 return CMD_RET_FAILURE;
411 }
412
413 /* Android standard slot names are 'a', 'b', ... */
414 slot[0] = BOOT_SLOT_NAME(ret);
415 slot[1] = '\0';
416 env_set(argv[1], slot);
417 printf("ANDROID: Booting slot: %s\n", slot);
418
419 return CMD_RET_SUCCESS;
420}
421
Dmitry Rokosov52f93d32024-10-17 17:12:10 +0300422__maybe_unused static int do_bcb_ab_dump(struct cmd_tbl *cmdtp,
423 int flag, int argc,
424 char *const argv[])
425{
426 int ret;
427 struct blk_desc *dev_desc;
428 struct disk_partition part_info;
429
430 if (argc < 3)
431 return CMD_RET_USAGE;
432
433 if (part_get_info_by_dev_and_name_or_num(argv[1], argv[2],
434 &dev_desc, &part_info,
435 false) < 0) {
436 return CMD_RET_FAILURE;
437 }
438
439 ret = ab_dump_abc(dev_desc, &part_info);
440 if (ret < 0) {
441 printf("Cannot dump ABC data, error %d.\n", ret);
442 return CMD_RET_FAILURE;
443 }
444
445 return CMD_RET_SUCCESS;
446}
447
Dmitry Rokosov4adb34e2024-10-17 17:12:07 +0300448U_BOOT_LONGHELP(bcb,
Dmitrii Merkurev927e2102023-11-10 05:59:54 +0000449 "load <interface> <dev> <part> - load BCB from <interface> <dev>:<part>\n"
450 "load <dev> <part> - load BCB from mmc <dev>:<part>\n"
451 "bcb set <field> <val> - set BCB <field> to <val>\n"
452 "bcb clear [<field>] - clear BCB <field> or all fields\n"
453 "bcb test <field> <op> <val> - test BCB <field> against <val>\n"
454 "bcb dump <field> - dump BCB <field>\n"
455 "bcb store - store BCB back to <interface>\n"
Eugeniu Rosca35c34be2019-05-23 17:32:22 +0200456 "\n"
Dmitry Rokosovea143cb2024-10-17 17:12:08 +0300457#if IS_ENABLED(CONFIG_ANDROID_AB)
458 "bcb ab_select -\n"
459 " Select the slot used to boot from and register the boot attempt.\n"
460 " <slot_var_name> <interface> <dev[:part|#part_name]> [--no-dec]\n"
461 " - Load the slot metadata from the partition 'part' on\n"
462 " device type 'interface' instance 'dev' and store the active\n"
463 " slot in the 'slot_var_name' variable. This also updates the\n"
464 " Android slot metadata with a boot attempt, which can cause\n"
465 " successive calls to this function to return a different result\n"
466 " if the returned slot runs out of boot attempts.\n"
467 " - If 'part_name' is passed, preceded with a # instead of :, the\n"
468 " partition name whose label is 'part_name' will be looked up in\n"
469 " the partition table. This is commonly the \"misc\" partition.\n"
470 " - If '--no-dec' is set, the number of tries remaining will not\n"
471 " decremented for the selected boot slot\n"
472 "\n"
Dmitry Rokosov52f93d32024-10-17 17:12:10 +0300473 "bcb ab_dump -\n"
474 " Dump boot_control information from specific partition.\n"
475 " <interface> <dev[:part|#part_name]>\n"
476 "\n"
Dmitry Rokosovea143cb2024-10-17 17:12:08 +0300477#endif
Eugeniu Rosca35c34be2019-05-23 17:32:22 +0200478 "Legend:\n"
Dmitrii Merkurev927e2102023-11-10 05:59:54 +0000479 "<interface> - storage device interface (virtio, mmc, etc)\n"
480 "<dev> - storage device index containing the BCB partition\n"
481 "<part> - partition index or name containing the BCB\n"
482 "<field> - one of {command,status,recovery,stage,reserved}\n"
483 "<op> - the binary operator used in 'bcb test':\n"
484 " '=' returns true if <val> matches the string stored in <field>\n"
485 " '~' returns true if <val> matches a subset of <field>'s string\n"
486 "<val> - string/text provided as input to bcb {set,test}\n"
487 " NOTE: any ':' character in <val> will be replaced by line feed\n"
488 " during 'bcb set' and used as separator by upper layers\n"
Eugeniu Rosca35c34be2019-05-23 17:32:22 +0200489);
Dmitry Rokosov4adb34e2024-10-17 17:12:07 +0300490
491U_BOOT_CMD_WITH_SUBCMDS(bcb,
492 "Load/set/clear/test/dump/store Android BCB fields", bcb_help_text,
493 U_BOOT_SUBCMD_MKENT(load, 4, 1, do_bcb_load),
494 U_BOOT_SUBCMD_MKENT(set, 3, 1, do_bcb_set),
495 U_BOOT_SUBCMD_MKENT(clear, 2, 1, do_bcb_clear),
496 U_BOOT_SUBCMD_MKENT(test, 4, 1, do_bcb_test),
497 U_BOOT_SUBCMD_MKENT(dump, 2, 1, do_bcb_dump),
498 U_BOOT_SUBCMD_MKENT(store, 1, 1, do_bcb_store),
Dmitry Rokosovea143cb2024-10-17 17:12:08 +0300499#if IS_ENABLED(CONFIG_ANDROID_AB)
500 U_BOOT_SUBCMD_MKENT(ab_select, 5, 1, do_bcb_ab_select),
Dmitry Rokosov52f93d32024-10-17 17:12:10 +0300501 U_BOOT_SUBCMD_MKENT(ab_dump, 3, 1, do_bcb_ab_dump),
Dmitry Rokosovea143cb2024-10-17 17:12:08 +0300502#endif
Dmitry Rokosov4adb34e2024-10-17 17:12:07 +0300503);