18cef63e3SAlvin Wang // SPDX-License-Identifier: Apache-2.0
28cef63e3SAlvin Wang // Copyright (C) 2018 IBM Corp.
38cef63e3SAlvin Wang 
48cef63e3SAlvin Wang #include "config.h"
58cef63e3SAlvin Wang 
68cef63e3SAlvin Wang extern "C" {
78cef63e3SAlvin Wang #include "test/mbox.h"
88cef63e3SAlvin Wang #include "test/system.h"
98cef63e3SAlvin Wang }
108cef63e3SAlvin Wang 
118cef63e3SAlvin Wang #include "vpnor/test/tmpd.hpp"
128cef63e3SAlvin Wang 
138cef63e3SAlvin Wang #include <cassert>
148cef63e3SAlvin Wang #include <cstring>
15*150be912SPatrick Williams #include <filesystem>
168cef63e3SAlvin Wang #include <fstream>
178cef63e3SAlvin Wang #include <vector>
188cef63e3SAlvin Wang 
198cef63e3SAlvin Wang #include "vpnor/backend.h"
208cef63e3SAlvin Wang 
218cef63e3SAlvin Wang // A read window assumes that the toc is located at offset 0,
228cef63e3SAlvin Wang // so create dummy partition at arbitrary offset 0x1000.
238cef63e3SAlvin Wang const std::string toc[] = {
248cef63e3SAlvin Wang     "partition01=HBB,00001000,00002000,80,ECC,READONLY",
258cef63e3SAlvin Wang     "partition05=DJVPD,0x000e5000,0x0022d000,00,ECC,PRESERVED",
268cef63e3SAlvin Wang };
278cef63e3SAlvin Wang 
288cef63e3SAlvin Wang static const auto BLOCK_SIZE = 4096;
298cef63e3SAlvin Wang static const auto ERASE_SIZE = BLOCK_SIZE;
308cef63e3SAlvin Wang static const auto N_WINDOWS = 1;
318cef63e3SAlvin Wang static const auto WINDOW_SIZE = 1024 * 1024;
328cef63e3SAlvin Wang static const auto MEM_SIZE = WINDOW_SIZE * 3;
338cef63e3SAlvin Wang 
348cef63e3SAlvin Wang static const uint8_t get_info[] = {0x02, 0x00, 0x02, 0x00, 0x00, 0x00,
358cef63e3SAlvin Wang                                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
368cef63e3SAlvin Wang                                    0x00, 0x00, 0x00, 0x00};
378cef63e3SAlvin Wang 
388cef63e3SAlvin Wang // Used to check the alignment
398cef63e3SAlvin Wang static const uint8_t create_read_window1[] = {
408cef63e3SAlvin Wang     0x04, 0x01, 0xe7, 0x00, 0x01, 0x00, 0x00, 0x00,
418cef63e3SAlvin Wang     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
428cef63e3SAlvin Wang 
438cef63e3SAlvin Wang static const uint8_t response1[] = {0x04, 0x01, 0x00, 0xfd, 0x00, 0x01, 0xe5,
448cef63e3SAlvin Wang                                     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
458cef63e3SAlvin Wang 
468cef63e3SAlvin Wang static const uint8_t create_read_window2[] = {
478cef63e3SAlvin Wang     0x04, 0x02, 0xe5, 0x01, 0x01, 0x00, 0x00, 0x00,
488cef63e3SAlvin Wang     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
498cef63e3SAlvin Wang 
508cef63e3SAlvin Wang static const uint8_t response2[] = {0x04, 0x02, 0x00, 0xfd, 0x48, 0x00, 0xe5,
518cef63e3SAlvin Wang                                     0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
528cef63e3SAlvin Wang 
538cef63e3SAlvin Wang namespace test = openpower::virtual_pnor::test;
548cef63e3SAlvin Wang 
main()558cef63e3SAlvin Wang int main()
568cef63e3SAlvin Wang {
578cef63e3SAlvin Wang     struct mbox_context* ctx;
588cef63e3SAlvin Wang 
598cef63e3SAlvin Wang     system_set_reserved_size(MEM_SIZE);
608cef63e3SAlvin Wang     system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE);
618cef63e3SAlvin Wang 
628cef63e3SAlvin Wang     ctx = mbox_create_frontend_context(N_WINDOWS, WINDOW_SIZE);
638cef63e3SAlvin Wang 
648cef63e3SAlvin Wang     test::VpnorRoot root(&ctx->backend, toc, BLOCK_SIZE);
658cef63e3SAlvin Wang 
668cef63e3SAlvin Wang     int rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info));
678cef63e3SAlvin Wang     assert(rc == 1);
688cef63e3SAlvin Wang 
698cef63e3SAlvin Wang     // send the request for partition5
708cef63e3SAlvin Wang     rc = mbox_command_dispatch(ctx, create_read_window1,
718cef63e3SAlvin Wang                                sizeof(create_read_window1));
728cef63e3SAlvin Wang     assert(rc == 1);
738cef63e3SAlvin Wang     rc = mbox_cmp(ctx, response1, sizeof(response1));
748cef63e3SAlvin Wang     assert(rc == 0);
758cef63e3SAlvin Wang 
768cef63e3SAlvin Wang     // send the request for partition5
778cef63e3SAlvin Wang     rc = mbox_command_dispatch(ctx, create_read_window2,
788cef63e3SAlvin Wang                                sizeof(create_read_window2));
798cef63e3SAlvin Wang     assert(rc == 1);
808cef63e3SAlvin Wang     rc = mbox_cmp(ctx, response2, sizeof(response2));
818cef63e3SAlvin Wang     assert(rc == 0);
828cef63e3SAlvin Wang 
838cef63e3SAlvin Wang     return rc;
848cef63e3SAlvin Wang }
85