xref: /openbmc/hiomapd/vpnor/test/write_ro.cpp (revision 150be912)
1 // SPDX-License-Identifier: Apache-2.0
2 // Copyright (C) 2018 IBM Corp.
3 #include "config.h"
4 
5 extern "C" {
6 #include "backend.h"
7 #include "common.h"
8 #include "mboxd.h"
9 }
10 
11 #include "vpnor/test/tmpd.hpp"
12 
13 #include <fcntl.h>
14 #include <sys/mman.h>
15 #include <sys/stat.h>
16 #include <sys/types.h>
17 #include <unistd.h>
18 
19 #include <cassert>
20 
21 static constexpr auto BLOCK_SIZE = 0x1000;
22 
23 const std::string toc[] = {
24     "partition01=TEST1,00001000,00002000,80,ECC,READONLY",
25 };
26 
main(void)27 int main(void)
28 {
29     namespace fs = std::filesystem;
30     namespace test = openpower::virtual_pnor::test;
31 
32     struct mbox_context _ctx, *ctx = &_ctx;
33     uint8_t src[8] = {0};
34     int rc;
35 
36     /* Setup */
37     memset(ctx, 0, sizeof(mbox_context));
38 
39     mbox_vlog = &mbox_log_console;
40     verbosity = (verbose)2;
41 
42     ctx->backend.flash_size = 0x2000;
43     test::VpnorRoot root(&ctx->backend, toc, BLOCK_SIZE);
44 
45     /* Test */
46     rc = backend_write(&ctx->backend, 0x1000, src, sizeof(src));
47 
48     /* Verify we can't write to RO partitions */
49     assert(rc != 0);
50 
51     return 0;
52 }
53