undefined reference to `flash_binary' (ESP Serial Flasher using ESP-IDF)

VincentChan
Posts: 4
Joined: Sun Sep 18, 2022 5:54 am

undefined reference to `flash_binary' (ESP Serial Flasher using ESP-IDF)

Postby VincentChan » Tue Oct 24, 2023 3:25 am

Code: Select all

#include <sys/param.h>
#include <string.h>
#include "esp_err.h"
#include "esp_log.h"
#include "driver/uart.h"
#include "driver/gpio.h"
#include "esp32_port.h"
#include "esp_loader.h"
#include "esp_loader_io.h"
#include <common/example_common.h>
#include "esp_flash.h"

static const char *TAG = "serial_flasher";
#define HIGHER_BAUDRATE 230400

void app_main() 
{
    example_binaries_t bin;
    const loader_esp32_config_t config = {
        .baud_rate = 115200,
        .uart_port = UART_NUM_1,
        .uart_rx_pin = GPIO_NUM_16,
        .uart_tx_pin = GPIO_NUM_17,
        .reset_trigger_pin = GPIO_NUM_8,
        .gpio0_trigger_pin = GPIO_NUM_20,
    };
    if (loader_port_esp32_init(&config) != ESP_LOADER_SUCCESS){ESP_LOGE(TAG, "Serial Initialization Failed.");return;}
    if (connect_to_target(HIGHER_BAUDRATE) == ESP_LOADER_SUCCESS)
    {
        get_example_binaries(esp_loader_get_target(), &bin);        
        ESP_LOGI(TAG, "Loading Bootloader......");        flash_binary(bin.boot.data, bin.boot.size, bin.boot.addr);        
        ESP_LOGI(TAG, "Loading Partition Table");       flash_binary(bin.part.data, bin.part.size, bin.part.addr);
        ESP_LOGI(TAG, "Loading APP......");         flash_binary(bin.app.data, bin.app.size, bin.app.addr);
        ESP_LOGI(TAG, "Done SUCCESS !!!");
    }    
}
Hi all,
I build the code above using ESP-IDF, the IDE is VS code platformIO.
I faced a problem after building the code above based on the default ESP Serial Flasher from Espressif.
The error resulted from the build is as follow:

c:/users/user/.platformio/packages/toolchain-xtensa-esp32s3/bin/../lib/gcc/xtensa-esp32s3-elf/12.2.0/../../../../xtensa-esp32s3-elf/bin/ld.exe: .pio/build/esp32-s3-devkitc-1-n16r8v/src/main.o:(.literal.app_main+0x20): undefined reference to `flash_binary'

c:/users/user/.platformio/packages/toolchain-xtensa-esp32s3/bin/../lib/gcc/xtensa-esp32s3-elf/12.2.0/../../../../xtensa-esp32s3-elf/bin/ld.exe: .pio/build/esp32-s3-devkitc-1-n16r8v/src/main.o: in function `app_main':

C:\Data\Desktop\Vincent\Testing\usingESPIDF\bootloader_v1/src/main.c:38: undefined reference to `flash_binary'
collect2.exe: error: ld returned 1 exit status

*** [.pio\build\esp32-s3-devkitc-1-n16r8v\firmware.elf] Error 1

Any solutions for this? Thanks in advanced.

MicroController
Posts: 1706
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: undefined reference to `flash_binary' (ESP Serial Flasher using ESP-IDF)

Postby MicroController » Tue Oct 24, 2023 10:51 am

It seems the library's .c files are not compiled during the build.
How did you include the serial flasher library into your project?

VincentChan
Posts: 4
Joined: Sun Sep 18, 2022 5:54 am

Re: undefined reference to `flash_binary' (ESP Serial Flasher using ESP-IDF)

Postby VincentChan » Thu Oct 26, 2023 1:21 am

Hi microcontroller,

I included those header files and some required c source files in the src folder, the flow is as follow:
.pio
.vscode
include
- README
lib
- README
src
- binaries
- ESP32_AT_Firmware
- Firmware.bin
- Hello-world
- ESP32_S3
- bootloader.bin
- hello_world.bin
- partition-table.bin
- RAM_APP
- ESP32_S3
- app.bin
- common
- bin2array.cmake
- example_common.c
- example_common.h
- CMakeList.txt
- esp_loader.c
- esp_loader.h
- esp_loader_io.h
- esp_targets.c
- esp_targets.h
- esp32_port.c
- esp32_port.h
- main.c
- md5_hash.c
- md5_hash.h
- protocol.h
- protocol_common.c
- protocol_prv.h
- protocol_uart.c
- slip.c
- slip.h
test
- README
.gitignore
CMakeLists.txt
dependencies.lock
partitions.csv
platformio.ini
sdkconfig.esp32-s3-devkitc-1-n16r8v

MicroController
Posts: 1706
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: undefined reference to `flash_binary' (ESP Serial Flasher using ESP-IDF)

Postby MicroController » Fri Oct 27, 2023 10:32 pm

In that case make sure the .c files are also listed as SRCS, together with "main.c", in the CMakeLists.txt file.

Who is online

Users browsing this forum: No registered users and 133 guests