Andrew Jeffery | 5bfc986 | 2018-03-02 09:13:31 +1030 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // Copyright (C) 2018 IBM Corp. |
| 3 | |
| 4 | #include "config.h" |
Andrew Jeffery | 5bfc986 | 2018-03-02 09:13:31 +1030 | [diff] [blame] | 5 | |
Andrew Jeffery | 5bfc986 | 2018-03-02 09:13:31 +1030 | [diff] [blame] | 6 | extern "C" { |
Andrew Jeffery | 261f61a | 2019-03-14 09:57:28 +1030 | [diff] [blame] | 7 | #include "common.h" |
Andrew Jeffery | 5bfc986 | 2018-03-02 09:13:31 +1030 | [diff] [blame] | 8 | #include "test/mbox.h" |
| 9 | #include "test/system.h" |
| 10 | } |
| 11 | |
Andrew Jeffery | 30bcf84 | 2018-03-26 12:13:20 +1030 | [diff] [blame] | 12 | #include "vpnor/test/tmpd.hpp" |
Andrew Jeffery | 5bfc986 | 2018-03-02 09:13:31 +1030 | [diff] [blame] | 13 | |
Andrew Jeffery | 261f61a | 2019-03-14 09:57:28 +1030 | [diff] [blame] | 14 | #include <cassert> |
| 15 | |
Andrew Jeffery | f4bc335 | 2019-03-18 12:09:48 +1030 | [diff] [blame] | 16 | #include "vpnor/backend.h" |
Andrew Jeffery | 261f61a | 2019-03-14 09:57:28 +1030 | [diff] [blame] | 17 | |
Andrew Jeffery | 5bfc986 | 2018-03-02 09:13:31 +1030 | [diff] [blame] | 18 | static constexpr auto BLOCK_SIZE = 0x1000; |
| 19 | static constexpr auto ERASE_SIZE = BLOCK_SIZE; |
| 20 | static constexpr auto PART_SIZE = BLOCK_SIZE * 4; |
| 21 | static constexpr auto PATCH_SIZE = PART_SIZE / 2; |
| 22 | static constexpr auto N_WINDOWS = 2; |
| 23 | static constexpr auto WINDOW_SIZE = PART_SIZE * 8; |
| 24 | static constexpr auto MEM_SIZE = WINDOW_SIZE * N_WINDOWS; |
| 25 | static constexpr auto PNOR_SIZE = MEM_SIZE * 2; |
| 26 | |
| 27 | const std::string toc[] = { |
| 28 | "partition01=ONE,00001000,00005000,80,ECC,READONLY", |
| 29 | }; |
| 30 | |
| 31 | static const uint8_t get_info[] = {0x02, 0x00, 0x02, 0x00, 0x00, 0x00, |
| 32 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 33 | 0x00, 0x00, 0x00, 0x00}; |
| 34 | |
| 35 | static const uint8_t create_read_window[] = {0x04, 0x01, 0x01, 0x00, 0x04, 0x00, |
| 36 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 37 | 0x00, 0x00, 0x00, 0x00}; |
| 38 | |
| 39 | static const uint8_t response[] = {0x04, 0x01, 0xc0, 0xff, 0x04, 0x00, 0x01, |
| 40 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}; |
| 41 | |
| 42 | int main() |
| 43 | { |
| 44 | namespace test = openpower::virtual_pnor::test; |
| 45 | |
William A. Kennington III | d5f1d40 | 2018-10-11 13:55:04 -0700 | [diff] [blame] | 46 | struct mbox_context* ctx; |
Andrew Jeffery | 5bfc986 | 2018-03-02 09:13:31 +1030 | [diff] [blame] | 47 | |
| 48 | system_set_reserved_size(MEM_SIZE); |
| 49 | system_set_mtd_sizes(PNOR_SIZE, ERASE_SIZE); |
Evan Lojewski | f1e547c | 2019-03-14 14:34:33 +1030 | [diff] [blame] | 50 | ctx = mbox_create_frontend_context(N_WINDOWS, WINDOW_SIZE); |
| 51 | test::VpnorRoot root(&ctx->backend, toc, BLOCK_SIZE); |
Andrew Jeffery | 5bfc986 | 2018-03-02 09:13:31 +1030 | [diff] [blame] | 52 | |
| 53 | // PATCH_SIZE is smaller than the size of the partition we defined. This |
| 54 | // test ensures that mboxd will behave correctly when we request an offset |
| 55 | // that is beyond the size of the backing file, but is in the set of valid |
| 56 | // offsets for the partition as defined by the ToC. |
| 57 | std::vector<uint8_t> patch(PATCH_SIZE, 0xff); |
| 58 | root.patch("ONE", patch.data(), patch.size()); |
| 59 | |
Andrew Jeffery | 5bfc986 | 2018-03-02 09:13:31 +1030 | [diff] [blame] | 60 | int rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info)); |
| 61 | assert(rc == 1); |
| 62 | |
| 63 | rc = mbox_command_dispatch(ctx, create_read_window, |
| 64 | sizeof(create_read_window)); |
| 65 | assert(rc == 1); |
| 66 | |
| 67 | rc = mbox_cmp(ctx, response, sizeof(response)); |
| 68 | assert(rc == 0); |
| 69 | |
| 70 | return 0; |
| 71 | } |