blob: f02272d64cf93ce7d45706813630783a124bf297 [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
Andrew Jeffery8de4c132018-02-23 17:50:51 +10306#include <assert.h>
William A. Kennington IIId5f1d402018-10-11 13:55:04 -07007#include <string.h>
8
Andrew Jeffery8de4c132018-02-23 17:50:51 +10309#include <experimental/filesystem>
10#include <fstream>
Andrew Jeffery8de4c132018-02-23 17:50:51 +103011#include <vector>
12
Andrew Jeffery53c21aa2018-03-26 11:56:16 +103013#include "vpnor/mboxd_pnor_partition_table.h"
Ratan Gupta3214b512017-05-11 08:58:19 +053014
15extern "C" {
16#include "test/mbox.h"
17#include "test/system.h"
18}
19
Andrew Jeffery30bcf842018-03-26 12:13:20 +103020#include "vpnor/test/tmpd.hpp"
Andrew Jeffery0b657f42018-02-22 12:04:02 +103021
Adriana Kobylak2ad21322017-11-28 14:59:19 -060022// A read window assumes that the toc is located at offset 0,
Andrew Jeffery8de4c132018-02-23 17:50:51 +103023// so create dummy partition at arbitrary offset 0x1000.
Andrew Jeffery0b657f42018-02-22 12:04:02 +103024const std::string toc[] = {
Andrew Jeffery8de4c132018-02-23 17:50:51 +103025 "partition01=HBB,00001000,00002000,80,ECC,READONLY",
Andrew Jeffery0b657f42018-02-22 12:04:02 +103026};
27
Andrew Jeffery8de4c132018-02-23 17:50:51 +103028static const uint8_t data[8] = {0xaa, 0x55, 0xaa, 0x66, 0x77, 0x88, 0x99, 0xab};
Ratan Gupta3214b512017-05-11 08:58:19 +053029
Andrew Jeffery8de4c132018-02-23 17:50:51 +103030static const auto BLOCK_SIZE = 4096;
31static const auto MEM_SIZE = BLOCK_SIZE * 2;
32static const auto ERASE_SIZE = BLOCK_SIZE;
33static const auto N_WINDOWS = 1;
34static const auto WINDOW_SIZE = BLOCK_SIZE;
Ratan Gupta3214b512017-05-11 08:58:19 +053035
Andrew Jefferyf34db312018-03-09 15:27:03 +103036static const uint8_t get_info[] = {0x02, 0x00, 0x02, 0x00, 0x00, 0x00,
37 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
38 0x00, 0x00, 0x00, 0x00};
Andrew Jeffery0b657f42018-02-22 12:04:02 +103039
Adriana Kobylak2ad21322017-11-28 14:59:19 -060040// offset 0x100 and size 6
Andrew Jeffery8de4c132018-02-23 17:50:51 +103041static const uint8_t create_read_window[] = {0x04, 0x01, 0x01, 0x00, 0x01, 0x00,
Andrew Jefferyf34db312018-03-09 15:27:03 +103042 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
43 0x00, 0x00, 0x00, 0x00};
Ratan Gupta3214b512017-05-11 08:58:19 +053044
Andrew Jefferyf34db312018-03-09 15:27:03 +103045static const uint8_t response[] = {0x04, 0x01, 0xfe, 0xff, 0x01, 0x00, 0x01,
46 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
Ratan Gupta3214b512017-05-11 08:58:19 +053047
Andrew Jeffery0b657f42018-02-22 12:04:02 +103048namespace test = openpower::virtual_pnor::test;
Ratan Gupta3214b512017-05-11 08:58:19 +053049
50int main()
51{
William A. Kennington IIId5f1d402018-10-11 13:55:04 -070052 struct mbox_context* ctx;
Ratan Gupta3214b512017-05-11 08:58:19 +053053
54 system_set_reserved_size(MEM_SIZE);
55 system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE);
56
Andrew Jeffery32476cb2018-02-22 15:34:17 +103057 ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE);
Ratan Gupta3214b512017-05-11 08:58:19 +053058
Andrew Jeffery32476cb2018-02-22 15:34:17 +103059 test::VpnorRoot root(ctx, toc, BLOCK_SIZE);
60 root.write("HBB", data, sizeof(data));
61
Andrew Jeffery742a1f62018-03-02 09:26:03 +103062 init_vpnor_from_paths(ctx);
Ratan Gupta3214b512017-05-11 08:58:19 +053063
64 int rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info));
65 assert(rc == 1);
66
67 // send the request for partition1
68 rc = mbox_command_dispatch(ctx, create_read_window,
Andrew Jefferyf34db312018-03-09 15:27:03 +103069 sizeof(create_read_window));
Ratan Gupta3214b512017-05-11 08:58:19 +053070 assert(rc == 1);
71
72 rc = mbox_cmp(ctx, response, sizeof(response));
73 assert(rc == 0);
74
75 // Compare the reserved memory to the pnor
76 rc = memcmp(ctx->mem, data, 6);
77 assert(rc == 0);
78
Ratan Gupta3214b512017-05-11 08:58:19 +053079 return rc;
80}