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