From fdcac08fc97bd049a6d616ea93822341efa9b6aa Mon Sep 17 00:00:00 2001 From: vintagepc <53943260+vintagepc@users.noreply.github.com> Date: Wed, 22 Dec 2021 06:21:43 -0500 Subject: [PATCH] 99 extra flash ram (#100) * #99 - proper deprecation * support -m arg * option to expand flash storage --- hw/arm/prusa/prusa-mini.c | 27 ++++++++++++-------------- hw/arm/prusa/stm32f407/stm32f407_soc.c | 4 +++- hw/arm/prusa/stm32f407/stm32f407_soc.h | 8 +++++--- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/hw/arm/prusa/prusa-mini.c b/hw/arm/prusa/prusa-mini.c index 1e568f1992..cf35c5f4b8 100644 --- a/hw/arm/prusa/prusa-mini.c +++ b/hw/arm/prusa/prusa-mini.c @@ -44,12 +44,17 @@ static void prusa_mini_init(MachineState *machine) dev = qdev_new(TYPE_STM32F407_SOC); qdev_prop_set_string(dev, "cpu-type", ARM_CPU_TYPE_NAME("cortex-m4")); + qdev_prop_set_uint32(dev,"sram-size", machine->ram_size); sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal); STM32F407State *SOC = STM32F407_SOC(dev); // We (ab)use the kernel command line to piggyback custom arguments into QEMU. // Parse those now. arghelper_setargs(machine->kernel_cmdline); - + int default_flash_size = FLASH_SIZE; + if (arghelper_is_arg("4x_flash")) + { + default_flash_size <<=2; // quadruple the flash size for debug code. + } if (arghelper_is_arg("appendix")) { SOC->gpio[GPIO_A].idr_mask |= 0x2000; } @@ -71,13 +76,13 @@ static void prusa_mini_init(MachineState *machine) load_image_targphys(machine->kernel_filename,0x20000-64,get_image_size(machine->kernel_filename)); armv7m_load_kernel(ARM_CPU(first_cpu), BOOTLOADER_IMAGE, - FLASH_SIZE); + default_flash_size); } else // Raw bin or ELF file, load directly. { armv7m_load_kernel(ARM_CPU(first_cpu), machine->kernel_filename, - FLASH_SIZE); + default_flash_size); } } @@ -314,25 +319,17 @@ static void prusa_mini_init(MachineState *machine) static void prusa_mini_machine_init(MachineClass *mc) { - mc->desc = "Prusa Mini Board"; + mc->desc = "Prusa Mini"; mc->init = prusa_mini_init; + mc->default_ram_size = F407_SRAM_SIZE; } DEFINE_MACHINE("prusa-mini", prusa_mini_machine_init) - -// TODO - remove this at some point in the future... - -static void buddy_init(MachineState *machine) -{ - error_setg(&error_fatal, "-machine prusabuddy has been deprecated. Please use -machine prusa-mini instead.\n"); -}; - - static void buddy_machine_init(MachineClass *mc) { - mc->desc = "Prusa Mini Board (Deprecated)"; - mc->init = buddy_init; + mc->desc = "Prusa Mini Board"; + mc->deprecation_reason = "prusabuddy has been deprecated because it's a board, not a machine. Use -machine prusa-mini instead"; } DEFINE_MACHINE("prusabuddy", buddy_machine_init) diff --git a/hw/arm/prusa/stm32f407/stm32f407_soc.c b/hw/arm/prusa/stm32f407/stm32f407_soc.c index 72e506c424..bc4c59aaa7 100644 --- a/hw/arm/prusa/stm32f407/stm32f407_soc.c +++ b/hw/arm/prusa/stm32f407/stm32f407_soc.c @@ -33,6 +33,7 @@ #include "net/net.h" #include "hw/i2c/smbus_eeprom.h" #include "exec/ramblock.h" +#include "hw/qdev-properties.h" #define SYSCFG_ADD 0x40013800 static const uint32_t usart_addr[] = { 0x40011000, 0x40004400, 0x40004800, 0x40004C00, 0x40005000, 0x40011400, @@ -194,7 +195,7 @@ static void stm32f407_soc_realize(DeviceState *dev_soc, Error **errp) memory_region_add_subregion(system_memory, FLASH_BASE_ADDRESS, &s->flash); memory_region_add_subregion(system_memory, 0, &s->flash_alias); - memory_region_init_ram(&s->sram, NULL, "STM32F407.sram", SRAM_SIZE, + memory_region_init_ram(&s->sram, NULL, "STM32F407.sram", s->ram_size, &err); if (err != NULL) { error_propagate(errp, err); @@ -560,6 +561,7 @@ static void stm32f407_soc_realize(DeviceState *dev_soc, Error **errp) static Property stm32f407_soc_properties[] = { DEFINE_PROP_STRING("cpu-type", STM32F407State, cpu_type), + DEFINE_PROP_UINT32("sram-size",STM32F407State, ram_size, 192*KiB), DEFINE_PROP_END_OF_LIST(), }; diff --git a/hw/arm/prusa/stm32f407/stm32f407_soc.h b/hw/arm/prusa/stm32f407/stm32f407_soc.h index 4cc40458a3..9a6477505e 100644 --- a/hw/arm/prusa/stm32f407/stm32f407_soc.h +++ b/hw/arm/prusa/stm32f407/stm32f407_soc.h @@ -28,7 +28,7 @@ #include "hw/misc/stm32f4xx_syscfg.h" #include "hw/timer/stm32f2xx_timer.h" -// #include "hw/char/stm32f2xx_usart.h" +#include "qemu/units.h" #include "hw/misc/stm32f4xx_exti.h" #include "hw/or-irq.h" #include "stm32f4xx_adc.h" @@ -64,9 +64,9 @@ OBJECT_DECLARE_SIMPLE_TYPE(STM32F407State, STM32F407_SOC) #define STM_NUM_DMAS 2 #define FLASH_BASE_ADDRESS 0x08000000 -#define FLASH_SIZE (1024 * 1024) +#define FLASH_SIZE (1U *MiB) #define SRAM_BASE_ADDRESS 0x20000000 -#define SRAM_SIZE (192 * 1024) +#define F407_SRAM_SIZE (192 * KiB) // Convenience enum. @@ -135,6 +135,8 @@ struct STM32F407State { MemoryRegion ccmsram; MemoryRegion temp_usb; + uint32_t ram_size; + }; #endif