将simple_ota_example移植到smart_config下,工程逻辑及源码如下:
void app_main(void)
{
ESP_ERROR_CHECK( nvs_flash_init() );
bsp_InitKey();
bsp_app_timer();
bsp_app_config_wifi();
app_ota_func();
while (1)
{
app_key_func();
}
}
void bsp_app_config_wifi(void)
{
ESP_ERROR_CHECK(esp_netif_init());
s_wifi_event_group = xEventGroupCreate();
ESP_ERROR_CHECK(esp_event_loop_create_default());
esp_netif_t *sta_netif = esp_netif_create_default_wifi_sta();
assert(sta_netif);
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
ESP_ERROR_CHECK( esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL) );
ESP_ERROR_CHECK( esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL) );
ESP_ERROR_CHECK( esp_event_handler_register(SC_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL) );
ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
ESP_ERROR_CHECK( esp_wifi_start() );
}
void app_ota_func(void)
{
get_sha256_of_partitions();
// esp_wifi_set_ps(WIFI_PS_NONE);
xTaskCreate(simple_ota_example_task, "ota_example_task", 8192, NULL, 5, NULL);
}
void simple_ota_example_task(void *pvParameter)
{
ESP_LOGI(TAG, "Starting OTA example task");
#ifdef CONFIG_EXAMPLE_FIRMWARE_UPGRADE_BIND_IF
esp_netif_t *netif = get_example_netif_from_desc(bind_interface_name);
if (netif == NULL) {
ESP_LOGE(TAG, "Can't find netif from interface description");
abort();
}
struct ifreq ifr;
esp_netif_get_netif_impl_name(netif, ifr.ifr_name);
ESP_LOGI(TAG, "Bind interface name is %s", ifr.ifr_name);
#endif
esp_http_client_config_t config = {
.url = CONFIG_EXAMPLE_FIRMWARE_UPGRADE_URL,
#ifdef CONFIG_EXAMPLE_USE_CERT_BUNDLE
.crt_bundle_attach = esp_crt_bundle_attach,
#else
.cert_pem = (char *)server_cert_pem_start,
#endif /* CONFIG_EXAMPLE_USE_CERT_BUNDLE */
.event_handler = _http_event_handler,
.keep_alive_enable = true,
#ifdef CONFIG_EXAMPLE_FIRMWARE_UPGRADE_BIND_IF
.if_name = &ifr,
#endif
};
#ifdef CONFIG_EXAMPLE_FIRMWARE_UPGRADE_URL_FROM_STDIN
char url_buf[OTA_URL_SIZE];
if (strcmp(config.url, "FROM_STDIN") == 0) {
example_configure_stdin_stdout();
fgets(url_buf, OTA_URL_SIZE, stdin);
int len = strlen(url_buf);
url_buf[len - 1] = '\0';
config.url = url_buf;
} else {
ESP_LOGE(TAG, "Configuration mismatch: wrong firmware upgrade image url");
abort();
}
#endif
#ifdef CONFIG_EXAMPLE_SKIP_COMMON_NAME_CHECK
config.skip_cert_common_name_check = true;
#endif
esp_https_ota_config_t ota_config = {
.http_config = &config,
};
ESP_LOGI(TAG, "Attempting to download update from %s", config.url);
esp_err_t ret = esp_https_ota(&ota_config);
if (ret == ESP_OK) {
ESP_LOGI(TAG, "OTA Succeed, Rebooting...");
esp_restart();
} else {
ESP_LOGE(TAG, "Firmware upgrade failed");
}
while (1) {
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
编译工程提示报错如下:
D:\esp_demo\app_smartconfig_wifi\smart_config>idf.py build
Executing action: all (aliases: build)
Running ninja in directory D:\esp_demo\app_smartconfig_wifi\smart_config\build
Executing "ninja all"...
[1/1] cmd.exe /C "cd /D D:\esp_demo\app_smartconfig_wifi\s...tconfig_wifi/smart_config/build/bootloader/bootloader.bin"Bootloader binary size 0x6710 bytes. 0x8f0 bytes (8%) free.
[2/4] Linking CXX executable smart_config.elfFAILED: smart_config.elf
cmd.exe /C "cd . && D:\Espressif\tools\xtensa-esp32-elf\esp-2022r1-11.2.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-g++.exe -mlongcalls -Wno-frame-address @CMakeFiles\smart_config.elf.rsp -o smart_config.elf && cd ."
d:/espressif/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(bsp_ota.c.obj):(.literal.simple_ota_example_task+0xc): undefined reference to `_binary_ca_cert_pem_start'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
ninja failed with exit code 1, output of the command is in the D:\esp_demo\app_smartconfig_wifi\smart_config\build\log\idf_py_stderr_output_7164 and D:\esp_demo\app_smartconfig_wifi\smart_config\build\log\idf_py_stdout_output_7164
D:\esp_demo\app_smartconfig_wifi\smart_config>idf.py build
Executing action: all (aliases: build)
Running ninja in directory D:\esp_demo\app_smartconfig_wifi\smart_config\build
Executing "ninja all"...
[1/1] cmd.exe /C "cd /D D:\esp_demo\app_smartconfig_wifi\s...tconfig_wifi/smart_config/build/bootloader/bootloader.bin"Bootloader binary size 0x6710 bytes. 0x8f0 bytes (8%) free.
[2/7] Building C object esp-idf/main/CMakeFiles/__idf_main.dir/main.c.objIn file included from D:/esp_demo/app_smartconfig_wifi/smart_config/main/bsp/inc/bsp_timer.h:9,
from D:/esp_demo/app_smartconfig_wifi/smart_config/main/main.c:4:
D:/Espressif/frameworks/esp-idf-v5.0.2/components/driver/deprecated/driver/timer.h:16:2: warning: #warning "legacy timer group driver is deprecated, please migrate to driver/gptimer.h" [-Wcpp]
16 | #warning "legacy timer group driver is deprecated, please migrate to driver/gptimer.h"
| ^~~~~~~
[5/7] Linking CXX executable smart_config.elfFAILED: smart_config.elf
cmd.exe /C "cd . && D:\Espressif\tools\xtensa-esp32-elf\esp-2022r1-11.2.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-g++.exe -mlongcalls -Wno-frame-address @CMakeFiles\smart_config.elf.rsp -o smart_config.elf && cd ."
d:/espressif/tools/xtensa-esp32-elf/esp-2022r1-11.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/11.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(bsp_ota.c.obj):(.literal.simple_ota_example_task+0xc): undefined reference to `_binary_ca_cert_pem_start'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
ninja failed with exit code 1, output of the command is in the D:\esp_demo\app_smartconfig_wifi\smart_config\build\log\idf_py_stderr_output_15380 and D:\esp_demo\app_smartconfig_wifi\smart_config\build\log\idf_py_stdout_output_15380
D:\esp_demo\app_smartconfig_wifi\smart_config>
请问下该从哪个方面排查比较好,或者有什么建议吗?
【已解决】将simple_ota_example移植到smart_config下,编译提示会报错
【已解决】将simple_ota_example移植到smart_config下,编译提示会报错
Last edited by chenARM on Wed Jul 12, 2023 3:24 am, edited 2 times in total.
-
- Posts: 786
- Joined: Wed Nov 14, 2018 8:45 am
Re: 将simple_ota_example移植到smart_config下,编译提示会报错
移植不完全。
错误原因: undefined reference to `_binary_ca_cert_pem_start',你需要再看下 simple_ota_example,示例里还有个目录 server_certs,你需要把证书嵌入进来,然后再看下 main/CMakeLists.txt。
或者配置中把 CONFIG_EXAMPLE_USE_CERT_BUNDLE 打开。
错误原因: undefined reference to `_binary_ca_cert_pem_start',你需要再看下 simple_ota_example,示例里还有个目录 server_certs,你需要把证书嵌入进来,然后再看下 main/CMakeLists.txt。
或者配置中把 CONFIG_EXAMPLE_USE_CERT_BUNDLE 打开。
Re: 将simple_ota_example移植到smart_config下,编译提示会报错
好的,我这边验证可以,感谢。
Who is online
Users browsing this forum: No registered users and 63 guests