All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/8] hw/avr: Introduce the Arduino boards
@ 2019-12-29 22:44 Philippe Mathieu-Daudé
  2019-12-29 22:44 ` [PATCH v3 1/8] hw/char/avr: Reduce USART I/O size Philippe Mathieu-Daudé
                   ` (9 more replies)
  0 siblings, 10 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2019-12-29 22:44 UTC (permalink / raw)
  To: qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Sarah Harris,
	Philippe Mathieu-Daudé,
	Michael Rolnik, Marc-André Lureau, Paolo Bonzini

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: <20191229215158.5788-1-mrolnik@gmail.com>
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

-- 
2.21.0



^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH v3 1/8] hw/char/avr: Reduce USART I/O size
  2019-12-29 22:44 [PATCH v3 0/8] hw/avr: Introduce the Arduino boards Philippe Mathieu-Daudé
@ 2019-12-29 22:44 ` Philippe Mathieu-Daudé
  2019-12-29 22:44 ` [PATCH v3 2/8] hw/timer/avr_timer16: Rename memory region debugging name Philippe Mathieu-Daudé
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2019-12-29 22:44 UTC (permalink / raw)
  To: qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Sarah Harris,
	Philippe Mathieu-Daudé,
	Michael Rolnik, Marc-André Lureau, Paolo Bonzini

Per the datasheet the USART uses 7 consecutive 8-bit registers.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 hw/char/avr_usart.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/char/avr_usart.c b/hw/char/avr_usart.c
index cb307fe23d..becdb87847 100644
--- a/hw/char/avr_usart.c
+++ b/hw/char/avr_usart.c
@@ -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;
-- 
2.21.0



