blob: 31a422ec377896548358b87fe9aa075564f6ecac [file] [log] [blame]
Andrew Jeffery5bfc9862018-03-02 09:13:31 +10301// SPDX-License-Identifier: Apache-2.0
2// Copyright (C) 2018 IBM Corp.
3
4#include "config.h"
5#include "common.h"
Andrew Jeffery53c21aa2018-03-26 11:56:16 +10306#include "vpnor/mboxd_pnor_partition_table.h"
Andrew Jeffery5bfc9862018-03-02 09:13:31 +10307
8#include <assert.h>
9
10extern "C" {
11#include "test/mbox.h"
12#include "test/system.h"
13}
14
Andrew Jeffery30bcf842018-03-26 12:13:20 +103015#include "vpnor/test/tmpd.hpp"
Andrew Jeffery5bfc9862018-03-02 09:13:31 +103016
17static constexpr auto BLOCK_SIZE = 0x1000;
18static constexpr auto ERASE_SIZE = BLOCK_SIZE;
19static constexpr auto PART_SIZE = BLOCK_SIZE * 4;
20static constexpr auto PATCH_SIZE = PART_SIZE / 2;
21static constexpr auto N_WINDOWS = 2;
22static constexpr auto WINDOW_SIZE = PART_SIZE * 8;
23static constexpr auto MEM_SIZE = WINDOW_SIZE * N_WINDOWS;
24static constexpr auto PNOR_SIZE = MEM_SIZE * 2;
25
26const std::string toc[] = {
27 "partition01=ONE,00001000,00005000,80,ECC,READONLY",
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
34static const uint8_t create_read_window[] = {0x04, 0x01, 0x01, 0x00, 0x04, 0x00,
35 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
36 0x00, 0x00, 0x00, 0x00};
37
38static const uint8_t response[] = {0x04, 0x01, 0xc0, 0xff, 0x04, 0x00, 0x01,
39 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
40
41int main()
42{
43 namespace test = openpower::virtual_pnor::test;
44
45 struct mbox_context *ctx;
46
47 system_set_reserved_size(MEM_SIZE);
48 system_set_mtd_sizes(PNOR_SIZE, ERASE_SIZE);
49 ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE);
50 test::VpnorRoot root(ctx, toc, BLOCK_SIZE);
51
52 // PATCH_SIZE is smaller than the size of the partition we defined. This
53 // test ensures that mboxd will behave correctly when we request an offset
54 // that is beyond the size of the backing file, but is in the set of valid
55 // offsets for the partition as defined by the ToC.
56 std::vector<uint8_t> patch(PATCH_SIZE, 0xff);
57 root.patch("ONE", patch.data(), patch.size());
58
Andrew Jeffery742a1f62018-03-02 09:26:03 +103059 init_vpnor_from_paths(ctx);
Andrew Jeffery5bfc9862018-03-02 09:13:31 +103060
61 int rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info));
62 assert(rc == 1);
63
64 rc = mbox_command_dispatch(ctx, create_read_window,
65 sizeof(create_read_window));
66 assert(rc == 1);
67
68 rc = mbox_cmp(ctx, response, sizeof(response));
69 assert(rc == 0);
70
71 return 0;
72}