blob: f198f29e727bd098f4cbeccfe8efe288638baebf [file] [log] [blame]
Andrew Jeffery4fe996c2018-02-27 12:16:48 +10301// SPDX-License-Identifier: Apache-2.0
2// Copyright (C) 2018 IBM Corp.
William A. Kennington IIId5f1d402018-10-11 13:55:04 -07003#include "config.h"
4
5#include "vpnor/pnor_partition_table.hpp"
6
Andrew Jeffery261f61a2019-03-14 09:57:28 +10307#include <cassert>
8#include <cstring>
Andrew Jeffery097495c2018-02-22 11:36:13 +10309
Andrew Jeffery742a1f62018-03-02 09:26:03 +103010extern "C" {
11#include "test/mbox.h"
12#include "test/system.h"
13}
14
Andrew Jeffery30bcf842018-03-26 12:13:20 +103015#include "vpnor/test/tmpd.hpp"
Andrew Jefferyd083efd2018-02-21 21:19:00 +103016
Andrew Jeffery9ecef792018-02-21 17:13:20 +103017static const auto BLOCK_SIZE = 4 * 1024;
Andrew Jeffery742a1f62018-03-02 09:26:03 +103018static const auto ERASE_SIZE = BLOCK_SIZE;
Andrew Jeffery9ecef792018-02-21 17:13:20 +103019static const auto PNOR_SIZE = 64 * 1024 * 1024;
Andrew Jeffery742a1f62018-03-02 09:26:03 +103020static const auto MEM_SIZE = PNOR_SIZE;
21static const auto N_WINDOWS = 1;
22static const auto WINDOW_SIZE = BLOCK_SIZE;
Andrew Jeffery9ecef792018-02-21 17:13:20 +103023
24const std::string toc[] = {
Andrew Jeffery742a1f62018-03-02 09:26:03 +103025 "partition01=HBB,00000000,00001000,80,ECC,PRESERVED",
Andrew Jeffery9ecef792018-02-21 17:13:20 +103026};
Deepak Kodihalli393821d2017-04-28 04:44:38 -050027constexpr auto partitionName = "HBB";
Andrew Jeffery9ecef792018-02-21 17:13:20 +103028
Andrew Jeffery812923d2018-02-22 11:59:52 +103029namespace test = openpower::virtual_pnor::test;
Andrew Jeffery9ecef792018-02-21 17:13:20 +103030
Deepak Kodihalli393821d2017-04-28 04:44:38 -050031int main()
32{
Andrew Jeffery742a1f62018-03-02 09:26:03 +103033 struct mbox_context* ctx;
Andrew Jeffery32476cb2018-02-22 15:34:17 +103034
Andrew Jeffery742a1f62018-03-02 09:26:03 +103035 system_set_reserved_size(MEM_SIZE);
36 system_set_mtd_sizes(PNOR_SIZE, ERASE_SIZE);
Evan Lojewskif1e547c2019-03-14 14:34:33 +103037 ctx = mbox_create_frontend_context(N_WINDOWS, WINDOW_SIZE);
38 test::VpnorRoot root(&ctx->backend, toc, BLOCK_SIZE);
39 const openpower::virtual_pnor::partition::Table table(&ctx->backend);
Deepak Kodihalli393821d2017-04-28 04:44:38 -050040
41 pnor_partition_table expectedTable{};
42 expectedTable.data.magic = PARTITION_HEADER_MAGIC;
43 expectedTable.data.version = PARTITION_VERSION_1;
Andrew Jeffery742a1f62018-03-02 09:26:03 +103044 expectedTable.data.size = 1;
Deepak Kodihalli393821d2017-04-28 04:44:38 -050045 expectedTable.data.entry_size = sizeof(pnor_partition);
Andrew Jeffery742a1f62018-03-02 09:26:03 +103046 expectedTable.data.entry_count = 1;
Andrew Jeffery9ecef792018-02-21 17:13:20 +103047 expectedTable.data.block_size = BLOCK_SIZE;
Deepak Kodihallid1d79302017-07-11 23:01:39 -050048 expectedTable.data.block_count =
Andrew Jeffery9ecef792018-02-21 17:13:20 +103049 (PNOR_SIZE) / expectedTable.data.block_size;
Deepak Kodihalli393821d2017-04-28 04:44:38 -050050 expectedTable.checksum =
51 openpower::virtual_pnor::details::checksum(expectedTable.data);
52
53 pnor_partition expectedPartition{};
54 strcpy(expectedPartition.data.name, partitionName);
Andrew Jeffery742a1f62018-03-02 09:26:03 +103055 expectedPartition.data.base = 0;
56 expectedPartition.data.size = 1;
57 expectedPartition.data.actual = 0x1000;
Deepak Kodihalli393821d2017-04-28 04:44:38 -050058 expectedPartition.data.id = 1;
59 expectedPartition.data.pid = PARENT_PATITION_ID;
60 expectedPartition.data.type = PARTITION_TYPE_DATA;
61 expectedPartition.data.flags = 0;
62 expectedPartition.data.user.data[0] = PARTITION_ECC_PROTECTED;
63 expectedPartition.data.user.data[1] |= PARTITION_PRESERVED;
Deepak Kodihallie8b0e8a2017-07-12 10:01:31 -050064 expectedPartition.data.user.data[1] |= PARTITION_VERSION_CHECK_SHA512;
Deepak Kodihalli393821d2017-04-28 04:44:38 -050065 expectedPartition.checksum =
66 openpower::virtual_pnor::details::checksum(expectedPartition.data);
67
68 const pnor_partition_table& result = table.getNativeTable();
69
Deepak Kodihalli393821d2017-04-28 04:44:38 -050070 auto rc = memcmp(&expectedTable, &result, sizeof(pnor_partition_table));
71 assert(rc == 0);
72
73 rc = memcmp(&expectedPartition, &result.partitions[0],
74 sizeof(pnor_partition));
75 assert(rc == 0);
76
Andrew Jeffery742a1f62018-03-02 09:26:03 +103077 const pnor_partition& first = table.partition(0);
Deepak Kodihalli393821d2017-04-28 04:44:38 -050078 rc = memcmp(&first, &result.partitions[0], sizeof(pnor_partition));
79 assert(rc == 0);
80
81 return 0;
82}