From nobody Mon Feb 9 08:38:58 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=1577659810; cv=none; d=zohomail.com; s=zohoarc; b=F3QU+ap7MZ8DWTjgP1KaQ/ug0CbgNltezir7Pto5LZQjTlB5DTK4UJgqLgUz26/51aQhGgk6TqZwAvxxMF9nOmiNBlxCV4Q34lQjmKCR+KDR6IH6x9pO7HM/5N8JvmKDJ8P6wlRCc/c25GJn/BMhjnUnA7jWUTrdSBDGLP7O45Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577659810; 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=/C5LDBn8jEim4X6RLEQh0yFX+kYNQVc4nphUu0gwNBg=; b=loZEcAFoB5BbWNKb+mJnkzACvacwKbrxB4uUtvM2/hFWcCLbyszxQX97r8bVQt72nN9y6yxyCLGnGV43vPCEhO4BnTvIECYPnm75aZ7ANOA6zlRxEcCsNSlRIKCuNSdvwtd6jwYqHbHVQmJLroKRgpZNRqEcYJD0OagVC/U739M= 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 15776598107661020.3973925170816; Sun, 29 Dec 2019 14:50:10 -0800 (PST) Received: from localhost ([::1]:55734 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ilhNx-0006rh-II for importer@patchew.org; Sun, 29 Dec 2019 17:50:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52842) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ilhJF-0002SI-Ny for qemu-devel@nongnu.org; Sun, 29 Dec 2019 17:45:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ilhJE-0001jA-1E for qemu-devel@nongnu.org; Sun, 29 Dec 2019 17:45:17 -0500 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:40684) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ilhJD-0001gr-QV for qemu-devel@nongnu.org; Sun, 29 Dec 2019 17:45:15 -0500 Received: by mail-wr1-x442.google.com with SMTP id c14so31243698wrn.7 for ; Sun, 29 Dec 2019 14:45:15 -0800 (PST) Received: from x1w.home ([2a01:cb18:8372:6b00:691b:aac5:8837:d4da]) by smtp.gmail.com with ESMTPSA id x1sm42709188wru.50.2019.12.29.14.45.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Dec 2019 14:45:14 -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=/C5LDBn8jEim4X6RLEQh0yFX+kYNQVc4nphUu0gwNBg=; b=krEj+0Yri67exkIJuscxSt3Zq1bQaoS3i/ncIHToVPvD/TrP89ZDlBGZkOvEkNlO9c GYVwWYG7h88lWC0+NulK2A00wRIqmjOV7SWXc8MwSA2gVE/Mh/Hh7KLSPLVcuv1WH8Gf RsdQ7e+V22g0AdNczPUC3HtbgCHeuOiQ1AZAoQvpyBJWQUsruFFDC6fGnAFb1aTLkVvq MTOu+ZjFsc1gopXHVAt0HNeNeUSha7vyJjOiM21zFM/oCPLIu8jd7dxpSmDIkQjdJKUM 8TId4Nd1lAZ/yW1LrxkpmnSfePWa75NIlmcj8jwWtks7hiSTjrvEvT48W3p1OMaPyUsD ypAA== 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=/C5LDBn8jEim4X6RLEQh0yFX+kYNQVc4nphUu0gwNBg=; b=RExLqNH0n57otwyjZmFQ0wKXlUOzN6v1jshcO8QZ0OVcjjO431/YfmyG+b8/oIQtTj UHFxaGXp6nnmOjvIbl5fO8DkrxDoneG2GRkKDiold1HVE2fS15S4uHolqPtYndxrpsPO qD5S5xemSUDH9ty4E1t9gh1mnJhGqs2EV41c/POTsmph+onj5UU6khcYonuDzZLHtdK6 JszICPegGT41Hy4+T8yAiFw8tSBka2q/PEJVJyNBTX4pAqc76Lt/TpHMm8FO5ninN2yh pNcN9Asx5NrglclUeUliOcd0EWGtUUsu50rnEaBV7r9Z2Uv3y0qRu5bxdMJVIYInTvNx Sqnw== X-Gm-Message-State: APjAAAVuRspBVTcchZ3cEGpTsmH5QShPXRnIeCqtHPkee06V0pae2SpM 5PUz3GAOpHF87Lc00Gxvw3N7U01n/18= X-Google-Smtp-Source: APXvYqzABapyzQdUjvn92NUZvnPMGAPk0zBVDJd5DYZ9d24/uWaGOX15QS0Ml9AH2aYFgMCRC41G2w== X-Received: by 2002:a5d:5267:: with SMTP id l7mr67643282wrc.84.1577659514656; Sun, 29 Dec 2019 14:45:14 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v3 4/8] hw/avr: Add some Arduino boards Date: Sun, 29 Dec 2019 23:45:01 +0100 Message-Id: <20191229224505.24466-5-f4bug@amsat.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191229224505.24466-1-f4bug@amsat.org> References: <20191229224505.24466-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::442 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 , Thomas Huth , Igor Mammedov , Sarah Harris , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Michael Rolnik , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Phillip Stevens 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 Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- v2: - Reword description adding more information (Aleksandar) - Use DEFINE_TYPES (Igor) Cc: Phillip Stevens Cc: Igor Mammedov --- 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=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 "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_MACH= INE) +#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 =3D qemu_find_file(QEMU_FILE_TYPE_BIOS, firmware); + if (filename =3D=3D NULL) { + error_report("Unable to find %s", firmware); + exit(1); + } + + bytes_loaded =3D load_elf(filename, NULL, NULL, NULL, NULL, NULL, NULL, + 0, EM_NONE, 0, 0); + if (bytes_loaded < 0) { + bytes_loaded =3D load_image_targphys(filename, OFFSET_CODE, flash_= size); + } + if (bytes_loaded < 0) { + error_report("Unable to load firmware image %s as ELF or raw binar= y", + firmware); + exit(1); + } +} + +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) { + load_firmware(machine->firmware, memory_region_size(&ams->mcu.flas= h)); + } +} + +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"; + mc->is_default =3D true; + 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/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 +=3D sample.o obj-y +=3D atmega.o +obj-y +=3D arduino.o --=20 2.21.0