blob: 12ac19bc19f5e5958bc942b77b6e5b16cf0f0d9f [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
Andrew Jeffery8de4c132018-02-23 17:50:51 +10304#include <assert.h>
5#include <experimental/filesystem>
6#include <fstream>
7#include <string.h>
8#include <vector>
9
Ratan Gupta3214b512017-05-11 08:58:19 +053010#include "config.h"
Andrew Jeffery53c21aa2018-03-26 11:56:16 +103011#include "vpnor/mboxd_pnor_partition_table.h"
Ratan Gupta3214b512017-05-11 08:58:19 +053012
13extern "C" {
14#include "test/mbox.h"
15#include "test/system.h"
16}
17
Andrew Jeffery30bcf842018-03-26 12:13:20 +103018#include "vpnor/test/tmpd.hpp"
Andrew Jeffery0b657f42018-02-22 12:04:02 +103019
Adriana Kobylak2ad21322017-11-28 14:59:19 -060020// A read window assumes that the toc is located at offset 0,
Andrew Jeffery8de4c132018-02-23 17:50:51 +103021// so create dummy partition at arbitrary offset 0x1000.
Andrew Jeffery0b657f42018-02-22 12:04:02 +103022const std::string toc[] = {
Andrew Jeffery8de4c132018-02-23 17:50:51 +103023 "partition01=HBB,00001000,00002000,80,ECC,READONLY",
Andrew Jeffery0b657f42018-02-22 12:04:02 +103024};
25
Andrew Jeffery8de4c132018-02-23 17:50:51 +103026static const uint8_t data[8] = {0xaa, 0x55, 0xaa, 0x66, 0x77, 0x88, 0x99, 0xab};
Ratan Gupta3214b512017-05-11 08:58:19 +053027
Andrew Jeffery8de4c132018-02-23 17:50:51 +103028static const auto BLOCK_SIZE = 4096;
29static const auto MEM_SIZE = BLOCK_SIZE * 2;
30static const auto ERASE_SIZE = BLOCK_SIZE;
31static const auto N_WINDOWS = 1;
32static const auto WINDOW_SIZE = BLOCK_SIZE;
Ratan Gupta3214b512017-05-11 08:58:19 +053033
Andrew Jefferyf34db312018-03-09 15:27:03 +103034static const uint8_t get_info[] = {0x02, 0x00, 0x02, 0x00, 0x00, 0x00,
35 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
36 0x00, 0x00, 0x00, 0x00};
Andrew Jeffery0b657f42018-02-22 12:04:02 +103037
Adriana Kobylak2ad21322017-11-28 14:59:19 -060038// offset 0x100 and size 6
Andrew Jeffery8de4c132018-02-23 17:50:51 +103039static const uint8_t create_read_window[] = {0x04, 0x01, 0x01, 0x00, 0x01, 0x00,
Andrew Jefferyf34db312018-03-09 15:27:03 +103040 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
41 0x00, 0x00, 0x00, 0x00};
Ratan Gupta3214b512017-05-11 08:58:19 +053042
Andrew Jefferyf34db312018-03-09 15:27:03 +103043static const uint8_t response[] = {0x04, 0x01, 0xfe, 0xff, 0x01, 0x00, 0x01,
44 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
Ratan Gupta3214b512017-05-11 08:58:19 +053045
Andrew Jeffery0b657f42018-02-22 12:04:02 +103046namespace test = openpower::virtual_pnor::test;
Ratan Gupta3214b512017-05-11 08:58:19 +053047
48int main()
49{
Andrew Jeffery32476cb2018-02-22 15:34:17 +103050 struct mbox_context *ctx;
Ratan Gupta3214b512017-05-11 08:58:19 +053051
52 system_set_reserved_size(MEM_SIZE);
53 system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE);
54
Andrew Jeffery32476cb2018-02-22 15:34:17 +103055 ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE);
Ratan Gupta3214b512017-05-11 08:58:19 +053056
Andrew Jeffery32476cb2018-02-22 15:34:17 +103057 test::VpnorRoot root(ctx, toc, BLOCK_SIZE);
58 root.write("HBB", data, sizeof(data));
59
Andrew Jeffery742a1f62018-03-02 09:26:03 +103060 init_vpnor_from_paths(ctx);
Ratan Gupta3214b512017-05-11 08:58:19 +053061
62 int rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info));
63 assert(rc == 1);
64
65 // send the request for partition1
66 rc = mbox_command_dispatch(ctx, create_read_window,
Andrew Jefferyf34db312018-03-09 15:27:03 +103067 sizeof(create_read_window));
Ratan Gupta3214b512017-05-11 08:58:19 +053068 assert(rc == 1);
69
70 rc = mbox_cmp(ctx, response, sizeof(response));
71 assert(rc == 0);
72
73 // Compare the reserved memory to the pnor
74 rc = memcmp(ctx->mem, data, 6);
75 assert(rc == 0);
76
Ratan Gupta3214b512017-05-11 08:58:19 +053077 return rc;
78}