Andrew Jeffery | 4fe996c | 2018-02-27 12:16:48 +1030 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // Copyright (C) 2018 IBM Corp. |
William A. Kennington III | d5f1d40 | 2018-10-11 13:55:04 -0700 | [diff] [blame] | 3 | #include "config.h" |
| 4 | |
| 5 | #include "vpnor/pnor_partition_table.hpp" |
| 6 | |
Deepak Kodihalli | 393821d | 2017-04-28 04:44:38 -0500 | [diff] [blame] | 7 | #include <assert.h> |
| 8 | #include <string.h> |
Andrew Jeffery | 097495c | 2018-02-22 11:36:13 +1030 | [diff] [blame] | 9 | |
Andrew Jeffery | 742a1f6 | 2018-03-02 09:26:03 +1030 | [diff] [blame] | 10 | extern "C" { |
| 11 | #include "test/mbox.h" |
| 12 | #include "test/system.h" |
| 13 | } |
| 14 | |
Andrew Jeffery | 30bcf84 | 2018-03-26 12:13:20 +1030 | [diff] [blame] | 15 | #include "vpnor/test/tmpd.hpp" |
Andrew Jeffery | d083efd | 2018-02-21 21:19:00 +1030 | [diff] [blame] | 16 | |
Andrew Jeffery | 9ecef79 | 2018-02-21 17:13:20 +1030 | [diff] [blame] | 17 | static const auto BLOCK_SIZE = 4 * 1024; |
Andrew Jeffery | 742a1f6 | 2018-03-02 09:26:03 +1030 | [diff] [blame] | 18 | static const auto ERASE_SIZE = BLOCK_SIZE; |
Andrew Jeffery | 9ecef79 | 2018-02-21 17:13:20 +1030 | [diff] [blame] | 19 | static const auto PNOR_SIZE = 64 * 1024 * 1024; |
Andrew Jeffery | 742a1f6 | 2018-03-02 09:26:03 +1030 | [diff] [blame] | 20 | static const auto MEM_SIZE = PNOR_SIZE; |
| 21 | static const auto N_WINDOWS = 1; |
| 22 | static const auto WINDOW_SIZE = BLOCK_SIZE; |
Andrew Jeffery | 9ecef79 | 2018-02-21 17:13:20 +1030 | [diff] [blame] | 23 | |
| 24 | const std::string toc[] = { |
Andrew Jeffery | 742a1f6 | 2018-03-02 09:26:03 +1030 | [diff] [blame] | 25 | "partition01=HBB,00000000,00001000,80,ECC,PRESERVED", |
Andrew Jeffery | 9ecef79 | 2018-02-21 17:13:20 +1030 | [diff] [blame] | 26 | }; |
Deepak Kodihalli | 393821d | 2017-04-28 04:44:38 -0500 | [diff] [blame] | 27 | constexpr auto partitionName = "HBB"; |
Andrew Jeffery | 9ecef79 | 2018-02-21 17:13:20 +1030 | [diff] [blame] | 28 | |
Andrew Jeffery | 812923d | 2018-02-22 11:59:52 +1030 | [diff] [blame] | 29 | namespace test = openpower::virtual_pnor::test; |
Andrew Jeffery | 9ecef79 | 2018-02-21 17:13:20 +1030 | [diff] [blame] | 30 | |
Deepak Kodihalli | 393821d | 2017-04-28 04:44:38 -0500 | [diff] [blame] | 31 | int main() |
| 32 | { |
Andrew Jeffery | 742a1f6 | 2018-03-02 09:26:03 +1030 | [diff] [blame] | 33 | struct mbox_context* ctx; |
Andrew Jeffery | 32476cb | 2018-02-22 15:34:17 +1030 | [diff] [blame] | 34 | |
Andrew Jeffery | 742a1f6 | 2018-03-02 09:26:03 +1030 | [diff] [blame] | 35 | system_set_reserved_size(MEM_SIZE); |
| 36 | system_set_mtd_sizes(PNOR_SIZE, ERASE_SIZE); |
| 37 | ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE); |
Andrew Jeffery | 32476cb | 2018-02-22 15:34:17 +1030 | [diff] [blame] | 38 | test::VpnorRoot root(ctx, toc, BLOCK_SIZE); |
Andrew Jeffery | 742a1f6 | 2018-03-02 09:26:03 +1030 | [diff] [blame] | 39 | const openpower::virtual_pnor::partition::Table table(ctx); |
Deepak Kodihalli | 393821d | 2017-04-28 04:44:38 -0500 | [diff] [blame] | 40 | |
| 41 | pnor_partition_table expectedTable{}; |
| 42 | expectedTable.data.magic = PARTITION_HEADER_MAGIC; |
| 43 | expectedTable.data.version = PARTITION_VERSION_1; |
Andrew Jeffery | 742a1f6 | 2018-03-02 09:26:03 +1030 | [diff] [blame] | 44 | expectedTable.data.size = 1; |
Deepak Kodihalli | 393821d | 2017-04-28 04:44:38 -0500 | [diff] [blame] | 45 | expectedTable.data.entry_size = sizeof(pnor_partition); |
Andrew Jeffery | 742a1f6 | 2018-03-02 09:26:03 +1030 | [diff] [blame] | 46 | expectedTable.data.entry_count = 1; |
Andrew Jeffery | 9ecef79 | 2018-02-21 17:13:20 +1030 | [diff] [blame] | 47 | expectedTable.data.block_size = BLOCK_SIZE; |
Deepak Kodihalli | d1d7930 | 2017-07-11 23:01:39 -0500 | [diff] [blame] | 48 | expectedTable.data.block_count = |
Andrew Jeffery | 9ecef79 | 2018-02-21 17:13:20 +1030 | [diff] [blame] | 49 | (PNOR_SIZE) / expectedTable.data.block_size; |
Deepak Kodihalli | 393821d | 2017-04-28 04:44:38 -0500 | [diff] [blame] | 50 | expectedTable.checksum = |
| 51 | openpower::virtual_pnor::details::checksum(expectedTable.data); |
| 52 | |
| 53 | pnor_partition expectedPartition{}; |
| 54 | strcpy(expectedPartition.data.name, partitionName); |
Andrew Jeffery | 742a1f6 | 2018-03-02 09:26:03 +1030 | [diff] [blame] | 55 | expectedPartition.data.base = 0; |
| 56 | expectedPartition.data.size = 1; |
| 57 | expectedPartition.data.actual = 0x1000; |
Deepak Kodihalli | 393821d | 2017-04-28 04:44:38 -0500 | [diff] [blame] | 58 | 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 Kodihalli | e8b0e8a | 2017-07-12 10:01:31 -0500 | [diff] [blame] | 64 | expectedPartition.data.user.data[1] |= PARTITION_VERSION_CHECK_SHA512; |
Deepak Kodihalli | 393821d | 2017-04-28 04:44:38 -0500 | [diff] [blame] | 65 | expectedPartition.checksum = |
| 66 | openpower::virtual_pnor::details::checksum(expectedPartition.data); |
| 67 | |
| 68 | const pnor_partition_table& result = table.getNativeTable(); |
| 69 | |
Deepak Kodihalli | 393821d | 2017-04-28 04:44:38 -0500 | [diff] [blame] | 70 | 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 Jeffery | 742a1f6 | 2018-03-02 09:26:03 +1030 | [diff] [blame] | 77 | const pnor_partition& first = table.partition(0); |
Deepak Kodihalli | 393821d | 2017-04-28 04:44:38 -0500 | [diff] [blame] | 78 | rc = memcmp(&first, &result.partitions[0], sizeof(pnor_partition)); |
| 79 | assert(rc == 0); |
| 80 | |
| 81 | return 0; |
| 82 | } |