Andrew Jeffery | 8a0efd5 | 2018-11-13 17:13:08 +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" |
Andrew Jeffery | dec59b4 | 2019-03-18 13:09:59 +1030 | [diff] [blame] | 9 | #include "vpnor/ffs.h" |
Andrew Jeffery | 035ad76 | 2019-03-18 13:02:01 +1030 | [diff] [blame] | 10 | } |
| 11 | |
Andrew Jeffery | de08ca2 | 2019-03-18 13:23:46 +1030 | [diff] [blame] | 12 | #include "vpnor/table.hpp" |
Andrew Jeffery | 035ad76 | 2019-03-18 13:02:01 +1030 | [diff] [blame] | 13 | #include "vpnor/test/tmpd.hpp" |
Andrew Jeffery | 8a0efd5 | 2018-11-13 17:13:08 +1030 | [diff] [blame] | 14 | |
Andrew Jeffery | 8a0efd5 | 2018-11-13 17:13:08 +1030 | [diff] [blame] | 15 | #include <endian.h> |
Andrew Jeffery | 8a0efd5 | 2018-11-13 17:13:08 +1030 | [diff] [blame] | 16 | #include <sys/mman.h> |
| 17 | |
Andrew Jeffery | 261f61a | 2019-03-14 09:57:28 +1030 | [diff] [blame] | 18 | #include <cassert> |
| 19 | #include <cstring> |
| 20 | |
Andrew Jeffery | 8a0efd5 | 2018-11-13 17:13:08 +1030 | [diff] [blame] | 21 | static constexpr auto BLOCK_SIZE = 4 * 1024; |
| 22 | static constexpr auto PNOR_SIZE = BLOCK_SIZE; |
| 23 | static constexpr auto MEM_SIZE = BLOCK_SIZE; |
| 24 | static constexpr auto ERASE_SIZE = BLOCK_SIZE; |
| 25 | static constexpr auto N_WINDOWS = 1; |
| 26 | static constexpr auto WINDOW_SIZE = BLOCK_SIZE; |
| 27 | static constexpr auto TOC_PART_SIZE = BLOCK_SIZE; |
| 28 | |
| 29 | const std::string toc[] = { |
| 30 | "partition00=part,00000000,00001000,80,READWRITE", |
| 31 | "partition01=ONE,00001000,00002000,80,READWRITE", |
| 32 | }; |
| 33 | |
| 34 | static const uint8_t get_info[] = {0x02, 0x00, 0x02, 0x00, 0x00, 0x00, |
| 35 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 36 | 0x00, 0x00, 0x00, 0x00}; |
| 37 | |
| 38 | static const uint8_t read_toc[] = {0x04, 0x04, 0x00, 0x00, 0x01, 0x00, |
| 39 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 40 | 0x00, 0x00, 0x00, 0x00}; |
| 41 | |
| 42 | int main() |
| 43 | { |
| 44 | namespace test = openpower::virtual_pnor::test; |
| 45 | namespace vpnor = openpower::virtual_pnor; |
| 46 | |
| 47 | struct pnor_partition_table* htable; |
| 48 | struct mbox_context* ctx; |
| 49 | uint32_t perms; |
| 50 | int rc; |
| 51 | |
| 52 | system_set_reserved_size(MEM_SIZE); |
| 53 | system_set_mtd_sizes(PNOR_SIZE, ERASE_SIZE); |
| 54 | |
Evan Lojewski | f1e547c | 2019-03-14 14:34:33 +1030 | [diff] [blame] | 55 | ctx = mbox_create_frontend_context(N_WINDOWS, WINDOW_SIZE); |
| 56 | test::VpnorRoot root(&ctx->backend, toc, BLOCK_SIZE); |
| 57 | vpnor::partition::Table table(&ctx->backend); |
Andrew Jeffery | 8a0efd5 | 2018-11-13 17:13:08 +1030 | [diff] [blame] | 58 | |
| 59 | assert(table.capacity() == TOC_PART_SIZE); |
| 60 | |
Andrew Jeffery | 8a0efd5 | 2018-11-13 17:13:08 +1030 | [diff] [blame] | 61 | rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info)); |
| 62 | assert(rc == MBOX_R_SUCCESS); |
| 63 | |
| 64 | rc = mbox_command_dispatch(ctx, read_toc, sizeof(read_toc)); |
| 65 | assert(rc == MBOX_R_SUCCESS); |
| 66 | |
| 67 | htable = reinterpret_cast<struct pnor_partition_table*>(ctx->mem); |
| 68 | perms = be32toh(htable->partitions[0].data.user.data[1]); |
| 69 | assert(perms & PARTITION_READONLY); |
| 70 | |
| 71 | htable = reinterpret_cast<struct pnor_partition_table*>(ctx->mem); |
| 72 | perms = be32toh(htable->partitions[1].data.user.data[1]); |
| 73 | assert(!(perms & PARTITION_READONLY)); |
| 74 | |
| 75 | return 0; |
| 76 | } |