Config.mk 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. ############################################################################
  2. # tools/esp32/Config.mk
  3. #
  4. # Licensed to the Apache Software Foundation (ASF) under one or more
  5. # contributor license agreements. See the NOTICE file distributed with
  6. # this work for additional information regarding copyright ownership. The
  7. # ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. # "License"); you may not use this file except in compliance with the
  9. # License. You may obtain a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. # License for the specific language governing permissions and limitations
  17. # under the License.
  18. #
  19. ############################################################################
  20. # These are the macros that will be used in the NuttX make system to compile
  21. # and assemble source files and to insert the resulting object files into an
  22. # archive. These replace the default definitions at tools/Config.mk
  23. ifeq ($(CONFIG_ESP32_FLASH_2M),y)
  24. FLASH_SIZE := 2MB
  25. else ifeq ($(CONFIG_ESP32_FLASH_4M),y)
  26. FLASH_SIZE := 4MB
  27. else ifeq ($(CONFIG_ESP32_FLASH_8M),y)
  28. FLASH_SIZE := 8MB
  29. else ifeq ($(CONFIG_ESP32_FLASH_16M),y)
  30. FLASH_SIZE := 16MB
  31. endif
  32. ifeq ($(CONFIG_ESP32_FLASH_MODE_DIO),y)
  33. FLASH_MODE := dio
  34. else ifeq ($(CONFIG_ESP32_FLASH_MODE_DOUT),y)
  35. FLASH_MODE := dout
  36. else ifeq ($(CONFIG_ESP32_FLASH_MODE_QIO),y)
  37. FLASH_MODE := qio
  38. else ifeq ($(CONFIG_ESP32_FLASH_MODE_QOUT),y)
  39. FLASH_MODE := qout
  40. endif
  41. ifeq ($(CONFIG_ESP32_FLASH_FREQ_80M),y)
  42. FLASH_FREQ := 80m
  43. else ifeq ($(CONFIG_ESP32_FLASH_FREQ_40M),y)
  44. FLASH_FREQ := 40m
  45. else ifeq ($(CONFIG_ESP32_FLASH_FREQ_26M),y)
  46. FLASH_FREQ := 26m
  47. else ifeq ($(CONFIG_ESP32_FLASH_FREQ_20M),y)
  48. FLASH_FREQ := 20m
  49. endif
  50. ESPTOOL_ELF2IMG_OPTS := -fs $(FLASH_SIZE) -fm $(FLASH_MODE) -ff $(FLASH_FREQ)
  51. ifeq ($(CONFIG_ESP32_FLASH_DETECT),y)
  52. ESPTOOL_WRITEFLASH_OPTS := -fs detect -fm dio -ff $(FLASH_FREQ)
  53. else
  54. ESPTOOL_WRITEFLASH_OPTS := -fs $(FLASH_SIZE) -fm dio -ff $(FLASH_FREQ)
  55. endif
  56. ifdef ESPTOOL_BINDIR
  57. BL_OFFSET=0x1000
  58. PT_OFFSET=0x8000
  59. BOOTLOADER=$(ESPTOOL_BINDIR)/bootloader-esp32.bin
  60. PARTITION_TABLE=$(ESPTOOL_BINDIR)/partition-table-esp32.bin
  61. FLASH_BL=$(BL_OFFSET) $(BOOTLOADER)
  62. FLASH_PT=$(PT_OFFSET) $(PARTITION_TABLE)
  63. endif
  64. ifeq ($(CONFIG_ESP32_QEMU_IMAGE),y)
  65. MK_QEMU_IMG=$(TOPDIR)/tools/esp32/mk_qemu_img.sh -b $(BOOTLOADER) -p $(PARTITION_TABLE)
  66. else
  67. MK_QEMU_IMG=
  68. endif
  69. # POSTBUILD -- Perform post build operations
  70. define POSTBUILD
  71. $(Q) echo "MKIMAGE: ESP32 binary"
  72. $(Q) if ! esptool.py version 1>/dev/null 2>&1; then \
  73. echo ""; \
  74. echo "esptool.py not found. Please run: \"pip install esptool\""; \
  75. echo ""; \
  76. echo "Run make again to create the nuttx.bin image."; \
  77. exit 1; \
  78. fi
  79. $(Q) if [ -z $(FLASH_SIZE) ]; then \
  80. echo "Missing Flash memory size configuration for the ESP32 chip."; \
  81. exit 1; \
  82. fi
  83. esptool.py -c esp32 elf2image $(ESPTOOL_ELF2IMG_OPTS) -o nuttx.bin nuttx
  84. $(Q) echo "Generated: nuttx.bin (ESP32 compatible)"
  85. $(Q) $(MK_QEMU_IMG)
  86. endef
  87. # ESPTOOL_BAUD -- Serial port baud rate used when flashing/reading via esptool.py
  88. ESPTOOL_BAUD ?= 921600
  89. # DOWNLOAD -- Download binary image via esptool.py
  90. define DOWNLOAD
  91. $(eval ESPTOOL_BINS := $(FLASH_BL) $(FLASH_PT) 0x10000 $(1).bin)
  92. $(Q) if [ -z $(ESPTOOL_PORT) ]; then \
  93. echo "DOWNLOAD error: Missing serial port device argument."; \
  94. echo "USAGE: make download ESPTOOL_PORT=<port> [ ESPTOOL_BAUD=<baud> ] [ ESPTOOL_BINDIR=<dir> ]"; \
  95. exit 1; \
  96. fi
  97. esptool.py -c esp32 -p $(ESPTOOL_PORT) -b $(ESPTOOL_BAUD) write_flash $(ESPTOOL_WRITEFLASH_OPTS) $(ESPTOOL_BINS)
  98. endef