Eugeniu Rosca | 35c34be | 2019-05-23 17:32:22 +0200 | [diff] [blame] | 1 | // 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 Rosca | 54a5548 | 2020-10-23 11:52:22 +0300 | [diff] [blame] | 9 | #include <bcb.h> |
Eugeniu Rosca | 35c34be | 2019-05-23 17:32:22 +0200 | [diff] [blame] | 10 | #include <command.h> |
| 11 | #include <common.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 12 | #include <log.h> |
Simon Glass | 655306c | 2020-05-10 11:39:58 -0600 | [diff] [blame] | 13 | #include <part.h> |
Eugeniu Rosca | 6005e93 | 2020-10-23 11:52:23 +0300 | [diff] [blame] | 14 | #include <malloc.h> |
Gary Bisson | f3f2c7b | 2022-01-11 18:06:06 +0100 | [diff] [blame] | 15 | #include <memalign.h> |
Eugeniu Rosca | 35c34be | 2019-05-23 17:32:22 +0200 | [diff] [blame] | 16 | |
| 17 | enum bcb_cmd { |
| 18 | BCB_CMD_LOAD, |
| 19 | BCB_CMD_FIELD_SET, |
| 20 | BCB_CMD_FIELD_CLEAR, |
| 21 | BCB_CMD_FIELD_TEST, |
| 22 | BCB_CMD_FIELD_DUMP, |
| 23 | BCB_CMD_STORE, |
| 24 | }; |
| 25 | |
| 26 | static int bcb_dev = -1; |
| 27 | static int bcb_part = -1; |
Gary Bisson | f3f2c7b | 2022-01-11 18:06:06 +0100 | [diff] [blame] | 28 | static struct bootloader_message bcb __aligned(ARCH_DMA_MINALIGN) = { { 0 } }; |
Eugeniu Rosca | 35c34be | 2019-05-23 17:32:22 +0200 | [diff] [blame] | 29 | |
| 30 | static int bcb_cmd_get(char *cmd) |
| 31 | { |
Eugeniu Rosca | 9bb6283 | 2019-07-19 23:26:13 +0200 | [diff] [blame] | 32 | if (!strcmp(cmd, "load")) |
Eugeniu Rosca | 35c34be | 2019-05-23 17:32:22 +0200 | [diff] [blame] | 33 | return BCB_CMD_LOAD; |
Eugeniu Rosca | 9bb6283 | 2019-07-19 23:26:13 +0200 | [diff] [blame] | 34 | if (!strcmp(cmd, "set")) |
Eugeniu Rosca | 35c34be | 2019-05-23 17:32:22 +0200 | [diff] [blame] | 35 | return BCB_CMD_FIELD_SET; |
Eugeniu Rosca | 9bb6283 | 2019-07-19 23:26:13 +0200 | [diff] [blame] | 36 | if (!strcmp(cmd, "clear")) |
Eugeniu Rosca | 35c34be | 2019-05-23 17:32:22 +0200 | [diff] [blame] | 37 | return BCB_CMD_FIELD_CLEAR; |
Eugeniu Rosca | 9bb6283 | 2019-07-19 23:26:13 +0200 | [diff] [blame] | 38 | if (!strcmp(cmd, "test")) |
Eugeniu Rosca | 35c34be | 2019-05-23 17:32:22 +0200 | [diff] [blame] | 39 | return BCB_CMD_FIELD_TEST; |
Eugeniu Rosca | 9bb6283 | 2019-07-19 23:26:13 +0200 | [diff] [blame] | 40 | if (!strcmp(cmd, "store")) |
Eugeniu Rosca | 35c34be | 2019-05-23 17:32:22 +0200 | [diff] [blame] | 41 | return BCB_CMD_STORE; |
Eugeniu Rosca | 9bb6283 | 2019-07-19 23:26:13 +0200 | [diff] [blame] | 42 | if (!strcmp(cmd, "dump")) |
Eugeniu Rosca | 35c34be | 2019-05-23 17:32:22 +0200 | [diff] [blame] | 43 | return BCB_CMD_FIELD_DUMP; |
| 44 | else |
| 45 | return -1; |
| 46 | } |
| 47 | |
| 48 | static int bcb_is_misused(int argc, char *const argv[]) |
| 49 | { |
| 50 | int cmd = bcb_cmd_get(argv[0]); |
| 51 | |
| 52 | switch (cmd) { |
| 53 | case BCB_CMD_LOAD: |
Eugeniu Rosca | 35c34be | 2019-05-23 17:32:22 +0200 | [diff] [blame] | 54 | case BCB_CMD_FIELD_SET: |
| 55 | if (argc != 3) |
| 56 | goto err; |
| 57 | break; |
| 58 | case BCB_CMD_FIELD_TEST: |
| 59 | if (argc != 4) |
| 60 | goto err; |
| 61 | break; |
| 62 | case BCB_CMD_FIELD_CLEAR: |
| 63 | if (argc != 1 && argc != 2) |
| 64 | goto err; |
| 65 | break; |
| 66 | case BCB_CMD_STORE: |
| 67 | if (argc != 1) |
| 68 | goto err; |
| 69 | break; |
| 70 | case BCB_CMD_FIELD_DUMP: |
| 71 | if (argc != 2) |
| 72 | goto err; |
| 73 | break; |
| 74 | default: |
| 75 | printf("Error: 'bcb %s' not supported\n", argv[0]); |
| 76 | return -1; |
| 77 | } |
| 78 | |
| 79 | if (cmd != BCB_CMD_LOAD && (bcb_dev < 0 || bcb_part < 0)) { |
| 80 | printf("Error: Please, load BCB first!\n"); |
| 81 | return -1; |
| 82 | } |
| 83 | |
| 84 | return 0; |
| 85 | err: |
| 86 | printf("Error: Bad usage of 'bcb %s'\n", argv[0]); |
| 87 | |
| 88 | return -1; |
| 89 | } |
| 90 | |
Eugeniu Rosca | cb10fc9 | 2019-07-19 23:26:14 +0200 | [diff] [blame] | 91 | static int bcb_field_get(char *name, char **fieldp, int *sizep) |
Eugeniu Rosca | 35c34be | 2019-05-23 17:32:22 +0200 | [diff] [blame] | 92 | { |
Eugeniu Rosca | 9bb6283 | 2019-07-19 23:26:13 +0200 | [diff] [blame] | 93 | if (!strcmp(name, "command")) { |
Eugeniu Rosca | cb10fc9 | 2019-07-19 23:26:14 +0200 | [diff] [blame] | 94 | *fieldp = bcb.command; |
| 95 | *sizep = sizeof(bcb.command); |
Eugeniu Rosca | 9bb6283 | 2019-07-19 23:26:13 +0200 | [diff] [blame] | 96 | } else if (!strcmp(name, "status")) { |
Eugeniu Rosca | cb10fc9 | 2019-07-19 23:26:14 +0200 | [diff] [blame] | 97 | *fieldp = bcb.status; |
| 98 | *sizep = sizeof(bcb.status); |
Eugeniu Rosca | 9bb6283 | 2019-07-19 23:26:13 +0200 | [diff] [blame] | 99 | } else if (!strcmp(name, "recovery")) { |
Eugeniu Rosca | cb10fc9 | 2019-07-19 23:26:14 +0200 | [diff] [blame] | 100 | *fieldp = bcb.recovery; |
| 101 | *sizep = sizeof(bcb.recovery); |
Eugeniu Rosca | 9bb6283 | 2019-07-19 23:26:13 +0200 | [diff] [blame] | 102 | } else if (!strcmp(name, "stage")) { |
Eugeniu Rosca | cb10fc9 | 2019-07-19 23:26:14 +0200 | [diff] [blame] | 103 | *fieldp = bcb.stage; |
| 104 | *sizep = sizeof(bcb.stage); |
Eugeniu Rosca | 9bb6283 | 2019-07-19 23:26:13 +0200 | [diff] [blame] | 105 | } else if (!strcmp(name, "reserved")) { |
Eugeniu Rosca | cb10fc9 | 2019-07-19 23:26:14 +0200 | [diff] [blame] | 106 | *fieldp = bcb.reserved; |
| 107 | *sizep = sizeof(bcb.reserved); |
Eugeniu Rosca | 35c34be | 2019-05-23 17:32:22 +0200 | [diff] [blame] | 108 | } else { |
| 109 | printf("Error: Unknown bcb field '%s'\n", name); |
| 110 | return -1; |
| 111 | } |
| 112 | |
| 113 | return 0; |
| 114 | } |
| 115 | |
Eugeniu Rosca | f308af5 | 2020-10-23 11:52:19 +0300 | [diff] [blame] | 116 | static int __bcb_load(int devnum, const char *partp) |
Eugeniu Rosca | 35c34be | 2019-05-23 17:32:22 +0200 | [diff] [blame] | 117 | { |
| 118 | struct blk_desc *desc; |
Simon Glass | c1c4a8f | 2020-05-10 11:39:57 -0600 | [diff] [blame] | 119 | struct disk_partition info; |
Eugeniu Rosca | 35c34be | 2019-05-23 17:32:22 +0200 | [diff] [blame] | 120 | u64 cnt; |
| 121 | char *endp; |
| 122 | int part, ret; |
| 123 | |
Eugeniu Rosca | f308af5 | 2020-10-23 11:52:19 +0300 | [diff] [blame] | 124 | desc = blk_get_devnum_by_type(IF_TYPE_MMC, devnum); |
| 125 | if (!desc) { |
| 126 | ret = -ENODEV; |
Eugeniu Rosca | cb10fc9 | 2019-07-19 23:26:14 +0200 | [diff] [blame] | 127 | goto err_read_fail; |
Eugeniu Rosca | f308af5 | 2020-10-23 11:52:19 +0300 | [diff] [blame] | 128 | } |
Eugeniu Rosca | 35c34be | 2019-05-23 17:32:22 +0200 | [diff] [blame] | 129 | |
Eugeniu Rosca | f308af5 | 2020-10-23 11:52:19 +0300 | [diff] [blame] | 130 | part = simple_strtoul(partp, &endp, 0); |
Eugeniu Rosca | 35c34be | 2019-05-23 17:32:22 +0200 | [diff] [blame] | 131 | if (*endp == '\0') { |
| 132 | ret = part_get_info(desc, part, &info); |
| 133 | if (ret) |
Eugeniu Rosca | cb10fc9 | 2019-07-19 23:26:14 +0200 | [diff] [blame] | 134 | goto err_read_fail; |
Eugeniu Rosca | 35c34be | 2019-05-23 17:32:22 +0200 | [diff] [blame] | 135 | } else { |
Eugeniu Rosca | f308af5 | 2020-10-23 11:52:19 +0300 | [diff] [blame] | 136 | part = part_get_info_by_name(desc, partp, &info); |
Eugeniu Rosca | 35c34be | 2019-05-23 17:32:22 +0200 | [diff] [blame] | 137 | if (part < 0) { |
| 138 | ret = part; |
Eugeniu Rosca | cb10fc9 | 2019-07-19 23:26:14 +0200 | [diff] [blame] | 139 | goto err_read_fail; |
Eugeniu Rosca | 35c34be | 2019-05-23 17:32:22 +0200 | [diff] [blame] | 140 | } |
| 141 | } |
| 142 | |
| 143 | cnt = DIV_ROUND_UP(sizeof(struct bootloader_message), info.blksz); |
| 144 | if (cnt > info.size) |
Eugeniu Rosca | cb10fc9 | 2019-07-19 23:26:14 +0200 | [diff] [blame] | 145 | goto err_too_small; |
Eugeniu Rosca | 35c34be | 2019-05-23 17:32:22 +0200 | [diff] [blame] | 146 | |
| 147 | if (blk_dread(desc, info.start, cnt, &bcb) != cnt) { |
| 148 | ret = -EIO; |
Eugeniu Rosca | cb10fc9 | 2019-07-19 23:26:14 +0200 | [diff] [blame] | 149 | goto err_read_fail; |
Eugeniu Rosca | 35c34be | 2019-05-23 17:32:22 +0200 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | bcb_dev = desc->devnum; |
| 153 | bcb_part = part; |
| 154 | debug("%s: Loaded from mmc %d:%d\n", __func__, bcb_dev, bcb_part); |
| 155 | |
| 156 | return CMD_RET_SUCCESS; |
Eugeniu Rosca | cb10fc9 | 2019-07-19 23:26:14 +0200 | [diff] [blame] | 157 | err_read_fail: |
Eugeniu Rosca | f308af5 | 2020-10-23 11:52:19 +0300 | [diff] [blame] | 158 | printf("Error: mmc %d:%s read failed (%d)\n", devnum, partp, ret); |
Eugeniu Rosca | 35c34be | 2019-05-23 17:32:22 +0200 | [diff] [blame] | 159 | goto err; |
Eugeniu Rosca | cb10fc9 | 2019-07-19 23:26:14 +0200 | [diff] [blame] | 160 | err_too_small: |
Eugeniu Rosca | f308af5 | 2020-10-23 11:52:19 +0300 | [diff] [blame] | 161 | printf("Error: mmc %d:%s too small!", devnum, partp); |
Eugeniu Rosca | 35c34be | 2019-05-23 17:32:22 +0200 | [diff] [blame] | 162 | goto err; |
| 163 | err: |
| 164 | bcb_dev = -1; |
| 165 | bcb_part = -1; |
| 166 | |
| 167 | return CMD_RET_FAILURE; |
| 168 | } |
| 169 | |
Eugeniu Rosca | f308af5 | 2020-10-23 11:52:19 +0300 | [diff] [blame] | 170 | static int do_bcb_load(struct cmd_tbl *cmdtp, int flag, int argc, |
| 171 | char * const argv[]) |
| 172 | { |
| 173 | char *endp; |
| 174 | int devnum = simple_strtoul(argv[1], &endp, 0); |
| 175 | |
| 176 | if (*endp != '\0') { |
| 177 | printf("Error: Device id '%s' not a number\n", argv[1]); |
| 178 | return CMD_RET_FAILURE; |
| 179 | } |
| 180 | |
| 181 | return __bcb_load(devnum, argv[2]); |
| 182 | } |
| 183 | |
Eugeniu Rosca | 6005e93 | 2020-10-23 11:52:23 +0300 | [diff] [blame] | 184 | static int __bcb_set(char *fieldp, const char *valp) |
Eugeniu Rosca | 35c34be | 2019-05-23 17:32:22 +0200 | [diff] [blame] | 185 | { |
| 186 | int size, len; |
Eugeniu Rosca | 6005e93 | 2020-10-23 11:52:23 +0300 | [diff] [blame] | 187 | char *field, *str, *found, *tmp; |
Eugeniu Rosca | 35c34be | 2019-05-23 17:32:22 +0200 | [diff] [blame] | 188 | |
Eugeniu Rosca | 92be544 | 2020-10-23 11:52:20 +0300 | [diff] [blame] | 189 | if (bcb_field_get(fieldp, &field, &size)) |
Eugeniu Rosca | 35c34be | 2019-05-23 17:32:22 +0200 | [diff] [blame] | 190 | return CMD_RET_FAILURE; |
| 191 | |
Eugeniu Rosca | 92be544 | 2020-10-23 11:52:20 +0300 | [diff] [blame] | 192 | len = strlen(valp); |
Eugeniu Rosca | 35c34be | 2019-05-23 17:32:22 +0200 | [diff] [blame] | 193 | if (len >= size) { |
| 194 | printf("Error: sizeof('%s') = %d >= %d = sizeof(bcb.%s)\n", |
Eugeniu Rosca | 92be544 | 2020-10-23 11:52:20 +0300 | [diff] [blame] | 195 | valp, len, size, fieldp); |
Eugeniu Rosca | 35c34be | 2019-05-23 17:32:22 +0200 | [diff] [blame] | 196 | return CMD_RET_FAILURE; |
| 197 | } |
Eugeniu Rosca | 6005e93 | 2020-10-23 11:52:23 +0300 | [diff] [blame] | 198 | str = strdup(valp); |
| 199 | if (!str) { |
| 200 | printf("Error: Out of memory while strdup\n"); |
| 201 | return CMD_RET_FAILURE; |
| 202 | } |
Eugeniu Rosca | 35c34be | 2019-05-23 17:32:22 +0200 | [diff] [blame] | 203 | |
Eugeniu Rosca | 6005e93 | 2020-10-23 11:52:23 +0300 | [diff] [blame] | 204 | tmp = str; |
Eugeniu Rosca | 35c34be | 2019-05-23 17:32:22 +0200 | [diff] [blame] | 205 | field[0] = '\0'; |
Eugeniu Rosca | 6005e93 | 2020-10-23 11:52:23 +0300 | [diff] [blame] | 206 | while ((found = strsep(&tmp, ":"))) { |
Eugeniu Rosca | 35c34be | 2019-05-23 17:32:22 +0200 | [diff] [blame] | 207 | if (field[0] != '\0') |
| 208 | strcat(field, "\n"); |
| 209 | strcat(field, found); |
| 210 | } |
Eugeniu Rosca | 6005e93 | 2020-10-23 11:52:23 +0300 | [diff] [blame] | 211 | free(str); |
Eugeniu Rosca | 35c34be | 2019-05-23 17:32:22 +0200 | [diff] [blame] | 212 | |
| 213 | return CMD_RET_SUCCESS; |
| 214 | } |
| 215 | |
Eugeniu Rosca | 92be544 | 2020-10-23 11:52:20 +0300 | [diff] [blame] | 216 | static int do_bcb_set(struct cmd_tbl *cmdtp, int flag, int argc, |
| 217 | char * const argv[]) |
| 218 | { |
| 219 | return __bcb_set(argv[1], argv[2]); |
| 220 | } |
| 221 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 222 | static int do_bcb_clear(struct cmd_tbl *cmdtp, int flag, int argc, |
| 223 | char *const argv[]) |
Eugeniu Rosca | 35c34be | 2019-05-23 17:32:22 +0200 | [diff] [blame] | 224 | { |
| 225 | int size; |
| 226 | char *field; |
| 227 | |
| 228 | 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 Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 241 | static int do_bcb_test(struct cmd_tbl *cmdtp, int flag, int argc, |
| 242 | char *const argv[]) |
Eugeniu Rosca | 35c34be | 2019-05-23 17:32:22 +0200 | [diff] [blame] | 243 | { |
| 244 | int size; |
| 245 | char *field; |
| 246 | char *op = argv[2]; |
| 247 | |
| 248 | if (bcb_field_get(argv[1], &field, &size)) |
| 249 | return CMD_RET_FAILURE; |
| 250 | |
| 251 | if (*op == '=' && *(op + 1) == '\0') { |
| 252 | if (!strncmp(argv[3], field, size)) |
| 253 | return CMD_RET_SUCCESS; |
| 254 | else |
| 255 | return CMD_RET_FAILURE; |
| 256 | } else if (*op == '~' && *(op + 1) == '\0') { |
| 257 | if (!strstr(field, argv[3])) |
| 258 | return CMD_RET_FAILURE; |
| 259 | else |
| 260 | return CMD_RET_SUCCESS; |
| 261 | } else { |
| 262 | printf("Error: Unknown operator '%s'\n", op); |
| 263 | } |
| 264 | |
| 265 | return CMD_RET_FAILURE; |
| 266 | } |
| 267 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 268 | static int do_bcb_dump(struct cmd_tbl *cmdtp, int flag, int argc, |
| 269 | char *const argv[]) |
Eugeniu Rosca | 35c34be | 2019-05-23 17:32:22 +0200 | [diff] [blame] | 270 | { |
| 271 | int size; |
| 272 | char *field; |
| 273 | |
| 274 | if (bcb_field_get(argv[1], &field, &size)) |
| 275 | return CMD_RET_FAILURE; |
| 276 | |
| 277 | print_buffer((ulong)field - (ulong)&bcb, (void *)field, 1, size, 16); |
| 278 | |
| 279 | return CMD_RET_SUCCESS; |
| 280 | } |
| 281 | |
Eugeniu Rosca | f6155bd | 2020-10-23 11:52:21 +0300 | [diff] [blame] | 282 | static int __bcb_store(void) |
Eugeniu Rosca | 35c34be | 2019-05-23 17:32:22 +0200 | [diff] [blame] | 283 | { |
| 284 | struct blk_desc *desc; |
Simon Glass | c1c4a8f | 2020-05-10 11:39:57 -0600 | [diff] [blame] | 285 | struct disk_partition info; |
Eugeniu Rosca | 35c34be | 2019-05-23 17:32:22 +0200 | [diff] [blame] | 286 | u64 cnt; |
| 287 | int ret; |
| 288 | |
| 289 | desc = blk_get_devnum_by_type(IF_TYPE_MMC, bcb_dev); |
| 290 | if (!desc) { |
| 291 | ret = -ENODEV; |
| 292 | goto err; |
| 293 | } |
| 294 | |
| 295 | ret = part_get_info(desc, bcb_part, &info); |
| 296 | if (ret) |
| 297 | goto err; |
| 298 | |
| 299 | cnt = DIV_ROUND_UP(sizeof(struct bootloader_message), info.blksz); |
| 300 | |
| 301 | if (blk_dwrite(desc, info.start, cnt, &bcb) != cnt) { |
| 302 | ret = -EIO; |
| 303 | goto err; |
| 304 | } |
| 305 | |
| 306 | return CMD_RET_SUCCESS; |
| 307 | err: |
| 308 | printf("Error: mmc %d:%d write failed (%d)\n", bcb_dev, bcb_part, ret); |
| 309 | |
| 310 | return CMD_RET_FAILURE; |
| 311 | } |
| 312 | |
Eugeniu Rosca | f6155bd | 2020-10-23 11:52:21 +0300 | [diff] [blame] | 313 | static int do_bcb_store(struct cmd_tbl *cmdtp, int flag, int argc, |
| 314 | char * const argv[]) |
| 315 | { |
| 316 | return __bcb_store(); |
| 317 | } |
| 318 | |
Eugeniu Rosca | 6005e93 | 2020-10-23 11:52:23 +0300 | [diff] [blame] | 319 | int bcb_write_reboot_reason(int devnum, char *partp, const char *reasonp) |
Eugeniu Rosca | 54a5548 | 2020-10-23 11:52:22 +0300 | [diff] [blame] | 320 | { |
| 321 | int ret; |
| 322 | |
| 323 | ret = __bcb_load(devnum, partp); |
| 324 | if (ret != CMD_RET_SUCCESS) |
| 325 | return ret; |
| 326 | |
| 327 | ret = __bcb_set("command", reasonp); |
| 328 | if (ret != CMD_RET_SUCCESS) |
| 329 | return ret; |
| 330 | |
| 331 | ret = __bcb_store(); |
| 332 | if (ret != CMD_RET_SUCCESS) |
| 333 | return ret; |
| 334 | |
| 335 | return 0; |
| 336 | } |
| 337 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 338 | static struct cmd_tbl cmd_bcb_sub[] = { |
Eugeniu Rosca | 35c34be | 2019-05-23 17:32:22 +0200 | [diff] [blame] | 339 | U_BOOT_CMD_MKENT(load, CONFIG_SYS_MAXARGS, 1, do_bcb_load, "", ""), |
| 340 | U_BOOT_CMD_MKENT(set, CONFIG_SYS_MAXARGS, 1, do_bcb_set, "", ""), |
| 341 | U_BOOT_CMD_MKENT(clear, CONFIG_SYS_MAXARGS, 1, do_bcb_clear, "", ""), |
| 342 | U_BOOT_CMD_MKENT(test, CONFIG_SYS_MAXARGS, 1, do_bcb_test, "", ""), |
| 343 | U_BOOT_CMD_MKENT(dump, CONFIG_SYS_MAXARGS, 1, do_bcb_dump, "", ""), |
| 344 | U_BOOT_CMD_MKENT(store, CONFIG_SYS_MAXARGS, 1, do_bcb_store, "", ""), |
| 345 | }; |
| 346 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 347 | static int do_bcb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
Eugeniu Rosca | 35c34be | 2019-05-23 17:32:22 +0200 | [diff] [blame] | 348 | { |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 349 | struct cmd_tbl *c; |
Eugeniu Rosca | 35c34be | 2019-05-23 17:32:22 +0200 | [diff] [blame] | 350 | |
| 351 | if (argc < 2) |
| 352 | return CMD_RET_USAGE; |
| 353 | |
| 354 | argc--; |
| 355 | argv++; |
| 356 | |
| 357 | c = find_cmd_tbl(argv[0], cmd_bcb_sub, ARRAY_SIZE(cmd_bcb_sub)); |
| 358 | if (!c) |
| 359 | return CMD_RET_USAGE; |
| 360 | |
| 361 | if (bcb_is_misused(argc, argv)) { |
Eugeniu Rosca | cb10fc9 | 2019-07-19 23:26:14 +0200 | [diff] [blame] | 362 | /* |
| 363 | * We try to improve the user experience by reporting the |
Eugeniu Rosca | 35c34be | 2019-05-23 17:32:22 +0200 | [diff] [blame] | 364 | * root-cause of misusage, so don't return CMD_RET_USAGE, |
| 365 | * since the latter prints out the full-blown help text |
| 366 | */ |
| 367 | return CMD_RET_FAILURE; |
| 368 | } |
| 369 | |
| 370 | return c->cmd(cmdtp, flag, argc, argv); |
| 371 | } |
| 372 | |
| 373 | U_BOOT_CMD( |
| 374 | bcb, CONFIG_SYS_MAXARGS, 1, do_bcb, |
| 375 | "Load/set/clear/test/dump/store Android BCB fields", |
| 376 | "load <dev> <part> - load BCB from mmc <dev>:<part>\n" |
| 377 | "bcb set <field> <val> - set BCB <field> to <val>\n" |
| 378 | "bcb clear [<field>] - clear BCB <field> or all fields\n" |
| 379 | "bcb test <field> <op> <val> - test BCB <field> against <val>\n" |
| 380 | "bcb dump <field> - dump BCB <field>\n" |
| 381 | "bcb store - store BCB back to mmc\n" |
| 382 | "\n" |
| 383 | "Legend:\n" |
| 384 | "<dev> - MMC device index containing the BCB partition\n" |
| 385 | "<part> - MMC partition index or name containing the BCB\n" |
| 386 | "<field> - one of {command,status,recovery,stage,reserved}\n" |
| 387 | "<op> - the binary operator used in 'bcb test':\n" |
| 388 | " '=' returns true if <val> matches the string stored in <field>\n" |
| 389 | " '~' returns true if <val> matches a subset of <field>'s string\n" |
| 390 | "<val> - string/text provided as input to bcb {set,test}\n" |
| 391 | " NOTE: any ':' character in <val> will be replaced by line feed\n" |
| 392 | " during 'bcb set' and used as separator by upper layers\n" |
| 393 | ); |