| Andrew Jeffery | 8998575 | 2018-11-13 15:17:30 +1030 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 | 
|  | 2 | // Copyright (C) 2018 IBM Corp. | 
|  | 3 | #include "config.h" | 
|  | 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 | 8998575 | 2018-11-13 15:17:30 +1030 | [diff] [blame] | 11 | #include "vpnor/pnor_partition_table.hpp" | 
| Andrew Jeffery | 035ad76 | 2019-03-18 13:02:01 +1030 | [diff] [blame^] | 12 | #include "vpnor/test/tmpd.hpp" | 
| Andrew Jeffery | 8998575 | 2018-11-13 15:17:30 +1030 | [diff] [blame] | 13 |  | 
| Andrew Jeffery | 8998575 | 2018-11-13 15:17:30 +1030 | [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 | 8998575 | 2018-11-13 15:17:30 +1030 | [diff] [blame] | 19 | static constexpr auto BLOCK_SIZE = 4 * 1024; | 
|  | 20 | static constexpr auto PNOR_SIZE = 2 * BLOCK_SIZE; | 
|  | 21 | static constexpr auto MEM_SIZE = BLOCK_SIZE; | 
|  | 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,READWRITE", | 
|  | 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 | static const uint8_t write_toc[] = {0x06, 0x01, 0x00, 0x00, 0x01, 0x00, | 
|  | 37 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
|  | 38 | 0x00, 0x00, 0x00, 0x00}; | 
|  | 39 |  | 
|  | 40 | static const uint8_t erase_toc[] = {0x0a, 0x02, 0x00, 0x00, 0x01, 0x00, | 
|  | 41 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
|  | 42 | 0x00, 0x00, 0x00, 0x00}; | 
|  | 43 |  | 
|  | 44 | static const uint8_t read_one[] = {0x04, 0x03, 0x01, 0x00, 0x01, 0x00, | 
|  | 45 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
|  | 46 | 0x00, 0x00, 0x00, 0x00}; | 
|  | 47 |  | 
|  | 48 | static const uint8_t read_toc[] = {0x04, 0x04, 0x00, 0x00, 0x01, 0x00, | 
|  | 49 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 
|  | 50 | 0x00, 0x00, 0x00, 0x00}; | 
|  | 51 |  | 
|  | 52 | int main() | 
|  | 53 | { | 
|  | 54 | namespace test = openpower::virtual_pnor::test; | 
|  | 55 | namespace vpnor = openpower::virtual_pnor; | 
|  | 56 |  | 
|  | 57 | struct mbox_context* ctx; | 
|  | 58 | int rc; | 
|  | 59 |  | 
|  | 60 | void* erased; | 
|  | 61 |  | 
|  | 62 | erased = malloc(BLOCK_SIZE); | 
|  | 63 | assert(erased); | 
|  | 64 |  | 
|  | 65 | memset(erased, 0xff, BLOCK_SIZE); | 
|  | 66 |  | 
|  | 67 | system_set_reserved_size(MEM_SIZE); | 
|  | 68 | system_set_mtd_sizes(PNOR_SIZE, ERASE_SIZE); | 
|  | 69 |  | 
| Evan Lojewski | f1e547c | 2019-03-14 14:34:33 +1030 | [diff] [blame] | 70 | ctx = mbox_create_frontend_context(N_WINDOWS, WINDOW_SIZE); | 
|  | 71 | test::VpnorRoot root(&ctx->backend, toc, BLOCK_SIZE); | 
|  | 72 | vpnor::partition::Table table(&ctx->backend); | 
| Andrew Jeffery | 8998575 | 2018-11-13 15:17:30 +1030 | [diff] [blame] | 73 |  | 
|  | 74 | assert(table.capacity() == TOC_PART_SIZE); | 
|  | 75 |  | 
| Andrew Jeffery | 8998575 | 2018-11-13 15:17:30 +1030 | [diff] [blame] | 76 | rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info)); | 
|  | 77 | assert(rc == MBOX_R_SUCCESS); | 
|  | 78 |  | 
|  | 79 | rc = mbox_command_dispatch(ctx, write_toc, sizeof(write_toc)); | 
|  | 80 | assert(rc == MBOX_R_SUCCESS); | 
|  | 81 |  | 
|  | 82 | rc = mbox_command_dispatch(ctx, erase_toc, sizeof(erase_toc)); | 
|  | 83 | assert(rc == MBOX_R_SUCCESS); | 
|  | 84 |  | 
|  | 85 | rc = memcmp(ctx->mem, erased, BLOCK_SIZE); | 
|  | 86 | assert(rc == 0); | 
|  | 87 |  | 
|  | 88 | rc = mbox_command_dispatch(ctx, read_one, sizeof(read_one)); | 
|  | 89 | assert(rc == MBOX_R_SUCCESS); | 
|  | 90 |  | 
|  | 91 | rc = mbox_command_dispatch(ctx, read_toc, sizeof(read_toc)); | 
|  | 92 | assert(rc == MBOX_R_SUCCESS); | 
|  | 93 |  | 
|  | 94 | rc = memcmp(ctx->mem, erased, BLOCK_SIZE); | 
|  | 95 | assert(rc == 0); | 
|  | 96 |  | 
|  | 97 | free(erased); | 
|  | 98 |  | 
|  | 99 | return 0; | 
|  | 100 | } |