blob: f4c80de31b1b02415415f2d1aa6dd69dffb1a7fd [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 Jeffery0b657f42018-02-22 12:04:02 +103068 fs::path path;
69 const char *cpath;
Ratan Gupta3214b512017-05-11 08:58:19 +053070
Andrew Jeffery0b657f42018-02-22 12:04:02 +103071 test::VpnorRoot root(toc, BLOCK_SIZE);
72 root.write("HBB", data, sizeof(data));
Ratan Gupta3214b512017-05-11 08:58:19 +053073
Andrew Jeffery0b657f42018-02-22 12:04:02 +103074 path = root.path();
75 cpath = path.c_str();
Ratan Gupta3214b512017-05-11 08:58:19 +053076
77 system_set_reserved_size(MEM_SIZE);
78 system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE);
79
Andrew Jeffery0b657f42018-02-22 12:04:02 +103080 struct mbox_context *ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE);
81 strcpy(ctx->paths.ro_loc, cpath);
82 strcpy(ctx->paths.rw_loc, cpath);
83 strcpy(ctx->paths.prsv_loc, cpath);
Ratan Gupta3214b512017-05-11 08:58:19 +053084
Andrew Jeffery0b657f42018-02-22 12:04:02 +103085 vpnor_create_partition_table_from_path(ctx, cpath);
Ratan Gupta3214b512017-05-11 08:58:19 +053086
87 int rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info));
88 assert(rc == 1);
89
90 // send the request for partition1
91 rc = mbox_command_dispatch(ctx, create_read_window,
Andrew Jefferyf34db312018-03-09 15:27:03 +103092 sizeof(create_read_window));
Ratan Gupta3214b512017-05-11 08:58:19 +053093 assert(rc == 1);
94
95 rc = mbox_cmp(ctx, response, sizeof(response));
96 assert(rc == 0);
97
98 // Compare the reserved memory to the pnor
99 rc = memcmp(ctx->mem, data, 6);
100 assert(rc == 0);
101
Andrew Jefferyf34db312018-03-09 15:27:03 +1030102 // TODO: Add few more test cases for read from multiple partitions(PRSV/RW)
Ratan Gupta6a98e182017-06-06 15:04:23 +0530103 // Read beyond the partition file size.
104 // openbmc/openbmc#1868
105
Ratan Gupta3214b512017-05-11 08:58:19 +0530106 return rc;
107}