Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

esp32s3 openeth ethernet driver #13527

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

casaroli
Copy link
Contributor

@casaroli casaroli commented Sep 18, 2024

Summary

Espressif recently added support for esp32s3 on their qemu, so we migrate the openeth ethernet driver to xtensa common and add it to the esp32s3-devkit config.

Impact for the user

  • Features added
    • Now we can run the esp32s3 port in qemu. By enabling the configuration ESP32S3_QEMU_IMAGE and nuttx.merged.bin will be built (as described in the documentation).
    • Now the user can enable the openeth driver in esp32s3 in qemu with the option ESP32S3_OPENETH and use network in qemu as described in https://github.com/espressif/esp-toolchain-docs/blob/main/qemu/esp32/README.md#ethernet-support
    • Adds a esp32s3-devkit:qemu-openeth config which automatically has networking enabled and is ready to boot on qemu with esp-idf legacy bootloader.
  • Impact on Build:
    • No changes to the build process itself.
    • Users will need to select the appropriate QEMU ESP32-S3 or ESP32 configurations.
  • Impact on Hardware: Support added for Opencore ethernet MAC on ESP32-S3 in QEMU.
  • Impact on Documentation: Documentation was updated to include instructions for running the ESP32-S3 port in QEMU with networking support.
  • Impact on Security: None.
  • Impact on Compatibility: No backward compatibility issues.

Currently, the simple boot is not working with QEMU. This issue was not introduced by this PR, as it is an effect or enabling the simple boot by default. The qemu-openeth defconfigs enable ESP32_APP_FORMAT_LEGACY or ESP32S3_APP_FORMAT_LEGACY to overcome this limitation._

Testing

  • Build Host: Ubuntu 22.04 LTS, esp-idf v5.3.1
  • Target: QEMU emulator version 9.0.0 (esp_develop_9.0.0_20240606)
  • Configs:
    • esp32-devkitc:qemu-openeth
    • esp32s3-devkit:qemu-openeth
  • Tests Performed:
    • Verified successful boot of NuttX in QEMU.
    • Network connectivity tested using ping command from the nsh console.

Commands

Download espressif qemu from https://github.com/espressif/qemu

esp32s3

$ ./tools/configure.sh -l esp32s3-devkit:qemu-openeth
$ make bootloader
$ make ESPTOOL_BINDIR=.
$ qemu-system-xtensa -nographic -machine esp32s3 -m 4 \
    -nic user,model=open_eth \
    -drive file=./nuttx.merged.bin,if=mtd,format=raw
...
NuttShell (NSH) NuttX-12.6.0-RC1
nsh> ping -c2 apache.org
PING 151.101.2.132 56 bytes of data
56 bytes from 151.101.2.132: icmp_seq=0 time=10.0 ms
56 bytes from 151.101.2.132: icmp_seq=1 time=10.0 ms
2 packets transmitted, 2 received, 0% packet loss, time 2020 ms
rtt min/avg/max/mdev = 10.000/10.000/10.000/0.000 ms
nsh> 

esp32

QEMU is not emulating the chip revision v3.0, so the user has two options:

$ ./tools/configure.sh -l esp32-devkitc:qemu-openeth
$ make bootloader
$ make ESPTOOL_BINDIR=.
$ qemu-system-xtensa -nographic -machine esp32 -m 4 \
    -nic user,model=open_eth \
    -drive file=./nuttx.merged.bin,if=mtd,format=raw
...
WARNING: NuttX supports ESP32 chip revision >= v3.0 (chip is v0.0).
Ignoring this error and continuing because `ESP32_IGNORE_CHIP_REVISION_CHECK` is set...
THIS MAY NOT WORK! DON'T USE THIS CHIP IN PRODUCTION!

NuttShell (NSH) NuttX-12.6.0-RC1
nsh> ping -c2 apache.org
PING 151.101.2.132 56 bytes of data
56 bytes from 151.101.2.132: icmp_seq=0 time=20.0 ms
56 bytes from 151.101.2.132: icmp_seq=1 time=10.0 ms
2 packets transmitted, 2 received, 0% packet loss, time 2020 ms
rtt min/avg/max/mdev = 10.000/15.000/20.000/5.000 ms
nsh> 

Out of scope

  • Currently the simple boot method is not working with QEMU. For this reason we enable the legacy esp-idf bootloader on the default config for qemu-openeth. As this PR did not introduce this defect, I plan on investigating this in the future, however I do not have any timeline for this.
  • esp32 qemu does not emulate the version v3.0, so we need to either add an efuse storage as described in the espressif documentation or define ESP32_IGNORE_CHIP_REVISION_CHECK in arch/xtensa/src/esp32/esp32_start.c. This is a defect of espressif qemu and is out of scope of NuttX. However, I have updated the esp32 documentation to reference this issue.

@lupyuen
Copy link
Member

lupyuen commented Sep 18, 2024

[Experimental Bot, please feedback here]

The PR summary is OK, but the other sections need significant work to meet the requirements.

Here's a breakdown of what's missing and how to improve it:

