diff --git a/include/android_avb/rk_avb_ops_user.h b/include/android_avb/rk_avb_ops_user.h index 7317f1795b..1d1b8c415d 100644 --- a/include/android_avb/rk_avb_ops_user.h +++ b/include/android_avb/rk_avb_ops_user.h @@ -76,6 +76,17 @@ int rk_avb_set_slot_active(unsigned int *slot_number); */ int rk_avb_get_current_slot(char *select_slot); +/** + * Append current slot to given partition name + * + * @param part_name partition name + * @param slot given slot suffix, auto append current slot if NULL + * @param new_name partition name with slot suffix appended + * + * @return 0 if the command succeeded, -1 if it failed + */ +int rk_avb_append_part_slot(const char *part_name, char *new_name); + /** * The android things defines permanent attributes to * store PSK_public, product id. We can use this function diff --git a/lib/avb/rk_avb_user/rk_avb_ops_user.c b/lib/avb/rk_avb_user/rk_avb_ops_user.c index e3a154f89e..63a3d10e19 100644 --- a/lib/avb/rk_avb_user/rk_avb_ops_user.c +++ b/lib/avb/rk_avb_user/rk_avb_ops_user.c @@ -112,6 +112,7 @@ AvbABFlowResult rk_avb_ab_slot_select(AvbABOps* ab_ops,char* select_slot) AvbIOResult io_ret = AVB_IO_RESULT_OK; AvbABData ab_data; size_t slot_index_to_boot; + static int last_slot_index = -1; io_ret = ab_ops->read_ab_metadata(ab_ops, &ab_data); if (io_ret != AVB_IO_RESULT_OK) { @@ -140,6 +141,14 @@ AvbABFlowResult rk_avb_ab_slot_select(AvbABOps* ab_ops,char* select_slot) } else if(slot_index_to_boot == 1) { strcpy(select_slot, "_b"); } + + if (last_slot_index != slot_index_to_boot) { + last_slot_index = slot_index_to_boot; + printf("A/B-slot: %s, successful: %d, tries-remain: %d\n", + select_slot, + ab_data.slots[slot_index_to_boot].successful_boot, + ab_data.slots[slot_index_to_boot].tries_remaining); + } out: return ret; } @@ -172,6 +181,26 @@ int rk_avb_get_current_slot(char *select_slot) return ret; } +int rk_avb_append_part_slot(const char *part_name, char *new_name) +{ + char slot_suffix[3] = {0}; + + if (!strcmp(part_name, "misc")) { + strcat(new_name, part_name); + return 0; + } + + if (rk_avb_get_current_slot(slot_suffix)) { + printf("%s: failed to get slot suffix !\n", __func__); + return -1; + } + + strcpy(new_name, part_name); + strcat(new_name, slot_suffix); + + return 0; +} + int rk_avb_read_permanent_attributes(uint8_t *attributes, uint32_t size) { #ifdef CONFIG_OPTEE_CLIENT