feat(make): Sync code from esp-idf and modify for ESP8266

Commit ID: f6bfe13e
This commit is contained in:
dongheng
2019-05-05 14:36:04 +08:00
parent 09d8546659
commit cca13e0f99
86 changed files with 2172 additions and 779 deletions

View File

@ -1,57 +1,96 @@
set(COMPONENT_SRCDIRS source driver)
if(BOOTLOADER_BUILD)
# For bootloader, all we need from esp8266 is headers
set(COMPONENT_ADD_INCLUDEDIRS include)
# set(COMPONENT_REQUIRES ${COMPONENTS})
set(COMPONENT_SRCS source/ets_printf.c)
register_component(esp8266)
set(COMPONENT_ADD_INCLUDEDIRS include)
# as cmake won't attach linker args to a header-only library, attach
# linker args directly to the bootloader.elf
set(ESP8266_BOOTLOADER_LINKER_SCRIPTS
"${CMAKE_CURRENT_SOURCE_DIR}/ld/esp8266.rom.ld"
PARENT_SCOPE
)
set(COMPONENT_PRIV_INCLUDEDIRS include/driver)
set(ESP8266_BOOTLOADER_LIBS
"-L ${CMAKE_CURRENT_SOURCE_DIR}/lib"
"core"
PARENT_SCOPE
)
set(COMPONENT_REQUIRES lwip)
set(COMPONENT_PRIV_REQUIRES freertos)
else()
# Regular app build
register_component()
set(COMPONENT_SRCDIRS "driver source")
set(COMPONENT_ADD_INCLUDEDIRS "include")
set(COMPONENT_PRIV_INCLUDEDIRS "include/driver")
set(COMPONENT_REQUIRES newlib)
# driver is a public requirement because esp_sleep.h uses gpio_num_t & touch_pad_t
# tcpip_adapter is a public requirement because esp_event.h uses tcpip_adapter types
set(COMPONENT_PRIV_REQUIRES "log" "nvs_flash" "spi_flash" "tcpip_adapter" "bootloader_support" "util" "esp_ringbuf")
register_component()
target_link_libraries(esp8266 "-L ${CMAKE_CURRENT_SOURCE_DIR}/lib")
if(NOT CONFIG_NO_BLOBS)
target_link_libraries(esp8266 gcc hal core net80211 phy pp smartconfig ssc wpa espnow wps)
endif()
target_linker_script(esp8266 "${CMAKE_CURRENT_BINARY_DIR}/esp8266_out.ld" "${CMAKE_CURRENT_BINARY_DIR}/esp8266_common_out.ld")
target_linker_script(esp8266
"ld/esp8266.rom.ld"
"ld/esp8266.peripherals.ld"
)
target_link_libraries(esp8266 "-u call_user_start")
# Preprocess esp8266.ld linker script to include configuration, becomes esp8266_out.ld
set(LD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ld)
add_custom_command(
OUTPUT esp8266_out.ld
COMMAND "${CMAKE_C_COMPILER}" -C -P -x c -E -o esp8266_out.ld ${CFLAGS} -I ${CONFIG_DIR} ${LD_DIR}/esp8266.ld
MAIN_DEPENDENCY ${LD_DIR}/esp8266.ld ${SDKCONFIG_H}
COMMENT "Generating memory map linker script..."
VERBATIM)
add_custom_command(
OUTPUT esp8266_common_out.ld
COMMAND "${CMAKE_C_COMPILER}" -C -P -x c -E -o esp8266_common_out.ld -I ${CONFIG_DIR} ${LD_DIR}/esp8266.common.ld
MAIN_DEPENDENCY ${LD_DIR}/esp8266.common.ld ${SDKCONFIG_H}
COMMENT "Generating section linker script..."
VERBATIM)
add_custom_target(esp8266_linker_script DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/esp8266_out.ld" "${CMAKE_CURRENT_BINARY_DIR}/esp8266_common_out.ld")
add_dependencies(esp8266 esp8266_linker_script)
if(CONFIG_ESP8266_PHY_INIT_DATA_IN_PARTITION)
set(PHY_INIT_DATA_BIN phy_init_data.bin)
# To get the phy_init_data.bin file, compile phy_init_data.h as a C file and then objcopy
# the object file to a raw binary
add_custom_command(
OUTPUT ${PHY_INIT_DATA_BIN}
DEPENDS ${CMAKE_CURRENT_LIST_DIR}/phy_init_data.h
COMMAND ${CMAKE_C_COMPILER} -x c -c
-I ${CMAKE_CURRENT_LIST_DIR} -I ${CMAKE_CURRENT_LIST_DIR}/include -I ${CMAKE_BINARY_DIR}
-o phy_init_data.obj
${CMAKE_CURRENT_LIST_DIR}/phy_init_data.h
COMMAND ${CMAKE_OBJCOPY} -O binary phy_init_data.obj ${PHY_INIT_DATA_BIN}
)
add_custom_target(phy_init_data ALL DEPENDS ${PHY_INIT_DATA_BIN})
add_dependencies(flash phy_init_data)
endif()
if(CONFIG_ESP_FILENAME_MACRO_NO_PATH)
target_compile_definitions(${COMPONENT_NAME} PUBLIC -D __ESP_FILE__=__FILE__)
endif()
if(CONFIG_ESP_FILENAME_MACRO_RAW)
target_compile_definitions(${COMPONENT_NAME} PUBLIC -D __ESP_FILE__=__FILE__)
endif()
if(CONFIG_ESP_FILENAME_MACRO_NULL)
target_compile_definitions(${COMPONENT_NAME} PUBLIC -D __ESP_FILE__="null")
endif()
target_link_libraries(${COMPONENT_NAME} "-L ${CMAKE_CURRENT_SOURCE_DIR}/lib")
if(NOT CONFIG_NO_BLOBS)
target_link_libraries(${COMPONENT_NAME} gcc hal core
net80211 phy pp smartconfig ssc wpa espnow wps)
endif()
target_link_libraries(${COMPONENT_NAME} "-u call_user_start")
set(ESPTOOLPY_FLASHSIZE ${CONFIG_ESPTOOLPY_FLASHSIZE})
if(ESPTOOLPY_FLASHSIZE STREQUAL "512KB")
set(ESP8266_LINKER_SCRIPTS eagle.app.v6.new.512.${CONFIG_ESPTOOLPY_APP_NUM}.ld)
endif()
if(ESPTOOLPY_FLASHSIZE STREQUAL "1MB")
set(ESP8266_LINKER_SCRIPTS eagle.app.v6.new.1024.${CONFIG_ESPTOOLPY_APP_NUM}.ld)
endif()
if(ESPTOOLPY_FLASHSIZE STREQUAL "2MB")
set(ESP8266_LINKER_SCRIPTS eagle.app.v6.new.1024.${CONFIG_ESPTOOLPY_APP_NUM}.ld)
endif()
if(ESPTOOLPY_FLASHSIZE STREQUAL "2MB-c1")
set(ESP8266_LINKER_SCRIPTS eagle.app.v6.new.2048.ld)
endif()
if(ESPTOOLPY_FLASHSIZE STREQUAL "4MB")
set(ESP8266_LINKER_SCRIPTS eagle.app.v6.new.1024.${CONFIG_ESPTOOLPY_APP_NUM}.ld)
endif()
if(ESPTOOLPY_FLASHSIZE STREQUAL "4MB-c1")
set(ESP8266_LINKER_SCRIPTS eagle.app.v6.new.2048.ld)
endif()
if(ESPTOOLPY_FLASHSIZE STREQUAL "8MB")
set(ESP8266_LINKER_SCRIPTS eagle.app.v6.new.2048.ld)
endif()
if(ESPTOOLPY_FLASHSIZE STREQUAL "16MB")
set(ESP8266_LINKER_SCRIPTS eagle.app.v6.new.2048.ld)
endif()
target_linker_script(${COMPONENT_NAME}
ld/${ESP8266_LINKER_SCRIPTS}
ld/eagle.app.v6.common.ld
ld/eagle.rom.addr.v6.ld)
target_compile_options(${COMPONENT_NAME} PUBLIC -Wno-error=char-subscripts -Wno-error=unknown-pragmas -Wno-error=implicit-function-declaration
-Wno-error=pointer-sign -Wno-error=switch -Wno-error=maybe-uninitialized -Wno-error=format=
-Wno-error=unused-value -Wno-error=address -Wno-error=return-type -Wno-error=format-extra-args
-Wno-error=format-zero-length -Wno-error=unused-label -Wno-error=sizeof-pointer-memaccess)
target_compile_options(${COMPONENT_NAME} PUBLIC -DICACHE_FLASH)

View File

@ -105,7 +105,7 @@ SECTIONS
*(.init.literal)
*(.init)
*(.iram1 .iram1.*)
*libspi_flash.a:spi_flash_raw.o(.literal .text .literal.* .text.*)
*libspi_flash.a:spi_flash_raw.*(.literal .text .literal.* .text.*)
#ifdef CONFIG_ESP8266_WIFI_DEBUG_LOG_ENABLE
*libpp_dbg.a:(.literal .text .literal.* .text.*)
#else
@ -134,13 +134,13 @@ SECTIONS
#endif
#ifdef CONFIG_FREERTOS_GLOBAL_DATA_LINK_IRAM
*libfreertos.a:tasks.o(.bss .data .bss.* .data.* COMMON)
*libfreertos.a:timers.o(.bss .data .bss.* .data.* COMMON)
*libfreertos.a:freertos_hooks.o(.bss .data .bss.* .data.* COMMON)
*libfreertos.a:tasks.*(.bss .data .bss.* .data.* COMMON)
*libfreertos.a:timers.*(.bss .data .bss.* .data.* COMMON)
*libfreertos.a:freertos_hooks.*(.bss .data .bss.* .data.* COMMON)
#endif
#ifdef CONFIG_LINK_ETS_PRINTF_TO_IRAM
*libesp8266.a:ets_printf.o(.literal .text .literal.* .text.* .rodata.* .rodata)
*libesp8266.a:ets_printf.*(.literal .text .literal.* .text.* .rodata.* .rodata)
#endif
_text_end = ABSOLUTE(.);
@ -182,13 +182,13 @@ SECTIONS
. = (. + 3) & ~ 3;
/* C++ constructor and destructor tables, properly ordered: */
__init_array_start = ABSOLUTE(.);
KEEP (*crtbegin.o(.ctors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
KEEP (*crtbegin.*(.ctors))
KEEP (*(EXCLUDE_FILE (*crtend.*) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
__init_array_end = ABSOLUTE(.);
KEEP (*crtbegin.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
KEEP (*crtbegin.*(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.*) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))
/* C++ exception handlers table: */

View File

@ -1,162 +0,0 @@
set(BOOTLOADER_FIRMWARE_DIR ${CMAKE_CURRENT_LIST_DIR}/firmware)
#configurate downloading parameters
set(ESPTOOLPY_FLASHSIZE ${CONFIG_ESPTOOLPY_FLASHSIZE})
set(ESPTOOLPY_FLASHMODE ${CONFIG_ESPTOOLPY_FLASHMODE})
set(ESPTOOLPY_FLASHFREQ ${CONFIG_ESPTOOLPY_FLASHFREQ})
if(${ESPTOOLPY_FLASHSIZE} STREQUAL "512KB")
set(BLANK_BIN_OFFSET1 0x7B000)
set(BLANK_BIN_OFFSET2 0x7E000)
set(ESP_INIT_DATA_DEFAULT_BIN_OFFSET 0x7C000)
set(ESP8266_SIZEMAP 0)
endif()
if(${ESPTOOLPY_FLASHSIZE} STREQUAL "1MB")
set(BLANK_BIN_OFFSET1 0xFB000)
set(BLANK_BIN_OFFSET2 0xFE000)
set(ESP_INIT_DATA_DEFAULT_BIN_OFFSET 0xFC000)
set(ESP8266_SIZEMAP 2)
endif()
if(${ESPTOOLPY_FLASHSIZE} STREQUAL "2MB")
set(BLANK_BIN_OFFSET1 0x1FB000)
set(BLANK_BIN_OFFSET2 0x1FE000)
set(ESP_INIT_DATA_DEFAULT_BIN_OFFSET 0x1FC000)
set(ESP8266_SIZEMAP 3)
endif()
if(${ESPTOOLPY_FLASHSIZE} STREQUAL "2MB-c1")
set(BLANK_BIN_OFFSET1 0x1FB000)
set(BLANK_BIN_OFFSET2 0x1FE000)
set(ESP_INIT_DATA_DEFAULT_BIN_OFFSET 0x1FC000)
set(ESP8266_SIZEMAP 5)
endif()
if(${ESPTOOLPY_FLASHSIZE} STREQUAL "4MB")
set(BLANK_BIN_OFFSET1 0x3FB000)
set(BLANK_BIN_OFFSET2 0x3FE000)
set(ESP_INIT_DATA_DEFAULT_BIN_OFFSET 0x3FC000)
set(ESP8266_SIZEMAP 4)
endif()
if(${ESPTOOLPY_FLASHSIZE} STREQUAL "4MB-c1")
set(BLANK_BIN_OFFSET1 0x3FB000)
set(BLANK_BIN_OFFSET2 0x3FE000)
set(ESP_INIT_DATA_DEFAULT_BIN_OFFSET 0x3FC000)
set(ESP8266_SIZEMAP 6)
endif()
if(${ESPTOOLPY_FLASHSIZE} STREQUAL "8MB")
set(BLANK_BIN_OFFSET1 0x7FB000)
set(BLANK_BIN_OFFSET2 0x7FE000)
set(ESP_INIT_DATA_DEFAULT_BIN_OFFSET 0x7FC000)
set(ESP8266_SIZEMAP 8)
endif()
if(${ESPTOOLPY_FLASHSIZE} STREQUAL "16MB")
set(BLANK_BIN_OFFSET1 0xFFB000)
set(BLANK_BIN_OFFSET2 0xFFE000)
set(ESP_INIT_DATA_DEFAULT_BIN_OFFSET 0xFFC000)
set(ESP8266_SIZEMAP 9)
endif()
set(BOOTLOADER_BIN_OFFSET 0)
set(APP_OFFSET 0x1000)
set(ESP8266_BOOTMODE 2) # always be 2
if(${ESPTOOLPY_FLASHMODE} STREQUAL "qio")
set(ESP8266_FLASHMODE 0)
endif()
if(${ESPTOOLPY_FLASHMODE} STREQUAL "qout")
set(ESP8266_FLASHMODE 1)
endif()
if(${ESPTOOLPY_FLASHMODE} STREQUAL "dio")
set(ESP8266_FLASHMODE 2)
endif()
if(${ESPTOOLPY_FLASHMODE} STREQUAL "dout")
set(ESP8266_FLASHMODE 3)
endif()
if(${ESPTOOLPY_FLASHFREQ} STREQUAL "20m")
set(ESP8266_FREQDIV 2)
endif()
if(${ESPTOOLPY_FLASHFREQ} STREQUAL "26m")
set(ESP8266_FREQDIV 1)
endif()
if(${ESPTOOLPY_FLASHFREQ} STREQUAL "40m")
set(ESP8266_FREQDIV 0)
endif()
if(${ESPTOOLPY_FLASHFREQ} STREQUAL "80m")
set(ESP8266_FREQDIV 15)
endif()
set(ESP8266_BINSCRIPT ${PYTHON} $(IDF_PATH)/tools/gen_appbin.py)
#
# Add 'app.bin' target - generates with elf2image
#
add_custom_command(OUTPUT ${PROJECT_NAME}.bin
COMMAND ${CMAKE_OBJCOPY_COMPILER} --only-section .text -O binary ${PROJECT_NAME}.elf eagle.app.v6.text.bin
COMMAND ${CMAKE_OBJCOPY_COMPILER} --only-section .data -O binary ${PROJECT_NAME}.elf eagle.app.v6.data.bin
COMMAND ${CMAKE_OBJCOPY_COMPILER} --only-section .rodata -O binary ${PROJECT_NAME}.elf eagle.app.v6.rodata.bin
COMMAND ${CMAKE_OBJCOPY_COMPILER} --only-section .irom0.text -O binary ${PROJECT_NAME}.elf eagle.app.v6.irom0text.bin
COMMAND ${ESP8266_BINSCRIPT} ${PROJECT_NAME}.elf ${ESP8266_BOOTMODE} ${ESP8266_FLASHMODE} ${ESP8266_FREQDIV} ${ESP8266_SIZEMAP}
COMMAND mv eagle.app.flash.bin ${PROJECT_NAME}.bin
COMMAND rm eagle.app.v6.text.bin eagle.app.v6.data.bin eagle.app.v6.rodata.bin eagle.app.v6.irom0text.bin
DEPENDS ${PROJECT_NAME}.elf
VERBATIM
)
add_custom_target(app ALL DEPENDS ${PROJECT_NAME}.bin)
set(BLANK_BIN ${BOOTLOADER_FIRMWARE_DIR}/blank.bin)
set(ESP_INIT_DATA_DEFAULT_BIN ${BOOTLOADER_FIRMWARE_DIR}/esp_init_data_default.bin)
set(BOOTLOADER_BIN ${BOOTLOADER_FIRMWARE_DIR}/boot_v1.7.bin)
set(PYTHON ${CONFIG_PYTHON})
set(ESPTOOLPY_SRC $(IDF_PATH)/components/esptool_py/esptool/esptool.py)
set(CHIP esp8266)
set(ESPPORT ${CONFIG_ESPTOOLPY_PORT})
set(ESPBAUD ${CONFIG_ESPTOOLPY_BAUD})
set(ESPFLASHMODE ${CONFIG_ESPTOOLPY_FLASHMODE})
set(ESPFLASHFREQ ${CONFIG_ESPTOOLPY_FLASHFREQ})
set(ESPFLASHSIZE ${CONFIG_ESPTOOLPY_FLASHSIZE})
set(ESPTOOLPY ${PYTHON} ${ESPTOOLPY_SRC} --chip ${CHIP})
set(ESPTOOL_WRITE_FLASH_OPTIONS --flash_mode ${ESPFLASHMODE} --flash_freq ${ESPFLASHFREQ} --flash_size ${ESPFLASHSIZE})
set(ESPTOOLPY_SERIAL ${ESPTOOLPY} --port ${ESPPORT} --baud ${ESPBAUD} --before ${CONFIG_ESPTOOLPY_BEFORE} --after ${CONFIG_ESPTOOLPY_AFTER})
set(ESPTOOLPY_WRITE_FLASH ${ESPTOOLPY_SERIAL} write_flash -z ${ESPTOOL_WRITE_FLASH_OPTIONS})
set(APP_BIN ${PROJECT_NAME}.bin)
set(ESPTOOL_ALL_FLASH_ARGS ${BOOTLOADER_BIN_OFFSET} ${BOOTLOADER_BIN}
${APP_OFFSET} ${APP_BIN}
${ESP_INIT_DATA_DEFAULT_BIN_OFFSET} ${ESP_INIT_DATA_DEFAULT_BIN}
${BLANK_BIN_OFFSET1} ${BLANK_BIN}
${BLANK_BIN_OFFSET2} ${BLANK_BIN})
add_custom_target(flash DEPENDS ${PROJECT_NAME}.bin
COMMAND echo "Flashing binaries to serial port ${ESPPORT} app at offset ${APP_OFFSET}..."
COMMAND echo ${ESPTOOL_ALL_FLASH_ARGS}
COMMAND ${ESPTOOLPY_WRITE_FLASH} ${ESPTOOL_ALL_FLASH_ARGS}
COMMAND echo "success"
)
add_custom_target(erase_flash DEPENDS ""
COMMAND echo "Erasing entire flash..."
COMMAND ${ESPTOOLPY_SERIAL} erase_flash
COMMAND echo "success"
)
set(MONITOR_PYTHON ${PYTHON})
set(MONITORBAUD ${CONFIG_MONITOR_BAUD})
set(APP_ELF ${PROJECT_NAME}.elf)
set(MONITOR_OPTS --baud ${MONITORBAUD} --port ${ESPPORT} --toolchain-prefix ${CONFIG_TOOLPREFIX} ${APP_ELF})
function(esp_monitor func dependencies)
add_custom_target(${func} DEPENDS ${dependencies}
COMMAND echo "start monitor ... "
COMMAND echo $(MONITOR_PYTHON) ${IDF_PATH}/tools/idf_monitor.py ${MONITOR_OPTS}
COMMAND $(MONITOR_PYTHON) ${IDF_PATH}/tools/idf_monitor.py ${MONITOR_OPTS}
COMMAND echo "idf monitor exit"
)
endfunction()
esp_monitor(monitor "")