1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright (C) 2018 IBM Corp. 3 4 #include "config.h" 5 6 extern "C" { 7 #include "backend.h" 8 #include "test/mbox.h" 9 #include "test/system.h" 10 } 11 12 #include "vpnor/table.hpp" 13 #include "vpnor/test/tmpd.hpp" 14 15 #include <cassert> 16 #include <cstring> 17 18 static const auto BLOCK_SIZE = 4 * 1024; 19 static const auto ERASE_SIZE = BLOCK_SIZE; 20 static const auto PNOR_SIZE = 64 * 1024 * 1024; 21 static const auto MEM_SIZE = PNOR_SIZE; 22 static const auto N_WINDOWS = 1; 23 static const auto WINDOW_SIZE = BLOCK_SIZE; 24 25 const std::string toc[] = { 26 "partition01=HBB,00000000,00001000,80,ECC,PRESERVED", 27 }; 28 constexpr auto partitionName = "HBB"; 29 30 namespace test = openpower::virtual_pnor::test; 31 32 int main() 33 { 34 struct mbox_context* ctx; 35 36 system_set_reserved_size(MEM_SIZE); 37 system_set_mtd_sizes(PNOR_SIZE, ERASE_SIZE); 38 ctx = mbox_create_frontend_context(N_WINDOWS, WINDOW_SIZE); 39 test::VpnorRoot root(&ctx->backend, toc, BLOCK_SIZE); 40 const openpower::virtual_pnor::partition::Table table(&ctx->backend); 41 42 pnor_partition_table expectedTable{}; 43 expectedTable.data.magic = PARTITION_HEADER_MAGIC; 44 expectedTable.data.version = PARTITION_VERSION_1; 45 expectedTable.data.size = 1; 46 expectedTable.data.entry_size = sizeof(pnor_partition); 47 expectedTable.data.entry_count = 1; 48 expectedTable.data.block_size = BLOCK_SIZE; 49 expectedTable.data.block_count = 50 (PNOR_SIZE) / expectedTable.data.block_size; 51 expectedTable.checksum = 52 openpower::virtual_pnor::details::checksum(expectedTable.data); 53 54 pnor_partition expectedPartition{}; 55 strcpy(expectedPartition.data.name, partitionName); 56 expectedPartition.data.base = 0; 57 expectedPartition.data.size = 1; 58 expectedPartition.data.actual = 0x1000; 59 expectedPartition.data.id = 1; 60 expectedPartition.data.pid = PARENT_PATITION_ID; 61 expectedPartition.data.type = PARTITION_TYPE_DATA; 62 expectedPartition.data.flags = 0; 63 expectedPartition.data.user.data[0] = PARTITION_ECC_PROTECTED; 64 expectedPartition.data.user.data[1] |= PARTITION_PRESERVED; 65 expectedPartition.data.user.data[1] |= PARTITION_VERSION_CHECK_SHA512; 66 expectedPartition.checksum = 67 openpower::virtual_pnor::details::checksum(expectedPartition.data); 68 69 const pnor_partition_table& result = table.getNativeTable(); 70 71 auto rc = memcmp(&expectedTable, &result, sizeof(pnor_partition_table)); 72 assert(rc == 0); 73 74 rc = memcmp(&expectedPartition, &result.partitions[0], 75 sizeof(pnor_partition)); 76 assert(rc == 0); 77 78 const pnor_partition& first = table.partition(0); 79 rc = memcmp(&first, &result.partitions[0], sizeof(pnor_partition)); 80 assert(rc == 0); 81 82 return 0; 83 } 84