xref: /openbmc/phosphor-mboxd/vpnor/test/read_patch.cpp (revision 30bcf84c932a579532e5f8417af549494e11b6e9)
1*30bcf84cSAndrew Jeffery // SPDX-License-Identifier: Apache-2.0
2*30bcf84cSAndrew Jeffery // Copyright (C) 2018 IBM Corp.
3*30bcf84cSAndrew Jeffery 
4*30bcf84cSAndrew Jeffery #include "config.h"
5*30bcf84cSAndrew Jeffery #include "common.h"
6*30bcf84cSAndrew Jeffery #include "vpnor/mboxd_pnor_partition_table.h"
7*30bcf84cSAndrew Jeffery 
8*30bcf84cSAndrew Jeffery #include <assert.h>
9*30bcf84cSAndrew Jeffery 
10*30bcf84cSAndrew Jeffery extern "C" {
11*30bcf84cSAndrew Jeffery #include "test/mbox.h"
12*30bcf84cSAndrew Jeffery #include "test/system.h"
13*30bcf84cSAndrew Jeffery }
14*30bcf84cSAndrew Jeffery 
15*30bcf84cSAndrew Jeffery #include "vpnor/test/tmpd.hpp"
16*30bcf84cSAndrew Jeffery 
17*30bcf84cSAndrew Jeffery static constexpr auto BLOCK_SIZE = 0x1000;
18*30bcf84cSAndrew Jeffery static constexpr auto ERASE_SIZE = BLOCK_SIZE;
19*30bcf84cSAndrew Jeffery static constexpr auto PART_SIZE = BLOCK_SIZE * 4;
20*30bcf84cSAndrew Jeffery static constexpr auto PATCH_SIZE = PART_SIZE / 2;
21*30bcf84cSAndrew Jeffery static constexpr auto N_WINDOWS = 2;
22*30bcf84cSAndrew Jeffery static constexpr auto WINDOW_SIZE = PART_SIZE * 8;
23*30bcf84cSAndrew Jeffery static constexpr auto MEM_SIZE = WINDOW_SIZE * N_WINDOWS;
24*30bcf84cSAndrew Jeffery static constexpr auto PNOR_SIZE = MEM_SIZE * 2;
25*30bcf84cSAndrew Jeffery 
26*30bcf84cSAndrew Jeffery const std::string toc[] = {
27*30bcf84cSAndrew Jeffery     "partition01=ONE,00001000,00005000,80,ECC,READONLY",
28*30bcf84cSAndrew Jeffery };
29*30bcf84cSAndrew Jeffery 
30*30bcf84cSAndrew Jeffery static const uint8_t get_info[] = {0x02, 0x00, 0x02, 0x00, 0x00, 0x00,
31*30bcf84cSAndrew Jeffery                                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
32*30bcf84cSAndrew Jeffery                                    0x00, 0x00, 0x00, 0x00};
33*30bcf84cSAndrew Jeffery 
34*30bcf84cSAndrew Jeffery static const uint8_t create_read_window[] = {0x04, 0x01, 0x01, 0x00, 0x04, 0x00,
35*30bcf84cSAndrew Jeffery                                              0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
36*30bcf84cSAndrew Jeffery                                              0x00, 0x00, 0x00, 0x00};
37*30bcf84cSAndrew Jeffery 
38*30bcf84cSAndrew Jeffery static const uint8_t response[] = {0x04, 0x01, 0xc0, 0xff, 0x04, 0x00, 0x01,
39*30bcf84cSAndrew Jeffery                                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
40*30bcf84cSAndrew Jeffery 
main()41*30bcf84cSAndrew Jeffery int main()
42*30bcf84cSAndrew Jeffery {
43*30bcf84cSAndrew Jeffery     namespace test = openpower::virtual_pnor::test;
44*30bcf84cSAndrew Jeffery 
45*30bcf84cSAndrew Jeffery     struct mbox_context *ctx;
46*30bcf84cSAndrew Jeffery 
47*30bcf84cSAndrew Jeffery     system_set_reserved_size(MEM_SIZE);
48*30bcf84cSAndrew Jeffery     system_set_mtd_sizes(PNOR_SIZE, ERASE_SIZE);
49*30bcf84cSAndrew Jeffery     ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE);
50*30bcf84cSAndrew Jeffery     test::VpnorRoot root(ctx, toc, BLOCK_SIZE);
51*30bcf84cSAndrew Jeffery 
52*30bcf84cSAndrew Jeffery     // PATCH_SIZE is smaller than the size of the partition we defined. This
53*30bcf84cSAndrew Jeffery     // test ensures that mboxd will behave correctly when we request an offset
54*30bcf84cSAndrew Jeffery     // that is beyond the size of the backing file, but is in the set of valid
55*30bcf84cSAndrew Jeffery     // offsets for the partition as defined by the ToC.
56*30bcf84cSAndrew Jeffery     std::vector<uint8_t> patch(PATCH_SIZE, 0xff);
57*30bcf84cSAndrew Jeffery     root.patch("ONE", patch.data(), patch.size());
58*30bcf84cSAndrew Jeffery 
59*30bcf84cSAndrew Jeffery     init_vpnor_from_paths(ctx);
60*30bcf84cSAndrew Jeffery 
61*30bcf84cSAndrew Jeffery     int rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info));
62*30bcf84cSAndrew Jeffery     assert(rc == 1);
63*30bcf84cSAndrew Jeffery 
64*30bcf84cSAndrew Jeffery     rc = mbox_command_dispatch(ctx, create_read_window,
65*30bcf84cSAndrew Jeffery                                sizeof(create_read_window));
66*30bcf84cSAndrew Jeffery     assert(rc == 1);
67*30bcf84cSAndrew Jeffery 
68*30bcf84cSAndrew Jeffery     rc = mbox_cmp(ctx, response, sizeof(response));
69*30bcf84cSAndrew Jeffery     assert(rc == 0);
70*30bcf84cSAndrew Jeffery 
71*30bcf84cSAndrew Jeffery     return 0;
72*30bcf84cSAndrew Jeffery }
73