Andrew Jeffery | acee683 | 2018-02-21 22:17:08 +1030 | [diff] [blame] | 1 | /* |
| 2 | * MBox Daemon Test File |
| 3 | * |
| 4 | * Copyright 2018 IBM |
| 5 | * |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | * |
| 18 | */ |
| 19 | |
Ratan Gupta | 3214b51 | 2017-05-11 08:58:19 +0530 | [diff] [blame] | 20 | #include "config.h" |
| 21 | #include "mboxd_pnor_partition_table.h" |
| 22 | |
| 23 | extern "C" { |
| 24 | #include "test/mbox.h" |
| 25 | #include "test/system.h" |
| 26 | } |
| 27 | |
| 28 | #include <assert.h> |
| 29 | #include <string.h> |
| 30 | |
| 31 | #include <vector> |
| 32 | #include <fstream> |
| 33 | #include <experimental/filesystem> |
| 34 | |
Andrew Jeffery | 0b657f4 | 2018-02-22 12:04:02 +1030 | [diff] [blame] | 35 | #include "test/vpnor/tmpd.hpp" |
| 36 | |
Adriana Kobylak | 2ad2132 | 2017-11-28 14:59:19 -0600 | [diff] [blame] | 37 | // A read window assumes that the toc is located at offset 0, |
| 38 | // so create dummy partition at arbitrary offset 0x100. |
Andrew Jeffery | 0b657f4 | 2018-02-22 12:04:02 +1030 | [diff] [blame] | 39 | const std::string toc[] = { |
| 40 | "partition01=HBB,00000100,0001000,ECC,PRESERVED", |
| 41 | }; |
| 42 | |
Andrew Jeffery | f34db31 | 2018-03-09 15:27:03 +1030 | [diff] [blame] | 43 | uint8_t data[8] = {0xaa, 0x55, 0xaa, 0x66, 0x77, 0x88, 0x99, 0xab}; |
Ratan Gupta | 3214b51 | 2017-05-11 08:58:19 +0530 | [diff] [blame] | 44 | |
Andrew Jeffery | f34db31 | 2018-03-09 15:27:03 +1030 | [diff] [blame] | 45 | #define BLOCK_SIZE 4096 |
| 46 | #define MEM_SIZE (BLOCK_SIZE * 2) |
| 47 | #define ERASE_SIZE BLOCK_SIZE |
| 48 | #define N_WINDOWS 1 |
Ratan Gupta | 3214b51 | 2017-05-11 08:58:19 +0530 | [diff] [blame] | 49 | #define WINDOW_SIZE BLOCK_SIZE |
| 50 | |
Andrew Jeffery | f34db31 | 2018-03-09 15:27:03 +1030 | [diff] [blame] | 51 | static const uint8_t get_info[] = {0x02, 0x00, 0x02, 0x00, 0x00, 0x00, |
| 52 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 53 | 0x00, 0x00, 0x00, 0x00}; |
Andrew Jeffery | 0b657f4 | 2018-02-22 12:04:02 +1030 | [diff] [blame] | 54 | |
Adriana Kobylak | 2ad2132 | 2017-11-28 14:59:19 -0600 | [diff] [blame] | 55 | // offset 0x100 and size 6 |
Andrew Jeffery | f34db31 | 2018-03-09 15:27:03 +1030 | [diff] [blame] | 56 | static const uint8_t create_read_window[] = {0x04, 0x01, 0x01, 0x00, 0x06, 0x00, |
| 57 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 58 | 0x00, 0x00, 0x00, 0x00}; |
Ratan Gupta | 3214b51 | 2017-05-11 08:58:19 +0530 | [diff] [blame] | 59 | |
Andrew Jeffery | f34db31 | 2018-03-09 15:27:03 +1030 | [diff] [blame] | 60 | static const uint8_t response[] = {0x04, 0x01, 0xfe, 0xff, 0x01, 0x00, 0x01, |
| 61 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}; |
Ratan Gupta | 3214b51 | 2017-05-11 08:58:19 +0530 | [diff] [blame] | 62 | |
| 63 | namespace fs = std::experimental::filesystem; |
Andrew Jeffery | 0b657f4 | 2018-02-22 12:04:02 +1030 | [diff] [blame] | 64 | namespace test = openpower::virtual_pnor::test; |
Ratan Gupta | 3214b51 | 2017-05-11 08:58:19 +0530 | [diff] [blame] | 65 | |
| 66 | int main() |
| 67 | { |
Andrew Jeffery | 32476cb | 2018-02-22 15:34:17 +1030 | [diff] [blame^] | 68 | struct mbox_context *ctx; |
Ratan Gupta | 3214b51 | 2017-05-11 08:58:19 +0530 | [diff] [blame] | 69 | |
| 70 | system_set_reserved_size(MEM_SIZE); |
| 71 | system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE); |
| 72 | |
Andrew Jeffery | 32476cb | 2018-02-22 15:34:17 +1030 | [diff] [blame^] | 73 | ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE); |
Ratan Gupta | 3214b51 | 2017-05-11 08:58:19 +0530 | [diff] [blame] | 74 | |
Andrew Jeffery | 32476cb | 2018-02-22 15:34:17 +1030 | [diff] [blame^] | 75 | test::VpnorRoot root(ctx, toc, BLOCK_SIZE); |
| 76 | root.write("HBB", data, sizeof(data)); |
| 77 | |
| 78 | vpnor_create_partition_table_from_path(ctx, root.ro().c_str()); |
Ratan Gupta | 3214b51 | 2017-05-11 08:58:19 +0530 | [diff] [blame] | 79 | |
| 80 | int rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info)); |
| 81 | assert(rc == 1); |
| 82 | |
| 83 | // send the request for partition1 |
| 84 | rc = mbox_command_dispatch(ctx, create_read_window, |
Andrew Jeffery | f34db31 | 2018-03-09 15:27:03 +1030 | [diff] [blame] | 85 | sizeof(create_read_window)); |
Ratan Gupta | 3214b51 | 2017-05-11 08:58:19 +0530 | [diff] [blame] | 86 | assert(rc == 1); |
| 87 | |
| 88 | rc = mbox_cmp(ctx, response, sizeof(response)); |
| 89 | assert(rc == 0); |
| 90 | |
| 91 | // Compare the reserved memory to the pnor |
| 92 | rc = memcmp(ctx->mem, data, 6); |
| 93 | assert(rc == 0); |
| 94 | |
Andrew Jeffery | f34db31 | 2018-03-09 15:27:03 +1030 | [diff] [blame] | 95 | // TODO: Add few more test cases for read from multiple partitions(PRSV/RW) |
Ratan Gupta | 6a98e18 | 2017-06-06 15:04:23 +0530 | [diff] [blame] | 96 | // Read beyond the partition file size. |
| 97 | // openbmc/openbmc#1868 |
| 98 | |
Ratan Gupta | 3214b51 | 2017-05-11 08:58:19 +0530 | [diff] [blame] | 99 | return rc; |
| 100 | } |