xref: /openbmc/qemu/tests/qtest/ast2700-smc-test.c (revision 557e1d67)
1 /*
2  * QTest testcase for the M25P80 Flash using the ASPEED SPI Controller since
3  * AST2700.
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * Copyright (C) 2024 ASPEED Technology Inc.
7  */
8 
9 #include "qemu/osdep.h"
10 #include "qemu/bswap.h"
11 #include "libqtest-single.h"
12 #include "qemu/bitops.h"
13 #include "aspeed-smc-utils.h"
14 
15 static void test_ast2700_evb(AspeedSMCTestData *data)
16 {
17     int ret;
18     int fd;
19 
20     fd = g_file_open_tmp("qtest.m25p80.w25q01jvq.XXXXXX",
21                          &data->tmp_path, NULL);
22     g_assert(fd >= 0);
23     ret = ftruncate(fd, 128 * 1024 * 1024);
24     g_assert(ret == 0);
25     close(fd);
26 
27     data->s = qtest_initf("-machine ast2700-evb "
28                           "-drive file=%s,format=raw,if=mtd",
29                           data->tmp_path);
30 
31     /* fmc cs0 with w25q01jvq flash */
32     data->flash_base = 0x100000000;
33     data->spi_base = 0x14000000;
34     data->jedec_id = 0xef4021;
35     data->cs = 0;
36     data->node = "/machine/soc/fmc/ssi.0/child[0]";
37     /* beyond 64MB */
38     data->page_addr = 0x40000 * FLASH_PAGE_SIZE;
39 
40     qtest_add_data_func("/ast2700/smc/read_jedec",
41                         data, aspeed_smc_test_read_jedec);
42     qtest_add_data_func("/ast2700/smc/erase_sector",
43                         data, aspeed_smc_test_erase_sector);
44     qtest_add_data_func("/ast2700/smc/erase_all",
45                         data, aspeed_smc_test_erase_all);
46     qtest_add_data_func("/ast2700/smc/write_page",
47                         data, aspeed_smc_test_write_page);
48     qtest_add_data_func("/ast2700/smc/read_page_mem",
49                         data, aspeed_smc_test_read_page_mem);
50     qtest_add_data_func("/ast2700/smc/write_page_mem",
51                         data, aspeed_smc_test_write_page_mem);
52     qtest_add_data_func("/ast2700/smc/read_status_reg",
53                         data, aspeed_smc_test_read_status_reg);
54     qtest_add_data_func("/ast2700/smc/write_page_qpi",
55                         data, aspeed_smc_test_write_page_qpi);
56 }
57 
58 int main(int argc, char **argv)
59 {
60     AspeedSMCTestData ast2700_evb_data;
61     int ret;
62 
63     g_test_init(&argc, &argv, NULL);
64 
65     test_ast2700_evb(&ast2700_evb_data);
66     ret = g_test_run();
67 
68     qtest_quit(ast2700_evb_data.s);
69     unlink(ast2700_evb_data.tmp_path);
70     return ret;
71 }
72