blob: 9429d4d7968ab9a19e94182db98be21ef251c245 [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"
Andrew Jeffery5bfc9862018-03-02 09:13:31 +10305
6#include <assert.h>
7
William A. Kennington IIId5f1d402018-10-11 13:55:04 -07008#include "common.h"
9#include "vpnor/mboxd_pnor_partition_table.h"
10
Andrew Jeffery5bfc9862018-03-02 09:13:31 +103011extern "C" {
12#include "test/mbox.h"
13#include "test/system.h"
14}
15
Andrew Jeffery30bcf842018-03-26 12:13:20 +103016#include "vpnor/test/tmpd.hpp"
Andrew Jeffery5bfc9862018-03-02 09:13:31 +103017
18static constexpr auto BLOCK_SIZE = 0x1000;
19static constexpr auto ERASE_SIZE = BLOCK_SIZE;
20static constexpr auto PART_SIZE = BLOCK_SIZE * 4;
21static constexpr auto PATCH_SIZE = PART_SIZE / 2;
22static constexpr auto N_WINDOWS = 2;
23static constexpr auto WINDOW_SIZE = PART_SIZE * 8;
24static constexpr auto MEM_SIZE = WINDOW_SIZE * N_WINDOWS;
25static constexpr auto PNOR_SIZE = MEM_SIZE * 2;
26
27const std::string toc[] = {
28 "partition01=ONE,00001000,00005000,80,ECC,READONLY",
29};
30
31static const uint8_t get_info[] = {0x02, 0x00, 0x02, 0x00, 0x00, 0x00,
32 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
33 0x00, 0x00, 0x00, 0x00};
34
35static const uint8_t create_read_window[] = {0x04, 0x01, 0x01, 0x00, 0x04, 0x00,
36 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
37 0x00, 0x00, 0x00, 0x00};
38
39static const uint8_t response[] = {0x04, 0x01, 0xc0, 0xff, 0x04, 0x00, 0x01,
40 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
41
42int main()
43{
44 namespace test = openpower::virtual_pnor::test;
45
William A. Kennington IIId5f1d402018-10-11 13:55:04 -070046 struct mbox_context* ctx;
Andrew Jeffery5bfc9862018-03-02 09:13:31 +103047
48 system_set_reserved_size(MEM_SIZE);
49 system_set_mtd_sizes(PNOR_SIZE, ERASE_SIZE);
50 ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE);
51 test::VpnorRoot root(ctx, toc, BLOCK_SIZE);
52
53 // PATCH_SIZE is smaller than the size of the partition we defined. This
54 // test ensures that mboxd will behave correctly when we request an offset
55 // that is beyond the size of the backing file, but is in the set of valid
56 // offsets for the partition as defined by the ToC.
57 std::vector<uint8_t> patch(PATCH_SIZE, 0xff);
58 root.patch("ONE", patch.data(), patch.size());
59
Andrew Jeffery742a1f62018-03-02 09:26:03 +103060 init_vpnor_from_paths(ctx);
Andrew Jeffery5bfc9862018-03-02 09:13:31 +103061
62 int rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info));
63 assert(rc == 1);
64
65 rc = mbox_command_dispatch(ctx, create_read_window,
66 sizeof(create_read_window));
67 assert(rc == 1);
68
69 rc = mbox_cmp(ctx, response, sizeof(response));
70 assert(rc == 0);
71
72 return 0;
73}