^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v3 2/8] hw/timer/avr_timer16: Rename memory region debugging name
  2019-12-29 22:44 [PATCH v3 0/8] hw/avr: Introduce the Arduino boards Philippe Mathieu-Daudé
  2019-12-29 22:44 ` [PATCH v3 1/8] hw/char/avr: Reduce USART I/O size Philippe Mathieu-Daudé
@ 2019-12-29 22:44 ` Philippe Mathieu-Daudé
  2019-12-29 22:45 ` [PATCH v3 3/8] hw/avr: Add some ATmega microcontrollers Philippe Mathieu-Daudé
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2019-12-29 22:44 UTC (permalink / raw)
  To: qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Sarah Harris,
	Philippe Mathieu-Daudé,
	Michael Rolnik, Marc-André Lureau, Paolo Bonzini

This device expose 3 different I/O regions. Name them differently
to have a clearer 'info mtree' output.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 hw/timer/avr_timer16.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/timer/avr_timer16.c b/hw/timer/avr_timer16.c
index aea1bf009e..a27933a18a 100644
--- a/hw/timer/avr_timer16.c
+++ b/hw/timer/avr_timer16.c
@@ -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);
-- 
2.21.0



^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v3 3/8] hw/avr: Add some ATmega microcontrollers
  2019-12-29 22:44 [PATCH v3 0/8] hw/avr: Introduce the Arduino boards Philippe Mathieu-Daudé
  2019-12-29 22:44 ` [PATCH v3 1/8] hw/char/avr: Reduce USART I/O size Philippe Mathieu-Daudé
  2019-12-29 22:44 ` [PATCH v3 2/8] hw/timer/avr_timer16: Rename memory region debugging name Philippe Mathieu-Daudé
@ 2019-12-29 22:45 ` Philippe Mathieu-Daudé
  2019-12-29 22:45 ` [PATCH v3 4/8] hw/avr: Add some Arduino boards Philippe Mathieu-Daudé
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2019-12-29 22:45 UTC (permalink / raw)
  To: qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Igor Mammedov, Sarah Harris,
	Philippe Mathieu-Daudé,
	Michael Rolnik, Marc-André Lureau, Paolo Bonzini

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

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
v2:
- Reword description adding more information (Aleksandar)
- Use DEFINE_TYPES and memory_region_init_ram (Igor)

Cc: Igor Mammedov <imammedo@redhat.com>
---
 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

diff --git a/hw/avr/atmega.h b/hw/avr/atmega.h
new file mode 100644
index 0000000000..aac09f7957
--- /dev/null
+++ b/hw/avr/atmega.h
@@ -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 */
diff --git a/hw/avr/atmega.c b/hw/avr/atmega.c
new file mode 100644
index 0000000000..81d20847a4
--- /dev/null
+++ b/hw/avr/atmega.c
@@ -0,0 +1,464 @@
+/*
+ * 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
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/module.h"
+#include "qemu/units.h"
+#include "qapi/error.h"
+#include "exec/memory.h"
+#include "exec/address-spaces.h"
+#include "sysemu/sysemu.h"
+#include "hw/qdev-properties.h"
+#include "hw/sysbus.h"
+#include "hw/boards.h" /* FIXME memory_region_allocate_system_memory for sram */
+#include "hw/misc/unimp.h"
+#include "atmega.h"
+
+enum AtmegaPeripheral {
+    POWER0, POWER1,
+    GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, GPIOF,
+    GPIOG, GPIOH, GPIOI, GPIOJ, GPIOK, GPIOL,
+    USART0, USART1, USART2, USART3,
+    TIMER0, TIMER1, TIMER2, TIMER3, TIMER4, TIMER5,
+    PERIFMAX
+};
+
+#define GPIO(n)     (n + GPIOA)
+#define USART(n)    (n + USART0)
+#define TIMER(n)    (n + TIMER0)
+#define POWER(n)    (n + POWER0)
+
+typedef struct {
+    uint16_t addr;
+    enum AtmegaPeripheral power_index;
+    uint8_t power_bit;
+    /* timer specific */
+    uint16_t intmask_addr;
+    uint16_t intflag_addr;
+    bool is_timer16;
+} peripheral_cfg;
+
+typedef struct AtmegaMcuClass {
+    /*< private >*/
+    SysBusDeviceClass parent_class;
+    /*< public >*/
+    const char *uc_name;
+    const char *cpu_type;
+    size_t flash_size;
+    size_t eeprom_size;
+    size_t sram_size;
+    size_t io_size;
+    size_t gpio_count;
+    size_t adc_count;
+    const uint8_t *irq;
+    const peripheral_cfg *dev;
+} AtmegaMcuClass;
+
+#define ATMEGA_MCU_CLASS(klass) \
+    OBJECT_CLASS_CHECK(AtmegaMcuClass, (klass), TYPE_ATMEGA_MCU)
+#define ATMEGA_MCU_GET_CLASS(obj) \
+    OBJECT_GET_CLASS(AtmegaMcuClass, (obj), TYPE_ATMEGA_MCU)
+
+static const peripheral_cfg dev168_328[PERIFMAX] = {
+    [USART0]        = {  0xc0, POWER0, 1 },
+    [TIMER2]        = {  0xb0, POWER0, 6, 0x70, 0x37, false },
+    [TIMER1]        = {  0x80, POWER0, 3, 0x6f, 0x36, true },
+    [POWER0]        = {  0x64 },
+    [TIMER0]        = {  0x44, POWER0, 5, 0x6e, 0x35, false },
+    [GPIOD]         = {  0x29 },
+    [GPIOC]         = {  0x26 },
+    [GPIOB]         = {  0x23 },
+}, dev1280_2560[PERIFMAX] = {
+    [USART3]        = { 0x130, POWER1, 2 },
+    [TIMER5]        = { 0x120, POWER1, 5, 0x73, 0x3a, true },
+    [GPIOL]         = { 0x109 },
+    [GPIOK]         = { 0x106 },
+    [GPIOJ]         = { 0x103 },
+    [GPIOH]         = { 0x100 },
+    [USART2]        = {  0xd0, POWER1, 1 },
+    [USART1]        = {  0xc8, POWER1, 0 },
+    [USART0]        = {  0xc0, POWER0, 1 },
+    [TIMER2]        = {  0xb0, POWER0, 6, 0x70, 0x37, false }, /* TODO async */
+    [TIMER4]        = {  0xa0, POWER1, 4, 0x72, 0x39, true },
+    [TIMER3]        = {  0x90, POWER1, 3, 0x71, 0x38, true },
+    [TIMER1]        = {  0x80, POWER0, 3, 0x6f, 0x36, true },
+    [POWER1]        = {  0x65 },
+    [POWER0]        = {  0x64 },
+    [TIMER0]        = {  0x44, POWER0, 5, 0x6e, 0x35, false },
+    [GPIOG]         = {  0x32 },
+    [GPIOF]         = {  0x2f },
+    [GPIOE]         = {  0x2c },
+    [GPIOD]         = {  0x29 },
+    [GPIOC]         = {  0x26 },
+    [GPIOB]         = {  0x23 },
+    [GPIOA]         = {  0x20 },
+};
+
+enum AtmegaIrq {
+    USART0_RXC_IRQ, USART0_DRE_IRQ, USART0_TXC_IRQ,
+    USART1_RXC_IRQ, USART1_DRE_IRQ, USART1_TXC_IRQ,
+    USART2_RXC_IRQ, USART2_DRE_IRQ, USART2_TXC_IRQ,
+    USART3_RXC_IRQ, USART3_DRE_IRQ, USART3_TXC_IRQ,
+    TIMER0_CAPT_IRQ, TIMER0_COMPA_IRQ, TIMER0_COMPB_IRQ,
+        TIMER0_COMPC_IRQ, TIMER0_OVF_IRQ,
+    TIMER1_CAPT_IRQ, TIMER1_COMPA_IRQ, TIMER1_COMPB_IRQ,
+        TIMER1_COMPC_IRQ, TIMER1_OVF_IRQ,
+    TIMER2_CAPT_IRQ, TIMER2_COMPA_IRQ, TIMER2_COMPB_IRQ,
+        TIMER2_COMPC_IRQ, TIMER2_OVF_IRQ,
+    TIMER3_CAPT_IRQ, TIMER3_COMPA_IRQ, TIMER3_COMPB_IRQ,
+        TIMER3_COMPC_IRQ, TIMER3_OVF_IRQ,
+    TIMER4_CAPT_IRQ, TIMER4_COMPA_IRQ, TIMER4_COMPB_IRQ,
+        TIMER4_COMPC_IRQ, TIMER4_OVF_IRQ,
+    TIMER5_CAPT_IRQ, TIMER5_COMPA_IRQ, TIMER5_COMPB_IRQ,
+        TIMER5_COMPC_IRQ, TIMER5_OVF_IRQ,
+    IRQ_COUNT
+};
+
+#define USART_IRQ_COUNT     3
+#define USART_RXC_IRQ(n)    (n * USART_IRQ_COUNT + USART0_RXC_IRQ)
+#define USART_DRE_IRQ(n)    (n * USART_IRQ_COUNT + USART0_DRE_IRQ)
+#define USART_TXC_IRQ(n)    (n * USART_IRQ_COUNT + USART0_TXC_IRQ)
+#define TIMER_IRQ_COUNT     5
+#define TIMER_CAPT_IRQ(n)   (n * TIMER_IRQ_COUNT + TIMER0_CAPT_IRQ)
+#define TIMER_COMPA_IRQ(n)  (n * TIMER_IRQ_COUNT + TIMER0_COMPA_IRQ)
+#define TIMER_COMPB_IRQ(n)  (n * TIMER_IRQ_COUNT + TIMER0_COMPB_IRQ)
+#define TIMER_COMPC_IRQ(n)  (n * TIMER_IRQ_COUNT + TIMER0_COMPC_IRQ)
+#define TIMER_OVF_IRQ(n)    (n * TIMER_IRQ_COUNT + TIMER0_OVF_IRQ)
+
+static const uint8_t irq168_328[IRQ_COUNT] = {
+    [TIMER2_COMPA_IRQ]      = 8,
+    [TIMER2_COMPB_IRQ]      = 9,
+    [TIMER2_OVF_IRQ]        = 10,
+    [TIMER1_CAPT_IRQ]       = 11,
+    [TIMER1_COMPA_IRQ]      = 12,
+    [TIMER1_COMPB_IRQ]      = 13,
+    [TIMER1_OVF_IRQ]        = 14,
+    [TIMER0_COMPA_IRQ]      = 15,
+    [TIMER0_COMPB_IRQ]      = 16,
+    [TIMER0_OVF_IRQ]        = 17,
+    [USART0_RXC_IRQ]        = 19,
+    [USART0_DRE_IRQ]        = 20,
+    [USART0_TXC_IRQ]        = 21,
+}, irq1280_2560[IRQ_COUNT] = {
+    [TIMER2_COMPA_IRQ]      = 14,
+    [TIMER2_COMPB_IRQ]      = 15,
+    [TIMER2_OVF_IRQ]        = 16,
+    [TIMER1_CAPT_IRQ]       = 17,
+    [TIMER1_COMPA_IRQ]      = 18,
+    [TIMER1_COMPB_IRQ]      = 19,
+    [TIMER1_COMPC_IRQ]      = 20,
+    [TIMER1_OVF_IRQ]        = 21,
+    [TIMER0_COMPA_IRQ]      = 22,
+    [TIMER0_COMPB_IRQ]      = 23,
+    [TIMER0_OVF_IRQ]        = 24,
+    [USART0_RXC_IRQ]        = 26,
+    [USART0_DRE_IRQ]        = 27,
+    [USART0_TXC_IRQ]        = 28,
+    [TIMER3_CAPT_IRQ]       = 32,
+    [TIMER3_COMPA_IRQ]      = 33,
+    [TIMER3_COMPB_IRQ]      = 34,
+    [TIMER3_COMPC_IRQ]      = 35,
+    [TIMER3_OVF_IRQ]        = 36,
+    [USART1_RXC_IRQ]        = 37,
+    [USART1_DRE_IRQ]        = 38,
+    [USART1_TXC_IRQ]        = 39,
+    [TIMER4_CAPT_IRQ]       = 42,
+    [TIMER4_COMPA_IRQ]      = 43,
+    [TIMER4_COMPB_IRQ]      = 44,
+    [TIMER4_COMPC_IRQ]      = 45,
+    [TIMER4_OVF_IRQ]        = 46,
+    [TIMER5_CAPT_IRQ]       = 47,
+    [TIMER5_COMPA_IRQ]      = 48,
+    [TIMER5_COMPB_IRQ]      = 49,
+    [TIMER5_COMPC_IRQ]      = 50,
+    [TIMER5_OVF_IRQ]        = 51,
+    [USART2_RXC_IRQ]        = 52,
+    [USART2_DRE_IRQ]        = 53,
+    [USART2_TXC_IRQ]        = 54,
+    [USART3_RXC_IRQ]        = 55,
+    [USART3_DRE_IRQ]        = 56,
+    [USART3_TXC_IRQ]        = 57,
+};
+
+static void connect_peripheral_irq(const AtmegaMcuClass *mc,
+                                   SysBusDevice *sbd,
+                                   DeviceState *dev, int n,
+                                   unsigned peripheral_irq)
+{
+    int irq = mc->irq[peripheral_irq];
+
+    if (!irq) {
+        return;
+    }
+    /* FIXME move that to avr_cpu_set_int() once 'sample' board is removed */
+    assert(irq >= 2);
+    irq -= 2;
+
+    sysbus_connect_irq(sbd, n, qdev_get_gpio_in(dev, irq));
+}
+
+static void connect_power_reduction_gpio(AtmegaMcuState *s,
+                                         const AtmegaMcuClass *mc,
+                                         DeviceState *dev,
+                                         int peripheral_index)
+{
+    unsigned power_index = mc->dev[peripheral_index].power_index;
+    assert(mc->dev[power_index].addr);
+    sysbus_connect_irq(SYS_BUS_DEVICE(&s->pwr[power_index - POWER0]),
+                       mc->dev[peripheral_index].power_bit,
+                       qdev_get_gpio_in(dev, 0));
+}
+
+static void atmega_realize(DeviceState *dev, Error **errp)
+{
+    AtmegaMcuState *s = ATMEGA_MCU(dev);
+    const AtmegaMcuClass *mc = ATMEGA_MCU_GET_CLASS(dev);
+    DeviceState *cpudev;
+    SysBusDevice *sbd;
+    Error *err = NULL;
+    char *devname;
+    size_t i;
+
+    assert(mc->io_size <= 0x200);
+
+    if (!s->xtal_freq_hz) {
+        error_setg(errp, "\"xtal-frequency-hz\" property must be provided.");
+        return;
+    }
+
+    /* CPU */
+    object_initialize_child(OBJECT(dev), "cpu", &s->cpu, sizeof(s->cpu),
+                            mc->cpu_type, &err, NULL);
+    if (err) {
+        error_propagate(errp, err);
+        return;
+    }
+    object_property_set_bool(OBJECT(&s->cpu), true, "realized", &error_abort);
+    cpudev = DEVICE(&s->cpu);
+
+    /* SRAM */
+    memory_region_init_ram(&s->sram, OBJECT(dev), "sram", mc->sram_size,
+                           &error_abort);
+    memory_region_add_subregion(get_system_memory(),
+                                OFFSET_DATA + 0x200, &s->sram);
+
+    /* Flash */
+    memory_region_init_rom(&s->flash, OBJECT(dev),
+                           "flash", mc->flash_size, &error_fatal);
+    memory_region_add_subregion(get_system_memory(), OFFSET_CODE, &s->flash);
+
+    /* I/O */
+    s->io = qdev_create(NULL, TYPE_UNIMPLEMENTED_DEVICE);
+    qdev_prop_set_string(s->io, "name", "I/O");
+    qdev_prop_set_uint64(s->io, "size", mc->io_size);
+    qdev_init_nofail(s->io);
+    sysbus_mmio_map_overlap(SYS_BUS_DEVICE(s->io), 0, OFFSET_DATA, -1234);
+
+    /* Power Reduction */
+    for (i = 0; i < POWER_MAX; i++) {
+        int idx = POWER(i);
+        if (!mc->dev[idx].addr) {
+            continue;
+        }
+        devname = g_strdup_printf("power%zu", i);
+        object_initialize_child(OBJECT(dev), devname,
+                                &s->pwr[i], sizeof(s->pwr[i]),
+                                TYPE_AVR_MASK, &error_abort, NULL);
+        object_property_set_bool(OBJECT(&s->pwr[i]), true, "realized",
+                                 &error_abort);
+        sysbus_mmio_map(SYS_BUS_DEVICE(&s->pwr[i]), 0,
+                        OFFSET_DATA + mc->dev[idx].addr);
+        g_free(devname);
+    }
+
+    /* GPIO */
+    for (i = 0; i < GPIO_MAX; i++) {
+        int idx = GPIO(i);
+        if (!mc->dev[idx].addr) {
+            continue;
+        }
+        devname = g_strdup_printf("avr-gpio-%c", 'a' + (char)i);
+        create_unimplemented_device(devname,
+                                    OFFSET_DATA + mc->dev[idx].addr, 3);
+        g_free(devname);
+    }
+
+    /* USART */
+    for (i = 0; i < USART_MAX; i++) {
+        int idx = USART(i);
+        if (!mc->dev[idx].addr) {
+            continue;
+        }
+        devname = g_strdup_printf("usart%zu", i);
+        object_initialize_child(OBJECT(dev), devname,
+                                &s->usart[i], sizeof(s->usart[i]),
+                                TYPE_AVR_USART, &error_abort, NULL);
+        qdev_prop_set_chr(DEVICE(&s->usart[i]), "chardev", serial_hd(i));
+        object_property_set_bool(OBJECT(&s->usart[i]), true, "realized",
+                                 &error_abort);
+        sbd = SYS_BUS_DEVICE(&s->usart[i]);
+        sysbus_mmio_map(sbd, 0, OFFSET_DATA + mc->dev[USART(i)].addr);
+        connect_peripheral_irq(mc, sbd, cpudev, 0, USART_RXC_IRQ(i));
+        connect_peripheral_irq(mc, sbd, cpudev, 1, USART_DRE_IRQ(i));
+        connect_peripheral_irq(mc, sbd, cpudev, 2, USART_TXC_IRQ(i));
+        connect_power_reduction_gpio(s, mc, DEVICE(&s->usart[i]), idx);
+        g_free(devname);
+    }
+
+    /* Timer */
+    for (i = 0; i < TIMER_MAX; i++) {
+        int idx = TIMER(i);
+        if (!mc->dev[idx].addr) {
+            continue;
+        }
+        if (!mc->dev[idx].is_timer16) {
+            create_unimplemented_device("avr-timer8",
+                                        OFFSET_DATA + mc->dev[idx].addr, 5);
+            create_unimplemented_device("avr-timer8-intmask",
+                                        OFFSET_DATA
+                                        + mc->dev[idx].intmask_addr, 1);
+            create_unimplemented_device("avr-timer8-intflag",
+                                        OFFSET_DATA
+                                        + mc->dev[idx].intflag_addr, 1);
+            continue;
+        }
+        devname = g_strdup_printf("timer%zu", i);
+        object_initialize_child(OBJECT(dev), devname,
+                                &s->timer[i], sizeof(s->timer[i]),
+                                TYPE_AVR_TIMER16, &error_abort, NULL);
+        object_property_set_uint(OBJECT(&s->timer[i]), s->xtal_freq_hz,
+                                 "cpu-frequency-hz", &error_abort);
+        object_property_set_bool(OBJECT(&s->timer[i]), true, "realized",
+                                 &error_abort);
+        sbd = SYS_BUS_DEVICE(&s->timer[i]);
+        sysbus_mmio_map(sbd, 0, OFFSET_DATA + mc->dev[idx].addr);
+        sysbus_mmio_map(sbd, 1, OFFSET_DATA + mc->dev[idx].intmask_addr);
+        sysbus_mmio_map(sbd, 2, OFFSET_DATA + mc->dev[idx].intflag_addr);
+        connect_peripheral_irq(mc, sbd, cpudev, 0, TIMER_CAPT_IRQ(i));
+        connect_peripheral_irq(mc, sbd, cpudev, 1, TIMER_COMPA_IRQ(i));
+        connect_peripheral_irq(mc, sbd, cpudev, 2, TIMER_COMPB_IRQ(i));
+        connect_peripheral_irq(mc, sbd, cpudev, 3, TIMER_COMPC_IRQ(i));
+        connect_peripheral_irq(mc, sbd, cpudev, 4, TIMER_OVF_IRQ(i));
+        connect_power_reduction_gpio(s, mc, DEVICE(&s->timer[i]), idx);
+        g_free(devname);
+    }
+
+    create_unimplemented_device("avr-twi",          OFFSET_DATA + 0x0b8, 6);
+    create_unimplemented_device("avr-adc",          OFFSET_DATA + 0x078, 8);
+    create_unimplemented_device("avr-ext-mem-ctrl", OFFSET_DATA + 0x074, 2);
+    create_unimplemented_device("avr-watchdog",     OFFSET_DATA + 0x060, 1);
+    create_unimplemented_device("avr-spi",          OFFSET_DATA + 0x04c, 3);
+    create_unimplemented_device("avr-eeprom",       OFFSET_DATA + 0x03f, 3);
+}
+
+static Property atmega_props[] = {
+    DEFINE_PROP_UINT64("xtal-frequency-hz", AtmegaMcuState,
+                       xtal_freq_hz, 0),
+    DEFINE_PROP_END_OF_LIST()
+};
+
+static void atmega_class_init(ObjectClass *oc, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(oc);
+
+    dc->realize = atmega_realize;
+    dc->props = atmega_props;
+    /* Reason: Mapped at fixed location on the system bus */
+    dc->user_creatable = false;
+}
+
+static void atmega168_class_init(ObjectClass *oc, void *data)
+{
+    AtmegaMcuClass *amc = ATMEGA_MCU_CLASS(oc);
+
+    amc->cpu_type = AVR_CPU_TYPE_NAME("avr5");
+    amc->flash_size = 16 * KiB;
+    amc->eeprom_size = 512;
+    amc->sram_size = 1 * KiB;
+    amc->io_size = 256;
+    amc->gpio_count = 23;
+    amc->adc_count = 6;
+    amc->irq = irq168_328;
+    amc->dev = dev168_328;
+};
+
+static void atmega328_class_init(ObjectClass *oc, void *data)
+{
+    AtmegaMcuClass *amc = ATMEGA_MCU_CLASS(oc);
+
+    amc->cpu_type = AVR_CPU_TYPE_NAME("avr5");
+    amc->flash_size = 32 * KiB;
+    amc->eeprom_size = 1 * KiB;
+    amc->sram_size = 2 * KiB;
+    amc->io_size = 256;
+    amc->gpio_count = 23;
+    amc->adc_count = 6;
+    amc->irq = irq168_328;
+    amc->dev = dev168_328;
+};
+
+static void atmega1280_class_init(ObjectClass *oc, void *data)
+{
+    AtmegaMcuClass *amc = ATMEGA_MCU_CLASS(oc);
+
+    amc->cpu_type = AVR_CPU_TYPE_NAME("avr6");
+    amc->flash_size = 128 * KiB;
+    amc->eeprom_size = 4 * KiB;
+    amc->sram_size = 8 * KiB;
+    amc->io_size = 512;
+    amc->gpio_count = 86;
+    amc->adc_count = 16;
+    amc->irq = irq1280_2560;
+    amc->dev = dev1280_2560;
+};
+
+static void atmega2560_class_init(ObjectClass *oc, void *data)
+{
+    AtmegaMcuClass *amc = ATMEGA_MCU_CLASS(oc);
+
+    amc->cpu_type = AVR_CPU_TYPE_NAME("avr6");
+    amc->flash_size = 256 * KiB;
+    amc->eeprom_size = 4 * KiB;
+    amc->sram_size = 8 * KiB;
+    amc->io_size = 512;
+    amc->gpio_count = 54;
+    amc->adc_count = 16;
+    amc->irq = irq1280_2560;
+    amc->dev = dev1280_2560;
+};
+
+static const TypeInfo atmega_mcu_types[] = {
+    {
+        .name           = TYPE_ATMEGA168_MCU,
+        .parent         = TYPE_ATMEGA_MCU,
+        .class_init     = atmega168_class_init,
+    }, {
+        .name           = TYPE_ATMEGA328_MCU,
+        .parent         = TYPE_ATMEGA_MCU,
+        .class_init     = atmega328_class_init,
+    }, {
+        .name           = TYPE_ATMEGA1280_MCU,
+        .parent         = TYPE_ATMEGA_MCU,
+        .class_init     = atmega1280_class_init,
+    }, {
+        .name           = TYPE_ATMEGA2560_MCU,
+        .parent         = TYPE_ATMEGA_MCU,
+        .class_init     = atmega2560_class_init,
+    }, {
+        .name           = TYPE_ATMEGA_MCU,
+        .parent         = TYPE_SYS_BUS_DEVICE,
+        .instance_size  = sizeof(AtmegaMcuState),
+        .class_size     = sizeof(AtmegaMcuClass),
+        .class_init     = atmega_class_init,
+        .abstract       = true,
+    }
+};
+
+DEFINE_TYPES(atmega_mcu_types)
diff --git a/hw/avr/Makefile.objs b/hw/avr/Makefile.objs
index 626b7064b3..4b6b911820 100644
--- a/hw/avr/Makefile.objs
+++ b/hw/avr/Makefile.objs
@@ -1 +1,2 @@
 obj-y += sample.o
+obj-y += atmega.o
-- 
2.21.0



^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v3 4/8] hw/avr: Add some Arduino boards
  2019-12-29 22:44 [PATCH v3 0/8] hw/avr: Introduce the Arduino boards Philippe Mathieu-Daudé
                   ` (2 preceding siblings ...)
  2019-12-29 22:45 ` [PATCH v3 3/8] hw/avr: Add some ATmega microcontrollers Philippe Mathieu-Daudé
@ 2019-12-29 22:45 ` Philippe Mathieu-Daudé
  2020-01-20  9:03   ` Igor Mammedov
  2019-12-29 22:45 ` [PATCH v3 5/8] tests/boot-serial-test: Test some Arduino boards (AVR based) Philippe Mathieu-Daudé
                   ` (5 subsequent siblings)
  9 siblings, 1 reply; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2019-12-29 22:45 UTC (permalink / raw)
  To: qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Igor Mammedov, Sarah Harris,
	Philippe Mathieu-Daudé,
	Michael Rolnik, Marc-André Lureau, Paolo Bonzini,
	Phillip Stevens

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

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
v2:
- Reword description adding more information (Aleksandar)
- Use DEFINE_TYPES (Igor)

Cc: Phillip Stevens <phillip.stevens@gmail.com>
Cc: Igor Mammedov <imammedo@redhat.com>
---
 hw/avr/arduino.c     | 177 +++++++++++++++++++++++++++++++++++++++++++
 hw/avr/Makefile.objs |   1 +
 2 files changed, 178 insertions(+)
 create mode 100644 hw/avr/arduino.c

diff --git a/hw/avr/arduino.c b/hw/avr/arduino.c
new file mode 100644
index 0000000000..ecaaa295d8
--- /dev/null
+++ b/hw/avr/arduino.c
@@ -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)
diff --git a/hw/avr/Makefile.objs b/hw/avr/Makefile.objs
index 4b6b911820..39ee3c32b2 100644
--- a/hw/avr/Makefile.objs
+++ b/hw/avr/Makefile.objs
@@ -1,2 +1,3 @@
 obj-y += sample.o
 obj-y += atmega.o
+obj-y += arduino.o
-- 
2.21.0



^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v3 5/8] tests/boot-serial-test: Test some Arduino boards (AVR based)
  2019-12-29 22:44 [PATCH v3 0/8] hw/avr: Introduce the Arduino boards Philippe Mathieu-Daudé
                   ` (3 preceding siblings ...)
  2019-12-29 22:45 ` [PATCH v3 4/8] hw/avr: Add some Arduino boards Philippe Mathieu-Daudé
@ 2019-12-29 22:45 ` Philippe Mathieu-Daudé
  2019-12-29 22:45 ` [PATCH v3 6/8] tests/acceptance: Do not set the machine type manually Philippe Mathieu-Daudé
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2019-12-29 22:45 UTC (permalink / raw)
  To: qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Sarah Harris,
	Philippe Mathieu-Daudé,
	Michael Rolnik, Marc-André Lureau, Paolo Bonzini

The Arduino Duemilanove is based on a AVR5 CPU, while the
Arduino MEGA2560 on a AVR6 CPU.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 tests/boot-serial-test.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tests/boot-serial-test.c b/tests/boot-serial-test.c
index e556f09db8..582a497963 100644
--- a/tests/boot-serial-test.c
+++ b/tests/boot-serial-test.c
@@ -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" },
-- 
2.21.0



^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v3 6/8] tests/acceptance: Do not set the machine type manually
  2019-12-29 22:44 [PATCH v3 0/8] hw/avr: Introduce the Arduino boards Philippe Mathieu-Daudé
                   ` (4 preceding siblings ...)
  2019-12-29 22:45 ` [PATCH v3 5/8] tests/boot-serial-test: Test some Arduino boards (AVR based) Philippe Mathieu-Daudé
@ 2019-12-29 22:45 ` Philippe Mathieu-Daudé
  2019-12-30 14:10   ` Wainer dos Santos Moschetta
  2019-12-29 22:45 ` [PATCH v3 7/8] tests/acceptance: Keep multilines comment consistent with other tests Philippe Mathieu-Daudé
                   ` (3 subsequent siblings)
  9 siblings, 1 reply; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2019-12-29 22:45 UTC (permalink / raw)
  To: qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Cleber Rosa, Sarah Harris,
	Philippe Mathieu-Daudé,
	Michael Rolnik, Marc-André Lureau, Paolo Bonzini

Since commit ba21bde93 we don't need to set the machine type
manually, the one set by the ":avocado: tags=machine" will be used.

Suggested-by: Cleber Rosa <crosa@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 tests/acceptance/machine_avr6.py | 1 -
 1 file changed, 1 deletion(-)

diff --git a/tests/acceptance/machine_avr6.py b/tests/acceptance/machine_avr6.py
index 7a7d8afc29..394b3d4f8f 100644
--- a/tests/acceptance/machine_avr6.py
+++ b/tests/acceptance/machine_avr6.py
@@ -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()
-- 
2.21.0



^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v3 7/8] tests/acceptance: Keep multilines comment consistent with other tests
  2019-12-29 22:44 [PATCH v3 0/8] hw/avr: Introduce the Arduino boards Philippe Mathieu-Daudé
                   ` (5 preceding siblings ...)
  2019-12-29 22:45 ` [PATCH v3 6/8] tests/acceptance: Do not set the machine type manually Philippe Mathieu-Daudé
@ 2019-12-29 22:45 ` Philippe Mathieu-Daudé
  2019-12-29 22:45 ` [PATCH v3 8/8] tests/acceptance: Test the Arduino MEGA2560 board Philippe Mathieu-Daudé
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2019-12-29 22:45 UTC (permalink / raw)
  To: qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Sarah Harris,
	Philippe Mathieu-Daudé,
	Michael Rolnik, Marc-André Lureau, Paolo Bonzini

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
note to maintainer: squash before merge?
---
 tests/acceptance/machine_avr6.py | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/tests/acceptance/machine_avr6.py b/tests/acceptance/machine_avr6.py
index 394b3d4f8f..94a8004e94 100644
--- a/tests/acceptance/machine_avr6.py
+++ b/tests/acceptance/machine_avr6.py
@@ -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)
 
-- 
2.21.0



^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v3 8/8] tests/acceptance: Test the Arduino MEGA2560 board
  2019-12-29 22:44 [PATCH v3 0/8] hw/avr: Introduce the Arduino boards Philippe Mathieu-Daudé
                   ` (6 preceding siblings ...)
  2019-12-29 22:45 ` [PATCH v3 7/8] tests/acceptance: Keep multilines comment consistent with other tests Philippe Mathieu-Daudé
@ 2019-12-29 22:45 ` Philippe Mathieu-Daudé
  2019-12-29 22:57 ` [PATCH v3 0/8] hw/avr: Introduce the Arduino boards no-reply
  2019-12-30 18:17 ` Michael Rolnik
  9 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2019-12-29 22:45 UTC (permalink / raw)
  To: qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Sarah Harris,
	Philippe Mathieu-Daudé,
	Michael Rolnik, Marc-André Lureau, Paolo Bonzini

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')

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 tests/acceptance/machine_avr6.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/acceptance/machine_avr6.py b/tests/acceptance/machine_avr6.py
index 94a8004e94..c5ff423e50 100644
--- a/tests/acceptance/machine_avr6.py
+++ b/tests/acceptance/machine_avr6.py
@@ -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
-- 
2.21.0



