@samitouri / QOSamiQemu / commits / d11199e771

tests/qtest/pflash-cfi02-test: Don't use musicpal machine for testing

We currently use the musicpal machine for testing the pflash-cfi02 device. We'd like to remove that machine, so switch the tests to the sh4 r2d board type instead. We use r2d because it happens to have the same "2 bank" config that musicpal did. (Of our other options, xilinx-zynq-a9 has only a 1-bank setup so wouldn't allow the same range of testing, and the canon-a1100 board both doesn't support specifying a flash drive via -drive if=pflash, plus it seems likely it too might be a candidate for deprecate-and-drop.) The r2d flash device is not quite the same config as the musicpal one: it has a different base address and size, and different ID values. So we need to update the test to match. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Acked-by: Jan Kiszka <jan.kiszka@web.de> Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com> Message-id: 20260819185430.3467629-2-peter.maydell@linaro.org

Peter Maydell committed Aug 19, 2026 at 19:54 UTC d11199e7711e7eff1197916bbf684fedc71e4c75
2 files changed +26 -18
tests/qtest/meson.build
+3 -3
@@ -198,7 +198,9 @@ qtests_ppc64 = \
198 (config_all_devices.has_key('CONFIG_USB_XHCI_NEC') ? ['usb-hcd-xhci-test'] : []) + \
199 qtests_pci + ['migration-test', 'cpu-plug-test', 'drive_del-test']
200
201 -qtests_sh4 = (config_all_devices.has_key('CONFIG_ISA_TESTDEV') ? ['endianness-test'] : [])
201 +qtests_sh4 = (config_all_devices.has_key('CONFIG_ISA_TESTDEV') ? ['endianness-test'] : []) + \
202 + (config_all_devices.has_key('CONFIG_PFLASH_CFI02') and
203 + config_all_devices.has_key('CONFIG_R2D') ? ['pflash-cfi02-test'] : [])
204 qtests_sh4eb = (config_all_devices.has_key('CONFIG_ISA_TESTDEV') ? ['endianness-test'] : [])
205
206 qtests_sparc = ['prom-env-test', 'm48t59-test', 'boot-serial-test'] + \
@@ -245,8 +247,6 @@ qtests_arm = \
247 (config_all_devices.has_key('CONFIG_CMSDK_APB_TIMER') ? ['cmsdk-apb-timer-test'] : []) + \
248 (config_all_devices.has_key('CONFIG_STELLARIS') or
249 config_all_devices.has_key('CONFIG_MPS2') ? ['cmsdk-apb-watchdog-test'] : []) + \
248 - (config_all_devices.has_key('CONFIG_PFLASH_CFI02') and
249 - config_all_devices.has_key('CONFIG_MUSICPAL') ? ['pflash-cfi02-test'] : []) + \
250 (config_all_devices.has_key('CONFIG_ASPEED_SOC') ? qtests_aspeed : []) + \
251 (config_all_devices.has_key('CONFIG_NPCM7XX') ? qtests_npcm7xx : []) + \
252 (config_all_devices.has_key('CONFIG_GENERIC_LOADER') ? ['hexloader-test'] : []) + \
tests/qtest/pflash-cfi02-test.c
+23 -15
@@ -11,17 +11,25 @@
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;
@@ -260,7 +268,7 @@ static void test_geometry(const void *opaque)
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,"
@@ -295,16 +303,16 @@ static void test_geometry(const void *opaque)
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
@@ -436,7 +444,7 @@ static void test_geometry(const void *opaque)
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 /*
@@ -580,7 +588,7 @@ static void test_cfi_in_autoselect(const void *opaque)
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);
@@ -590,7 +598,7 @@ static void test_cfi_in_autoselect(const void *opaque)
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);
@@ -600,7 +608,7 @@ static void test_cfi_in_autoselect(const void *opaque)
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 }
@@ -613,7 +621,7 @@ static void cleanup(void *opaque)
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. */
@@ -624,13 +632,13 @@ static const FlashConfig configuration[] = {
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