blob: 8ee4b05f8e878294e023f716ec6b7e1654dae41c [file] [log] [blame]
Andrew Jeffery3dce83d2018-03-22 16:52:42 +10301// SPDX-License-Identifier: Apache-2.0
2// Copyright (C) 2018 IBM Corp.
3
4#include <assert.h>
5#include <string.h>
6
7#include "config.h"
8#include "mboxd_msg.h"
9#include "mboxd_pnor_partition_table.h"
10
11extern "C" {
12#include "test/mbox.h"
13#include "test/system.h"
14}
15
16#include "test/vpnor/tmpd.hpp"
17
18struct test_context
19{
20 uint8_t seq;
21 struct mbox_context *ctx;
22};
23
24// Configure the system and the paritions such that we eventually request a
25// window that covers the last section of flash, but the remaining flash is
26// smaller than the window size
27static constexpr auto BLOCK_SIZE = 4096;
28static constexpr auto ERASE_SIZE = BLOCK_SIZE;
29static constexpr auto N_WINDOWS = 3;
30static constexpr auto WINDOW_SIZE = 2 * BLOCK_SIZE;
31static constexpr auto MEM_SIZE = N_WINDOWS * WINDOW_SIZE;
32static constexpr auto PNOR_SIZE = (4 * BLOCK_SIZE);
33
34const std::string toc[] = {
35 "partition01=ONE,00001000,00003000,80,ECC,READONLY",
36};
37
38static const uint8_t get_info[] = {0x02, 0x00, 0x02, 0x00, 0x00, 0x00,
39 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
40 0x00, 0x00, 0x00, 0x00};
41
42static constexpr auto MBOX_CREATE_READ_WINDOW = 4;
43
44static int mbox_create_read_window(struct test_context *tctx, size_t offset,
45 size_t len)
46{
47 union mbox_regs regs;
48
49 memset(&regs, 0, sizeof(regs));
50 regs.msg.command = MBOX_CREATE_READ_WINDOW;
51 regs.msg.seq = ++tctx->seq;
52 put_u16(&regs.msg.args[0], offset);
53 put_u16(&regs.msg.args[2], len);
54
55 return mbox_command_dispatch(tctx->ctx, regs.raw, sizeof(regs.raw));
56}
57
58int main()
59{
60 namespace test = openpower::virtual_pnor::test;
61
62 struct test_context _tctx = {0}, *tctx = &_tctx;
63 size_t len;
64 size_t pos;
65 int rc;
66
67 system_set_reserved_size(MEM_SIZE);
68 system_set_mtd_sizes(PNOR_SIZE, ERASE_SIZE);
69
70 tctx->ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE);
71 test::VpnorRoot root(tctx->ctx, toc, BLOCK_SIZE);
72 init_vpnor_from_paths(tctx->ctx);
73
74 rc = mbox_command_dispatch(tctx->ctx, get_info, sizeof(get_info));
75 assert(rc == 1);
76
77 pos = 0;
78 while (pos < (PNOR_SIZE / BLOCK_SIZE))
79 {
80 struct mbox_msg _msg, *msg = &_msg;
81
82 rc = mbox_create_read_window(tctx, pos, (WINDOW_SIZE / BLOCK_SIZE));
83 assert(rc == 1);
84
85 mbox_rspcpy(tctx->ctx, msg);
86
87 len = get_u16(&msg->args[2]);
88 pos = get_u16(&msg->args[4]) + len;
89 }
90
91 return 0;
92}