1791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
2791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson * Use of this source code is governed by a BSD-style license that can be
3791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson * found in the LICENSE file.
4791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson *
5791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson * Tests for vboot_api_firmware
6791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson */
7791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
8791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson#include <stddef.h>
90c3ba249abb1dc60f5ebabccf84ff13206440b83Bill Richardson#include <stdint.h>
1094d703459063fd144ec31ea0b70b9e94b208cfc8Bill Richardson#include <stdio.h>
11791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson#include <stdlib.h>
12791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
13791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson#include "crc32.h"
1494d703459063fd144ec31ea0b70b9e94b208cfc8Bill Richardson#include "gbb_header.h"
15791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson#include "host_common.h"
1694d703459063fd144ec31ea0b70b9e94b208cfc8Bill Richardson#include "load_kernel_fw.h"
17791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson#include "rollback_index.h"
18791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson#include "test_common.h"
19791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson#include "vboot_common.h"
2094d703459063fd144ec31ea0b70b9e94b208cfc8Bill Richardson#include "vboot_display.h"
21791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson#include "vboot_nvstorage.h"
22791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson#include "vboot_struct.h"
23791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
24791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
25791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson/* Expected results */
26791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
27791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson#define MAX_NOTE_EVENTS 10
28037dba21243559e93aa98c428c0655ceb418b23fBill Richardson#define TICKS_PER_MSEC 1900ULL
29037dba21243559e93aa98c428c0655ceb418b23fBill Richardson#define TIME_FUZZ 500
30037dba21243559e93aa98c428c0655ceb418b23fBill Richardson#define KBD_READ_TIME 60
31791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
32791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardsontypedef struct {
33791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  uint16_t msec;
34791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  uint16_t freq;
35037dba21243559e93aa98c428c0655ceb418b23fBill Richardson  int time;
36791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson} note_event_t;
37791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
38791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardsontypedef struct {
39791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  char *name;
40791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  uint32_t gbb_flags;
41791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  VbError_t beep_return;
42791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  uint32_t keypress_key;
43791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  int keypress_at_count;
44791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  int num_events;
45791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  note_event_t notes[MAX_NOTE_EVENTS];
46791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson} test_case_t;
47791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
48791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardsontest_case_t test[] = {
49791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
50791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  { "VbBootDeveloperSoundTest( fast, background )",
51791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    0x00000001, VBERROR_SUCCESS,
52791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    0, 0,
53037dba21243559e93aa98c428c0655ceb418b23fBill Richardson    2,
54791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    {
55791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson      {0, 0, 0},                        // probing for capability
56791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson      {0, 0, 2000},                     // off and return at 2 seconds
57791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    }},
58791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
59791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  { "VbBootDeveloperSoundTest( normal, background )",
60791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    0x00000000, VBERROR_SUCCESS,
61791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    0, 0,
62037dba21243559e93aa98c428c0655ceb418b23fBill Richardson    6,
63791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    {
64791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson      {0, 0, 0},                        // probing for capability
65791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson      {0, 400, 20000},                  // starts first beep at 20 seconds
66791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson      {0, 0, 20250},                    // stops 250ms later
67791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson      {0, 400, 20500},                  // starts second beep
68791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson      {0, 0, 20750},                    // stops 250ms later
69791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson      {0, 0, 30000},                    // off and return at 30 seconds
70791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    }},
71791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
72791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  { "VbBootDeveloperSoundTest( fast, no background )",
73791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    0x00000001, VBERROR_NO_BACKGROUND_SOUND,
74791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    0, 0,
75791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    2,
76791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    {
77791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson      {0, 0, 0},                        // probing for capability
78791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson      {0, 0, 2000},                     // off and return at 2 seconds
79791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    }},
80791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
81791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  { "VbBootDeveloperSoundTest( normal, no background )",
82791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    0x00000000, VBERROR_NO_BACKGROUND_SOUND,
83791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    0, 0,
84791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    4,
85791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    {
86791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson      {0, 0, 0},                        // probing for capability
87791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson      {250, 400, 20000},                // first beep at 20 seconds
88791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson      {250, 400, 20510},                // second beep shortly after
89791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson      {0, 0, 30020},                    // off and return at 30 seconds
90791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    }},
91791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
92791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  // Now with some keypresses
93791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
94791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  { "VbBootDeveloperSoundTest( normal, background, Ctrl-D )",
95791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    0x00000000, VBERROR_SUCCESS,
96791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    4, 10000,                           // Ctrl-D at 10 seconds
97037dba21243559e93aa98c428c0655ceb418b23fBill Richardson    2,
98791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    {
99791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson      {0, 0, 0},                        // probing for capability
100791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson      {0, 0, 10000},                    // sees Ctrl-D, sound off, return
101791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    }},
102791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
103791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  { "VbBootDeveloperSoundTest( normal, no background, Ctrl-D )",
104791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    0x00000000, VBERROR_NO_BACKGROUND_SOUND,
105791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    4, 20400,                           // Ctrl-D between beeps
106791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    3,
107791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    {
108791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson      {0, 0, 0},                        // probing for capability
109791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson      {250, 400, 20000},                // first beep at 20 seconds
110791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson      {0, 0, 20400},                    // sees Ctrl-D, sound off, return
111791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    }},
112791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
113791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  { "VbBootDeveloperSoundTest( normal, background, Ctrl-U not allowed )",
114791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    0x00000000, VBERROR_SUCCESS,
115791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    21, 10000,                          // Ctrl-U at 10 seconds
116037dba21243559e93aa98c428c0655ceb418b23fBill Richardson    8,
117791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    {
118791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson      {0, 0, 0},                        // probing for capability
119791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson      {120, 400, 10000},                // complains about Ctrl-U (one beep)
120791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson                                        // waits 120ms...
121791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson      {120, 400, 10240},                // complains about Ctrl-U (two beeps)
122791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson                                        // original sequence is now shifted...
123791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson      {0, 400, 20360},                  // starts first beep at 20 seconds
124791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson      {0, 0, 20610},                    // stops 250ms later
125791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson      {0, 400, 20860},                  // starts second beep
126791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson      {0, 0, 21110},                    // stops 250ms later
127791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson      {0, 0, 30360},                    // returns at 30 seconds + 360ms
128791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    }},
129791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
130791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson};
131791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
132791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson/* Mock data */
133791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardsonstatic VbCommonParams cparams;
134791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardsonstatic LoadKernelParams lkparams;
135791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardsonstatic VbNvContext vnc;
136791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardsonstatic uint8_t shared_data[VB_SHARED_DATA_MIN_SIZE];
137791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardsonstatic VbSharedDataHeader* shared = (VbSharedDataHeader*)shared_data;
138791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardsonstatic GoogleBinaryBlockHeader gbb;
139791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardsonstatic int current_time;
140037dba21243559e93aa98c428c0655ceb418b23fBill Richardsonstatic uint64_t current_ticks;
141791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardsonstatic int current_event;
142791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardsonstatic int max_events;
143791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardsonstatic int matched_events;
144791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardsonstatic int kbd_fire_at;
145791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardsonstatic uint32_t kbd_fire_key;
146791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardsonstatic VbError_t beep_return;
147791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardsonstatic note_event_t *expected_event;
148791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
149791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson/* Reset mock data (for use before each test) */
150791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardsonstatic void ResetMocks(void) {
151791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
152791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  Memset(&cparams, 0, sizeof(cparams));
153791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  cparams.shared_data_size = sizeof(shared_data);
154791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  cparams.shared_data_blob = shared_data;
155791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  cparams.gbb_data = &gbb;
156527ba810eff4006cf69579f6b96cb4350cb1e189Simon Glass  cparams.gbb = &gbb;
157791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
158791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  Memset(&lkparams, 0, sizeof(lkparams));
159791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
160791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  Memset(&vnc, 0, sizeof(vnc));
161791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  VbNvSetup(&vnc);
162791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  VbNvTeardown(&vnc);  /* So CRC gets generated */
163791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
164791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  Memset(&shared_data, 0, sizeof(shared_data));
165791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  VbSharedDataInit(shared, sizeof(shared_data));
166791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  shared->fw_keyblock_flags = 0xABCDE0;
167791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
168791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  Memset(&gbb, 0, sizeof(gbb));
169791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  gbb.major_version = GBB_MAJOR_VER;
170791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  gbb.minor_version = GBB_MINOR_VER;
171791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  gbb.flags = 0;
172791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
173037dba21243559e93aa98c428c0655ceb418b23fBill Richardson  current_ticks = 0;
174791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  current_time = 0;
175037dba21243559e93aa98c428c0655ceb418b23fBill Richardson
176791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  current_event = 0;
177791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  kbd_fire_at = 0;
178791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  kbd_fire_key = 0;
179791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
180791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  beep_return = VBERROR_SUCCESS;
181791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
182791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  matched_events = 0;
183791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  max_events = 0;
184791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson}
185791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
186791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson/****************************************************************************/
187791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson/* Mocked verification functions */
188791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
189791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill RichardsonVbError_t VbExNvStorageRead(uint8_t* buf) {
190791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  Memcpy(buf, vnc.raw, sizeof(vnc.raw));
191791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  return VBERROR_SUCCESS;
192791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson}
193791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
194791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill RichardsonVbError_t VbExNvStorageWrite(const uint8_t* buf) {
195791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  Memcpy(vnc.raw, buf, sizeof(vnc.raw));
196791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  return VBERROR_SUCCESS;
197791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson}
198791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
199791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill RichardsonVbError_t VbExDiskGetInfo(VbDiskInfo** infos_ptr, uint32_t* count,
200791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson                          uint32_t disk_flags) {
201791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  return VBERROR_UNKNOWN;
202791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson}
203791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
204791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill RichardsonVbError_t VbExDiskFreeInfo(VbDiskInfo* infos,
205791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson                           VbExDiskHandle_t preserve_handle) {
206791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  return VBERROR_SUCCESS;
207791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson}
208791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
209791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill RichardsonVbError_t VbExDiskRead(VbExDiskHandle_t handle, uint64_t lba_start,
210791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson                       uint64_t lba_count, void* buffer) {
211791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  return VBERROR_UNKNOWN;
212791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson}
213791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
214791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill RichardsonVbError_t VbExDiskWrite(VbExDiskHandle_t handle, uint64_t lba_start,
215791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson                        uint64_t lba_count, const void* buffer) {
216791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  return VBERROR_UNKNOWN;
217791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson}
218791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
219791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardsonuint32_t VbExIsShutdownRequested(void) {
220791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  return 0;
221791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson}
222791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
223791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardsonuint32_t VbExKeyboardRead(void) {
224791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  uint32_t tmp;
225037dba21243559e93aa98c428c0655ceb418b23fBill Richardson  uint32_t now;
226037dba21243559e93aa98c428c0655ceb418b23fBill Richardson
227037dba21243559e93aa98c428c0655ceb418b23fBill Richardson  VbExSleepMs(KBD_READ_TIME);
228037dba21243559e93aa98c428c0655ceb418b23fBill Richardson  now = current_time;
229037dba21243559e93aa98c428c0655ceb418b23fBill Richardson
230037dba21243559e93aa98c428c0655ceb418b23fBill Richardson  if (kbd_fire_key && now >= kbd_fire_at) {
231791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    VBDEBUG(("  VbExKeyboardRead() - returning %d at %d msec\n",
232037dba21243559e93aa98c428c0655ceb418b23fBill Richardson             kbd_fire_key, now));
233791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    tmp = kbd_fire_key;
234791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    kbd_fire_key = 0;
235791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    return tmp;
236791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  }
237037dba21243559e93aa98c428c0655ceb418b23fBill Richardson  VBDEBUG(("  VbExKeyboardRead() - returning %d at %d msec\n",
238037dba21243559e93aa98c428c0655ceb418b23fBill Richardson           0, now));
239791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  return 0;
240791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson}
241791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
242791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardsonvoid VbExSleepMs(uint32_t msec) {
243037dba21243559e93aa98c428c0655ceb418b23fBill Richardson  current_ticks += (uint64_t)msec * TICKS_PER_MSEC;
244037dba21243559e93aa98c428c0655ceb418b23fBill Richardson  current_time = current_ticks / TICKS_PER_MSEC;
245037dba21243559e93aa98c428c0655ceb418b23fBill Richardson  VBDEBUG(("VbExSleepMs(%d) -> %d\n", msec, current_time));
246037dba21243559e93aa98c428c0655ceb418b23fBill Richardson}
247037dba21243559e93aa98c428c0655ceb418b23fBill Richardson
248037dba21243559e93aa98c428c0655ceb418b23fBill Richardsonuint64_t VbExGetTimer(void) {
249037dba21243559e93aa98c428c0655ceb418b23fBill Richardson  return current_ticks;
250791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson}
251791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
252791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill RichardsonVbError_t VbExBeep(uint32_t msec, uint32_t frequency) {
253791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  VBDEBUG(("VbExBeep(%d, %d) at %d msec\n", msec, frequency, current_time));
254791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
255791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  if (current_event < max_events &&
256791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson      msec == expected_event[current_event].msec &&
257791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson      frequency == expected_event[current_event].freq &&
258037dba21243559e93aa98c428c0655ceb418b23fBill Richardson      abs(current_time - expected_event[current_event].time) < TIME_FUZZ ) {
259791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    matched_events++;
260791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  }
261791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
262037dba21243559e93aa98c428c0655ceb418b23fBill Richardson  if (msec)
263037dba21243559e93aa98c428c0655ceb418b23fBill Richardson    VbExSleepMs(msec);
264791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  current_event++;
265791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  return beep_return;
266791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson}
267791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
268791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill RichardsonVbError_t VbExDisplayScreen(uint32_t screen_type) {
269791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  switch(screen_type) {
270791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  case VB_SCREEN_BLANK:
271791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    VBDEBUG(("VbExDisplayScreen(BLANK)\n"));
272791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    break;
273791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  case VB_SCREEN_DEVELOPER_WARNING:
274791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    VBDEBUG(("VbExDisplayScreen(DEV)\n"));
275791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    break;
276791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  case VB_SCREEN_DEVELOPER_EGG:
277791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    VBDEBUG(("VbExDisplayScreen(EGG)\n"));
278791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    break;
279791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  case VB_SCREEN_RECOVERY_REMOVE:
280791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    VBDEBUG(("VbExDisplayScreen(REMOVE)\n"));
281791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    break;
282791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  case VB_SCREEN_RECOVERY_INSERT:
283791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    VBDEBUG(("VbExDisplayScreen(INSERT)\n"));
284791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    break;
285791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  case VB_SCREEN_RECOVERY_NO_GOOD:
286791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    VBDEBUG(("VbExDisplayScreen(NO_GOOD)\n"));
287791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    break;
288791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  default:
289791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    VBDEBUG(("VbExDisplayScreen(%d)\n", screen_type));
290791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  }
291791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
292791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  VBDEBUG(("  current_time is %d msec\n", current_time));
293791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
294791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  return VBERROR_SUCCESS;
295791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson}
296791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
297791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson/****************************************************************************/
298791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
299791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill RichardsonVbError_t VbBootDeveloper(VbCommonParams* cparams, LoadKernelParams* p);
300791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
301791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
302791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardsonstatic void VbBootDeveloperSoundTest(void) {
303791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  int i;
304791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  int num_tests =  sizeof(test) / sizeof(test_case_t);
305791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
306791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  for (i=0; i<num_tests; i++) {
307791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    VBDEBUG(("STARTING %s ...\n", test[i].name));
308791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    ResetMocks();
309791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    gbb.flags = test[i].gbb_flags;
310791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    beep_return = test[i].beep_return;
311791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    kbd_fire_key = test[i].keypress_key;
312791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    kbd_fire_at = test[i].keypress_at_count;
313791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    max_events = test[i].num_events;
314791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    expected_event = test[i].notes;
315791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    (void) VbBootDeveloper(&cparams, &lkparams);
316791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    VBDEBUG(("INFO: matched %d total %d expected %d\n",
317791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson             matched_events, current_event, test[i].num_events));
31894d703459063fd144ec31ea0b70b9e94b208cfc8Bill Richardson    TEST_TRUE(matched_events == test[i].num_events &&
31994d703459063fd144ec31ea0b70b9e94b208cfc8Bill Richardson              current_event == test[i].num_events, test[i].name);
320791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  }
321791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson}
322791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
323791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
324791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardsonint main(int argc, char* argv[]) {
325791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  int error_code = 0;
326791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
327791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  VbBootDeveloperSoundTest();
328791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
329791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  if (!gTestSuccess)
330791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson    error_code = 255;
3312500185a83b453580f187087fffc6376f19f8ff0Simon Glass  if (vboot_api_stub_check_memory())
3322500185a83b453580f187087fffc6376f19f8ff0Simon Glass    error_code = 255;
333791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson
334791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson  return error_code;
335791c95fa23d93fb6104f3c6ec248c7ad4c773b8cBill Richardson}
336