summaryrefslogtreecommitdiff
path: root/common/cmd_vboot_test.c
diff options
context:
space:
mode:
authorTom Wai-Hong Tam <waihong@chromium.org>2011-07-25 16:10:55 +0800
committerSimon Glass <sjg@chromium.org>2011-08-29 10:59:10 -0700
commitd35b07d80b44f300f461df4e20cf7b12e126f2e8 (patch)
tree4f1d8825e3ae53d779f56fbbccd31fb6f5b216e3 /common/cmd_vboot_test.c
parentb987ec791ede0f8215373c9a88585a9e41566ff0 (diff)
CHROMIUM: Test firmware and disk R/W with user-input length.
Also add timing metrics. It is useful for benchmark the firmware and disk R/W performance. BUG=chromium-os:18126 TEST=build and run on Aebl: Tegra2 # vboot_test fwrw 80000 test_fwrw: fw_read, length: 0x80000, time: 507045 test_fwrw: fw_write, length: 0x80000, time: 8620418 Read and write firmware test SUCCESS. Tegra2 # vbexport_test diskrw 1024 test_diskrw: disk_read, lba_count: 1024, time: 31019 test_diskrw: disk_write, lba_count: 1024, time: 94955 Read and write disk test SUCCESS. Change-Id: I8e92994dd8ca2938ec6d2b8321286f54ab5868a5 Reviewed-on: http://gerrit.chromium.org/gerrit/4652 Reviewed-by: Tom Wai-Hong Tam <waihong@chromium.org> Tested-by: Tom Wai-Hong Tam <waihong@chromium.org>
Diffstat (limited to 'common/cmd_vboot_test.c')
-rw-r--r--common/cmd_vboot_test.c72
1 files changed, 56 insertions, 16 deletions
diff --git a/common/cmd_vboot_test.c b/common/cmd_vboot_test.c
index 501f92c7e2..3abb5611db 100644
--- a/common/cmd_vboot_test.c
+++ b/common/cmd_vboot_test.c
@@ -24,8 +24,8 @@
* TODO: Pick a better region for test instead of GBB.
* We now test the region of GBB.
*/
-#define TEST_FW_START 0xbfc00
-#define TEST_FW_LENGTH 0x1000
+#define TEST_FW_START 0xc1000
+#define DEFAULT_TEST_FW_LENGTH 0x1000
DECLARE_GLOBAL_DATA_PTR;
@@ -34,14 +34,33 @@ static int do_vboot_test_fwrw(cmd_tbl_t *cmdtp,
{
int ret = 0;
firmware_storage_t file;
- uint8_t original_buf[TEST_FW_LENGTH];
- uint8_t target_buf[TEST_FW_LENGTH];
- uint8_t verify_buf[TEST_FW_LENGTH];
- int i;
+ uint32_t test_length, i;
+ uint8_t *original_buf, *target_buf, *verify_buf;
+ uint64_t t0, t1;
+
+ switch (argc) {
+ case 1: /* if no argument given, use the default length */
+ test_length = DEFAULT_TEST_FW_LENGTH;
+ break;
+ case 2: /* use argument */
+ test_length = simple_strtoul(argv[1], NULL, 16);
+ if (!test_length) {
+ VbExDebug("The first argument is not a number!\n");
+ return cmd_usage(cmdtp);
+ }
+ break;
+ default:
+ return cmd_usage(cmdtp);
+ }
+
+ /* Allocate the buffer and fill the target test pattern. */
+ original_buf = VbExMalloc(test_length);
+ target_buf = VbExMalloc(test_length);
+ verify_buf = VbExMalloc(test_length);
/* Fill the target test pattern. */
- for (i = 0; i < TEST_FW_LENGTH; i++)
- target_buf[i] = i & 0xFF;
+ for (i = 0; i < test_length; i++)
+ target_buf[i] = i & 0xff;
/* Open firmware storage device. */
if (firmware_storage_open_spi(&file)) {
@@ -49,29 +68,50 @@ static int do_vboot_test_fwrw(cmd_tbl_t *cmdtp,
return 1;
}
- if (file.read(&file, TEST_FW_START, TEST_FW_LENGTH, original_buf)) {
+ t0 = VbExGetTimer();
+ if (file.read(&file, TEST_FW_START, test_length, original_buf)) {
VbExDebug("Failed to read firmware!\n");
- return 1;
+ goto out;
}
-
- if (file.write(&file, TEST_FW_START, TEST_FW_LENGTH, target_buf)) {
+ t1 = VbExGetTimer();
+ VbExDebug("test_fwrw: fw_read, length: %#x, time: %llu\n",
+ test_length, t1 - t0);
+
+ t0 = VbExGetTimer();
+ ret = file.write(&file, TEST_FW_START, test_length, target_buf);
+ VbExDebug("file.write returned\n");
+ if (ret) {
VbExDebug("Failed to write firmware!\n");
ret = 1;
} else {
/* Read back and verify the data. */
- file.read(&file, TEST_FW_START, TEST_FW_LENGTH, verify_buf);
- if (memcmp(target_buf, verify_buf, TEST_FW_LENGTH) != 0) {
+ VbExDebug("start read again\n");
+ file.read(&file, TEST_FW_START, test_length, verify_buf);
+ VbExDebug("start memcmp\n");
+ if (memcmp(target_buf, verify_buf, test_length) != 0) {
VbExDebug("Verify failed. The target data wrote "
"wrong.\n");
ret = 1;
}
}
+ t1 = VbExGetTimer();
+ VbExDebug("test_fwrw: fw_write, length: %#x, time: %llu\n",
+ test_length, t1 - t0);
/* Write the original data back. */
- file.write(&file, TEST_FW_START, TEST_FW_LENGTH, original_buf);
+ if (file.write(&file, TEST_FW_START, test_length, original_buf)) {
+ VbExDebug("Failed to write the original data back. The "
+ "firmware may now be corrupt.\n");
+ }
+
+out:
file.close(&file);
+ VbExFree(original_buf);
+ VbExFree(target_buf);
+ VbExFree(verify_buf);
+
if (ret == 0)
VbExDebug("Read and write firmware test SUCCESS.\n");
@@ -174,7 +214,7 @@ static int do_vboot_test(cmd_tbl_t *cmdtp,
U_BOOT_CMD(vboot_test, CONFIG_SYS_MAXARGS, 1, do_vboot_test,
"Perform tests for basic vboot related utilities",
"all - perform all tests\n"
- "vboot_test fwrw - test the firmware read/write functions\n"
+ "vboot_test fwrw [length] - test the firmware read/write\n"
"vboot_test memwipe - test the memory wipe functions\n"
"vboot_test gpio - print the status of gpio\n"
);