esp32: Refactor QEMU image generation on POSTBUILD

This commit is contained in:
Gustavo Henrique Nihei 2021-02-02 19:08:54 -03:00 committed by Alan Carvalho de Assis
parent 07792a696b
commit afad13dfaa
8 changed files with 93 additions and 51 deletions

View File

@ -2,3 +2,9 @@
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#
config ESP32_QEMU_IMAGE
bool "ESP32 binary image for QEMU"
default n
---help---
Create a binary flash image used for QEMU.

View File

@ -38,11 +38,7 @@ config ESP32_DEVKITC_RUN_IRAM
allows interoperability with the esp-idf system but makes you
reliant on the esp-idf design for these parts. Both are possible.
config ESP32_DEVKITC_FLASH_IMAGE
bool "esp32 flash image"
default n
---help---
Create flash_image.bin mainly used for QEMU.
source boards/xtensa/esp32/common/Kconfig
choice
prompt "SPIFLASH File System"

View File

@ -32,10 +32,15 @@ else
PARTITION_TABLE=$(IDF_PATH)/hello_world/build/partition_table/partition-table.bin
endif
ifeq ($(CONFIG_ESP32_DEVKITC_FLASH_IMAGE),y)
ifeq ($(CONFIG_ESP32_QEMU_IMAGE),y)
MK_QEMU_IMG=$(TOPDIR)/tools/esp32/mk_qemu_img.sh $(BOOTLOADER) $(PARTITION_TABLE) $(NUTTXNAME)
else
MK_QEMU_IMG=
endif
define POSTBUILD
@echo "MKIMAGE: ESP32 binary"
$(Q) if ! esptool.py version ; then \
$(Q) if ! esptool.py version ; then \
echo ""; \
echo "Please install ESP-IDF tools"; \
echo ""; \
@ -48,15 +53,6 @@ define POSTBUILD
echo "Generating: $(NUTTXNAME).bin (ESP32 compatible)"; \
esptool.py --chip esp32 elf2image --flash_mode dio --flash_size 4MB -o $(NUTTXNAME).bin nuttx; \
echo "Generated: $(NUTTXNAME).bin (ESP32 compatible)"; \
echo "Generating: flash_image.bin"; \
echo " Bootloader: $(BOOTLOADER)"; \
echo " Parition Table: $(PARTITION_TABLE)"; \
dd if=/dev/zero bs=1024 count=4096 of=flash_image.bin && \
dd if=$(BOOTLOADER) bs=1 seek=$(shell printf "%d" 0x1000) of=flash_image.bin conv=notrunc && \
dd if=$(PARTITION_TABLE) bs=1 seek=$(shell printf "%d" 0x8000) of=flash_image.bin conv=notrunc && \
dd if=$(NUTTXNAME).bin bs=1 seek=$(shell printf "%d" 0x10000) of=flash_image.bin conv=notrunc && \
echo "Generated: flash_image.bin (it can be run with 'qemu-system-xtensa -nographic -machine esp32 -drive file=flash_image.bin,if=mtd,format=raw')"; \
echo "flash_image.bin" >> $(NUTTXNAME).manifest; \
fi
$(MK_QEMU_IMG)
endef
endif

View File

@ -38,10 +38,6 @@ config ESP32_ETHERNETKIT_RUN_IRAM
allows interoperability with the esp-idf system but makes you
reliant on the esp-idf design for these parts. Both are possible.
config ESP32_ETHERNETKIT_FLASH_IMAGE
bool "esp32 flash image"
default n
---help---
Create flash_image.bin mainly used for QEMU.
source boards/xtensa/esp32/common/Kconfig
endif # ARCH_BOARD_ESP32_ETHERNETKIT

View File

@ -32,10 +32,15 @@ else
PARTITION_TABLE=$(IDF_PATH)/hello_world/build/partition_table/partition-table.bin
endif
ifeq ($(CONFIG_ESP32_ETHERNETKIT_FLASH_IMAGE),y)
ifeq ($(CONFIG_ESP32_QEMU_IMAGE),y)
MK_QEMU_IMG=$(TOPDIR)/tools/esp32/mk_qemu_img.sh $(BOOTLOADER) $(PARTITION_TABLE) $(NUTTXNAME)
else
MK_QEMU_IMG=
endif
define POSTBUILD
@echo "MKIMAGE: ESP32 binary"
$(Q) if ! esptool.py version ; then \
$(Q) if ! esptool.py version ; then \
echo ""; \
echo "Please install ESP-IDF tools"; \
echo ""; \
@ -48,15 +53,6 @@ define POSTBUILD
echo "Generating: $(NUTTXNAME).bin (ESP32 compatible)"; \
esptool.py --chip esp32 elf2image --flash_mode dio --flash_size 4MB -o $(NUTTXNAME).bin nuttx; \
echo "Generated: $(NUTTXNAME).bin (ESP32 compatible)"; \
echo "Generating: flash_image.bin"; \
echo " Bootloader: $(BOOTLOADER)"; \
echo " Parition Table: $(PARTITION_TABLE)"; \
dd if=/dev/zero bs=1024 count=4096 of=flash_image.bin && \
dd if=$(BOOTLOADER) bs=1 seek=$(shell printf "%d" 0x1000) of=flash_image.bin conv=notrunc && \
dd if=$(PARTITION_TABLE) bs=1 seek=$(shell printf "%d" 0x8000) of=flash_image.bin conv=notrunc && \
dd if=$(NUTTXNAME).bin bs=1 seek=$(shell printf "%d" 0x10000) of=flash_image.bin conv=notrunc && \
echo "Generated: flash_image.bin (it can be run with 'qemu-system-xtensa -nographic -machine esp32 -drive file=flash_image.bin,if=mtd,format=raw')"; \
echo "flash_image.bin" >> $(NUTTXNAME).manifest; \
fi
$(MK_QEMU_IMG)
endef
endif

