fastboot: Add fastboot related flags to nvstorage

Use unused offset 8 for fastboot related flags.

BUG=chrome-os-partner:40196
BRANCH=None
TEST=Compiles successfully.

Change-Id: I6df0985924ba80cdcb68bb6b7658bf962f01287f
Signed-off-by: Furquan Shaikh <furquan@google.com>
Reviewed-on: https://chromium-review.googlesource.com/273180
Tested-by: Furquan Shaikh <furquan@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Commit-Queue: Furquan Shaikh <furquan@chromium.org>
Trybot-Ready: Furquan Shaikh <furquan@chromium.org>
This commit is contained in:
Furquan Shaikh
2015-05-25 21:46:10 -07:00
committed by ChromeOS Commit Bot
parent ebf886b5fd
commit c180460feb
7 changed files with 38 additions and 0 deletions

View File

@@ -110,6 +110,9 @@ typedef enum VbNvParam {
/* Wipeout request from firmware present. */ /* Wipeout request from firmware present. */
VBNV_FW_REQ_WIPEOUT, VBNV_FW_REQ_WIPEOUT,
/* Fastboot: Unlock in firmware, 0=disabled, 1=enabled. */
VBNV_FASTBOOT_UNLOCK_IN_FW,
} VbNvParam; } VbNvParam;
/* Result of trying the firmware in VBNV_FW_TRIED */ /* Result of trying the firmware in VBNV_FW_TRIED */

View File

@@ -323,6 +323,7 @@ VbError_t VbInit(VbCommonParams *cparams, VbInitParams *iparams)
VbNvSet(&vnc, VBNV_DEV_BOOT_LEGACY, 0); VbNvSet(&vnc, VBNV_DEV_BOOT_LEGACY, 0);
VbNvSet(&vnc, VBNV_DEV_BOOT_SIGNED_ONLY, 0); VbNvSet(&vnc, VBNV_DEV_BOOT_SIGNED_ONLY, 0);
VbNvSet(&vnc, VBNV_DEV_BOOT_FASTBOOT_FULL_CAP, 0); VbNvSet(&vnc, VBNV_DEV_BOOT_FASTBOOT_FULL_CAP, 0);
VbNvSet(&vnc, VBNV_FASTBOOT_UNLOCK_IN_FW, 0);
/* /*
* Back up any changes now, so these values can't be forgotten * Back up any changes now, so these values can't be forgotten
* by draining the battery. We really only care about these * by draining the battery. We really only care about these

View File

@@ -57,6 +57,9 @@
#define BOOT2_PREV_RESULT_SHIFT 4 /* Number of bits to shift result */ #define BOOT2_PREV_RESULT_SHIFT 4 /* Number of bits to shift result */
#define BOOT2_PREV_TRIED 0x40 #define BOOT2_PREV_TRIED 0x40
#define FASTBOOT_OFFSET 8
#define FASTBOOT_UNLOCK_IN_FW 0x01
#define KERNEL_FIELD_OFFSET 11 #define KERNEL_FIELD_OFFSET 11
#define CRC_OFFSET 15 #define CRC_OFFSET 15
@@ -202,6 +205,10 @@ int VbNvGet(VbNvContext *context, VbNvParam param, uint32_t *dest)
*dest = (raw[HEADER_OFFSET] & HEADER_WIPEOUT) ? 1 : 0; *dest = (raw[HEADER_OFFSET] & HEADER_WIPEOUT) ? 1 : 0;
return 0; return 0;
case VBNV_FASTBOOT_UNLOCK_IN_FW:
*dest = (raw[FASTBOOT_OFFSET] & FASTBOOT_UNLOCK_IN_FW) ? 1 : 0;
return 0;
default: default:
return 1; return 1;
} }
@@ -388,6 +395,13 @@ int VbNvSet(VbNvContext *context, VbNvParam param, uint32_t value)
raw[HEADER_OFFSET] &= ~HEADER_WIPEOUT; raw[HEADER_OFFSET] &= ~HEADER_WIPEOUT;
break; break;
case VBNV_FASTBOOT_UNLOCK_IN_FW:
if (value)
raw[FASTBOOT_OFFSET] |= FASTBOOT_UNLOCK_IN_FW;
else
raw[FASTBOOT_OFFSET] &= ~FASTBOOT_UNLOCK_IN_FW;
break;
default: default:
return 1; return 1;
} }

View File

@@ -21,6 +21,7 @@ static const VbNvParam backup_params[] = {
VBNV_DEV_BOOT_LEGACY, VBNV_DEV_BOOT_LEGACY,
VBNV_DEV_BOOT_SIGNED_ONLY, VBNV_DEV_BOOT_SIGNED_ONLY,
VBNV_DEV_BOOT_FASTBOOT_FULL_CAP, VBNV_DEV_BOOT_FASTBOOT_FULL_CAP,
VBNV_FASTBOOT_UNLOCK_IN_FW,
}; };
/* We can't back things up if there isn't enough storage. */ /* We can't back things up if there isn't enough storage. */

View File

