1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright (C) 2018 IBM Corp. 3 4 #include "config.h" 5 6 extern "C" { 7 #include "test/mbox.h" 8 #include "test/system.h" 9 #include "transport_mbox.h" 10 } 11 12 #include "vpnor/test/tmpd.hpp" 13 14 #include <cassert> 15 #include <cstring> 16 17 #include "vpnor/mboxd_pnor_partition_table.h" 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_frontend_context(N_WINDOWS, WINDOW_SIZE); 72 test::VpnorRoot root(&tctx->ctx->backend, toc, BLOCK_SIZE); 73 74 rc = mbox_command_dispatch(tctx->ctx, get_info, sizeof(get_info)); 75 assert(rc == 1); 76 77 pos = 0; 78 while (pos < (PNOR_SIZE / BLOCK_SIZE)) 79 { 80 struct mbox_msg _msg, *msg = &_msg; 81 82 rc = mbox_create_read_window(tctx, pos, (WINDOW_SIZE / BLOCK_SIZE)); 83 assert(rc == 1); 84 85 mbox_rspcpy(tctx->ctx, msg); 86 87 len = get_u16(&msg->args[2]); 88 pos = get_u16(&msg->args[4]) + len; 89 } 90 91 return 0; 92 } 93