Andrew Jeffery | 912c9bd | 2018-03-23 13:31:46 +1030 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // Copyright (C) 2018 IBM Corp. |
| 3 | |
| 4 | #include <assert.h> |
| 5 | #include <experimental/filesystem> |
| 6 | #include <fstream> |
| 7 | #include <string.h> |
| 8 | #include <vector> |
| 9 | |
| 10 | #include "config.h" |
Andrew Jeffery | 53c21aa | 2018-03-26 11:56:16 +1030 | [diff] [blame] | 11 | #include "vpnor/mboxd_pnor_partition_table.h" |
Andrew Jeffery | 912c9bd | 2018-03-23 13:31:46 +1030 | [diff] [blame] | 12 | |
| 13 | extern "C" { |
| 14 | #include "test/mbox.h" |
| 15 | #include "test/system.h" |
| 16 | } |
| 17 | |
Andrew Jeffery | 30bcf84 | 2018-03-26 12:13:20 +1030 | [diff] [blame] | 18 | #include "vpnor/test/tmpd.hpp" |
Andrew Jeffery | 912c9bd | 2018-03-23 13:31:46 +1030 | [diff] [blame] | 19 | |
| 20 | static const auto BLOCK_SIZE = 4096; |
| 21 | static const auto ERASE_SIZE = BLOCK_SIZE; |
| 22 | static const auto WINDOW_SIZE = 16 * BLOCK_SIZE; |
| 23 | static const auto N_WINDOWS = 2; |
| 24 | static const auto MEM_SIZE = N_WINDOWS * WINDOW_SIZE; |
| 25 | |
| 26 | const std::string toc[] = { |
| 27 | "partition01=ONE,00001000,00011000,80,ECC,READONLY", |
| 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 | namespace test = openpower::virtual_pnor::test; |
| 35 | |
| 36 | int main() |
| 37 | { |
| 38 | uint8_t request[] = {0x04, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, |
| 39 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; |
| 40 | |
| 41 | uint8_t response[] = {0x04, 0x01, 0xe0, 0xff, 0x10, 0x00, 0x01, |
| 42 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}; |
| 43 | |
| 44 | struct mbox_context *ctx; |
| 45 | |
| 46 | system_set_reserved_size(MEM_SIZE); |
| 47 | system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE); |
| 48 | |
| 49 | ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE); |
| 50 | test::VpnorRoot root(ctx, toc, BLOCK_SIZE); |
| 51 | init_vpnor_from_paths(ctx); |
| 52 | |
| 53 | int rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info)); |
| 54 | assert(rc == 1); |
| 55 | |
| 56 | for (int i = 1; i < (0x10000 / BLOCK_SIZE); i++) |
| 57 | { |
| 58 | /* Update the requested offset */ |
| 59 | put_u16(&request[2], i); |
| 60 | |
| 61 | /* |
| 62 | * Reuse the offset as a sequence number, because it's unique. Request |
| 63 | * and response have the same sequence number |
| 64 | */ |
| 65 | request[1] = i; |
| 66 | response[1] = i; |
| 67 | |
| 68 | rc = mbox_command_dispatch(ctx, request, sizeof(request)); |
| 69 | assert(rc == 1); |
| 70 | |
| 71 | /* Check that it maps to the same window each time */ |
| 72 | rc = mbox_cmp(ctx, response, sizeof(response)); |
| 73 | assert(rc == 0); |
| 74 | } |
| 75 | |
| 76 | return 0; |
| 77 | } |