summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Kitching <kitching@google.com>2020-04-21 12:50:03 +0800
committerCommit Bot <commit-bot@chromium.org>2020-05-28 07:11:17 +0000
commit72d4c9dae9c910e2bb5d0fcb8b34771fd4ce16f0 (patch)
tree4cdc51b85e5fa77b58d434bb1a0d04b000775239
parent0bbd72df633a90258d8f5203614ef16258c25a00 (diff)
downloadvboot-72d4c9dae9c910e2bb5d0fcb8b34771fd4ce16f0.tar.gz
vboot: move timer and beep functions to vboot2 namespace
Move these functions from vboot_api.h into 2api.h: VbExGetTimer --> vb2ex_mtime (usec -> msec) VbExSleepMs --> vb2ex_msleep VbExBeep --> vb2ex_beep Rename the constants: VB_USEC_PER_MSEC --> VB2_USEC_PER_MSEC VB_MSEC_PER_SEC --> VB2_MSEC_PER_SEC Remove the constant VB_USEC_PER_SEC. The error code VBERROR_NO_BACKGROUND_SOUND is dropped since it is not currently used. Update a few printf lines to use VB2_DEBUG instead. BUG=b:124141368, chromium:988410 TEST=make clean && make runtests BRANCH=none Change-Id: I887112ffd5f68fb6a9c4d9ad624aa420cbd55b4b Signed-off-by: Joel Kitching <kitching@google.com> Cq-Depend: chromium:2158665 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/2158666 Tested-by: Joel Kitching <kitching@chromium.org> Reviewed-by: Julius Werner <jwerner@chromium.org> Commit-Queue: Joel Kitching <kitching@chromium.org>
-rw-r--r--firmware/2lib/2ui.c2
-rw-r--r--firmware/2lib/2ui_screens.c14
-rw-r--r--firmware/2lib/include/2api.h33
-rw-r--r--firmware/2lib/include/2common.h4
-rw-r--r--firmware/2lib/include/2return_codes.h2
-rw-r--r--firmware/2lib/include/2ui.h2
-rw-r--r--firmware/include/vboot_api.h43
-rw-r--r--firmware/lib/vboot_audio.c16
-rw-r--r--firmware/lib/vboot_kernel.c20
-rw-r--r--firmware/lib/vboot_ui_legacy.c8
-rw-r--r--firmware/lib/vboot_ui_legacy_clamshell.c14
-rw-r--r--firmware/lib/vboot_ui_legacy_menu.c8
-rw-r--r--firmware/lib/vboot_ui_legacy_wilco.c14
-rw-r--r--firmware/stub/tpm_lite_stub.c4
-rw-r--r--firmware/stub/vboot_api_stub.c5
-rw-r--r--firmware/stub/vboot_api_stub_init.c4
-rw-r--r--tests/vb2_ui_tests.c21
-rw-r--r--tests/vboot_ui_legacy_clamshell_beep_tests.c71
-rw-r--r--tests/vboot_ui_legacy_clamshell_tests.c12
-rw-r--r--tests/vboot_ui_legacy_menu_tests.c35
20 files changed, 155 insertions, 177 deletions
diff --git a/firmware/2lib/2ui.c b/firmware/2lib/2ui.c
index 14507ec9..eaa2bc4f 100644
--- a/firmware/2lib/2ui.c
+++ b/firmware/2lib/2ui.c
@@ -267,7 +267,7 @@ vb2_error_t ui_loop(struct vb2_context *ctx, enum vb2_screen root_screen_id,
}
/* Delay. */
- VbExSleepMs(KEY_DELAY_MS);
+ vb2ex_msleep(KEY_DELAY_MS);
}
return VB2_SUCCESS;
diff --git a/firmware/2lib/2ui_screens.c b/firmware/2lib/2ui_screens.c
index 3156fb51..50a61423 100644
--- a/firmware/2lib/2ui_screens.c
+++ b/firmware/2lib/2ui_screens.c
@@ -277,7 +277,7 @@ vb2_error_t developer_mode_init(struct vb2_ui_context *ui)
break;
}
- ui->start_time = VbExGetTimer();
+ ui->start_time = vb2ex_mtime();
return VB2_REQUEST_UI_CONTINUE;
}
@@ -326,24 +326,24 @@ vb2_error_t developer_mode_action(struct vb2_ui_context *ui)
if (ui->disable_timer)
return VB2_REQUEST_UI_CONTINUE;
- elapsed = VbExGetTimer() - ui->start_time;
+ elapsed = vb2ex_mtime() - ui->start_time;
/* If we're using short delay, wait 2 seconds and don't beep. */
- if (use_short && elapsed > 2 * VB_USEC_PER_SEC) {
+ if (use_short && elapsed > 2 * VB2_MSEC_PER_SEC) {
VB2_DEBUG("Booting default target after 2s\n");
ui->disable_timer = 1;
return vb2_ui_menu_select(ui);
}
/* Otherwise, beep at 20 and 20.5 seconds. */
- if ((ui->beep_count == 0 && elapsed > 20 * VB_USEC_PER_SEC) ||
- (ui->beep_count == 1 && elapsed > 20500 * VB_USEC_PER_MSEC)) {
- VbExBeep(250, 400);
+ if ((ui->beep_count == 0 && elapsed > 20 * VB2_MSEC_PER_SEC) ||
+ (ui->beep_count == 1 && elapsed > 20 * VB2_MSEC_PER_SEC + 500)) {
+ vb2ex_beep(250, 400);
ui->beep_count++;
}
/* Stop after 30 seconds. */
- if (elapsed > 30 * VB_USEC_PER_SEC) {
+ if (elapsed > 30 * VB2_MSEC_PER_SEC) {
VB2_DEBUG("Booting default target after 30s\n");
ui->disable_timer = 1;
return vb2_ui_menu_select(ui);
diff --git a/firmware/2lib/include/2api.h b/firmware/2lib/include/2api.h
index f8a1b4e0..4a6fe0d4 100644
--- a/firmware/2lib/include/2api.h
+++ b/firmware/2lib/include/2api.h
@@ -1220,4 +1220,37 @@ int vb2ex_physical_presence_pressed(void);
*/
uint32_t vb2ex_get_locale_count(void);
+/**
+ * Delay for at least the specified number of milliseconds.
+ *
+ * @param msec Duration in milliseconds.
+ */
+void vb2ex_msleep(uint32_t msec);
+
+/**
+ * Play a beep tone of the specified frequency in Hz for the duration msec.
+ *
+ * This is effectively a sleep call that makes noise. The implementation may
+ * beep at a fixed frequency if frequency support is not available. Regardless
+ * of whether any errors occur, the callback is expected to delay for the
+ * specified duration before returning.
+ *
+ * @param msec Duration of beep in milliseconds.
+ * @param frequency Sound frequency in Hz.
+ */
+void vb2ex_beep(uint32_t msec, uint32_t frequency);
+
+/*****************************************************************************/
+/* Timer. */
+
+/**
+ * Read a millisecond timer.
+ *
+ * This should have a sufficient number of bits to avoid wraparound for at
+ * least 10 minutes.
+ *
+ * @return Current timer value in milliseconds.
+ */
+uint32_t vb2ex_mtime(void);
+
#endif /* VBOOT_REFERENCE_2API_H_ */
diff --git a/firmware/2lib/include/2common.h b/firmware/2lib/include/2common.h
index 135beb96..e3a7989b 100644
--- a/firmware/2lib/include/2common.h
+++ b/firmware/2lib/include/2common.h
@@ -17,6 +17,10 @@
struct vb2_public_key;
+/* Time conversion constants. */
+#define VB2_USEC_PER_MSEC 1000ULL
+#define VB2_MSEC_PER_SEC 1000ULL
+
/*
* Return the min/max of A and B. This is used in macros which calculate the
* required buffer size, so can't be turned into a static inline function.
diff --git a/firmware/2lib/include/2return_codes.h b/firmware/2lib/include/2return_codes.h
index 989420aa..f94d0b20 100644
--- a/firmware/2lib/include/2return_codes.h
+++ b/firmware/2lib/include/2return_codes.h
@@ -63,8 +63,6 @@ enum vb2_return_code {
* vboot1-style errors
* TODO: deprecate these once they have all moved over to vboot2 style
*/
- /* VbExBeep() can't make sound in the background */
- VBERROR_NO_BACKGROUND_SOUND = 0x10019,
/* Peripheral busy. Cannot upgrade firmware at present. */
VBERROR_PERIPHERAL_BUSY = 0x10030,
/* Error writing VPD */
diff --git a/firmware/2lib/include/2ui.h b/firmware/2lib/include/2ui.h
index d4d2ba4b..eee1565f 100644
--- a/firmware/2lib/include/2ui.h
+++ b/firmware/2lib/include/2ui.h
@@ -65,7 +65,7 @@ struct vb2_ui_context {
/* For developer mode. */
int disable_timer;
- uint64_t start_time;
+ uint32_t start_time;
int beep_count;
/* For manual recovery. */
diff --git a/firmware/include/vboot_api.h b/firmware/include/vboot_api.h
index 4931d59f..a4eb23db 100644
--- a/firmware/include/vboot_api.h
+++ b/firmware/include/vboot_api.h
@@ -85,49 +85,6 @@ vb2_error_t VbSelectAndLoadKernel(struct vb2_context *ctx,
VbSelectAndLoadKernelParams *kparams);
/*****************************************************************************/
-/* Timer and delay */
-
-#define VB_USEC_PER_MSEC 1000ULL
-#define VB_MSEC_PER_SEC VB_USEC_PER_MSEC
-#define VB_USEC_PER_SEC (VB_USEC_PER_MSEC * VB_MSEC_PER_SEC)
-
-/**
- * Read a microsecond timer.
- *
- * This should have a sufficient number of bits to avoid wraparound for at
- * least 10 minutes. A 32-bit value would be plenty, but for historical
- * reasons this returns uint64_t.
- */
-uint64_t VbExGetTimer(void);
-
-/**
- * Delay for at least the specified number of milliseconds. Should be accurate
- * to within 10% (a requested delay of 1000 ms should result in an actual delay
- * of between 1000 - 1100 ms).
- */
-void VbExSleepMs(uint32_t msec);
-
-/**
- * Play a beep tone of the specified frequency in Hz and duration in msec.
- * This is effectively a VbSleep() variant that makes noise.
- *
- * If the audio codec can run in the background, then:
- * zero frequency means OFF, non-zero frequency means ON
- * zero msec means return immediately, non-zero msec means delay (and
- * then OFF if needed)
- * otherwise,
- * non-zero msec and non-zero frequency means ON, delay, OFF, return
- * zero msec or zero frequency means do nothing and return immediately
- *
- * The return value is used by the caller to determine the capabilities. The
- * implementation should always do the best it can if it cannot fully support
- * all features - for example, beeping at a fixed frequency if frequency
- * support is not available. At a minimum, it must delay for the specified
- * non-zero duration.
- */
-vb2_error_t VbExBeep(uint32_t msec, uint32_t frequency);
-
-/*****************************************************************************/
/* TPM (from tlcl_stub.h) */
/**
diff --git a/firmware/lib/vboot_audio.c b/firmware/lib/vboot_audio.c
index 5e44606d..7f9b5a5b 100644
--- a/firmware/lib/vboot_audio.c
+++ b/firmware/lib/vboot_audio.c
@@ -13,7 +13,7 @@
int audio_open_count = 0; /* Times audio has been opened */
static int audio_use_short; /* Use short delay? */
-static uint64_t open_time; /* Time of last open */
+static uint32_t open_time; /* Time of last open */
static int beep_count; /* Number of beeps so far */
/**
@@ -23,7 +23,7 @@ void vb2_audio_start(struct vb2_context *ctx)
{
struct vb2_gbb_header *gbb = vb2_get_gbb(ctx);
- open_time = VbExGetTimer(); /* "zero" starts now */
+ open_time = vb2ex_mtime(); /* "zero" starts now */
beep_count = 0;
/*
@@ -44,19 +44,19 @@ void vb2_audio_start(struct vb2_context *ctx)
*/
int vb2_audio_looping(void)
{
- uint64_t now = VbExGetTimer() - open_time;
+ uint32_t now = vb2ex_mtime() - open_time;
/* If we're using short delay, wait 2 seconds and don't beep */
if (audio_use_short)
- return (now < 2 * VB_USEC_PER_SEC);
+ return now < 2 * VB2_MSEC_PER_SEC;
/* Otherwise, beep at 20 and 20.5 seconds */
- if ((beep_count == 0 && now > 20000 * VB_MSEC_PER_SEC) ||
- (beep_count == 1 && now > 20500 * VB_MSEC_PER_SEC)) {
- VbExBeep(250, 400);
+ if ((beep_count == 0 && now > 20 * VB2_MSEC_PER_SEC) ||
+ (beep_count == 1 && now > 20 * VB2_MSEC_PER_SEC + 500)) {
+ vb2ex_beep(250, 400);
beep_count++;
}
/* Stop after 30 seconds */
- return (now < 30 * VB_USEC_PER_SEC);
+ return (now < 30 * VB2_MSEC_PER_SEC);
}
diff --git a/firmware/lib/vboot_kernel.c b/firmware/lib/vboot_kernel.c
index 7f6c880f..50a4d062 100644
--- a/firmware/lib/vboot_kernel.c
+++ b/firmware/lib/vboot_kernel.c
@@ -320,7 +320,7 @@ static vb2_error_t vb2_load_partition(
LoadKernelParams *params, uint32_t min_version,
VbSharedDataKernelPart *shpart, struct vb2_workbuf *wb)
{
- uint64_t read_us = 0, start_ts;
+ uint32_t read_ms = 0, start_ts;
struct vb2_workbuf wblocal = *wb;
/* Allocate kernel header buffer in workbuf */
@@ -328,13 +328,13 @@ static vb2_error_t vb2_load_partition(
if (!kbuf)
return VB2_ERROR_LOAD_PARTITION_WORKBUF;
- start_ts = VbExGetTimer();
+ start_ts = vb2ex_mtime();
if (VbExStreamRead(stream, KBUF_SIZE, kbuf)) {
VB2_DEBUG("Unable to read start of partition.\n");
shpart->check_result = VBSD_LKP_CHECK_READ_START;
return VB2_ERROR_LOAD_PARTITION_READ_VBLOCK;
}
- read_us += VbExGetTimer() - start_ts;
+ read_ms += vb2ex_mtime() - start_ts;
if (VB2_SUCCESS !=
vb2_verify_kernel_vblock(ctx, kbuf, KBUF_SIZE, kernel_subkey,
@@ -389,17 +389,19 @@ static vb2_error_t vb2_load_partition(
body_readptr += body_copied;
/* Read the kernel data */
- start_ts = VbExGetTimer();
+ start_ts = vb2ex_mtime();
if (body_toread && VbExStreamRead(stream, body_toread, body_readptr)) {
VB2_DEBUG("Unable to read kernel data.\n");
shpart->check_result = VBSD_LKP_CHECK_READ_DATA;
return VB2_ERROR_LOAD_PARTITION_READ_BODY;
}
- read_us += VbExGetTimer() - start_ts;
- VB2_DEBUG("read %" PRIu32 " KB in %" PRIu64 " ms at %" PRIu64 " KB/s.\n",
- (body_toread + KBUF_SIZE) / 1024, read_us / 1000,
- ((uint64_t)(body_toread + KBUF_SIZE) * 1000 * 1000) /
- (read_us * 1024));
+ read_ms += vb2ex_mtime() - start_ts;
+ if (read_ms == 0) /* Avoid division by 0 in speed calculation */
+ read_ms = 1;
+ VB2_DEBUG("read %u KB in %u ms at %u KB/s.\n",
+ (body_toread + KBUF_SIZE) / 1024, read_ms,
+ (uint32_t)(((body_toread + KBUF_SIZE) * VB2_MSEC_PER_SEC) /
+ (read_ms * 1024)));
/* Get key for preamble/data verification from the keyblock. */
struct vb2_public_key data_key;
diff --git a/firmware/lib/vboot_ui_legacy.c b/firmware/lib/vboot_ui_legacy.c
index f1288418..1b6a32e8 100644
--- a/firmware/lib/vboot_ui_legacy.c
+++ b/firmware/lib/vboot_ui_legacy.c
@@ -219,13 +219,13 @@ void vb2_error_beep(enum vb2_beep_type beep)
{
switch (beep) {
case VB_BEEP_FAILED:
- VbExBeep(250, 200);
+ vb2ex_beep(250, 200);
break;
default:
case VB_BEEP_NOT_ALLOWED:
- VbExBeep(120, 400);
- VbExSleepMs(120);
- VbExBeep(120, 400);
+ vb2ex_beep(120, 400);
+ vb2ex_msleep(120);
+ vb2ex_beep(120, 400);
break;
}
}
diff --git a/firmware/lib/vboot_ui_legacy_clamshell.c b/firmware/lib/vboot_ui_legacy_clamshell.c
index e91e090c..8054227f 100644
--- a/firmware/lib/vboot_ui_legacy_clamshell.c
+++ b/firmware/lib/vboot_ui_legacy_clamshell.c
@@ -130,7 +130,7 @@ int VbUserConfirms(struct vb2_context *ctx, uint32_t confirm_flags)
}
VbCheckDisplayKey(ctx, key, disp_current_screen, NULL);
}
- VbExSleepMs(KEY_DELAY_MS);
+ vb2ex_msleep(KEY_DELAY_MS);
} while (!shutdown_requested);
return -1;
@@ -182,7 +182,7 @@ static vb2_error_t vb2_altfw_ui(struct vb2_context *ctx)
VbCheckDisplayKey(ctx, key, disp_current_screen, NULL);
break;
}
- VbExSleepMs(KEY_DELAY_MS);
+ vb2ex_msleep(KEY_DELAY_MS);
} while (active);
/* Back to developer screen */
@@ -253,7 +253,7 @@ static vb2_error_t vb2_developer_ui(struct vb2_context *ctx)
vb2_nv_set(ctx, VB2_NV_DISABLE_DEV_REQUEST, 1);
VbDisplayScreen(ctx,
VB_SCREEN_TO_NORM_CONFIRMED, 0, NULL);
- VbExSleepMs(5000);
+ vb2ex_msleep(5 * VB2_MSEC_PER_SEC);
return VB2_REQUEST_REBOOT;
case -1:
VB2_DEBUG("shutdown requested\n");
@@ -324,7 +324,7 @@ static vb2_error_t vb2_developer_ui(struct vb2_context *ctx)
vb2_nv_set(ctx, VB2_NV_DISABLE_DEV_REQUEST, 1);
VbDisplayScreen(ctx,
VB_SCREEN_TO_NORM_CONFIRMED, 0, NULL);
- VbExSleepMs(5000);
+ vb2ex_msleep(5 * VB2_MSEC_PER_SEC);
return VB2_REQUEST_REBOOT;
case -1:
VB2_DEBUG("shutdown requested\n");
@@ -403,7 +403,7 @@ static vb2_error_t vb2_developer_ui(struct vb2_context *ctx)
break;
}
- VbExSleepMs(KEY_DELAY_MS);
+ vb2ex_msleep(KEY_DELAY_MS);
} while(vb2_audio_looping());
fallout:
@@ -465,7 +465,7 @@ static vb2_error_t recovery_ui(struct vb2_context *ctx)
vb2_check_diagnostic_key(ctx, key)) !=
VB2_SUCCESS)
return retval;
- VbExSleepMs(KEY_DELAY_MS);
+ vb2ex_msleep(KEY_DELAY_MS);
}
}
@@ -531,7 +531,7 @@ static vb2_error_t recovery_ui(struct vb2_context *ctx)
}
if (vb2_want_shutdown(ctx, key))
return VB2_REQUEST_SHUTDOWN;
- VbExSleepMs(KEY_DELAY_MS);
+ vb2ex_msleep(KEY_DELAY_MS);
}
return VB2_SUCCESS;
diff --git a/firmware/lib/vboot_ui_legacy_menu.c b/firmware/lib/vboot_ui_legacy_menu.c
index bcdd41ce..e9e9b4e8 100644
--- a/firmware/lib/vboot_ui_legacy_menu.c
+++ b/firmware/lib/vboot_ui_legacy_menu.c
@@ -106,7 +106,7 @@ static vb2_error_t vb2_draw_current_screen(struct vb2_context *ctx) {
static void vb2_flash_screen(struct vb2_context *ctx)
{
VbDisplayMenu(ctx, VB_SCREEN_BLANK, 0, 0, 0);
- VbExSleepMs(50);
+ vb2ex_msleep(50);
vb2_draw_current_screen(ctx);
}
@@ -414,7 +414,7 @@ static vb2_error_t to_norm_action(struct vb2_context *ctx)
vb2_nv_set(ctx, VB2_NV_DISABLE_DEV_REQUEST, 1);
vb2_change_menu(VB_MENU_TO_NORM_CONFIRMED, 0);
vb2_draw_current_screen(ctx);
- VbExSleepMs(5000);
+ vb2ex_msleep(5 * VB2_MSEC_PER_SEC);
return VB2_REQUEST_REBOOT;
}
@@ -837,7 +837,7 @@ static vb2_error_t vb2_developer_legacy_menu(struct vb2_context *ctx)
if (key != 0)
vb2_audio_start(ctx);
- VbExSleepMs(KEY_DELAY_MS);
+ vb2ex_msleep(KEY_DELAY_MS);
/* If dev mode was disabled, loop forever (never timeout) */
} while (disable_dev_boot ? 1 : vb2_audio_looping());
@@ -916,7 +916,7 @@ static vb2_error_t recovery_ui(struct vb2_context *ctx)
if (ret != VB2_REQUEST_UI_CONTINUE)
return ret;
}
- VbExSleepMs(KEY_DELAY_MS);
+ vb2ex_msleep(KEY_DELAY_MS);
}
}
diff --git a/firmware/lib/vboot_ui_legacy_wilco.c b/firmware/lib/vboot_ui_legacy_wilco.c
index fc379ee4..59a49684 100644
--- a/firmware/lib/vboot_ui_legacy_wilco.c
+++ b/firmware/lib/vboot_ui_legacy_wilco.c
@@ -109,7 +109,7 @@ static vb2_error_t vb2_enter_vendor_data_ui(struct vb2_context *ctx,
&data);
break;
}
- VbExSleepMs(KEY_DELAY_MS);
+ vb2ex_msleep(KEY_DELAY_MS);
if (++blink_count == blinks) {
blink_count = 0;
@@ -182,7 +182,7 @@ static vb2_error_t vb2_confirm_vendor_data_ui(struct vb2_context *ctx,
"set.\n"
"System will now shutdown\n",
NULL, VB_BEEP_FAILED);
- VbExSleepMs(5000);
+ vb2ex_msleep(5 * VB2_MSEC_PER_SEC);
return VB2_REQUEST_SHUTDOWN;
}
} else {
@@ -198,7 +198,7 @@ static vb2_error_t vb2_confirm_vendor_data_ui(struct vb2_context *ctx,
VB_SCREEN_CONFIRM_VENDOR_DATA, data);
break;
}
- VbExSleepMs(KEY_DELAY_MS);
+ vb2ex_msleep(KEY_DELAY_MS);
} while (1);
return VB2_SUCCESS;
}
@@ -285,11 +285,11 @@ vb2_error_t vb2_diagnostics_ui(struct vb2_context *ctx)
int button_pressed = 0;
vb2_error_t result = VB2_REQUEST_REBOOT;
int action_confirmed = 0;
- uint64_t start_time_us;
+ uint32_t start_time_ms;
VbDisplayScreen(ctx, VB_SCREEN_CONFIRM_DIAG, 0, NULL);
- start_time_us = VbExGetTimer();
+ start_time_ms = vb2ex_mtime();
/* We'll loop until the user decides what to do */
do {
@@ -334,12 +334,12 @@ vb2_error_t vb2_diagnostics_ui(struct vb2_context *ctx)
NULL);
break;
}
- if (VbExGetTimer() - start_time_us >= 30 * VB_USEC_PER_SEC) {
+ if (vb2ex_mtime() - start_time_ms >= 30 * VB2_MSEC_PER_SEC) {
VB2_DEBUG("vb2_diagnostics_ui() - timeout\n");
break;
}
if (active) {
- VbExSleepMs(KEY_DELAY_MS);
+ vb2ex_msleep(KEY_DELAY_MS);
}
} while (active);
diff --git a/firmware/stub/tpm_lite_stub.c b/firmware/stub/tpm_lite_stub.c
index 54accb56..7d3e5d28 100644
--- a/firmware/stub/tpm_lite_stub.c
+++ b/firmware/stub/tpm_lite_stub.c
@@ -268,8 +268,8 @@ uint32_t VbExTpmSendReceive(const uint8_t* request, uint32_t request_length,
VB2_DEBUG("response (%d bytes):\n", *response_length);
DbgPrintBytes(response, *response_length);
VB2_DEBUG("execution time: %dms\n",
- (int) ((after.tv_sec - before.tv_sec) * VB_MSEC_PER_SEC +
- (after.tv_usec - before.tv_usec) / VB_USEC_PER_MSEC));
+ (int) ((after.tv_sec - before.tv_sec) * VB2_MSEC_PER_SEC +
+ (after.tv_usec - before.tv_usec) / VB2_USEC_PER_MSEC));
#endif
#ifndef NDEBUG
diff --git a/firmware/stub/vboot_api_stub.c b/firmware/stub/vboot_api_stub.c
index f59c4009..17f42070 100644
--- a/firmware/stub/vboot_api_stub.c
+++ b/firmware/stub/vboot_api_stub.c
@@ -17,13 +17,12 @@
#include "vboot_api.h"
#include "vboot_test.h"
-void VbExSleepMs(uint32_t msec)
+void vb2ex_msleep(uint32_t msec)
{
}
-vb2_error_t VbExBeep(uint32_t msec, uint32_t frequency)
+void vb2ex_beep(uint32_t msec, uint32_t frequency)
{
- return VB2_SUCCESS;
}
vb2_error_t VbExDisplayScreen(uint32_t screen_type, uint32_t locale,
diff --git a/firmware/stub/vboot_api_stub_init.c b/firmware/stub/vboot_api_stub_init.c
index 4688a7ea..bd5c0c2b 100644
--- a/firmware/stub/vboot_api_stub_init.c
+++ b/firmware/stub/vboot_api_stub_init.c
@@ -13,11 +13,11 @@
#include "2common.h"
#include "vboot_api.h"
-uint64_t VbExGetTimer(void)
+uint32_t vb2ex_mtime(void)
{
struct timeval tv;
gettimeofday(&tv, NULL);
- return (uint64_t)tv.tv_sec * VB_USEC_PER_SEC + (uint64_t)tv.tv_usec;
+ return tv.tv_sec * VB2_MSEC_PER_SEC + tv.tv_usec / VB2_USEC_PER_MSEC;
}
vb2_error_t vb2ex_commit_data(struct vb2_context *ctx)
diff --git a/tests/vb2_ui_tests.c b/tests/vb2_ui_tests.c
index 13c037c1..6f5ca68b 100644
--- a/tests/vb2_ui_tests.c
+++ b/tests/vb2_ui_tests.c
@@ -46,9 +46,9 @@ static int mock_key_trusted[64];
static int mock_key_count;
static int mock_key_total;
-static uint64_t mock_get_timer_last;
-static uint64_t mock_time;
-static const uint64_t mock_time_start = 31ULL * VB_USEC_PER_SEC;
+static uint32_t mock_get_timer_last;
+static uint32_t mock_time;
+static const uint32_t mock_time_start = 31ULL * VB2_MSEC_PER_SEC;
static int mock_vbexbeep_called;
static enum vb2_dev_default_boot mock_default_boot;
@@ -273,21 +273,20 @@ uint32_t VbExKeyboardReadWithFlags(uint32_t *key_flags)
return 0;
}
-uint64_t VbExGetTimer(void)
+uint32_t vb2ex_mtime(void)
{
mock_get_timer_last = mock_time;
return mock_time;
}
-void VbExSleepMs(uint32_t msec)
+void vb2ex_msleep(uint32_t msec)
{
- mock_time += msec * VB_USEC_PER_MSEC;
+ mock_time += msec;
}
-vb2_error_t VbExBeep(uint32_t msec, uint32_t frequency)
+void vb2ex_beep(uint32_t msec, uint32_t frequency)
{
mock_vbexbeep_called++;
- return VB2_SUCCESS;
}
enum vb2_dev_default_boot vb2_get_dev_boot_target(struct vb2_context *c)
@@ -349,7 +348,7 @@ static void developer_tests(void)
MOCK_IGNORE, MOCK_IGNORE);
displayed_no_extra();
TEST_TRUE(mock_get_timer_last - mock_time_start >=
- 30 * VB_USEC_PER_SEC, " finished delay");
+ 30 * VB2_MSEC_PER_SEC, " finished delay");
TEST_EQ(mock_vbexbeep_called, 2, " beeped twice");
TEST_EQ(mock_vbtlk_count, mock_vbtlk_total, " used up mock_vbtlk");
@@ -364,7 +363,7 @@ static void developer_tests(void)
MOCK_IGNORE, MOCK_IGNORE);
displayed_no_extra();
TEST_TRUE(mock_get_timer_last - mock_time_start >=
- 30 * VB_USEC_PER_SEC, " finished delay");
+ 30 * VB2_MSEC_PER_SEC, " finished delay");
TEST_EQ(mock_vbexbeep_called, 2, " beeped twice");
TEST_EQ(mock_vbtlk_count, mock_vbtlk_total, " used up mock_vbtlk");
@@ -377,7 +376,7 @@ static void developer_tests(void)
MOCK_IGNORE, MOCK_IGNORE);
displayed_no_extra();
TEST_TRUE(mock_get_timer_last - mock_time_start >=
- 30 * VB_USEC_PER_SEC, " finished delay");
+ 30 * VB2_MSEC_PER_SEC, " finished delay");
TEST_EQ(mock_vbexbeep_called, 2, " beeped twice");
TEST_EQ(mock_vbtlk_count, mock_vbtlk_total, " used up mock_vbtlk");
diff --git a/tests/vboot_ui_legacy_clamshell_beep_tests.c b/tests/vboot_ui_legacy_clamshell_beep_tests.c
index 9d0d12e7..cb0b4765 100644
--- a/tests/vboot_ui_legacy_clamshell_beep_tests.c
+++ b/tests/vboot_ui_legacy_clamshell_beep_tests.c
@@ -37,7 +37,6 @@ typedef struct {
typedef struct {
const char *name;
uint32_t gbb_flags;
- vb2_error_t beep_return;
uint32_t keypress_key;
int keypress_at_count;
int num_events;
@@ -47,16 +46,14 @@ typedef struct {
test_case_t test[] = {
{ "VbBootDeveloperSoundTest( fast )",
- VB2_GBB_FLAG_DEV_SCREEN_SHORT_DELAY, VBERROR_NO_BACKGROUND_SOUND,
- 0, 0,
+ VB2_GBB_FLAG_DEV_SCREEN_SHORT_DELAY, 0, 0,
1,
{
{0, 0, 2000}, // off and return at 2 seconds
}},
{ "VbBootDeveloperSoundTest( normal )",
- 0, VBERROR_NO_BACKGROUND_SOUND,
- 0, 0,
+ 0, 0, 0,
3,
{
{250, 400, 20000}, // first beep at 20 seconds
@@ -67,8 +64,7 @@ test_case_t test[] = {
// Now with some keypresses
{ "VbBootDeveloperSoundTest( normal, Ctrl-D )",
- 0, VBERROR_NO_BACKGROUND_SOUND,
- 4, 20400, // Ctrl-D between beeps
+ 0, 4, 20400, // Ctrl-D between beeps
2,
{
{250, 400, 20000}, // first beep at 20 seconds
@@ -76,8 +72,7 @@ test_case_t test[] = {
}},
{ "VbBootDeveloperSoundTest( normal, Ctrl-U not allowed )",
- 0, VBERROR_NO_BACKGROUND_SOUND,
- 21, 10000, // Ctrl-U at 10 seconds
+ 0, 21, 10000, // Ctrl-U at 10 seconds
5,
{
{120, 400, 10000}, // complains about Ctrl-U (one beep)
@@ -94,14 +89,13 @@ static uint8_t workbuf[VB2_KERNEL_WORKBUF_RECOMMENDED_SIZE]
static struct vb2_context *ctx;
static struct vb2_shared_data *sd;
static struct vb2_gbb_header gbb;
-static int current_time;
-static uint64_t current_ticks;
+static uint32_t current_time;
+static uint32_t current_ticks;
static int current_event;
static int max_events;
static int matched_events;
static int kbd_fire_at;
static uint32_t kbd_fire_key;
-static vb2_error_t beep_return;
static note_event_t *expected_event;
/* Audio open count, so we can reset it */
@@ -127,8 +121,6 @@ static void ResetMocks(void)
current_event = 0;
kbd_fire_at = 0;
kbd_fire_key = 0;
-
- beep_return = VB2_SUCCESS;
audio_open_count = 0;
matched_events = 0;
@@ -181,76 +173,72 @@ uint32_t VbExKeyboardRead(void)
uint32_t tmp;
uint32_t now;
- VbExSleepMs(KBD_READ_TIME);
+ vb2ex_msleep(KBD_READ_TIME);
now = current_time;
if (kbd_fire_key && now >= kbd_fire_at) {
- VB2_DEBUG(" VbExKeyboardRead() - returning %d at %d msec\n",
+ VB2_DEBUG("returning %d at %d msec\n",
kbd_fire_key, now);
tmp = kbd_fire_key;
kbd_fire_key = 0;
return tmp;
}
- VB2_DEBUG(" VbExKeyboardRead() - returning %d at %d msec\n",
- 0, now);
+ VB2_DEBUG("returning %d at %d msec\n", 0, now);
return 0;
}
-void VbExSleepMs(uint32_t msec)
+void vb2ex_msleep(uint32_t msec)
{
- current_ticks += (uint64_t)msec * VB_USEC_PER_MSEC;
- current_time = current_ticks / VB_USEC_PER_MSEC;
- VB2_DEBUG("VbExSleepMs(%d) -> %d\n", msec, current_time);
+ current_ticks += msec;
+ current_time = current_ticks;
+ VB2_DEBUG("msec=%d at %d msec\n", msec, current_time);
}
-uint64_t VbExGetTimer(void)
+uint32_t vb2ex_mtime(void)
{
return current_ticks;
}
-vb2_error_t VbExBeep(uint32_t msec, uint32_t frequency)
+void vb2ex_beep(uint32_t msec, uint32_t frequency)
{
- VB2_DEBUG("VbExBeep(%d, %d) at %d msec\n",
+ VB2_DEBUG("msec=%d, frequency=%d at %d msec\n",
msec, frequency, current_time);
if (current_event < max_events &&
msec == expected_event[current_event].msec &&
frequency == expected_event[current_event].freq &&
- abs(current_time - expected_event[current_event].time)
- < TIME_FUZZ ) {
+ (current_time - expected_event[current_event].time) < TIME_FUZZ)
matched_events++;
- }
if (msec)
- VbExSleepMs(msec);
+ vb2ex_msleep(msec);
current_event++;
- return beep_return;
}
vb2_error_t VbExDisplayScreen(uint32_t screen_type, uint32_t locale,
const VbScreenData *data)
{
- switch(screen_type) {
+ switch (screen_type) {
case VB_SCREEN_BLANK:
- VB2_DEBUG("VbExDisplayScreen(BLANK)\n");
+ VB2_DEBUG("screen_type=BLANK\n");
break;
case VB_SCREEN_DEVELOPER_WARNING:
- VB2_DEBUG("VbExDisplayScreen(DEV)\n");
+ VB2_DEBUG("screen_type=DEV\n");
break;
case VB_SCREEN_RECOVERY_INSERT:
- VB2_DEBUG("VbExDisplayScreen(INSERT)\n");
+ VB2_DEBUG("screen_type=INSERT\n");
break;
case VB_SCREEN_RECOVERY_NO_GOOD:
- VB2_DEBUG("VbExDisplayScreen(NO_GOOD)\n");
+ VB2_DEBUG("screen_type=NO_GOOD\n");
break;
case VB_SCREEN_OS_BROKEN:
- VB2_DEBUG("VbExDisplayScreen(BROKEN)\n");
+ VB2_DEBUG("screen_type=BROKEN\n");
break;
default:
- VB2_DEBUG("VbExDisplayScreen(%d)\n", screen_type);
+ VB2_DEBUG("screen_type=%#x\n", screen_type);
}
- VB2_DEBUG(" current_time is %d msec\n", current_time);
+ VB2_DEBUG("current_time is %d msec\n", current_time);
return VB2_SUCCESS;
}
@@ -262,17 +250,16 @@ static void VbBootDeveloperSoundTest(void)
int i;
int num_tests = sizeof(test) / sizeof(test_case_t);
- for (i=0; i<num_tests; i++) {
+ for (i = 0; i < num_tests; i++) {
VB2_DEBUG("STARTING %s ...\n", test[i].name);
ResetMocks();
gbb.flags = test[i].gbb_flags;
- beep_return = test[i].beep_return;
kbd_fire_key = test[i].keypress_key;
kbd_fire_at = test[i].keypress_at_count;
max_events = test[i].num_events;
expected_event = test[i].notes;
- (void) VbBootDeveloperLegacyClamshell(ctx);
- VbExBeep(0, 0); /* Dummy call to determine end time */
+ VbBootDeveloperLegacyClamshell(ctx);
+ vb2ex_beep(0, 0); /* Dummy call to determine end time */
VB2_DEBUG("INFO: matched %d total %d expected %d\n",
matched_events, current_event, test[i].num_events);
TEST_TRUE(matched_events == test[i].num_events &&
diff --git a/tests/vboot_ui_legacy_clamshell_tests.c b/tests/vboot_ui_legacy_clamshell_tests.c
index 5d973e66..84f7ea72 100644
--- a/tests/vboot_ui_legacy_clamshell_tests.c
+++ b/tests/vboot_ui_legacy_clamshell_tests.c
@@ -35,7 +35,7 @@ static int vbtlk_expect_fixed;
static int vbtlk_expect_removable;
static int vbexlegacy_called;
static enum VbAltFwIndex_t altfw_num;
-static uint64_t current_ticks;
+static uint32_t current_ticks;
static int trust_ec;
static int virtdev_set;
static uint32_t virtdev_fail;
@@ -192,12 +192,12 @@ vb2_error_t VbExLegacy(enum VbAltFwIndex_t _altfw_num)
return VB2_ERROR_UNKNOWN;
}
-void VbExSleepMs(uint32_t msec)
+void vb2ex_msleep(uint32_t msec)
{
- current_ticks += (uint64_t)msec * VB_USEC_PER_MSEC;
+ current_ticks += msec;
}
-uint64_t VbExGetTimer(void)
+uint32_t vb2ex_mtime(void)
{
return current_ticks;
}
@@ -1541,7 +1541,7 @@ static void VbBootDiagTest(void)
" blank screen");
TEST_EQ(tpm_set_mode_called, 0, " no tpm call");
TEST_EQ(vbexlegacy_called, 0, " not legacy");
- TEST_EQ(current_ticks, 30 * VB_USEC_PER_SEC,
+ TEST_EQ(current_ticks, 30 * VB2_MSEC_PER_SEC,
" waited for 30 seconds");
/* Esc key pressed. */
@@ -1568,7 +1568,7 @@ static void VbBootDiagTest(void)
" blank screen");
TEST_EQ(tpm_set_mode_called, 0, " no tpm call");
TEST_EQ(vbexlegacy_called, 0, " not legacy");
- TEST_TRUE(current_ticks < VB_USEC_PER_SEC, " didn't wait long");
+ TEST_TRUE(current_ticks < VB2_MSEC_PER_SEC, " didn't wait long");
/* Power button pressed but not released. */
ResetMocks();
diff --git a/tests/vboot_ui_legacy_menu_tests.c b/tests/vboot_ui_legacy_menu_tests.c
index 6fa2d404..324c6b41 100644
--- a/tests/vboot_ui_legacy_menu_tests.c
+++ b/tests/vboot_ui_legacy_menu_tests.c
@@ -190,8 +190,8 @@ vb2_error_t VbDisplayScreen(struct vb2_context *c, uint32_t screen, int force,
{
if (screens_count < ARRAY_SIZE(screens_displayed))
screens_displayed[screens_count++] = screen;
- printf("VbDisplayScreen: screens_displayed[%d] = %#x\n",
- screens_count - 1, screen);
+ VB2_DEBUG("screens_displayed[%d] = %#x\n",
+ screens_count - 1, screen);
return VB2_SUCCESS;
}
@@ -201,11 +201,11 @@ vb2_error_t VbDisplayMenu(struct vb2_context *c, uint32_t screen, int force,
if (screens_count < ARRAY_SIZE(screens_displayed))
screens_displayed[screens_count++] = screen;
else
- printf("Ran out of screens_displayed entries!\n");
- printf("VbDisplayMenu: screens_displayed[%d] = %#x,"
- " selected_index = %u, disabled_idx_mask = %#x\n",
- screens_count - 1, screen,
- selected_index, disabled_idx_mask);
+ VB2_DEBUG("Ran out of screens_displayed entries!\n");
+ VB2_DEBUG("screens_displayed[%d] = %#x,"
+ " selected_index = %u, disabled_idx_mask = %#x\n",
+ screens_count - 1, screen,
+ selected_index, disabled_idx_mask);
return VB2_SUCCESS;
}
@@ -216,13 +216,12 @@ vb2_error_t VbDisplayDebugInfo(struct vb2_context *c)
return VB2_SUCCESS;
}
-vb2_error_t VbExBeep(uint32_t msec, uint32_t frequency)
+void vb2ex_beep(uint32_t msec, uint32_t frequency)
{
if (beeps_count < ARRAY_SIZE(beeps_played))
beeps_played[beeps_count++] = frequency;
- printf("VbExBeep: beeps_played[%d] = %dHz for %dms\n",
- beeps_count - 1, frequency, msec);
- return VB2_SUCCESS;
+ VB2_DEBUG("beeps_played[%d] = %dHz for %dms\n",
+ beeps_count - 1, frequency, msec);
}
void vb2_enable_developer_mode(struct vb2_context *c)
@@ -237,7 +236,7 @@ static void VbBootDevTest(void)
{
int i;
- printf("Testing VbBootDeveloperLegacyMenu()...\n");
+ VB2_DEBUG("Testing VbBootDeveloperLegacyMenu()...\n");
/* Proceed after timeout */
ResetMocksForDeveloper();
@@ -1252,14 +1251,14 @@ static void VbBootDevTest(void)
TEST_EQ(beeps_count, 0, " no beeps for debug info");
- printf("...done.\n");
+ VB2_DEBUG("...done.\n");
}
static void VbBootRecTest(void)
{
int i;
- printf("Testing VbBootRecoveryLegacyMenu()...\n");
+ VB2_DEBUG("Testing VbBootRecoveryLegacyMenu()...\n");
/* Shutdown requested in BROKEN */
ResetMocks();
@@ -1842,14 +1841,14 @@ static void VbBootRecTest(void)
TEST_EQ(screens_count, 3, " no extra screens");
TEST_EQ(beeps_count, 0, " no beeps");
- printf("...done.\n");
+ VB2_DEBUG("...done.\n");
}
static void VbTestLanguageMenu(void)
{
int i;
- printf("Testing VbTestLanguageMenu()...\n");
+ VB2_DEBUG("Testing VbTestLanguageMenu()...\n");
/* Navigate to language menu from BROKEN */
ResetMocks();
@@ -2030,14 +2029,14 @@ static void VbTestLanguageMenu(void)
TEST_EQ(screens_count, i, " no extra screens");
TEST_EQ(beeps_count, 0, " no beeps");
- printf("...done.\n");
+ VB2_DEBUG("...done.\n");
}
static void VbNavigationTest(void)
{
int i;
- printf("Testing long navigation sequences...");
+ VB2_DEBUG("Testing long navigation sequences...");
/*
* NOGOOD, OPTIONS, LANGUAGE, TODEV, LANGUAGE, TODEV,