blob: a783bc78c44ab24ae1b9d29bf183cd846f3b12d1 [file] [log] [blame]
Andrew Jeffery8a0efd52018-11-13 17:13:08 +10301// SPDX-License-Identifier: Apache-2.0
2// Copyright (C) 2018 IBM Corp.
3#include "config.h"
4
5#include "vpnor/pnor_partition_table.hpp"
6
7#include <assert.h>
8#include <endian.h>
9#include <string.h>
10#include <sys/mman.h>
11
12extern "C" {
13#include "test/mbox.h"
14#include "test/system.h"
15#include "vpnor/pnor_partition_defs.h"
16}
17
18#include "vpnor/test/tmpd.hpp"
19
20static constexpr auto BLOCK_SIZE = 4 * 1024;
21static constexpr auto PNOR_SIZE = BLOCK_SIZE;
22static constexpr auto MEM_SIZE = BLOCK_SIZE;
23static constexpr auto ERASE_SIZE = BLOCK_SIZE;
24static constexpr auto N_WINDOWS = 1;
25static constexpr auto WINDOW_SIZE = BLOCK_SIZE;
26static constexpr auto TOC_PART_SIZE = BLOCK_SIZE;
27
28const std::string toc[] = {
29 "partition00=part,00000000,00001000,80,READWRITE",
30 "partition01=ONE,00001000,00002000,80,READWRITE",
31};
32
33static const uint8_t get_info[] = {0x02, 0x00, 0x02, 0x00, 0x00, 0x00,
34 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
35 0x00, 0x00, 0x00, 0x00};
36
37static const uint8_t read_toc[] = {0x04, 0x04, 0x00, 0x00, 0x01, 0x00,
38 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
39 0x00, 0x00, 0x00, 0x00};
40
41int main()
42{
43 namespace test = openpower::virtual_pnor::test;
44 namespace vpnor = openpower::virtual_pnor;
45
46 struct pnor_partition_table* htable;
47 struct mbox_context* ctx;
48 uint32_t perms;
49 int rc;
50
51 system_set_reserved_size(MEM_SIZE);
52 system_set_mtd_sizes(PNOR_SIZE, ERASE_SIZE);
53
54 ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE);
55 test::VpnorRoot root(ctx, toc, BLOCK_SIZE);
56 vpnor::partition::Table table(ctx);
57
58 assert(table.capacity() == TOC_PART_SIZE);
59
60 init_vpnor_from_paths(ctx);
61
62 rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info));
63 assert(rc == MBOX_R_SUCCESS);
64
65 rc = mbox_command_dispatch(ctx, read_toc, sizeof(read_toc));
66 assert(rc == MBOX_R_SUCCESS);
67
68 htable = reinterpret_cast<struct pnor_partition_table*>(ctx->mem);
69 perms = be32toh(htable->partitions[0].data.user.data[1]);
70 assert(perms & PARTITION_READONLY);
71
72 htable = reinterpret_cast<struct pnor_partition_table*>(ctx->mem);
73 perms = be32toh(htable->partitions[1].data.user.data[1]);
74 assert(!(perms & PARTITION_READONLY));
75
76 return 0;
77}