From e4095df25187075a25b1b50c79941c1e03712a73 Mon Sep 17 00:00:00 2001 From: Kyunghwan Kwon Date: Wed, 3 Jan 2024 10:15:34 +0900 Subject: [PATCH] Refactor build system (#11) --- .github/memsize.baseline | 2 +- .github/workflows/ci.yml | 2 +- .gitignore | 1 + CMakeLists.txt | 15 +++++- LICENSE | 21 +++++++++ Makefile | 6 +++ ports/esp_idf/build.cmake | 80 ++++++++++++++++++++++++++++++++ ports/esp_idf/partitions.csv | 11 +++++ ports/esp_idf/sdkconfig.defaults | 8 ++++ {main => src}/main.c | 0 10 files changed, 143 insertions(+), 3 deletions(-) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 ports/esp_idf/build.cmake create mode 100644 ports/esp_idf/partitions.csv create mode 100644 ports/esp_idf/sdkconfig.defaults rename {main => src}/main.c (100%) diff --git a/.github/memsize.baseline b/.github/memsize.baseline index 9d8bb8d..fddea5f 100644 --- a/.github/memsize.baseline +++ b/.github/memsize.baseline @@ -1,2 +1,2 @@ text data bss dec hex filename - 159061 46756 367669 573486 8c02e build/template.elf + 159173 46760 367669 573602 8c0a2 build/template.elf diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e6cd826..232f670 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -104,7 +104,7 @@ jobs: body: body }) - name: Store codechecker baseline - if: always() + if: always() && github.event_name == 'pull_request' uses: EndBug/add-and-commit@v9 with: add: '[${{ env.CODECHECKER_BASE }}, ${{ env.MEMSEG_BASE }}]' diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..378eac2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build diff --git a/CMakeLists.txt b/CMakeLists.txt index f021b20..1f228aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,17 @@ cmake_minimum_required(VERSION 3.16) -include($ENV{IDF_PATH}/tools/cmake/project.cmake) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0") + cmake_policy(SET CMP0135 NEW) +endif() + +if (NOT DEFINED IDF_TARGET) + set(IDF_TARGET esp32s3) +endif() +set(CMAKE_TOOLCHAIN_FILE $ENV{IDF_PATH}/tools/cmake/toolchain-${IDF_TARGET}.cmake) + project(template) + +include($ENV{IDF_PATH}/tools/cmake/idf.cmake) +include(${CMAKE_SOURCE_DIR}/ports/esp_idf/build.cmake) diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..26edc47 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Kyunghwan Kwon + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Makefile b/Makefile index 889cfe5..aac99bd 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,12 @@ export Q include version.mk +all: build size + +build: + cmake -GNinja -B build + cmake --build build + .PHONY: confirm confirm: @echo 'Are you sure? [y/N] ' && read ans && [ $${ans:-N} = y ] diff --git a/ports/esp_idf/build.cmake b/ports/esp_idf/build.cmake new file mode 100644 index 0000000..42d5cb3 --- /dev/null +++ b/ports/esp_idf/build.cmake @@ -0,0 +1,80 @@ +set(COMPONENTS_USED + freertos + esptool_py + bt + esp-tls + esp_http_server + esp_http_client + esp_https_ota + app_update +) + +if ($ENV{IDF_VERSION} VERSION_GREATER_EQUAL "5.0.0") + list(APPEND COMPONENTS_USED esp_adc) +else() + list(APPEND COMPONENTS_USED esp_adc_cal) +endif() + +idf_build_process(${IDF_TARGET} + COMPONENTS + ${COMPONENTS_USED} + SDKCONFIG_DEFAULTS + "${CMAKE_CURRENT_LIST_DIR}/sdkconfig.defaults" + BUILD_DIR + ${CMAKE_CURRENT_BINARY_DIR} +) + +set(mapfile "${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}.map") +# project_description.json metadata file used for the flash and the monitor of +# idf.py to get the project information. +set(PROJECT_EXECUTABLE ${CMAKE_PROJECT_NAME}.elf) +set(PROJECT_BIN ${CMAKE_PROJECT_NAME}.bin) +set(build_components_json "[]") +set(build_component_paths_json "[]") +configure_file("${IDF_PATH}/tools/cmake/project_description.json.in" + "${CMAKE_CURRENT_BINARY_DIR}/project_description.json") + +add_executable(${PROJECT_EXECUTABLE} + ${CMAKE_SOURCE_DIR}/src/main.c +) + +target_compile_definitions(${PROJECT_EXECUTABLE} + PRIVATE + ESP_PLATFORM=1 + xPortIsInsideInterrupt=xPortInIsrContext +) +target_include_directories(${PROJECT_EXECUTABLE} + PRIVATE + $ENV{IDF_PATH}/components/freertos/FreeRTOS-Kernel/include/freertos + $ENV{IDF_PATH}/components/freertos/include/freertos + ${CMAKE_CURRENT_LIST_DIR} +) + +target_link_libraries(${PROJECT_EXECUTABLE} + idf::freertos + idf::spi_flash + idf::nvs_flash + idf::driver + idf::pthread + idf::esp_http_server + idf::esp_http_client + idf::esp_https_ota + idf::app_update + + -Wl,--cref + -Wl,--Map=\"${mapfile}\" +) +if ($ENV{IDF_VERSION} VERSION_GREATER_EQUAL "5.0.0") +target_link_libraries(${PROJECT_EXECUTABLE} idf::esp_adc) +else() +target_link_libraries(${PROJECT_EXECUTABLE} idf::esp_adc_cal) +endif() + +set(idf_size ${python} $ENV{IDF_PATH}/tools/idf_size.py) +add_custom_target(size DEPENDS ${mapfile} COMMAND ${idf_size} ${mapfile}) +add_custom_target(size-files DEPENDS ${mapfile} COMMAND ${idf_size} --files ${mapfile}) +add_custom_target(size-components DEPENDS ${mapfile} COMMAND ${idf_size} --archives ${mapfile}) + +# Attach additional targets to the executable file for flashing, +# linker script generation, partition_table generation, etc. +idf_build_executable(${PROJECT_EXECUTABLE}) diff --git a/ports/esp_idf/partitions.csv b/ports/esp_idf/partitions.csv new file mode 100644 index 0000000..1ca021a --- /dev/null +++ b/ports/esp_idf/partitions.csv @@ -0,0 +1,11 @@ +# Espressif ESP32 Partition Table +# Name , Type, SubType, Offset, Size, Flags +nvs , data, nvs, 0x10000, 0xc000 +nvs_key , data, nvs_keys, 0x1c000, 0x1000, encrypted +otadata , data, ota, 0x1d000, 0x2000 +phy_init , data, phy, 0x1f000, 0x1000 +ota_0 , app, ota_0, 0x20000, 0x300000 +ota_1 , app, ota_1, 0x320000, 0x300000 +fs , data, spiffs, 0x620000, 0x80000 +nvs_eeprom, data, nvs, 0x6a0000, 0x4000 +spare , data, nvs, 0x6a4000, 0x40000 diff --git a/ports/esp_idf/sdkconfig.defaults b/ports/esp_idf/sdkconfig.defaults new file mode 100644 index 0000000..e043cb0 --- /dev/null +++ b/ports/esp_idf/sdkconfig.defaults @@ -0,0 +1,8 @@ +CONFIG_PARTITION_TABLE_CUSTOM=y +CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="ports/esp_idf/partitions.csv" +CONFIG_PARTITION_TABLE_FILENAME="ports/esp_idf/partitions.csv" +CONFIG_PARTITION_TABLE_OFFSET=0xE000 + +CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y + +CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y diff --git a/main/main.c b/src/main.c similarity index 100% rename from main/main.c rename to src/main.c