blob: 3a46e38b7b68efac8c2cbd3a63e4d1330c968b7a [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"
Andrew Jeffery53c21aa2018-03-26 11:56:16 +10307#include "vpnor/pnor_partition_table.hpp"
Deepak Kodihalli393821d2017-04-28 04:44:38 -05008
Andrew Jeffery742a1f62018-03-02 09:26:03 +10309extern "C" {
10#include "test/mbox.h"
11#include "test/system.h"
12}
13
Andrew Jeffery30bcf842018-03-26 12:13:20 +103014#include "vpnor/test/tmpd.hpp"
Andrew Jefferyd083efd2018-02-21 21:19:00 +103015
Andrew Jeffery9ecef792018-02-21 17:13:20 +103016static const auto BLOCK_SIZE = 4 * 1024;
Andrew Jeffery742a1f62018-03-02 09:26:03 +103017static const auto ERASE_SIZE = BLOCK_SIZE;
Andrew Jeffery9ecef792018-02-21 17:13:20 +103018static const auto PNOR_SIZE = 64 * 1024 * 1024;
Andrew Jeffery742a1f62018-03-02 09:26:03 +103019static const auto MEM_SIZE = PNOR_SIZE;
20static const auto N_WINDOWS = 1;
21static const auto WINDOW_SIZE = BLOCK_SIZE;
Andrew Jeffery9ecef792018-02-21 17:13:20 +103022
23const std::string toc[] = {
Andrew Jeffery742a1f62018-03-02 09:26:03 +103024 "partition01=HBB,00000000,00001000,80,ECC,PRESERVED",
Andrew Jeffery9ecef792018-02-21 17:13:20 +103025};
Deepak Kodihalli393821d2017-04-28 04:44:38 -050026constexpr auto partitionName = "HBB";
Andrew Jeffery9ecef792018-02-21 17:13:20 +103027
Andrew Jeffery812923d2018-02-22 11:59:52 +103028namespace test = openpower::virtual_pnor::test;
Andrew Jeffery9ecef792018-02-21 17:13:20 +103029
Deepak Kodihalli393821d2017-04-28 04:44:38 -050030int main()
31{
Andrew Jeffery742a1f62018-03-02 09:26:03 +103032 struct mbox_context* ctx;
Andrew Jeffery32476cb2018-02-22 15:34:17 +103033
Andrew Jeffery742a1f62018-03-02 09:26:03 +103034 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);
Andrew Jeffery32476cb2018-02-22 15:34:17 +103037 test::VpnorRoot root(ctx, toc, BLOCK_SIZE);
Andrew Jeffery742a1f62018-03-02 09:26:03 +103038 const openpower::virtual_pnor::partition::Table table(ctx);
Deepak Kodihalli393821d2017-04-28 04:44:38 -050039
40 pnor_partition_table expectedTable{};
41 expectedTable.data.magic = PARTITION_HEADER_MAGIC;
42 expectedTable.data.version = PARTITION_VERSION_1;
Andrew Jeffery742a1f62018-03-02 09:26:03 +103043 expectedTable.data.size = 1;
Deepak Kodihalli393821d2017-04-28 04:44:38 -050044 expectedTable.data.entry_size = sizeof(pnor_partition);
Andrew Jeffery742a1f62018-03-02 09:26:03 +103045 expectedTable.data.entry_count = 1;
Andrew Jeffery9ecef792018-02-21 17:13:20 +103046 expectedTable.data.block_size = BLOCK_SIZE;
Deepak Kodihallid1d79302017-07-11 23:01:39 -050047 expectedTable.data.block_count =
Andrew Jeffery9ecef792018-02-21 17:13:20 +103048 (PNOR_SIZE) / expectedTable.data.block_size;
Deepak Kodihalli393821d2017-04-28 04:44:38 -050049 expectedTable.checksum =
50 openpower::virtual_pnor::details::checksum(expectedTable.data);
51
52 pnor_partition expectedPartition{};
53 strcpy(expectedPartition.data.name, partitionName);
Andrew Jeffery742a1f62018-03-02 09:26:03 +103054 expectedPartition.data.base = 0;
55 expectedPartition.data.size = 1;
56 expectedPartition.data.actual = 0x1000;
Deepak Kodihalli393821d2017-04-28 04:44:38 -050057 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;
Deepak Kodihallie8b0e8a2017-07-12 10:01:31 -050063 expectedPartition.data.user.data[1] |= PARTITION_VERSION_CHECK_SHA512;
Deepak Kodihalli393821d2017-04-28 04:44:38 -050064 expectedPartition.checksum =
65 openpower::virtual_pnor::details::checksum(expectedPartition.data);
66
67 const pnor_partition_table& result = table.getNativeTable();
68
Deepak Kodihalli393821d2017-04-28 04:44:38 -050069 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
Andrew Jeffery742a1f62018-03-02 09:26:03 +103076 const pnor_partition& first = table.partition(0);
Deepak Kodihalli393821d2017-04-28 04:44:38 -050077 rc = memcmp(&first, &result.partitions[0], sizeof(pnor_partition));
78 assert(rc == 0);
79
80 return 0;
81}