View File

@ -38,10 +38,6 @@ config ESP32_WROVERKIT_RUN_IRAM
allows interoperability with the esp-idf system but makes you
reliant on the esp-idf design for these parts. Both are possible.
config ESP32_WROVERKIT_FLASH_IMAGE
bool "esp32 flash image"
default n
---help---
Create flash_image.bin mainly used for QEMU.
source boards/xtensa/esp32/common/Kconfig
endif # ARCH_BOARD_ESP32_WROVERKIT

View File

@ -32,10 +32,15 @@ else
PARTITION_TABLE=$(IDF_PATH)/hello_world/build/partition_table/partition-table.bin
endif
ifeq ($(CONFIG_ESP32_WROVERKIT_FLASH_IMAGE),y)
ifeq ($(CONFIG_ESP32_QEMU_IMAGE),y)
MK_QEMU_IMG=$(TOPDIR)/tools/esp32/mk_qemu_img.sh $(BOOTLOADER) $(PARTITION_TABLE) $(NUTTXNAME)
else
MK_QEMU_IMG=
endif
define POSTBUILD
@echo "MKIMAGE: ESP32 binary"
$(Q) if ! esptool.py version ; then \
$(Q) if ! esptool.py version ; then \
echo ""; \
echo "Please install ESP-IDF tools"; \
echo ""; \
@ -48,15 +53,6 @@ define POSTBUILD
echo "Generating: $(NUTTXNAME).bin (ESP32 compatible)"; \
esptool.py --chip esp32 elf2image --flash_mode dio --flash_size 4MB -o $(NUTTXNAME).bin nuttx; \
echo "Generated: $(NUTTXNAME).bin (ESP32 compatible)"; \
echo "Generating: flash_image.bin"; \
echo " Bootloader: $(BOOTLOADER)"; \
echo " Parition Table: $(PARTITION_TABLE)"; \
dd if=/dev/zero bs=1024 count=4096 of=flash_image.bin && \
dd if=$(BOOTLOADER) bs=1 seek=$(shell printf "%d" 0x1000) of=flash_image.bin conv=notrunc && \
dd if=$(PARTITION_TABLE) bs=1 seek=$(shell printf "%d" 0x8000) of=flash_image.bin conv=notrunc && \
dd if=$(NUTTXNAME).bin bs=1 seek=$(shell printf "%d" 0x10000) of=flash_image.bin conv=notrunc && \
echo "Generated: flash_image.bin (it can be run with 'qemu-system-xtensa -nographic -machine esp32 -drive file=flash_image.bin,if=mtd,format=raw')"; \
echo "flash_image.bin" >> $(NUTTXNAME).manifest; \
fi
$(MK_QEMU_IMG)
endef
endif

60
tools/esp32/mk_qemu_img.sh Executable file
View File

@ -0,0 +1,60 @@
#!/usr/bin/env bash
############################################################################
# tools/esp32/mk_qemu_img.sh
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
SCRIPT_NAME=$(basename "${0}")
USAGE="USAGE: ${SCRIPT_NAME} <bootloader_img> <partition_table_img> [nuttx_name]"
# Make sure we have the required argument(s)
if [ -z "${1}" ] || [ -z "${2}" ] ; then
printf "%s requires the bootloader and partition table binary images.\n " "${SCRIPT_NAME}"
printf "%s\n " "${USAGE}"
exit 1
fi
BOOTLOADER=${1}
PARTITION_TABLE=${2}
NUTTXNAME=${3}
if [ -z "${NUTTXNAME}" ]; then
NUTTXNAME="nuttx"
printf "NUTTXNAME not provided, assuming \"%s\".\n" "${NUTTXNAME}"
fi
printf "Generating esp32_qemu_image.bin...\n"
printf "\tBootloader: %s\n" "${BOOTLOADER}"
printf "\tPartition Table: %s\n" "${PARTITION_TABLE}"
dd if=/dev/zero bs=1024 count=4096 of=esp32_qemu_image.bin && \
dd if="${BOOTLOADER}" bs=1 seek="$(printf '%d' 0x1000)" of=esp32_qemu_image.bin conv=notrunc && \
dd if="${PARTITION_TABLE}" bs=1 seek="$(printf '%d' 0x8000)" of=esp32_qemu_image.bin conv=notrunc && \
dd if="${NUTTXNAME}".bin bs=1 seek="$(printf '%d' 0x10000)" of=esp32_qemu_image.bin conv=notrunc
if [ ${?} -ne 0 ]; then
printf "Failed to generate esp32_qemu_image.bin.\n"
exit 1
fi
printf "Generated esp32_qemu_image.bin successfully!\n"
printf "You can use QEMU for executing it with the following command line:\n"
printf "\tqemu-system-xtensa -nographic -machine esp32 -drive file=esp32_qemu_image.bin,if=mtd,format=raw\n"
echo "esp32_qemu_image.bin" >> "${NUTTXNAME}".manifest