summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Delco <delco@google.com>2019-03-05 16:45:06 -0800
committerchrome-bot <chrome-bot@chromium.org>2019-03-20 19:51:15 -0700
commit7a748886003bad0a8971ca17d23f6641bc05bf59 (patch)
treed50b11490f88a58fdca55f49521c758a8256e9fe
parent45e420b83313d7217938737a6b7233d6c1097b90 (diff)
downloadvboot-7a748886003bad0a8971ca17d23f6641bc05bf59.tar.gz
firmware/lib: commit nvram before running legacy
vb2_run_altfw() can jump to run a legacy payload, so this change adds a call to vb2_nv_commit() to commit any pending changes to nvram before making the jump. The call to commit requires a vb2_context, so the majority of this change is to plumb this context through various functions. BUG=b:124358784 BRANCH=None TEST=local compile. Tested with a later change that helps confirm that a pending nvram change is written before jumping. Change-Id: Ib32980527aa07357d62dd695a6ff479e8c918cf8 Signed-off-by: Matt Delco <delco@google.com> Reviewed-on: https://chromium-review.googlesource.com/1504757 Reviewed-by: Julius Werner <jwerner@chromium.org>
-rw-r--r--firmware/lib/include/vboot_ui_common.h7
-rw-r--r--firmware/lib/vboot_ui.c6
-rw-r--r--firmware/lib/vboot_ui_common.c9
-rw-r--r--firmware/lib/vboot_ui_menu.c6
4 files changed, 17 insertions, 11 deletions
diff --git a/firmware/lib/include/vboot_ui_common.h b/firmware/lib/include/vboot_ui_common.h
index 8998229d..17eb8151 100644
--- a/firmware/lib/include/vboot_ui_common.h
+++ b/firmware/lib/include/vboot_ui_common.h
@@ -36,9 +36,10 @@ void vb2_error_notify(const char *print_msg,
* This will only return if it is not allowed, or the bootloader fails to
* cannot be found / fails to start
*
+ * @ctx Context
* @altfw_num Number of bootloader to start (0=any, 1=first, etc.)
*/
-void vb2_run_altfw(enum VbAltFwIndex_t altfw_num);
+void vb2_run_altfw(struct vb2_context *ctx, enum VbAltFwIndex_t altfw_num);
/** Display an error and beep to indicate that altfw is not available */
void vb2_error_no_altfw(void);
@@ -52,9 +53,11 @@ void vb2_error_no_altfw(void);
* If the operation is not permitted, or it is permitted but the bootloader
* cannot be found, it beeps and returns.
*
+ * @ctx Context
* @allowed 1 if allowed, 0 if not allowed
* @altfw_num Number of bootloader to start (0=any, 1=first, etc.)
*/
-void vb2_try_alt_fw(int allowed, enum VbAltFwIndex_t altfw_num);
+void vb2_try_alt_fw(struct vb2_context *ctx, int allowed,
+ enum VbAltFwIndex_t altfw_num);
#endif /* VBOOT_REFERENCE_VBOOT_UI_COMMON_H_ */
diff --git a/firmware/lib/vboot_ui.c b/firmware/lib/vboot_ui.c
index 5a663c29..6d19a164 100644
--- a/firmware/lib/vboot_ui.c
+++ b/firmware/lib/vboot_ui.c
@@ -206,7 +206,7 @@ VbError_t vb2_altfw_ui(struct vb2_context *ctx)
* This will not return if successful. Drop out to
* developer mode on failure.
*/
- vb2_run_altfw(key - '0');
+ vb2_run_altfw(ctx, key - '0');
active = 0;
break;
default:
@@ -612,7 +612,7 @@ VbError_t vb2_developer_ui(struct vb2_context *ctx)
VB2_DEBUG("VbBootDeveloper() - "
"user pressed key '%c': Boot alternative "
"firmware\n", key);
- vb2_try_alt_fw(allow_legacy, key - '0');
+ vb2_try_alt_fw(ctx, allow_legacy, key - '0');
break;
default:
VB2_DEBUG("VbBootDeveloper() - pressed key %d\n", key);
@@ -628,7 +628,7 @@ VbError_t vb2_developer_ui(struct vb2_context *ctx)
/* If defaulting to legacy boot, try that unless Ctrl+D was pressed */
if (use_legacy && !ctrl_d_pressed) {
VB2_DEBUG("VbBootDeveloper() - defaulting to legacy\n");
- vb2_try_alt_fw(allow_legacy, 0);
+ vb2_try_alt_fw(ctx, allow_legacy, 0);
}
if ((use_usb && !ctrl_d_pressed) && allow_usb) {
diff --git a/firmware/lib/vboot_ui_common.c b/firmware/lib/vboot_ui_common.c
index 01201ca5..be5d1f24 100644
--- a/firmware/lib/vboot_ui_common.c
+++ b/firmware/lib/vboot_ui_common.c
@@ -12,6 +12,7 @@
#include "rollback_index.h"
#include "vboot_api.h"
+#include "vboot_kernel.h"
#include "vboot_ui_common.h"
/* One or two beeps to notify that attempted action was disallowed. */
@@ -43,12 +44,13 @@ void vb2_error_notify(const char *print_msg,
vb2_error_beep(beep);
}
-void vb2_run_altfw(enum VbAltFwIndex_t altfw_num)
+void vb2_run_altfw(struct vb2_context *ctx, enum VbAltFwIndex_t altfw_num)
{
if (RollbackKernelLock(0)) {
vb2_error_notify("Error locking kernel versions on legacy "
"boot.\n", NULL, VB_BEEP_FAILED);
} else {
+ vb2_nv_commit(ctx);
VbExLegacy(altfw_num); /* will not return if found */
vb2_error_notify("Legacy boot failed. Missing BIOS?\n", NULL,
VB_BEEP_FAILED);
@@ -64,10 +66,11 @@ void vb2_error_no_altfw(void)
vb2_error_beep(VB_BEEP_NOT_ALLOWED);
}
-void vb2_try_alt_fw(int allowed, enum VbAltFwIndex_t altfw_num)
+void vb2_try_alt_fw(struct vb2_context *ctx, int allowed,
+ enum VbAltFwIndex_t altfw_num)
{
if (allowed)
- vb2_run_altfw(altfw_num); /* will not return if found */
+ vb2_run_altfw(ctx, altfw_num); /* will not return if found */
else
vb2_error_no_altfw();
}
diff --git a/firmware/lib/vboot_ui_menu.c b/firmware/lib/vboot_ui_menu.c
index 17c1137e..5ac4bb40 100644
--- a/firmware/lib/vboot_ui_menu.c
+++ b/firmware/lib/vboot_ui_menu.c
@@ -162,7 +162,7 @@ static VbError_t boot_legacy_action(struct vb2_context *ctx)
return VBERROR_KEEP_LOOPING;
}
- vb2_run_altfw(VB_ALTFW_DEFAULT);
+ vb2_run_altfw(ctx, VB_ALTFW_DEFAULT);
vb2_flash_screen(ctx);
return VBERROR_KEEP_LOOPING;
}
@@ -342,7 +342,7 @@ static VbError_t language_action(struct vb2_context *ctx)
/* Action when selecting a bootloader in the alternative firmware menu. */
static VbError_t altfw_action(struct vb2_context *ctx)
{
- vb2_run_altfw(current_menu_idx + 1);
+ vb2_run_altfw(ctx, current_menu_idx + 1);
vb2_flash_screen(ctx);
VB2_DEBUG(no_legacy);
VbExDisplayDebugInfo(no_legacy, 0);
@@ -797,7 +797,7 @@ static VbError_t vb2_developer_menu(struct vb2_context *ctx)
VB2_DEBUG("VbBootDeveloper() - "
"user pressed key '%c': Boot alternative "
"firmware\n", key);
- vb2_try_alt_fw(altfw_allowed, key - '0');
+ vb2_try_alt_fw(ctx, altfw_allowed, key - '0');
break;
default:
ret = vb2_handle_menu_input(ctx, key, 0);