Andrew Jeffery | ad341a2 | 2018-02-22 17:13:15 +1030 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // Copyright (C) 2018 IBM Corp. |
| 3 | |
| 4 | #include <assert.h> |
| 5 | #include <fcntl.h> |
| 6 | #include <sys/mman.h> |
| 7 | #include <sys/stat.h> |
| 8 | #include <sys/types.h> |
| 9 | #include <unistd.h> |
| 10 | |
| 11 | #include "common.h" |
| 12 | #include "mbox.h" |
| 13 | #include "mboxd_flash.h" |
| 14 | |
Andrew Jeffery | 30bcf84 | 2018-03-26 12:13:20 +1030 | [diff] [blame^] | 15 | #include "vpnor/test/tmpd.hpp" |
Andrew Jeffery | ad341a2 | 2018-02-22 17:13:15 +1030 | [diff] [blame] | 16 | |
| 17 | static constexpr auto BLOCK_SIZE = 0x1000; |
| 18 | |
| 19 | const std::string toc[] = { |
| 20 | "partition01=TEST1,00001000,00002000,80,ECC,PRESERVED", |
| 21 | }; |
| 22 | |
| 23 | namespace test = openpower::virtual_pnor::test; |
| 24 | |
| 25 | int main(void) |
| 26 | { |
| 27 | namespace fs = std::experimental::filesystem; |
| 28 | |
| 29 | struct mbox_context _ctx, *ctx = &_ctx; |
| 30 | uint8_t src[8]; |
| 31 | void *map; |
| 32 | int fd; |
| 33 | int rc; |
| 34 | |
| 35 | /* Setup */ |
| 36 | memset(ctx, 0, sizeof(mbox_context)); |
| 37 | |
| 38 | mbox_vlog = &mbox_log_console; |
| 39 | verbosity = (verbose)2; |
| 40 | |
| 41 | test::VpnorRoot root(ctx, toc, BLOCK_SIZE); |
Andrew Jeffery | 742a1f6 | 2018-03-02 09:26:03 +1030 | [diff] [blame] | 42 | init_vpnor_from_paths(ctx); |
Andrew Jeffery | ad341a2 | 2018-02-22 17:13:15 +1030 | [diff] [blame] | 43 | |
| 44 | /* Test */ |
| 45 | memset(src, 0xaa, sizeof(src)); |
| 46 | rc = write_flash(ctx, 0x1000, src, sizeof(src)); |
| 47 | assert(rc == 0); |
| 48 | |
| 49 | /* Verify */ |
| 50 | fd = open((root.prsv() / "TEST1").c_str(), O_RDONLY); |
| 51 | assert(fd >= 0); |
| 52 | map = mmap(NULL, sizeof(src), PROT_READ, MAP_PRIVATE, fd, 0); |
| 53 | assert(map != MAP_FAILED); |
| 54 | |
| 55 | rc = memcmp(src, map, sizeof(src)); |
| 56 | assert(rc == 0); |
| 57 | munmap(map, sizeof(src)); |
| 58 | close(fd); |
| 59 | |
| 60 | /* Cleanup */ |
| 61 | destroy_vpnor(ctx); |
| 62 | |
| 63 | return 0; |
| 64 | } |