^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [PATCH v3 0/8] hw/avr: Introduce the Arduino boards
  2019-12-29 22:44 [PATCH v3 0/8] hw/avr: Introduce the Arduino boards Philippe Mathieu-Daudé
                   ` (7 preceding siblings ...)
  2019-12-29 22:45 ` [PATCH v3 8/8] tests/acceptance: Test the Arduino MEGA2560 board Philippe Mathieu-Daudé
@ 2019-12-29 22:57 ` no-reply
  2019-12-29 23:18   ` Philippe Mathieu-Daudé
  2019-12-30 18:17 ` Michael Rolnik
  9 siblings, 1 reply; 20+ messages in thread
From: no-reply @ 2019-12-29 22:57 UTC (permalink / raw)
  To: f4bug
  Cc: lvivier, thuth, S.E.Harris, qemu-devel, f4bug, mrolnik, pbonzini,
	marcandre.lureau

Patchew URL: https://patchew.org/QEMU/20191229224505.24466-1-f4bug@amsat.org/



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/20191229224505.24466-1-f4bug@amsat.org/testing.docker-quick@centos7/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-devel@redhat.com

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v3 0/8] hw/avr: Introduce the Arduino boards
  2019-12-29 22:57 ` [PATCH v3 0/8] hw/avr: Introduce the Arduino boards no-reply
