Skip to content

Commit

Permalink
Merge branch 'feature/non_os_build' into 'master'
Browse files Browse the repository at this point in the history
change(build): Add a new CMake flag `NON_OS_BUILD` for non-FreeRTOS builds

See merge request espressif/esp-idf!34129
  • Loading branch information
laukik-hase committed Oct 23, 2024
2 parents 96632b7 + 5328dcd commit 6f466df
Show file tree
Hide file tree
Showing 17 changed files with 46 additions and 30 deletions.
4 changes: 3 additions & 1 deletion components/bootloader/subproject/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ foreach(component ${proj_components})
endforeach()

set(BOOTLOADER_BUILD 1)
set(NON_OS_BUILD 1)
include("${IDF_PATH}/tools/cmake/project.cmake")
set(common_req log esp_rom esp_common esp_hw_support newlib)
idf_build_set_property(EXTRA_COMPONENT_EXCLUDE_DIRS "${EXTRA_COMPONENT_EXCLUDE_DIRS}")
Expand All @@ -66,6 +67,7 @@ idf_build_set_property(__OUTPUT_SDKCONFIG 0)
project(bootloader)

idf_build_set_property(COMPILE_DEFINITIONS "BOOTLOADER_BUILD=1" APPEND)
idf_build_set_property(COMPILE_DEFINITIONS "NON_OS_BUILD=1" APPEND)
idf_build_set_property(COMPILE_OPTIONS "-fno-stack-protector" APPEND)

