xref: /openbmc/qemu/tests/qtest/aspeed_smc-test.c (revision 11d94251)
1 /*
2  * QTest testcase for the M25P80 Flash (Using the Aspeed SPI
3  * Controller)
4  *
5  * Copyright (C) 2016 IBM Corp.
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy
8  * of this software and associated documentation files (the "Software"), to deal
9  * in the Software without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in
15  * all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23  * THE SOFTWARE.
24  */
25 
26 #include "qemu/osdep.h"
27 #include "qemu/bswap.h"
28 #include "libqtest-single.h"
29 #include "qemu/bitops.h"
30 #include "aspeed-smc-utils.h"
31 
test_palmetto_bmc(AspeedSMCTestData * data)32 static void test_palmetto_bmc(AspeedSMCTestData *data)
33 {
34     int ret;
35     int fd;
36 
37     fd = g_file_open_tmp("qtest.m25p80.n25q256a.XXXXXX", &data->tmp_path, NULL);
38     g_assert(fd >= 0);
39     ret = ftruncate(fd, 32 * 1024 * 1024);
40     g_assert(ret == 0);
41     close(fd);
42 
43     data->s = qtest_initf("-m 256 -machine palmetto-bmc "
44                           "-drive file=%s,format=raw,if=mtd",
45                           data->tmp_path);
46 
47     /* fmc cs0 with n25q256a flash */
48     data->flash_base = 0x20000000;
49     data->spi_base = 0x1E620000;
50     data->jedec_id = 0x20ba19;
51     data->cs = 0;
52     data->node = "/machine/soc/fmc/ssi.0/child[0]";
53     /* beyond 16MB */
54     data->page_addr = 0x14000 * FLASH_PAGE_SIZE;
55 
56     qtest_add_data_func("/ast2400/smc/read_jedec",
57                         data, aspeed_smc_test_read_jedec);
58     qtest_add_data_func("/ast2400/smc/erase_sector",
59                         data, aspeed_smc_test_erase_sector);
60     qtest_add_data_func("/ast2400/smc/erase_all",
61                         data, aspeed_smc_test_erase_all);
62     qtest_add_data_func("/ast2400/smc/write_page",
63                         data, aspeed_smc_test_write_page);
64     qtest_add_data_func("/ast2400/smc/read_page_mem",
65                         data, aspeed_smc_test_read_page_mem);
66     qtest_add_data_func("/ast2400/smc/write_page_mem",
67                         data, aspeed_smc_test_write_page_mem);
68     qtest_add_data_func("/ast2400/smc/read_status_reg",
69                         data, aspeed_smc_test_read_status_reg);
70     qtest_add_data_func("/ast2400/smc/status_reg_write_protection",
71                         data, aspeed_smc_test_status_reg_write_protection);
72     qtest_add_data_func("/ast2400/smc/write_block_protect",
73                         data, aspeed_smc_test_write_block_protect);
74     qtest_add_data_func("/ast2400/smc/write_block_protect_bottom_bit",
75                         data, aspeed_smc_test_write_block_protect_bottom_bit);
76 }
77 
test_ast2500_evb(AspeedSMCTestData * data)78 static void test_ast2500_evb(AspeedSMCTestData *data)
79 {
80     int ret;
81     int fd;
82 
83     fd = g_file_open_tmp("qtest.m25p80.mx25l25635e.XXXXXX",
84                          &data->tmp_path, NULL);
85     g_assert(fd >= 0);
86     ret = ftruncate(fd, 32 * 1024 * 1024);
87     g_assert(ret == 0);
88     close(fd);
89 
90     data->s = qtest_initf("-machine ast2500-evb "
91                           "-drive file=%s,format=raw,if=mtd",
92                           data->tmp_path);
93 
94     /* fmc cs0 with mx25l25635e flash */
95     data->flash_base = 0x20000000;
96     data->spi_base = 0x1E620000;
97     data->jedec_id = 0xc22019;
98     data->cs = 0;
99     data->node = "/machine/soc/fmc/ssi.0/child[0]";
100     /* beyond 16MB */
101     data->page_addr = 0x14000 * FLASH_PAGE_SIZE;
102 
103     qtest_add_data_func("/ast2500/smc/read_jedec",
104                         data, aspeed_smc_test_read_jedec);
105     qtest_add_data_func("/ast2500/smc/erase_sector",
106                         data, aspeed_smc_test_erase_sector);
107     qtest_add_data_func("/ast2500/smc/erase_all",
108                         data, aspeed_smc_test_erase_all);
109     qtest_add_data_func("/ast2500/smc/write_page",
110                         data, aspeed_smc_test_write_page);
111     qtest_add_data_func("/ast2500/smc/read_page_mem",
112                         data, aspeed_smc_test_read_page_mem);
113     qtest_add_data_func("/ast2500/smc/write_page_mem",
114                         data, aspeed_smc_test_write_page_mem);
115     qtest_add_data_func("/ast2500/smc/read_status_reg",
116                         data, aspeed_smc_test_read_status_reg);
117     qtest_add_data_func("/ast2500/smc/write_page_qpi",
118                         data, aspeed_smc_test_write_page_qpi);
119 }
120 
test_ast2600_evb(AspeedSMCTestData * data)121 static void test_ast2600_evb(AspeedSMCTestData *data)
122 {
123     int ret;
124     int fd;
125 
126     fd = g_file_open_tmp("qtest.m25p80.mx66u51235f.XXXXXX",
127                          &data->tmp_path, NULL);
128     g_assert(fd >= 0);
129     ret = ftruncate(fd, 64 * 1024 * 1024);
130     g_assert(ret == 0);
131     close(fd);
132 
133     data->s = qtest_initf("-machine ast2600-evb "
134                           "-drive file=%s,format=raw,if=mtd",
135                           data->tmp_path);
136 
137     /* fmc cs0 with mx66u51235f flash */
138     data->flash_base = 0x20000000;
139     data->spi_base = 0x1E620000;
140     data->jedec_id = 0xc2253a;
141     data->cs = 0;
142     data->node = "/machine/soc/fmc/ssi.0/child[0]";
143     /* beyond 16MB */
144     data->page_addr = 0x14000 * FLASH_PAGE_SIZE;
145 
146     qtest_add_data_func("/ast2600/smc/read_jedec",
147                         data, aspeed_smc_test_read_jedec);
148     qtest_add_data_func("/ast2600/smc/erase_sector",
149                         data, aspeed_smc_test_erase_sector);
150     qtest_add_data_func("/ast2600/smc/erase_all",
151                         data, aspeed_smc_test_erase_all);
152     qtest_add_data_func("/ast2600/smc/write_page",
153                         data, aspeed_smc_test_write_page);
154     qtest_add_data_func("/ast2600/smc/read_page_mem",
155                         data, aspeed_smc_test_read_page_mem);
156     qtest_add_data_func("/ast2600/smc/write_page_mem",
157                         data, aspeed_smc_test_write_page_mem);
158     qtest_add_data_func("/ast2600/smc/read_status_reg",
159                         data, aspeed_smc_test_read_status_reg);
160     qtest_add_data_func("/ast2600/smc/write_page_qpi",
161                         data, aspeed_smc_test_write_page_qpi);
162 }
163 
test_ast1030_evb(AspeedSMCTestData * data)164 static void test_ast1030_evb(AspeedSMCTestData *data)
165 {
166     int ret;
167     int fd;
168 
169     fd = g_file_open_tmp("qtest.m25p80.w25q80bl.XXXXXX",
170                          &data->tmp_path, NULL);
171     g_assert(fd >= 0);
172     ret = ftruncate(fd, 1 * 1024 * 1024);
173     g_assert(ret == 0);
174     close(fd);
175 
176     data->s = qtest_initf("-machine ast1030-evb "
177                           "-drive file=%s,format=raw,if=mtd",
178                           data->tmp_path);
179 
180     /* fmc cs0 with w25q80bl flash */
181     data->flash_base = 0x80000000;
182     data->spi_base = 0x7E620000;
183     data->jedec_id = 0xef4014;
184     data->cs = 0;
185     data->node = "/machine/soc/fmc/ssi.0/child[0]";
186     /* beyond 512KB */
187     data->page_addr = 0x800 * FLASH_PAGE_SIZE;
188 
189     qtest_add_data_func("/ast1030/smc/read_jedec",
190                         data, aspeed_smc_test_read_jedec);
191     qtest_add_data_func("/ast1030/smc/erase_sector",
192                         data, aspeed_smc_test_erase_sector);
193     qtest_add_data_func("/ast1030/smc/erase_all",
194                         data, aspeed_smc_test_erase_all);
195     qtest_add_data_func("/ast1030/smc/write_page",
196                         data, aspeed_smc_test_write_page);
197     qtest_add_data_func("/ast1030/smc/read_page_mem",
198                         data, aspeed_smc_test_read_page_mem);
199     qtest_add_data_func("/ast1030/smc/write_page_mem",
200                         data, aspeed_smc_test_write_page_mem);
201     qtest_add_data_func("/ast1030/smc/read_status_reg",
202                         data, aspeed_smc_test_read_status_reg);
203     qtest_add_data_func("/ast1030/smc/write_page_qpi",
204                         data, aspeed_smc_test_write_page_qpi);
205 }
206 
main(int argc,char ** argv)207 int main(int argc, char **argv)
208 {
209     AspeedSMCTestData palmetto_data;
210     AspeedSMCTestData ast2500_evb_data;
211     AspeedSMCTestData ast2600_evb_data;
212     AspeedSMCTestData ast1030_evb_data;
213     int ret;
214 
215     g_test_init(&argc, &argv, NULL);
216 
217     test_palmetto_bmc(&palmetto_data);
218     test_ast2500_evb(&ast2500_evb_data);
219     test_ast2600_evb(&ast2600_evb_data);
220     test_ast1030_evb(&ast1030_evb_data);
221     ret = g_test_run();
222 
223     qtest_quit(palmetto_data.s);
224     qtest_quit(ast2500_evb_data.s);
225     qtest_quit(ast2600_evb_data.s);
226     qtest_quit(ast1030_evb_data.s);
227     unlink(palmetto_data.tmp_path);
228     unlink(ast2500_evb_data.tmp_path);
229     unlink(ast2600_evb_data.tmp_path);
230     unlink(ast1030_evb_data.tmp_path);
231     return ret;
232 }
233