@ 2019-12-29 23:18   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2019-12-29 23:18 UTC (permalink / raw)
  To: qemu-devel@nongnu.org Developers, Paolo Bonzini, patchew-devel
  Cc: Laurent Vivier, Marc-André Lureau, Thomas Huth,
	Michael Rolnik, Sarah Harris

On Sun, Dec 29, 2019 at 11:58 PM <no-reply@patchew.org> 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 patchew-devel@redhat.com

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 - [tag update]      patchew/20191229215158.5788-1-mrolnik@gmail.com
-> patchew/20191229215158.5788-1-mrolnik@gmail.com
 * [new tag]         patchew/20191229224505.24466-1-f4bug@amsat.org ->
patchew/20191229224505.24466-1-f4bug@amsat.org
fatal: failed to write ref-pack file
fatal: The remote end hung up unexpectedly

Is patchew disk full?


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v3 6/8] tests/acceptance: Do not set the machine type manually
  2019-12-29 22:45 ` [PATCH v3 6/8] tests/acceptance: Do not set the machine type manually Philippe Mathieu-Daudé
@ 2019-12-30 14:10   ` Wainer dos Santos Moschetta
  0 siblings, 0 replies; 20+ messages in thread
From: Wainer dos Santos Moschetta @ 2019-12-30 14:10 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Sarah Harris, Paolo Bonzini,
	Michael Rolnik, Cleber Rosa, Marc-André Lureau


