130bcf84cSAndrew Jeffery // SPDX-License-Identifier: Apache-2.0
230bcf84cSAndrew Jeffery // Copyright (C) 2018 IBM Corp.
330bcf84cSAndrew Jeffery
4d5f1d40fSWilliam A. Kennington III #include "config.h"
5d5f1d40fSWilliam A. Kennington III
630bcf84cSAndrew Jeffery extern "C" {
730bcf84cSAndrew Jeffery #include "test/mbox.h"
830bcf84cSAndrew Jeffery #include "test/system.h"
930bcf84cSAndrew Jeffery }
1030bcf84cSAndrew Jeffery
1130bcf84cSAndrew Jeffery #include "vpnor/test/tmpd.hpp"
1230bcf84cSAndrew Jeffery
13261f61a1SAndrew Jeffery #include <cassert>
14261f61a1SAndrew Jeffery #include <cstring>
15261f61a1SAndrew Jeffery
16*f4bc335bSAndrew Jeffery #include "vpnor/backend.h"
17261f61a1SAndrew Jeffery
1830bcf84cSAndrew Jeffery const std::string toc[] = {
1930bcf84cSAndrew Jeffery "partition01=HBB,00001000,00002000,80,ECC,READONLY",
2030bcf84cSAndrew Jeffery };
2130bcf84cSAndrew Jeffery
2230bcf84cSAndrew Jeffery static constexpr auto BLOCK_SIZE = 4096;
2330bcf84cSAndrew Jeffery static constexpr auto MEM_SIZE = (BLOCK_SIZE * 2);
2430bcf84cSAndrew Jeffery static constexpr auto ERASE_SIZE = BLOCK_SIZE;
2530bcf84cSAndrew Jeffery static constexpr auto N_WINDOWS = 1;
2630bcf84cSAndrew Jeffery static constexpr auto WINDOW_SIZE = BLOCK_SIZE;
2730bcf84cSAndrew Jeffery static constexpr auto PNOR_SIZE = (BLOCK_SIZE * 4);
2830bcf84cSAndrew Jeffery
2930bcf84cSAndrew Jeffery static const uint8_t get_info[] = {0x02, 0x00, 0x02, 0x00, 0x00, 0x00,
3030bcf84cSAndrew Jeffery 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3130bcf84cSAndrew Jeffery 0x00, 0x00, 0x00, 0x00};
3230bcf84cSAndrew Jeffery
3330bcf84cSAndrew Jeffery /* Request access beyond the last (only) partition */
3430bcf84cSAndrew Jeffery static const uint8_t create_read_window[] = {0x04, 0x01, 0x03, 0x00, 0x01, 0x00,
3530bcf84cSAndrew Jeffery 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3630bcf84cSAndrew Jeffery 0x00, 0x00, 0x00, 0x00};
3730bcf84cSAndrew Jeffery
3830bcf84cSAndrew Jeffery static const uint8_t response[] = {0x04, 0x01, 0xfe, 0xff, 0x01, 0x00, 0x03,
3930bcf84cSAndrew Jeffery 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
4030bcf84cSAndrew Jeffery
main()4130bcf84cSAndrew Jeffery int main()
4230bcf84cSAndrew Jeffery {
4330bcf84cSAndrew Jeffery namespace test = openpower::virtual_pnor::test;
4430bcf84cSAndrew Jeffery
4530bcf84cSAndrew Jeffery struct mbox_context* ctx;
4630bcf84cSAndrew Jeffery int rc;
4730bcf84cSAndrew Jeffery
4830bcf84cSAndrew Jeffery system_set_reserved_size(MEM_SIZE);
4930bcf84cSAndrew Jeffery system_set_mtd_sizes(PNOR_SIZE, ERASE_SIZE);
5030bcf84cSAndrew Jeffery
51f1e547c7SEvan Lojewski ctx = mbox_create_frontend_context(N_WINDOWS, WINDOW_SIZE);
52f1e547c7SEvan Lojewski test::VpnorRoot root(&ctx->backend, toc, BLOCK_SIZE);
5330bcf84cSAndrew Jeffery
5430bcf84cSAndrew Jeffery rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info));
5530bcf84cSAndrew Jeffery assert(rc == 1);
5630bcf84cSAndrew Jeffery
5730bcf84cSAndrew Jeffery rc = mbox_command_dispatch(ctx, create_read_window,
5830bcf84cSAndrew Jeffery sizeof(create_read_window));
5930bcf84cSAndrew Jeffery assert(rc == 1);
6030bcf84cSAndrew Jeffery
6130bcf84cSAndrew Jeffery rc = mbox_cmp(ctx, response, sizeof(response));
6230bcf84cSAndrew Jeffery assert(rc == 0);
6330bcf84cSAndrew Jeffery
6430bcf84cSAndrew Jeffery return 0;
6530bcf84cSAndrew Jeffery }
66