blob: 26f1d86d3b125001a2e66d334475a1f9291576f5 [file] [log] [blame]
Andrew Jefferyad341a22018-02-22 17:13:15 +10301// 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 Jeffery30bcf842018-03-26 12:13:20 +103015#include "vpnor/test/tmpd.hpp"
Andrew Jefferyad341a22018-02-22 17:13:15 +103016
17static constexpr auto BLOCK_SIZE = 0x1000;
18
19const std::string toc[] = {
20 "partition01=TEST1,00001000,00002000,80,ECC,PRESERVED",
21};
22
23namespace test = openpower::virtual_pnor::test;
24
25int 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 Jeffery742a1f62018-03-02 09:26:03 +103042 init_vpnor_from_paths(ctx);
Andrew Jefferyad341a22018-02-22 17:13:15 +103043
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}