hw/avr: Introduce the Arduino boards
v3 cover hw/avr: Introduce the Arduino boards
Hi,
This series add the arduino boards, aiming at removing the 'sample' board that doesn't follow any specification.
Since v2:
- rebased on Michael's v40
Since v1:
- Addressed Igor comments
- Addressed Aleksandar comments
- Fixed UART issue (was due to IRQ shifted by 2 in CPU)
TODO after merge is:
- Extract Timer8 common parts from Timer16
- Add GPIOs
- Connect LED to GPIO on Arduino
- Plug to Scratch (See http://s4a.cat/).
(I plan to purpose that as a GSoC idea).
Michael, thank you for having insisted with this port during so long!
Regards,
Phil.
Series available at https://gitlab.com/philmd/qemu/commits/arduino-v3
Regards,
Phil.
Based-on: <[email protected]>
https://lists.gnu.org/archive/html/qemu-devel/2019-12/msg05309.html
Philippe Mathieu-Daudé (8):
hw/char/avr: Reduce USART I/O size
hw/timer/avr_timer16: Rename memory region debugging name hw/avr: Add some ATmega microcontrollers
hw/avr: Add some Arduino boards
tests/boot-serial-test: Test some Arduino boards (AVR based) tests/acceptance: Do not set the machine type manually tests/acceptance: Keep multilines comment consistent with other tests tests/acceptance: Test the Arduino MEGA2560 board
hw/avr/atmega.h | 48 ++++ hw/avr/arduino.c | 177 ++++++++++++ hw/avr/atmega.c | 464 +++++++++++++++++++++++++++++++ hw/char/avr_usart.c | 2 +- hw/timer/avr_timer16.c | 6 +- tests/boot-serial-test.c | 2 + hw/avr/Makefile.objs | 2 + tests/acceptance/machine_avr6.py | 11 +- 8 files changed, 701 insertions(+), 11 deletions(-) create mode 100644 hw/avr/atmega.h create mode 100644 hw/avr/arduino.c create mode 100644 hw/avr/atmega.c
Signature · 1 line
2.21.0
PATCH v3 1/8 hw/char/avr: Reduce USART I/O size
Per the datasheet the USART uses 7 consecutive 8-bit registers.
--- hw/char/avr_usart.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/char/avr_usart.c +1 -1
@@ -280,7 +280,7 @@ static void avr_usart_init(Object *obj)sysbus_init_irq (SYS_BUS_DEVICE (obj), &s->rxc_irq);sysbus_init_irq (SYS_BUS_DEVICE (obj), &s->dre_irq);sysbus_init_irq (SYS_BUS_DEVICE (obj), &s->txc_irq); -memory_region_init_io (&s->mmio, obj, &avr_usart_ops, s,TYPE_AVR_USART ,8 ); +memory_region_init_io (&s->mmio, obj, &avr_usart_ops, s,TYPE_AVR_USART ,7 );sysbus_init_mmio (SYS_BUS_DEVICE (obj), &s->mmio);qdev_init_gpio_in (DEVICE (s), avr_usart_pr,1 ); s->enabled = true;
Signature · 1 line
2.21.0
PATCH v3 2/8 hw/timer/avr_timer16: Rename memory region debugging name
In reply to Philippe Mathieu-DaudéThis device expose 3 different I/O regions. Name them differently to have a clearer 'info mtree' output.
--- hw/timer/avr_timer16.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
hw/timer/avr_timer16.c +3 -3
@@ -563,11 +563,11 @@ static void avr_timer16_init(Object *obj)sysbus_init_irq (SYS_BUS_DEVICE (obj), &s->ovf_irq);memory_region_init_io (&s->iomem, obj, &avr_timer16_ops, - s,TYPE_AVR_TIMER16 ,0xe ); + s,"avr-timer16" ,0xe );memory_region_init_io (&s->imsk_iomem, obj, &avr_timer16_imsk_ops, - s,TYPE_AVR_TIMER16 ,0x1 ); + s,"avr-timer16-intmask" ,0x1 );memory_region_init_io (&s->ifr_iomem, obj, &avr_timer16_ifr_ops, - s,TYPE_AVR_TIMER16 ,0x1 ); + s,"avr-timer16-intflag" ,0x1 );sysbus_init_mmio (SYS_BUS_DEVICE (obj), &s->iomem);sysbus_init_mmio (SYS_BUS_DEVICE (obj), &s->imsk_iomem);
Signature · 1 line
2.21.0
PATCH v3 3/8 hw/avr: Add some ATmega microcontrollers
In reply to Philippe Mathieu-DaudéAdd some microcontrollers from the megaAVR family (ATmega series):
- middle range: ATmega168 and ATmega328
- high range: ATmega1280 and ATmega2560
For product comparison:
https://www.microchip.com/wwwproducts/ProductCompare/ATmega168P/ATmega328P
https://www.microchip.com/wwwproducts/ProductCompare/ATmega1280/ATmega2560
Datasheets:
http://ww1.microchip.com/downloads/en/DeviceDoc/ATmega48A-PA-88A-PA-168A-PA-328-P-DS-DS40002061A.pdf
http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-2549-8-bit-AVR-Microcontroller-ATmega640-1280-1281-2560-2561_datasheet.pdf
---
v2:
- Reword description adding more information (Aleksandar)
- Use DEFINE_TYPES and memory_region_init_ram (Igor)
--- hw/avr/atmega.h | 48 +++++ hw/avr/atmega.c | 464 +++++++++++++++++++++++++++++++++++++++++++ hw/avr/Makefile.objs | 1 + 3 files changed, 513 insertions(+) create mode 100644 hw/avr/atmega.h create mode 100644 hw/avr/atmega.c
hw/avr/atmega.h new file +48 -0
@@ -0,0 +1,48 @@ +/* +* QEMU ATmega MCU +* +* Copyright (c) 2019 Philippe Mathieu-Daudé +* +* This work is licensed under the terms of the GNU GPLv2 or later. +* See the COPYING file in the top-level directory. +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef HW_AVR_ATMEGA_H +#define HW_AVR_ATMEGA_H + +#include "hw/char/avr_usart.h" +#include "hw/timer/avr_timer16.h" +#include "hw/misc/avr_mask.h" +#include "target/avr/cpu.h" + +#define TYPE_ATMEGA_MCU "ATmega" +#define TYPE_ATMEGA168_MCU "ATmega168" +#define TYPE_ATMEGA328_MCU "ATmega328" +#define TYPE_ATMEGA1280_MCU "ATmega1280" +#define TYPE_ATMEGA2560_MCU "ATmega2560" + +#define ATMEGA_MCU (obj) OBJECT_CHECK(AtmegaMcuState, (obj), TYPE_ATMEGA_MCU) + +#define POWER_MAX 2 +#define USART_MAX 4 +#define TIMER_MAX 6 +#define GPIO_MAX 12 + +typedef struct AtmegaMcuState { +/*< private >*/ +SysBusDevice parent_obj; +/*< public >*/ + +AVRCPU cpu; +MemoryRegion flash; +MemoryRegion eeprom; +MemoryRegion sram; +DeviceState *io; +AVRMaskState pwr[POWER_MAX ]; +AVRUsartState usart[USART_MAX ]; +AVRTimer16State timer[TIMER_MAX ]; +uint64_t xtal_freq_hz; +}AtmegaMcuState ; + +#endif /* HW_AVR_ATMEGA_H */
hw/avr/atmega.c new file +464 -0
464 lines not on this page · raw message
hw/avr/Makefile.objs +1 -0
@@ -1 +1,2 @@ obj-y += sample.o +obj-y += atmega.o
Signature · 1 line
2.21.0
PATCH v3 4/8 hw/avr: Add some Arduino boards
In reply to Philippe Mathieu-DaudéArduino boards are build with AVR chipsets.
Add some of the popular boards:
- Arduino Duemilanove
- Arduino Uno
- Arduino Mega
For more information:
https://www.arduino.cc/en/Main/Products
https://store.arduino.cc/arduino-genuino/most-popular
---
v2:
- Reword description adding more information (Aleksandar)
- Use DEFINE_TYPES (Igor)
--- hw/avr/arduino.c | 177 +++++++++++++++++++++++++++++++++++++++++++ hw/avr/Makefile.objs | 1 + 2 files changed, 178 insertions(+) create mode 100644 hw/avr/arduino.c
hw/avr/arduino.c new file +177 -0
@@ -0,0 +1,177 @@ +/* +* QEMU Arduino boards +* +* Copyright (c) 2019 Philippe Mathieu-Daudé +* +* This work is licensed under the terms of the GNU GPLv2 or later. +* See the COPYING file in the top-level directory. +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +/* TODO: Implement the use of EXTRAM */ + +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "qapi/error.h" +#include "hw/boards.h" +#include "hw/loader.h" +#include "elf.h" +#include "atmega.h" + +typedef struct ArduinoMachineState { +/*< private >*/ +MachineState parent_obj; +/*< public >*/ +AtmegaMcuState mcu; +MemoryRegion extram; +}ArduinoMachineState ; + +typedef struct ArduinoMachineClass { +/*< private >*/ +MachineClass parent_class; +/*< public >*/ +const char *mcu_type; +uint64_t xtal_hz; +size_t extram_size; +}ArduinoMachineClass ; + +#define TYPE_ARDUINO_MACHINE \ + MACHINE_TYPE_NAME("arduino") +#define ARDUINO_MACHINE (obj) \ + OBJECT_CHECK(ArduinoMachineState, (obj), TYPE_ARDUINO_MACHINE) +#define ARDUINO_MACHINE_CLASS (klass) \ + OBJECT_CLASS_CHECK(ArduinoMachineClass, (klass), TYPE_ARDUINO_MACHINE) +#define ARDUINO_MACHINE_GET_CLASS (obj) \ + OBJECT_GET_CLASS(ArduinoMachineClass, (obj), TYPE_ARDUINO_MACHINE) + +static void load_firmware (const char *firmware,uint64_t flash_size) +{ +const char *filename; +int bytes_loaded; + +/* Load firmware (contents of flash) trying to auto-detect format */ + filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , firmware); +if (filename ==NULL ) { +error_report ("Unable to find %s" , firmware); +exit (1 ); + } + + bytes_loaded =load_elf (filename,NULL ,NULL ,NULL ,NULL ,NULL ,NULL , +0 ,EM_NONE ,0 ,0 ); +if (bytes_loaded <0 ) { + bytes_loaded =load_image_targphys (filename,OFFSET_CODE , flash_size); + } +if (bytes_loaded <0 ) { +error_report ("Unable to load firmware image %s as ELF or raw binary" , + firmware); +exit (1 ); + } +} + +static void arduino_machine_init (MachineState *machine) +{ +ArduinoMachineClass *amc =ARDUINO_MACHINE_GET_CLASS (machine); +ArduinoMachineState *ams =ARDUINO_MACHINE (machine); + +sysbus_init_child_obj (OBJECT (machine),"mcu" , &ams->mcu,sizeof (ams->mcu), + amc->mcu_type); +object_property_set_uint (OBJECT (&ams->mcu), amc->xtal_hz, +"xtal-frequency-hz" , &error_abort); +object_property_set_bool (OBJECT (&ams->mcu), true,"realized" , + &error_abort); + +if (machine->firmware) { +load_firmware (machine->firmware,memory_region_size (&ams->mcu.flash)); + } +} + +static void arduino_machine_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); + + mc->init = arduino_machine_init; + mc->default_cpus =1 ; + mc->min_cpus = mc->default_cpus; + mc->max_cpus = mc->default_cpus; + mc->no_floppy =1 ; + mc->no_cdrom =1 ; + mc->no_parallel =1 ; +} + +static void arduino_duemilanove_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); +ArduinoMachineClass *amc =ARDUINO_MACHINE_CLASS (oc); + +/* https://www.arduino.cc/en/Main/ArduinoBoardDuemilanove */ + mc->desc ="Arduino Duemilanove (ATmega168)" , + mc->alias ="2009" ; + amc->mcu_type =TYPE_ATMEGA168_MCU ; + amc->xtal_hz =16 *1000 *1000 ; +}; + +static void arduino_uno_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); +ArduinoMachineClass *amc =ARDUINO_MACHINE_CLASS (oc); + +/* https://store.arduino.cc/arduino-uno-rev3 */ + mc->desc ="Arduino UNO (ATmega328P)" ; + mc->alias ="uno" ; + amc->mcu_type =TYPE_ATMEGA328_MCU ; + amc->xtal_hz =16 *1000 *1000 ; +}; + +static void arduino_mega_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); +ArduinoMachineClass *amc =ARDUINO_MACHINE_CLASS (oc); + +/* https://www.arduino.cc/en/Main/ArduinoBoardMega */ + mc->desc ="Arduino Mega (ATmega1280)" ; + mc->alias ="mega" ; + amc->mcu_type =TYPE_ATMEGA1280_MCU ; + amc->xtal_hz =16 *1000 *1000 ; +}; + +static void arduino_mega2560_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); +ArduinoMachineClass *amc =ARDUINO_MACHINE_CLASS (oc); + +/* https://store.arduino.cc/arduino-mega-2560-rev3 */ + mc->desc ="Arduino Mega 2560 (ATmega2560)" ; + mc->alias ="mega2560" ; + mc->is_default = true; + amc->mcu_type =TYPE_ATMEGA2560_MCU ; + amc->xtal_hz =16 *1000 *1000 ;/* CSTCE16M0V53-R0 */ +}; + +static const TypeInfo arduino_machine_types[] = { + { + .name =MACHINE_TYPE_NAME ("arduino-duemilanove" ), + .parent =TYPE_ARDUINO_MACHINE , + .class_init = arduino_duemilanove_class_init, + }, { + .name =MACHINE_TYPE_NAME ("arduino-uno" ), + .parent =TYPE_ARDUINO_MACHINE , + .class_init = arduino_uno_class_init, + }, { + .name =MACHINE_TYPE_NAME ("arduino-mega" ), + .parent =TYPE_ARDUINO_MACHINE , + .class_init = arduino_mega_class_init, + }, { + .name =MACHINE_TYPE_NAME ("arduino-mega-2560-v3" ), + .parent =TYPE_ARDUINO_MACHINE , + .class_init = arduino_mega2560_class_init, + }, { + .name =TYPE_ARDUINO_MACHINE , + .parent =TYPE_MACHINE , + .instance_size =sizeof (ArduinoMachineState), + .class_size =sizeof (ArduinoMachineClass), + .class_init = arduino_machine_class_init, + .abstract = true, + } +}; + +DEFINE_TYPES (arduino_machine_types)
hw/avr/Makefile.objs +1 -0
@@ -1,2 +1,3 @@ obj-y += sample.o obj-y += atmega.o +obj-y += arduino.o
Signature · 1 line
2.21.0
Re: [PATCH v3 4/8] hw/avr: Add some Arduino boards
Quoted 52 lines · On Sun, 29 Dec 2019 23:45:01 +0100 Philippe Mathieu-Daudé <[email protected]>…
Arduino boards are build with AVR chipsets.
Add some of the popular boards:- Arduino Duemilanove
- Arduino Uno
- Arduino MegaFor more information:
https://www.arduino.cc/en/Main/Products
https://store.arduino.cc/arduino-genuino/most-popularSigned-off-by Philippe Mathieu-Daudé <[email protected]>---
v2:
- Reword description adding more information (Aleksandar)
- UseDEFINE_TYPES(Igor)Cc Phillip Stevens <[email protected]>Cc Igor Mammedov <[email protected]>--- hw/avr/arduino.c | 177 +++++++++++++++++++++++++++++++++++++++++++ hw/avr/Makefile.objs | 1 + 2 files changed, 178 insertions(+) create mode 100644 hw/avr/arduino.chw/avr/arduino.c new file +21
-0@@ -0,0 +1,177 @@ +/* +* QEMU Arduino boards +* +* Copyright (c) 2019 Philippe Mathieu-Daudé +* +* This work is licensed under the terms of the GNU GPLv2 or later. +* See the COPYING file in the top-level directory. +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +/* TODO: Implement the use of EXTRAM */ + +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "qapi/error.h" +#include "hw/boards.h" +#include "hw/loader.h" +#include "elf.h" +#include "atmega.h" + +typedef struct ArduinoMachineState {
[...]
Quoted 4 lines
hw/avr/arduino.c new file +4
-0+MemoryRegion extram; +} ArduinoMachineState; + +typedef struct ArduinoMachineClass {
[...]
Quoted 1 line
+
size_textram_size;
extfoo doesn't seem to be used in this patch
Quoted 150 lines
hw/avr/arduino.c new file +142
-0+} ArduinoMachineClass; + +#define TYPE_ARDUINO_MACHINE \ + MACHINE_TYPE_NAME("arduino") +#define ARDUINO_MACHINE (obj) \ + OBJECT_CHECK(ArduinoMachineState, (obj), TYPE_ARDUINO_MACHINE) +#define ARDUINO_MACHINE_CLASS (klass) \ + OBJECT_CLASS_CHECK(ArduinoMachineClass, (klass), TYPE_ARDUINO_MACHINE) +#define ARDUINO_MACHINE_GET_CLASS (obj) \ + OBJECT_GET_CLASS(ArduinoMachineClass, (obj), TYPE_ARDUINO_MACHINE) + +static void load_firmware (const char *firmware,uint64_t flash_size) +{ +const char *filename; +int bytes_loaded; + +/* Load firmware (contents of flash) trying to auto-detect format */ + filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , firmware); +if (filename ==NULL ) { +error_report ("Unable to find %s" , firmware); +exit (1 ); + } + + bytes_loaded =load_elf (filename,NULL ,NULL ,NULL ,NULL ,NULL ,NULL , +0 ,EM_NONE ,0 ,0 ); +if (bytes_loaded <0 ) { + bytes_loaded =load_image_targphys (filename,OFFSET_CODE , flash_size); + } +if (bytes_loaded <0 ) { +error_report ("Unable to load firmware image %s as ELF or raw binary" , + firmware); +exit (1 ); + } +} + +static void arduino_machine_init (MachineState *machine) +{ +ArduinoMachineClass *amc =ARDUINO_MACHINE_GET_CLASS (machine); +ArduinoMachineState *ams =ARDUINO_MACHINE (machine); + +sysbus_init_child_obj (OBJECT (machine),"mcu" , &ams->mcu,sizeof (ams->mcu), + amc->mcu_type); +object_property_set_uint (OBJECT (&ams->mcu), amc->xtal_hz, +"xtal-frequency-hz" , &error_abort); +object_property_set_bool (OBJECT (&ams->mcu), true,"realized" , + &error_abort); + +if (machine->firmware) { +load_firmware (machine->firmware,memory_region_size (&ams->mcu.flash)); + } +} + +static void arduino_machine_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); + + mc->init = arduino_machine_init; + mc->default_cpus =1 ; + mc->min_cpus = mc->default_cpus; + mc->max_cpus = mc->default_cpus; + mc->no_floppy =1 ; + mc->no_cdrom =1 ; + mc->no_parallel =1 ; +} + +static void arduino_duemilanove_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); +ArduinoMachineClass *amc =ARDUINO_MACHINE_CLASS (oc); + +/* https://www.arduino.cc/en/Main/ArduinoBoardDuemilanove */ + mc->desc ="Arduino Duemilanove (ATmega168)" , + mc->alias ="2009" ; + amc->mcu_type =TYPE_ATMEGA168_MCU ; + amc->xtal_hz =16 *1000 *1000 ; +}; + +static void arduino_uno_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); +ArduinoMachineClass *amc =ARDUINO_MACHINE_CLASS (oc); + +/* https://store.arduino.cc/arduino-uno-rev3 */ + mc->desc ="Arduino UNO (ATmega328P)" ; + mc->alias ="uno" ; + amc->mcu_type =TYPE_ATMEGA328_MCU ; + amc->xtal_hz =16 *1000 *1000 ; +}; + +static void arduino_mega_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); +ArduinoMachineClass *amc =ARDUINO_MACHINE_CLASS (oc); + +/* https://www.arduino.cc/en/Main/ArduinoBoardMega */ + mc->desc ="Arduino Mega (ATmega1280)" ; + mc->alias ="mega" ; + amc->mcu_type =TYPE_ATMEGA1280_MCU ; + amc->xtal_hz =16 *1000 *1000 ; +}; + +static void arduino_mega2560_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); +ArduinoMachineClass *amc =ARDUINO_MACHINE_CLASS (oc); + +/* https://store.arduino.cc/arduino-mega-2560-rev3 */ + mc->desc ="Arduino Mega 2560 (ATmega2560)" ; + mc->alias ="mega2560" ; + mc->is_default = true; + amc->mcu_type =TYPE_ATMEGA2560_MCU ; + amc->xtal_hz =16 *1000 *1000 ;/* CSTCE16M0V53-R0 */ +}; + +static const TypeInfo arduino_machine_types[] = { + { + .name =MACHINE_TYPE_NAME ("arduino-duemilanove" ), + .parent =TYPE_ARDUINO_MACHINE , + .class_init = arduino_duemilanove_class_init, + }, { + .name =MACHINE_TYPE_NAME ("arduino-uno" ), + .parent =TYPE_ARDUINO_MACHINE , + .class_init = arduino_uno_class_init, + }, { + .name =MACHINE_TYPE_NAME ("arduino-mega" ), + .parent =TYPE_ARDUINO_MACHINE , + .class_init = arduino_mega_class_init, + }, { + .name =MACHINE_TYPE_NAME ("arduino-mega-2560-v3" ), + .parent =TYPE_ARDUINO_MACHINE , + .class_init = arduino_mega2560_class_init, + }, { + .name =TYPE_ARDUINO_MACHINE , + .parent =TYPE_MACHINE , + .instance_size =sizeof (ArduinoMachineState), + .class_size =sizeof (ArduinoMachineClass), + .class_init = arduino_machine_class_init, + .abstract = true, + } +}; + +DEFINE_TYPES (arduino_machine_types)hw/avr/Makefile.objs +1
-0@@ -1,2 +1,3 @@ obj-y += sample.o obj-y += atmega.o +obj-y += arduino.o
Re: [PATCH v3 4/8] hw/avr: Add some Arduino boards
Quoted 56 lines · Igor Mammedov
Quoted 52 lines · On Sun, 29 Dec 2019 23:45:01 +0100 Philippe Mathieu-Daudé <[email protected]>…
Arduino boards are build with AVR chipsets.
Add some of the popular boards:- Arduino Duemilanove
- Arduino Uno
- Arduino MegaFor more information:
https://www.arduino.cc/en/Main/Products
https://store.arduino.cc/arduino-genuino/most-popularSigned-off-by Philippe Mathieu-Daudé <[email protected]>---
v2:
- Reword description adding more information (Aleksandar)
- UseDEFINE_TYPES(Igor)Cc Phillip Stevens <[email protected]>Cc Igor Mammedov <[email protected]>--- hw/avr/arduino.c | 177 +++++++++++++++++++++++++++++++++++++++++++ hw/avr/Makefile.objs | 1 + 2 files changed, 178 insertions(+)create mode 100644
hw/avr/arduino.chw/avr/arduino.c new file +21
-0@@ -0,0 +1,177 @@ +/* +* QEMU Arduino boards +* +* Copyright (c) 2019 Philippe Mathieu-Daudé +* +* This work is licensed under the terms of the GNU GPLv2 or later. +* See the COPYING file in the top-level directory. +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +/* TODO: Implement the use of EXTRAM */ + +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "qapi/error.h" +#include "hw/boards.h" +#include "hw/loader.h" +#include "elf.h" +#include "atmega.h" + +typedef struct ArduinoMachineState {[...]
Quoted 8 lines
Quoted 4 lines
hw/avr/arduino.c new file +4
-0+MemoryRegion extram; +} ArduinoMachineState; + +typedef struct ArduinoMachineClass {[...]
Quoted 1 line
+
size_textram_size;extfoo doesn't seem to be used in this patch
Ah leftover from adapting from the 'sample' board which has SIZE_EXMEM=0 so I ended removing a chunk and forgot this field.
Can I add your R-b tag when respining this patch without the field?
Quoted 152 lines
Quoted 150 lines
hw/avr/arduino.c new file +142
-0+} ArduinoMachineClass; + +#define TYPE_ARDUINO_MACHINE \ + MACHINE_TYPE_NAME("arduino") +#define ARDUINO_MACHINE (obj) \ + OBJECT_CHECK(ArduinoMachineState, (obj), TYPE_ARDUINO_MACHINE) +#define ARDUINO_MACHINE_CLASS (klass) \ + OBJECT_CLASS_CHECK(ArduinoMachineClass, (klass), TYPE_ARDUINO_MACHINE) +#define ARDUINO_MACHINE_GET_CLASS (obj) \ + OBJECT_GET_CLASS(ArduinoMachineClass, (obj), TYPE_ARDUINO_MACHINE) + +static void load_firmware (const char *firmware,uint64_t flash_size) +{ +const char *filename; +int bytes_loaded; + +/* Load firmware (contents of flash) trying to auto-detect format */ + filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , firmware); +if (filename ==NULL ) { +error_report ("Unable to find %s" , firmware); +exit (1 ); + } + + bytes_loaded =load_elf (filename,NULL ,NULL ,NULL ,NULL ,NULL ,NULL , +0 ,EM_NONE ,0 ,0 ); +if (bytes_loaded <0 ) { + bytes_loaded =load_image_targphys (filename,OFFSET_CODE , flash_size); + } +if (bytes_loaded <0 ) { +error_report ("Unable to load firmware image %s as ELF or raw binary" , + firmware); +exit (1 ); + } +} + +static void arduino_machine_init (MachineState *machine) +{ +ArduinoMachineClass *amc =ARDUINO_MACHINE_GET_CLASS (machine); +ArduinoMachineState *ams =ARDUINO_MACHINE (machine); + +sysbus_init_child_obj (OBJECT (machine),"mcu" , &ams->mcu,sizeof (ams->mcu), + amc->mcu_type); +object_property_set_uint (OBJECT (&ams->mcu), amc->xtal_hz, +"xtal-frequency-hz" , &error_abort); +object_property_set_bool (OBJECT (&ams->mcu), true,"realized" , + &error_abort); + +if (machine->firmware) { +load_firmware (machine->firmware,memory_region_size (&ams->mcu.flash)); + } +} + +static void arduino_machine_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); + + mc->init = arduino_machine_init; + mc->default_cpus =1 ; + mc->min_cpus = mc->default_cpus; + mc->max_cpus = mc->default_cpus; + mc->no_floppy =1 ; + mc->no_cdrom =1 ; + mc->no_parallel =1 ; +} + +static void arduino_duemilanove_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); +ArduinoMachineClass *amc =ARDUINO_MACHINE_CLASS (oc); + +/* https://www.arduino.cc/en/Main/ArduinoBoardDuemilanove */ + mc->desc ="Arduino Duemilanove (ATmega168)" , + mc->alias ="2009" ; + amc->mcu_type =TYPE_ATMEGA168_MCU ; + amc->xtal_hz =16 *1000 *1000 ; +}; + +static void arduino_uno_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); +ArduinoMachineClass *amc =ARDUINO_MACHINE_CLASS (oc); + +/* https://store.arduino.cc/arduino-uno-rev3 */ + mc->desc ="Arduino UNO (ATmega328P)" ; + mc->alias ="uno" ; + amc->mcu_type =TYPE_ATMEGA328_MCU ; + amc->xtal_hz =16 *1000 *1000 ; +}; + +static void arduino_mega_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); +ArduinoMachineClass *amc =ARDUINO_MACHINE_CLASS (oc); + +/* https://www.arduino.cc/en/Main/ArduinoBoardMega */ + mc->desc ="Arduino Mega (ATmega1280)" ; + mc->alias ="mega" ; + amc->mcu_type =TYPE_ATMEGA1280_MCU ; + amc->xtal_hz =16 *1000 *1000 ; +}; + +static void arduino_mega2560_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); +ArduinoMachineClass *amc =ARDUINO_MACHINE_CLASS (oc); + +/* https://store.arduino.cc/arduino-mega-2560-rev3 */ + mc->desc ="Arduino Mega 2560 (ATmega2560)" ; + mc->alias ="mega2560" ; + mc->is_default = true; + amc->mcu_type =TYPE_ATMEGA2560_MCU ; + amc->xtal_hz =16 *1000 *1000 ;/* CSTCE16M0V53-R0 */ +}; + +static const TypeInfo arduino_machine_types[] = { + { + .name =MACHINE_TYPE_NAME ("arduino-duemilanove" ), + .parent =TYPE_ARDUINO_MACHINE , + .class_init = arduino_duemilanove_class_init, + }, { + .name =MACHINE_TYPE_NAME ("arduino-uno" ), + .parent =TYPE_ARDUINO_MACHINE , + .class_init = arduino_uno_class_init, + }, { + .name =MACHINE_TYPE_NAME ("arduino-mega" ), + .parent =TYPE_ARDUINO_MACHINE , + .class_init = arduino_mega_class_init, + }, { + .name =MACHINE_TYPE_NAME ("arduino-mega-2560-v3" ), + .parent =TYPE_ARDUINO_MACHINE , + .class_init = arduino_mega2560_class_init, + }, { + .name =TYPE_ARDUINO_MACHINE , + .parent =TYPE_MACHINE , + .instance_size =sizeof (ArduinoMachineState), + .class_size =sizeof (ArduinoMachineClass), + .class_init = arduino_machine_class_init, + .abstract = true, + } +}; + +DEFINE_TYPES (arduino_machine_types)hw/avr/Makefile.objs +1
-0@@ -1,2 +1,3 @@ obj-y += sample.o obj-y += atmega.o +obj-y += arduino.o
Re: [PATCH v3 4/8] hw/avr: Add some Arduino boards
Quoted 62 lines · On Mon, 20 Jan 2020 10:21:52 +0100 Philippe Mathieu-Daudé <[email protected]>…
Quoted 61 lines · Igor Mammedov
Quoted 52 lines · On Sun, 29 Dec 2019 23:45:01 +0100 Philippe Mathieu-Daudé <[email protected]>…
Arduino boards are build with AVR chipsets.
Add some of the popular boards:- Arduino Duemilanove
- Arduino Uno
- Arduino MegaFor more information:
https://www.arduino.cc/en/Main/Products
https://store.arduino.cc/arduino-genuino/most-popularSigned-off-by Philippe Mathieu-Daudé <[email protected]>---
v2:
- Reword description adding more information (Aleksandar)
- UseDEFINE_TYPES(Igor)Cc Phillip Stevens <[email protected]>Cc Igor Mammedov <[email protected]>--- hw/avr/arduino.c | 177 +++++++++++++++++++++++++++++++++++++++++++ hw/avr/Makefile.objs | 1 + 2 files changed, 178 insertions(+)create mode 100644
hw/avr/arduino.chw/avr/arduino.c new file +21
-0@@ -0,0 +1,177 @@ +/* +* QEMU Arduino boards +* +* Copyright (c) 2019 Philippe Mathieu-Daudé +* +* This work is licensed under the terms of the GNU GPLv2 or later. +* See the COPYING file in the top-level directory. +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +/* TODO: Implement the use of EXTRAM */ + +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "qapi/error.h" +#include "hw/boards.h" +#include "hw/loader.h" +#include "elf.h" +#include "atmega.h" + +typedef struct ArduinoMachineState {[...]
Quoted 4 lines
hw/avr/arduino.c new file +4
-0+MemoryRegion extram; +} ArduinoMachineState; + +typedef struct ArduinoMachineClass {[...]
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
+
size_textram_size;extfoo doesn't seem to be used in this patch
Ah leftover from adapting from the 'sample' board which has SIZE_EXMEM=0 so I ended removing a chunk and forgot this field.
Can I add your R-b tag when respining this patch without the field?
sure
later on we need to make up some generic way for machine to say that -m is not supported to avoid useless/confusing option where board doesn't care about it.
Quoted 153 lines
Quoted 152 lines
Quoted 150 lines
hw/avr/arduino.c new file +142
-0+} ArduinoMachineClass; + +#define TYPE_ARDUINO_MACHINE \ + MACHINE_TYPE_NAME("arduino") +#define ARDUINO_MACHINE (obj) \ + OBJECT_CHECK(ArduinoMachineState, (obj), TYPE_ARDUINO_MACHINE) +#define ARDUINO_MACHINE_CLASS (klass) \ + OBJECT_CLASS_CHECK(ArduinoMachineClass, (klass), TYPE_ARDUINO_MACHINE) +#define ARDUINO_MACHINE_GET_CLASS (obj) \ + OBJECT_GET_CLASS(ArduinoMachineClass, (obj), TYPE_ARDUINO_MACHINE) + +static void load_firmware (const char *firmware,uint64_t flash_size) +{ +const char *filename; +int bytes_loaded; + +/* Load firmware (contents of flash) trying to auto-detect format */ + filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , firmware); +if (filename ==NULL ) { +error_report ("Unable to find %s" , firmware); +exit (1 ); + } + + bytes_loaded =load_elf (filename,NULL ,NULL ,NULL ,NULL ,NULL ,NULL , +0 ,EM_NONE ,0 ,0 ); +if (bytes_loaded <0 ) { + bytes_loaded =load_image_targphys (filename,OFFSET_CODE , flash_size); + } +if (bytes_loaded <0 ) { +error_report ("Unable to load firmware image %s as ELF or raw binary" , + firmware); +exit (1 ); + } +} + +static void arduino_machine_init (MachineState *machine) +{ +ArduinoMachineClass *amc =ARDUINO_MACHINE_GET_CLASS (machine); +ArduinoMachineState *ams =ARDUINO_MACHINE (machine); + +sysbus_init_child_obj (OBJECT (machine),"mcu" , &ams->mcu,sizeof (ams->mcu), + amc->mcu_type); +object_property_set_uint (OBJECT (&ams->mcu), amc->xtal_hz, +"xtal-frequency-hz" , &error_abort); +object_property_set_bool (OBJECT (&ams->mcu), true,"realized" , + &error_abort); + +if (machine->firmware) { +load_firmware (machine->firmware,memory_region_size (&ams->mcu.flash)); + } +} + +static void arduino_machine_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); + + mc->init = arduino_machine_init; + mc->default_cpus =1 ; + mc->min_cpus = mc->default_cpus; + mc->max_cpus = mc->default_cpus; + mc->no_floppy =1 ; + mc->no_cdrom =1 ; + mc->no_parallel =1 ; +} + +static void arduino_duemilanove_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); +ArduinoMachineClass *amc =ARDUINO_MACHINE_CLASS (oc); + +/* https://www.arduino.cc/en/Main/ArduinoBoardDuemilanove */ + mc->desc ="Arduino Duemilanove (ATmega168)" , + mc->alias ="2009" ; + amc->mcu_type =TYPE_ATMEGA168_MCU ; + amc->xtal_hz =16 *1000 *1000 ; +}; + +static void arduino_uno_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); +ArduinoMachineClass *amc =ARDUINO_MACHINE_CLASS (oc); + +/* https://store.arduino.cc/arduino-uno-rev3 */ + mc->desc ="Arduino UNO (ATmega328P)" ; + mc->alias ="uno" ; + amc->mcu_type =TYPE_ATMEGA328_MCU ; + amc->xtal_hz =16 *1000 *1000 ; +}; + +static void arduino_mega_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); +ArduinoMachineClass *amc =ARDUINO_MACHINE_CLASS (oc); + +/* https://www.arduino.cc/en/Main/ArduinoBoardMega */ + mc->desc ="Arduino Mega (ATmega1280)" ; + mc->alias ="mega" ; + amc->mcu_type =TYPE_ATMEGA1280_MCU ; + amc->xtal_hz =16 *1000 *1000 ; +}; + +static void arduino_mega2560_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); +ArduinoMachineClass *amc =ARDUINO_MACHINE_CLASS (oc); + +/* https://store.arduino.cc/arduino-mega-2560-rev3 */ + mc->desc ="Arduino Mega 2560 (ATmega2560)" ; + mc->alias ="mega2560" ; + mc->is_default = true; + amc->mcu_type =TYPE_ATMEGA2560_MCU ; + amc->xtal_hz =16 *1000 *1000 ;/* CSTCE16M0V53-R0 */ +}; + +static const TypeInfo arduino_machine_types[] = { + { + .name =MACHINE_TYPE_NAME ("arduino-duemilanove" ), + .parent =TYPE_ARDUINO_MACHINE , + .class_init = arduino_duemilanove_class_init, + }, { + .name =MACHINE_TYPE_NAME ("arduino-uno" ), + .parent =TYPE_ARDUINO_MACHINE , + .class_init = arduino_uno_class_init, + }, { + .name =MACHINE_TYPE_NAME ("arduino-mega" ), + .parent =TYPE_ARDUINO_MACHINE , + .class_init = arduino_mega_class_init, + }, { + .name =MACHINE_TYPE_NAME ("arduino-mega-2560-v3" ), + .parent =TYPE_ARDUINO_MACHINE , + .class_init = arduino_mega2560_class_init, + }, { + .name =TYPE_ARDUINO_MACHINE , + .parent =TYPE_MACHINE , + .instance_size =sizeof (ArduinoMachineState), + .class_size =sizeof (ArduinoMachineClass), + .class_init = arduino_machine_class_init, + .abstract = true, + } +}; + +DEFINE_TYPES (arduino_machine_types)hw/avr/Makefile.objs +1
-0@@ -1,2 +1,3 @@ obj-y += sample.o obj-y += atmega.o +obj-y += arduino.o
Re: [PATCH v3 4/8] hw/avr: Add some Arduino boards
Quoted 67 lines · Igor Mammedov
Quoted 64 lines · On Mon, 20 Jan 2020 10:21:52 +0100 Philippe Mathieu-Daudé <[email protected]>…
Quoted 63 lines · Igor Mammedov
Quoted 52 lines · On Sun, 29 Dec 2019 23:45:01 +0100 Philippe Mathieu-Daudé <[email protected]>…
Arduino boards are build with AVR chipsets.
Add some of the popular boards:- Arduino Duemilanove
- Arduino Uno
- Arduino MegaFor more information:
https://www.arduino.cc/en/Main/Products
https://store.arduino.cc/arduino-genuino/most-popularSigned-off-by Philippe Mathieu-Daudé <[email protected]>---
v2:
- Reword description adding more information (Aleksandar)
- UseDEFINE_TYPES(Igor)Cc Phillip Stevens <[email protected]>Cc Igor Mammedov <[email protected]>--- hw/avr/arduino.c | 177 +++++++++++++++++++++++++++++++++++++++++++ hw/avr/Makefile.objs | 1 + 2 files changed, 178 insertions(+)create mode 100644
hw/avr/arduino.chw/avr/arduino.c new file +21
-0@@ -0,0 +1,177 @@ +/* +* QEMU Arduino boards +* +* Copyright (c) 2019 Philippe Mathieu-Daudé +* +* This work is licensed under the terms of the GNU GPLv2 or later. +* See the COPYING file in the top-level directory. +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +/* TODO: Implement the use of EXTRAM */ + +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "qapi/error.h" +#include "hw/boards.h" +#include "hw/loader.h" +#include "elf.h" +#include "atmega.h" + +typedef struct ArduinoMachineState {[...]
Quoted 4 lines
hw/avr/arduino.c new file +4
-0+MemoryRegion extram; +} ArduinoMachineState; + +typedef struct ArduinoMachineClass {[...]
Quoted 1 line
+
size_textram_size;
Quoted 7 lines
Quoted 6 lines
Quoted 1 line
extfoo doesn't seem to be used in this patch
Ah leftover from adapting from the 'sample' board which has SIZE_EXMEM=0 so I ended removing a chunk and forgot this field.
Can I add your R-b tag when respining this patch without the field?
sure
Thanks!
Quoted 3 lines
later on we need to make up some generic way for machine to say that -m is not supported to avoid useless/confusing option where board doesn't care about it.
Does that means that when running this machine with '-m 3G' on top your memdev series, QEMU will still allocate 3G of unnecessary RAM?
Quoted 154 lines
Quoted 153 lines
Quoted 152 lines
Quoted 150 lines
hw/avr/arduino.c new file +142
-0+} ArduinoMachineClass; + +#define TYPE_ARDUINO_MACHINE \ + MACHINE_TYPE_NAME("arduino") +#define ARDUINO_MACHINE (obj) \ + OBJECT_CHECK(ArduinoMachineState, (obj), TYPE_ARDUINO_MACHINE) +#define ARDUINO_MACHINE_CLASS (klass) \ + OBJECT_CLASS_CHECK(ArduinoMachineClass, (klass), TYPE_ARDUINO_MACHINE) +#define ARDUINO_MACHINE_GET_CLASS (obj) \ + OBJECT_GET_CLASS(ArduinoMachineClass, (obj), TYPE_ARDUINO_MACHINE) + +static void load_firmware (const char *firmware,uint64_t flash_size) +{ +const char *filename; +int bytes_loaded; + +/* Load firmware (contents of flash) trying to auto-detect format */ + filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , firmware); +if (filename ==NULL ) { +error_report ("Unable to find %s" , firmware); +exit (1 ); + } + + bytes_loaded =load_elf (filename,NULL ,NULL ,NULL ,NULL ,NULL ,NULL , +0 ,EM_NONE ,0 ,0 ); +if (bytes_loaded <0 ) { + bytes_loaded =load_image_targphys (filename,OFFSET_CODE , flash_size); + } +if (bytes_loaded <0 ) { +error_report ("Unable to load firmware image %s as ELF or raw binary" , + firmware); +exit (1 ); + } +} + +static void arduino_machine_init (MachineState *machine) +{ +ArduinoMachineClass *amc =ARDUINO_MACHINE_GET_CLASS (machine); +ArduinoMachineState *ams =ARDUINO_MACHINE (machine); + +sysbus_init_child_obj (OBJECT (machine),"mcu" , &ams->mcu,sizeof (ams->mcu), + amc->mcu_type); +object_property_set_uint (OBJECT (&ams->mcu), amc->xtal_hz, +"xtal-frequency-hz" , &error_abort); +object_property_set_bool (OBJECT (&ams->mcu), true,"realized" , + &error_abort); + +if (machine->firmware) { +load_firmware (machine->firmware,memory_region_size (&ams->mcu.flash)); + } +} + +static void arduino_machine_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); + + mc->init = arduino_machine_init; + mc->default_cpus =1 ; + mc->min_cpus = mc->default_cpus; + mc->max_cpus = mc->default_cpus; + mc->no_floppy =1 ; + mc->no_cdrom =1 ; + mc->no_parallel =1 ; +} + +static void arduino_duemilanove_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); +ArduinoMachineClass *amc =ARDUINO_MACHINE_CLASS (oc); + +/* https://www.arduino.cc/en/Main/ArduinoBoardDuemilanove */ + mc->desc ="Arduino Duemilanove (ATmega168)" , + mc->alias ="2009" ; + amc->mcu_type =TYPE_ATMEGA168_MCU ; + amc->xtal_hz =16 *1000 *1000 ; +}; + +static void arduino_uno_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); +ArduinoMachineClass *amc =ARDUINO_MACHINE_CLASS (oc); + +/* https://store.arduino.cc/arduino-uno-rev3 */ + mc->desc ="Arduino UNO (ATmega328P)" ; + mc->alias ="uno" ; + amc->mcu_type =TYPE_ATMEGA328_MCU ; + amc->xtal_hz =16 *1000 *1000 ; +}; + +static void arduino_mega_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); +ArduinoMachineClass *amc =ARDUINO_MACHINE_CLASS (oc); + +/* https://www.arduino.cc/en/Main/ArduinoBoardMega */ + mc->desc ="Arduino Mega (ATmega1280)" ; + mc->alias ="mega" ; + amc->mcu_type =TYPE_ATMEGA1280_MCU ; + amc->xtal_hz =16 *1000 *1000 ; +}; + +static void arduino_mega2560_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); +ArduinoMachineClass *amc =ARDUINO_MACHINE_CLASS (oc); + +/* https://store.arduino.cc/arduino-mega-2560-rev3 */ + mc->desc ="Arduino Mega 2560 (ATmega2560)" ; + mc->alias ="mega2560" ; + mc->is_default = true; + amc->mcu_type =TYPE_ATMEGA2560_MCU ; + amc->xtal_hz =16 *1000 *1000 ;/* CSTCE16M0V53-R0 */ +}; + +static const TypeInfo arduino_machine_types[] = { + { + .name =MACHINE_TYPE_NAME ("arduino-duemilanove" ), + .parent =TYPE_ARDUINO_MACHINE , + .class_init = arduino_duemilanove_class_init, + }, { + .name =MACHINE_TYPE_NAME ("arduino-uno" ), + .parent =TYPE_ARDUINO_MACHINE , + .class_init = arduino_uno_class_init, + }, { + .name =MACHINE_TYPE_NAME ("arduino-mega" ), + .parent =TYPE_ARDUINO_MACHINE , + .class_init = arduino_mega_class_init, + }, { + .name =MACHINE_TYPE_NAME ("arduino-mega-2560-v3" ), + .parent =TYPE_ARDUINO_MACHINE , + .class_init = arduino_mega2560_class_init, + }, { + .name =TYPE_ARDUINO_MACHINE , + .parent =TYPE_MACHINE , + .instance_size =sizeof (ArduinoMachineState), + .class_size =sizeof (ArduinoMachineClass), + .class_init = arduino_machine_class_init, + .abstract = true, + } +}; + +DEFINE_TYPES (arduino_machine_types)hw/avr/Makefile.objs +1
-0@@ -1,2 +1,3 @@ obj-y += sample.o obj-y += atmega.o +obj-y += arduino.o
Re: [PATCH v3 4/8] hw/avr: Add some Arduino boards
Quoted 76 lines · On Mon, 20 Jan 2020 12:05:24 +0100 Philippe Mathieu-Daudé <[email protected]>…
Quoted 67 lines · Igor Mammedov
Quoted 64 lines · On Mon, 20 Jan 2020 10:21:52 +0100 Philippe Mathieu-Daudé <[email protected]>…
Quoted 63 lines · Igor Mammedov
Quoted 52 lines · On Sun, 29 Dec 2019 23:45:01 +0100 Philippe Mathieu-Daudé <[email protected]>…
Arduino boards are build with AVR chipsets.
Add some of the popular boards:- Arduino Duemilanove
- Arduino Uno
- Arduino MegaFor more information:
https://www.arduino.cc/en/Main/Products
https://store.arduino.cc/arduino-genuino/most-popularSigned-off-by Philippe Mathieu-Daudé <[email protected]>---
v2:
- Reword description adding more information (Aleksandar)
- UseDEFINE_TYPES(Igor)Cc Phillip Stevens <[email protected]>Cc Igor Mammedov <[email protected]>--- hw/avr/arduino.c | 177 +++++++++++++++++++++++++++++++++++++++++++ hw/avr/Makefile.objs | 1 + 2 files changed, 178 insertions(+)create mode 100644
hw/avr/arduino.chw/avr/arduino.c new file +21
-0@@ -0,0 +1,177 @@ +/* +* QEMU Arduino boards +* +* Copyright (c) 2019 Philippe Mathieu-Daudé +* +* This work is licensed under the terms of the GNU GPLv2 or later. +* See the COPYING file in the top-level directory. +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +/* TODO: Implement the use of EXTRAM */ + +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "qapi/error.h" +#include "hw/boards.h" +#include "hw/loader.h" +#include "elf.h" +#include "atmega.h" + +typedef struct ArduinoMachineState {[...]
Quoted 4 lines
hw/avr/arduino.c new file +4
-0+MemoryRegion extram; +} ArduinoMachineState; + +typedef struct ArduinoMachineClass {[...]
Quoted 1 line
+
size_textram_size;Quoted 7 lines
Quoted 6 lines
Quoted 1 line
extfoo doesn't seem to be used in this patch
Ah leftover from adapting from the 'sample' board which has SIZE_EXMEM=0 so I ended removing a chunk and forgot this field.
Can I add your R-b tag when respining this patch without the field?
sure
Quoted 8 lines
Thanks!
Quoted 3 lines
later on we need to make up some generic way for machine to say that -m is not supported to avoid useless/confusing option where board doesn't care about it.
Does that means that when running this machine with '-m 3G' on top your memdev series, QEMU will still allocate 3G of unnecessary RAM?
yep,
to refuse "-m" at all or make size checks earlier we need to make boards declare supported sizes or provide check callback.
In this series, I was only adding checks in boards that were missing checks to make sure boards will eventually error out (far from ideal but refactoring checks is out of scope of my series).
Quoted 156 lines
Quoted 155 lines
Quoted 154 lines
Quoted 153 lines
Quoted 151 lines
hw/avr/arduino.c new file +142
-0+} ArduinoMachineClass; + +#define TYPE_ARDUINO_MACHINE \ + MACHINE_TYPE_NAME("arduino") +#define ARDUINO_MACHINE (obj) \ + OBJECT_CHECK(ArduinoMachineState, (obj), TYPE_ARDUINO_MACHINE) +#define ARDUINO_MACHINE_CLASS (klass) \ + OBJECT_CLASS_CHECK(ArduinoMachineClass, (klass), TYPE_ARDUINO_MACHINE) +#define ARDUINO_MACHINE_GET_CLASS (obj) \ + OBJECT_GET_CLASS(ArduinoMachineClass, (obj), TYPE_ARDUINO_MACHINE) + +static void load_firmware (const char *firmware,uint64_t flash_size) +{ +const char *filename; +int bytes_loaded; + +/* Load firmware (contents of flash) trying to auto-detect format */ + filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , firmware); +if (filename ==NULL ) { +error_report ("Unable to find %s" , firmware); +exit (1 ); + } + + bytes_loaded =load_elf (filename,NULL ,NULL ,NULL ,NULL ,NULL ,NULL , +0 ,EM_NONE ,0 ,0 ); +if (bytes_loaded <0 ) { + bytes_loaded =load_image_targphys (filename,OFFSET_CODE , flash_size); + } +if (bytes_loaded <0 ) { +error_report ("Unable to load firmware image %s as ELF or raw binary" , + firmware); +exit (1 ); + } +} + +static void arduino_machine_init (MachineState *machine) +{ +ArduinoMachineClass *amc =ARDUINO_MACHINE_GET_CLASS (machine); +ArduinoMachineState *ams =ARDUINO_MACHINE (machine); + +sysbus_init_child_obj (OBJECT (machine),"mcu" , &ams->mcu,sizeof (ams->mcu), + amc->mcu_type); +object_property_set_uint (OBJECT (&ams->mcu), amc->xtal_hz, +"xtal-frequency-hz" , &error_abort); +object_property_set_bool (OBJECT (&ams->mcu), true,"realized" , + &error_abort); + +if (machine->firmware) { +load_firmware (machine->firmware,memory_region_size (&ams->mcu.flash)); + } +} + +static void arduino_machine_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); + + mc->init = arduino_machine_init; + mc->default_cpus =1 ; + mc->min_cpus = mc->default_cpus; + mc->max_cpus = mc->default_cpus; + mc->no_floppy =1 ; + mc->no_cdrom =1 ; + mc->no_parallel =1 ; +} + +static void arduino_duemilanove_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); +ArduinoMachineClass *amc =ARDUINO_MACHINE_CLASS (oc); + +/* https://www.arduino.cc/en/Main/ArduinoBoardDuemilanove */ + mc->desc ="Arduino Duemilanove (ATmega168)" , + mc->alias ="2009" ; + amc->mcu_type =TYPE_ATMEGA168_MCU ; + amc->xtal_hz =16 *1000 *1000 ; +}; + +static void arduino_uno_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); +ArduinoMachineClass *amc =ARDUINO_MACHINE_CLASS (oc); + +/* https://store.arduino.cc/arduino-uno-rev3 */ + mc->desc ="Arduino UNO (ATmega328P)" ; + mc->alias ="uno" ; + amc->mcu_type =TYPE_ATMEGA328_MCU ; + amc->xtal_hz =16 *1000 *1000 ; +}; + +static void arduino_mega_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); +ArduinoMachineClass *amc =ARDUINO_MACHINE_CLASS (oc); + +/* https://www.arduino.cc/en/Main/ArduinoBoardMega */ + mc->desc ="Arduino Mega (ATmega1280)" ; + mc->alias ="mega" ; + amc->mcu_type =TYPE_ATMEGA1280_MCU ; + amc->xtal_hz =16 *1000 *1000 ; +}; + +static void arduino_mega2560_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); +ArduinoMachineClass *amc =ARDUINO_MACHINE_CLASS (oc); + +/* https://store.arduino.cc/arduino-mega-2560-rev3 */ + mc->desc ="Arduino Mega 2560 (ATmega2560)" ; + mc->alias ="mega2560" ; + mc->is_default = true; + amc->mcu_type =TYPE_ATMEGA2560_MCU ; + amc->xtal_hz =16 *1000 *1000 ;/* CSTCE16M0V53-R0 */ +}; + +static const TypeInfo arduino_machine_types[] = { + { + .name =MACHINE_TYPE_NAME ("arduino-duemilanove" ), + .parent =TYPE_ARDUINO_MACHINE , + .class_init = arduino_duemilanove_class_init, + }, { + .name =MACHINE_TYPE_NAME ("arduino-uno" ), + .parent =TYPE_ARDUINO_MACHINE , + .class_init = arduino_uno_class_init, + }, { + .name =MACHINE_TYPE_NAME ("arduino-mega" ), + .parent =TYPE_ARDUINO_MACHINE , + .class_init = arduino_mega_class_init, + }, { + .name =MACHINE_TYPE_NAME ("arduino-mega-2560-v3" ), + .parent =TYPE_ARDUINO_MACHINE , + .class_init = arduino_mega2560_class_init, + }, { + .name =TYPE_ARDUINO_MACHINE , + .parent =TYPE_MACHINE , + .instance_size =sizeof (ArduinoMachineState), + .class_size =sizeof (ArduinoMachineClass), + .class_init = arduino_machine_class_init, + .abstract = true, + } +}; + +DEFINE_TYPES (arduino_machine_types)hw/avr/Makefile.objs +1
-0@@ -1,2 +1,3 @@ obj-y += sample.o obj-y += atmega.o +obj-y += arduino.o
PATCH v3 5/8 tests/boot-serial-test: Test some Arduino boards (AVR based)
In reply to Philippe Mathieu-DaudéThe Arduino Duemilanove is based on a AVR5 CPU, while the Arduino MEGA2560 on a AVR6 CPU.
--- tests/boot-serial-test.c | 2 ++ 1 file changed, 2 insertions(+)
tests/boot-serial-test.c +2 -0
@@ -113,6 +113,8 @@ typedef struct testdef {static testdef_t tests[] = { {"alpha" ,"clipper" ,"" ,"PCI:" }, {"avr" ,"sample" ,"" ,"T" ,sizeof (bios_avr),NULL , bios_avr }, + {"avr" ,"arduino-duemilanove" ,"" ,"T" ,sizeof (bios_avr),NULL , bios_avr }, + {"avr" ,"arduino-mega-2560-v3" ,"" ,"T" ,sizeof (bios_avr),NULL , bios_avr}, {"ppc" ,"ppce500" ,"" ,"U-Boot" }, {"ppc" ,"40p" ,"-vga none -boot d" ,"Trying cd:," }, {"ppc" ,"g3beige" ,"" ,"PowerPC,750" },
Signature · 1 line
2.21.0
PATCH v3 6/8 tests/acceptance: Do not set the machine type manually
In reply to Philippe Mathieu-DaudéSince commit ba21bde93 we don't need to set the machine type manually, the one set by the ":avocado: tags=machine" will be used.
--- tests/acceptance/machine_avr6.py | 1 - 1 file changed, 1 deletion(-)
tests/acceptance/machine_avr6.py +0 -1
@@ -45,7 +45,6 @@ class AVR6Machine(Test): rom_hash = '7eb521f511ca8f2622e0a3c5e8dd686efbb911d4' rom_path = self.fetch_asset(rom_url, asset_hash=rom_hash) - self.vm.set_machine('sample') self.vm.add_args('-bios', rom_path) self.vm.add_args('-nographic') self.vm.launch()
Signature · 1 line
2.21.0
Re: [PATCH v3 6/8] tests/acceptance: Do not set the machine type manually
Quoted 2 lines · Philippe Mathieu-Daudé
Since commit
ba21bde93we don't need to set the machine type manually, the one set by the ":avocado: tags=machine" will be used.
Correct.
Quoted 6 lines
Suggested-by Cleber Rosa <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- tests/acceptance/machine_avr6.py | 1 - 1 file changed, 1 deletion(-)
Quoted 13 lines
tests/acceptance/machine_avr6.py +0
-1@@ -45,7 +45,6 @@ class AVR6Machine(Test): rom_hash = '7eb521f511ca8f2622e0a3c5e8dd686efbb911d4' rom_path = self.fetch_asset(rom_url, asset_hash=rom_hash) - self.vm.set_machine('sample') self.vm.add_args('-bios', rom_path) self.vm.add_args('-nographic') self.vm.launch()
PATCH v3 7/8 tests/acceptance: Keep multilines comment consistent with other tests
In reply to Philippe Mathieu-Daudé---
note to maintainer: squash before merge?
--- tests/acceptance/machine_avr6.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
tests/acceptance/machine_avr6.py +3 -5
@@ -37,11 +37,9 @@ class AVR6Machine(Test): https://github.com/seharris/qemu-avr-tests/raw/master/free-rtos/Demo/AVR_ATMega2560_GCC/demo.elf constantly prints out 'ABCDEFGHIJKLMNOPQRSTUVWXABCDEFGHIJKLMNOPQRSTUVWX' """ - rom_url = 'https://github.com/seharris/qemu-avr-tests' - rom_sha1= '36c3e67b8755dcf37e06af6730ef5d477b8ed16d' - rom_url += '/raw/' - rom_url += rom_sha1 - rom_url += '/free-rtos/Demo/AVR_ATMega2560_GCC/demo.elf' + rom_url = ('https://github.com/seharris/qemu-avr-tests' + '/raw/36c3e67b8755dcf/free-rtos/Demo' + '/AVR_ATMega2560_GCC/demo.elf') rom_hash = '7eb521f511ca8f2622e0a3c5e8dd686efbb911d4' rom_path = self.fetch_asset(rom_url, asset_hash=rom_hash)
Signature · 1 line
2.21.0
PATCH v3 8/8 tests/acceptance: Test the Arduino MEGA2560 board
In reply to Philippe Mathieu-DaudéAs the path name demonstrates, the FreeRTOS tests target a board based on a ATMega2560 MCU. We have one, the Arduino MEGA2560.
Complementary documentation:
https://feilipu.me/2012/01/15/ethermega-arduino-mega-2560-and-freertos/
https://feilipu.me/2015/11/24/arduino_freertos/ (see 'Compatibility')
--- tests/acceptance/machine_avr6.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/acceptance/machine_avr6.py +1 -1
@@ -31,7 +31,7 @@ class AVR6Machine(Test): def test_freertos(self): """ :avocado: tags=arch:avr - :avocado: tags=machine:sample + :avocado: tags=machine:arduino-mega-2560-v3 """ """ https://github.com/seharris/qemu-avr-tests/raw/master/free-rtos/Demo/AVR_ATMega2560_GCC/demo.elf
Signature · 1 line
2.21.0
Patchew URL: https://patchew.org/QEMU/[email protected]/
Patchew URL: https://patchew.org/QEMU/[email protected]/
Hi,
This series failed the docker-quick@centos7 build test. Please find the testing commands and their output below. If you have Docker installed, you can probably reproduce it locally.
=== TEST SCRIPT BEGIN ===
#!/bin/bash
make docker-image-centos7 V=1 NETWORK=1
time make docker-test-quick@centos7 SHOW_ENV=1 J=14 NETWORK=1 === TEST SCRIPT END ===
The full log is available at
http://patchew.org/logs/[email protected]/testing.docker-quick@centos7/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]
Quoted 4 lines · On Sun, Dec 29, 2019 at 11:58 PM <[email protected]> wrote:
This series failed the docker-quick@centos7 build test. Please find the testing commands and their output below. If you have Docker installed, you can probably reproduce it locally.
Please send your feedback to [email protected]
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384 From https://github.com/patchew-project/qemu
- [tag update] patchew/[email protected]
-> patchew/[email protected]
* [new tag] patchew/[email protected] ->
patchew/[email protected]
fatal: failed to write ref-pack file
fatal: The remote end hung up unexpectedly
Is patchew disk full?
Hi Philippe.
Thank you for joining the effort.
Regards,
Michael Rolnik
Quoted 62 lines · Philippe Mathieu-Daudé
Hi,
This series add the arduino boards, aiming at removing the 'sample' board that doesn't follow any specification.
Since v2:
- rebased on Michael's v40Since v1:
- Addressed Igor comments
- Addressed Aleksandar comments
- Fixed UART issue (was due to IRQ shifted by 2 in CPU)TODO after merge is:
- Extract Timer8 common parts from Timer16
- Add GPIOs
- Connect LED to GPIO on Arduino
- Plug to Scratch (See http://s4a.cat/).
(I plan to purpose that as a GSoC idea).Michael, thank you for having insisted with this port during so long!
Regards,
Phil.
Series available at https://gitlab.com/philmd/qemu/commits/arduino-v3
Regards,
Phil.
Based-on: <[email protected]>
https://lists.gnu.org/archive/html/qemu-devel/2019-12/msg05309.htmlPhilippe Mathieu-Daudé (8):
hw/char/avr: Reduce USART I/O size
hw/timer/avr_timer16: Rename memory region debugging name hw/avr: Add some ATmega microcontrollers
hw/avr: Add some Arduino boards
tests/boot-serial-test: Test some Arduino boards (AVR based) tests/acceptance: Do not set the machine type manually tests/acceptance: Keep multilines comment consistent with other tests tests/acceptance: Test the Arduino MEGA2560 boardhw/avr/atmega.h | 48 ++++ hw/avr/arduino.c | 177 ++++++++++++ hw/avr/atmega.c | 464 +++++++++++++++++++++++++++++++ hw/char/avr_usart.c | 2 +- hw/timer/avr_timer16.c | 6 +- tests/boot-serial-test.c | 2 + hw/avr/Makefile.objs | 2 + tests/acceptance/machine_avr6.py | 11 +- 8 files changed, 701 insertions(+), 11 deletions(-) create mode 100644 hw/avr/atmega.h create mode 100644 hw/avr/arduino.c create mode 100644 hw/avr/atmega.c--
2.21.0
Signature · 2 lines
Best Regards, Michael Rolnik
Hi Michael,
Quoted 3 lines · Michael Rolnik
Hi Philippe.
Thank you for joining the effort.
Could you test this series?
Are you OK if we use the Arduino machines it introduces to replace your 'sample' board?
Quoted 74 lines
Regards,
Michael RolnikOn Mon, Dec 30, 2019 at 12:45 AM Philippe Mathieu-Daudé <[email protected] <mailto:[email protected]>> wrote:
Hi,
This series add the arduino boards, aiming at removing the 'sample' board that doesn't follow any specification.
Since v2:
- rebased on Michael's v40Since v1:
- Addressed Igor comments
- Addressed Aleksandar comments
- Fixed UART issue (was due to IRQ shifted by 2 in CPU)TODO after merge is:
- Extract Timer8 common parts from Timer16
- Add GPIOs
- Connect LED to GPIO on Arduino
- Plug to Scratch (See http://s4a.cat/).
(I plan to purpose that as a GSoC idea).Michael, thank you for having insisted with this port during so long!
Regards,
Phil.
Series available at https://gitlab.com/philmd/qemu/commits/arduino-v3
Regards,
Phil.
Based-on: <[email protected] <mailto:[email protected]>>
https://lists.gnu.org/archive/html/qemu-devel/2019-12/msg05309.htmlPhilippe Mathieu-Daudé (8):
hw/char/avr: Reduce USART I/O size
hw/timer/avr_timer16: Rename memory region debugging name hw/avr: Add some ATmega microcontrollers
hw/avr: Add some Arduino boards
tests/boot-serial-test: Test some Arduino boards (AVR based) tests/acceptance: Do not set the machine type manually tests/acceptance: Keep multilines comment consistent with other tests tests/acceptance: Test the Arduino MEGA2560 boardhw/avr/atmega.h | 48 ++++ hw/avr/arduino.c | 177 ++++++++++++ hw/avr/atmega.c | 464 +++++++++++++++++++++++++++++++ hw/char/avr_usart.c | 2 +- hw/timer/avr_timer16.c | 6 +- tests/boot-serial-test.c | 2 + hw/avr/Makefile.objs | 2 +
tests/acceptance/machine_avr6.py| 11 +-
8 files changed, 701 insertions(+), 11 deletions(-)
create mode 100644hw/avr/atmega.h
create mode 100644hw/avr/arduino.c
create mode 100644hw/avr/atmega.c--
2.21.0Signature · 2 lines
Best Regards, Michael Rolnik
Sure, no problem.
Quoted 90 lines · Philippe Mathieu-Daudé
Hi Michael,
Quoted 3 lines · Michael Rolnik
Hi Philippe.
Thank you for joining the effort.
Could you test this series?
Are you OK if we use the Arduino machines it introduces to replace your 'sample' board?
Quoted 27 lines
Regards,
Michael RolnikOn Mon, Dec 30, 2019 at 12:45 AM Philippe Mathieu-Daudé <[email protected] <mailto:[email protected]>> wrote:
Hi,
This series add the arduino boards, aiming at removing the 'sample' board that doesn't follow any specification.
Since v2:
- rebased on Michael's v40Since v1:
- Addressed Igor comments
- Addressed Aleksandar comments
- Fixed UART issue (was due to IRQ shifted by 2 in CPU)TODO after merge is:
- Extract Timer8 common parts from Timer16
- Add GPIOs
- Connect LED to GPIO on Arduino
- Plug to Scratch (See http://s4a.cat/).
(I plan to purpose that as a GSoC idea).Quoted 7 lines
Michael, thank you for having insisted with this port during so long!
Regards,
Phil.
Series available at
https://gitlab.com/philmd/qemu/commits/arduino-v3
Quoted 9 lines
Regards,
Phil.
Based-on: <[email protected] <mailto:[email protected]>>
https://lists.gnu.org/archive/html/qemu-devel/2019-12/msg05309.htmlQuoted 8 lines
Philippe Mathieu-Daudé (8):
hw/char/avr: Reduce USART I/O size hw/timer/avr_timer16: Rename memory region debugging name hw/avr: Add some ATmega microcontrollers
hw/avr: Add some Arduino boards tests/boot-serial-test: Test some Arduino boards (AVR based) tests/acceptance: Do not set the machine type manually tests/acceptance: Keep multilines comment consistent with othertests
Quoted 5 lines
tests/acceptance: Test the Arduino MEGA2560 board
hw/avr/atmega.h| 48 ++++
hw/avr/arduino.c| 177 ++++++++++++
hw/avr/atmega.c| 464+++++++++++++++++++++++++++++++
Quoted 18 lines
hw/char/avr_usart.c | 2 +- hw/timer/avr_timer16.c | 6 +- tests/boot-serial-test.c | 2 + hw/avr/Makefile.objs | 2 + tests/acceptance/machine_avr6.py | 11 +- 8 files changed, 701 insertions(+), 11 deletions(-) create mode 100644 hw/avr/atmega.h create mode 100644 hw/avr/arduino.c create mode 100644 hw/avr/atmega.c -- 2.21.0--
Best Regards,
Michael Rolnik
Signature · 2 lines
Best Regards, Michael Rolnik