1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright (C) 2018 IBM Corp. 3 4 #include "config.h" 5 6 extern "C" { 7 #include "test/mbox.h" 8 #include "test/system.h" 9 } 10 11 #include "vpnor/test/tmpd.hpp" 12 13 #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 21 // A read window assumes that the toc is located at offset 0, 22 // so create dummy partition at arbitrary offset 0x1000. 23 const std::string toc[] = { 24 "partition01=HBB,00001000,00002000,80,ECC,READONLY", 25 }; 26 27 static const uint8_t data[8] = {0xaa, 0x55, 0xaa, 0x66, 0x77, 0x88, 0x99, 0xab}; 28 29 static const auto BLOCK_SIZE = 4096; 30 static const auto MEM_SIZE = BLOCK_SIZE * 2; 31 static const auto ERASE_SIZE = BLOCK_SIZE; 32 static const auto N_WINDOWS = 1; 33 static const auto WINDOW_SIZE = BLOCK_SIZE; 34 35 static const uint8_t get_info[] = {0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 36 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 37 0x00, 0x00, 0x00, 0x00}; 38 39 // offset 0x100 and size 6 40 static const uint8_t create_read_window[] = {0x04, 0x01, 0x01, 0x00, 0x01, 0x00, 41 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 42 0x00, 0x00, 0x00, 0x00}; 43 44 static const uint8_t response[] = {0x04, 0x01, 0xfe, 0xff, 0x01, 0x00, 0x01, 45 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}; 46 47 namespace test = openpower::virtual_pnor::test; 48 49 int main() 50 { 51 struct mbox_context* ctx; 52 53 system_set_reserved_size(MEM_SIZE); 54 system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE); 55 56 ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE); 57 58 test::VpnorRoot root(ctx, toc, BLOCK_SIZE); 59 root.write("HBB", data, sizeof(data)); 60 61 init_vpnor_from_paths(ctx); 62 63 int rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info)); 64 assert(rc == 1); 65 66 // send the request for partition1 67 rc = mbox_command_dispatch(ctx, create_read_window, 68 sizeof(create_read_window)); 69 assert(rc == 1); 70 71 rc = mbox_cmp(ctx, response, sizeof(response)); 72 assert(rc == 0); 73 74 // Compare the reserved memory to the pnor 75 rc = memcmp(ctx->mem, data, 6); 76 assert(rc == 0); 77 78 return rc; 79 } 80