blob: 7a11053789a20837758e25c7e58a9234d4b2d46a [file] [log] [blame]
Andrew Jeffery912c9bd2018-03-23 13:31:46 +10301// SPDX-License-Identifier: Apache-2.0
2// Copyright (C) 2018 IBM Corp.
3
William A. Kennington IIId5f1d402018-10-11 13:55:04 -07004#include "config.h"
5
Andrew Jeffery912c9bd2018-03-23 13:31:46 +10306extern "C" {
7#include "test/mbox.h"
8#include "test/system.h"
9}
10
Andrew Jeffery30bcf842018-03-26 12:13:20 +103011#include "vpnor/test/tmpd.hpp"
Andrew Jeffery912c9bd2018-03-23 13:31:46 +103012
Andrew Jeffery261f61a2019-03-14 09:57:28 +103013#include <cassert>
14#include <cstring>
15#include <experimental/filesystem>
16#include <fstream>
17#include <vector>
18
19#include "vpnor/mboxd_pnor_partition_table.h"
20
Andrew Jeffery912c9bd2018-03-23 13:31:46 +103021static const auto BLOCK_SIZE = 4096;
22static const auto ERASE_SIZE = BLOCK_SIZE;
23static const auto WINDOW_SIZE = 16 * BLOCK_SIZE;
24static const auto N_WINDOWS = 2;
25static const auto MEM_SIZE = N_WINDOWS * WINDOW_SIZE;
26
27const std::string toc[] = {
28 "partition01=ONE,00001000,00011000,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
35namespace test = openpower::virtual_pnor::test;
36
37int main()
38{
39 uint8_t request[] = {0x04, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
40 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
41
42 uint8_t response[] = {0x04, 0x01, 0xe0, 0xff, 0x10, 0x00, 0x01,
43 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
44
William A. Kennington IIId5f1d402018-10-11 13:55:04 -070045 struct mbox_context* ctx;
Andrew Jeffery912c9bd2018-03-23 13:31:46 +103046
47 system_set_reserved_size(MEM_SIZE);
48 system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE);
49
50 ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE);
51 test::VpnorRoot root(ctx, toc, BLOCK_SIZE);
52 init_vpnor_from_paths(ctx);
53
54 int rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info));
55 assert(rc == 1);
56
57 for (int i = 1; i < (0x10000 / BLOCK_SIZE); i++)
58 {
59 /* Update the requested offset */
60 put_u16(&request[2], i);
61
62 /*
63 * Reuse the offset as a sequence number, because it's unique. Request
64 * and response have the same sequence number
65 */
66 request[1] = i;
67 response[1] = i;
68
69 rc = mbox_command_dispatch(ctx, request, sizeof(request));
70 assert(rc == 1);
71
72 /* Check that it maps to the same window each time */
73 rc = mbox_cmp(ctx, response, sizeof(response));
74 assert(rc == 0);
75 }
76
77 return 0;
78}