11
#include "libqtest.h"
12
13
/*
14
- * To test the pflash_cfi02 device, we run QEMU with the musicpal machine with
14
+ * To test the pflash_cfi02 device, we run QEMU with the sh4 r2d machine with
15
* a pflash drive. This enables us to test some flash configurations, but not
16
* all. In particular, we're limited to a 16-bit wide flash device.
17
*/
18
19
-#define MP_FLASH_SIZE_MAX (32 * 1024 * 1024)
20
-#define BASE_ADDR (0x100000000ULL - MP_FLASH_SIZE_MAX)
19
+/*
20
+ * These need to match the flash size and address in r2d.c.
21
+ * If the flash size changes then the sector_len[] and nb_blocs[]
22
+ * values in configuration[] below will need to be updated to match.
23
+ */
24
+#define BASE_ADDR 0x00000000
25
22
-#define UNIFORM_FLASH_SIZE (8 * 1024 * 1024)
26
+#define UNIFORM_FLASH_SIZE (16 * 1024 * 1024)
27
#define UNIFORM_FLASH_SECTOR_SIZE (64 * 1024)
28
29
+/* These must match the id0, id1 args to pflash_cfi02_register() in r2d.c */
30
+#define FLASH_ID0 0x0001
31
+#define FLASH_ID1 0x227E
32
+
33
/* Use a newtype to keep flash addresses separate from byte addresses. */
34
typedef struct {
35
uint64_t addr;
268
{
269
const FlashConfig *config = opaque;
270
QTestState *qtest;
263
- qtest = qtest_initf("-M musicpal"
271
+ qtest = qtest_initf("-M r2d"
272
" -drive if=pflash,file=%s,format=raw,copy-on-read=on"
273
/* Device geometry properties. */
274
" -global driver=cfi.pflash02,"
303
/* Check the IDs. */
304
unlock(c);
305
flash_cmd(c, UNLOCK0_ADDR, AUTOSELECT_CMD);
298
- g_assert_cmphex(flash_query(c, FLASH_ADDR(0)), ==, replicate(c, 0xBF));
306
+ g_assert_cmphex(flash_query(c, FLASH_ADDR(0)), ==, replicate(c, FLASH_ID0));
307
if (c->bank_width >= 2) {
308
/*
301
- * XXX: The ID returned by the musicpal flash chip is 16 bits which
309
+ * XXX: The ID returned by the r2d flash chip is 16 bits which
310
* wouldn't happen with an 8-bit device. It would probably be best to
311
* prohibit addresses larger than the device width in pflash_cfi02.c,
312
* but then we couldn't test smaller device widths at all.
313
*/
314
g_assert_cmphex(flash_query(c, FLASH_ADDR(1)), ==,
307
- replicate(c, 0x236D));
315
+ replicate(c, FLASH_ID1));
316
}
317
reset(c);
318
444
flash_cmd(c, FLASH_ADDR(0x5555), UNLOCK0_CMD);
445
flash_cmd(c, FLASH_ADDR(0x2AAA), UNLOCK1_CMD);
446
flash_cmd(c, FLASH_ADDR(0x5555), AUTOSELECT_CMD);
439
- g_assert_cmphex(flash_query(c, FLASH_ADDR(0)), ==, replicate(c, 0xBF));
447
+ g_assert_cmphex(flash_query(c, FLASH_ADDR(0)), ==, replicate(c, FLASH_ID0));
448
reset(c);
449
450
/*
588
{
589
const FlashConfig *config = opaque;
590
QTestState *qtest;
583
- qtest = qtest_initf("-M musicpal"
591
+ qtest = qtest_initf("-M r2d"
592
" -drive if=pflash,file=%s,format=raw,copy-on-read=on",
593
image_path);
594
FlashConfig explicit_config = expand_config_defaults(config);
598
/* 1. Enter autoselect. */
599
unlock(c);
600
flash_cmd(c, UNLOCK0_ADDR, AUTOSELECT_CMD);
593
- g_assert_cmphex(flash_query(c, FLASH_ADDR(0)), ==, replicate(c, 0xBF));
601
+ g_assert_cmphex(flash_query(c, FLASH_ADDR(0)), ==, replicate(c, FLASH_ID0));
602
603
/* 2. Enter CFI. */
604
flash_cmd(c, CFI_ADDR, CFI_CMD);
608
609
/* 3. Exit CFI. */
610
reset(c);
603
- g_assert_cmphex(flash_query(c, FLASH_ADDR(0)), ==, replicate(c, 0xBF));
611
+ g_assert_cmphex(flash_query(c, FLASH_ADDR(0)), ==, replicate(c, FLASH_ID0));
612
613
qtest_quit(qtest);
614
}
621
622
/*
623
* XXX: Tests are limited to bank_width = 2 for now because that's what
616
- * hw/arm/musicpal.c has.
624
+ * hw/sh4/r2d.c has.
625
*/
626
static const FlashConfig configuration[] = {
627
/* One x16 device. */
632
{
633
.bank_width = 2,
634
.nb_blocs = { 127, 1, 2, 1 },
627
- .sector_len = { 0x10000, 0x08000, 0x02000, 0x04000 },
635
+ .sector_len = { 0x20000, 0x10000, 0x04000, 0x08000 },
636
},
637
/* Nonuniform sectors (bottom boot). */
638
{
639
.bank_width = 2,
640
.nb_blocs = { 1, 2, 1, 127 },
633
- .sector_len = { 0x04000, 0x02000, 0x08000, 0x10000 },
641
+ .sector_len = { 0x08000, 0x04000, 0x10000, 0x20000 },
642
},
643
};
644