blob: 53e5282c6667702725a2a4244b7387ca830a5b9f [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
Andrew Jeffery035ad762019-03-18 13:02:01 +10305extern "C" {
6#include "backend.h"
7#include "test/mbox.h"
8#include "test/system.h"
Andrew Jefferydec59b42019-03-18 13:09:59 +10309#include "vpnor/ffs.h"
Andrew Jeffery035ad762019-03-18 13:02:01 +103010}
11
Andrew Jefferyde08ca22019-03-18 13:23:46 +103012#include "vpnor/table.hpp"
Andrew Jeffery035ad762019-03-18 13:02:01 +103013#include "vpnor/test/tmpd.hpp"
Andrew Jeffery8a0efd52018-11-13 17:13:08 +103014
Andrew Jeffery8a0efd52018-11-13 17:13:08 +103015#include <endian.h>
Andrew Jeffery8a0efd52018-11-13 17:13:08 +103016#include <sys/mman.h>
17
Andrew Jeffery261f61a2019-03-14 09:57:28 +103018#include <cassert>
19#include <cstring>
20
Andrew Jeffery8a0efd52018-11-13 17:13:08 +103021static constexpr auto BLOCK_SIZE = 4 * 1024;
22static constexpr auto PNOR_SIZE = BLOCK_SIZE;
23static constexpr auto MEM_SIZE = BLOCK_SIZE;
24static constexpr auto ERASE_SIZE = BLOCK_SIZE;
25static constexpr auto N_WINDOWS = 1;
26static constexpr auto WINDOW_SIZE = BLOCK_SIZE;
27static constexpr auto TOC_PART_SIZE = BLOCK_SIZE;
28
29const std::string toc[] = {
30 "partition00=part,00000000,00001000,80,READWRITE",
31 "partition01=ONE,00001000,00002000,80,READWRITE",
32};
33
34static const uint8_t get_info[] = {0x02, 0x00, 0x02, 0x00, 0x00, 0x00,
35 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
36 0x00, 0x00, 0x00, 0x00};
37
38static const uint8_t read_toc[] = {0x04, 0x04, 0x00, 0x00, 0x01, 0x00,
39 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
40 0x00, 0x00, 0x00, 0x00};
41
42int main()
43{
44 namespace test = openpower::virtual_pnor::test;
45 namespace vpnor = openpower::virtual_pnor;
46
47 struct pnor_partition_table* htable;
48 struct mbox_context* ctx;
49 uint32_t perms;
50 int rc;
51
52 system_set_reserved_size(MEM_SIZE);
53 system_set_mtd_sizes(PNOR_SIZE, ERASE_SIZE);
54
Evan Lojewskif1e547c2019-03-14 14:34:33 +103055 ctx = mbox_create_frontend_context(N_WINDOWS, WINDOW_SIZE);
56 test::VpnorRoot root(&ctx->backend, toc, BLOCK_SIZE);
57 vpnor::partition::Table table(&ctx->backend);
Andrew Jeffery8a0efd52018-11-13 17:13:08 +103058
59 assert(table.capacity() == TOC_PART_SIZE);
60
Andrew Jeffery8a0efd52018-11-13 17:13:08 +103061 rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info));
62 assert(rc == MBOX_R_SUCCESS);
63
64 rc = mbox_command_dispatch(ctx, read_toc, sizeof(read_toc));
65 assert(rc == MBOX_R_SUCCESS);
66
67 htable = reinterpret_cast<struct pnor_partition_table*>(ctx->mem);
68 perms = be32toh(htable->partitions[0].data.user.data[1]);
69 assert(perms & PARTITION_READONLY);
70
71 htable = reinterpret_cast<struct pnor_partition_table*>(ctx->mem);
72 perms = be32toh(htable->partitions[1].data.user.data[1]);
73 assert(!(perms & PARTITION_READONLY));
74
75 return 0;
76}