On 12/29/19 8:45 PM, Philippe Mathieu-Daudé wrote:
> Since commit ba21bde93 we don't need to set the machine type
> manually, the one set by the ":avocado: tags=machine" will be used.

Correct.

>
> Suggested-by: Cleber Rosa <crosa@redhat.com>
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
>   tests/acceptance/machine_avr6.py | 1 -
>   1 file changed, 1 deletion(-)


Reviewed-by: Wainer dos Santos Moschetta <wainersm@redhat.com>


>
> diff --git a/tests/acceptance/machine_avr6.py b/tests/acceptance/machine_avr6.py
> index 7a7d8afc29..394b3d4f8f 100644
> --- a/tests/acceptance/machine_avr6.py
> +++ b/tests/acceptance/machine_avr6.py
> @@ -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()



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v3 0/8] hw/avr: Introduce the Arduino boards
  2019-12-29 22:44 [PATCH v3 0/8] hw/avr: Introduce the Arduino boards Philippe Mathieu-Daudé
                   ` (8 preceding siblings ...)
  2019-12-29 22:57 ` [PATCH v3 0/8] hw/avr: Introduce the Arduino boards no-reply
@ 2019-12-30 18:17 ` Michael Rolnik
  2020-01-19 22:50   ` Philippe Mathieu-Daudé
  9 siblings, 1 reply; 20+ messages in thread
