blob: d8b63ce4d4eb93938992ab0cee830baee28ce45d [file] [log] [blame]
Andrew Jeffery89985752018-11-13 15:17:30 +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"
9}
10
Andrew Jeffery89985752018-11-13 15:17:30 +103011#include "vpnor/pnor_partition_table.hpp"
Andrew Jeffery035ad762019-03-18 13:02:01 +103012#include "vpnor/test/tmpd.hpp"
Andrew Jeffery89985752018-11-13 15:17:30 +103013
Andrew Jeffery89985752018-11-13 15:17:30 +103014#include <sys/mman.h>
15
Andrew Jeffery261f61a2019-03-14 09:57:28 +103016#include <cassert>
17#include <cstring>
18
Andrew Jeffery89985752018-11-13 15:17:30 +103019static constexpr auto BLOCK_SIZE = 4 * 1024;
20static constexpr auto PNOR_SIZE = 2 * BLOCK_SIZE;
21static constexpr auto MEM_SIZE = BLOCK_SIZE;
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,READWRITE",
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
36static const uint8_t write_toc[] = {0x06, 0x01, 0x00, 0x00, 0x01, 0x00,
37 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
38 0x00, 0x00, 0x00, 0x00};
39
40static const uint8_t erase_toc[] = {0x0a, 0x02, 0x00, 0x00, 0x01, 0x00,
41 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
42 0x00, 0x00, 0x00, 0x00};
43
44static const uint8_t read_one[] = {0x04, 0x03, 0x01, 0x00, 0x01, 0x00,
45 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
46 0x00, 0x00, 0x00, 0x00};
47
48static const uint8_t read_toc[] = {0x04, 0x04, 0x00, 0x00, 0x01, 0x00,
49 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
50 0x00, 0x00, 0x00, 0x00};
51
52int main()
53{
54 namespace test = openpower::virtual_pnor::test;
55 namespace vpnor = openpower::virtual_pnor;
56
57 struct mbox_context* ctx;
58 int rc;
59
60 void* erased;
61
62 erased = malloc(BLOCK_SIZE);
63 assert(erased);
64
65 memset(erased, 0xff, BLOCK_SIZE);
66
67 system_set_reserved_size(MEM_SIZE);
68 system_set_mtd_sizes(PNOR_SIZE, ERASE_SIZE);
69
Evan Lojewskif1e547c2019-03-14 14:34:33 +103070 ctx = mbox_create_frontend_context(N_WINDOWS, WINDOW_SIZE);
71 test::VpnorRoot root(&ctx->backend, toc, BLOCK_SIZE);
72 vpnor::partition::Table table(&ctx->backend);
Andrew Jeffery89985752018-11-13 15:17:30 +103073
74 assert(table.capacity() == TOC_PART_SIZE);
75
Andrew Jeffery89985752018-11-13 15:17:30 +103076 rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info));
77 assert(rc == MBOX_R_SUCCESS);
78
79 rc = mbox_command_dispatch(ctx, write_toc, sizeof(write_toc));
80 assert(rc == MBOX_R_SUCCESS);
81
82 rc = mbox_command_dispatch(ctx, erase_toc, sizeof(erase_toc));
83 assert(rc == MBOX_R_SUCCESS);
84
85 rc = memcmp(ctx->mem, erased, BLOCK_SIZE);
86 assert(rc == 0);
87
88 rc = mbox_command_dispatch(ctx, read_one, sizeof(read_one));
89 assert(rc == MBOX_R_SUCCESS);
90
91 rc = mbox_command_dispatch(ctx, read_toc, sizeof(read_toc));
92 assert(rc == MBOX_R_SUCCESS);
93
94 rc = memcmp(ctx->mem, erased, BLOCK_SIZE);
95 assert(rc == 0);
96
97 free(erased);
98
99 return 0;
100}