xref: /openbmc/phosphor-mboxd/test/read_window_mark_write_erased.c (revision 4fe996c2e7f157d521b5c8732e8b80e03bd25ff0)
1*4fe996c2SAndrew Jeffery // SPDX-License-Identifier: Apache-2.0
2*4fe996c2SAndrew Jeffery // Copyright (C) 2018 IBM Corp.
3aed3a5ffSAndrew Jeffery 
4aed3a5ffSAndrew Jeffery #include <assert.h>
5aed3a5ffSAndrew Jeffery 
6aed3a5ffSAndrew Jeffery #include "mbox.h"
7aed3a5ffSAndrew Jeffery #include "mboxd_msg.h"
8aed3a5ffSAndrew Jeffery 
9aed3a5ffSAndrew Jeffery #include "test/mbox.h"
10aed3a5ffSAndrew Jeffery #include "test/system.h"
11aed3a5ffSAndrew Jeffery 
12aed3a5ffSAndrew Jeffery static const uint8_t get_info[] = {
13aed3a5ffSAndrew Jeffery 	0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
14aed3a5ffSAndrew Jeffery 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
15aed3a5ffSAndrew Jeffery };
16aed3a5ffSAndrew Jeffery 
17aed3a5ffSAndrew Jeffery static const uint8_t create_read_window[] = {
18aed3a5ffSAndrew Jeffery 	0x04, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
19aed3a5ffSAndrew Jeffery 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
20aed3a5ffSAndrew Jeffery };
21aed3a5ffSAndrew Jeffery 
22aed3a5ffSAndrew Jeffery static const uint8_t mark_write_erased[] = {
23aed3a5ffSAndrew Jeffery 	0x0a, 0x02, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
24aed3a5ffSAndrew Jeffery 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
25aed3a5ffSAndrew Jeffery };
26aed3a5ffSAndrew Jeffery 
27aed3a5ffSAndrew Jeffery static const uint8_t response[] = {
28aed3a5ffSAndrew Jeffery 	0x0a, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
29aed3a5ffSAndrew Jeffery 	0x00, 0x00, 0x00, 0x00, 0x00, 0x07
30aed3a5ffSAndrew Jeffery };
31aed3a5ffSAndrew Jeffery 
32aed3a5ffSAndrew Jeffery uint8_t data[3] = { 0xaa, 0x55, 0xaa };
33aed3a5ffSAndrew Jeffery 
34aed3a5ffSAndrew Jeffery #define MEM_SIZE	sizeof(data)
35aed3a5ffSAndrew Jeffery #define ERASE_SIZE	1
36aed3a5ffSAndrew Jeffery #define N_WINDOWS	1
37aed3a5ffSAndrew Jeffery #define WINDOW_SIZE	sizeof(data)
38aed3a5ffSAndrew Jeffery 
main(void)39aed3a5ffSAndrew Jeffery int main(void)
40aed3a5ffSAndrew Jeffery {
41aed3a5ffSAndrew Jeffery 	struct mbox_context *ctx;
42aed3a5ffSAndrew Jeffery 	int rc;
43aed3a5ffSAndrew Jeffery 
44aed3a5ffSAndrew Jeffery 	system_set_reserved_size(MEM_SIZE);
45aed3a5ffSAndrew Jeffery 	system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE);
46aed3a5ffSAndrew Jeffery 
47aed3a5ffSAndrew Jeffery 	ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE);
48aed3a5ffSAndrew Jeffery 	rc = mbox_set_mtd_data(ctx, data, sizeof(data));
49aed3a5ffSAndrew Jeffery 	assert(rc == 0);
50aed3a5ffSAndrew Jeffery 
51aed3a5ffSAndrew Jeffery 	rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info));
52aed3a5ffSAndrew Jeffery 	assert(rc == 1);
53aed3a5ffSAndrew Jeffery 
54aed3a5ffSAndrew Jeffery 	rc = mbox_command_dispatch(ctx, create_read_window,
55aed3a5ffSAndrew Jeffery 			sizeof(create_read_window));
56aed3a5ffSAndrew Jeffery 	assert(rc == 1);
57aed3a5ffSAndrew Jeffery 
58aed3a5ffSAndrew Jeffery 	rc = mbox_command_dispatch(ctx, mark_write_erased,
59aed3a5ffSAndrew Jeffery 			sizeof(mark_write_erased));
60aed3a5ffSAndrew Jeffery 	assert(rc == 7);
61aed3a5ffSAndrew Jeffery 
62aed3a5ffSAndrew Jeffery 	rc = mbox_cmp(ctx, response, sizeof(response));
63aed3a5ffSAndrew Jeffery 	assert(rc == 0);
64aed3a5ffSAndrew Jeffery 
65aed3a5ffSAndrew Jeffery 	return rc;
66aed3a5ffSAndrew Jeffery };
67