summaryrefslogtreecommitdiff
path: root/firmware/2lib/2api.c
diff options
context:
space:
mode:
authorSubrata Banik <subratabanik@google.com>2022-07-13 23:48:23 +0530
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-07-29 09:37:19 +0000
commit81b8d3faabad2f16bfd08efa6920bdaaeb637ce8 (patch)
treea8842889f148b4b56d93892e40a179c3dc0c3543 /firmware/2lib/2api.c
parentaa4671712ddb54216febc103cc9ff530b586b54a (diff)
downloadvboot-81b8d3faabad2f16bfd08efa6920bdaaeb637ce8.tar.gz
firmware/2lib: Introduce `vb2api_get_fw_boot_info` API
This patch introduces a new API named `vb2api_get_fw_boot_info` to get the FW slot information like tries, current boot slot, previous boot slot, previous boot status and boot mode. Additionally, moved the required data structures from 2api.h to newly created 2info.h file to keep vboot information and inline functions for coreboot/eventlog usage. BUG=b:215615970 TEST=Able to compile the Google/Kano board using the emerge command. Signed-off-by: Subrata Banik <subratabanik@google.com> Change-Id: Ib3f197c851dc4b445dbf64868c3f9157a4f6c9fe Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/3737570 Auto-Submit: Subrata Banik <subratabanik@chromium.org> Commit-Queue: Yu-Ping Wu <yupingso@chromium.org> Tested-by: Subrata Banik <subratabanik@chromium.org> Reviewed-by: Julius Werner <jwerner@chromium.org>
Diffstat (limited to 'firmware/2lib/2api.c')
-rw-r--r--firmware/2lib/2api.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/firmware/2lib/2api.c b/firmware/2lib/2api.c
index 9184b23d..13b3a697 100644
--- a/firmware/2lib/2api.c
+++ b/firmware/2lib/2api.c
@@ -365,3 +365,33 @@ int vb2api_check_hash(struct vb2_context *ctx)
{
return vb2api_check_hash_get_digest(ctx, NULL, 0);
}
+
+union vb2_fw_boot_info vb2api_get_fw_boot_info(struct vb2_context *ctx)
+{
+ union vb2_fw_boot_info info;
+
+ struct vb2_shared_data *sd = vb2_get_sd(ctx);
+
+ info.tries = vb2_nv_get(ctx, VB2_NV_TRY_COUNT);
+ info.slot = sd->fw_slot;
+ info.prev_slot = sd->last_fw_slot;
+ info.prev_result = sd->last_fw_result;
+ info.boot_mode = ctx->boot_mode;
+
+ VB2_DEBUG("boot_mode=`%s`\n", vb2_boot_mode_string(info.boot_mode));
+
+ if (ctx->flags & VB2_CONTEXT_RECOVERY_MODE) {
+ info.recovery_reason = sd->recovery_reason;
+ info.recovery_subcode = vb2_nv_get(ctx, VB2_NV_RECOVERY_SUBCODE);
+ VB2_DEBUG("recovery_reason: %#x / %#x\n",
+ info.recovery_reason, info.recovery_subcode);
+ }
+
+ VB2_DEBUG("fw_tried=`%s` fw_try_count=%d "
+ "fw_prev_tried=`%s` fw_prev_result=`%s`.\n",
+ vb2_slot_string(info.slot), info.tries,
+ vb2_slot_string(info.prev_slot),
+ vb2_result_string(info.prev_result));
+
+ return info;
+}