当前位置: 首页 > news >正文

【物联网设备端开发】ESP开发工具:QEMU如何模拟以太网口接入网络

以太网口支持

ESP-IDF中添加了对Opencores以太网MAC的支持。

  • 运行以太网示例时,启用CONFIG_EXAMPLE_CONNECT_ETHERNETCONFIG_EXAMPLE_USE_OPENETH.。
  • 运行自定义应用程序时,启用CONFIG_ETH_USE_OPENETH 并初始化以太网驱动程序,如示例 /common_components/protocol_example.common/connect.c 中所示(查找 esp_eth_mac_new_openeth)。

启动QEMU时,使用open_eth网络设备。

用户模式网络

例如,要在用户模式下启动网络(仅TCP/UDP,模拟设备位于NAT之后),请在QEMU命令行中添加以下选项:

-nic user,model=open_eth

一些ESP项目(特别是运行TCP侦听器)可能需要设置端口转发,

-nic user,model=open_eth,id=lo0,hostfwd=tcp:127.0.0.1:PORT_HOST-:PORT_GUEST

(例如,asio-echo服务器默认在2222上设置服务器,因此hostfwd=tcp:127.0.0.1:22222-:2222 允许从主机访问 nc localhost 2222

指定引导模式

要指定所需的 strapping 模式, 在运行QEMU时需要添加以下参数:

-global driver=esp32.gpio,property=strap_mode,value=0x0f

这将设置 GPIO_STRAP 寄存器的值。

  • 使用 0x12 作为闪存启动模式(默认)
  • 0x0f 用于仅UART下载模式(因为SDIO部分未实现)

Specifying eFuse storage

Add extra arguments to the command line:

-drive file=qemu_efuse.bin,if=none,format=raw,id=efuse
-global driver=nvram.esp32.efuse,property=drive,value=efuse

The first argument creates a block device backed by qemu_efuse.bin file, with identifier efuse. The second line configures nvram.esp32.efuse device to use this block device for storage.

The file must be created before starting QEMU:

dd if=/dev/zero bs=1 count=124 of=/tmp/qemu_efuse.bin

124 bytes is the total size of ESP32 eFuse blocks.

Note

Specifying eFuse storage is mandatory to test out any platform security features like “Secure Boot” or “Flash Encryption”.

Emulating ESP32 ECO3

For the application to detect the emulated chip as ESP32 ECO3, the following virtual efuses must be set:

  • CHIP_VER_REV1
  • CHIP_VER_REV2

Here is the corresponding efuse file (in hexadecimal, produced using xxd -p):

000000000000000000000000008000000000000000001000000000000000
000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000
00000000

To convert this (efuse.hex) back to binary, run xxd -r -p efuse.hex qemu_efuse.bin.

Alternatively, these bits can be set using espefuse:

espefuse.py --port=socket://localhost:5555 burn_efuse CHIP_VER_REV1
espefuse.py --port=socket://localhost:5555 burn_efuse CHIP_VER_REV2

Disabling the watchdogs

By default, Timer Group watchdog timers are emulated, and TG0 WDT is enabled at reset. It is sometimes useful to disable these watchdog timers. This can be done by adding the following to the command line:

-global driver=timer.esp32.timg,property=wdt_disable,value=true

This disables the emulation of TG watchdog timers. Even if the application configures them, they will not fire.

The RTC watchdog timer is not emulated yet, so it doesn’t need to be disabled.

Using esptool.py and espefuse.py to interact with QEMU

  1. Start QEMU:

    build/qemu-system-xtensa -nographic \-machine esp32 \-drive file=flash_image.bin,if=mtd,format=raw \-global driver=esp32.gpio,property=strap_mode,value=0x0f \-drive file=qemu_efuse.bin,if=none,format=raw,id=efuse \-global driver=nvram.esp32.efuse,property=drive,value=efuse \-serial tcp::5555,server,nowait
    

    The final line redirects the emulated UART to TCP port 5555 (QEMU acts as a server).

    Type q and press Enter at any time to quit.

  2. Run esptool.py:

    esptool.py -p socket://localhost:5555 flash_id
    

    Flashing with idf.py also works:

    export ESPPORT=socket://localhost:5555
    idf.py flash
    
  3. Or, run espefuse.py:

    espefuse.py --port socket://localhost:5555 --do-not-confirm burn_custom_mac 00:11:22:33:44:55
    

Note: esptool can not reset the emulated chip using the RTS signal, because the state of RTS is not transmitted over TCP to QEMU. To reset the emulated chip, run system_reset command in QEMU console (started at step 1).

Specifying ROM ELF file

If -kernel and -bios arguments are not given, ESP32 (rev. 3) ROM code will be loaded. This ROM code binary is included in the repository. To specify the ROM code ELF file to load, pass the filename with a -bios <filename> argument.

Using flash encryption

Self-encryption workflow

  1. In the IDF application, enable CONFIG_SECURE_FLASH_ENC_ENABLED through menuconfig, and build it
  2. Build the flash image as per the instructions from the Compiling the ESP-IDF program to emulate section.
  3. Create qemu_efuse.bin as highlighted in the Specifying eFuse storage section.
  4. Execute qemu-system-xtensa using the following command:
    build/qemu-system-xtensa -nographic -machine esp32 \-drive file=/path/to/qemu_efuse.bin,if=none,format=raw,id=efuse   \-global driver=nvram.esp32.efuse,property=drive,value=efuse       \-drive file=/path/to/flash_image.bin,if=mtd,format=raw            \-global driver=timer.esp32.timg,property=wdt_disable,value=true
    

Adding PSRAM

QEMU “memory size” option can be used to enable PSRAM emulation. By default, no PSRAM is added to the machine. You can add 2MB or 4MB PSRAM using -m 2M or -m 4M command line options, respectively.

Note that PSRAM MMU is not emulated yet, so things like bank switching (himem in IDF) do not work.

Using SD cards

QEMU emulates SD/MMC host controller used in ESP32. To add an SD card to the system, create an image and pass it to QEMU.

  1. Create a raw image file, for example, 64 MB:

    $ dd if=/dev/zero bs=$((1024*1024)) count=64 of=sd_image.bin
    
  2. Add the following argument when running QEMU:

    -drive file=sd_image.bin,if=sd,format=raw
    

If you need to create a large SD card image, it is recommended to use sparse cqow2 images instead of raw ones. Consult QEMU manual about qemu-img tool for details.

Only one SD card is supported at a time. You can use either slot 0 or slot 1 of the SD/MMC controller in the application code.

Enabling graphical user interface (GUI)

The ESP32 QEMU implementation implements a virtual RGB panel, absent on the real hardware, that can be used to show graphical interface. It is associated to a virtual frame buffer that can be used to populate the pixels to show. It is also possible to use the target internal RAM as a frame buffer.

To enable the graphical interface, while keeping the serial output in the console, use the following command line:

build/qemu-system-xtensa \-machine esp32 \-drive file=flash_image.bin,if=mtd,format=raw-display sdl \-serial stdio

If gtk backend was enabled when compiling QEMU, it is possible to replace -display sdl with -display gtk

相关文章:

【物联网设备端开发】ESP开发工具:QEMU如何模拟以太网口接入网络

以太网口支持 ESP-IDF中添加了对Opencores以太网MAC的支持。 运行以太网示例时&#xff0c;启用CONFIG_EXAMPLE_CONNECT_ETHERNET和 CONFIG_EXAMPLE_USE_OPENETH.。运行自定义应用程序时&#xff0c;启用CONFIG_ETH_USE_OPENETH 并初始化以太网驱动程序&#xff0c;如示例 /c…...

Python学习笔记(四)

# 数据容器分为5类&#xff0c;分别是&#xff1a;列表&#xff08;list)、元组&#xff08;tuple)、字符串&#xff08;str&#xff09;、集合&#xff08;set)、字典&#xff08;dict)""" 演示数据容器之&#xff1a;list列表 语法&#xff1a;[元素&#xff…...

跨域:安全分步实施指南

什么是跨域问题&#xff1f; 跨域&#xff08;Cross-Origin Resource Sharing&#xff0c;CORS&#xff09;问题发生在浏览器的同源策略&#xff08;Same-Origin Policy&#xff09;限制下。当一个域上的网页试图访问另一个域上的资源时&#xff0c;浏览器会阻止这些操作以保护…...

【iOS】AutoreleasePool自动释放池的实现原理

目录 ARC与MRC项目中的main函数自动释放池autoreleasepool {}实现原理AutoreleasePoolPage总结 objc_autoreleasePoolPush的源码分析autoreleaseNewPageautoreleaseFullPageautoreleaseNoPage autoreleaseFast总结 autorelease方法源码分析objc_autoreleasePoolPop的源码分析po…...

stm32—GPIO

0. 引入 在单片机产品中,我们常常可以见到三种模块:LCD灯、KEY按键、BEEP蜂鸣器 LED灯: 一个比较常见的LED电路LED0 ---------- 通过控制LED0引脚(电线) 给它一个低电平(低电压),LED灯就会亮 给它一个高电平(高电压),LED灯就会灭 …...

CocosCreator使用 ProtoBuf WebSocket与服务器对接方法

在 Cocos Creator 中使用 .proto 文件和转换成 TypeScript&#xff08;TS&#xff09;两者各有其优缺点&#xff0c;具体选择取决于你的项目需求和团队的开发习惯。以下是两者的一些比较&#xff1a; 1、使用 .proto 文件的优点&#xff1a; 跨语言支持&#xff1a;Protocol B…...

【python基础】while循环语句练习

明显可以感觉到循环比判断要更加难以理解一些&#xff0c;这个就只能通过练习来提高理解和思维能力了。 学习视频&#xff1a;第一阶段-第四章-05-while循环案例-九九乘法表_哔哩哔哩_bilibili 练习一&#xff1a;计算1-10的和 i1#循环的起始值 sum0 while i&l…...

【SpringBoot系列】WebMvcConfigurer配置

&#x1f49d;&#x1f49d;&#x1f49d;欢迎来到我的博客&#xff0c;很高兴能够在这里和您见面&#xff01;希望您在这里可以感受到一份轻松愉快的氛围&#xff0c;不仅可以获得有趣的内容和知识&#xff0c;也可以畅所欲言、分享您的想法和见解。 推荐:kwan 的首页,持续学…...

学懂C++ (十九):高级教程——深入详解C++信号处理

目录 C中的信号处理 1. 信号处理的本质 2. 主要信号类型 3. 核心关键点 4. 经典实例 代码分析 5. 进阶&#xff1a;信号屏蔽与多线程 例子&#xff1a;使用sigaction() 6. Windows中的信号处理 7. 比较与总结 示例&#xff1a;Windows控制台事件处理 总结 C中的信号…...

SOMEIP_ETS_032:echoUINT8ArrayMinSize

测试目的&#xff1a; 确保DUT能够正确处理最小尺寸的UINT8数组参数&#xff0c;并且在发送和接收过程中保持参数值和顺序不变。 描述 本测试用例旨在验证DUT在处理包含最小尺寸UINT8数组参数的SOME/IP消息时&#xff0c;是否能够准确地发送和接收这些参数&#xff0c;确保返…...

JS+CSS案例:可适应上下布局和左右布局的菜单(含二级菜单)

今天,我给大家分享一个原创的CSS菜单,整个菜单全由CSS写成,仅在切换布局时使用JS。合不合意,先看看效果图。 本例图片 接下来,我来详细给大家分享它的制作方法。 文件夹结构 因为涉及到了样式表切换,所以,你需要借鉴一下我的文件夹结构。 CSS文件夹: reset.css 用于…...

【数据结构】线性表,顺序表

一. 线性表 1. 线性表(linear list)是n个具有相同特性的数据元素的有限序列。 2. 线性表是一种在实际中广泛使用的数据结构&#xff0c;常见的线性表&#xff1a;顺序表、链表、栈、队列、字符串... 3. 线性表在逻辑上是线性结构&#xff0c;也就说是连续的一条直线。但是在物理…...

Spring之最基础的创建与Bean的存储与获取(还有Maven加载jar包报错的解决方法)

目录 创建Spring项目 如何解决Maven加载jar包报错 存储Bean和取Bean 在Java中对象也称为Bean。所以后面我提到Bean&#xff0c;大家要知道我说的是什么。 创建Spring项目 我的idea是2022版本的&#xff0c;如果大家和我一样可以参考我的。 1.创建一个Maven项目。图片上忘了…...

RabbitMQ应用问题 - 消息顺序性保证、消息积压问题

文章目录 MQ 消息顺序性保证概述原因分析解决方案基于 spring-cloud-stream 实现分区消费 消息挤压问题概述原因分析解决方案 MQ 消息顺序性保证 概述 a&#xff09;消息顺序性&#xff1a;消费者消费的消息的顺序 和 生产者发送消息的顺序是一致的. 例如 生产者 发送消息顺序…...

linux tcp通讯demo

linux tcp通讯demo代码。通过用chatgpt生成的代码。做一个代码记录。 一、基本的通讯demo server.c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <sys/types.h> #include <sys/socket.h>…...

在 MongoDB 中,如何配置副本集以实现读写分离?

在 MongoDB 中&#xff0c;配置副本集以实现读写分离主要涉及以下几个步骤&#xff1a; 初始化副本集&#xff1a; 创建副本集时&#xff0c;需要在所有参与节点上运行 rs.initiate() 命令。这将初始化一个新的副本集。 添加成员到副本集&#xff1a; 使用 rs.add() 命令将所有…...

虚拟dom-Diff算法

虚拟dom-Diff算法 vue2 diff算法在vue2中就是patch&#xff0c;通过新旧虚拟dom对比&#xff0c;找到最小变化然后进行dom操作 在页面首次渲染的时候会调用一次patch并创建新的vnode&#xff0c;不会进行深层次的比较&#xff0c;然后再组件中数据发生变化的时候&#xff0c;…...

01创建型设计模式——单例模式

一、单例模式简介 单例模式&#xff08;Singleton Pattern&#xff09;是一种创建型设计模式&#xff08;GoF书中解释创建型设计模式&#xff1a;一种用来处理对象的创建过程的模式&#xff09;&#xff0c;单例模式是其中的一种&#xff0c;它确保一个类只有一个实例&#xff…...

图像分割(一)

一、概述 语义分割&#xff1a;是把每个像素都打上标签&#xff08;这个像素点是人、树、背景等&#xff09; 实例分割&#xff1a;不光要区别类别&#xff0c;还要区分类别中的每一个个体 损失函数&#xff1a;逐像素的交叉熵&#xff1b;样本均衡问题 MIOU指标&#xff1a…...

C++ 新经典:设计模式 目录(先留框架,慢慢来~)

C 新经典&#xff1a;设计模式 C 新经典&#xff1a;设计模式 C 新经典&#xff1a;设计模式第1章 设计模式与软件开发思想、编程环境介绍第2章 模板方法模式第3章 工厂模式、原型模式、建造者模式第4章 策略模式第5章 观察者模式第6章 装饰模式第7章 单件模式第8章 外观模式第…...

XML Group端口详解

在XML数据映射过程中&#xff0c;经常需要对数据进行分组聚合操作。例如&#xff0c;当处理包含多个物料明细的XML文件时&#xff0c;可能需要将相同物料号的明细归为一组&#xff0c;或对相同物料号的数量进行求和计算。传统实现方式通常需要编写脚本代码&#xff0c;增加了开…...

云启出海,智联未来|阿里云网络「企业出海」系列客户沙龙上海站圆满落地

借阿里云中企出海大会的东风&#xff0c;以**「云启出海&#xff0c;智联未来&#xff5c;打造安全可靠的出海云网络引擎」为主题的阿里云企业出海客户沙龙云网络&安全专场于5.28日下午在上海顺利举办&#xff0c;现场吸引了来自携程、小红书、米哈游、哔哩哔哩、波克城市、…...

连锁超市冷库节能解决方案:如何实现超市降本增效

在连锁超市冷库运营中&#xff0c;高能耗、设备损耗快、人工管理低效等问题长期困扰企业。御控冷库节能解决方案通过智能控制化霜、按需化霜、实时监控、故障诊断、自动预警、远程控制开关六大核心技术&#xff0c;实现年省电费15%-60%&#xff0c;且不改动原有装备、安装快捷、…...

转转集团旗下首家二手多品类循环仓店“超级转转”开业

6月9日&#xff0c;国内领先的循环经济企业转转集团旗下首家二手多品类循环仓店“超级转转”正式开业。 转转集团创始人兼CEO黄炜、转转循环时尚发起人朱珠、转转集团COO兼红布林CEO胡伟琨、王府井集团副总裁祝捷等出席了开业剪彩仪式。 据「TMT星球」了解&#xff0c;“超级…...

linux arm系统烧录

1、打开瑞芯微程序 2、按住linux arm 的 recover按键 插入电源 3、当瑞芯微检测到有设备 4、松开recover按键 5、选择升级固件 6、点击固件选择本地刷机的linux arm 镜像 7、点击升级 &#xff08;忘了有没有这步了 估计有&#xff09; 刷机程序 和 镜像 就不提供了。要刷的时…...

Spring AI与Spring Modulith核心技术解析

Spring AI核心架构解析 Spring AI&#xff08;https://spring.io/projects/spring-ai&#xff09;作为Spring生态中的AI集成框架&#xff0c;其核心设计理念是通过模块化架构降低AI应用的开发复杂度。与Python生态中的LangChain/LlamaIndex等工具类似&#xff0c;但特别为多语…...

重启Eureka集群中的节点,对已经注册的服务有什么影响

先看答案&#xff0c;如果正确地操作&#xff0c;重启Eureka集群中的节点&#xff0c;对已经注册的服务影响非常小&#xff0c;甚至可以做到无感知。 但如果操作不当&#xff0c;可能会引发短暂的服务发现问题。 下面我们从Eureka的核心工作原理来详细分析这个问题。 Eureka的…...

C#学习第29天:表达式树(Expression Trees)

目录 什么是表达式树&#xff1f; 核心概念 1.表达式树的构建 2. 表达式树与Lambda表达式 3.解析和访问表达式树 4.动态条件查询 表达式树的优势 1.动态构建查询 2.LINQ 提供程序支持&#xff1a; 3.性能优化 4.元数据处理 5.代码转换和重写 适用场景 代码复杂性…...

三分算法与DeepSeek辅助证明是单峰函数

前置 单峰函数有唯一的最大值&#xff0c;最大值左侧的数值严格单调递增&#xff0c;最大值右侧的数值严格单调递减。 单谷函数有唯一的最小值&#xff0c;最小值左侧的数值严格单调递减&#xff0c;最小值右侧的数值严格单调递增。 三分的本质 三分和二分一样都是通过不断缩…...

MinIO Docker 部署:仅开放一个端口

MinIO Docker 部署:仅开放一个端口 在实际的服务器部署中,出于安全和管理的考虑,我们可能只能开放一个端口。MinIO 是一个高性能的对象存储服务,支持 Docker 部署,但默认情况下它需要两个端口:一个是 API 端口(用于存储和访问数据),另一个是控制台端口(用于管理界面…...