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 | 035ad76 | 2019-03-18 13:02:01 +1030 | [diff] [blame] | 5 | extern "C" { |
| 6 | #include "backend.h" |
| 7 | #include "test/mbox.h" |
| 8 | #include "test/system.h" |
| 9 | } |
| 10 | |
Andrew Jeffery | de08ca2 | 2019-03-18 13:23:46 +1030 | [diff] [blame] | 11 | #include "vpnor/table.hpp" |
Andrew Jeffery | 035ad76 | 2019-03-18 13:02:01 +1030 | [diff] [blame] | 12 | #include "vpnor/test/tmpd.hpp" |
Andrew Jeffery | 7eed6de | 2018-03-01 12:11:23 +1030 | [diff] [blame] | 13 | |
William A. Kennington III | d5f1d40 | 2018-10-11 13:55:04 -0700 | [diff] [blame] | 14 | #include <sys/mman.h> |
| 15 | |
Andrew Jeffery | 261f61a | 2019-03-14 09:57:28 +1030 | [diff] [blame] | 16 | #include <cassert> |
| 17 | #include <cstring> |
| 18 | |
Andrew Jeffery | 7eed6de | 2018-03-01 12:11:23 +1030 | [diff] [blame] | 19 | static constexpr auto BLOCK_SIZE = 4 * 1024; |
| 20 | static constexpr auto PNOR_SIZE = 64 * 1024 * 1024; |
| 21 | static constexpr auto MEM_SIZE = BLOCK_SIZE * 2; |
| 22 | static constexpr auto ERASE_SIZE = BLOCK_SIZE; |
| 23 | static constexpr auto N_WINDOWS = 1; |
| 24 | static constexpr auto WINDOW_SIZE = BLOCK_SIZE; |
| 25 | static constexpr auto TOC_PART_SIZE = BLOCK_SIZE; |
| 26 | |
| 27 | const std::string toc[] = { |
| 28 | "partition00=part,00000000,00001000,80,READONLY", |
| 29 | "partition01=ONE,00001000,00002000,80,READWRITE", |
| 30 | }; |
| 31 | |
| 32 | static const uint8_t get_info[] = {0x02, 0x00, 0x02, 0x00, 0x00, 0x00, |
| 33 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 34 | 0x00, 0x00, 0x00, 0x00}; |
| 35 | |
| 36 | /* Request access to the ToC base for one block */ |
| 37 | static const uint8_t create_read_window[] = {0x04, 0x01, 0x00, 0x00, 0x01, 0x00, |
| 38 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 39 | 0x00, 0x00, 0x00, 0x00}; |
| 40 | |
| 41 | /* Expect a response containing the ToC in one block */ |
| 42 | static const uint8_t response[] = { |
| 43 | 0x04, 0x01, 0xfe, 0xff, 0x01, 0x00, 0x00, |
| 44 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, |
| 45 | }; |
| 46 | |
| 47 | int main() |
| 48 | { |
| 49 | namespace test = openpower::virtual_pnor::test; |
| 50 | namespace vpnor = openpower::virtual_pnor; |
| 51 | |
| 52 | struct mbox_context* ctx; |
| 53 | int rc; |
| 54 | |
| 55 | system_set_reserved_size(MEM_SIZE); |
| 56 | system_set_mtd_sizes(PNOR_SIZE, ERASE_SIZE); |
| 57 | |
Evan Lojewski | f1e547c | 2019-03-14 14:34:33 +1030 | [diff] [blame] | 58 | ctx = mbox_create_frontend_context(N_WINDOWS, WINDOW_SIZE); |
| 59 | test::VpnorRoot root(&ctx->backend, toc, BLOCK_SIZE); |
| 60 | vpnor::partition::Table table(&ctx->backend); |
Andrew Jeffery | 7eed6de | 2018-03-01 12:11:23 +1030 | [diff] [blame] | 61 | |
| 62 | /* Make sure the ToC exactly fits in the space allocated for it */ |
| 63 | assert(table.capacity() == TOC_PART_SIZE); |
| 64 | |
Andrew Jeffery | 7eed6de | 2018-03-01 12:11:23 +1030 | [diff] [blame] | 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 | } |