blob: 2d5dc5dea3cff9300f40e2a8ce3dbc80ebade032 [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 +10306extern "C" {
7#include "test/mbox.h"
8#include "test/system.h"
Andrew Jeffery261f61a2019-03-14 09:57:28 +10309#include "transport_mbox.h"
Andrew Jeffery3dce83d2018-03-22 16:52:42 +103010}
11
Andrew Jeffery30bcf842018-03-26 12:13:20 +103012#include "vpnor/test/tmpd.hpp"
Andrew Jeffery3dce83d2018-03-22 16:52:42 +103013
Andrew Jeffery261f61a2019-03-14 09:57:28 +103014#include <cassert>
15#include <cstring>
16
Andrew Jefferyf4bc3352019-03-18 12:09:48 +103017#include "vpnor/backend.h"
Andrew Jeffery261f61a2019-03-14 09:57:28 +103018
Andrew Jeffery3dce83d2018-03-22 16:52:42 +103019struct 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
Evan Lojewskif1e547c2019-03-14 14:34:33 +103071 tctx->ctx = mbox_create_frontend_context(N_WINDOWS, WINDOW_SIZE);
72 test::VpnorRoot root(&tctx->ctx->backend, toc, BLOCK_SIZE);
Andrew Jeffery3dce83d2018-03-22 16:52:42 +103073
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}