From d08a3435f867700c90e33398bf104557d98bf791 Mon Sep 17 00:00:00 2001 From: Furquan Shaikh Date: Mon, 25 May 2015 21:48:02 -0700 Subject: fastboot: Add fastboot related flags to vb2 BUG=chrome-os-partner:40196 BRANCH=None TEST=Compiles successfully. Change-Id: I4305436b2ae46254e4e8b12039ffed95634d62c2 Signed-off-by: Furquan Shaikh Reviewed-on: https://chromium-review.googlesource.com/273181 Tested-by: Furquan Shaikh Reviewed-by: Randall Spangler Commit-Queue: Furquan Shaikh Trybot-Ready: Furquan Shaikh --- firmware/2lib/2misc.c | 2 ++ firmware/2lib/2nvstorage.c | 17 +++++++++++++++++ firmware/2lib/include/2nvstorage.h | 8 ++++++++ firmware/2lib/include/2nvstorage_fields.h | 9 +++++++-- tests/vb2_misc_tests.c | 6 ++++++ tests/vb2_nvstorage_tests.c | 2 ++ 6 files changed, 42 insertions(+), 2 deletions(-) diff --git a/firmware/2lib/2misc.c b/firmware/2lib/2misc.c index 360365d8..5805093b 100644 --- a/firmware/2lib/2misc.c +++ b/firmware/2lib/2misc.c @@ -263,6 +263,8 @@ int vb2_check_dev_switch(struct vb2_context *ctx) vb2_nv_set(ctx, VB2_NV_DEV_BOOT_USB, 0); vb2_nv_set(ctx, VB2_NV_DEV_BOOT_LEGACY, 0); vb2_nv_set(ctx, VB2_NV_DEV_BOOT_SIGNED_ONLY, 0); + vb2_nv_set(ctx, VB2_NV_DEV_BOOT_FASTBOOT_FULL_CAP, 0); + vb2_nv_set(ctx, VB2_NV_FASTBOOT_UNLOCK_IN_FW, 0); } if (ctx->flags & VB2_CONTEXT_FORCE_WIPEOUT_MODE) diff --git a/firmware/2lib/2nvstorage.c b/firmware/2lib/2nvstorage.c index 4d3c8bad..35cf6fcc 100644 --- a/firmware/2lib/2nvstorage.c +++ b/firmware/2lib/2nvstorage.c @@ -135,6 +135,10 @@ uint32_t vb2_nv_get(struct vb2_context *ctx, enum vb2_nv_param param) case VB2_NV_DEV_BOOT_SIGNED_ONLY: return GETBIT(VB2_NV_OFFS_DEV, VB2_NV_DEV_FLAG_SIGNED_ONLY); + case VB2_NV_DEV_BOOT_FASTBOOT_FULL_CAP: + return GETBIT(VB2_NV_OFFS_DEV, + VB2_NV_DEV_FLAG_FASTBOOT_FULL_CAP); + case VB2_NV_DISABLE_DEV_REQUEST: return GETBIT(VB2_NV_OFFS_BOOT, VB2_NV_BOOT_DISABLE_DEV); @@ -152,6 +156,10 @@ uint32_t vb2_nv_get(struct vb2_context *ctx, enum vb2_nv_param param) case VB2_NV_REQ_WIPEOUT: return GETBIT(VB2_NV_OFFS_HEADER , VB2_NV_HEADER_WIPEOUT); + + case VB2_NV_FASTBOOT_UNLOCK_IN_FW: + return GETBIT(VB2_NV_OFFS_FASTBOOT, + VB2_NV_FASTBOOT_FLAG_UNLOCK_IN_FW); } /* @@ -275,6 +283,10 @@ void vb2_nv_set(struct vb2_context *ctx, SETBIT(VB2_NV_OFFS_DEV, VB2_NV_DEV_FLAG_SIGNED_ONLY); break; + case VB2_NV_DEV_BOOT_FASTBOOT_FULL_CAP: + SETBIT(VB2_NV_OFFS_DEV, VB2_NV_DEV_FLAG_FASTBOOT_FULL_CAP); + break; + case VB2_NV_DISABLE_DEV_REQUEST: SETBIT(VB2_NV_OFFS_BOOT, VB2_NV_BOOT_DISABLE_DEV); break; @@ -298,6 +310,11 @@ void vb2_nv_set(struct vb2_context *ctx, case VB2_NV_REQ_WIPEOUT: SETBIT(VB2_NV_OFFS_HEADER , VB2_NV_HEADER_WIPEOUT); break; + + case VB2_NV_FASTBOOT_UNLOCK_IN_FW: + SETBIT(VB2_NV_OFFS_FASTBOOT, VB2_NV_FASTBOOT_FLAG_UNLOCK_IN_FW); + break; + } /* diff --git a/firmware/2lib/include/2nvstorage.h b/firmware/2lib/include/2nvstorage.h index 3b3f34c8..9ade3e78 100644 --- a/firmware/2lib/include/2nvstorage.h +++ b/firmware/2lib/include/2nvstorage.h @@ -50,6 +50,11 @@ enum vb2_nv_param { VB2_NV_DEV_BOOT_LEGACY, /* Only boot Google-signed images in developer mode. 0=no, 1=yes. */ VB2_NV_DEV_BOOT_SIGNED_ONLY, + /* + * Allow full fastboot capability in firmware in developer mode. + * 0=no, 1=yes. + */ + VB2_NV_DEV_BOOT_FASTBOOT_FULL_CAP, /* * Set by userspace to request that RO firmware disable dev-mode on the * next boot. This is likely only possible if the dev-switch is @@ -80,6 +85,9 @@ enum vb2_nv_param { VB2_NV_FW_PREV_RESULT, /* Request wipeout of the device by the app. */ VB2_NV_REQ_WIPEOUT, + + /* Fastboot: Unlock in firmware, 0=disabled, 1=enabled. */ + VB2_NV_FASTBOOT_UNLOCK_IN_FW, }; /* Firmware result codes for VB2_NV_FW_RESULT and VB2_NV_FW_PREV_RESULT */ diff --git a/firmware/2lib/include/2nvstorage_fields.h b/firmware/2lib/include/2nvstorage_fields.h index 1c4fdf41..0a6c5385 100644 --- a/firmware/2lib/include/2nvstorage_fields.h +++ b/firmware/2lib/include/2nvstorage_fields.h @@ -28,7 +28,8 @@ enum vb2_nv_offset { VB2_NV_OFFS_TPM = 5, VB2_NV_OFFS_RECOVERY_SUBCODE = 6, VB2_NV_OFFS_BOOT2 = 7, - /* Offsets 8-10 are currently unused */ + VB2_NV_OFFS_FASTBOOT = 8, + /* Offsets 9-10 are currently unused */ VB2_NV_OFFS_KERNEL = 11, /* 11-14; field is 32 bits */ /* CRC must be last field */ VB2_NV_OFFS_CRC = 15 @@ -56,13 +57,17 @@ enum vb2_nv_offset { #define VB2_NV_BOOT2_PREV_RESULT_SHIFT 4 /* Number of bits to shift result */ #define VB2_NV_BOOT2_PREV_TRIED 0x40 -/* Fields in VB2_NV_OFFS_DEV (unused = 0xf8) */ +/* Fields in VB2_NV_OFFS_DEV (unused = 0xf0) */ #define VB2_NV_DEV_FLAG_USB 0x01 #define VB2_NV_DEV_FLAG_SIGNED_ONLY 0x02 #define VB2_NV_DEV_FLAG_LEGACY 0x04 +#define VB2_NV_DEV_FLAG_FASTBOOT_FULL_CAP 0x08 /* Fields in VB2_NV_OFFS_TPM (unused = 0xfc) */ #define VB2_NV_TPM_CLEAR_OWNER_REQUEST 0x01 #define VB2_NV_TPM_CLEAR_OWNER_DONE 0x02 +/* Fields in VB2_NV_OFFS_FASTBOOT (unused = 0xfe) */ +#define VB2_NV_FASTBOOT_FLAG_UNLOCK_IN_FW 0x01 + #endif /* VBOOT_REFERENCE_VBOOT_2NVSTORAGE_FIELDS_H_ */ diff --git a/tests/vb2_misc_tests.c b/tests/vb2_misc_tests.c index e41a16d9..3346f20f 100644 --- a/tests/vb2_misc_tests.c +++ b/tests/vb2_misc_tests.c @@ -309,6 +309,8 @@ static void dev_switch_tests(void) vb2_nv_set(&cc, VB2_NV_DEV_BOOT_USB, 1); vb2_nv_set(&cc, VB2_NV_DEV_BOOT_LEGACY, 1); vb2_nv_set(&cc, VB2_NV_DEV_BOOT_SIGNED_ONLY, 1); + vb2_nv_set(&cc, VB2_NV_DEV_BOOT_FASTBOOT_FULL_CAP, 1); + vb2_nv_set(&cc, VB2_NV_FASTBOOT_UNLOCK_IN_FW, 1); TEST_SUCC(vb2_check_dev_switch(&cc), "dev mode off"); TEST_EQ(vb2_nv_get(&cc, VB2_NV_DEV_BOOT_USB), 0, "cleared dev boot usb"); @@ -316,6 +318,10 @@ static void dev_switch_tests(void) 0, "cleared dev boot legacy"); TEST_EQ(vb2_nv_get(&cc, VB2_NV_DEV_BOOT_SIGNED_ONLY), 0, "cleared dev boot signed only"); + TEST_EQ(vb2_nv_get(&cc, VB2_NV_DEV_BOOT_FASTBOOT_FULL_CAP), + 0, "cleared dev boot fastboot full cap"); + TEST_EQ(vb2_nv_get(&cc, VB2_NV_FASTBOOT_UNLOCK_IN_FW), + 0, "cleared dev boot fastboot unlock in fw"); /* Normal-dev transition clears TPM */ reset_common_data(); diff --git a/tests/vb2_nvstorage_tests.c b/tests/vb2_nvstorage_tests.c index 1471e1bf..8b1aa2d6 100644 --- a/tests/vb2_nvstorage_tests.c +++ b/tests/vb2_nvstorage_tests.c @@ -43,11 +43,13 @@ static struct nv_field nvfields[] = { {VB2_NV_DEV_BOOT_USB, 0, 1, 0, "dev boot usb"}, {VB2_NV_DEV_BOOT_LEGACY, 0, 1, 0, "dev boot legacy"}, {VB2_NV_DEV_BOOT_SIGNED_ONLY, 0, 1, 0, "dev boot custom"}, + {VB2_NV_DEV_BOOT_FASTBOOT_FULL_CAP, 0, 1, 0, "dev boot fb full cap"}, {VB2_NV_DISABLE_DEV_REQUEST, 0, 1, 0, "disable dev request"}, {VB2_NV_CLEAR_TPM_OWNER_REQUEST, 0, 1, 0, "clear tpm owner request"}, {VB2_NV_CLEAR_TPM_OWNER_DONE, 0, 1, 0, "clear tpm owner done"}, {VB2_NV_OPROM_NEEDED, 0, 1, 0, "oprom needed"}, {VB2_NV_BACKUP_NVRAM_REQUEST, 0, 1, 0, "backup nvram request"}, + {VB2_NV_FASTBOOT_UNLOCK_IN_FW, 0, 1, 0, "fastboot unlock in fw"}, {0, 0, 0, 0, NULL} }; -- cgit v1.2.1