summaryrefslogtreecommitdiff
path: root/common/cmd_vbexport_test.c
diff options
context:
space:
mode:
authorTom Wai-Hong Tam <waihong@chromium.org>2011-06-28 15:56:00 +0800
committerSimon Glass <sjg@chromium.org>2011-08-29 10:39:38 -0700
commit03d42cec762af381f8510e1291330b9160099c19 (patch)
treed3d61de3e7405914e2f47356fc8c7deaddf682bc /common/cmd_vbexport_test.c
parentc74acad6927b8c04c980f426ff68d11c4fabf12c (diff)
CHROMIUM: Implement read and write disk for vboot_wrapper APIs.
An unit test is also added. BUG=chromium-os:16543 TEST=Build u-boot and put it in seaboard and run: Tegra2 (SeaBoard) # vbexport_test diskrw Requested clock rate 52000000 not honored (got 48000000) Read and write disk test SUCCESS. Change-Id: I005ecaa6e981324c57da09bc93c8dd3b218148f3 Reviewed-on: http://gerrit.chromium.org/gerrit/2850 Reviewed-by: Tom Wai-Hong Tam <waihong@chromium.org> Tested-by: Tom Wai-Hong Tam <waihong@chromium.org>
Diffstat (limited to 'common/cmd_vbexport_test.c')
-rw-r--r--common/cmd_vbexport_test.c69
1 files changed, 68 insertions, 1 deletions
diff --git a/common/cmd_vbexport_test.c b/common/cmd_vbexport_test.c
index 734ea809aa..48205bb715 100644
--- a/common/cmd_vbexport_test.c
+++ b/common/cmd_vbexport_test.c
@@ -18,6 +18,9 @@
#include <command.h>
#include <vboot_api.h>
+#define TEST_LBA_START 0
+#define TEST_LBA_COUNT 2
+
static int do_vbexport_test_debug(
cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
@@ -202,6 +205,67 @@ static int do_vbexport_test_diskinfo(
return ret;
}
+static int do_vbexport_test_diskrw(
+ cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+ int ret = 0;
+ VbDiskInfo *disk_info;
+ VbExDiskHandle_t handle;
+ uint32_t disk_count, buf_byte_count, i;
+ uint8_t *original_buf, *target_buf, *verify_buf;
+
+ /* We perform read/write operations on the first internal disk. */
+ if (VbExDiskGetInfo(&disk_info, &disk_count, VB_DISK_FLAG_FIXED) ||
+ disk_count == 0) {
+ VbExDebug("No internal disk found!\n");
+ return 1;
+ }
+ handle = disk_info[0].handle;
+ buf_byte_count = disk_info[0].bytes_per_lba * TEST_LBA_COUNT;
+ VbExDiskFreeInfo(disk_info, handle);
+
+ /* Allocate the buffer and fill the target test pattern. */
+ original_buf = VbExMalloc(buf_byte_count);
+ target_buf = VbExMalloc(buf_byte_count);
+ verify_buf = VbExMalloc(buf_byte_count);
+ for (i = 0; i < buf_byte_count; i++) {
+ target_buf[i] = i % 0x100;
+ }
+
+ if (VbExDiskRead(handle, TEST_LBA_START, TEST_LBA_COUNT,
+ original_buf)) {
+ VbExDebug("Failed to read disk.\n");
+ return 1;
+ }
+
+ if (VbExDiskWrite(handle, TEST_LBA_START, TEST_LBA_COUNT,
+ target_buf)) {
+ VbExDebug("Failed to write disk.\n");
+ ret = 1;
+ } else {
+ /* Read back and verify the data. */
+ VbExDiskRead(handle, TEST_LBA_START, TEST_LBA_COUNT,
+ verify_buf);
+ if (memcmp(target_buf, verify_buf, buf_byte_count) != 0) {
+ VbExDebug("Verify failed. The target data wrote "
+ "wrong.\n");
+ ret = 1;
+ }
+ }
+
+ /* Write the original data back. */
+ VbExDiskWrite(handle, TEST_LBA_START, TEST_LBA_COUNT, original_buf);
+
+ VbExFree(original_buf);
+ VbExFree(target_buf);
+ VbExFree(verify_buf);
+
+ if (ret == 0)
+ VbExDebug("Read and write disk test SUCCESS.\n");
+
+ return ret;
+}
+
static int do_vbexport_test_all(
cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
@@ -211,6 +275,7 @@ static int do_vbexport_test_all(
ret |= do_vbexport_test_sleep(cmdtp, flag, argc, argv);
ret |= do_vbexport_test_beep(cmdtp, flag, argc, argv);
ret |= do_vbexport_test_diskinfo(cmdtp, flag, argc, argv);
+ ret |= do_vbexport_test_diskrw(cmdtp, flag, argc, argv);
if (!ret)
VbExDebug("All tests passed!\n");
return ret;
@@ -224,6 +289,7 @@ static cmd_tbl_t cmd_vbexport_test_sub[] = {
U_BOOT_CMD_MKENT(longsleep, 0, 1, do_vbexport_test_longsleep, "", ""),
U_BOOT_CMD_MKENT(beep, 0, 1, do_vbexport_test_beep, "", ""),
U_BOOT_CMD_MKENT(diskinfo, 0, 1, do_vbexport_test_diskinfo, "", ""),
+ U_BOOT_CMD_MKENT(diskrw, 0, 1, do_vbexport_test_diskrw, "", ""),
};
static int do_vbexport_test(
@@ -252,6 +318,7 @@ U_BOOT_CMD(vbexport_test, CONFIG_SYS_MAXARGS, 1, do_vbexport_test,
"vbexport_test sleep - test the sleep and timer functions\n"
"vbexport_test longsleep - test the sleep functions for long delays\n"
"vbexport_test beep - test the beep functions\n"
- "vbexport_test diskinfo - test the diskgetinfo and free functions"
+ "vbexport_test diskinfo - test the diskgetinfo and free functions\n"
+ "vbexport_test diskrw - test the disk read and write functions"
);