summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile14
-rw-r--r--firmware/include/vboot_api.h16
-rw-r--r--firmware/lib/include/vboot_audio.h13
-rw-r--r--firmware/lib/include/vboot_audio_private.h57
-rw-r--r--firmware/lib/vboot_audio.c310
-rw-r--r--firmware/lib/vboot_ui.c16
-rw-r--r--firmware/lib/vboot_ui_menu.c25
-rw-r--r--tests/vboot_api_devmode_tests.c436
-rw-r--r--tests/vboot_api_kernel2_tests.c2
-rw-r--r--tests/vboot_audio_tests.c224
-rw-r--r--tests/vboot_detach_menu_tests.c2
11 files changed, 261 insertions, 854 deletions
diff --git a/Makefile b/Makefile
index 9cbcf264..3c12e79b 100644
--- a/Makefile
+++ b/Makefile
@@ -165,10 +165,6 @@ CC ?= gcc
CFLAGS += -DCHROMEOS_ENVIRONMENT -Wall ${WERROR} ${DEBUG_FLAGS}
endif
-ifneq (${CUSTOM_MUSIC},)
-CFLAGS += -DCUSTOM_MUSIC
-endif
-
ifneq (${DEBUG},)
CFLAGS += -DVBOOT_DEBUG
endif
@@ -739,8 +735,7 @@ TEST_NAMES = \
tests/vboot_api_kernel5_tests \
tests/vboot_api_kernel6_tests \
tests/vboot_detach_menu_tests \
- tests/vboot_audio_tests \
- tests/vboot_common_tests \
+tests/vboot_common_tests \
tests/vboot_display_tests \
tests/vboot_kernel_tests \
tests/verify_kernel
@@ -1313,12 +1308,6 @@ ${BUILD}/tests/tlcl_tests: \
${TLCL_OBJS_FOR_TEST}
TEST_OBJS += ${TLCL_OBJS_FOR_TEST}
-${BUILD}/tests/vboot_audio_tests: OBJS += \
- ${BUILD}/firmware/lib/vboot_audio_for_test.o
-${BUILD}/tests/vboot_audio_tests: \
- ${BUILD}/firmware/lib/vboot_audio_for_test.o
-TEST_OBJS += ${BUILD}/firmware/lib/vboot_audio_for_test.o
-
ifeq (${TPM2_MODE},)
# TODO(apronin): tests for TPM2 case?
TLCL_TEST_BINS = $(addprefix ${BUILD}/,${TLCL_TEST_NAMES})
@@ -1443,7 +1432,6 @@ endif
${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel5_tests
${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel6_tests
${RUNTEST} ${BUILD_RUN}/tests/vboot_detach_menu_tests
- ${RUNTEST} ${BUILD_RUN}/tests/vboot_audio_tests
${RUNTEST} ${BUILD_RUN}/tests/vboot_common_tests
${RUNTEST} ${BUILD_RUN}/tests/vboot_display_tests
${RUNTEST} ${BUILD_RUN}/tests/vboot_kernel_tests
diff --git a/firmware/include/vboot_api.h b/firmware/include/vboot_api.h
index cedf266d..c71dfbf1 100644
--- a/firmware/include/vboot_api.h
+++ b/firmware/include/vboot_api.h
@@ -457,18 +457,12 @@ void VbExDebug(const char *format, ...)
/* Timer and delay (first two from utility.h) */
/**
- * Read a high-resolution timer. Returns the current timer value in arbitrary
- * units.
+ * Read a microsecond timer.
*
- * This is intended for benchmarking, so this call MUST be fast. The timer
- * frequency must be >1 KHz (preferably >1 MHz), and the timer must not wrap
- * around for at least 10 minutes. It is preferable (but not required) that
- * the timer be initialized to 0 at boot.
- *
- * It is assumed that the firmware has some other way of communicating the
- * timer frequency to the OS. For example, on x86 we use TSC, and the OS
- * kernel reports the initial TSC value at kernel-start and calculates the
- * frequency. */
+ * 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);
/**
diff --git a/firmware/lib/include/vboot_audio.h b/firmware/lib/include/vboot_audio.h
index afcac140..05f22f92 100644
--- a/firmware/lib/include/vboot_audio.h
+++ b/firmware/lib/include/vboot_audio.h
@@ -10,22 +10,15 @@
#include "vboot_api.h"
-typedef struct VbAudioContext VbAudioContext;
-
/**
- * Initialization function. Returns context for processing dev-mode delay.
+ * Initialization function.
*/
-VbAudioContext *VbAudioOpen(VbCommonParams *cparams);
+void vb2_audio_start(struct vb2_context *ctx);
/**
* Caller should loop without extra delay until this returns false.
*/
-int VbAudioLooping(VbAudioContext *audio);
-
-/**
- * Caller should call this prior to booting.
- */
-void VbAudioClose(VbAudioContext *audio);
+int vb2_audio_looping(void);
#endif /* VBOOT_REFERENCE_VBOOT_AUDIO_H_ */
diff --git a/firmware/lib/include/vboot_audio_private.h b/firmware/lib/include/vboot_audio_private.h
deleted file mode 100644
index 902bc62e..00000000
--- a/firmware/lib/include/vboot_audio_private.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- *
- * Private declarations for vboot_audio.c. Defined here for easier testing.
- */
-
-#ifndef VBOOT_REFERENCE_VBOOT_AUDIO_PRIVATE_H_
-#define VBOOT_REFERENCE_VBOOT_AUDIO_PRIVATE_H_
-
-#include "vboot_api.h"
-#include "vboot_audio.h"
-
-typedef struct VbDevMusicNote {
- uint16_t msec;
- uint16_t frequency;
-} __attribute__((packed)) VbDevMusicNote;
-
-typedef struct VbDevMusic {
- uint8_t sig[4]; /* "$SND" */
- uint32_t checksum; /* crc32 over count & all notes */
- uint32_t count; /* number of notes */
- VbDevMusicNote notes[1]; /* gcc allows [0], MSVC doesn't */
- /* more VbDevMusicNotes follow immediately */
-} __attribute__((packed)) VbDevMusic;
-
-struct VbAudioContext {
- /* note tracking */
- VbDevMusicNote *music_notes;
- uint32_t note_count;
- uint32_t next_note;
-
- /* implementation flags */
- int background_beep;
- int free_notes_when_done;
-
- /* sound tracking */
- uint16_t current_frequency;
- uint64_t play_until;
- uint64_t last_time;
-};
-
-#ifdef FOR_TEST
-#define CUSTOM_MUSIC
-#endif
-
-#ifdef CUSTOM_MUSIC
-void *VbExGetMusicPtr(void);
-uint32_t VbExMaxMusicSize(void);
-#define CUSTOM_MUSIC_NOTES VbExGetMusicPtr()
-#define CUSTOM_MUSIC_MAXSIZE VbExMaxMusicSize()
-#else
-#define CUSTOM_MUSIC_NOTES 0
-#define CUSTOM_MUSIC_MAXSIZE 0
-#endif
-
-#endif /* VBOOT_REFERENCE_VBOOT_AUDIO_PRIVATE_H_ */
diff --git a/firmware/lib/vboot_audio.c b/firmware/lib/vboot_audio.c
index e1988e03..42a50798 100644
--- a/firmware/lib/vboot_audio.c
+++ b/firmware/lib/vboot_audio.c
@@ -7,309 +7,63 @@
#include "2sysincludes.h"
#include "2common.h"
+#include "2misc.h"
#include "sysincludes.h"
-#include "crc32.h"
-#include "gbb_header.h"
#include "utility.h"
#include "vboot_api.h"
#include "vboot_audio.h"
-#include "vboot_audio_private.h"
#include "vboot_common.h"
-/* BIOS doesn't have /usr/include */
-#ifndef UINT_MAX
-#define UINT_MAX 4294967295U /* 0xffffffff */
-#endif
+/* 1000 microsecond ticks per msec */
+#define TICKS_PER_MSEC 1000
-/*
- * Need one second of noise in the first 22 seconds.
- * Total delay >= 30 seconds, <= 5 minutes.
- */
-#define REQUIRED_NOISE_TIME 1000
-#define REQUIRED_NOISE_WITHIN 22000
-#define REQUIRED_TOTAL_DELAY 30000
-#define MAX_CUSTOM_DELAY 300000
-
-/* These are visible externally only to make testing easier */
-VbDevMusicNote default_notes_[] = { {20000, 0}, /* 20 seconds */
- {250, 400}, /* two beeps */
- {250, 0},
- {250, 400},
- {9250, 0} }; /* total 30 seconds */
-uint32_t default_count_ = sizeof(default_notes_) / sizeof(VbDevMusicNote);
-
-VbDevMusicNote short_notes_[] = { {2000, 0} }; /* two seconds */
-uint32_t short_count_ = sizeof(short_notes_) / sizeof(VbDevMusicNote);
-
-/* No need to dynamically allocate this, is there? */
-static VbAudioContext au;
-
-/* Flag to override GBB_FLAG_DEV_SCREEN_SHORT_DELAY gbb flag */
-int audio_open_count = 0;
-
-/* Convert from msecs to VbExGetTimer() units. */
-static uint64_t ticks_per_msec = 0; /* Initialized by VbAudioOpen() */
-static uint64_t VbMsecToTicks(uint16_t msec) {
- return ticks_per_msec * msec;
-}
-
-/**
- * Find and return a valid set of note events.
- *
- * We'll use the user's struct if possible, but we will still enforce the
- * 30-second timeout and require at least a second of audible noise within that
- * period. We allocate storage for two reasons: the user's struct will be in
- * flash, which is slow to read, and we may need one extra note at the end to
- * pad out the user's notes to a full 30 seconds. The caller should free it
- * when finished.
- */
-static void VbGetDevMusicNotes(VbAudioContext *audio, int use_short)
-{
- VbDevMusicNote *notebuf = 0;
- VbDevMusicNote *builtin = 0;
- VbDevMusic *hdr = CUSTOM_MUSIC_NOTES;
- uint32_t maxsize = CUSTOM_MUSIC_MAXSIZE; /* always <= flash size (8M) */
- uint32_t maxnotes, mysum, mylen, i;
- uint32_t this_msecs, on_msecs, total_msecs;
- uint32_t count;
-
- VB2_DEBUG("VbGetDevMusicNotes: use_short is %d, hdr is %p, "
- "maxsize is %d\n", use_short, hdr, maxsize);
-
- if (use_short) {
- builtin = short_notes_;
- count = short_count_;
- goto nope;
- }
-
- builtin = default_notes_;
- count = default_count_;
-
- /* If we can't beep in the background, don't allow customization. */
- if (!audio->background_beep)
- goto nope;
-
- if (!hdr || maxsize < sizeof(VbDevMusic))
- goto nope;
-
- if (0 != memcmp(hdr->sig, "$SND", sizeof(hdr->sig))) {
- VB2_DEBUG("VbGetDevMusicNotes: bad sig\n");
- goto nope;
- }
-
- /*
- * How many notes will fit in the flash region? One more than you'd
- * think, because there's one note in the header itself.
- */
- maxnotes = 1 + (maxsize - sizeof(VbDevMusic)) / sizeof(VbDevMusicNote);
- if (hdr->count == 0 || hdr->count > maxnotes) {
- VB2_DEBUG("VbGetDevMusicNotes: count=%d maxnotes=%d\n",
- hdr->count, maxnotes);
- goto nope;
- }
-
- /*
- * CUSTOM_MUSIC_MAXSIZE can't be larger than the size of the flash
- * (around 8M or so) so this isn't really necessary, but let's be safe
- * anyway.
- */
- if ((sizeof(VbDevMusicNote) > UINT_MAX / hdr->count) ||
- (sizeof(hdr->count) >
- UINT_MAX - hdr->count * sizeof(VbDevMusicNote))) {
- VB2_DEBUG("VbGetDevMusicNotes: count=%d, just isn't right\n",
- hdr->count);
- goto nope;
- }
-
- /* Now we know this won't overflow */
- mylen = (uint32_t)(sizeof(hdr->count) +
- hdr->count * sizeof(VbDevMusicNote));
- mysum = Crc32(&(hdr->count), mylen);
-
- if (mysum != hdr->checksum) {
- VB2_DEBUG("VbGetDevMusicNotes: mysum=%08x, want=%08x\n",
- mysum, hdr->checksum);
- goto nope;
- }
-
- VB2_DEBUG("VbGetDevMusicNotes: custom notes struct at %p\n", hdr);
-
- /*
- * Measure the audible sound up to the first 22 seconds, being careful
- * to avoid rollover. The note time is 16 bits, and the note count is
- * 32 bits. The product should fit in 64 bits.
- */
- total_msecs = 0;
- on_msecs = 0;
- for (i=0; i < hdr->count; i++) {
- this_msecs = hdr->notes[i].msec ;
- if (this_msecs) {
- total_msecs += this_msecs;
- if (total_msecs <= REQUIRED_NOISE_WITHIN &&
- hdr->notes[i].frequency >= 100 &&
- hdr->notes[i].frequency <= 2000)
- on_msecs += this_msecs;
- }
- }
-
- /* We require at least one second of noise in the first 22 seconds */
- VB2_DEBUG("VbGetDevMusicNotes: with %d msecs of sound to begin\n",
- on_msecs);
- if (on_msecs < REQUIRED_NOISE_TIME)
- goto nope;
-
- /*
- * We'll also require that the total time be less than 5 minutes. No
- * real reason, it just gives us less to worry about.
- */
- VB2_DEBUG("VbGetDevMusicNotes: lasting %d msecs\n", total_msecs);
- if (total_msecs > MAX_CUSTOM_DELAY) {
- goto nope;
- }
-
- /* One more check, just to be paranoid. */
- if (hdr->count > (UINT_MAX / sizeof(VbDevMusicNote) - 1)) {
- VB2_DEBUG("VbGetDevMusicNotes: they're all out to get me!\n");
- goto nope;
- }
-
- /* Looks good. Allocate the space (plus one) and copy it over. */
- notebuf = malloc((hdr->count + 1) * sizeof(VbDevMusicNote));
- memcpy(notebuf, hdr->notes, hdr->count * sizeof(VbDevMusicNote));
- count = hdr->count;
-
- /* We also require at least 30 seconds of delay. */
- if (total_msecs < REQUIRED_TOTAL_DELAY) {
- /*
- * If the total time is less than 30 seconds, the needed
- * difference will fit in 16 bits.
- */
- this_msecs = (REQUIRED_TOTAL_DELAY - total_msecs) & 0xffff;
- notebuf[hdr->count].msec = this_msecs;
- notebuf[hdr->count].frequency = 0;
- count++;
- VB2_DEBUG("VbGetDevMusicNotes: adding %d msecs of silence\n",
- this_msecs);
- }
-
- /* Done */
- audio->music_notes = notebuf;
- audio->note_count = count;
- audio->free_notes_when_done = 1;
- return;
-
- nope:
- /* No custom notes, use the default. The count is already set. */
- VB2_DEBUG("VbGetDevMusicNotes: using %d default notes\n", count);
- audio->music_notes = builtin;
- audio->note_count = count;
- audio->free_notes_when_done = 0;
-}
+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 int beep_count; /* Number of beeps so far */
/**
- * Initialization function. Returns context for processing dev-mode delay.
+ * Initialization function.
*/
-VbAudioContext *VbAudioOpen(VbCommonParams *cparams)
+void vb2_audio_start(struct vb2_context *ctx)
{
- GoogleBinaryBlockHeader *gbb = cparams->gbb;
- VbAudioContext *audio = &au;
- int use_short = 0;
- uint64_t a, b;
-
- /* Note: may need to allocate things here in future */
+ struct vb2_shared_data *sd = vb2_get_sd(ctx);
- /* Calibrate audio delay */
- a = VbExGetTimer();
- VbExSleepMs(10);
- b = VbExGetTimer();
- ticks_per_msec = (b - a) / 10ULL ;
- VB2_DEBUG("VbAudioOpen() - ticks_per_msec is %" PRIu64 "\n",
- ticks_per_msec);
-
- /* Initialize */
- memset(audio, 0, sizeof(*audio));
- audio->background_beep = 1;
- audio->play_until = b; /* "zero" starts now */
-
- /* See if we have full background sound capability or not. */
- if (VBERROR_SUCCESS != VbExBeep(0,0)) {
- VB2_DEBUG("VbAudioOpen() - VbExBeep() is limited\n");
- audio->background_beep = 0;
- }
+ open_time = VbExGetTimer(); /* "zero" starts now */
+ beep_count = 0;
/*
- * Prepare to generate audio/delay event. Use a short developer screen
- * delay if indicated by GBB flags.
+ * Use a short developer screen delay on the first audio if indicated
+ * by GBB flags.
*/
- if ((gbb->major_version == GBB_MAJOR_VER && gbb->minor_version >= 1
- && (gbb->flags & GBB_FLAG_DEV_SCREEN_SHORT_DELAY))) {
- VB2_DEBUG("VbAudioOpen() - using short dev screen delay\n");
- use_short = 1;
+ if ((sd->gbb_flags & VB2_GBB_FLAG_DEV_SCREEN_SHORT_DELAY) &&
+ (audio_open_count++ == 0)) {
+ VB2_DEBUG("vb2_audio_start() - using short dev screen delay\n");
+ audio_use_short = 1;
+ } else {
+ audio_use_short = 0;
}
-
- /* Only use short dev screen delay on the first audio */
- if (audio_open_count++ > 0)
- use_short = 0;
-
- VbGetDevMusicNotes(audio, use_short);
- VB2_DEBUG("VbAudioOpen() - note count %d\n", audio->note_count);
-
- return audio;
}
/**
* Caller should loop without extra delay until this returns false.
*/
-int VbAudioLooping(VbAudioContext *audio)
+int vb2_audio_looping(void)
{
- uint64_t now;
- uint16_t freq = audio->current_frequency;
- uint16_t msec = 0;
- int looping = 1;
-
- /* if no audio context, never timeout */
- if (!audio)
- return 1;
-
- now = VbExGetTimer();
- while (audio->next_note < audio->note_count &&
- now >= audio->play_until) {
- freq = audio->music_notes[audio->next_note].frequency;
- msec = audio->music_notes[audio->next_note].msec;
- audio->play_until += VbMsecToTicks(msec);
- audio->next_note++;
- }
+ uint64_t now = VbExGetTimer() - open_time;
- if (now >= audio->play_until) {
- looping = 0;
- freq = 0;
- }
+ /* If we're using short delay, wait 2 seconds and don't beep */
+ if (audio_use_short)
+ return (now < 2000 * TICKS_PER_MSEC);
- /* Do action here. */
- if (audio->background_beep) {
- if (audio->current_frequency != freq) {
- VbExBeep(0, freq);
- audio->current_frequency = freq;
- }
- } else if (freq && msec) {
- VbExBeep(msec, freq);
- now = VbExGetTimer();
+ /* Otherwise, beep at 20 and 20.5 seconds */
+ if ((beep_count == 0 && now > 20000 * TICKS_PER_MSEC) ||
+ (beep_count == 1 && now > 20500 * TICKS_PER_MSEC)) {
+ VbExBeep(250, 400);
+ beep_count++;
}
- audio->last_time = now;
- return looping;
-}
-
-/**
- * Caller should call this prior to booting.
- */
-void VbAudioClose(VbAudioContext *audio)
-{
- if (!audio)
- return;
-
- VbExBeep(0,0);
- if (audio->free_notes_when_done)
- free(audio->music_notes);
+ /* Stop after 30 seconds */
+ return (now < 30000 * TICKS_PER_MSEC);
}
diff --git a/firmware/lib/vboot_ui.c b/firmware/lib/vboot_ui.c
index 50c27e76..4057ed18 100644
--- a/firmware/lib/vboot_ui.c
+++ b/firmware/lib/vboot_ui.c
@@ -171,8 +171,6 @@ VbError_t vb2_developer_ui(struct vb2_context *ctx, VbCommonParams *cparams)
uint32_t use_legacy = 0;
uint32_t ctrl_d_pressed = 0;
- VbAudioContext *audio = 0;
-
VB2_DEBUG("Entering\n");
/* Check if USB booting is allowed */
@@ -240,15 +238,14 @@ VbError_t vb2_developer_ui(struct vb2_context *ctx, VbCommonParams *cparams)
/* Show the dev mode warning screen */
VbDisplayScreen(ctx, cparams, VB_SCREEN_DEVELOPER_WARNING, 0);
- /* Get audio/delay context */
- audio = VbAudioOpen(cparams);
+ /* Initialize audio/delay context */
+ vb2_audio_start(ctx);
/* We'll loop until we finish the delay or are interrupted */
do {
uint32_t key = VbExKeyboardRead();
if (VbWantShutdown(ctx, key)) {
VB2_DEBUG("VbBootDeveloper() - shutdown requested!\n");
- VbAudioClose(audio);
return VBERROR_SHUTDOWN_REQUESTED;
}
@@ -267,7 +264,6 @@ VbError_t vb2_developer_ui(struct vb2_context *ctx, VbCommonParams *cparams)
if (shared->flags & VBSD_HONOR_VIRT_DEV_SWITCH &&
shared->flags & VBSD_BOOT_DEV_SWITCH_ON) {
/* Stop the countdown while we go ask... */
- VbAudioClose(audio);
if (sd->gbb_flags &
GBB_FLAG_FORCE_DEV_SWITCH_ON) {
/*
@@ -308,7 +304,7 @@ VbError_t vb2_developer_ui(struct vb2_context *ctx, VbCommonParams *cparams)
VB_SCREEN_DEVELOPER_WARNING,
0);
/* Start new countdown */
- audio = VbAudioOpen(cparams);
+ vb2_audio_start(ctx);
}
} else {
/*
@@ -318,7 +314,6 @@ VbError_t vb2_developer_ui(struct vb2_context *ctx, VbCommonParams *cparams)
VB2_DEBUG("going to recovery\n");
vb2_nv_set(ctx, VB2_NV_RECOVERY_REQUEST,
VB2_RECOVERY_RW_DEV_SCREEN);
- VbAudioClose(audio);
return VBERROR_LOAD_KERNEL_RECOVERY;
}
break;
@@ -364,7 +359,6 @@ VbError_t vb2_developer_ui(struct vb2_context *ctx, VbCommonParams *cparams)
0);
if (VBERROR_SUCCESS ==
VbTryUsb(ctx, cparams)) {
- VbAudioClose(audio);
return VBERROR_SUCCESS;
} else {
/* Show dev mode warning screen again */
@@ -380,7 +374,7 @@ VbError_t vb2_developer_ui(struct vb2_context *ctx, VbCommonParams *cparams)
VbCheckDisplayKey(ctx, cparams, key);
break;
}
- } while(VbAudioLooping(audio));
+ } while(vb2_audio_looping());
fallout:
@@ -392,14 +386,12 @@ VbError_t vb2_developer_ui(struct vb2_context *ctx, VbCommonParams *cparams)
if ((use_usb && !ctrl_d_pressed) && allow_usb) {
if (VBERROR_SUCCESS == VbTryUsb(ctx, cparams)) {
- VbAudioClose(audio);
return VBERROR_SUCCESS;
}
}
/* Timeout or Ctrl+D; attempt loading from fixed disk */
VB2_DEBUG("VbBootDeveloper() - trying fixed disk\n");
- VbAudioClose(audio);
return VbTryLoadKernel(ctx, cparams, VB_DISK_FLAG_FIXED);
}
diff --git a/firmware/lib/vboot_ui_menu.c b/firmware/lib/vboot_ui_menu.c
index ce0496d6..d19e2994 100644
--- a/firmware/lib/vboot_ui_menu.c
+++ b/firmware/lib/vboot_ui_menu.c
@@ -598,7 +598,6 @@ VbError_t vb2_developer_menu(struct vb2_context *ctx, VbCommonParams *cparams)
uint32_t use_legacy = 0;
uint32_t ctrl_d_pressed = 0;
- VbAudioContext *audio = NULL;
VbError_t ret;
VB2_DEBUG("Entering\n");
@@ -651,8 +650,7 @@ VbError_t vb2_developer_menu(struct vb2_context *ctx, VbCommonParams *cparams)
vb2_draw_current_screen(ctx, cparams);
/* Get audio/delay context */
- if (!disable_dev_boot)
- audio = VbAudioOpen(cparams);
+ vb2_audio_start(ctx);
/* We'll loop until we finish the delay or are interrupted */
do {
@@ -660,8 +658,6 @@ VbError_t vb2_developer_menu(struct vb2_context *ctx, VbCommonParams *cparams)
if (VbWantShutdownMenu(ctx)) {
VB2_DEBUG("shutdown requested!\n");
- if (audio)
- VbAudioClose(audio);
return VBERROR_SHUTDOWN_REQUESTED;
}
@@ -714,8 +710,6 @@ VbError_t vb2_developer_menu(struct vb2_context *ctx, VbCommonParams *cparams)
0);
if (VBERROR_SUCCESS ==
VbTryUsbMenu(ctx, cparams)) {
- if (audio)
- VbAudioClose(audio);
return VBERROR_SUCCESS;
} else {
/* Show dev mode warning screen again */
@@ -728,16 +722,14 @@ VbError_t vb2_developer_menu(struct vb2_context *ctx, VbCommonParams *cparams)
vb2_update_selection(cparams, key);
vb2_draw_current_screen(ctx, cparams);
/* reset 30 second timer */
- if (audio)
- audio = VbAudioOpen(cparams);
+ vb2_audio_start(ctx);
break;
case VB_BUTTON_VOL_DOWN_SHORT_PRESS:
case VB_KEY_DOWN:
vb2_update_selection(cparams, key);
vb2_draw_current_screen(ctx, cparams);
/* reset 30 second timer */
- if (audio)
- audio = VbAudioOpen(cparams);
+ vb2_audio_start(ctx);
break;
case VB_BUTTON_POWER_SHORT_PRESS:
case '\r':
@@ -802,8 +794,6 @@ VbError_t vb2_developer_menu(struct vb2_context *ctx, VbCommonParams *cparams)
cparams, VB_SCREEN_BLANK, 0);
if (VBERROR_SUCCESS ==
VbTryUsbMenu(ctx, cparams)) {
- if (audio)
- VbAudioClose(audio);
return VBERROR_SUCCESS;
} else
/*
@@ -861,14 +851,15 @@ VbError_t vb2_developer_menu(struct vb2_context *ctx, VbCommonParams *cparams)
}
}
/* reset 30 second timer */
- if (audio)
- audio = VbAudioOpen(cparams);
+ vb2_audio_start(ctx);
break;
default:
VB2_DEBUG("pressed key %d\n", key);
break;
}
- } while(VbAudioLooping(audio));
+
+ /* If dev mode was disabled, loop forever (never timeout) */
+ } while(disable_dev_boot ? 1 : vb2_audio_looping());
fallout:
@@ -880,14 +871,12 @@ fallout:
if ((use_usb && !ctrl_d_pressed) && allow_usb) {
if (VBERROR_SUCCESS == VbTryUsbMenu(ctx, cparams)) {
- VbAudioClose(audio);
return VBERROR_SUCCESS;
}
}
/* Timeout or Ctrl+D; attempt loading from fixed disk */
VB2_DEBUG("trying fixed disk\n");
- VbAudioClose(audio);
return VbTryLoadKernel(ctx, cparams, VB_DISK_FLAG_FIXED);
}
diff --git a/tests/vboot_api_devmode_tests.c b/tests/vboot_api_devmode_tests.c
index 5b495163..0a336d90 100644
--- a/tests/vboot_api_devmode_tests.c
+++ b/tests/vboot_api_devmode_tests.c
@@ -29,114 +29,75 @@
/* Expected results */
#define MAX_NOTE_EVENTS 10
-#define TICKS_PER_MSEC 1900ULL
+#define TICKS_PER_MSEC 1000ULL
#define TIME_FUZZ 500
#define KBD_READ_TIME 60
typedef struct {
- uint16_t msec;
- uint16_t freq;
- int time;
+ uint16_t msec;
+ uint16_t freq;
+ int time;
} note_event_t;
typedef struct {
- char *name;
- uint32_t gbb_flags;
- VbError_t beep_return;
- uint32_t keypress_key;
- int keypress_at_count;
- int num_events;
- note_event_t notes[MAX_NOTE_EVENTS];
+ char *name;
+ uint32_t gbb_flags;
+ VbError_t beep_return;
+ uint32_t keypress_key;
+ int keypress_at_count;
+ int num_events;
+ note_event_t notes[MAX_NOTE_EVENTS];
} test_case_t;
test_case_t test[] = {
- { "VbBootDeveloperSoundTest( fast, background )",
- 0x00000001, VBERROR_SUCCESS,
- 0, 0,
- 2,
- {
- {0, 0, 0}, // probing for capability
- {0, 0, 2000}, // off and return at 2 seconds
- }},
-
- { "VbBootDeveloperSoundTest( normal, background )",
- 0x00000000, VBERROR_SUCCESS,
- 0, 0,
- 6,
- {
- {0, 0, 0}, // probing for capability
- {0, 400, 20000}, // starts first beep at 20 seconds
- {0, 0, 20250}, // stops 250ms later
- {0, 400, 20500}, // starts second beep
- {0, 0, 20750}, // stops 250ms later
- {0, 0, 30000}, // off and return at 30 seconds
- }},
-
- { "VbBootDeveloperSoundTest( fast, no background )",
- 0x00000001, VBERROR_NO_BACKGROUND_SOUND,
- 0, 0,
- 2,
- {
- {0, 0, 0}, // probing for capability
- {0, 0, 2000}, // off and return at 2 seconds
- }},
-
- { "VbBootDeveloperSoundTest( normal, no background )",
- 0x00000000, VBERROR_NO_BACKGROUND_SOUND,
- 0, 0,
- 4,
- {
- {0, 0, 0}, // probing for capability
- {250, 400, 20000}, // first beep at 20 seconds
- {250, 400, 20510}, // second beep shortly after
- {0, 0, 30020}, // off and return at 30 seconds
- }},
-
- // Now with some keypresses
-
- { "VbBootDeveloperSoundTest( normal, background, Ctrl-D )",
- 0x00000000, VBERROR_SUCCESS,
- 4, 10000, // Ctrl-D at 10 seconds
- 2,
- {
- {0, 0, 0}, // probing for capability
- {0, 0, 10000}, // sees Ctrl-D, sound off, return
- }},
-
- { "VbBootDeveloperSoundTest( normal, no background, Ctrl-D )",
- 0x00000000, VBERROR_NO_BACKGROUND_SOUND,
- 4, 20400, // Ctrl-D between beeps
- 3,
- {
- {0, 0, 0}, // probing for capability
- {250, 400, 20000}, // first beep at 20 seconds
- {0, 0, 20400}, // sees Ctrl-D, sound off, return
- }},
-
- { "VbBootDeveloperSoundTest( normal, background, Ctrl-U not allowed )",
- 0x00000000, VBERROR_SUCCESS,
- 21, 10000, // Ctrl-U at 10 seconds
- 8,
- {
- {0, 0, 0}, // probing for capability
- {120, 400, 10000}, // complains about Ctrl-U (one beep)
- // waits 120ms...
- {120, 400, 10240}, // complains about Ctrl-U (two beeps)
- // original sequence is now shifted...
- {0, 400, 20360}, // starts first beep at 20 seconds
- {0, 0, 20610}, // stops 250ms later
- {0, 400, 20860}, // starts second beep
- {0, 0, 21110}, // stops 250ms later
- {0, 0, 30360}, // returns at 30 seconds + 360ms
- }},
-
+ { "VbBootDeveloperSoundTest( fast )",
+ VB2_GBB_FLAG_DEV_SCREEN_SHORT_DELAY, VBERROR_NO_BACKGROUND_SOUND,
+ 0, 0,
+ 1,
+ {
+ {0, 0, 2000}, // off and return at 2 seconds
+ }},
+
+ { "VbBootDeveloperSoundTest( normal )",
+ 0, VBERROR_NO_BACKGROUND_SOUND,
+ 0, 0,
+ 3,
+ {
+ {250, 400, 20000}, // first beep at 20 seconds
+ {250, 400, 20510}, // second beep shortly after
+ {0, 0, 30020}, // off and return at 30 seconds
+ }},
+
+ // Now with some keypresses
+
+ { "VbBootDeveloperSoundTest( normal, Ctrl-D )",
+ 0, VBERROR_NO_BACKGROUND_SOUND,
+ 4, 20400, // Ctrl-D between beeps
+ 2,
+ {
+ {250, 400, 20000}, // first beep at 20 seconds
+ {0, 0, 20400}, // sees Ctrl-D, sound off, return
+ }},
+
+ { "VbBootDeveloperSoundTest( normal, Ctrl-U not allowed )",
+ 0, VBERROR_NO_BACKGROUND_SOUND,
+ 21, 10000, // Ctrl-U at 10 seconds
+ 5,
+ {
+ {120, 400, 10000}, // complains about Ctrl-U (one beep)
+ {120, 400, 10240}, // complains about Ctrl-U (two beeps)
+ {250, 400, 20000}, // starts first beep at 20 seconds
+ {250, 400, 20510}, // starts second beep
+ {0, 0, 30020}, // returns at 30 seconds + 360ms
+ }},
};
/* Mock data */
static VbCommonParams cparams;
static uint8_t workbuf[VB2_KERNEL_WORKBUF_RECOMMENDED_SIZE];
static struct vb2_context ctx;
+static struct vb2_shared_data *sd;
static uint8_t shared_data[VB_SHARED_DATA_MIN_SIZE];
static VbSharedDataHeader* shared = (VbSharedDataHeader*)shared_data;
static GoogleBinaryBlockHeader gbb;
@@ -150,184 +111,201 @@ static uint32_t kbd_fire_key;
static VbError_t beep_return;
static note_event_t *expected_event;
+/* Audio open count, so we can reset it */
extern int audio_open_count;
/* Reset mock data (for use before each test) */
-static void ResetMocks(void) {
-
- memset(&cparams, 0, sizeof(cparams));
- cparams.shared_data_size = sizeof(shared_data);
- cparams.shared_data_blob = shared_data;
- cparams.gbb_data = &gbb;
- cparams.gbb = &gbb;
-
- memset(&ctx, 0, sizeof(ctx));
- ctx.workbuf = workbuf;
- ctx.workbuf_size = sizeof(workbuf);
- vb2_init_context(&ctx);
- vb2_nv_init(&ctx);
-
- memset(&shared_data, 0, sizeof(shared_data));
- VbSharedDataInit(shared, sizeof(shared_data));
- shared->fw_keyblock_flags = 0xABCDE0;
-
- memset(&gbb, 0, sizeof(gbb));
- gbb.major_version = GBB_MAJOR_VER;
- gbb.minor_version = GBB_MINOR_VER;
- gbb.flags = 0;
-
- current_ticks = 0;
- current_time = 0;
-
- current_event = 0;
- kbd_fire_at = 0;
- kbd_fire_key = 0;
-
- beep_return = VBERROR_SUCCESS;
- audio_open_count = 0;
-
- matched_events = 0;
- max_events = 0;
+static void ResetMocks(void)
+{
+ memset(&cparams, 0, sizeof(cparams));
+ cparams.shared_data_size = sizeof(shared_data);
+ cparams.shared_data_blob = shared_data;
+ cparams.gbb_data = &gbb;
+ cparams.gbb = &gbb;
+
+ memset(&ctx, 0, sizeof(ctx));
+ ctx.workbuf = workbuf;
+ ctx.workbuf_size = sizeof(workbuf);
+ vb2_init_context(&ctx);
+ vb2_nv_init(&ctx);
+ sd = vb2_get_sd(&ctx);
+
+ memset(&shared_data, 0, sizeof(shared_data));
+ VbSharedDataInit(shared, sizeof(shared_data));
+ shared->fw_keyblock_flags = 0xABCDE0;
+
+ memset(&gbb, 0, sizeof(gbb));
+ gbb.major_version = GBB_MAJOR_VER;
+ gbb.minor_version = GBB_MINOR_VER;
+ gbb.flags = 0;
+
+ current_ticks = 0;
+ current_time = 0;
+
+ current_event = 0;
+ kbd_fire_at = 0;
+ kbd_fire_key = 0;
+
+ beep_return = VBERROR_SUCCESS;
+ audio_open_count = 0;
+
+ matched_events = 0;
+ max_events = 0;
}
/****************************************************************************/
/* Mocked verification functions */
-VbError_t VbExNvStorageRead(uint8_t* buf) {
- return VBERROR_SUCCESS;
+VbError_t VbExNvStorageRead(uint8_t* buf)
+{
+ return VBERROR_SUCCESS;
}
-VbError_t VbExNvStorageWrite(const uint8_t* buf) {
- return VBERROR_SUCCESS;
+VbError_t VbExNvStorageWrite(const uint8_t* buf)
+{
+ return VBERROR_SUCCESS;
}
VbError_t VbExDiskGetInfo(VbDiskInfo** infos_ptr, uint32_t* count,
- uint32_t disk_flags) {
- return VBERROR_UNKNOWN;
+ uint32_t disk_flags)
+{
+ return VBERROR_UNKNOWN;
}
VbError_t VbExDiskFreeInfo(VbDiskInfo* infos,
- VbExDiskHandle_t preserve_handle) {
- return VBERROR_SUCCESS;
+ VbExDiskHandle_t preserve_handle)
+{
+ return VBERROR_SUCCESS;
}
VbError_t VbExDiskRead(VbExDiskHandle_t handle, uint64_t lba_start,
- uint64_t lba_count, void* buffer) {
- return VBERROR_UNKNOWN;
+ uint64_t lba_count, void* buffer)
+{
+ return VBERROR_UNKNOWN;
}
VbError_t VbExDiskWrite(VbExDiskHandle_t handle, uint64_t lba_start,
- uint64_t lba_count, const void* buffer) {
- return VBERROR_UNKNOWN;
+ uint64_t lba_count, const void* buffer)
+{
+ return VBERROR_UNKNOWN;
}
-uint32_t VbExIsShutdownRequested(void) {
- return 0;
+uint32_t VbExIsShutdownRequested(void)
+{
+ return 0;
}
-uint32_t VbExKeyboardRead(void) {
- uint32_t tmp;
- uint32_t now;
-
- VbExSleepMs(KBD_READ_TIME);
- now = current_time;
-
- if (kbd_fire_key && now >= kbd_fire_at) {
- VB2_DEBUG(" VbExKeyboardRead() - 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);
- return 0;
+uint32_t VbExKeyboardRead(void)
+{
+ uint32_t tmp;
+ uint32_t now;
+
+ VbExSleepMs(KBD_READ_TIME);
+ now = current_time;
+
+ if (kbd_fire_key && now >= kbd_fire_at) {
+ VB2_DEBUG(" VbExKeyboardRead() - 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);
+ return 0;
}
-void VbExSleepMs(uint32_t msec) {
- current_ticks += (uint64_t)msec * TICKS_PER_MSEC;
- current_time = current_ticks / TICKS_PER_MSEC;
- VB2_DEBUG("VbExSleepMs(%d) -> %d\n", msec, current_time);
+void VbExSleepMs(uint32_t msec)
+{
+ current_ticks += (uint64_t)msec * TICKS_PER_MSEC;
+ current_time = current_ticks / TICKS_PER_MSEC;
+ VB2_DEBUG("VbExSleepMs(%d) -> %d\n", msec, current_time);
}
-uint64_t VbExGetTimer(void) {
- return current_ticks;
+uint64_t VbExGetTimer(void)
+{
+ return current_ticks;
}
-VbError_t VbExBeep(uint32_t msec, uint32_t frequency) {
- VB2_DEBUG("VbExBeep(%d, %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 ) {
- matched_events++;
- }
-
- if (msec)
- VbExSleepMs(msec);
- current_event++;
- return beep_return;
+VbError_t VbExBeep(uint32_t msec, uint32_t frequency)
+{
+ VB2_DEBUG("VbExBeep(%d, %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 ) {
+ matched_events++;
+ }
+
+ if (msec)
+ VbExSleepMs(msec);
+ current_event++;
+ return beep_return;
}
-VbError_t VbExDisplayScreen(uint32_t screen_type, uint32_t locale) {
- switch(screen_type) {
- case VB_SCREEN_BLANK:
- VB2_DEBUG("VbExDisplayScreen(BLANK)\n");
- break;
- case VB_SCREEN_DEVELOPER_WARNING:
- VB2_DEBUG("VbExDisplayScreen(DEV)\n");
- break;
- case VB_SCREEN_DEVELOPER_EGG:
- VB2_DEBUG("VbExDisplayScreen(EGG)\n");
- break;
- case VB_SCREEN_RECOVERY_REMOVE:
- VB2_DEBUG("VbExDisplayScreen(REMOVE)\n");
- break;
- case VB_SCREEN_RECOVERY_INSERT:
- VB2_DEBUG("VbExDisplayScreen(INSERT)\n");
- break;
- case VB_SCREEN_RECOVERY_NO_GOOD:
- VB2_DEBUG("VbExDisplayScreen(NO_GOOD)\n");
- break;
- case VB_SCREEN_OS_BROKEN:
- VB2_DEBUG("VbExDisplayScreen(BROKEN)\n");
- break;
- default:
- VB2_DEBUG("VbExDisplayScreen(%d)\n", screen_type);
- }
-
- VB2_DEBUG(" current_time is %d msec\n", current_time);
-
- return VBERROR_SUCCESS;
+VbError_t VbExDisplayScreen(uint32_t screen_type, uint32_t locale)
+{
+ switch(screen_type) {
+ case VB_SCREEN_BLANK:
+ VB2_DEBUG("VbExDisplayScreen(BLANK)\n");
+ break;
+ case VB_SCREEN_DEVELOPER_WARNING:
+ VB2_DEBUG("VbExDisplayScreen(DEV)\n");
+ break;
+ case VB_SCREEN_DEVELOPER_EGG:
+ VB2_DEBUG("VbExDisplayScreen(EGG)\n");
+ break;
+ case VB_SCREEN_RECOVERY_REMOVE:
+ VB2_DEBUG("VbExDisplayScreen(REMOVE)\n");
+ break;
+ case VB_SCREEN_RECOVERY_INSERT:
+ VB2_DEBUG("VbExDisplayScreen(INSERT)\n");
+ break;
+ case VB_SCREEN_RECOVERY_NO_GOOD:
+ VB2_DEBUG("VbExDisplayScreen(NO_GOOD)\n");
+ break;
+ case VB_SCREEN_OS_BROKEN:
+ VB2_DEBUG("VbExDisplayScreen(BROKEN)\n");
+ break;
+ default:
+ VB2_DEBUG("VbExDisplayScreen(%d)\n", screen_type);
+ }
+
+ VB2_DEBUG(" current_time is %d msec\n", current_time);
+
+ return VBERROR_SUCCESS;
}
/****************************************************************************/
-static void VbBootDeveloperSoundTest(void) {
- int i;
- int num_tests = sizeof(test) / sizeof(test_case_t);
-
- 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) VbBootDeveloper(&ctx, &cparams);
- 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 &&
- current_event == test[i].num_events, test[i].name);
- }
+static void VbBootDeveloperSoundTest(void)
+{
+ int i;
+ int num_tests = sizeof(test) / sizeof(test_case_t);
+
+ for (i=0; i<num_tests; i++) {
+ VB2_DEBUG("STARTING %s ...\n", test[i].name);
+ ResetMocks();
+ sd->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) VbBootDeveloper(&ctx, &cparams);
+ VbExBeep(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 &&
+ current_event == test[i].num_events, test[i].name);
+ }
}
-
int main(int argc, char* argv[])
{
- VbBootDeveloperSoundTest();
- return gTestSuccess ? 0 : 255;
+ VbBootDeveloperSoundTest();
+ return gTestSuccess ? 0 : 255;
}
diff --git a/tests/vboot_api_kernel2_tests.c b/tests/vboot_api_kernel2_tests.c
index f03a8dcd..abcf1951 100644
--- a/tests/vboot_api_kernel2_tests.c
+++ b/tests/vboot_api_kernel2_tests.c
@@ -174,7 +174,7 @@ int VbExTrustEC(int devidx)
return trust_ec;
}
-int VbAudioLooping(VbAudioContext *audio)
+int vb2_audio_looping(void)
{
if (audio_looping_calls_left == 0)
return 0;
diff --git a/tests/vboot_audio_tests.c b/tests/vboot_audio_tests.c
deleted file mode 100644
index 94bbb0ac..00000000
--- a/tests/vboot_audio_tests.c
+++ /dev/null
@@ -1,224 +0,0 @@
-/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- *
- * Tests for vboot_audio
- */
-
-#include <stddef.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "crc32.h"
-#include "gbb_header.h"
-#include "host_common.h"
-#include "load_kernel_fw.h"
-#include "rollback_index.h"
-#include "test_common.h"
-#include "vboot_audio.h"
-#include "vboot_audio_private.h"
-#include "vboot_common.h"
-#include "vboot_display.h"
-#include "vboot_struct.h"
-
-
-/* Builtin notes */
-extern VbDevMusicNote default_notes_[], short_notes_[];
-extern uint32_t default_count_, short_count_;
-
-/* Mock data */
-static VbCommonParams cparams;
-static GoogleBinaryBlockHeader gbb;
-static VbDevMusicNote good_notes[] = { {100, 100},
- {100, 0},
- {200, 200},
- {100, 0},
- {300, 300},
- {100, 0},
- {400, 400},
- {30000, 0} };
-static VbDevMusic good_header =
-{ .sig = { '$', 'S', 'N', 'D' },
- .count = sizeof(good_notes) / sizeof(VbDevMusicNote),
-};
-
-static uint8_t notebuf[sizeof(good_header) +
- sizeof(good_notes) - sizeof(VbDevMusicNote)];
-
-static VbDevMusic *use_hdr;
-static VbDevMusicNote *use_notes;
-static uint32_t use_size;
-extern int audio_open_count;
-
-/* Set correct checksum for custom notes */
-void FixChecksum(VbDevMusic *hdr) {
- hdr->checksum = Crc32(&(hdr->count), sizeof(hdr->count) +
- hdr->count * sizeof(hdr->notes[0]));
-}
-
-/* Reset mock data (for use before each test) */
-static void ResetMocks(void) {
- memset(&cparams, 0, sizeof(cparams));
- cparams.gbb_data = &gbb;
- cparams.gbb = &gbb;
- memset(&gbb, 0, sizeof(gbb));
- gbb.major_version = GBB_MAJOR_VER;
- gbb.minor_version = GBB_MINOR_VER;
- gbb.flags = 0;
- use_hdr = (VbDevMusic *)notebuf;
- use_notes = use_hdr->notes;
- memcpy(use_hdr, &good_header, sizeof(good_header));
- memcpy(use_notes, good_notes, sizeof(good_notes));
- FixChecksum(use_hdr);
- use_size = sizeof(notebuf);
- audio_open_count = 0;
-}
-
-/* Compare two sets of notes */
-static int NotesMatch(VbDevMusicNote *a, VbDevMusicNote *b, uint32_t count) {
- int i;
- if (!a || !b)
- return 0;
-
- for ( i=0; i<count; i++) {
- if ( a[i].msec != b[i].msec || a[i].frequency != b[i].frequency)
- return 0;
- }
-
- return count;
-}
-
-
-
-
-/****************************************************************************/
-/* Mocked verification functions */
-
-void *VbExGetMusicPtr(void) {
- return use_hdr;
-}
-
-uint32_t VbExMaxMusicSize(void) {
- return use_size;
-}
-
-
-/****************************************************************************/
-
-static void VbAudioTest(void) {
- VbAudioContext* a = 0;
-
- /* default is okay */
- ResetMocks();
- use_hdr = 0;
- a = VbAudioOpen(&cparams);
- TEST_TRUE(a->music_notes == default_notes_ &&
- a->note_count == default_count_,
- "VbAudioTest( default )");
- VbAudioClose(a);
-
- /* short is okay */
- ResetMocks();
- use_hdr = 0;
- gbb.flags = 0x00000001;
- a = VbAudioOpen(&cparams);
- TEST_TRUE(a->music_notes == short_notes_ &&
- a->note_count == short_count_,
- "VbAudioTest( short )");
- VbAudioClose(a);
-
- /* good custom is okay */
- ResetMocks();
- a = VbAudioOpen(&cparams);
- TEST_TRUE(NotesMatch(a->music_notes, good_notes, good_header.count) &&
- a->note_count == good_header.count,
- "VbAudioTest( custom good )");
- VbAudioClose(a);
-
- /* good custom is rejected when short flag is set */
- ResetMocks();
- gbb.flags = 0x00000001;
- a = VbAudioOpen(&cparams);
- TEST_TRUE(a->music_notes == short_notes_ &&
- a->note_count == short_count_,
- "VbAudioTest( short has priority )");
- VbAudioClose(a);
-
- /* too short gets extended */
- ResetMocks();
- use_hdr->count--;
- FixChecksum(use_hdr);
- a = VbAudioOpen(&cparams);
- TEST_TRUE(NotesMatch(a->music_notes, use_notes, use_hdr->count) &&
- a->note_count == use_hdr->count + 1 &&
- a->music_notes[use_hdr->count].msec == 28700 &&
- a->music_notes[use_hdr->count].frequency == 0,
- "VbAudioTest( too short )");
- VbAudioClose(a);
-
- /* too quiet is rejected */
- ResetMocks();
- use_notes[6].msec = 10;
- FixChecksum(use_hdr);
- a = VbAudioOpen(&cparams);
- TEST_TRUE(a->music_notes == default_notes_ &&
- a->note_count == default_count_,
- "VbAudioTest( too quiet )");
- VbAudioClose(a);
-
- /* inaudible is rejected */
- ResetMocks();
- use_notes[0].frequency = 99;
- use_notes[2].frequency = 2001;
- FixChecksum(use_hdr);
- a = VbAudioOpen(&cparams);
- TEST_TRUE(a->music_notes == default_notes_ &&
- a->note_count == default_count_,
- "VbAudioTest( inaudible )");
- VbAudioClose(a);
-
- /* bad signature is rejected */
- ResetMocks();
- use_hdr->sig[0] = 'C';
- a = VbAudioOpen(&cparams);
- TEST_TRUE(a->music_notes == default_notes_ &&
- a->note_count == default_count_,
- "VbAudioTest( bad signature )");
- VbAudioClose(a);
-
- /* count == 0 is rejected */
- ResetMocks();
- use_hdr->count = 0;
- a = VbAudioOpen(&cparams);
- TEST_TRUE(a->music_notes == default_notes_ &&
- a->note_count == default_count_,
- "VbAudioTest( count == 0 )");
- VbAudioClose(a);
-
- /* too big is rejected */
- ResetMocks();
- use_hdr->count = 999;
- a = VbAudioOpen(&cparams);
- TEST_TRUE(a->music_notes == default_notes_ &&
- a->note_count == default_count_,
- "VbAudioTest( count too big )");
- VbAudioClose(a);
-
- /* bad checksum is rejected */
- ResetMocks();
- use_hdr->checksum++;
- a = VbAudioOpen(&cparams);
- TEST_TRUE(a->music_notes == default_notes_ &&
- a->note_count == default_count_,
- "VbAudioTest( count too big )");
- VbAudioClose(a);
-}
-
-
-int main(int argc, char* argv[])
-{
- VbAudioTest();
-
- return gTestSuccess ? 0 : 255;
-}
diff --git a/tests/vboot_detach_menu_tests.c b/tests/vboot_detach_menu_tests.c
index f0aa4255..7fd9ea90 100644
--- a/tests/vboot_detach_menu_tests.c
+++ b/tests/vboot_detach_menu_tests.c
@@ -180,7 +180,7 @@ int VbExTrustEC(int devidx)
return trust_ec;
}
-int VbAudioLooping(VbAudioContext *audio)
+int vb2_audio_looping(void)
{
if (audio_looping_calls_left == 0)
return 0;