blob: 87deb9c6912c8056a7d90dc6349fdb58eea95c83 [file] [log] [blame]
Andrew Jefferyacee6832018-02-21 22:17:08 +10301/*
2 * MBox Daemon Test File
3 *
4 * Copyright 2018 IBM
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 */
19
Ratan Gupta3214b512017-05-11 08:58:19 +053020#include "config.h"
21#include "mboxd_pnor_partition_table.h"
22
23extern "C" {
24#include "test/mbox.h"
25#include "test/system.h"
26}
27
28#include <assert.h>
29#include <string.h>
30
31#include <vector>
32#include <fstream>
33#include <experimental/filesystem>
34
Andrew Jeffery0b657f42018-02-22 12:04:02 +103035#include "test/vpnor/tmpd.hpp"
36
Adriana Kobylak2ad21322017-11-28 14:59:19 -060037// A read window assumes that the toc is located at offset 0,
38// so create dummy partition at arbitrary offset 0x100.
Andrew Jeffery0b657f42018-02-22 12:04:02 +103039const std::string toc[] = {
40 "partition01=HBB,00000100,0001000,ECC,PRESERVED",
41};
42
Andrew Jefferyf34db312018-03-09 15:27:03 +103043uint8_t data[8] = {0xaa, 0x55, 0xaa, 0x66, 0x77, 0x88, 0x99, 0xab};
Ratan Gupta3214b512017-05-11 08:58:19 +053044
Andrew Jefferyf34db312018-03-09 15:27:03 +103045#define BLOCK_SIZE 4096
46#define MEM_SIZE (BLOCK_SIZE * 2)
47#define ERASE_SIZE BLOCK_SIZE
48#define N_WINDOWS 1
Ratan Gupta3214b512017-05-11 08:58:19 +053049#define WINDOW_SIZE BLOCK_SIZE
50
Andrew Jefferyf34db312018-03-09 15:27:03 +103051static const uint8_t get_info[] = {0x02, 0x00, 0x02, 0x00, 0x00, 0x00,
52 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
53 0x00, 0x00, 0x00, 0x00};
Andrew Jeffery0b657f42018-02-22 12:04:02 +103054
Adriana Kobylak2ad21322017-11-28 14:59:19 -060055// offset 0x100 and size 6
Andrew Jefferyf34db312018-03-09 15:27:03 +103056static const uint8_t create_read_window[] = {0x04, 0x01, 0x01, 0x00, 0x06, 0x00,
57 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
58 0x00, 0x00, 0x00, 0x00};
Ratan Gupta3214b512017-05-11 08:58:19 +053059
Andrew Jefferyf34db312018-03-09 15:27:03 +103060static const uint8_t response[] = {0x04, 0x01, 0xfe, 0xff, 0x01, 0x00, 0x01,
61 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
Ratan Gupta3214b512017-05-11 08:58:19 +053062
63namespace fs = std::experimental::filesystem;
Andrew Jeffery0b657f42018-02-22 12:04:02 +103064namespace test = openpower::virtual_pnor::test;
Ratan Gupta3214b512017-05-11 08:58:19 +053065
66int main()
67{
Andrew Jeffery32476cb2018-02-22 15:34:17 +103068 struct mbox_context *ctx;
Ratan Gupta3214b512017-05-11 08:58:19 +053069
70 system_set_reserved_size(MEM_SIZE);
71 system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE);
72
Andrew Jeffery32476cb2018-02-22 15:34:17 +103073 ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE);
Ratan Gupta3214b512017-05-11 08:58:19 +053074
Andrew Jeffery32476cb2018-02-22 15:34:17 +103075 test::VpnorRoot root(ctx, toc, BLOCK_SIZE);
76 root.write("HBB", data, sizeof(data));
77
78 vpnor_create_partition_table_from_path(ctx, root.ro().c_str());
Ratan Gupta3214b512017-05-11 08:58:19 +053079
80 int rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info));
81 assert(rc == 1);
82
83 // send the request for partition1
84 rc = mbox_command_dispatch(ctx, create_read_window,
Andrew Jefferyf34db312018-03-09 15:27:03 +103085 sizeof(create_read_window));
Ratan Gupta3214b512017-05-11 08:58:19 +053086 assert(rc == 1);
87
88 rc = mbox_cmp(ctx, response, sizeof(response));
89 assert(rc == 0);
90
91 // Compare the reserved memory to the pnor
92 rc = memcmp(ctx->mem, data, 6);
93 assert(rc == 0);
94
Andrew Jefferyf34db312018-03-09 15:27:03 +103095 // TODO: Add few more test cases for read from multiple partitions(PRSV/RW)
Ratan Gupta6a98e182017-06-06 15:04:23 +053096 // Read beyond the partition file size.
97 // openbmc/openbmc#1868
98
Ratan Gupta3214b512017-05-11 08:58:19 +053099 return rc;
100}