Make startup delay and noises simpler to change.

BUG=none
TEST=manual

Booted in dev-mode. All noises and delays are unchanged (2 second delay when
gbb.flags is 1, 30-second with beeps at 20 seconds when gbb.flags is 0).

Change-Id: I816e57c4f8f6025299851b3d42b4a350f9925994
Reviewed-on: http://gerrit.chromium.org/gerrit/8240
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Tested-by: Bill Richardson <wfrichar@chromium.org>
This commit is contained in:
Bill Richardson
2011-09-23 15:14:49 -07:00
parent 4313fba2fb
commit 25a3dbc83c
2 changed files with 113 additions and 29 deletions

View File

@@ -21,5 +21,18 @@ VbError_t VbCheckDisplayKey(VbCommonParams* cparams, uint32_t key,
void VbExEasterEgg(VbCommonParams* cparams, VbNvContext *vncptr); void VbExEasterEgg(VbCommonParams* cparams, VbNvContext *vncptr);
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;
#endif /* VBOOT_REFERENCE_VBOOT_DISPLAY_H_ */ #endif /* VBOOT_REFERENCE_VBOOT_DISPLAY_H_ */

View File

@@ -105,77 +105,110 @@ VbError_t VbBootNormal(VbCommonParams* cparams, LoadKernelParams* p) {
return VbTryLoadKernel(cparams, p, VB_DISK_FLAG_FIXED); return VbTryLoadKernel(cparams, p, VB_DISK_FLAG_FIXED);
} }
#define DEV_LOOP_TIME 10 /* Minimum note granularity in msecs */
static uint16_t VbMsecToLoops(uint16_t msec) {
return (DEV_LOOP_TIME / 2 + msec) / DEV_LOOP_TIME;
}
static VbDevMusicNote default_notes[] = { {20000, 0}, /* 20 seconds */
{250, 400}, /* two beeps */
{250, 0},
{250, 400},
{9250, 0} }; /* total 30 seconds */
static VbDevMusicNote short_notes[] = { {2000, 0} }; /* two seconds */
/* Return a valid set of note events. */
static VbDevMusicNote* VbGetDevMusicNotes(uint32_t *count, int use_short) {
if (use_short) {
*count = sizeof(short_notes) / sizeof(short_notes[0]);
return short_notes;
}
*count = sizeof(default_notes) / sizeof(default_notes[0]);
return default_notes;
}
/* Developer mode delays. All must be multiples of DEV_DELAY_INCREMENT */
#define DEV_DELAY_INCREMENT 250 /* Delay each loop, in msec */
#define DEV_DELAY_BEEP1 20000 /* Beep for first time at this time */
#define DEV_DELAY_BEEP2 20500 /* Beep for second time at this time */
#define DEV_DELAY_TIMEOUT 30000 /* Give up at this time */
#define DEV_DELAY_TIMEOUT_SHORT 2000 /* Give up at this time (short delay) */
/* Handle a developer-mode boot */ /* Handle a developer-mode boot */
VbError_t VbBootDeveloper(VbCommonParams* cparams, LoadKernelParams* p) { VbError_t VbBootDeveloper(VbCommonParams* cparams, LoadKernelParams* p) {
GoogleBinaryBlockHeader* gbb = (GoogleBinaryBlockHeader*)cparams->gbb_data; GoogleBinaryBlockHeader* gbb = (GoogleBinaryBlockHeader*)cparams->gbb_data;
uint32_t delay_timeout = DEV_DELAY_TIMEOUT;
uint32_t delay_time = 0;
uint32_t allow_usb = 0; uint32_t allow_usb = 0;
uint32_t note_count = 0;
VbDevMusicNote* music_notes = 0;
uint32_t current_note = 0;
uint32_t current_note_loops = 0;
int background_beep = 1;
/* Check if USB booting is allowed */ /* Check if USB booting is allowed */
VbNvGet(&vnc, VBNV_DEV_BOOT_USB, &allow_usb); VbNvGet(&vnc, VBNV_DEV_BOOT_USB, &allow_usb);
/* Use a short developer screen delay if indicated by GBB flags */
if (gbb->major_version == GBB_MAJOR_VER && gbb->minor_version >= 1
&& (gbb->flags & GBB_FLAG_DEV_SCREEN_SHORT_DELAY)) {
VBDEBUG(("VbBootDeveloper() - using short developer screen delay\n"));
delay_timeout = DEV_DELAY_TIMEOUT_SHORT;
}
/* Show the dev mode warning screen */ /* Show the dev mode warning screen */
VbDisplayScreen(cparams, VB_SCREEN_DEVELOPER_WARNING, 0, &vnc); VbDisplayScreen(cparams, VB_SCREEN_DEVELOPER_WARNING, 0, &vnc);
/* Loop for dev mode warning delay */ /* See if we have full background sound capability or not. */
for (delay_time = 0; delay_time < delay_timeout; if (VBERROR_SUCCESS != VbExBeep(0,0)) {
delay_time += DEV_DELAY_INCREMENT) { VBDEBUG(("VbBootDeveloper: VbExBeep() is limited\n"));
background_beep = 0;
}
/* Prepare to generate audio/delay event. Use a short developer screen delay
* if indicated by GBB flags.
*/
if (gbb->major_version == GBB_MAJOR_VER && gbb->minor_version >= 1
&& (gbb->flags & GBB_FLAG_DEV_SCREEN_SHORT_DELAY)) {
VBDEBUG(("VbBootDeveloper() - using short developer screen delay\n"));
music_notes = VbGetDevMusicNotes(&note_count, 1);
} else {
music_notes = VbGetDevMusicNotes(&note_count, 0);
}
VBDEBUG(("VbBootDeveloper() - note count %d\n", note_count));
/* We'll loop until we finish the notes or are interrupted */
while(1) {
uint32_t key; uint32_t key;
if (VbExIsShutdownRequested()) if (VbExIsShutdownRequested())
return VBERROR_SHUTDOWN_REQUESTED; return VBERROR_SHUTDOWN_REQUESTED;
if (DEV_DELAY_BEEP1 == delay_time || DEV_DELAY_BEEP2 == delay_time)
VbExBeep(DEV_DELAY_INCREMENT, 400);
else
VbExSleepMs(DEV_DELAY_INCREMENT);
/* Handle keypress */
key = VbExKeyboardRead(); key = VbExKeyboardRead();
switch (key) { switch (key) {
case 0:
/* nothing pressed */
break;
case '\r': case '\r':
case ' ': case ' ':
case 0x1B: case 0x1B:
/* Enter, space, or ESC = reboot to recovery */ /* Enter, space, or ESC = reboot to recovery */
VBDEBUG(("VbBootDeveloper() - user pressed ENTER/SPACE/ESC\n")); VBDEBUG(("VbBootDeveloper() - user pressed ENTER/SPACE/ESC\n"));
VbExBeep(0, 0); /* sound off */
VbSetRecoveryRequest(VBNV_RECOVERY_RW_DEV_SCREEN); VbSetRecoveryRequest(VBNV_RECOVERY_RW_DEV_SCREEN);
return 1; return 1;
case 0x04: case 0x04:
/* Ctrl+D = dismiss warning; advance to timeout */ /* Ctrl+D = dismiss warning; advance to timeout */
VBDEBUG(("VbBootDeveloper() - user pressed Ctrl+D; skip delay\n")); VBDEBUG(("VbBootDeveloper() - user pressed Ctrl+D; skip delay\n"));
delay_time = DEV_DELAY_TIMEOUT; goto fallout;
break; break;
case 0x15: case 0x15:
/* Ctrl+U = try USB boot, or beep if failure */ /* Ctrl+U = try USB boot, or beep if failure */
VBDEBUG(("VbBootDeveloper() - user pressed Ctrl+U; try USB\n")); VBDEBUG(("VbBootDeveloper() - user pressed Ctrl+U; try USB\n"));
VbExBeep(0, 0); /* sound off */
if (!allow_usb) { if (!allow_usb) {
VBDEBUG(("VbBootDeveloper() - USB booting is disabled\n")); VBDEBUG(("VbBootDeveloper() - USB booting is disabled\n"));
VbExBeep(DEV_DELAY_INCREMENT / 2, 400); VbExBeep(120, 400);
VbExSleepMs(DEV_DELAY_INCREMENT / 2); VbExSleepMs(120);
VbExBeep(DEV_DELAY_INCREMENT / 2, 400); VbExBeep(120, 400);
} else if (VBERROR_SUCCESS == } else if (VBERROR_SUCCESS ==
VbTryLoadKernel(cparams, p, VB_DISK_FLAG_REMOVABLE)) { VbTryLoadKernel(cparams, p, VB_DISK_FLAG_REMOVABLE)) {
VBDEBUG(("VbBootDeveloper() - booting USB\n")); VBDEBUG(("VbBootDeveloper() - booting USB\n"));
return VBERROR_SUCCESS; return VBERROR_SUCCESS;
} else { } else {
VBDEBUG(("VbBootDeveloper() - no kernel found on USB\n")); VBDEBUG(("VbBootDeveloper() - no kernel found on USB\n"));
VbExBeep(DEV_DELAY_INCREMENT, 400); VbExBeep(250, 200);
VbExBeep(100, 0);
/* Clear recovery requests from failed kernel loading, so /* Clear recovery requests from failed kernel loading, so
* that powering off at this point doesn't put us into * that powering off at this point doesn't put us into
* recovery mode. */ * recovery mode. */
@@ -186,9 +219,47 @@ VbError_t VbBootDeveloper(VbCommonParams* cparams, LoadKernelParams* p) {
VbCheckDisplayKey(cparams, key, &vnc); VbCheckDisplayKey(cparams, key, &vnc);
break; break;
} }
/* Time to play a note? */
if (!current_note_loops) {
VBDEBUG(("VbBootDeveloper() - current_note is %d\n", current_note));
/* Sorry, out of notes */
if (current_note >= note_count)
break;
/* For how many loops do we hold this note? */
current_note_loops = VbMsecToLoops(music_notes[current_note].msec);
VBDEBUG(("VbBootDeveloper() - new current_note_loops == %d\n",
current_note_loops));
if (background_beep) {
/* start (or stop) the sound */
VbExBeep(0, music_notes[current_note].frequency);
} else if (music_notes[current_note].frequency) {
/* the sound will block, so don't loop repeatedly */
current_note_loops = 1;
VbExBeep(music_notes[current_note].msec,
music_notes[current_note].frequency);
} }
current_note++;
}
/* Wait a bit. Yes, one extra loop sometimes, but it's only 10msec */
VbExSleepMs(DEV_LOOP_TIME);
/* That's one... */
if (current_note_loops)
current_note_loops--;
}
fallout:
/* Timeout or Ctrl+D; attempt loading from fixed disk */ /* Timeout or Ctrl+D; attempt loading from fixed disk */
VbExBeep(0, 0); /* sound off */
VBDEBUG(("VbBootDeveloper() - trying fixed disk\n")); VBDEBUG(("VbBootDeveloper() - trying fixed disk\n"));
return VbTryLoadKernel(cparams, p, VB_DISK_FLAG_FIXED); return VbTryLoadKernel(cparams, p, VB_DISK_FLAG_FIXED);
} }