test: mbr: Use RAM for the buffers
The normal approach with sandbox is to use a fixed memory address in the
RAM, to avoid needing to create a map for transient local variables.
Update this test to use this approach.
Signed-off-by: Simon Glass <sjg@chromium.org>
diff --git a/test/cmd/mbr.c b/test/cmd/mbr.c
index e67e777..7279961 100644
--- a/test/cmd/mbr.c
+++ b/test/cmd/mbr.c
@@ -232,9 +232,11 @@
static int mbr_test_run(struct unit_test_state *uts)
{
struct blk_desc *mmc_dev_desc;
- unsigned char mbr_wbuf[BLKSZ], ebr_wbuf[BLKSZ], rbuf[BLKSZ];
+ unsigned char *mbr_wbuf, *ebr_wbuf, *rbuf;
char mbr_parts_buf[256];
- ulong mbr_wa, ebr_wa, ra, ebr_blk, mbr_parts_max;
+ ulong addr = 0x1000; /* start address for buffers */
+ ulong mbr_wa = addr, ebr_wa = addr + BLKSZ, ra = addr + BLKSZ * 2;
+ ulong ebr_blk, mbr_parts_max;
struct udevice *dev;
ofnode root, node;
@@ -258,9 +260,9 @@
ut_assertf(sizeof(mbr_parts_buf) >= mbr_parts_max, "Buffer avail: %ld; buffer req: %ld\n",
sizeof(mbr_parts_buf), mbr_parts_max);
- mbr_wa = map_to_sysmem(mbr_wbuf);
- ebr_wa = map_to_sysmem(ebr_wbuf);
- ra = map_to_sysmem(rbuf);
+ mbr_wbuf = map_sysmem(mbr_wa, BLKSZ);
+ ebr_wbuf = map_sysmem(ebr_wa, BLKSZ);
+ rbuf = map_sysmem(ra, BLKSZ);
ebr_blk = (ulong)0xb00000 / BLKSZ;
/* Make sure mmc6 exists */
@@ -278,11 +280,11 @@
init_write_buffers(mbr_wbuf, sizeof(mbr_wbuf), ebr_wbuf, sizeof(ebr_wbuf), __LINE__);
ut_assertok(build_mbr_parts(mbr_parts_buf, sizeof(mbr_parts_buf), 1));
ut_assertok(run_commandf("write mmc 6:0 %lx 0 1", mbr_wa));
- memset(rbuf, 0, sizeof(rbuf));
+ memset(rbuf, '\0', BLKSZ);
ut_assertok(run_commandf("read mmc 6:0 %lx 0 1", ra));
ut_assertok(memcmp(mbr_wbuf, rbuf, BLKSZ));
ut_assertok(run_commandf("write mmc 6:0 %lx %lx 1", ebr_wa, ebr_blk));
- memset(rbuf, 0, sizeof(rbuf));
+ memset(rbuf, '\0', BLKSZ);
ut_assertok(run_commandf("read mmc 6:0 %lx %lx 1", ra, ebr_blk));
ut_assertok(memcmp(ebr_wbuf, rbuf, BLKSZ));
ut_assertf(0 == run_commandf(mbr_parts_buf), "Invalid partitions string: %s\n", mbr_parts_buf);
@@ -291,7 +293,7 @@
ut_assert_nextline("MBR: write success!");
ut_assertok(run_commandf("mbr verify mmc 6"));
ut_assert_nextline("MBR: verify success!");
- memset(rbuf, 0, sizeof(rbuf));
+ memset(rbuf, '\0', BLKSZ);
ut_assertok(run_commandf("read mmc 6:0 %lx %lx 1", ra, ebr_blk));
ut_assertok(memcmp(ebr_wbuf, rbuf, BLKSZ));
ut_assert_console_end();
@@ -302,7 +304,7 @@
000001e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
000001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa |..............U.|
*/
- memset(rbuf, 0, sizeof(rbuf));
+ memset(rbuf, '\0', BLKSZ);
ut_assertok(run_commandf("read mmc 6:0 %lx 0 1", ra));
for (unsigned i = 0; i < mbr_cmp_size; i++) {
ut_assertf(rbuf[mbr_cmp_start + i] == mbr_parts_ref_p1[i],
@@ -314,11 +316,11 @@
init_write_buffers(mbr_wbuf, sizeof(mbr_wbuf), ebr_wbuf, sizeof(ebr_wbuf), __LINE__);
ut_assertok(build_mbr_parts(mbr_parts_buf, sizeof(mbr_parts_buf), 2));
ut_assertok(run_commandf("write mmc 6:0 %lx 0 1", mbr_wa));
- memset(rbuf, 0, sizeof(rbuf));
+ memset(rbuf, '\0', BLKSZ);
ut_assertok(run_commandf("read mmc 6:0 %lx 0 1", ra));
ut_assertok(memcmp(mbr_wbuf, rbuf, BLKSZ));
ut_assertok(run_commandf("write mmc 6:0 %lx %lx 1", ebr_wa, ebr_blk));
- memset(rbuf, 0, sizeof(rbuf));
+ memset(rbuf, '\0', BLKSZ);
ut_assertok(run_commandf("read mmc 6:0 %lx %lx 1", ra, ebr_blk));
ut_assertok(memcmp(ebr_wbuf, rbuf, BLKSZ));
ut_assertf(0 == run_commandf(mbr_parts_buf), "Invalid partitions string: %s\n", mbr_parts_buf);
@@ -326,7 +328,7 @@
ut_assert_nextline("MBR: write success!");
ut_assertok(run_commandf("mbr verify mmc 6"));
ut_assert_nextline("MBR: verify success!");
- memset(rbuf, 0, sizeof(rbuf));
+ memset(rbuf, '\0', BLKSZ);
ut_assertok(run_commandf("read mmc 6:0 %lx %lx 1", ra, ebr_blk));
ut_assertok(memcmp(ebr_wbuf, rbuf, BLKSZ));
ut_assert_console_end();
@@ -337,7 +339,7 @@
000001e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
000001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa |..............U.|
*/
- memset(rbuf, 0, sizeof(rbuf));
+ memset(rbuf, '\0', BLKSZ);
ut_assertok(run_commandf("read mmc 6:0 %lx 0 1", ra));
for (unsigned i = 0; i < mbr_cmp_size; i++) {
ut_assertf(rbuf[mbr_cmp_start + i] == mbr_parts_ref_p2[i],
@@ -349,11 +351,11 @@
init_write_buffers(mbr_wbuf, sizeof(mbr_wbuf), ebr_wbuf, sizeof(ebr_wbuf), __LINE__);
ut_assertok(build_mbr_parts(mbr_parts_buf, sizeof(mbr_parts_buf), 3));
ut_assertok(run_commandf("write mmc 6:0 %lx 0 1", mbr_wa));
- memset(rbuf, 0, sizeof(rbuf));
+ memset(rbuf, '\0', BLKSZ);
ut_assertok(run_commandf("read mmc 6:0 %lx 0 1", ra));
ut_assertok(memcmp(mbr_wbuf, rbuf, BLKSZ));
ut_assertok(run_commandf("write mmc 6:0 %lx %lx 1", ebr_wa, ebr_blk));
- memset(rbuf, 0, sizeof(rbuf));
+ memset(rbuf, '\0', BLKSZ);
ut_assertok(run_commandf("read mmc 6:0 %lx %lx 1", ra, ebr_blk));
ut_assertok(memcmp(ebr_wbuf, rbuf, BLKSZ));
ut_assertf(0 == run_commandf(mbr_parts_buf), "Invalid partitions string: %s\n", mbr_parts_buf);
@@ -361,7 +363,7 @@
ut_assert_nextline("MBR: write success!");
ut_assertok(run_commandf("mbr verify mmc 6"));
ut_assert_nextline("MBR: verify success!");
- memset(rbuf, 0, sizeof(rbuf));
+ memset(rbuf, '\0', BLKSZ);
ut_assertok(run_commandf("read mmc 6:0 %lx %lx 1", ra, ebr_blk));
ut_assertok(memcmp(ebr_wbuf, rbuf, BLKSZ));
ut_assert_console_end();
@@ -372,7 +374,7 @@
000001e0 06 01 0e 66 25 01 00 50 00 00 00 08 00 00 00 00 |...f%..P........|
000001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa |..............U.|
*/
- memset(rbuf, 0, sizeof(rbuf));
+ memset(rbuf, '\0', BLKSZ);
ut_assertok(run_commandf("read mmc 6:0 %lx 0 1", ra));
for (unsigned i = 0; i < mbr_cmp_size; i++) {
ut_assertf(rbuf[mbr_cmp_start + i] == mbr_parts_ref_p3[i],
@@ -384,11 +386,11 @@
init_write_buffers(mbr_wbuf, sizeof(mbr_wbuf), ebr_wbuf, sizeof(ebr_wbuf), __LINE__);
ut_assertok(build_mbr_parts(mbr_parts_buf, sizeof(mbr_parts_buf), 4));
ut_assertok(run_commandf("write mmc 6:0 %lx 0 1", mbr_wa));
- memset(rbuf, 0, sizeof(rbuf));
+ memset(rbuf, '\0', BLKSZ);
ut_assertok(run_commandf("read mmc 6:0 %lx 0 1", ra));
ut_assertok(memcmp(mbr_wbuf, rbuf, BLKSZ));
ut_assertok(run_commandf("write mmc 6:0 %lx %lx 1", ebr_wa, ebr_blk));
- memset(rbuf, 0, sizeof(rbuf));
+ memset(rbuf, '\0', BLKSZ);
ut_assertok(run_commandf("read mmc 6:0 %lx %lx 1", ra, ebr_blk));
ut_assertok(memcmp(ebr_wbuf, rbuf, BLKSZ));
ut_assertf(0 == run_commandf(mbr_parts_buf), "Invalid partitions string: %s\n", mbr_parts_buf);
@@ -396,7 +398,7 @@
ut_assert_nextline("MBR: write success!");
ut_assertok(run_commandf("mbr verify mmc 6"));
ut_assert_nextline("MBR: verify success!");
- memset(rbuf, 0, sizeof(rbuf));
+ memset(rbuf, '\0', BLKSZ);
ut_assertok(run_commandf("read mmc 6:0 %lx %lx 1", ra, ebr_blk));
ut_assertok(memcmp(ebr_wbuf, rbuf, BLKSZ));
ut_assert_console_end();
@@ -407,7 +409,7 @@
000001e0 06 01 0e 66 25 01 00 50 00 00 00 08 00 00 00 66 |...f%..P.......f|
000001f0 26 01 0e 87 06 01 00 58 00 00 00 08 00 00 55 aa |&......X......U.|
*/
- memset(rbuf, 0, sizeof(rbuf));
+ memset(rbuf, '\0', BLKSZ);
ut_assertok(run_commandf("read mmc 6:0 %lx 0 1", ra));
for (unsigned i = 0; i < mbr_cmp_size; i++) {
ut_assertf(rbuf[mbr_cmp_start + i] == mbr_parts_ref_p4[i],
@@ -419,11 +421,11 @@
init_write_buffers(mbr_wbuf, sizeof(mbr_wbuf), ebr_wbuf, sizeof(ebr_wbuf), __LINE__);
ut_assertok(build_mbr_parts(mbr_parts_buf, sizeof(mbr_parts_buf), 5));
ut_assertok(run_commandf("write mmc 6:0 %lx 0 1", mbr_wa));
- memset(rbuf, 0, sizeof(rbuf));
+ memset(rbuf, '\0', BLKSZ);
ut_assertok(run_commandf("read mmc 6:0 %lx 0 1", ra));
ut_assertok(memcmp(mbr_wbuf, rbuf, BLKSZ));
ut_assertok(run_commandf("write mmc 6:0 %lx %lx 1", ebr_wa, ebr_blk));
- memset(rbuf, 0, sizeof(rbuf));
+ memset(rbuf, '\0', BLKSZ);
ut_assertok(run_commandf("read mmc 6:0 %lx %lx 1", ra, ebr_blk));
ut_assertok(memcmp(ebr_wbuf, rbuf, BLKSZ));
ut_assertf(0 == run_commandf(mbr_parts_buf), "Invalid partitions string: %s\n", mbr_parts_buf);
@@ -439,7 +441,7 @@
000001e0 06 01 0e 66 25 01 00 50 00 00 00 08 00 00 00 66 |...f%..P.......f|
000001f0 26 01 05 a7 26 01 00 58 00 00 00 10 00 00 55 aa |&...&..X......U.|
*/
- memset(rbuf, 0, sizeof(rbuf));
+ memset(rbuf, '\0', BLKSZ);
ut_assertok(run_commandf("read mmc 6:0 %lx 0 1", ra));
for (unsigned i = 0; i < mbr_cmp_size; i++) {
ut_assertf(rbuf[mbr_cmp_start + i] == mbr_parts_ref_p5[i],
@@ -453,7 +455,7 @@
00b001e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00b001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa |..............U.|
*/
- memset(rbuf, 0, sizeof(rbuf));
+ memset(rbuf, '\0', BLKSZ);
ut_assertok(run_commandf("read mmc 6:0 %lx %lx 1", ra, ebr_blk));
for (unsigned i = 0; i < ebr_cmp_size; i++) {
ut_assertf(rbuf[ebr_cmp_start + i] == ebr_parts_ref_p5[i],