blob: 8fbd48ee5a215d4887b22949461d24aba99e0a5b [file] [log] [blame]
Igor Opaniuk29cb8862024-02-09 20:20:40 +01001// SPDX-License-Identifier: GPL-2.0+
Igor Opaniuk60291192018-06-03 21:56:39 +03002/*
3 * (C) Copyright 2018, Linaro Limited
Igor Opaniuk60291192018-06-03 21:56:39 +03004 */
5
6#include <avb_verify.h>
7#include <command.h>
Simon Glass5e6201b2019-08-01 09:46:51 -06008#include <env.h>
Igor Opaniuk60291192018-06-03 21:56:39 +03009#include <image.h>
10#include <malloc.h>
11#include <mmc.h>
12
13#define AVB_BOOTARGS "avb_bootargs"
Igor Opaniuka4669d72024-02-09 20:20:42 +010014
Igor Opaniuk60291192018-06-03 21:56:39 +030015static struct AvbOps *avb_ops;
16
Simon Glassed38aef2020-05-10 11:40:03 -060017int do_avb_init(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Igor Opaniuk60291192018-06-03 21:56:39 +030018{
19 unsigned long mmc_dev;
20
21 if (argc != 2)
22 return CMD_RET_USAGE;
23
Simon Glass3ff49ec2021-07-24 09:03:29 -060024 mmc_dev = hextoul(argv[1], NULL);
Igor Opaniuk60291192018-06-03 21:56:39 +030025
26 if (avb_ops)
27 avb_ops_free(avb_ops);
28
29 avb_ops = avb_ops_alloc(mmc_dev);
30 if (avb_ops)
31 return CMD_RET_SUCCESS;
Igor Opaniuka4669d72024-02-09 20:20:42 +010032 else
33 printf("Can't allocate AvbOps");
Igor Opaniuk60291192018-06-03 21:56:39 +030034
Igor Opaniuka4669d72024-02-09 20:20:42 +010035 printf("Failed to initialize AVB\n");
Jens Wiklander6815afc2018-09-25 16:40:07 +020036
Igor Opaniuk60291192018-06-03 21:56:39 +030037 return CMD_RET_FAILURE;
38}
39
Simon Glassed38aef2020-05-10 11:40:03 -060040int do_avb_read_part(struct cmd_tbl *cmdtp, int flag, int argc,
41 char *const argv[])
Igor Opaniuk60291192018-06-03 21:56:39 +030042{
43 const char *part;
44 s64 offset;
45 size_t bytes, bytes_read = 0;
46 void *buffer;
Igor Opaniuka4669d72024-02-09 20:20:42 +010047 int ret;
Igor Opaniuk60291192018-06-03 21:56:39 +030048
49 if (!avb_ops) {
Igor Opaniuka4669d72024-02-09 20:20:42 +010050 printf("AVB is not initialized, please run 'avb init <id>'\n");
51 return CMD_RET_FAILURE;
Igor Opaniuk60291192018-06-03 21:56:39 +030052 }
53
54 if (argc != 5)
55 return CMD_RET_USAGE;
56
57 part = argv[1];
Simon Glass3ff49ec2021-07-24 09:03:29 -060058 offset = hextoul(argv[2], NULL);
59 bytes = hextoul(argv[3], NULL);
60 buffer = (void *)hextoul(argv[4], NULL);
Igor Opaniuk60291192018-06-03 21:56:39 +030061
Igor Opaniuka4669d72024-02-09 20:20:42 +010062 ret = avb_ops->read_from_partition(avb_ops, part, offset,
63 bytes, buffer, &bytes_read);
64 if (ret == AVB_IO_RESULT_OK) {
Igor Opaniuk60291192018-06-03 21:56:39 +030065 printf("Read %zu bytes\n", bytes_read);
66 return CMD_RET_SUCCESS;
67 }
68
Igor Opaniuka4669d72024-02-09 20:20:42 +010069 printf("Failed to read from partition '%s', err = %d\n",
70 part, ret);
Jens Wiklander6815afc2018-09-25 16:40:07 +020071
Igor Opaniuk60291192018-06-03 21:56:39 +030072 return CMD_RET_FAILURE;
73}
74
Simon Glassed38aef2020-05-10 11:40:03 -060075int do_avb_read_part_hex(struct cmd_tbl *cmdtp, int flag, int argc,
Igor Opaniuk60291192018-06-03 21:56:39 +030076 char *const argv[])
77{
78 const char *part;
79 s64 offset;
80 size_t bytes, bytes_read = 0;
81 char *buffer;
Igor Opaniuka4669d72024-02-09 20:20:42 +010082 int ret;
Igor Opaniuk60291192018-06-03 21:56:39 +030083
84 if (!avb_ops) {
Igor Opaniuka4669d72024-02-09 20:20:42 +010085 printf("AVB is not initialized, please run 'avb init <id>'\n");
86 return CMD_RET_FAILURE;
Igor Opaniuk60291192018-06-03 21:56:39 +030087 }
88
89 if (argc != 4)
90 return CMD_RET_USAGE;
91
92 part = argv[1];
Simon Glass3ff49ec2021-07-24 09:03:29 -060093 offset = hextoul(argv[2], NULL);
94 bytes = hextoul(argv[3], NULL);
Igor Opaniuk60291192018-06-03 21:56:39 +030095
96 buffer = malloc(bytes);
97 if (!buffer) {
98 printf("Failed to tlb_allocate buffer for data\n");
99 return CMD_RET_FAILURE;
100 }
101 memset(buffer, 0, bytes);
102
Igor Opaniuka4669d72024-02-09 20:20:42 +0100103 ret = avb_ops->read_from_partition(avb_ops, part, offset,
104 bytes, buffer, &bytes_read);
105 if (ret == AVB_IO_RESULT_OK) {
Igor Opaniuk60291192018-06-03 21:56:39 +0300106 printf("Requested %zu, read %zu bytes\n", bytes, bytes_read);
107 printf("Data: ");
108 for (int i = 0; i < bytes_read; i++)
109 printf("%02X", buffer[i]);
110
111 printf("\n");
112
113 free(buffer);
114 return CMD_RET_SUCCESS;
115 }
116
Igor Opaniuka4669d72024-02-09 20:20:42 +0100117 printf("Failed to read from partition '%s', err = %d\n",
118 part, ret);
Jens Wiklander6815afc2018-09-25 16:40:07 +0200119
Igor Opaniuk60291192018-06-03 21:56:39 +0300120 free(buffer);
121 return CMD_RET_FAILURE;
122}
123
Simon Glassed38aef2020-05-10 11:40:03 -0600124int do_avb_write_part(struct cmd_tbl *cmdtp, int flag, int argc,
125 char *const argv[])
Igor Opaniuk60291192018-06-03 21:56:39 +0300126{
127 const char *part;
128 s64 offset;
129 size_t bytes;
130 void *buffer;
Igor Opaniuka4669d72024-02-09 20:20:42 +0100131 int ret;
Igor Opaniuk60291192018-06-03 21:56:39 +0300132
133 if (!avb_ops) {
Igor Opaniuka4669d72024-02-09 20:20:42 +0100134 printf("AVB is not initialized, please run 'avb init <id>'\n");
Igor Opaniuk60291192018-06-03 21:56:39 +0300135 return CMD_RET_FAILURE;
136 }
137
138 if (argc != 5)
139 return CMD_RET_USAGE;
140
141 part = argv[1];
Simon Glass3ff49ec2021-07-24 09:03:29 -0600142 offset = hextoul(argv[2], NULL);
143 bytes = hextoul(argv[3], NULL);
144 buffer = (void *)hextoul(argv[4], NULL);
Igor Opaniuk60291192018-06-03 21:56:39 +0300145
Igor Opaniuka4669d72024-02-09 20:20:42 +0100146 ret = avb_ops->write_to_partition(avb_ops, part, offset,
147 bytes, buffer);
148 if (ret == AVB_IO_RESULT_OK) {
Igor Opaniuk60291192018-06-03 21:56:39 +0300149 printf("Wrote %zu bytes\n", bytes);
150 return CMD_RET_SUCCESS;
151 }
152
Igor Opaniuka4669d72024-02-09 20:20:42 +0100153 printf("Failed to write in partition '%s', err = %d\n",
154 part, ret);
Jens Wiklander6815afc2018-09-25 16:40:07 +0200155
Igor Opaniuk60291192018-06-03 21:56:39 +0300156 return CMD_RET_FAILURE;
157}
158
Simon Glassed38aef2020-05-10 11:40:03 -0600159int do_avb_read_rb(struct cmd_tbl *cmdtp, int flag, int argc,
160 char *const argv[])
Igor Opaniuk60291192018-06-03 21:56:39 +0300161{
162 size_t index;
163 u64 rb_idx;
Igor Opaniuka4669d72024-02-09 20:20:42 +0100164 int ret;
Igor Opaniuk60291192018-06-03 21:56:39 +0300165
166 if (!avb_ops) {
Igor Opaniuka4669d72024-02-09 20:20:42 +0100167 printf("AVB is not initialized, please run 'avb init <id>'\n");
Igor Opaniuk60291192018-06-03 21:56:39 +0300168 return CMD_RET_FAILURE;
169 }
170
171 if (argc != 2)
172 return CMD_RET_USAGE;
173
Simon Glass3ff49ec2021-07-24 09:03:29 -0600174 index = (size_t)hextoul(argv[1], NULL);
Igor Opaniuk60291192018-06-03 21:56:39 +0300175
Igor Opaniuka4669d72024-02-09 20:20:42 +0100176 ret = avb_ops->read_rollback_index(avb_ops, index, &rb_idx);
177 if (ret == AVB_IO_RESULT_OK) {
Jens Wiklander5f51dcc2018-09-25 16:40:06 +0200178 printf("Rollback index: %llx\n", rb_idx);
Igor Opaniuk60291192018-06-03 21:56:39 +0300179 return CMD_RET_SUCCESS;
180 }
Jens Wiklander6815afc2018-09-25 16:40:07 +0200181
Igor Opaniuka4669d72024-02-09 20:20:42 +0100182 printf("Failed to read rollback index id = %zu, err = %d\n",
183 index, ret);
Jens Wiklander6815afc2018-09-25 16:40:07 +0200184
Igor Opaniuk60291192018-06-03 21:56:39 +0300185 return CMD_RET_FAILURE;
186}
187
Simon Glassed38aef2020-05-10 11:40:03 -0600188int do_avb_write_rb(struct cmd_tbl *cmdtp, int flag, int argc,
189 char *const argv[])
Igor Opaniuk60291192018-06-03 21:56:39 +0300190{
191 size_t index;
192 u64 rb_idx;
Igor Opaniuka4669d72024-02-09 20:20:42 +0100193 int ret;
Igor Opaniuk60291192018-06-03 21:56:39 +0300194
195 if (!avb_ops) {
Igor Opaniuka4669d72024-02-09 20:20:42 +0100196 printf("AVB is not initialized, please run 'avb init <id>'\n");
Igor Opaniuk60291192018-06-03 21:56:39 +0300197 return CMD_RET_FAILURE;
198 }
199
200 if (argc != 3)
201 return CMD_RET_USAGE;
202
Simon Glass3ff49ec2021-07-24 09:03:29 -0600203 index = (size_t)hextoul(argv[1], NULL);
204 rb_idx = hextoul(argv[2], NULL);
Igor Opaniuk60291192018-06-03 21:56:39 +0300205
Igor Opaniuka4669d72024-02-09 20:20:42 +0100206 ret = avb_ops->write_rollback_index(avb_ops, index, rb_idx);
207 if (ret == AVB_IO_RESULT_OK)
Igor Opaniuk60291192018-06-03 21:56:39 +0300208 return CMD_RET_SUCCESS;
209
Igor Opaniuka4669d72024-02-09 20:20:42 +0100210 printf("Failed to write rollback index id = %zu, err = %d\n",
211 index, ret);
Jens Wiklander6815afc2018-09-25 16:40:07 +0200212
Igor Opaniuk60291192018-06-03 21:56:39 +0300213 return CMD_RET_FAILURE;
214}
215
Simon Glassed38aef2020-05-10 11:40:03 -0600216int do_avb_get_uuid(struct cmd_tbl *cmdtp, int flag,
217 int argc, char *const argv[])
Igor Opaniuk60291192018-06-03 21:56:39 +0300218{
219 const char *part;
220 char buffer[UUID_STR_LEN + 1];
Igor Opaniuka4669d72024-02-09 20:20:42 +0100221 int ret;
Igor Opaniuk60291192018-06-03 21:56:39 +0300222
223 if (!avb_ops) {
Igor Opaniuka4669d72024-02-09 20:20:42 +0100224 printf("AVB is not initialized, please run 'avb init <id>'\n");
Igor Opaniuk60291192018-06-03 21:56:39 +0300225 return CMD_RET_FAILURE;
226 }
227
228 if (argc != 2)
229 return CMD_RET_USAGE;
230
231 part = argv[1];
232
Igor Opaniuka4669d72024-02-09 20:20:42 +0100233 ret = avb_ops->get_unique_guid_for_partition(avb_ops, part,
234 buffer,
235 UUID_STR_LEN + 1);
236 if (ret == AVB_IO_RESULT_OK) {
Igor Opaniuk60291192018-06-03 21:56:39 +0300237 printf("'%s' UUID: %s\n", part, buffer);
238 return CMD_RET_SUCCESS;
239 }
240
Igor Opaniuka4669d72024-02-09 20:20:42 +0100241 printf("Failed to read partition '%s' UUID, err = %d\n",
242 part, ret);
Jens Wiklander6815afc2018-09-25 16:40:07 +0200243
Igor Opaniuk60291192018-06-03 21:56:39 +0300244 return CMD_RET_FAILURE;
245}
246
Simon Glassed38aef2020-05-10 11:40:03 -0600247int do_avb_verify_part(struct cmd_tbl *cmdtp, int flag,
Igor Opaniuk60291192018-06-03 21:56:39 +0300248 int argc, char *const argv[])
249{
Sam Protsenkoac80a982019-08-15 20:49:47 +0300250 const char * const requested_partitions[] = {"boot", NULL};
Igor Opaniuk60291192018-06-03 21:56:39 +0300251 AvbSlotVerifyResult slot_result;
252 AvbSlotVerifyData *out_data;
Igor Opaniukd2e83e22024-02-09 20:20:44 +0100253 enum avb_boot_state boot_state;
Igor Opaniukf0f3bfe2018-06-03 21:56:40 +0300254 char *cmdline;
255 char *extra_args;
Sam Protsenkof6b91bf2019-10-21 13:55:16 +0300256 char *slot_suffix = "";
Igor Opaniuka4669d72024-02-09 20:20:42 +0100257 int ret;
Igor Opaniuk60291192018-06-03 21:56:39 +0300258
259 bool unlocked = false;
260 int res = CMD_RET_FAILURE;
261
262 if (!avb_ops) {
Igor Opaniuka4669d72024-02-09 20:20:42 +0100263 printf("AVB is not initialized, please run 'avb init <id>'\n");
Igor Opaniuk60291192018-06-03 21:56:39 +0300264 return CMD_RET_FAILURE;
265 }
266
Sam Protsenkof6b91bf2019-10-21 13:55:16 +0300267 if (argc < 1 || argc > 2)
Igor Opaniuk60291192018-06-03 21:56:39 +0300268 return CMD_RET_USAGE;
269
Sam Protsenkof6b91bf2019-10-21 13:55:16 +0300270 if (argc == 2)
271 slot_suffix = argv[1];
272
Igor Opaniuk60291192018-06-03 21:56:39 +0300273 printf("## Android Verified Boot 2.0 version %s\n",
274 avb_version_string());
275
Igor Opaniuka4669d72024-02-09 20:20:42 +0100276 ret = avb_ops->read_is_device_unlocked(avb_ops, &unlocked);
277 if (ret != AVB_IO_RESULT_OK) {
278 printf("Can't determine device lock state, err = %d\n",
279 ret);
Igor Opaniuk60291192018-06-03 21:56:39 +0300280 return CMD_RET_FAILURE;
281 }
282
283 slot_result =
284 avb_slot_verify(avb_ops,
285 requested_partitions,
Sam Protsenkof6b91bf2019-10-21 13:55:16 +0300286 slot_suffix,
Igor Opaniuk60291192018-06-03 21:56:39 +0300287 unlocked,
288 AVB_HASHTREE_ERROR_MODE_RESTART_AND_INVALIDATE,
289 &out_data);
290
Igor Opaniukd2e83e22024-02-09 20:20:44 +0100291 /*
292 * LOCKED devices with custom root of trust setup is not supported (YELLOW)
293 */
294 if (slot_result == AVB_SLOT_VERIFY_RESULT_OK) {
Igor Opaniuk60291192018-06-03 21:56:39 +0300295 printf("Verification passed successfully\n");
296
Igor Opaniukd2e83e22024-02-09 20:20:44 +0100297 /*
298 * ORANGE state indicates that device may be freely modified.
299 * Device integrity is left to the user to verify out-of-band.
300 */
301 if (unlocked)
302 boot_state = AVB_ORANGE;
303 else
304 boot_state = AVB_GREEN;
Igor Opaniukf0f3bfe2018-06-03 21:56:40 +0300305
Igor Opaniukd2e83e22024-02-09 20:20:44 +0100306 /* export boot state to AVB_BOOTARGS env var */
307 extra_args = avb_set_state(avb_ops, boot_state);
Igor Opaniukf0f3bfe2018-06-03 21:56:40 +0300308 if (extra_args)
309 cmdline = append_cmd_line(out_data->cmdline,
310 extra_args);
311 else
312 cmdline = out_data->cmdline;
313
314 env_set(AVB_BOOTARGS, cmdline);
Igor Opaniuk60291192018-06-03 21:56:39 +0300315
316 res = CMD_RET_SUCCESS;
Igor Opaniukd2e83e22024-02-09 20:20:44 +0100317 } else {
318 printf("Verification failed, reason: %s\n", str_avb_slot_error(slot_result));
Igor Opaniuk60291192018-06-03 21:56:39 +0300319 }
320
Gary Bissonb12df3a2020-05-11 12:11:53 +0200321 if (out_data)
322 avb_slot_verify_data_free(out_data);
323
Igor Opaniuk60291192018-06-03 21:56:39 +0300324 return res;
325}
326
Simon Glassed38aef2020-05-10 11:40:03 -0600327int do_avb_is_unlocked(struct cmd_tbl *cmdtp, int flag,
328 int argc, char *const argv[])
Igor Opaniuk60291192018-06-03 21:56:39 +0300329{
330 bool unlock;
Igor Opaniuka4669d72024-02-09 20:20:42 +0100331 int ret;
Igor Opaniuk60291192018-06-03 21:56:39 +0300332
333 if (!avb_ops) {
Igor Opaniuka4669d72024-02-09 20:20:42 +0100334 printf("AVB is not initialized, please run 'avb init <id>'\n");
Igor Opaniuk60291192018-06-03 21:56:39 +0300335 return CMD_RET_FAILURE;
336 }
337
338 if (argc != 1) {
339 printf("--%s(-1)\n", __func__);
340 return CMD_RET_USAGE;
341 }
342
Igor Opaniuka4669d72024-02-09 20:20:42 +0100343 ret = avb_ops->read_is_device_unlocked(avb_ops, &unlock);
344 if (ret == AVB_IO_RESULT_OK) {
Igor Opaniuk60291192018-06-03 21:56:39 +0300345 printf("Unlocked = %d\n", unlock);
346 return CMD_RET_SUCCESS;
347 }
348
Igor Opaniuka4669d72024-02-09 20:20:42 +0100349 printf("Can't determine device lock state, err = %d\n",
350 ret);
Jens Wiklander6815afc2018-09-25 16:40:07 +0200351
Igor Opaniuk60291192018-06-03 21:56:39 +0300352 return CMD_RET_FAILURE;
353}
354
Simon Glassed38aef2020-05-10 11:40:03 -0600355int do_avb_read_pvalue(struct cmd_tbl *cmdtp, int flag, int argc,
356 char *const argv[])
Igor Opaniuk78b0b9d2019-04-09 15:38:14 +0200357{
358 const char *name;
359 size_t bytes;
360 size_t bytes_read;
361 void *buffer;
362 char *endp;
Igor Opaniuka4669d72024-02-09 20:20:42 +0100363 int ret;
Igor Opaniuk78b0b9d2019-04-09 15:38:14 +0200364
365 if (!avb_ops) {
Igor Opaniuka4669d72024-02-09 20:20:42 +0100366 printf("AVB is not initialized, please run 'avb init <id>'\n");
Igor Opaniuk78b0b9d2019-04-09 15:38:14 +0200367 return CMD_RET_FAILURE;
368 }
369
370 if (argc != 3)
371 return CMD_RET_USAGE;
372
373 name = argv[1];
Simon Glassff9b9032021-07-24 09:03:30 -0600374 bytes = dectoul(argv[2], &endp);
Igor Opaniuk78b0b9d2019-04-09 15:38:14 +0200375 if (*endp && *endp != '\n')
376 return CMD_RET_USAGE;
377
378 buffer = malloc(bytes);
379 if (!buffer)
380 return CMD_RET_FAILURE;
381
Igor Opaniuka4669d72024-02-09 20:20:42 +0100382 ret = avb_ops->read_persistent_value(avb_ops, name, bytes,
383 buffer, &bytes_read);
384 if (ret == AVB_IO_RESULT_OK) {
Sam Protsenko69543512019-07-31 19:59:09 +0300385 printf("Read %zu bytes, value = %s\n", bytes_read,
Igor Opaniuk78b0b9d2019-04-09 15:38:14 +0200386 (char *)buffer);
387 free(buffer);
388 return CMD_RET_SUCCESS;
389 }
390
Igor Opaniuka4669d72024-02-09 20:20:42 +0100391 printf("Failed to read persistent value, err = %d\n", ret);
Igor Opaniuk78b0b9d2019-04-09 15:38:14 +0200392
393 free(buffer);
394
395 return CMD_RET_FAILURE;
396}
397
Simon Glassed38aef2020-05-10 11:40:03 -0600398int do_avb_write_pvalue(struct cmd_tbl *cmdtp, int flag, int argc,
399 char *const argv[])
Igor Opaniuk78b0b9d2019-04-09 15:38:14 +0200400{
401 const char *name;
402 const char *value;
Igor Opaniuka4669d72024-02-09 20:20:42 +0100403 int ret;
Igor Opaniuk78b0b9d2019-04-09 15:38:14 +0200404
405 if (!avb_ops) {
Igor Opaniuka4669d72024-02-09 20:20:42 +0100406 printf("AVB is not initialized, please run 'avb init <id>'\n");
Igor Opaniuk78b0b9d2019-04-09 15:38:14 +0200407 return CMD_RET_FAILURE;
408 }
409
410 if (argc != 3)
411 return CMD_RET_USAGE;
412
413 name = argv[1];
414 value = argv[2];
415
Igor Opaniuka4669d72024-02-09 20:20:42 +0100416 ret = avb_ops->write_persistent_value(avb_ops, name,
417 strlen(value) + 1,
418 (const uint8_t *)value);
419 if (ret == AVB_IO_RESULT_OK) {
Sam Protsenko69543512019-07-31 19:59:09 +0300420 printf("Wrote %zu bytes\n", strlen(value) + 1);
Igor Opaniuk78b0b9d2019-04-09 15:38:14 +0200421 return CMD_RET_SUCCESS;
422 }
423
Igor Opaniuka4669d72024-02-09 20:20:42 +0100424 printf("Failed to write persistent value `%s` = `%s`, err = %d\n",
425 name, value, ret);
Igor Opaniuk78b0b9d2019-04-09 15:38:14 +0200426
427 return CMD_RET_FAILURE;
428}
429
Simon Glassed38aef2020-05-10 11:40:03 -0600430static struct cmd_tbl cmd_avb[] = {
Igor Opaniuk60291192018-06-03 21:56:39 +0300431 U_BOOT_CMD_MKENT(init, 2, 0, do_avb_init, "", ""),
432 U_BOOT_CMD_MKENT(read_rb, 2, 0, do_avb_read_rb, "", ""),
433 U_BOOT_CMD_MKENT(write_rb, 3, 0, do_avb_write_rb, "", ""),
434 U_BOOT_CMD_MKENT(is_unlocked, 1, 0, do_avb_is_unlocked, "", ""),
435 U_BOOT_CMD_MKENT(get_uuid, 2, 0, do_avb_get_uuid, "", ""),
436 U_BOOT_CMD_MKENT(read_part, 5, 0, do_avb_read_part, "", ""),
437 U_BOOT_CMD_MKENT(read_part_hex, 4, 0, do_avb_read_part_hex, "", ""),
438 U_BOOT_CMD_MKENT(write_part, 5, 0, do_avb_write_part, "", ""),
Sam Protsenkof6b91bf2019-10-21 13:55:16 +0300439 U_BOOT_CMD_MKENT(verify, 2, 0, do_avb_verify_part, "", ""),
Igor Opaniuk78b0b9d2019-04-09 15:38:14 +0200440#ifdef CONFIG_OPTEE_TA_AVB
441 U_BOOT_CMD_MKENT(read_pvalue, 3, 0, do_avb_read_pvalue, "", ""),
442 U_BOOT_CMD_MKENT(write_pvalue, 3, 0, do_avb_write_pvalue, "", ""),
443#endif
Igor Opaniuk60291192018-06-03 21:56:39 +0300444};
445
Simon Glassed38aef2020-05-10 11:40:03 -0600446static int do_avb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Igor Opaniuk60291192018-06-03 21:56:39 +0300447{
Simon Glassed38aef2020-05-10 11:40:03 -0600448 struct cmd_tbl *cp;
Igor Opaniuk60291192018-06-03 21:56:39 +0300449
450 cp = find_cmd_tbl(argv[1], cmd_avb, ARRAY_SIZE(cmd_avb));
451
452 argc--;
453 argv++;
454
455 if (!cp || argc > cp->maxargs)
456 return CMD_RET_USAGE;
457
458 if (flag == CMD_FLAG_REPEAT)
459 return CMD_RET_FAILURE;
460
461 return cp->cmd(cmdtp, flag, argc, argv);
462}
463
464U_BOOT_CMD(
465 avb, 29, 0, do_avb,
466 "Provides commands for testing Android Verified Boot 2.0 functionality",
467 "init <dev> - initialize avb2 for <dev>\n"
468 "avb read_rb <num> - read rollback index at location <num>\n"
469 "avb write_rb <num> <rb> - write rollback index <rb> to <num>\n"
470 "avb is_unlocked - returns unlock status of the device\n"
471 "avb get_uuid <partname> - read and print uuid of partition <part>\n"
472 "avb read_part <partname> <offset> <num> <addr> - read <num> bytes from\n"
473 " partition <partname> to buffer <addr>\n"
474 "avb read_part_hex <partname> <offset> <num> - read <num> bytes from\n"
475 " partition <partname> and print to stdout\n"
476 "avb write_part <partname> <offset> <num> <addr> - write <num> bytes to\n"
477 " <partname> by <offset> using data from <addr>\n"
Igor Opaniuk78b0b9d2019-04-09 15:38:14 +0200478#ifdef CONFIG_OPTEE_TA_AVB
479 "avb read_pvalue <name> <bytes> - read a persistent value <name>\n"
480 "avb write_pvalue <name> <value> - write a persistent value <name>\n"
481#endif
Sam Protsenkof6b91bf2019-10-21 13:55:16 +0300482 "avb verify [slot_suffix] - run verification process using hash data\n"
Igor Opaniuk60291192018-06-03 21:56:39 +0300483 " from vbmeta structure\n"
Sam Protsenkof6b91bf2019-10-21 13:55:16 +0300484 " [slot_suffix] - _a, _b, etc (if vbmeta partition is slotted)\n"
Igor Opaniuk60291192018-06-03 21:56:39 +0300485 );