mirror of
https://xff.cz/git/u-boot/
synced 2025-09-03 09:42:22 +02:00
avb: add support for named persistent values
AVB 2.0 spec. revision 1.1 introduces support for named persistent values that must be tamper evident and allows AVB to store arbitrary key-value pairs [1]. Introduce implementation of two additional AVB operations read_persistent_value()/write_persistent_value() for retrieving/storing named persistent values. Correspondent pull request in the OP-TEE OS project repo [2]. [1]: https://android.googlesource.com/platform/external/avb/+/android-9.0.0_r22 [2]: https://github.com/OP-TEE/optee_os/pull/2699 Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org> Signed-off-by: Igor Opaniuk <igor.opaniuk@gmail.com>
This commit is contained in:
78
cmd/avb.c
78
cmd/avb.c
@@ -340,6 +340,76 @@ int do_avb_is_unlocked(cmd_tbl_t *cmdtp, int flag,
|
||||
return CMD_RET_FAILURE;
|
||||
}
|
||||
|
||||
int do_avb_read_pvalue(cmd_tbl_t *cmdtp, int flag, int argc,
|
||||
char * const argv[])
|
||||
{
|
||||
const char *name;
|
||||
size_t bytes;
|
||||
size_t bytes_read;
|
||||
void *buffer;
|
||||
char *endp;
|
||||
|
||||
if (!avb_ops) {
|
||||
printf("AVB 2.0 is not initialized, run 'avb init' first\n");
|
||||
return CMD_RET_FAILURE;
|
||||
}
|
||||
|
||||
if (argc != 3)
|
||||
return CMD_RET_USAGE;
|
||||
|
||||
name = argv[1];
|
||||
bytes = simple_strtoul(argv[2], &endp, 10);
|
||||
if (*endp && *endp != '\n')
|
||||
return CMD_RET_USAGE;
|
||||
|
||||
buffer = malloc(bytes);
|
||||
if (!buffer)
|
||||
return CMD_RET_FAILURE;
|
||||
|
||||
if (avb_ops->read_persistent_value(avb_ops, name, bytes, buffer,
|
||||
&bytes_read) == AVB_IO_RESULT_OK) {
|
||||
printf("Read %ld bytes, value = %s\n", bytes_read,
|
||||
(char *)buffer);
|
||||
free(buffer);
|
||||
return CMD_RET_SUCCESS;
|
||||
}
|
||||
|
||||
printf("Failed to read persistent value\n");
|
||||
|
||||
free(buffer);
|
||||
|
||||
return CMD_RET_FAILURE;
|
||||
}
|
||||
|
||||
int do_avb_write_pvalue(cmd_tbl_t *cmdtp, int flag, int argc,
|
||||
char * const argv[])
|
||||
{
|
||||
const char *name;
|
||||
const char *value;
|
||||
|
||||
if (!avb_ops) {
|
||||
printf("AVB 2.0 is not initialized, run 'avb init' first\n");
|
||||
return CMD_RET_FAILURE;
|
||||
}
|
||||
|
||||
if (argc != 3)
|
||||
return CMD_RET_USAGE;
|
||||
|
||||
name = argv[1];
|
||||
value = argv[2];
|
||||
|
||||
if (avb_ops->write_persistent_value(avb_ops, name, strlen(value) + 1,
|
||||
(const uint8_t *)value) ==
|
||||
AVB_IO_RESULT_OK) {
|
||||
printf("Wrote %ld bytes\n", strlen(value) + 1);
|
||||
return CMD_RET_SUCCESS;
|
||||
}
|
||||
|
||||
printf("Failed to write persistent value\n");
|
||||
|
||||
return CMD_RET_FAILURE;
|
||||
}
|
||||
|
||||
static cmd_tbl_t cmd_avb[] = {
|
||||
U_BOOT_CMD_MKENT(init, 2, 0, do_avb_init, "", ""),
|
||||
U_BOOT_CMD_MKENT(read_rb, 2, 0, do_avb_read_rb, "", ""),
|
||||
@@ -350,6 +420,10 @@ static cmd_tbl_t cmd_avb[] = {
|
||||
U_BOOT_CMD_MKENT(read_part_hex, 4, 0, do_avb_read_part_hex, "", ""),
|
||||
U_BOOT_CMD_MKENT(write_part, 5, 0, do_avb_write_part, "", ""),
|
||||
U_BOOT_CMD_MKENT(verify, 1, 0, do_avb_verify_part, "", ""),
|
||||
#ifdef CONFIG_OPTEE_TA_AVB
|
||||
U_BOOT_CMD_MKENT(read_pvalue, 3, 0, do_avb_read_pvalue, "", ""),
|
||||
U_BOOT_CMD_MKENT(write_pvalue, 3, 0, do_avb_write_pvalue, "", ""),
|
||||
#endif
|
||||
};
|
||||
|
||||
static int do_avb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
||||
@@ -384,6 +458,10 @@ U_BOOT_CMD(
|
||||
" partition <partname> and print to stdout\n"
|
||||
"avb write_part <partname> <offset> <num> <addr> - write <num> bytes to\n"
|
||||
" <partname> by <offset> using data from <addr>\n"
|
||||
#ifdef CONFIG_OPTEE_TA_AVB
|
||||
"avb read_pvalue <name> <bytes> - read a persistent value <name>\n"
|
||||
"avb write_pvalue <name> <value> - write a persistent value <name>\n"
|
||||
#endif
|
||||
"avb verify - run verification process using hash data\n"
|
||||
" from vbmeta structure\n"
|
||||
);
|
||||
|
Reference in New Issue
Block a user