summaryrefslogtreecommitdiffstats
path: root/test/vpnor/create_pnor_partition_table.cpp
blob: 09f481d5b346d28bc825e3601ee882d2cbef4f94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2018 IBM Corp.
#include <assert.h>
#include <string.h>

#include "config.h"
#include "pnor_partition_table.hpp"

#include "test/vpnor/tmpd.hpp"

static const auto BLOCK_SIZE = 4 * 1024;
static const auto PNOR_SIZE = 64 * 1024 * 1024;

const std::string toc[] = {
    "partition01=HBB,00000000,00000400,80,ECC,PRESERVED",
};
constexpr auto partitionName = "HBB";

namespace test = openpower::virtual_pnor::test;

int main()
{
    struct mbox_context _ctx, *ctx = &_ctx;

    test::VpnorRoot root(ctx, toc, BLOCK_SIZE);

    const openpower::virtual_pnor::partition::Table table(root.ro(), BLOCK_SIZE,
                                                          PNOR_SIZE);

    pnor_partition_table expectedTable{};
    expectedTable.data.magic = PARTITION_HEADER_MAGIC;
    expectedTable.data.version = PARTITION_VERSION_1;
    expectedTable.data.size = 1; // 1 block
    expectedTable.data.entry_size = sizeof(pnor_partition);
    expectedTable.data.entry_count = 1; // 1 partition
    expectedTable.data.block_size = BLOCK_SIZE;
    expectedTable.data.block_count =
        (PNOR_SIZE) / expectedTable.data.block_size;
    expectedTable.checksum =
        openpower::virtual_pnor::details::checksum(expectedTable.data);

    pnor_partition expectedPartition{};
    strcpy(expectedPartition.data.name, partitionName);
    expectedPartition.data.base = 0;       // starts at offset 0
    expectedPartition.data.size = 1;       // 1 block
    expectedPartition.data.actual = 0x400; // 1024 bytes
    expectedPartition.data.id = 1;
    expectedPartition.data.pid = PARENT_PATITION_ID;
    expectedPartition.data.type = PARTITION_TYPE_DATA;
    expectedPartition.data.flags = 0;
    expectedPartition.data.user.data[0] = PARTITION_ECC_PROTECTED;
    expectedPartition.data.user.data[1] |= PARTITION_PRESERVED;
    expectedPartition.data.user.data[1] |= PARTITION_VERSION_CHECK_SHA512;
    expectedPartition.checksum =
        openpower::virtual_pnor::details::checksum(expectedPartition.data);

    const pnor_partition_table& result = table.getNativeTable();

    auto rc = memcmp(&expectedTable, &result, sizeof(pnor_partition_table));
    assert(rc == 0);

    rc = memcmp(&expectedPartition, &result.partitions[0],
                sizeof(pnor_partition));
    assert(rc == 0);

    const pnor_partition& first = table.partition(0); // Partition at offset 0
    rc = memcmp(&first, &result.partitions[0], sizeof(pnor_partition));
    assert(rc == 0);

    return 0;
}
OpenPOWER on IntegriCloud