From nobody Sat Feb 7 04:01:30 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1579827666; cv=none; d=zohomail.com; s=zohoarc; b=ItzppZtYHSpON1Nl8oxaAVw9SfuSjXXz9aUE+e2StMNCF0wL3AMU4Jz5ebovs/LR7vSyxvybBrrnvBvrzcWUbuillHbdCsyOFW0muw43YVXvhvk+kmC9+vdFgVVf74EuXr+xg9XRhWiHPLHrVhhGWCdOqlUDM1QUNtgnxZwrXog= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579827666; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=sLoFhPRTsuQW0YnaNUatCV3smyi2QhBP5JRij1kuWcA=; b=bpDDqTgVowqj3lTaCN0bQ3I7qAj7lDf5jAf5Fm7plLugKMh19SLEbObkl4UrRz63L3SXzjx2nLKqIlqbyXjdbEAgAf+M5d9mHbdjrmMvT2KG82D7PM3HBLZn889ywL+ZGVC3qaZn0gYvKkzTmO1znyZTnkPRZZKfwFT7godpkSY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1579827666984110.34355677759936; Thu, 23 Jan 2020 17:01:06 -0800 (PST) Received: from localhost ([::1]:36162 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iunLN-0003oG-U5 for importer@patchew.org; Thu, 23 Jan 2020 20:01:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44586) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iunCz-0002i9-SZ for qemu-devel@nongnu.org; Thu, 23 Jan 2020 19:52:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iunCy-0005fv-2I for qemu-devel@nongnu.org; Thu, 23 Jan 2020 19:52:25 -0500 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:34474) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iunCx-0005ek-RX; Thu, 23 Jan 2020 19:52:24 -0500 Received: by mail-wr1-x441.google.com with SMTP id t2so90970wrr.1; Thu, 23 Jan 2020 16:52:23 -0800 (PST) Received: from x1w.redhat.com (113.red-83-57-172.dynamicip.rima-tde.net. [83.57.172.113]) by smtp.gmail.com with ESMTPSA id s139sm4598271wme.35.2020.01.23.16.52.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jan 2020 16:52:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sLoFhPRTsuQW0YnaNUatCV3smyi2QhBP5JRij1kuWcA=; b=QdUtDPZi7Mq5jPI3IMXwK/f302XolF+ZplVhL1Pa0Sz0m09yfm98Ke55GvfmSIbnSV gbeBa6BGaCzqUVVzlauoUa51/eMeqw0h7Zs9tT0H6wUJK1bk1fJ60W2avNb0chl/w4SJ DdJ6hXs+cJzCjxFkENsaFyeqL1GKfrymblDyTzZ7diush5/OoqN/mYfxQS6XdqlyG5QE U/OfwQb99R4WQ5lp2Z1Z0hYx20niFp3Rg2pGbK3O5YPivCKqQYV2a2v81ng+VHPIGbHE Gxe06DIu9940venz9yw/hjq/H653tLQECpUIB3OdUoAebLDAiK+f7nZekcK0tBvev5nh aLIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=sLoFhPRTsuQW0YnaNUatCV3smyi2QhBP5JRij1kuWcA=; b=Sgg7bHUOPelb+ZiR1XGQoE6W2mYJBckomB2o12z4kqazPzstK5ARriwy1brfwRH1OV lmv1o+Rz7Mu5jtgVt0HjNJVQGL1RFIHrg5K7ReO+H7ebKS2HrJj3ZCi3qyEnG8VY6fMU 2H738In/apsaoLQvDAQw6hT/B4R++JHIc/zFq4nR0W2fquLGTjMX20jZZzVa43iEvliZ 6sEfjSrmWNFHoo7UGxrwCL3xqlJw48o9zJCmOKEHOahxsWzovQBVn/AjqUqffvl0b9Cw j9IgQHnUp39MmzFtS7XZJvG2V6GAhs454Eh1/yXog9u+BMEz6A46f/yXQOmRM1up/Nsz SPWw== X-Gm-Message-State: APjAAAWogbDkJJSQVys5sROeeA7Trx1Rn3ofsfeAXKPCsxcSK6HAMiwF KPhEO25asE+0jm6aVC+9bQ0HdpHL X-Google-Smtp-Source: APXvYqzCGtGqYfoPHmtcJYNvZ7E8CpUJ0DeRZhcvTLFIaBr/0ohOtOq+5hq2t3LhnlXlRbW+sT2hNA== X-Received: by 2002:a5d:6652:: with SMTP id f18mr893224wrw.246.1579827142619; Thu, 23 Jan 2020 16:52:22 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, mrolnik@gmail.com, richard.henderson@linaro.org, me@xcancerberox.com.ar Subject: [PATCH rc2 21/25] hw/avr: Add some Arduino boards Date: Fri, 24 Jan 2020 01:51:27 +0100 Message-Id: <20200124005131.16276-22-f4bug@amsat.org> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200124005131.16276-1-f4bug@amsat.org> References: <20200124005131.16276-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::441 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Fam Zheng , S.E.Harris@kent.ac.uk, qemu-riscv@nongnu.org, Eduardo Habkost , Sagar Karandikar , dovgaluk@ispras.ru, Bastian Koppelmann , thuth@redhat.com, Markus Armbruster , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Alistair Francis , imammedo@redhat.com, Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Palmer Dabbelt , aleksandar.m.mail@gmail.com, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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 Reviewed-by: Igor Mammedov Signed-off-by: Philippe Mathieu-Daud=C3=A9 Message-Id: <20200120220107.17825-15-f4bug@amsat.org> Signed-off-by: Richard Henderson Reviewed-by: Joaquin de Andres --- rc2: - Use avr_load_firmware (Aleksandar) - No default machine on AVR (Richard) - Add entry in MAINTAINERS (Michael is still the maintainer of hw/avr/) --- hw/avr/arduino.c | 151 +++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 6 ++ hw/avr/Kconfig | 4 ++ hw/avr/Makefile.objs | 1 + 4 files changed, 162 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..2fb2e96ffe --- /dev/null +++ b/hw/avr/arduino.c @@ -0,0 +1,151 @@ +/* + * QEMU Arduino boards + * + * Copyright (c) 2019 Philippe Mathieu-Daud=C3=A9 + * + * 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 "qapi/error.h" +#include "hw/boards.h" +#include "atmel_atmega.h" +#include "boot.h" + +typedef struct ArduinoMachineState { + /*< private >*/ + MachineState parent_obj; + /*< public >*/ + AtmegaMcuState mcu; +} ArduinoMachineState; + +typedef struct ArduinoMachineClass { + /*< private >*/ + MachineClass parent_class; + /*< public >*/ + const char *mcu_type; + uint64_t xtal_hz; +} 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_MACH= INE) +#define ARDUINO_MACHINE_GET_CLASS(obj) \ + OBJECT_GET_CLASS(ArduinoMachineClass, (obj), TYPE_ARDUINO_MACHINE) + +static void arduino_machine_init(MachineState *machine) +{ + ArduinoMachineClass *amc =3D ARDUINO_MACHINE_GET_CLASS(machine); + ArduinoMachineState *ams =3D ARDUINO_MACHINE(machine); + + sysbus_init_child_obj(OBJECT(machine), "mcu", &ams->mcu, sizeof(ams->m= cu), + 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) { + if (!avr_load_firmware(&ams->mcu.cpu, machine, + &ams->mcu.flash, machine->firmware)) { + exit(1); + } + } +} + +static void arduino_machine_class_init(ObjectClass *oc, void *data) +{ + MachineClass *mc =3D MACHINE_CLASS(oc); + + mc->init =3D arduino_machine_init; + mc->default_cpus =3D 1; + mc->min_cpus =3D mc->default_cpus; + mc->max_cpus =3D mc->default_cpus; + mc->no_floppy =3D 1; + mc->no_cdrom =3D 1; + mc->no_parallel =3D 1; +} + +static void arduino_duemilanove_class_init(ObjectClass *oc, void *data) +{ + MachineClass *mc =3D MACHINE_CLASS(oc); + ArduinoMachineClass *amc =3D ARDUINO_MACHINE_CLASS(oc); + + /* https://www.arduino.cc/en/Main/ArduinoBoardDuemilanove */ + mc->desc =3D "Arduino Duemilanove (ATmega168)", + mc->alias =3D "2009"; + amc->mcu_type =3D TYPE_ATMEGA168_MCU; + amc->xtal_hz =3D 16 * 1000 * 1000; +}; + +static void arduino_uno_class_init(ObjectClass *oc, void *data) +{ + MachineClass *mc =3D MACHINE_CLASS(oc); + ArduinoMachineClass *amc =3D ARDUINO_MACHINE_CLASS(oc); + + /* https://store.arduino.cc/arduino-uno-rev3 */ + mc->desc =3D "Arduino UNO (ATmega328P)"; + mc->alias =3D "uno"; + amc->mcu_type =3D TYPE_ATMEGA328_MCU; + amc->xtal_hz =3D 16 * 1000 * 1000; +}; + +static void arduino_mega_class_init(ObjectClass *oc, void *data) +{ + MachineClass *mc =3D MACHINE_CLASS(oc); + ArduinoMachineClass *amc =3D ARDUINO_MACHINE_CLASS(oc); + + /* https://www.arduino.cc/en/Main/ArduinoBoardMega */ + mc->desc =3D "Arduino Mega (ATmega1280)"; + mc->alias =3D "mega"; + amc->mcu_type =3D TYPE_ATMEGA1280_MCU; + amc->xtal_hz =3D 16 * 1000 * 1000; +}; + +static void arduino_mega2560_class_init(ObjectClass *oc, void *data) +{ + MachineClass *mc =3D MACHINE_CLASS(oc); + ArduinoMachineClass *amc =3D ARDUINO_MACHINE_CLASS(oc); + + /* https://store.arduino.cc/arduino-mega-2560-rev3 */ + mc->desc =3D "Arduino Mega 2560 (ATmega2560)"; + mc->alias =3D "mega2560"; + amc->mcu_type =3D TYPE_ATMEGA2560_MCU; + amc->xtal_hz =3D 16 * 1000 * 1000; /* CSTCE16M0V53-R0 */ +}; + +static const TypeInfo arduino_machine_types[] =3D { + { + .name =3D MACHINE_TYPE_NAME("arduino-duemilanove"), + .parent =3D TYPE_ARDUINO_MACHINE, + .class_init =3D arduino_duemilanove_class_init, + }, { + .name =3D MACHINE_TYPE_NAME("arduino-uno"), + .parent =3D TYPE_ARDUINO_MACHINE, + .class_init =3D arduino_uno_class_init, + }, { + .name =3D MACHINE_TYPE_NAME("arduino-mega"), + .parent =3D TYPE_ARDUINO_MACHINE, + .class_init =3D arduino_mega_class_init, + }, { + .name =3D MACHINE_TYPE_NAME("arduino-mega-2560-v3"), + .parent =3D TYPE_ARDUINO_MACHINE, + .class_init =3D arduino_mega2560_class_init, + }, { + .name =3D TYPE_ARDUINO_MACHINE, + .parent =3D TYPE_MACHINE, + .instance_size =3D sizeof(ArduinoMachineState), + .class_size =3D sizeof(ArduinoMachineClass), + .class_init =3D arduino_machine_class_init, + .abstract =3D true, + } +}; + +DEFINE_TYPES(arduino_machine_types) diff --git a/MAINTAINERS b/MAINTAINERS index 066515ac8e..07c8912489 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -904,6 +904,12 @@ F: hw/misc/atmel_power.c F: include/hw/misc/atmel_power.h F: tests/acceptance/machine_avr6.py =20 +Arduino +M: Philippe Mathieu-Daud=C3=A9 +S: Maintained +F: hw/avr/arduino.c +F: hw/avr/atmel_atmega.* + CRIS Machines ------------- Axis Dev88 diff --git a/hw/avr/Kconfig b/hw/avr/Kconfig index da3b10afec..59d9649d27 100644 --- a/hw/avr/Kconfig +++ b/hw/avr/Kconfig @@ -3,3 +3,7 @@ config ATMEL_ATMEGA_MCU select ATMEL_TIMER16 select ATMEL_USART select ATMEL_POWER + +config ARDUINO + select ATMEL_ATMEGA_MCU + select UNIMP diff --git a/hw/avr/Makefile.objs b/hw/avr/Makefile.objs index 1f73fd5469..c8a131923c 100644 --- a/hw/avr/Makefile.objs +++ b/hw/avr/Makefile.objs @@ -1,2 +1,3 @@ obj-y +=3D boot.o obj-$(CONFIG_ATMEL_ATMEGA_MCU) +=3D atmel_atmega.o +obj-$(CONFIG_ARDUINO) +=3D arduino.o --=20 2.21.1