From: Michael Rolnik @ 2019-12-30 18:17 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Laurent Vivier, Thomas Huth, Sarah Harris, QEMU Developers,
	Marc-André Lureau, Paolo Bonzini

[-- Attachment #1: Type: text/plain, Size: 2156 bytes --]

Hi Philippe.

Thank you for joining the effort.

Regards,
Michael Rolnik


On Mon, Dec 30, 2019 at 12:45 AM Philippe Mathieu-Daudé <f4bug@amsat.org>
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 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: <20191229215158.5788-1-mrolnik@gmail.com>
> 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
>
> --
> 2.21.0
>
>

-- 
Best Regards,
Michael Rolnik

[-- Attachment #2: Type: text/html, Size: 3156 bytes --]

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v3 0/8] hw/avr: Introduce the Arduino boards
  2019-12-30 18:17 ` Michael Rolnik
@ 2020-01-19 22:50   ` Philippe Mathieu-Daudé
  2020-01-20  5:29     ` Michael Rolnik
  0 siblings, 1 reply; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-01-19 22:50 UTC (permalink / raw)
  To: Michael Rolnik
  Cc: Laurent Vivier, Thomas Huth, Sarah Harris, QEMU Developers,
	Marc-André Lureau, Paolo Bonzini, Richard Henderson

Hi Michael,

On 12/30/19 7:17 PM, Michael Rolnik wrote:
> 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?

> Regards,
> Michael Rolnik
> 
> 
> On Mon, Dec 30, 2019 at 12:45 AM Philippe Mathieu-Daudé <f4bug@amsat.org
> <mailto:f4bug@amsat.org>> 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 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: <20191229215158.5788-1-mrolnik@gmail.com
>     <mailto:20191229215158.5788-1-mrolnik@gmail.com>>
>     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
> 
>     -- 
>     2.21.0
> 
> 
> 
> -- 
> Best Regards,
> Michael Rolnik


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v3 0/8] hw/avr: Introduce the Arduino boards
  2020-01-19 22:50   ` Philippe Mathieu-Daudé
@ 2020-01-20  5:29     ` Michael Rolnik
  0 siblings, 0 replies; 20+ messages in thread
From: Michael Rolnik @ 2020-01-20  5:29 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Laurent Vivier, Thomas Huth, Sarah Harris, QEMU Developers,
	Marc-André Lureau, Paolo Bonzini, Richard Henderson

[-- Attachment #1: Type: text/plain, Size: 2952 bytes --]

Sure, no problem.

On Mon, Jan 20, 2020 at 12:50 AM Philippe Mathieu-Daudé <f4bug@amsat.org>
wrote:

> Hi Michael,
>
> On 12/30/19 7:17 PM, Michael Rolnik wrote:
> > 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?
>
> > Regards,
> > Michael Rolnik
> >
> >
> > On Mon, Dec 30, 2019 at 12:45 AM Philippe Mathieu-Daudé <f4bug@amsat.org
> > <mailto:f4bug@amsat.org>> 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 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: <20191229215158.5788-1-mrolnik@gmail.com
> >     <mailto:20191229215158.5788-1-mrolnik@gmail.com>>
> >     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
> >
> >     --
> >     2.21.0
> >
> >
> >
> > --
> > Best Regards,
> > Michael Rolnik
>


-- 
Best Regards,
Michael Rolnik

[-- Attachment #2: Type: text/html, Size: 4527 bytes --]

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v3 4/8] hw/avr: Add some Arduino boards
  2019-12-29 22:45 ` [PATCH v3 4/8] hw/avr: Add some Arduino boards Philippe Mathieu-Daudé
@ 2020-01-20  9:03   ` Igor Mammedov
  2020-01-20  9:21     ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 20+ messages in thread
From: Igor Mammedov @ 2020-01-20  9:03 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Laurent Vivier, Thomas Huth, Sarah Harris, qemu-devel,
	Michael Rolnik, Paolo Bonzini, Marc-André Lureau,
	Phillip Stevens

On Sun, 29 Dec 2019 23:45:01 +0100
Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:

> 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
> 
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
> v2:
> - Reword description adding more information (Aleksandar)
> - Use DEFINE_TYPES (Igor)
> 
> Cc: Phillip Stevens <phillip.stevens@gmail.com>
> Cc: Igor Mammedov <imammedo@redhat.com>
> ---
>  hw/avr/arduino.c     | 177 +++++++++++++++++++++++++++++++++++++++++++
>  hw/avr/Makefile.objs |   1 +
>  2 files changed, 178 insertions(+)
>  create mode 100644 hw/avr/arduino.c
> 
> diff --git a/hw/avr/arduino.c b/hw/avr/arduino.c
> new file mode 100644
> index 0000000000..ecaaa295d8
> --- /dev/null
> +++ b/hw/avr/arduino.c
> @@ -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 {
[...]
> +    MemoryRegion extram;
> +} ArduinoMachineState;
> +
> +typedef struct ArduinoMachineClass {
[...]
> +    size_t extram_size;

extfoo doesn't seem to be used in this patch

> +} 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)
> diff --git a/hw/avr/Makefile.objs b/hw/avr/Makefile.objs
> index 4b6b911820..39ee3c32b2 100644
> --- a/hw/avr/Makefile.objs
> +++ b/hw/avr/Makefile.objs
> @@ -1,2 +1,3 @@
>  obj-y += sample.o
>  obj-y += atmega.o
> +obj-y += arduino.o



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v3 4/8] hw/avr: Add some Arduino boards
  2020-01-20  9:03   ` Igor Mammedov
@ 2020-01-20  9:21     ` Philippe Mathieu-Daudé
  2020-01-20 10:09       ` Igor Mammedov
  0 siblings, 1 reply; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-01-20  9:21 UTC (permalink / raw)
  To: Igor Mammedov, Philippe Mathieu-Daudé
  Cc: Laurent Vivier, Thomas Huth, Sarah Harris, qemu-devel,
	Michael Rolnik, Marc-André Lureau, Paolo Bonzini,
	Phillip Stevens

On 1/20/20 10:03 AM, Igor Mammedov wrote:
> On Sun, 29 Dec 2019 23:45:01 +0100
> Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
> 
>> 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
>>
>> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
>> ---
>> v2:
>> - Reword description adding more information (Aleksandar)
>> - Use DEFINE_TYPES (Igor)
>>
>> Cc: Phillip Stevens <phillip.stevens@gmail.com>
>> Cc: Igor Mammedov <imammedo@redhat.com>
>> ---
>>   hw/avr/arduino.c     | 177 +++++++++++++++++++++++++++++++++++++++++++
>>   hw/avr/Makefile.objs |   1 +
>>   2 files changed, 178 insertions(+)
>>   create mode 100644 hw/avr/arduino.c
>>
>> diff --git a/hw/avr/arduino.c b/hw/avr/arduino.c
>> new file mode 100644
>> index 0000000000..ecaaa295d8
>> --- /dev/null
>> +++ b/hw/avr/arduino.c
>> @@ -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 {
> [...]
>> +    MemoryRegion extram;
>> +} ArduinoMachineState;
>> +
>> +typedef struct ArduinoMachineClass {
> [...]
>> +    size_t extram_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?

>> +} 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)
>> diff --git a/hw/avr/Makefile.objs b/hw/avr/Makefile.objs
>> index 4b6b911820..39ee3c32b2 100644
>> --- a/hw/avr/Makefile.objs
>> +++ b/hw/avr/Makefile.objs
>> @@ -1,2 +1,3 @@
>>   obj-y += sample.o
>>   obj-y += atmega.o
>> +obj-y += arduino.o
> 
> 



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v3 4/8] hw/avr: Add some Arduino boards
  2020-01-20  9:21     ` Philippe Mathieu-Daudé
@ 2020-01-20 10:09       ` Igor Mammedov
  2020-01-20 11:05         ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 20+ messages in thread