Impact:

  • Not specific enough: Simply stating "Now we can run the esp32s3 port in qemu" isn't sufficient.
    • Be Explicit: List which features are added. Does this enable any new APIs for developers using NuttX on ESP32-S3?
    • Consider the User: Will users need to change configurations, build scripts, or application code to utilize this?
    • Address all points: Go through each impact category (build process, hardware, documentation, security, compatibility) and explicitly state "NO" or provide a detailed "YES" explanation.

Testing:

  • "Manual testing" is insufficient: Provide concrete details.
    • Commands: What commands did you run to build and test? (Show the full commands, not just "make").
    • Configurations: Which specific ESP32-S3 board and configurations were tested?
    • Functionality: What specific tests did you perform to validate the changes? (e.g., Networking tests, peripheral tests).
  • Logs: The "Testing logs" sections are empty. Include relevant logs before and after your changes, demonstrating the problem being solved or the new functionality working.

Out of Scope:

  • Actionable information is better: While it's good to note limitations, consider:
    • Issue Tracking: Is there an existing issue for the simple boot method problem? If so, link it here. If not, create one so it's tracked.
    • Timeline: When can users expect the separate PR? (e.g., "Will be addressed in an upcoming PR within the next sprint").

Example improvements:

Impact:

  • Feature Added: Support for running the ESP32-S3 port of NuttX in QEMU using the esp-idf bootloader.
  • Impact on User:
    • Users who want to use QEMU for ESP32-S3 development will need to use the esp-idf bootloader instead of the simple bootloader.
    • Documentation will be updated to reflect this requirement.
  • Impact on Build:
    • No changes to the build process itself.
    • Users will need to select the appropriate QEMU and ESP32-S3 configurations.
  • Impact on Hardware: Support added for ESP32-S3 in QEMU.
  • Impact on Documentation: Documentation will be updated to include instructions for running the ESP32-S3 port in QEMU.
  • Impact on Security: None.
  • Impact on Compatibility: No backward compatibility issues.

Testing:

  • Build Host: Ubuntu 20.04, GCC 9.4.0
  • Target: QEMU, ESP32-S3 DevKitC (config: esp32s3-devkitc_qemu)
  • Commands:
    • ./tools/configure.sh esp32s3-devkitc_qemu
    • make
    • qemu-system-xtensa -nographic -machine esp32s3 -drive file=nuttx.bin,if=mtd,format=raw
  • Tests Performed:
    • Verified successful boot of NuttX in QEMU.
    • Network connectivity tested using ping command from the NuttX console.
  • Testing Logs: (Include actual log output here)

Out of Scope:

  • The simple boot method is currently not working with QEMU for the ESP32-S3 port. This issue is being tracked in [link to GitHub issue]. A fix for this issue will be addressed in a separate PR.

By providing this level of detail, you make it much easier for reviewers to understand your changes and ensure they meet the project's requirements.

The current simple boot method is not working with qemu.

We enable this option for now until we can make the simple-boot
image boot with QEMU.
Copy link
Contributor

@cederom cederom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @casaroli amazing work! :-)

@casaroli
Copy link
Contributor Author

Can anyone help me understand why the workflow is failing? What should I do to fix it?

@casaroli casaroli marked this pull request as ready for review September 18, 2024 20:23
@cederom
Copy link
Contributor

cederom commented Sep 18, 2024

Can anyone help me understand why the workflow is failing? What should I do to fix it?

Looks like internal CI problem, builds fine for me on FreeBSD :-)

arch/xtensa/src/common/xtensa_openeth.c Outdated Show resolved Hide resolved
arch/xtensa/src/common/xtensa_openeth.c Outdated Show resolved Hide resolved
arch/xtensa/src/common/xtensa_openeth.c Outdated Show resolved Hide resolved
@@ -1,5 +1,5 @@
/****************************************************************************
* arch/xtensa/src/esp32/esp32_openeth.c
* arch/xtensa/src/common/xtensa_openeth.c
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this driver be used by other non esp chip?

Copy link
Contributor Author

@casaroli casaroli Sep 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. AFAIK this is only for esp32 family on qemu.

Another chip with a real openeth peripheral will require a more complete driver and features that are not available in the openeth qemu implementation, which has many parts mocked.

Maybe this can be used by other qemu like arm or riscv, but I have not tested as in those cases, network can usually be done with virtio or some other better interface (than mocking openeth nic).

@@ -245,7 +245,7 @@ int board_ws2812_initialize(
*
****************************************************************************/
#ifdef CONFIG_ESP32_OPENETH
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't contain chip specific macro in common.folder

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will put header files in the chip specific directory and include them in the common driver. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, @xiaoxiang781216 can you please suggest me how to do this?

I thought about moving those definitions to the chip specific chip.h and including it from the driver. WDYT?

Or should I create another file like openeth.h in each chips directory?

Do you have any other idea? How should I proceed?

Co-authored-by: Petro Karashchenko <[email protected]>
@github-actions github-actions bot added the Size: M The size of the change in this PR is medium label Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Size: M The size of the change in this PR is medium
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants