Skip to content

Commit 4b4181b

Browse files
author
listout
committed
hw/xtensa/esp32.c: Using the largest flash size by default.
In commit listout@0152246 4MB (or gd25q32) was being hardcoded, as a result we could not use larger image size (> 4Mb). This PR should fix it, by using the largest available (gd25q64). Fixes: #66 Fixes: #17 Signed-off-by: listout <[email protected]>
1 parent 1f88fe7 commit 4b4181b

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

hw/xtensa/esp32.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,19 @@ static void esp32_machine_init_spi_flash(Esp32SocState *ss, BlockBackend* blk)
669669
/* "main" flash chip is attached to SPI1, CS0 */
670670
DeviceState *spi_master = DEVICE(&ss->spi[1]);
671671
BusState* spi_bus = qdev_get_child_bus(spi_master, "spi");
672-
DeviceState *flash_dev = qdev_new("gd25q32");
672+
673+
/* select the flash chip based on the image size */
674+
int64_t image_size = blk_getlength(blk);
675+
const char* flash_chip_model = NULL;
676+
switch (image_size) {
677+
case 2 * 1024 * 1024: flash_chip_model = "w25x16"; break;
678+
case 4 * 1024 * 1024: flash_chip_model = "gd25q32"; break;
679+
case 8 * 1024 * 1024: flash_chip_model = "gd25q64"; break;
680+
case 16 * 1024 * 1024: flash_chip_model = "is25lp128"; break;
681+
default: error_report("Error: only 2, 4, 8, 16 MB flash images are supported"); return;
682+
}
683+
684+
DeviceState *flash_dev = qdev_new(flash_chip_model);
673685
qdev_prop_set_drive(flash_dev, "drive", blk);
674686
qdev_realize_and_unref(flash_dev, spi_bus, &error_fatal);
675687
qdev_connect_gpio_out_named(spi_master, SSI_GPIO_CS, 0,

0 commit comments

Comments
 (0)