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