Andrew Jeffery | de90fdc | 2018-02-23 15:59:46 +1030 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // Copyright (C) 2018 IBM Corp. |
Andrew Jeffery | acee683 | 2018-02-21 22:17:08 +1030 | [diff] [blame] | 3 | |
William A. Kennington III | d5f1d40 | 2018-10-11 13:55:04 -0700 | [diff] [blame] | 4 | #include "config.h" |
| 5 | |
Ratan Gupta | 3214b51 | 2017-05-11 08:58:19 +0530 | [diff] [blame] | 6 | extern "C" { |
| 7 | #include "test/mbox.h" |
| 8 | #include "test/system.h" |
| 9 | } |
| 10 | |
Andrew Jeffery | 30bcf84 | 2018-03-26 12:13:20 +1030 | [diff] [blame] | 11 | #include "vpnor/test/tmpd.hpp" |
Andrew Jeffery | 0b657f4 | 2018-02-22 12:04:02 +1030 | [diff] [blame] | 12 | |
Andrew Jeffery | 261f61a | 2019-03-14 09:57:28 +1030 | [diff] [blame] | 13 | #include <cassert> |
| 14 | #include <cstring> |
| 15 | #include <experimental/filesystem> |
| 16 | #include <fstream> |
| 17 | #include <vector> |
| 18 | |
Andrew Jeffery | f4bc335 | 2019-03-18 12:09:48 +1030 | [diff] [blame] | 19 | #include "vpnor/backend.h" |
Andrew Jeffery | 261f61a | 2019-03-14 09:57:28 +1030 | [diff] [blame] | 20 | |
Adriana Kobylak | 2ad2132 | 2017-11-28 14:59:19 -0600 | [diff] [blame] | 21 | // A read window assumes that the toc is located at offset 0, |
Andrew Jeffery | 8de4c13 | 2018-02-23 17:50:51 +1030 | [diff] [blame] | 22 | // so create dummy partition at arbitrary offset 0x1000. |
Andrew Jeffery | 0b657f4 | 2018-02-22 12:04:02 +1030 | [diff] [blame] | 23 | const std::string toc[] = { |
Andrew Jeffery | 8de4c13 | 2018-02-23 17:50:51 +1030 | [diff] [blame] | 24 | "partition01=HBB,00001000,00002000,80,ECC,READONLY", |
Andrew Jeffery | 0b657f4 | 2018-02-22 12:04:02 +1030 | [diff] [blame] | 25 | }; |
| 26 | |
Andrew Jeffery | 8de4c13 | 2018-02-23 17:50:51 +1030 | [diff] [blame] | 27 | static const uint8_t data[8] = {0xaa, 0x55, 0xaa, 0x66, 0x77, 0x88, 0x99, 0xab}; |
Ratan Gupta | 3214b51 | 2017-05-11 08:58:19 +0530 | [diff] [blame] | 28 | |
Andrew Jeffery | 8de4c13 | 2018-02-23 17:50:51 +1030 | [diff] [blame] | 29 | static const auto BLOCK_SIZE = 4096; |
| 30 | static const auto MEM_SIZE = BLOCK_SIZE * 2; |
| 31 | static const auto ERASE_SIZE = BLOCK_SIZE; |
| 32 | static const auto N_WINDOWS = 1; |
| 33 | static const auto WINDOW_SIZE = BLOCK_SIZE; |
Ratan Gupta | 3214b51 | 2017-05-11 08:58:19 +0530 | [diff] [blame] | 34 | |
Andrew Jeffery | f34db31 | 2018-03-09 15:27:03 +1030 | [diff] [blame] | 35 | static const uint8_t get_info[] = {0x02, 0x00, 0x02, 0x00, 0x00, 0x00, |
| 36 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 37 | 0x00, 0x00, 0x00, 0x00}; |
Andrew Jeffery | 0b657f4 | 2018-02-22 12:04:02 +1030 | [diff] [blame] | 38 | |
Adriana Kobylak | 2ad2132 | 2017-11-28 14:59:19 -0600 | [diff] [blame] | 39 | // offset 0x100 and size 6 |
Andrew Jeffery | 8de4c13 | 2018-02-23 17:50:51 +1030 | [diff] [blame] | 40 | static const uint8_t create_read_window[] = {0x04, 0x01, 0x01, 0x00, 0x01, 0x00, |
Andrew Jeffery | f34db31 | 2018-03-09 15:27:03 +1030 | [diff] [blame] | 41 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 42 | 0x00, 0x00, 0x00, 0x00}; |
Ratan Gupta | 3214b51 | 2017-05-11 08:58:19 +0530 | [diff] [blame] | 43 | |
Andrew Jeffery | f34db31 | 2018-03-09 15:27:03 +1030 | [diff] [blame] | 44 | static const uint8_t response[] = {0x04, 0x01, 0xfe, 0xff, 0x01, 0x00, 0x01, |
| 45 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}; |
Ratan Gupta | 3214b51 | 2017-05-11 08:58:19 +0530 | [diff] [blame] | 46 | |
Andrew Jeffery | 0b657f4 | 2018-02-22 12:04:02 +1030 | [diff] [blame] | 47 | namespace test = openpower::virtual_pnor::test; |
Ratan Gupta | 3214b51 | 2017-05-11 08:58:19 +0530 | [diff] [blame] | 48 | |
| 49 | int main() |
| 50 | { |
William A. Kennington III | d5f1d40 | 2018-10-11 13:55:04 -0700 | [diff] [blame] | 51 | struct mbox_context* ctx; |
Ratan Gupta | 3214b51 | 2017-05-11 08:58:19 +0530 | [diff] [blame] | 52 | |
| 53 | system_set_reserved_size(MEM_SIZE); |
| 54 | system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE); |
| 55 | |
Evan Lojewski | f1e547c | 2019-03-14 14:34:33 +1030 | [diff] [blame] | 56 | ctx = mbox_create_frontend_context(N_WINDOWS, WINDOW_SIZE); |
Ratan Gupta | 3214b51 | 2017-05-11 08:58:19 +0530 | [diff] [blame] | 57 | |
Evan Lojewski | f1e547c | 2019-03-14 14:34:33 +1030 | [diff] [blame] | 58 | test::VpnorRoot root(&ctx->backend, toc, BLOCK_SIZE); |
Andrew Jeffery | 32476cb | 2018-02-22 15:34:17 +1030 | [diff] [blame] | 59 | root.write("HBB", data, sizeof(data)); |
| 60 | |
Ratan Gupta | 3214b51 | 2017-05-11 08:58:19 +0530 | [diff] [blame] | 61 | int rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info)); |
| 62 | assert(rc == 1); |
| 63 | |
| 64 | // send the request for partition1 |
| 65 | rc = mbox_command_dispatch(ctx, create_read_window, |
Andrew Jeffery | f34db31 | 2018-03-09 15:27:03 +1030 | [diff] [blame] | 66 | sizeof(create_read_window)); |
Ratan Gupta | 3214b51 | 2017-05-11 08:58:19 +0530 | [diff] [blame] | 67 | assert(rc == 1); |
| 68 | |
| 69 | rc = mbox_cmp(ctx, response, sizeof(response)); |
| 70 | assert(rc == 0); |
| 71 | |
| 72 | // Compare the reserved memory to the pnor |
| 73 | rc = memcmp(ctx->mem, data, 6); |
| 74 | assert(rc == 0); |
| 75 | |
Ratan Gupta | 3214b51 | 2017-05-11 08:58:19 +0530 | [diff] [blame] | 76 | return rc; |
| 77 | } |