1 // SPDX-License-Identifier: Apache-2.0
2 // Copyright (C) 2018 IBM Corp.
3
4 #include "config.h"
5
6 extern "C" {
7 #include "test/mbox.h"
8 #include "test/system.h"
9 }
10
11 #include "vpnor/test/tmpd.hpp"
12
13 #include <cassert>
14 #include <cstring>
15 #include <filesystem>
16 #include <fstream>
17 #include <vector>
18
19 #include "vpnor/backend.h"
20
21 // A read window assumes that the toc is located at offset 0,
22 // so create dummy partition at arbitrary offset 0x1000.
23 const std::string toc[] = {
24 "partition01=HBB,00001000,00002000,80,ECC,READONLY",
25 };
26
27 static const uint8_t data[8] = {0xaa, 0x55, 0xaa, 0x66, 0x77, 0x88, 0x99, 0xab};
28
29 static const auto BLOCK_SIZE = 4096;
30 static const auto MEM_SIZE = BLOCK_SIZE * 2;
31 static const auto ERASE_SIZE = BLOCK_SIZE;
32 static const auto N_WINDOWS = 1;
33 static const auto WINDOW_SIZE = BLOCK_SIZE;
34
35 static const uint8_t get_info[] = {0x02, 0x00, 0x02, 0x00, 0x00, 0x00,
36 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
37 0x00, 0x00, 0x00, 0x00};
38
39 // offset 0x100 and size 6
40 static const uint8_t create_read_window[] = {0x04, 0x01, 0x01, 0x00, 0x01, 0x00,
41 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
42 0x00, 0x00, 0x00, 0x00};
43
44 static const uint8_t response[] = {0x04, 0x01, 0xfe, 0xff, 0x01, 0x00, 0x01,
45 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
46
47 namespace test = openpower::virtual_pnor::test;
48
main()49 int main()
50 {
51 struct mbox_context* ctx;
52
53 system_set_reserved_size(MEM_SIZE);
54 system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE);
55
56 ctx = mbox_create_frontend_context(N_WINDOWS, WINDOW_SIZE);
57
58 test::VpnorRoot root(&ctx->backend, toc, BLOCK_SIZE);
59 root.write("HBB", data, sizeof(data));
60
61 int rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info));
62 assert(rc == 1);
63
64 // send the request for partition1
65 rc = mbox_command_dispatch(ctx, create_read_window,
66 sizeof(create_read_window));
67 assert(rc == 1);
68
69 rc = mbox_cmp(ctx, response, sizeof(response));
70 assert(rc == 0);
71
72 // Compare the reserved memory to the pnor
73 rc = memcmp(ctx->mem, data, 6);
74 assert(rc == 0);
75
76 return rc;
77 }
78