1 /* Copyright 2022 The ChromiumOS Authors
2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
4 *
5 * Some helper function related to boot mode.
6 */
7
8 #include "2api.h"
9 #include "2misc.h"
10 #include "2nvstorage.h"
11 #include "common/boot_mode.h"
12 #include "common/tests.h"
13
_set_boot_mode(struct vb2_context * ctx,enum vb2_boot_mode boot_mode,uint32_t recovery_reason,...)14 void _set_boot_mode(struct vb2_context *ctx, enum vb2_boot_mode boot_mode,
15 uint32_t recovery_reason, ...)
16 {
17 struct vb2_shared_data *sd = vb2_get_sd(ctx);
18
19 switch (boot_mode) {
20 case VB2_BOOT_MODE_MANUAL_RECOVERY:
21 TEST_NEQ(recovery_reason, 0,
22 "recovery_reason should be set in recovery mode");
23 ctx->flags |= VB2_CONTEXT_RECOVERY_MODE;
24 sd->recovery_reason = recovery_reason;
25 ctx->flags |= VB2_CONTEXT_FORCE_RECOVERY_MODE;
26 ctx->flags |= VB2_CONTEXT_EC_TRUSTED;
27 break;
28 case VB2_BOOT_MODE_BROKEN_SCREEN:
29 TEST_NEQ(recovery_reason, 0,
30 "recovery_reason should be set in recovery mode");
31 ctx->flags |= VB2_CONTEXT_RECOVERY_MODE;
32 sd->recovery_reason = recovery_reason;
33 break;
34 case VB2_BOOT_MODE_DIAGNOSTICS:
35 vb2_nv_set(ctx, VB2_NV_DIAG_REQUEST, 1);
36 break;
37 case VB2_BOOT_MODE_DEVELOPER:
38 ctx->flags |= VB2_CONTEXT_DEVELOPER_MODE;
39 break;
40 case VB2_BOOT_MODE_NORMAL:
41 break;
42 default:
43 TEST_TRUE(0, "SET_BOOT_MODE: Undefined boot mode");
44 return;
45 }
46 vb2_set_boot_mode(ctx);
47 TEST_EQ(ctx->boot_mode, boot_mode, "Validity check for set boot mode");
48 }
49