blob: 09f481d5b346d28bc825e3601ee882d2cbef4f94 [file] [log] [blame]
Andrew Jeffery4fe996c2018-02-27 12:16:48 +10301// SPDX-License-Identifier: Apache-2.0
2// Copyright (C) 2018 IBM Corp.
Deepak Kodihalli393821d2017-04-28 04:44:38 -05003#include <assert.h>
4#include <string.h>
Andrew Jeffery097495c2018-02-22 11:36:13 +10305
6#include "config.h"
7#include "pnor_partition_table.hpp"
Deepak Kodihalli393821d2017-04-28 04:44:38 -05008
Andrew Jefferyd083efd2018-02-21 21:19:00 +10309#include "test/vpnor/tmpd.hpp"
10
Andrew Jeffery9ecef792018-02-21 17:13:20 +103011static const auto BLOCK_SIZE = 4 * 1024;
12static const auto PNOR_SIZE = 64 * 1024 * 1024;
13
14const std::string toc[] = {
15 "partition01=HBB,00000000,00000400,80,ECC,PRESERVED",
16};
Deepak Kodihalli393821d2017-04-28 04:44:38 -050017constexpr auto partitionName = "HBB";
Andrew Jeffery9ecef792018-02-21 17:13:20 +103018
Andrew Jeffery812923d2018-02-22 11:59:52 +103019namespace test = openpower::virtual_pnor::test;
Andrew Jeffery9ecef792018-02-21 17:13:20 +103020
Deepak Kodihalli393821d2017-04-28 04:44:38 -050021int main()
22{
Andrew Jeffery32476cb2018-02-22 15:34:17 +103023 struct mbox_context _ctx, *ctx = &_ctx;
24
25 test::VpnorRoot root(ctx, toc, BLOCK_SIZE);
Deepak Kodihalli393821d2017-04-28 04:44:38 -050026
Andrew Jeffery097495c2018-02-22 11:36:13 +103027 const openpower::virtual_pnor::partition::Table table(root.ro(), BLOCK_SIZE,
28 PNOR_SIZE);
Deepak Kodihalli393821d2017-04-28 04:44:38 -050029
30 pnor_partition_table expectedTable{};
31 expectedTable.data.magic = PARTITION_HEADER_MAGIC;
32 expectedTable.data.version = PARTITION_VERSION_1;
33 expectedTable.data.size = 1; // 1 block
34 expectedTable.data.entry_size = sizeof(pnor_partition);
35 expectedTable.data.entry_count = 1; // 1 partition
Andrew Jeffery9ecef792018-02-21 17:13:20 +103036 expectedTable.data.block_size = BLOCK_SIZE;
Deepak Kodihallid1d79302017-07-11 23:01:39 -050037 expectedTable.data.block_count =
Andrew Jeffery9ecef792018-02-21 17:13:20 +103038 (PNOR_SIZE) / expectedTable.data.block_size;
Deepak Kodihalli393821d2017-04-28 04:44:38 -050039 expectedTable.checksum =
40 openpower::virtual_pnor::details::checksum(expectedTable.data);
41
42 pnor_partition expectedPartition{};
43 strcpy(expectedPartition.data.name, partitionName);
Andrew Jefferyf34db312018-03-09 15:27:03 +103044 expectedPartition.data.base = 0; // starts at offset 0
45 expectedPartition.data.size = 1; // 1 block
Deepak Kodihalli393821d2017-04-28 04:44:38 -050046 expectedPartition.data.actual = 0x400; // 1024 bytes
47 expectedPartition.data.id = 1;
48 expectedPartition.data.pid = PARENT_PATITION_ID;
49 expectedPartition.data.type = PARTITION_TYPE_DATA;
50 expectedPartition.data.flags = 0;
51 expectedPartition.data.user.data[0] = PARTITION_ECC_PROTECTED;
52 expectedPartition.data.user.data[1] |= PARTITION_PRESERVED;
Deepak Kodihallie8b0e8a2017-07-12 10:01:31 -050053 expectedPartition.data.user.data[1] |= PARTITION_VERSION_CHECK_SHA512;
Deepak Kodihalli393821d2017-04-28 04:44:38 -050054 expectedPartition.checksum =
55 openpower::virtual_pnor::details::checksum(expectedPartition.data);
56
57 const pnor_partition_table& result = table.getNativeTable();
58
Deepak Kodihalli393821d2017-04-28 04:44:38 -050059 auto rc = memcmp(&expectedTable, &result, sizeof(pnor_partition_table));
60 assert(rc == 0);
61
62 rc = memcmp(&expectedPartition, &result.partitions[0],
63 sizeof(pnor_partition));
64 assert(rc == 0);
65
Adriana Kobylak2ad21322017-11-28 14:59:19 -060066 const pnor_partition& first = table.partition(0); // Partition at offset 0
Deepak Kodihalli393821d2017-04-28 04:44:38 -050067 rc = memcmp(&first, &result.partitions[0], sizeof(pnor_partition));
68 assert(rc == 0);
69
70 return 0;
71}