From 339454ff19f5fd04f8c72de1818bd98d08764459 Mon Sep 17 00:00:00 2001 From: Omar Chebib Date: Wed, 11 Aug 2021 14:59:16 +0800 Subject: [PATCH] bootloader: Kconfig files in bootloader_components is now part of menuconfig It is now possible to configure the options (Kconfig) of bootloader components directly from the menuconfig --- .../bootloader_components/main/Kconfig | 8 +++++ .../main/bootloader_start.c | 3 +- .../bootloader_override/example_test.py | 5 +++- tools/cmake/kconfig.cmake | 29 +++++++++++++++++++ tools/cmake/project.cmake | 14 +++++++++ 5 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 examples/custom_bootloader/bootloader_override/bootloader_components/main/Kconfig diff --git a/examples/custom_bootloader/bootloader_override/bootloader_components/main/Kconfig b/examples/custom_bootloader/bootloader_override/bootloader_components/main/Kconfig new file mode 100644 index 0000000000..5d46d31c01 --- /dev/null +++ b/examples/custom_bootloader/bootloader_override/bootloader_components/main/Kconfig @@ -0,0 +1,8 @@ +menu "Bootloader welcome message" + + config EXAMPLE_BOOTLOADER_WELCOME_MESSAGE + string "Bootloader welcome message" + default "Custom bootloader message defined in the KConfig file." + help + Message to print by the custom bootloader when booting up. +endmenu diff --git a/examples/custom_bootloader/bootloader_override/bootloader_components/main/bootloader_start.c b/examples/custom_bootloader/bootloader_override/bootloader_components/main/bootloader_start.c index b1762d5160..74d97a14f6 100644 --- a/examples/custom_bootloader/bootloader_override/bootloader_components/main/bootloader_start.c +++ b/examples/custom_bootloader/bootloader_override/bootloader_components/main/bootloader_start.c @@ -4,6 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ #include +#include "sdkconfig.h" #include "esp_log.h" #include "bootloader_init.h" #include "bootloader_utility.h" @@ -41,7 +42,7 @@ void __attribute__((noreturn)) call_start_cpu0(void) } // 2.1 Print a custom message! - esp_rom_printf("[%s] Custom bootloader has been initialized correctly.\n", TAG); + esp_rom_printf("[%s] %s\n", TAG, CONFIG_EXAMPLE_BOOTLOADER_WELCOME_MESSAGE); // 3. Load the app image for booting bootloader_utility_load_boot_image(&bs, boot_index); diff --git a/examples/custom_bootloader/bootloader_override/example_test.py b/examples/custom_bootloader/bootloader_override/example_test.py index 78462c2bff..104a828498 100644 --- a/examples/custom_bootloader/bootloader_override/example_test.py +++ b/examples/custom_bootloader/bootloader_override/example_test.py @@ -10,7 +10,10 @@ def test_custom_bootloader_impl_example(env, _): # type: ignore dut.start_app() # Expect to read a message from the custom bootloader - dut.expect('Custom bootloader has been initialized correctly.') + # This message is defined in the Kconfig file, retrieve it while deleting + # leading and trailing quotes (") + welcome_message = dut.app.get_sdkconfig()['CONFIG_EXAMPLE_BOOTLOADER_WELCOME_MESSAGE'].strip("\"") + dut.expect(welcome_message) # Expect to read a message from the user application dut.expect('Application started!') diff --git a/tools/cmake/kconfig.cmake b/tools/cmake/kconfig.cmake index 91dcfb3171..30cec00829 100644 --- a/tools/cmake/kconfig.cmake +++ b/tools/cmake/kconfig.cmake @@ -112,6 +112,29 @@ function(__kconfig_component_init component_target) __component_set_property(${component_target} SDKCONFIG_RENAME "${sdkconfig_rename}") endfunction() +# +# Add bootloader components Kconfig and Kconfig.projbuild files to BOOTLOADER_KCONFIG +# and BOOTLOADER_KCONFIGS_PROJ properties respectively. +# +function(__kconfig_bootloader_component_add component_dir) + idf_build_get_property(bootloader_kconfigs BOOTLOADER_KCONFIGS) + idf_build_get_property(bootloader_kconfigs_proj BOOTLOADER_KCONFIGS_PROJ) + + file(GLOB kconfig "${component_dir}/Kconfig") + if(EXISTS "${kconfig}" AND NOT IS_DIRECTORY "${kconfig}") + list(APPEND bootloader_kconfigs "${kconfig}") + endif() + + file(GLOB kconfig "${component_dir}/Kconfig.projbuild") + if(EXISTS "${kconfig}" AND NOT IS_DIRECTORY "${kconfig}") + list(APPEND bootloader_kconfigs_proj "${kconfig}") + endif() + + idf_build_set_property(BOOTLOADER_KCONFIGS "${bootloader_kconfigs}") + idf_build_set_property(BOOTLOADER_KCONFIGS_PROJ "${bootloader_kconfigs_proj}") +endfunction() + + # # Generate the config files and create config related targets and configure # dependencies. @@ -137,6 +160,12 @@ function(__kconfig_generate_config sdkconfig sdkconfig_defaults) endif() endforeach() + # Take into account bootloader components configuration files + idf_build_get_property(bootloader_kconfigs BOOTLOADER_KCONFIGS) + idf_build_get_property(bootloader_kconfigs_proj BOOTLOADER_KCONFIGS_PROJ) + list(APPEND kconfigs "${bootloader_kconfigs}") + list(APPEND kconfig_projbuilds "${bootloader_kconfigs_proj}") + # Store the list version of kconfigs and kconfig_projbuilds idf_build_set_property(KCONFIGS "${kconfigs}") idf_build_set_property(KCONFIG_PROJBUILDS "${kconfig_projbuilds}") diff --git a/tools/cmake/project.cmake b/tools/cmake/project.cmake index c88a3eca13..11b6f45c30 100644 --- a/tools/cmake/project.cmake +++ b/tools/cmake/project.cmake @@ -197,6 +197,20 @@ function(__project_init components_var test_components_var) __project_component_dir("${CMAKE_CURRENT_LIST_DIR}/components") endif() + # For bootloader components, we only need to set-up the Kconfig files. + # Indeed, bootloader is currently compiled as a subproject, thus, + # its components are not part of the main project. + # However, in order to be able to configure these bootloader components + # using menuconfig, we need to look for their Kconfig-related files now. + file(GLOB bootloader_component_dirs "${CMAKE_CURRENT_LIST_DIR}/bootloader_components/*") + list(SORT bootloader_component_dirs) + foreach(bootloader_component_dir ${bootloader_component_dirs}) + __component_dir_quick_check(is_component ${bootloader_component_dir}) + if(is_component) + __kconfig_bootloader_component_add("${bootloader_component_dir}") + endif() + endforeach() + spaces2list(COMPONENTS) spaces2list(EXCLUDE_COMPONENTS) idf_build_get_property(component_targets __COMPONENT_TARGETS)