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

tools/esp32: Refactor generation of QEMU-compatible image #4701

Merged
merged 2 commits into from Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 11 additions & 7 deletions Documentation/platforms/xtensa/esp32/index.rst
Expand Up @@ -329,15 +329,19 @@ Using QEMU
==========

First follow the instructions `here <https://github.com/espressif/qemu/wiki>`_ to build QEMU.
Enable the ESP32_QEMU_IMAGE config found in "Board Selection -> ESP32 binary image for QEMU".

Enable the ``ESP32_QEMU_IMAGE`` config found in :menuselection:`Board Selection --> ESP32 binary image for QEMU`.

Download the bootloader and the partition table from https://github.com/espressif/esp-nuttx-bootloader/releases
and place them in a directory, say ../esp-bins.
Build and generate the QEMU image: `make ESPTOOL_BINDIR=../esp-bins`
A new image "esp32_qemu_image.bin" will be created. It can be run as::
and place them in a directory, say ``../esp-bins``.

Build and generate the QEMU image::

$ make ESPTOOL_BINDIR=../esp-bins

A QEMU-compatible ``nuttx.merged.bin`` binary image will be created. It can be run as::

~/PATH_TO_QEMU/qemu/build/xtensa-softmmu/qemu-system-xtensa -nographic \
-machine esp32 \
-drive file=esp32_qemu_image.bin,if=mtd,format=raw
$ qemu-system-xtensa -nographic -machine esp32 -drive file=nuttx.merged.bin,if=mtd,format=raw

Things to Do
============
Expand Down
1 change: 1 addition & 0 deletions boards/xtensa/esp32/common/Kconfig
Expand Up @@ -14,6 +14,7 @@ config ESP32_MERGE_BINS
config ESP32_QEMU_IMAGE
bool "ESP32 binary image for QEMU"
default n
select ESP32_MERGE_BINS
---help---
Create a binary flash image used for QEMU.

Expand Down
1 change: 0 additions & 1 deletion boards/xtensa/esp32/esp32-devkitc/src/Make.defs
Expand Up @@ -62,7 +62,6 @@ context:: $(SCRIPTOUT)

distclean::
$(call DELFILE, $(SCRIPTOUT))
$(call DELFILE, $(TOPDIR)/esp32_qemu_img.bin)

DEPPATH += --dep-path board
VPATH += :board
Expand Down
1 change: 0 additions & 1 deletion boards/xtensa/esp32/esp32-ethernet-kit/src/Make.defs
Expand Up @@ -54,7 +54,6 @@ context:: $(SCRIPTOUT)

distclean::
$(call DELFILE, $(SCRIPTOUT))
$(call DELFILE, $(TOPDIR)/esp32_qemu_img.bin)

DEPPATH += --dep-path board
VPATH += :board
Expand Down
1 change: 0 additions & 1 deletion boards/xtensa/esp32/esp32-wrover-kit/src/Make.defs
Expand Up @@ -64,7 +64,6 @@ context:: $(SCRIPTOUT)

distclean::
$(call DELFILE, $(SCRIPTOUT))
$(call DELFILE, $(TOPDIR)/esp32_qemu_img.bin)

DEPPATH += --dep-path board
VPATH += :board
Expand Down
1 change: 0 additions & 1 deletion boards/xtensa/esp32/ttgo_lora_esp32/src/Make.defs
Expand Up @@ -62,7 +62,6 @@ context:: $(SCRIPTOUT)

distclean::
$(call DELFILE, $(SCRIPTOUT))
$(call DELFILE, $(TOPDIR)/esp32_qemu_img.bin)

DEPPATH += --dep-path board
VPATH += :board
Expand Down
30 changes: 14 additions & 16 deletions tools/esp32/Config.mk
Expand Up @@ -98,15 +98,8 @@ endif

ESPTOOL_BINS += $(FLASH_APP)

ifeq ($(CONFIG_ESP32_QEMU_IMAGE),y)
MK_QEMU_IMG=$(TOPDIR)/tools/esp32/mk_qemu_img.sh -b $(BOOTLOADER) -p $(PARTITION_TABLE)
else
MK_QEMU_IMG=
endif

# MERGEBIN -- Merge raw binary files into a single file

ifeq ($(CONFIG_ESP32_MERGE_BINS),y)
define MERGEBIN
$(Q) if [ -z $(ESPTOOL_BINDIR) ]; then \
echo "MERGEBIN error: Missing argument for binary files directory."; \
Expand All @@ -117,15 +110,21 @@ define MERGEBIN
echo "Missing Flash memory size configuration for the ESP32 chip."; \
exit 1; \
fi
esptool.py -c esp32 merge_bin --output nuttx.merged.bin $(ESPTOOL_FLASH_OPTS) $(ESPTOOL_BINS)
$(eval ESPTOOL_MERGEBIN_OPTS := \
$(if $(CONFIG_ESP32_QEMU_IMAGE), \
--fill-flash-size $(FLASH_SIZE) -fm $(FLASH_MODE) -ff $(FLASH_FREQ), \
$(ESPTOOL_FLASH_OPTS) \
) \
)
esptool.py -c esp32 merge_bin --output nuttx.merged.bin $(ESPTOOL_MERGEBIN_OPTS) $(ESPTOOL_BINS)
$(Q) echo nuttx.merged.bin >> nuttx.manifest
$(Q) echo "Generated: nuttx.merged.bin"
endef
else
define MERGEBIN

$(Q) if [ "$(CONFIG_ESP32_QEMU_IMAGE)" = "y" ]; then \
echo "Generated: nuttx.merged.bin (QEMU compatible)"; \
else \
echo "Generated: nuttx.merged.bin"; \
fi
endef
endif

# SIGNBIN -- Sign the binary image file

Expand Down Expand Up @@ -174,13 +173,12 @@ endif
ifeq ($(CONFIG_ESP32_APP_FORMAT_MCUBOOT),y)
define POSTBUILD
$(call SIGNBIN)
$(call MERGEBIN)
$(if $(CONFIG_ESP32_MERGE_BINS), $(call MERGEBIN), )
endef
else ifeq ($(CONFIG_ESP32_APP_FORMAT_LEGACY),y)
define POSTBUILD
$(call ELF2IMAGE)
$(call MERGEBIN)
$(Q) $(MK_QEMU_IMG)
$(if $(CONFIG_ESP32_MERGE_BINS), $(call MERGEBIN), )
endef
endif

Expand Down
106 changes: 0 additions & 106 deletions tools/esp32/mk_qemu_img.sh

This file was deleted.