1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright (C) 2018 IBM Corp. 3 4 #include "config.h" 5 6 #include <assert.h> 7 #include <string.h> 8 9 #include "transport_mbox.h" 10 #include "vpnor/mboxd_pnor_partition_table.h" 11 12 extern "C" { 13 #include "test/mbox.h" 14 #include "test/system.h" 15 } 16 17 #include "vpnor/test/tmpd.hpp" 18 19 struct test_context 20 { 21 uint8_t seq; 22 struct mbox_context* ctx; 23 }; 24 25 // Configure the system and the paritions such that we eventually request a 26 // window that covers the last section of flash, but the remaining flash is 27 // smaller than the window size 28 static constexpr auto BLOCK_SIZE = 4096; 29 static constexpr auto ERASE_SIZE = BLOCK_SIZE; 30 static constexpr auto N_WINDOWS = 3; 31 static constexpr auto WINDOW_SIZE = 2 * BLOCK_SIZE; 32 static constexpr auto MEM_SIZE = N_WINDOWS * WINDOW_SIZE; 33 static constexpr auto PNOR_SIZE = (4 * BLOCK_SIZE); 34 35 const std::string toc[] = { 36 "partition01=ONE,00001000,00003000,80,ECC,READONLY", 37 }; 38 39 static const uint8_t get_info[] = {0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 40 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 41 0x00, 0x00, 0x00, 0x00}; 42 43 static constexpr auto MBOX_CREATE_READ_WINDOW = 4; 44 45 static int mbox_create_read_window(struct test_context* tctx, size_t offset, 46 size_t len) 47 { 48 union mbox_regs regs; 49 50 memset(®s, 0, sizeof(regs)); 51 regs.msg.command = MBOX_CREATE_READ_WINDOW; 52 regs.msg.seq = ++tctx->seq; 53 put_u16(®s.msg.args[0], offset); 54 put_u16(®s.msg.args[2], len); 55 56 return mbox_command_dispatch(tctx->ctx, regs.raw, sizeof(regs.raw)); 57 } 58 59 int main() 60 { 61 namespace test = openpower::virtual_pnor::test; 62 63 struct test_context _tctx = {0}, *tctx = &_tctx; 64 size_t len; 65 size_t pos; 66 int rc; 67 68 system_set_reserved_size(MEM_SIZE); 69 system_set_mtd_sizes(PNOR_SIZE, ERASE_SIZE); 70 71 tctx->ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE); 72 test::VpnorRoot root(tctx->ctx, toc, BLOCK_SIZE); 73 init_vpnor_from_paths(tctx->ctx); 74 75 rc = mbox_command_dispatch(tctx->ctx, get_info, sizeof(get_info)); 76 assert(rc == 1); 77 78 pos = 0; 79 while (pos < (PNOR_SIZE / BLOCK_SIZE)) 80 { 81 struct mbox_msg _msg, *msg = &_msg; 82 83 rc = mbox_create_read_window(tctx, pos, (WINDOW_SIZE / BLOCK_SIZE)); 84 assert(rc == 1); 85 86 mbox_rspcpy(tctx->ctx, msg); 87 88 len = get_u16(&msg->args[2]); 89 pos = get_u16(&msg->args[4]) + len; 90 } 91 92 return 0; 93 } 94