- idf_component_register(SRCS "bootloader_start.c"
- INCLUDE_DIRS "."
- REQUIRES bootloader bootloader_support nvs_flash esp_wifi freertos esp_system protocol_examples_common)
- idf_build_get_property(target IDF_TARGET)
- # Use the linker script files from the actual bootloader
- set(scripts "${IDF_PATH}/components/bootloader/subproject/main/ld/${target}/bootloader.ld"
- "${IDF_PATH}/components/bootloader/subproject/main/ld/${target}/bootloader.rom.ld")
- target_linker_script(${COMPONENT_LIB} INTERFACE "${scripts}")
I would like to write custom bootloader code to perform an OTA firmware upgrade over wifi in the second bootloader step. My code to initialize wifi during the bootloader stage was unsuccessful due to several issues. The cause for my error was found
here: https://esp32.com/viewtopic.php?t=27605 .
So, at the second stage bootloader, how can I upgrade the firmware over the air using wifi?
Could someone help explain the proper procedure to me?
bootloader_start.c code:
- #include <stdbool.h>
- #include "sdkconfig.h"
- #include "esp_log.h"
- #include "bootloader_init.h"
- #include "bootloader_utility.h"
- #include "bootloader_common.h"
- #include "esp_wifi.h"
- #include "esp_event.h"
- #include "esp_log.h"
- #include "nvs_flash.h"
- #include "esp_netif.h"
- #include "protocol_examples_common.h"
- static const char* TAG = "boot";
- static int select_partition_number(bootloader_state_t *bs);
- void __attribute__((noreturn)) call_start_cpu0(void)
- {
- // 1. Hardware initialization
- if (bootloader_init() != ESP_OK) {
- bootloader_reset();
- }
- #ifdef CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP
- bootloader_utility_load_boot_image_from_deep_sleep();
- #endif
- //Wi-Fi Initialization
- nvs_flash_init();
- esp_netif_init();
- esp_event_loop_create_default();
- example_connect();
- // 2. Select the number of boot partition
- bootloader_state_t bs = {0};
- select_partition_number(&bs);
- int boot_index = FACTORY_INDEX;
- // Print boot index
- ESP_LOGI(TAG, "Boot Index: %d", boot_index);
- if (boot_index == INVALID_INDEX) {
- bootloader_reset();
- }
- // 2.1 Print a custom message!
- 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);
- }
- // Select the number of boot partition
- static int select_partition_number(bootloader_state_t *bs)
- {
- // 1. Load partition table
- if (!bootloader_utility_load_partition_table(bs)) {
- ESP_LOGE(TAG, "load partition table error!");
- return INVALID_INDEX;
- }
- // 2. Select the number of boot partition
- return bootloader_utility_get_selected_boot_partition(bs);
- }
- // Return global reent struct if any newlib functions are linked to bootloader
- struct _reent *__getreent(void)
- {
- return _GLOBAL_REENT;
- }
Executing action: all (aliases: build)
Running ninja in directory /home/suraj/trial/newf/bootloader_override/build
Executing "ninja all"...
[12/659] Performing build step for 'bootloader'
FAILED: bootloader-prefix/src/bootloader-stamp/bootloader-build bootloader/bootloader.elf bootloader/bootloader.bin bootloader/bootloader.map /home/suraj/trial/newf/bootloader_override/build/bootloader-prefix/src/bootloader-stamp/bootloader-build /home/suraj/trial/newf/bootloader_override/build/bootloader/bootloader.elf /home/suraj/trial/newf/bootloader_override/build/bootloader/bootloader.bin /home/suraj/trial/newf/bootloader_override/build/bootloader/bootloader.map
cd /home/suraj/trial/newf/bootloader_override/build/bootloader && /usr/bin/cmake --build .
[1/483] Building C object esp-idf/mbedtls/mbedtls/library/CMakeFiles/mbedcrypto.dir/camellia.c.obj
[2/483] Building C object esp-idf/mbedtls/mbedtls/library/CMakeFiles/mbedcrypto.dir/chachapoly.c.obj
[3/483] Building C object esp-idf/wpa_supplicant/CMakeFiles/__idf_wpa_supplicant.dir/src/crypto/crypto_mbedtls.c.obj
FAILED: esp-idf/wpa_supplicant/CMakeFiles/__idf_wpa_supplicant.dir/src/crypto/crypto_mbedtls.c.obj
/home/suraj/.espressif/tools/xtensa-esp32s3-elf/esp-2021r2-patch5-8.4.0/xtensa-esp32s3-elf/bin/xtensa-esp32s3-elf-gcc -DCONFIG_ECC -DCONFIG_IEEE80211W -DCONFIG_SHA256 -DCONFIG_WNM -DCONFIG_WPA3_SAE -DCONFIG_WPS2 -DCONFIG_WPS_PIN -DEAP_FAST -DEAP_MSCHAPv2 -DEAP_PEAP -DEAP_PEER_METHOD -DEAP_TLS -DEAP_TTLS -DESP32_WORKAROUND -DESPRESSIF_USE -DESP_SUPPLICANT -DIEEE8021X_EAPOL -DMBEDTLS_CONFIG_FILE=\"mbedtls/esp_config.h\" -DUSE_WPA2_TASK -DUSE_WPS_TASK -D__ets__ -I/home/suraj/trial/newf/bootloader_override/build/bootloader/config -I/home/suraj/esp/esp-idf/components/wpa_supplicant/include -I/home/suraj/esp/esp-idf/components/wpa_supplicant/port/include -I/home/suraj/esp/esp-idf/components/wpa_supplicant/esp_supplicant/include -I/home/suraj/esp/esp-idf/components/wpa_supplicant/src -I/home/suraj/esp/esp-idf/components/wpa_supplicant/src/utils -I/home/suraj/esp/esp-idf/components/wpa_supplicant/esp_supplicant/src -I/home/suraj/esp/esp-idf/components/log/include -I/home/suraj/esp/esp-idf/components/esp_rom/include -I/home/suraj/esp/esp-idf/components/esp_rom/include/esp32s3 -I/home/suraj/esp/esp-idf/components/esp_rom/esp32s3 -I/home/suraj/esp/esp-idf/components/esp_common/include -I/home/suraj/esp/esp-idf/components/esp_hw_support/include -I/home/suraj/esp/esp-idf/components/esp_hw_support/include/soc -I/home/suraj/esp/esp-idf/components/esp_hw_support/include/soc/esp32s3 -I/home/suraj/esp/esp-idf/components/esp_hw_support/port/esp32s3/. -I/home/suraj/esp/esp-idf/components/esp_hw_support/port/esp32s3/private_include -I/home/suraj/esp/esp-idf/components/hal/esp32s3/include -I/home/suraj/esp/esp-idf/components/hal/include -I/home/suraj/esp/esp-idf/components/hal/platform_port/include -I/home/suraj/esp/esp-idf/components/newlib/platform_include -I/home/suraj/esp/esp-idf/components/xtensa/include -I/home/suraj/esp/esp-idf/components/xtensa/esp32s3/include -I/home/suraj/esp/esp-idf/components/soc/include -I/home/suraj/esp/esp-idf/components/soc/esp32s3/. -I/home/suraj/esp/esp-idf/components/soc/esp32s3/include -I/home/suraj/esp/esp-idf/components/mbedtls/port/include -I/home/suraj/esp/esp-idf/components/mbedtls/mbedtls/include -I/home/suraj/esp/esp-idf/components/mbedtls/esp_crt_bundle/include -I/home/suraj/esp/esp-idf/components/lwip/include/apps -I/home/suraj/esp/esp-idf/components/lwip/include/apps/sntp -I/home/suraj/esp/esp-idf/components/lwip/lwip/src/include -I/home/suraj/esp/esp-idf/components/lwip/port/esp32/include -I/home/suraj/esp/esp-idf/components/lwip/port/esp32/include/arch -I/home/suraj/esp/esp-idf/components/vfs/include -I/home/suraj/esp/esp-idf/components/esp_wifi/include -I/home/suraj/esp/esp-idf/components/esp_event/include -I/home/suraj/esp/esp-idf/components/esp_netif/include -I/home/suraj/esp/esp-idf/components/esp_eth/include -I/home/suraj/esp/esp-idf/components/tcpip_adapter/include -I/home/suraj/esp/esp-idf/components/esp_phy/include -I/home/suraj/esp/esp-idf/components/esp_phy/esp32s3/include -I/home/suraj/esp/esp-idf/components/driver/include -I/home/suraj/esp/esp-idf/components/driver/esp32s3/include -I/home/suraj/esp/esp-idf/components/esp_pm/include -I/home/suraj/esp/esp-idf/components/esp_ringbuf/include -I/home/suraj/esp/esp-idf/components/esp_timer/include -mlongcalls -ffunction-sections -fdata-sections -Wall -Werror=all -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wextra -Wno-unused-parameter -Wno-sign-compare -ggdb -Os -freorder-blocks -fmacro-prefix-map=/home/suraj/esp/esp-idf/components/bootloader/subproject=. -fmacro-prefix-map=/home/suraj/esp/esp-idf=IDF -fstrict-volatile-bitfields -Wno-error=unused-but-set-variable -fno-jump-tables -fno-tree-switch-conversion -fno-stack-protector -std=gnu99 -Wno-old-style-declaration -D_GNU_SOURCE -DIDF_VER=\"v4.4.3-dirty\" -DESP_PLATFORM -DBOOTLOADER_BUILD=1 -Wno-strict-aliasing -Wno-write-strings -MD -MT esp-idf/wpa_supplicant/CMakeFiles/__idf_wpa_supplicant.dir/src/crypto/crypto_mbedtls.c.obj -MF esp-idf/wpa_supplicant/CMakeFiles/__idf_wpa_supplicant.dir/src/crypto/crypto_mbedtls.c.obj.d -o esp-idf/wpa_supplicant/CMakeFiles/__idf_wpa_supplicant.dir/src/crypto/crypto_mbedtls.c.obj -c /home/suraj/esp/esp-idf/components/wpa_supplicant/src/crypto/crypto_mbedtls.c
/home/suraj/esp/esp-idf/components/wpa_supplicant/src/crypto/crypto_mbedtls.c:8:10: fatal error: esp_system.h: No such file or directory
#include "esp_system.h"
^~~~~~~~~~~~~~
compilation terminated.
[4/483] Building C object esp-idf/mbedtls/mbedtls/library/CMakeFiles/mbedcrypto.dir/chacha20.c.obj
[5/483] Building C object esp-idf/mbedtls/mbedtls/library/CMakeFiles/mbedcrypto.dir/cmac.c.obj
[6/483] Building C object esp-idf/mbedtls/mbedtls/library/CMakeFiles/mbedcrypto.dir/des.c.obj
[7/483] Building C object esp-idf/mbedtls/mbedtls/library/CMakeFiles/mbedcrypto.dir/ccm.c.obj
[8/483] Building C object esp-idf/mbedtls/mbedtls/library/CMakeFiles/mbedcrypto.dir/cipher_wrap.c.obj
[9/483] Building C object esp-idf/mbedtls/mbedtls/library/CMakeFiles/mbedcrypto.dir/constant_time.c.obj
[10/483] Building C object esp-idf/mbedtls/mbedtls/library/CMakeFiles/mbedcrypto.dir/dhm.c.obj
[11/483] Building C object esp-idf/mbedtls/mbedtls/library/CMakeFiles/mbedcrypto.dir/ctr_drbg.c.obj
[12/483] Building C object esp-idf/mbedtls/mbedtls/library/CMakeFiles/mbedcrypto.dir/cipher.c.obj
ninja: build stopped: subcommand failed.
[21/659] Building C object esp-idf/lwip/CMakeFiles/__idf_lwip.dir/lwip/src/core/ipv4/dhcp.c.obj
ninja: build stopped: subcommand failed.
ninja failed with exit code 1