Andrew Jeffery | 7eed6de | 2018-03-01 12:11:23 +1030 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // Copyright (C) 2018 IBM Corp. |
Andrew Jeffery | 7eed6de | 2018-03-01 12:11:23 +1030 | [diff] [blame] | 3 | #include "config.h" |
William A. Kennington III | d5f1d40 | 2018-10-11 13:55:04 -0700 | [diff] [blame^] | 4 | |
Andrew Jeffery | 53c21aa | 2018-03-26 11:56:16 +1030 | [diff] [blame] | 5 | #include "vpnor/pnor_partition_table.hpp" |
Andrew Jeffery | 7eed6de | 2018-03-01 12:11:23 +1030 | [diff] [blame] | 6 | |
William A. Kennington III | d5f1d40 | 2018-10-11 13:55:04 -0700 | [diff] [blame^] | 7 | #include <assert.h> |
| 8 | #include <string.h> |
| 9 | #include <sys/mman.h> |
| 10 | |
Andrew Jeffery | 7eed6de | 2018-03-01 12:11:23 +1030 | [diff] [blame] | 11 | extern "C" { |
| 12 | #include "test/mbox.h" |
| 13 | #include "test/system.h" |
| 14 | } |
| 15 | |
Andrew Jeffery | 30bcf84 | 2018-03-26 12:13:20 +1030 | [diff] [blame] | 16 | #include "vpnor/test/tmpd.hpp" |
Andrew Jeffery | 7eed6de | 2018-03-01 12:11:23 +1030 | [diff] [blame] | 17 | |
| 18 | static constexpr auto BLOCK_SIZE = 4 * 1024; |
| 19 | static constexpr auto PNOR_SIZE = 64 * 1024 * 1024; |
| 20 | static constexpr auto MEM_SIZE = BLOCK_SIZE * 2; |
| 21 | static constexpr auto ERASE_SIZE = BLOCK_SIZE; |
| 22 | static constexpr auto N_WINDOWS = 1; |
| 23 | static constexpr auto WINDOW_SIZE = BLOCK_SIZE; |
| 24 | static constexpr auto TOC_PART_SIZE = BLOCK_SIZE; |
| 25 | |
| 26 | const std::string toc[] = { |
| 27 | "partition00=part,00000000,00001000,80,READONLY", |
| 28 | "partition01=ONE,00001000,00002000,80,READWRITE", |
| 29 | }; |
| 30 | |
| 31 | static const uint8_t get_info[] = {0x02, 0x00, 0x02, 0x00, 0x00, 0x00, |
| 32 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 33 | 0x00, 0x00, 0x00, 0x00}; |
| 34 | |
| 35 | /* Request access to the ToC base for one block */ |
| 36 | static const uint8_t create_read_window[] = {0x04, 0x01, 0x00, 0x00, 0x01, 0x00, |
| 37 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 38 | 0x00, 0x00, 0x00, 0x00}; |
| 39 | |
| 40 | /* Expect a response containing the ToC in one block */ |
| 41 | static const uint8_t response[] = { |
| 42 | 0x04, 0x01, 0xfe, 0xff, 0x01, 0x00, 0x00, |
| 43 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, |
| 44 | }; |
| 45 | |
| 46 | int main() |
| 47 | { |
| 48 | namespace test = openpower::virtual_pnor::test; |
| 49 | namespace vpnor = openpower::virtual_pnor; |
| 50 | |
| 51 | struct mbox_context* ctx; |
| 52 | int rc; |
| 53 | |
| 54 | system_set_reserved_size(MEM_SIZE); |
| 55 | system_set_mtd_sizes(PNOR_SIZE, ERASE_SIZE); |
| 56 | |
| 57 | ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE); |
| 58 | test::VpnorRoot root(ctx, toc, BLOCK_SIZE); |
Andrew Jeffery | 742a1f6 | 2018-03-02 09:26:03 +1030 | [diff] [blame] | 59 | vpnor::partition::Table table(ctx); |
Andrew Jeffery | 7eed6de | 2018-03-01 12:11:23 +1030 | [diff] [blame] | 60 | |
| 61 | /* Make sure the ToC exactly fits in the space allocated for it */ |
| 62 | assert(table.capacity() == TOC_PART_SIZE); |
| 63 | |
Andrew Jeffery | 742a1f6 | 2018-03-02 09:26:03 +1030 | [diff] [blame] | 64 | init_vpnor_from_paths(ctx); |
Andrew Jeffery | 7eed6de | 2018-03-01 12:11:23 +1030 | [diff] [blame] | 65 | |
| 66 | rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info)); |
| 67 | assert(rc == 1); |
| 68 | |
| 69 | rc = mbox_command_dispatch(ctx, create_read_window, |
| 70 | sizeof(create_read_window)); |
| 71 | assert(rc == 1); |
| 72 | |
| 73 | rc = mbox_cmp(ctx, response, sizeof(response)); |
| 74 | assert(rc == 0); |
| 75 | |
| 76 | /* Ensure our partition table is present and as expected */ |
| 77 | const pnor_partition_table& toc = table.getHostTable(); |
| 78 | rc = memcmp(ctx->mem, &toc, table.size()); |
| 79 | assert(rc == 0); |
| 80 | |
| 81 | return 0; |
| 82 | } |