From f050fcf9ef67756546d4decb2ef6cffbb1af41a8 Mon Sep 17 00:00:00 2001 From: Andrew Jeffery Date: Thu, 22 Feb 2018 17:35:34 +1030 Subject: test: vpnor: Extract write_ro from write_flash_vpnor Change-Id: I10b82d84cd40d52b0a489dc834269eec1a0d5240 Signed-off-by: Andrew Jeffery --- test/vpnor/Makefile.am.include | 13 ++++++++++- test/vpnor/write_flash_vpnor.cpp | 12 ---------- test/vpnor/write_ro.cpp | 50 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 13 deletions(-) create mode 100644 test/vpnor/write_ro.cpp 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 +#include +#include +#include +#include +#include + +#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; +} -- cgit v1.2.1