This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 86fd6843c36e1c7d502949c2dd4f7dcb12fe8388 Author: Abdelatif Guettouche <[email protected]> AuthorDate: Sat Feb 20 17:38:58 2021 +0100 tools/esp32: Refine the QEMU image generation. Use the usual while loop idiom when parsing arguments. Add more options to the script to be able to specify the name of the NuttX binary and final image. Signed-off-by: Abdelatif Guettouche <[email protected]> --- tools/esp32/Config.mk | 2 +- tools/esp32/mk_qemu_img.sh | 81 +++++++++++++++++++++++++++++++++++----------- 2 files changed, 63 insertions(+), 20 deletions(-) diff --git a/tools/esp32/Config.mk b/tools/esp32/Config.mk index ddd5ca3..0d7acf4 100644 --- a/tools/esp32/Config.mk +++ b/tools/esp32/Config.mk @@ -42,7 +42,7 @@ else ifeq ($(CONFIG_ESP32_FLASH_16M),y) endif ifeq ($(CONFIG_ESP32_QEMU_IMAGE),y) - MK_QEMU_IMG=$(TOPDIR)/tools/esp32/mk_qemu_img.sh $(BOOTLOADER) $(PARTITION_TABLE) + MK_QEMU_IMG=$(TOPDIR)/tools/esp32/mk_qemu_img.sh -b $(BOOTLOADER) -p $(PARTITION_TABLE) else MK_QEMU_IMG= endif diff --git a/tools/esp32/mk_qemu_img.sh b/tools/esp32/mk_qemu_img.sh index f23a2ff..19373e9 100755 --- a/tools/esp32/mk_qemu_img.sh +++ b/tools/esp32/mk_qemu_img.sh @@ -20,35 +20,78 @@ ############################################################################ SCRIPT_NAME=$(basename "${0}") -USAGE="USAGE: ${SCRIPT_NAME} <bootloader_img> <partition_table_img>" + +BOOTLOADER_IMG="" +PARTITION_IMG="" +NUTTX_IMG="nuttx.bin" +FLASH_IMG="esp32_qemu_img.bin" + +usage() { + echo "" + echo "USAGE: ${SCRIPT_NAME} [-h] -b <bootloader> -p <partition_table> [-n <nuttx>] [-i <image_name>]" + echo "" + echo "Where:" + echo " -b <bootloader> path to the bootloader image" + echo " -p <partition_table> path to the partition table image" + echo " -n <nuttx> path to the nuttx image (default nuttx.bin)" + echo " -i <image_name> name of the resulting image (default esp32_qemu_img.bin)" + echo " -h will show this help and terminate" +} + +while [ ! -z "$1" ]; do + case "$1" in + -b ) + shift + BOOTLOADER_IMG=$1 + ;; + -p ) + shift + PARTITION_IMG=$1 + ;; + -n ) + shift + NUTTX_IMG=$1 + ;; + -i ) + shift + FLASH_IMG=$1 + ;; + -h ) + usage + exit 0 + ;; + *) + usage + exit 1 + ;; + esac + shift +done # 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}" +if [ -z "${BOOTLOADER_IMG}" ] || [ -z "${PARTITION_IMG}" ] ; then + echo "Missing bootloader and partition table binary images." + usage exit 1 fi -BOOTLOADER=${1} -PARTITION_TABLE=${2} - -printf "Generating esp32_qemu_image.bin...\n" -printf "\tBootloader: %s\n" "${BOOTLOADER}" -printf "\tPartition Table: %s\n" "${PARTITION_TABLE}" +printf "Generating %s...\n" "${FLASH_IMG}" +printf "\tBootloader: %s\n" "${BOOTLOADER_IMG}" +printf "\tPartition Table: %s\n" "${PARTITION_IMG}" -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=nuttx.bin bs=1 seek="$(printf '%d' 0x10000)" of=esp32_qemu_image.bin conv=notrunc +dd if=/dev/zero bs=1024 count=4096 of=${FLASH_IMG} && \ +dd if="${BOOTLOADER_IMG}" bs=1 seek="$(printf '%d' 0x1000)" of=${FLASH_IMG} conv=notrunc && \ +dd if="${PARTITION_IMG}" bs=1 seek="$(printf '%d' 0x8000)" of=${FLASH_IMG} conv=notrunc && \ +dd if=$NUTTX_IMG bs=1 seek="$(printf '%d' 0x10000)" of=${FLASH_IMG} conv=notrunc if [ ${?} -ne 0 ]; then - printf "Failed to generate esp32_qemu_image.bin.\n" + printf "Failed to generate ${FLASH_IMG}.\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" +printf "Generated ${FLASH_IMG} successfully!\n" +printf "You can run it with QEMU using:\n" +printf "\tqemu-system-xtensa -nographic -machine esp32 -drive file=${FLASH_IMG},if=mtd,format=raw\n" -echo "esp32_qemu_image.bin" >> nuttx.manifest +echo "${FLASH_IMG}" >> nuttx.manifest
