blob: 1f68371f22cabd02fcc98e1e2dc1a39f9a48425f [file] [log] [blame]
Andrew Jeffery7eed6de2018-03-01 12:11:23 +10301// SPDX-License-Identifier: Apache-2.0
2// Copyright (C) 2018 IBM Corp.
3#include <assert.h>
4#include <sys/mman.h>
5#include <string.h>
6
7#include "config.h"
8#include "pnor_partition_table.hpp"
9
10extern "C" {
11#include "test/mbox.h"
12#include "test/system.h"
13}
14
15#include "test/vpnor/tmpd.hpp"
16
17static constexpr auto BLOCK_SIZE = 4 * 1024;
18static constexpr auto PNOR_SIZE = 64 * 1024 * 1024;
19static constexpr auto MEM_SIZE = BLOCK_SIZE * 2;
20static constexpr auto ERASE_SIZE = BLOCK_SIZE;
21static constexpr auto N_WINDOWS = 1;
22static constexpr auto WINDOW_SIZE = BLOCK_SIZE;
23static constexpr auto TOC_PART_SIZE = BLOCK_SIZE;
24
25const std::string toc[] = {
26 "partition00=part,00000000,00001000,80,READONLY",
27 "partition01=ONE,00001000,00002000,80,READWRITE",
28};
29
30static const uint8_t get_info[] = {0x02, 0x00, 0x02, 0x00, 0x00, 0x00,
31 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
32 0x00, 0x00, 0x00, 0x00};
33
34/* Request access to the ToC base for one block */
35static const uint8_t create_read_window[] = {0x04, 0x01, 0x00, 0x00, 0x01, 0x00,
36 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
37 0x00, 0x00, 0x00, 0x00};
38
39/* Expect a response containing the ToC in one block */
40static const uint8_t response[] = {
41 0x04, 0x01, 0xfe, 0xff, 0x01, 0x00, 0x00,
42 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
43};
44
45int main()
46{
47 namespace test = openpower::virtual_pnor::test;
48 namespace vpnor = openpower::virtual_pnor;
49
50 struct mbox_context* ctx;
51 int rc;
52
53 system_set_reserved_size(MEM_SIZE);
54 system_set_mtd_sizes(PNOR_SIZE, ERASE_SIZE);
55
56 ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE);
57 test::VpnorRoot root(ctx, toc, BLOCK_SIZE);
Andrew Jeffery742a1f62018-03-02 09:26:03 +103058 vpnor::partition::Table table(ctx);
Andrew Jeffery7eed6de2018-03-01 12:11:23 +103059
60 /* Make sure the ToC exactly fits in the space allocated for it */
61 assert(table.capacity() == TOC_PART_SIZE);
62
Andrew Jeffery742a1f62018-03-02 09:26:03 +103063 init_vpnor_from_paths(ctx);
Andrew Jeffery7eed6de2018-03-01 12:11:23 +103064
65 rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info));
66 assert(rc == 1);
67
68 rc = mbox_command_dispatch(ctx, create_read_window,
69 sizeof(create_read_window));
70 assert(rc == 1);
71
72 rc = mbox_cmp(ctx, response, sizeof(response));
73 assert(rc == 0);
74
75 /* Ensure our partition table is present and as expected */
76 const pnor_partition_table& toc = table.getHostTable();
77 rc = memcmp(ctx->mem, &toc, table.size());
78 assert(rc == 0);
79
80 return 0;
81}