From: Igor Mammedov @ 2020-01-20 10:09 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Laurent Vivier, Thomas Huth, Sarah Harris,
	Philippe Mathieu-Daudé,
	qemu-devel, Michael Rolnik, Marc-André Lureau,
	Paolo Bonzini, Phillip Stevens

On Mon, 20 Jan 2020 10:21:52 +0100
Philippe Mathieu-Daudé <philmd@redhat.com> wrote:

> On 1/20/20 10:03 AM, Igor Mammedov wrote:
> > On Sun, 29 Dec 2019 23:45:01 +0100
> > Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
> >   
> >> 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
> >>
> >> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> >> ---
> >> v2:
> >> - Reword description adding more information (Aleksandar)
> >> - Use DEFINE_TYPES (Igor)
> >>
> >> Cc: Phillip Stevens <phillip.stevens@gmail.com>
> >> Cc: Igor Mammedov <imammedo@redhat.com>
> >> ---
> >>   hw/avr/arduino.c     | 177 +++++++++++++++++++++++++++++++++++++++++++
> >>   hw/avr/Makefile.objs |   1 +
> >>   2 files changed, 178 insertions(+)
> >>   create mode 100644 hw/avr/arduino.c
> >>
> >> diff --git a/hw/avr/arduino.c b/hw/avr/arduino.c
> >> new file mode 100644
> >> index 0000000000..ecaaa295d8
> >> --- /dev/null
> >> +++ b/hw/avr/arduino.c
> >> @@ -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 {  
> > [...]  
> >> +    MemoryRegion extram;
> >> +} ArduinoMachineState;
> >> +
> >> +typedef struct ArduinoMachineClass {  
> > [...]  
> >> +    size_t extram_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.
 
> >> +} 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)
> >> diff --git a/hw/avr/Makefile.objs b/hw/avr/Makefile.objs
> >> index 4b6b911820..39ee3c32b2 100644
> >> --- a/hw/avr/Makefile.objs
> >> +++ b/hw/avr/Makefile.objs
> >> @@ -1,2 +1,3 @@
> >>   obj-y += sample.o
> >>   obj-y += atmega.o
> >> +obj-y += arduino.o  
> > 
> >   
> 



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v3 4/8] hw/avr: Add some Arduino boards
  2020-01-20 10:09       ` Igor Mammedov
@ 2020-01-20 11:05         ` Philippe Mathieu-Daudé
  2020-01-20 14:48           ` Igor Mammedov
  0 siblings, 1 reply; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-01-20 11:05 UTC (permalink / raw)
  To: Igor Mammedov
  Cc: Laurent Vivier, Thomas Huth, Sarah Harris,
	Philippe Mathieu-Daudé,
	qemu-devel, Michael Rolnik, Marc-André Lureau,
	Paolo Bonzini, Phillip Stevens

On 1/20/20 11:09 AM, Igor Mammedov wrote:
> On Mon, 20 Jan 2020 10:21:52 +0100
> Philippe Mathieu-Daudé <philmd@redhat.com> wrote:
> 
>> On 1/20/20 10:03 AM, Igor Mammedov wrote:
>>> On Sun, 29 Dec 2019 23:45:01 +0100
>>> Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
>>>    
>>>> 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
>>>>
>>>> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
>>>> ---
>>>> v2:
>>>> - Reword description adding more information (Aleksandar)
>>>> - Use DEFINE_TYPES (Igor)
>>>>
>>>> Cc: Phillip Stevens <phillip.stevens@gmail.com>
>>>> Cc: Igor Mammedov <imammedo@redhat.com>
>>>> ---
>>>>    hw/avr/arduino.c     | 177 +++++++++++++++++++++++++++++++++++++++++++
>>>>    hw/avr/Makefile.objs |   1 +
>>>>    2 files changed, 178 insertions(+)
>>>>    create mode 100644 hw/avr/arduino.c
>>>>
>>>> diff --git a/hw/avr/arduino.c b/hw/avr/arduino.c
>>>> new file mode 100644
>>>> index 0000000000..ecaaa295d8
>>>> --- /dev/null
>>>> +++ b/hw/avr/arduino.c
>>>> @@ -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 {
>>> [...]
>>>> +    MemoryRegion extram;
>>>> +} ArduinoMachineState;
>>>> +
>>>> +typedef struct ArduinoMachineClass {
>>> [...]
>>>> +    size_t extram_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

Thanks!

> 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?

>>>> +} 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)
>>>> diff --git a/hw/avr/Makefile.objs b/hw/avr/Makefile.objs
>>>> index 4b6b911820..39ee3c32b2 100644
>>>> --- a/hw/avr/Makefile.objs
>>>> +++ b/hw/avr/Makefile.objs
>>>> @@ -1,2 +1,3 @@
>>>>    obj-y += sample.o
>>>>    obj-y += atmega.o
>>>> +obj-y += arduino.o
>>>
>>>    
>>
> 



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v3 4/8] hw/avr: Add some Arduino boards
  2020-01-20 11:05         ` Philippe Mathieu-Daudé