@@ -534,6 +534,10 @@ int VbGetSystemPropertyInt(const char* name) {
} else if (!strcasecmp(name,"recovery_reason")) { } else if (!strcasecmp(name,"recovery_reason")) {
value = GetVdatInt(VDAT_INT_RECOVERY_REASON); value = GetVdatInt(VDAT_INT_RECOVERY_REASON);
} }
/* Fastboot-related parameters */
else if (!strcasecmp(name, "fastboot_unlock_in_fw")) {
value = VbGetNvStorage(VBNV_FASTBOOT_UNLOCK_IN_FW);
}
return value; return value;
} }
@@ -657,6 +661,8 @@ int VbSetSystemPropertyInt(const char* name, int value) {
return VbSetNvStorage_WithBackup(VBNV_DEV_BOOT_SIGNED_ONLY, value); return VbSetNvStorage_WithBackup(VBNV_DEV_BOOT_SIGNED_ONLY, value);
} else if (!strcasecmp(name,"dev_boot_fastboot_full_cap")) { } else if (!strcasecmp(name,"dev_boot_fastboot_full_cap")) {
return VbSetNvStorage_WithBackup(VBNV_DEV_BOOT_FASTBOOT_FULL_CAP, value); return VbSetNvStorage_WithBackup(VBNV_DEV_BOOT_FASTBOOT_FULL_CAP, value);
} else if (!strcasecmp(name, "fastboot_unlock_in_fw")) {
return VbSetNvStorage_WithBackup(VBNV_FASTBOOT_UNLOCK_IN_FW, value);
} }
return -1; return -1;

View File

