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