@ 2020-01-20 14:48           ` Igor Mammedov
  0 siblings, 0 replies; 20+ messages in thread
From: Igor Mammedov @ 2020-01-20 14:48 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Laurent Vivier, Thomas Huth, Sarah Harris,
	Philippe Mathieu-Daudé,
	qemu-devel, Michael Rolnik, Marc-André Lureau,
	Paolo Bonzini, Phillip Stevens

On Mon, 20 Jan 2020 12:05:24 +0100
Philippe Mathieu-Daudé <philmd@redhat.com> wrote:

> On 1/20/20 11:09 AM, Igor Mammedov wrote:
> > On Mon, 20 Jan 2020 10:21:52 +0100
> > Philippe Mathieu-Daudé <philmd@redhat.com> wrote:
> >   
> >> On 1/20/20 10:03 AM, Igor Mammedov wrote:  
> >>> On Sun, 29 Dec 2019 23:45:01 +0100
> >>> Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
> >>>      
> >>>> 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
> >>>>
> >>>> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> >>>> ---
> >>>> v2:
> >>>> - Reword description adding more information (Aleksandar)
> >>>> - Use DEFINE_TYPES (Igor)
> >>>>
> >>>> Cc: Phillip Stevens <phillip.stevens@gmail.com>
> >>>> Cc: Igor Mammedov <imammedo@redhat.com>
> >>>> ---
> >>>>    hw/avr/arduino.c     | 177 +++++++++++++++++++++++++++++++++++++++++++
> >>>>    hw/avr/Makefile.objs |   1 +
> >>>>    2 files changed, 178 insertions(+)
> >>>>    create mode 100644 hw/avr/arduino.c
> >>>>
> >>>> diff --git a/hw/avr/arduino.c b/hw/avr/arduino.c
> >>>> new file mode 100644
> >>>> index 0000000000..ecaaa295d8
> >>>> --- /dev/null
> >>>> +++ b/hw/avr/arduino.c
> >>>> @@ -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 {  
> >>> [...]  
> >>>> +    MemoryRegion extram;
> >>>> +} ArduinoMachineState;
> >>>> +
> >>>> +typedef struct ArduinoMachineClass {  
> >>> [...]  
> >>>> +    size_t extram_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  
> 
> Thanks!
> 
> > 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).


> 
> >>>> +} 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)
> >>>> diff --git a/hw/avr/Makefile.objs b/hw/avr/Makefile.objs
> >>>> index 4b6b911820..39ee3c32b2 100644
> >>>> --- a/hw/avr/Makefile.objs
> >>>> +++ b/hw/avr/Makefile.objs
> >>>> @@ -1,2 +1,3 @@
> >>>>    obj-y += sample.o
> >>>>    obj-y += atmega.o
> >>>> +obj-y += arduino.o  
> >>>
> >>>      
> >>  
> >   
> 



^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2020-01-20 14:50 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-29 22:44 [PATCH v3 0/8] hw/avr: Introduce the Arduino boards Philippe Mathieu-Daudé
2019-12-29 22:44 ` [PATCH v3 1/8] hw/char/avr: Reduce USART I/O size Philippe Mathieu-Daudé
2019-12-29 22:44 ` [PATCH v3 2/8] hw/timer/avr_timer16: Rename memory region debugging name Philippe Mathieu-Daudé
2019-12-29 22:45 ` [PATCH v3 3/8] hw/avr: Add some ATmega microcontrollers Philippe Mathieu-Daudé
2019-12-29 22:45 ` [PATCH v3 4/8] hw/avr: Add some Arduino boards Philippe Mathieu-Daudé
2020-01-20  9:03   ` Igor Mammedov
2020-01-20  9:21     ` Philippe Mathieu-Daudé
2020-01-20 10:09       ` Igor Mammedov
2020-01-20 11:05         ` Philippe Mathieu-Daudé
2020-01-20 14:48           ` Igor Mammedov
2019-12-29 22:45 ` [PATCH v3 5/8] tests/boot-serial-test: Test some Arduino boards (AVR based) Philippe Mathieu-Daudé
2019-12-29 22:45 ` [PATCH v3 6/8] tests/acceptance: Do not set the machine type manually Philippe Mathieu-Daudé
2019-12-30 14:10   ` Wainer dos Santos Moschetta
2019-12-29 22:45 ` [PATCH v3 7/8] tests/acceptance: Keep multilines comment consistent with other tests Philippe Mathieu-Daudé
2019-12-29 22:45 ` [PATCH v3 8/8] tests/acceptance: Test the Arduino MEGA2560 board Philippe Mathieu-Daudé
2019-12-29 22:57 ` [PATCH v3 0/8] hw/avr: Introduce the Arduino boards no-reply
2019-12-29 23:18   ` Philippe Mathieu-Daudé
2019-12-30 18:17 ` Michael Rolnik
2020-01-19 22:50   ` Philippe Mathieu-Daudé
2020-01-20  5:29     ` Michael Rolnik

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.