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