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 "mboxd.h" 13 extern "C" { 14 #include "flash.h" 15 } 16 17 #include "vpnor/test/tmpd.hpp" 18 19 static constexpr auto BLOCK_SIZE = 0x1000; 20 21 const std::string toc[] = { 22 "partition01=TEST1,00001000,00002000,80,ECC,PRESERVED", 23 }; 24 25 namespace test = openpower::virtual_pnor::test; 26 27 int main(void) 28 { 29 namespace fs = std::experimental::filesystem; 30 31 struct mbox_context _ctx, *ctx = &_ctx; 32 uint8_t src[8]; 33 void* map; 34 int fd; 35 int rc; 36 37 /* Setup */ 38 memset(ctx, 0, sizeof(mbox_context)); 39 40 mbox_vlog = &mbox_log_console; 41 verbosity = (verbose)2; 42 43 test::VpnorRoot root(ctx, toc, BLOCK_SIZE); 44 init_vpnor_from_paths(ctx); 45 46 /* Test */ 47 memset(src, 0xaa, sizeof(src)); 48 rc = flash_write(ctx, 0x1000, src, sizeof(src)); 49 assert(rc == 0); 50 51 /* Verify */ 52 fd = open((root.prsv() / "TEST1").c_str(), O_RDONLY); 53 assert(fd >= 0); 54 map = mmap(NULL, sizeof(src), PROT_READ, MAP_SHARED, fd, 0); 55 assert(map != MAP_FAILED); 56 57 rc = memcmp(src, map, sizeof(src)); 58 assert(rc == 0); 59 munmap(map, sizeof(src)); 60 close(fd); 61 62 /* Cleanup */ 63 destroy_vpnor(ctx); 64 65 return 0; 66 } 67