From: Igor Mammedov <imammedo@redhat.com>
To: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
Cc: "Sarah Harris" <S.E.Harris@kent.ac.uk>,
"Pavel Dovgalyuk" <dovgaluk@ispras.ru>,
"Thomas Huth" <huth@tuxfamily.org>,
"Joaquin de Andres" <me@xcancerberox.com.ar>,
"Richard Henderson" <richard.henderson@linaro.org>,
qemu-devel@nongnu.org, "Michael Rolnik" <mrolnik@gmail.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Aleksandar Markovic" <aleksandar.m.mail@gmail.com>
Subject: Re: [RFC PATCH 07/10] hw/avr: Add few Arduino boards
Date: Fri, 20 Dec 2019 11:01:00 +0100 [thread overview]
Message-ID: <20191220110100.4528a3ea@redhat.com> (raw)
In-Reply-To: <20191128015030.27543-8-f4bug@amsat.org>
On Thu, 28 Nov 2019 02:50:27 +0100
Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
> Add famous Arduino boards:
>
> - Arduino Duemilanove
> - Arduino Mega
>
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
> hw/avr/arduino.c | 173 +++++++++++++++++++++++++++++++++++++++++++
> hw/avr/Makefile.objs | 1 +
> 2 files changed, 174 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..191193d614
> --- /dev/null
> +++ b/hw/avr/arduino.c
> @@ -0,0 +1,173 @@
> +/*
> + * 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 ArduinoBoardConfig {
> + const char *name;
> + const char *desc;
> + const char *alias;
> + const char *mcu_type;
> + uint64_t xtal_hz;
> + size_t extram_size;
> + bool is_default;
> +} ArduinoBoardConfig;
> +
> +static const ArduinoBoardConfig arduino_boards[] = {
> + {
> + /* https://www.arduino.cc/en/Main/ArduinoBoardDuemilanove */
> + .name = MACHINE_TYPE_NAME("arduino-duemilanove"),
> + .desc = "Arduino Duemilanove (ATmega168)",
> + .alias = "2009",
> + .mcu_type = TYPE_ATMEGA168,
> + .xtal_hz = 16 * 1000 * 1000,
> + }, {
> + /* https://store.arduino.cc/arduino-uno-rev3 */
> + .name = MACHINE_TYPE_NAME("arduino-uno"),
> + .desc = "Arduino Duemilanove (ATmega328P)",
> + .alias = "UNO",
> + .mcu_type = TYPE_ATMEGA328,
> + .xtal_hz = 16 * 1000 * 1000,
> + }, {
> + /* https://www.arduino.cc/en/Main/ArduinoBoardMega */
> + .name = MACHINE_TYPE_NAME("arduino-mega"),
> + .desc = "Arduino Mega (ATmega1280)",
> + .alias = "MEGA",
> + .mcu_type = TYPE_ATMEGA1280,
> + .xtal_hz = 16 * 1000 * 1000,
> + }, {
> + /* https://store.arduino.cc/arduino-mega-2560-rev3 */
> + .name = MACHINE_TYPE_NAME("arduino-mega-2560-v3"),
> + .desc = "Arduino Mega 2560 (ATmega2560)",
> + .alias = "MEGA2560",
> + .mcu_type = TYPE_ATMEGA2560,
> + .xtal_hz = 16 * 1000 * 1000, /* CSTCE16M0V53-R0 */
> + .is_default = true,
> + },
> +};
It's common pre QOM pattern, but it would be better use machine class
for defining machine properties. See
baa4732bc10b3fd7 aspeed: Remove AspeedBoardConfig array and use AspeedMachineClass
that recently did conversion.
> +
> +typedef struct ArduinoMachineState {
> + /*< private >*/
> + MachineState parent_obj;
> + /*< public >*/
> + AtmegaState mcu;
> + MemoryRegion extram;
> +} ArduinoMachineState;
> +
> +typedef struct ArduinoMachineClass {
> + /*< private >*/
> + MachineClass parent_class;
> + /*< public >*/
> + const ArduinoBoardConfig *config;
> +} 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->config->mcu_type);
> + object_property_set_uint(OBJECT(&ams->mcu), amc->config->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);
> + ArduinoMachineClass *amc = ARDUINO_MACHINE_CLASS(oc);
> + const ArduinoBoardConfig *cfg = data;
> +
> + mc->desc = cfg->desc;
> + mc->alias = cfg->alias;
> + 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;
> + mc->is_default = cfg->is_default;
> + mc->default_ram_size = cfg->extram_size;
> + amc->config = cfg;
> +}
> +
> +static const TypeInfo arduino_machine_type = {
> + .name = TYPE_ARDUINO_MACHINE,
> + .parent = TYPE_MACHINE,
> + .instance_size = sizeof(ArduinoMachineState),
> + .class_size = sizeof(ArduinoMachineClass),
> + .abstract = true,
> +};
> +
> +static void arduino_machine_types(void)
> +{
> + size_t i;
> +
> + type_register_static(&arduino_machine_type);
> + for (i = 0; i < ARRAY_SIZE(arduino_boards); ++i) {
> + TypeInfo ti = {
> + .name = arduino_boards[i].name,
> + .parent = TYPE_ARDUINO_MACHINE,
> + .class_init = arduino_machine_class_init,
> + .class_data = (void *)&arduino_boards[i],
> + };
> + type_register(&ti);
> + }
> +}
> +
> +type_init(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
next prev parent reply other threads:[~2019-12-20 10:02 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-28 1:50 [RFC PATCH 00/10] hw/avr: Introduce the Arduino board Philippe Mathieu-Daudé
2019-11-28 1:50 ` [NOTFORMERGE PATCH 01/10] hw/avr: Kludge to fix build failure Philippe Mathieu-Daudé
2019-11-28 1:50 ` [PATCH 02/10] target/avr: Remove unused include Philippe Mathieu-Daudé
2019-11-28 1:50 ` [PATCH 03/10] target/avr: Add missing definitions Philippe Mathieu-Daudé
2019-11-28 1:50 ` [NOTFORMERGE PATCH 04/10] target/avr: Fix IRQ count Philippe Mathieu-Daudé
2019-11-28 1:50 ` [RFC PATCH 05/10] hw/char/avr: Reduce USART I/O size Philippe Mathieu-Daudé
2019-11-28 1:50 ` [RFC PATCH 06/10] hw/avr: Add ATmega microcontrollers Philippe Mathieu-Daudé
2019-11-28 1:55 ` Philippe Mathieu-Daudé
2019-11-28 9:28 ` Aleksandar Markovic
2019-11-28 9:48 ` dovgaluk
2019-11-28 10:20 ` Aleksandar Markovic
2019-11-28 11:08 ` dovgaluk
2019-11-28 11:25 ` Aleksandar Markovic
2019-11-28 11:12 ` Philippe Mathieu-Daudé
2019-11-28 11:36 ` Philippe Mathieu-Daudé
2019-12-20 10:09 ` Igor Mammedov
2019-12-20 12:58 ` Philippe Mathieu-Daudé
2019-12-20 15:03 ` Igor Mammedov
2019-11-28 1:50 ` [RFC PATCH 07/10] hw/avr: Add few Arduino boards Philippe Mathieu-Daudé
2019-12-20 10:01 ` Igor Mammedov [this message]
2019-11-28 1:50 ` [PATCH 08/10] tests/acceptance: Keep multilines comment consistent with other tests Philippe Mathieu-Daudé
2019-11-28 1:50 ` [RFC PATCH 09/10] tests/acceptance: Use the ATmega2560 board Philippe Mathieu-Daudé
2019-11-28 1:50 ` [NOTFORMERGE PATCH 10/10] hw/avr: Remove the 'sample' board Philippe Mathieu-Daudé
2019-11-28 10:30 ` [RFC PATCH 00/10] hw/avr: Introduce the Arduino board Michael Rolnik
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191220110100.4528a3ea@redhat.com \
--to=imammedo@redhat.com \
--cc=S.E.Harris@kent.ac.uk \
--cc=aleksandar.m.mail@gmail.com \
--cc=dovgaluk@ispras.ru \
--cc=f4bug@amsat.org \
--cc=huth@tuxfamily.org \
--cc=marcandre.lureau@redhat.com \
--cc=me@xcancerberox.com.ar \
--cc=mrolnik@gmail.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.