idf_component_get_property(main_args esptool_py FLASH_ARGS)
Expand Down Expand Up @@ -207,7 +209,7 @@ elseif(CONFIG_SECURE_BOOTLOADER_REFLASHABLE)
COMMAND ${CMAKE_COMMAND} -E echo
"* After first boot, only re-flashes of this kind (with same key) will be accepted."
COMMAND ${CMAKE_COMMAND} -E echo
"* Not recommended to re-use the same secure boot keyfile on multiple production devices."
"* Not recommended to reuse the same secure boot keyfile on multiple production devices."
DEPENDS gen_secure_bootloader_key gen_bootloader_digest_bin
VERBATIM)
elseif(
Expand Down
3 changes: 2 additions & 1 deletion components/efuse/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
idf_build_get_property(target IDF_TARGET)
idf_build_get_property(non_os_build NON_OS_BUILD)

if(CONFIG_EFUSE_VIRTUAL)
message(STATUS "Efuse virtual mode is enabled. If Secure boot or Flash encryption is on"
Expand Down Expand Up @@ -28,7 +29,7 @@ list(APPEND srcs "src/esp_efuse_api.c"
"src/esp_efuse_utility.c"
"src/efuse_controller/keys/${type}/esp_efuse_api_key.c")

if(BOOTLOADER_BUILD)
if(non_os_build)
idf_component_register(SRCS "${srcs}"
PRIV_REQUIRES bootloader_support soc spi_flash
INCLUDE_DIRS "${include_dirs}"
Expand Down
10 changes: 5 additions & 5 deletions components/efuse/src/esp_efuse_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

const static char *TAG = "efuse";

#if defined(BOOTLOADER_BUILD)
#ifdef NON_OS_BUILD
#define EFUSE_LOCK_ACQUIRE_RECURSIVE()
#define EFUSE_LOCK_RELEASE_RECURSIVE()
#else
Expand All @@ -39,11 +39,11 @@ esp_err_t esp_efuse_read_field_blob(const esp_efuse_desc_t* field[], void* dst,
do {
memset((uint8_t *)dst, 0, esp_efuse_utility_get_number_of_items(dst_size_bits, 8));
err = esp_efuse_utility_process(field, dst, dst_size_bits, esp_efuse_utility_fill_buff);
#ifndef BOOTLOADER_BUILD
#ifndef NON_OS_BUILD
if (err == ESP_ERR_DAMAGED_READING) {
vTaskDelay(1);
}
#endif // BOOTLOADER_BUILD
#endif // NON_OS_BUILD
} while (err == ESP_ERR_DAMAGED_READING);
}
return err;
Expand All @@ -67,11 +67,11 @@ esp_err_t esp_efuse_read_field_cnt(const esp_efuse_desc_t* field[], size_t* out_
do {
*out_cnt = 0;
err = esp_efuse_utility_process(field, out_cnt, 0, esp_efuse_utility_count_once);
#ifndef BOOTLOADER_BUILD
#ifndef NON_OS_BUILD
if (err == ESP_ERR_DAMAGED_READING) {
vTaskDelay(1);
}
#endif // BOOTLOADER_BUILD
#endif // NON_OS_BUILD
} while (err == ESP_ERR_DAMAGED_READING);
}
return err;
Expand Down
5 changes: 3 additions & 2 deletions components/esp_hw_support/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
idf_build_get_property(target IDF_TARGET)
idf_build_get_property(non_os_build NON_OS_BUILD)

# On Linux, we only support a few features, hence this simple component registration
if(${target} STREQUAL "linux")
Expand All @@ -22,7 +23,7 @@ if(CONFIG_RTC_CLK_SRC_INT_RC32K)
endif()

set(srcs "cpu.c" "port/${IDF_TARGET}/esp_cpu_intr.c" "esp_memory_utils.c" "port/${IDF_TARGET}/cpu_region_protect.c")
if(NOT BOOTLOADER_BUILD)
if(NOT non_os_build)
list(APPEND srcs "esp_clk.c"
"clk_ctrl_os.c"
"hw_random.c"
Expand Down Expand Up @@ -167,7 +168,7 @@ if(CONFIG_ESP_SLEEP_GPIO_RESET_WORKAROUND OR CONFIG_PM_SLP_DISABLE_GPIO)
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u esp_sleep_gpio_include")
endif()

if(NOT BOOTLOADER_BUILD)
if(NOT non_os_build)
if(CONFIG_SPIRAM)
idf_component_optional_requires(PRIVATE esp_psram)
endif()
Expand Down
5 changes: 3 additions & 2 deletions components/esp_security/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
idf_build_get_property(target IDF_TARGET)
idf_build_get_property(non_os_build NON_OS_BUILD)

if(${target} STREQUAL "linux")
return() # This component is not supported by the POSIX/Linux simulator
Expand All @@ -8,7 +9,7 @@ set(srcs "")
set(priv_requires "")
set(priv_includes "")

if(NOT BOOTLOADER_BUILD)
if(NOT non_os_build)
list(APPEND srcs "src/init.c")
list(APPEND priv_includes "src/${IDF_TARGET}")

Expand Down Expand Up @@ -37,6 +38,6 @@ idf_component_register(SRCS ${srcs}
PRIV_INCLUDE_DIRS ${priv_includes}
PRIV_REQUIRES ${priv_requires})

if(NOT BOOTLOADER_BUILD)
if(NOT non_os_build)
target_link_libraries(${COMPONENT_LIB} PRIVATE "-u esp_security_init_include_impl")
endif()
5 changes: 3 additions & 2 deletions components/esptool_py/project_include.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ idf_build_get_property(target IDF_TARGET)
idf_build_get_property(python PYTHON)
idf_build_get_property(idf_path IDF_PATH)

idf_build_get_property(non_os_build NON_OS_BUILD)

set(chip_model ${target})

Expand Down Expand Up @@ -151,7 +152,7 @@ elseif(CONFIG_SECURE_SIGNED_APPS_RSA_SCHEME OR CONFIG_SECURE_SIGNED_APPS_ECDSA_V
set(secure_boot_version "2")
endif()

if(NOT BOOTLOADER_BUILD AND CONFIG_SECURE_SIGNED_APPS)
if(NOT non_os_build AND CONFIG_SECURE_SIGNED_APPS)
if(CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES)
# for locally signed secure boot image, add a signing step to get from unsigned app to signed app
get_filename_component(secure_boot_signing_key "${CONFIG_SECURE_BOOT_SIGNING_KEY}"
Expand Down Expand Up @@ -526,7 +527,7 @@ function(esptool_py_custom_target target_name flasher_filename dependencies)
endif()
endfunction()

if(NOT BOOTLOADER_BUILD)
if(NOT non_os_build)
set(flash_deps "")

if(CONFIG_APP_BUILD_TYPE_APP_2NDBOOT)
Expand Down
4 changes: 3 additions & 1 deletion components/freertos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
# - Files common across all kernel implementations and all ports

# Bootloader builds only needs FreeRTOS for config, not for anything else
if(BOOTLOADER_BUILD)
idf_build_get_property(non_os_build NON_OS_BUILD)

if(non_os_build)
idf_component_register()
return()
endif()
Expand Down
5 changes: 3 additions & 2 deletions components/log/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
idf_build_get_property(target IDF_TARGET)
idf_build_get_property(non_os_build NON_OS_BUILD)

if(BOOTLOADER_BUILD)
if(non_os_build)
set(system_target "noos")
else()
if(${target} STREQUAL "linux")
Expand All @@ -15,7 +16,7 @@ set(srcs "src/${system_target}/log_timestamp.c"
"src/${system_target}/log_lock.c")
set(priv_requires "")

if(NOT BOOTLOADER_BUILD)
if(NOT non_os_build)
list(APPEND priv_requires soc hal esp_hw_support)

list(APPEND srcs "src/os/log_write.c")
Expand Down
4 changes: 2 additions & 2 deletions components/log/include/esp_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void esp_log_writev(esp_log_level_t level, const char* tag, const char* format,
esp_rom_printf(LOG_FORMAT(log_tag_letter, format), esp_log_timestamp(), tag, ##__VA_ARGS__); \
}} while(0)

#ifndef BOOTLOADER_BUILD
#ifndef NON_OS_BUILD
#if defined(__cplusplus) && (__cplusplus > 201703L)
#define ESP_LOGE( tag, format, ... ) ESP_LOG_LEVEL_LOCAL(ESP_LOG_ERROR, tag, format __VA_OPT__(,) __VA_ARGS__)
#define ESP_LOGW( tag, format, ... ) ESP_LOG_LEVEL_LOCAL(ESP_LOG_WARN, tag, format __VA_OPT__(,) __VA_ARGS__)
Expand Down Expand Up @@ -147,7 +147,7 @@ void esp_log_writev(esp_log_level_t level, const char* tag, const char* format,
/// macro to output logs at ``ESP_LOG_VERBOSE`` level. @see ``ESP_LOGE``
#define ESP_LOGV( tag, format, ... ) ESP_EARLY_LOGV(tag, format, ##__VA_ARGS__)
#endif // !(defined(__cplusplus) && (__cplusplus > 201703L))
#endif // BOOTLOADER_BUILD
#endif // !NON_OS_BUILD

/** runtime macro to output logs at a specified level.
*
Expand Down
4 changes: 2 additions & 2 deletions components/log/include/esp_log_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
extern "C" {
#endif

#if !BOOTLOADER_BUILD || __DOXYGEN__
#if !NON_OS_BUILD || __DOXYGEN__

/**
* @brief Logs a buffer of hexadecimal bytes at the specified log level.
Expand Down Expand Up @@ -173,7 +173,7 @@ static inline void esp_log_buffer_char(const char *tag, const void *buffer, uint
}
/** @endcond */

#endif // !BOOTLOADER_BUILD || __DOXYGEN__
#endif // !NON_OS_BUILD || __DOXYGEN__

#ifdef __cplusplus
}
Expand Down
6 changes: 3 additions & 3 deletions components/log/include/esp_log_level.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ typedef enum {
#endif // !BOOTLOADER_BUILD
#endif // LOG_LOCAL_LEVEL

#if BOOTLOADER_BUILD
#ifdef NON_OS_BUILD

#define _ESP_LOG_ENABLED(log_level) (LOG_LOCAL_LEVEL >= (log_level))
#define _ESP_LOG_EARLY_ENABLED(log_level) _ESP_LOG_ENABLED(log_level)

#else // !BOOTLOADER_BUILD
#else // !NON_OS_BUILD

#if CONFIG_LOG_MASTER_LEVEL
#define _ESP_LOG_ENABLED(log_level) (esp_log_get_level_master() >= (log_level) && LOG_LOCAL_LEVEL >= (log_level))
Expand All @@ -54,7 +54,7 @@ typedef enum {
currently configured min log level are higher than the log level */
#define _ESP_LOG_EARLY_ENABLED(log_level) (LOG_LOCAL_LEVEL >= (log_level) && esp_log_get_default_level() >= (log_level))

#endif // !BOOTLOADER_BUILD
#endif // !NON_OS_BUILD

/** @endcond */

Expand Down
4 changes: 2 additions & 2 deletions components/log/src/log_timestamp_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "esp_private/log_timestamp.h"
#include "sdkconfig.h"

#if !BOOTLOADER_BUILD
#ifndef NON_OS_BUILD
#include <sys/lock.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
Expand Down Expand Up @@ -60,7 +60,7 @@ char *esp_log_system_timestamp(void)
}
return buffer;
}
#endif // !BOOTLOADER_BUILD
#endif // !NON_OS_BUILD

uint64_t esp_log_timestamp64(bool critical)
{
Expand Down
3 changes: 2 additions & 1 deletion components/newlib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
idf_build_get_property(target IDF_TARGET)
idf_build_get_property(non_os_build NON_OS_BUILD)

if(${target} STREQUAL "linux")
return() # This component is not supported by the POSIX/Linux simulator
endif()

set(include_dirs "platform_include")

if(BOOTLOADER_BUILD)
if(non_os_build)
# Bootloader builds need the platform_include directory (for assert.h), but nothing else
idf_component_register(INCLUDE_DIRS platform_include)
return()
Expand Down
4 changes: 3 additions & 1 deletion components/partition_table/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
idf_build_get_property(target IDF_TARGET)
idf_build_get_property(non_os_build NON_OS_BUILD)

set(priv_req)
if(NOT ${target} STREQUAL "linux")
list(APPEND priv_req esptool_py)
endif()

idf_component_register(PRIV_REQUIRES ${priv_req})

if(BOOTLOADER_BUILD)
if(non_os_build)
return()
endif()

Expand Down
3 changes: 2 additions & 1 deletion components/partition_table/project_include.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ set(PARTITION_TABLE_CHECK_SIZES_TOOL_PATH "${CMAKE_CURRENT_LIST_DIR}/check_sizes

idf_build_get_property(build_dir BUILD_DIR)
idf_build_set_property(PARTITION_TABLE_BIN_PATH "${build_dir}/partition_table/partition-table.bin")
idf_build_get_property(non_os_build NON_OS_BUILD)

if(NOT BOOTLOADER_BUILD)
if(NOT non_os_build)
# Set PARTITION_CSV_PATH to the configured partition CSV file
# absolute path
if(CONFIG_PARTITION_TABLE_CUSTOM)
Expand Down
6 changes: 4 additions & 2 deletions components/spi_flash/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
idf_build_get_property(target IDF_TARGET)
idf_build_get_property(non_os_build NON_OS_BUILD)

if(${target} STREQUAL "linux")
idf_component_register(SRCS "linux/spi_flash_linux.c"
"linux/cache_utils.c"
Expand All @@ -8,7 +10,7 @@ if(${target} STREQUAL "linux")
return()
endif()

if(BOOTLOADER_BUILD OR CONFIG_APP_BUILD_TYPE_PURE_RAM_APP)
if(non_os_build OR CONFIG_APP_BUILD_TYPE_PURE_RAM_APP)
set(srcs "spi_flash_wrap.c")
set(priv_requires bootloader_support soc)
else()
Expand Down Expand Up @@ -70,7 +72,7 @@ if(CMAKE_C_COMPILER_ID MATCHES "GNU")
" -fno-inline-small-functions -fno-inline-functions-called-once")
endif()

if(NOT BOOTLOADER_BUILD AND NOT CONFIG_APP_BUILD_TYPE_PURE_RAM_APP)
if(NOT non_os_build AND NOT CONFIG_APP_BUILD_TYPE_PURE_RAM_APP)
if(CONFIG_SPIRAM)
# [refactor-todo]: requires "esp_psram" for few MMU usages in `flash_mmap.c`
# will be replaced with MMU requirements
Expand Down
1 change: 1 addition & 0 deletions tools/cmake/build.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ macro(idf_build_process target)
cmake_parse_arguments(_ "${options}" "${single_value}" "${multi_value}" ${ARGN})

idf_build_set_property(BOOTLOADER_BUILD "${BOOTLOADER_BUILD}")
idf_build_set_property(NON_OS_BUILD "${NON_OS_BUILD}")

idf_build_set_property(IDF_TOOLCHAIN "${IDF_TOOLCHAIN}")

Expand Down

0 comments on commit 6f466df

Please sign in to comment.