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" |
| 8 | #include "pnor_partition_table.hpp" |
| 9 | |
| 10 | extern "C" { |
| 11 | #include "test/mbox.h" |
| 12 | #include "test/system.h" |
| 13 | } |
| 14 | |
| 15 | #include "test/vpnor/tmpd.hpp" |
| 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); |
| 58 | vpnor::partition::Table table(root.ro(), BLOCK_SIZE, PNOR_SIZE); |
| 59 | |
| 60 | /* Make sure the ToC exactly fits in the space allocated for it */ |
| 61 | assert(table.capacity() == TOC_PART_SIZE); |
| 62 | |
| 63 | vpnor_create_partition_table_from_path(ctx, root.ro().c_str()); |
| 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 | } |