blob: fb371cb1c05d333a9ebcc9f548c200b5608b4f64 [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 "pnor_partition_table.hpp"
4#include "config.h"
5#include <assert.h>
6#include <string.h>
7#include <vector>
8#include <fstream>
9#include <experimental/filesystem>
10
Andrew Jefferyd083efd2018-02-21 21:19:00 +103011#include "test/vpnor/tmpd.hpp"
12
Andrew Jeffery9ecef792018-02-21 17:13:20 +103013static const auto BLOCK_SIZE = 4 * 1024;
14static const auto PNOR_SIZE = 64 * 1024 * 1024;
15
16const std::string toc[] = {
17 "partition01=HBB,00000000,00000400,80,ECC,PRESERVED",
18};
Deepak Kodihalli393821d2017-04-28 04:44:38 -050019constexpr auto partitionName = "HBB";
Andrew Jeffery9ecef792018-02-21 17:13:20 +103020
21namespace fs = std::experimental::filesystem;
Andrew Jeffery812923d2018-02-22 11:59:52 +103022namespace test = openpower::virtual_pnor::test;
Andrew Jeffery9ecef792018-02-21 17:13:20 +103023
Deepak Kodihalli393821d2017-04-28 04:44:38 -050024int main()
25{
Andrew Jeffery812923d2018-02-22 11:59:52 +103026 test::VpnorRoot root(toc, BLOCK_SIZE);
Deepak Kodihalli393821d2017-04-28 04:44:38 -050027
Andrew Jefferyf34db312018-03-09 15:27:03 +103028 const openpower::virtual_pnor::partition::Table table(
Andrew Jeffery812923d2018-02-22 11:59:52 +103029 fs::path{root.path()}, BLOCK_SIZE, PNOR_SIZE);
Deepak Kodihalli393821d2017-04-28 04:44:38 -050030
31 pnor_partition_table expectedTable{};
32 expectedTable.data.magic = PARTITION_HEADER_MAGIC;
33 expectedTable.data.version = PARTITION_VERSION_1;
34 expectedTable.data.size = 1; // 1 block
35 expectedTable.data.entry_size = sizeof(pnor_partition);
36 expectedTable.data.entry_count = 1; // 1 partition
Andrew Jeffery9ecef792018-02-21 17:13:20 +103037 expectedTable.data.block_size = BLOCK_SIZE;
Deepak Kodihallid1d79302017-07-11 23:01:39 -050038 expectedTable.data.block_count =
Andrew Jeffery9ecef792018-02-21 17:13:20 +103039 (PNOR_SIZE) / expectedTable.data.block_size;
Deepak Kodihalli393821d2017-04-28 04:44:38 -050040 expectedTable.checksum =
41 openpower::virtual_pnor::details::checksum(expectedTable.data);
42
43 pnor_partition expectedPartition{};
44 strcpy(expectedPartition.data.name, partitionName);
Andrew Jefferyf34db312018-03-09 15:27:03 +103045 expectedPartition.data.base = 0; // starts at offset 0
46 expectedPartition.data.size = 1; // 1 block
Deepak Kodihalli393821d2017-04-28 04:44:38 -050047 expectedPartition.data.actual = 0x400; // 1024 bytes
48 expectedPartition.data.id = 1;
49 expectedPartition.data.pid = PARENT_PATITION_ID;
50 expectedPartition.data.type = PARTITION_TYPE_DATA;
51 expectedPartition.data.flags = 0;
52 expectedPartition.data.user.data[0] = PARTITION_ECC_PROTECTED;
53 expectedPartition.data.user.data[1] |= PARTITION_PRESERVED;
Deepak Kodihallie8b0e8a2017-07-12 10:01:31 -050054 expectedPartition.data.user.data[1] |= PARTITION_VERSION_CHECK_SHA512;
Deepak Kodihalli393821d2017-04-28 04:44:38 -050055 expectedPartition.checksum =
56 openpower::virtual_pnor::details::checksum(expectedPartition.data);
57
58 const pnor_partition_table& result = table.getNativeTable();
59
Deepak Kodihalli393821d2017-04-28 04:44:38 -050060 auto rc = memcmp(&expectedTable, &result, sizeof(pnor_partition_table));
61 assert(rc == 0);
62
63 rc = memcmp(&expectedPartition, &result.partitions[0],
64 sizeof(pnor_partition));
65 assert(rc == 0);
66
Adriana Kobylak2ad21322017-11-28 14:59:19 -060067 const pnor_partition& first = table.partition(0); // Partition at offset 0
Deepak Kodihalli393821d2017-04-28 04:44:38 -050068 rc = memcmp(&first, &result.partitions[0], sizeof(pnor_partition));
69 assert(rc == 0);
70
71 return 0;
72}