summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Jeffery <andrew@aj.id.au>2018-02-22 17:35:34 +1030
committerAndrew Jeffery <andrew@aj.id.au>2018-03-24 13:59:32 +1030
commitf050fcf9ef67756546d4decb2ef6cffbb1af41a8 (patch)
tree8956322fce1a1eaf78b40500d20a51be2612ca9e
parentad341a2e1c8d81ae99ecbe2e93fd8c98c35e772d (diff)
downloadphosphor-mboxd-f050fcf9ef67756546d4decb2ef6cffbb1af41a8.tar.gz
phosphor-mboxd-f050fcf9ef67756546d4decb2ef6cffbb1af41a8.zip
test: vpnor: Extract write_ro from write_flash_vpnor
Change-Id: I10b82d84cd40d52b0a489dc834269eec1a0d5240 Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
-rw-r--r--test/vpnor/Makefile.am.include13
-rw-r--r--test/vpnor/write_flash_vpnor.cpp12
-rw-r--r--test/vpnor/write_ro.cpp50
3 files changed, 62 insertions, 13 deletions
diff --git a/test/vpnor/Makefile.am.include b/test/vpnor/Makefile.am.include
index 5b6cc3d..b28f586 100644
--- a/test/vpnor/Makefile.am.include
+++ b/test/vpnor/Makefile.am.include
@@ -45,10 +45,21 @@ test_vpnor_write_prsv_SOURCES = \
test_vpnor_write_prsv_LDFLAGS = $(OESDK_TESTCASE_FLAGS)
test_vpnor_write_prsv_LDADD = $(VPNOR_LDADD)
+test_vpnor_write_ro_SOURCES = \
+ $(TEST_MBOX_VPNOR_SRCS) \
+ mboxd_pnor_partition_table.cpp \
+ mboxd_flash_virtual.cpp \
+ mtd.c \
+ pnor_partition.cpp \
+ %reldir%/write_ro.cpp
+test_vpnor_write_ro_LDFLAGS = $(OESDK_TESTCASE_FLAGS)
+test_vpnor_write_ro_LDADD = $(VPNOR_LDADD)
+
if VIRTUAL_PNOR_ENABLED
check_PROGRAMS += \
%reldir%/create_pnor_partition_table \
%reldir%/create_read_window_vpnor \
%reldir%/write_flash_vpnor \
- %reldir%/write_prsv
+ %reldir%/write_prsv \
+ %reldir%/write_ro
endif
diff --git a/test/vpnor/write_flash_vpnor.cpp b/test/vpnor/write_flash_vpnor.cpp
index 23d065d..9b6fc89 100644
--- a/test/vpnor/write_flash_vpnor.cpp
+++ b/test/vpnor/write_flash_vpnor.cpp
@@ -101,18 +101,6 @@ int main(void)
// create the partition table
vpnor_create_partition_table_from_path(ctx, root.ro().c_str());
- // Write to the RO partition
- memset(src, 0x55, sizeof(src));
- fd = open((root.ro() / "TEST1").c_str(), O_RDONLY);
- map = mmap(NULL, MEM_SIZE, PROT_READ, MAP_PRIVATE, fd, 0);
- assert(map != MAP_FAILED);
- rc = write_flash(ctx, (OFFSET), src, sizeof(src));
- // Should not be allowed to write on RO
- assert(rc != 0);
-
- munmap(map, MEM_SIZE);
- close(fd);
-
// Write to the RW partition
memset(src, 0xbb, sizeof(src));
fd = open((root.rw() / "TEST2").c_str(), O_RDONLY);
diff --git a/test/vpnor/write_ro.cpp b/test/vpnor/write_ro.cpp
new file mode 100644
index 0000000..fe934dd
--- /dev/null
+++ b/test/vpnor/write_ro.cpp
@@ -0,0 +1,50 @@
+// SPDX-License-Identifier: Apache-2.0
+// Copyright (C) 2018 IBM Corp.
+
+#include <assert.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include "common.h"
+#include "mbox.h"
+#include "mboxd_flash.h"
+
+#include "test/vpnor/tmpd.hpp"
+
+static constexpr auto BLOCK_SIZE = 0x1000;
+
+const std::string toc[] = {
+ "partition01=TEST1,00001000,00002000,80,ECC,READONLY",
+};
+
+int main(void)
+{
+ namespace fs = std::experimental::filesystem;
+ namespace test = openpower::virtual_pnor::test;
+
+ struct mbox_context _ctx, *ctx = &_ctx;
+ uint8_t src[8] = {0};
+ int rc;
+
+ /* Setup */
+ memset(ctx, 0, sizeof(mbox_context));
+
+ mbox_vlog = &mbox_log_console;
+ verbosity = (verbose)2;
+
+ test::VpnorRoot root(ctx, toc, BLOCK_SIZE);
+ vpnor_create_partition_table_from_path(ctx, root.ro().c_str());
+
+ /* Test */
+ rc = write_flash(ctx, 0x1000, src, sizeof(src));
+
+ /* Verify we can't write to RO partitions */
+ assert(rc != 0);
+
+ destroy_vpnor(ctx);
+
+ return 0;
+}
OpenPOWER on IntegriCloud