@@ -556,6 +556,7 @@ static void VbInitTestBackup(void)
VbNvSet(&vnc, VBNV_DEV_BOOT_LEGACY, 1); VbNvSet(&vnc, VBNV_DEV_BOOT_LEGACY, 1);
VbNvSet(&vnc, VBNV_DEV_BOOT_SIGNED_ONLY, 1); VbNvSet(&vnc, VBNV_DEV_BOOT_SIGNED_ONLY, 1);
VbNvSet(&vnc, VBNV_DEV_BOOT_FASTBOOT_FULL_CAP, 1); VbNvSet(&vnc, VBNV_DEV_BOOT_FASTBOOT_FULL_CAP, 1);
VbNvSet(&vnc, VBNV_FASTBOOT_UNLOCK_IN_FW, 1);
/* and some that don't */ /* and some that don't */
VbNvSet(&vnc, VBNV_OPROM_NEEDED, 1); VbNvSet(&vnc, VBNV_OPROM_NEEDED, 1);
VbNvSet(&vnc, VBNV_TRY_B_COUNT, 3); VbNvSet(&vnc, VBNV_TRY_B_COUNT, 3);
@@ -585,6 +586,8 @@ static void VbInitTestBackup(void)
TEST_EQ(u, 0, " NV dev_boot_signed_only"); TEST_EQ(u, 0, " NV dev_boot_signed_only");
VbNvGet(&vnc, VBNV_DEV_BOOT_FASTBOOT_FULL_CAP, &u); VbNvGet(&vnc, VBNV_DEV_BOOT_FASTBOOT_FULL_CAP, &u);
TEST_EQ(u, 0, " NV dev_boot_fastboot_full_cap"); TEST_EQ(u, 0, " NV dev_boot_fastboot_full_cap");
VbNvGet(&vnc, VBNV_FASTBOOT_UNLOCK_IN_FW, &u);
TEST_EQ(u, 0, " NV_fastboot_unlock_in_fw ");
/* So we should have written the backup */ /* So we should have written the backup */
TEST_EQ(backup_write_called, 1, " Backup written once"); TEST_EQ(backup_write_called, 1, " Backup written once");
/* And the backup should reflect the persisent flags. */ /* And the backup should reflect the persisent flags. */
@@ -602,6 +605,8 @@ static void VbInitTestBackup(void)
TEST_EQ(u, 0, " BU dev_boot_signed_only"); TEST_EQ(u, 0, " BU dev_boot_signed_only");
VbNvGet(&tmp_vnc, VBNV_DEV_BOOT_FASTBOOT_FULL_CAP, &u); VbNvGet(&tmp_vnc, VBNV_DEV_BOOT_FASTBOOT_FULL_CAP, &u);
TEST_EQ(u, 0, " BU dev_boot_fastboot_full_cap"); TEST_EQ(u, 0, " BU dev_boot_fastboot_full_cap");
VbNvGet(&tmp_vnc, VBNV_FASTBOOT_UNLOCK_IN_FW, &u);
TEST_EQ(u, 0, " BU fastboot_unlock_in_fw");
/* but not the others */ /* but not the others */
VbNvGet(&tmp_vnc, VBNV_OPROM_NEEDED, &u); VbNvGet(&tmp_vnc, VBNV_OPROM_NEEDED, &u);
TEST_EQ(u, 0, " BU oprom_needed"); TEST_EQ(u, 0, " BU oprom_needed");
@@ -642,6 +647,7 @@ static void VbInitTestBackup(void)
VbNvSet(&vnc, VBNV_DEV_BOOT_LEGACY, 1); VbNvSet(&vnc, VBNV_DEV_BOOT_LEGACY, 1);
VbNvSet(&vnc, VBNV_DEV_BOOT_SIGNED_ONLY, 1); VbNvSet(&vnc, VBNV_DEV_BOOT_SIGNED_ONLY, 1);
VbNvSet(&vnc, VBNV_DEV_BOOT_FASTBOOT_FULL_CAP, 1); VbNvSet(&vnc, VBNV_DEV_BOOT_FASTBOOT_FULL_CAP, 1);
VbNvSet(&vnc, VBNV_FASTBOOT_UNLOCK_IN_FW, 1);
/* and some that don't */ /* and some that don't */
VbNvSet(&vnc, VBNV_OPROM_NEEDED, 1); VbNvSet(&vnc, VBNV_OPROM_NEEDED, 1);
VbNvSet(&vnc, VBNV_TRY_B_COUNT, 4); VbNvSet(&vnc, VBNV_TRY_B_COUNT, 4);
@@ -691,6 +697,8 @@ static void VbInitTestBackup(void)
TEST_EQ(u, 1, " BU dev_boot_signed_only"); TEST_EQ(u, 1, " BU dev_boot_signed_only");
VbNvGet(&tmp_vnc, VBNV_DEV_BOOT_FASTBOOT_FULL_CAP, &u); VbNvGet(&tmp_vnc, VBNV_DEV_BOOT_FASTBOOT_FULL_CAP, &u);
TEST_EQ(u, 1, " BU dev_boot_fastboot_full_cap"); TEST_EQ(u, 1, " BU dev_boot_fastboot_full_cap");
VbNvGet(&tmp_vnc, VBNV_FASTBOOT_UNLOCK_IN_FW, &u);
TEST_EQ(u, 1, " BU fastboot_unlock_in_fw");
/* but not the others */ /* but not the others */
VbNvGet(&tmp_vnc, VBNV_OPROM_NEEDED, &u); VbNvGet(&tmp_vnc, VBNV_OPROM_NEEDED, &u);
TEST_EQ(u, 0, " BU oprom_needed"); TEST_EQ(u, 0, " BU oprom_needed");
@@ -730,6 +738,8 @@ static void VbInitTestBackup(void)
TEST_EQ(u, 1, " BU dev_boot_signed_only"); TEST_EQ(u, 1, " BU dev_boot_signed_only");
VbNvGet(&vnc, VBNV_DEV_BOOT_FASTBOOT_FULL_CAP, &u); VbNvGet(&vnc, VBNV_DEV_BOOT_FASTBOOT_FULL_CAP, &u);
TEST_EQ(u, 1, " BU dev_boot_fastboot_full_cap"); TEST_EQ(u, 1, " BU dev_boot_fastboot_full_cap");
VbNvGet(&vnc, VBNV_FASTBOOT_UNLOCK_IN_FW, &u);
TEST_EQ(u, 1, " BU fastboot_unlock_in_fw");
/* /*
* But if we lose the NV storage and go back to normal mode at the same * But if we lose the NV storage and go back to normal mode at the same
@@ -766,6 +776,8 @@ static void VbInitTestBackup(void)
TEST_EQ(u, 0, " BU dev_boot_signed_only"); TEST_EQ(u, 0, " BU dev_boot_signed_only");
VbNvGet(&vnc, VBNV_DEV_BOOT_FASTBOOT_FULL_CAP, &u); VbNvGet(&vnc, VBNV_DEV_BOOT_FASTBOOT_FULL_CAP, &u);
TEST_EQ(u, 0, " BU dev_boot_fastboot_full_cap"); TEST_EQ(u, 0, " BU dev_boot_fastboot_full_cap");
VbNvGet(&vnc, VBNV_FASTBOOT_UNLOCK_IN_FW, &u);
TEST_EQ(u, 0, " BU fastboot_unlock_in_fw");
} }

View File

@@ -44,6 +44,7 @@ static VbNvField nvfields[] = {
{VBNV_FW_RESULT, VBNV_FW_RESULT_UNKNOWN, 1, 2, "firmware result"}, {VBNV_FW_RESULT, VBNV_FW_RESULT_UNKNOWN, 1, 2, "firmware result"},
{VBNV_FW_PREV_TRIED, 0, 1, 0, "firmware prev tried"}, {VBNV_FW_PREV_TRIED, 0, 1, 0, "firmware prev tried"},
{VBNV_FW_PREV_RESULT, VBNV_FW_RESULT_UNKNOWN, 1, 3, "firmware prev result"}, {VBNV_FW_PREV_RESULT, VBNV_FW_RESULT_UNKNOWN, 1, 3, "firmware prev result"},
{VBNV_FASTBOOT_UNLOCK_IN_FW, 0, 1, 0, "fastboot unlock in firmware"},
{0, 0, 0, 0, NULL} {0, 0, 0, 0, NULL}
}; };