blob: 7ff301885114a602979f69ffa4ad5601acbbb64f [file] [log] [blame]
Andrew Jefferyde90fdc2018-02-23 15:59:46 +10301// SPDX-License-Identifier: Apache-2.0
2// Copyright (C) 2018 IBM Corp.
Andrew Jefferyacee6832018-02-21 22:17:08 +10303
William A. Kennington IIId5f1d402018-10-11 13:55:04 -07004#include "config.h"
5
Ratan Gupta3214b512017-05-11 08:58:19 +05306extern "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 Jeffery0b657f42018-02-22 12:04:02 +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
Adriana Kobylak2ad21322017-11-28 14:59:19 -060021// A read window assumes that the toc is located at offset 0,
Andrew Jeffery8de4c132018-02-23 17:50:51 +103022// so create dummy partition at arbitrary offset 0x1000.
Andrew Jeffery0b657f42018-02-22 12:04:02 +103023const std::string toc[] = {
Andrew Jeffery8de4c132018-02-23 17:50:51 +103024 "partition01=HBB,00001000,00002000,80,ECC,READONLY",
Andrew Jeffery0b657f42018-02-22 12:04:02 +103025};
26
Andrew Jeffery8de4c132018-02-23 17:50:51 +103027static const uint8_t data[8] = {0xaa, 0x55, 0xaa, 0x66, 0x77, 0x88, 0x99, 0xab};
Ratan Gupta3214b512017-05-11 08:58:19 +053028
Andrew Jeffery8de4c132018-02-23 17:50:51 +103029static const auto BLOCK_SIZE = 4096;
30static const auto MEM_SIZE = BLOCK_SIZE * 2;
31static const auto ERASE_SIZE = BLOCK_SIZE;
32static const auto N_WINDOWS = 1;
33static const auto WINDOW_SIZE = BLOCK_SIZE;
Ratan Gupta3214b512017-05-11 08:58:19 +053034
Andrew Jefferyf34db312018-03-09 15:27:03 +103035static const uint8_t get_info[] = {0x02, 0x00, 0x02, 0x00, 0x00, 0x00,
36 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
37 0x00, 0x00, 0x00, 0x00};
Andrew Jeffery0b657f42018-02-22 12:04:02 +103038
Adriana Kobylak2ad21322017-11-28 14:59:19 -060039// offset 0x100 and size 6
Andrew Jeffery8de4c132018-02-23 17:50:51 +103040static const uint8_t create_read_window[] = {0x04, 0x01, 0x01, 0x00, 0x01, 0x00,
Andrew Jefferyf34db312018-03-09 15:27:03 +103041 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
42 0x00, 0x00, 0x00, 0x00};
Ratan Gupta3214b512017-05-11 08:58:19 +053043
Andrew Jefferyf34db312018-03-09 15:27:03 +103044static const uint8_t response[] = {0x04, 0x01, 0xfe, 0xff, 0x01, 0x00, 0x01,
45 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
Ratan Gupta3214b512017-05-11 08:58:19 +053046
Andrew Jeffery0b657f42018-02-22 12:04:02 +103047namespace test = openpower::virtual_pnor::test;
Ratan Gupta3214b512017-05-11 08:58:19 +053048
49int main()
50{
William A. Kennington IIId5f1d402018-10-11 13:55:04 -070051 struct mbox_context* ctx;
Ratan Gupta3214b512017-05-11 08:58:19 +053052
53 system_set_reserved_size(MEM_SIZE);
54 system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE);
55
Evan Lojewskif1e547c2019-03-14 14:34:33 +103056 ctx = mbox_create_frontend_context(N_WINDOWS, WINDOW_SIZE);
Ratan Gupta3214b512017-05-11 08:58:19 +053057
Evan Lojewskif1e547c2019-03-14 14:34:33 +103058 test::VpnorRoot root(&ctx->backend, toc, BLOCK_SIZE);
Andrew Jeffery32476cb2018-02-22 15:34:17 +103059 root.write("HBB", data, sizeof(data));
60
Ratan Gupta3214b512017-05-11 08:58:19 +053061 int rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info));
62 assert(rc == 1);
63
64 // send the request for partition1
65 rc = mbox_command_dispatch(ctx, create_read_window,
Andrew Jefferyf34db312018-03-09 15:27:03 +103066 sizeof(create_read_window));
Ratan Gupta3214b512017-05-11 08:58:19 +053067 assert(rc == 1);
68
69 rc = mbox_cmp(ctx, response, sizeof(response));
70 assert(rc == 0);
71
72 // Compare the reserved memory to the pnor
73 rc = memcmp(ctx->mem, data, 6);
74 assert(rc == 0);
75
Ratan Gupta3214b512017-05-11 08:58:19 +053076 return rc;
77}