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