Skip to content

IDF (Arduino) OTA problem #5929

Closed
Closed
@marcelwinter04

Description

@marcelwinter04

I'm trying to get the OTA SD Card example working. This thing worked with the Arduino IDE unfortunately there is no option to change the menuconfig with the arduino ide. So now im trying the same example with the esp idf but with the arduino component.

#include <FS.h>
#include <SD_MMC.h>
#include <Update.h>

void rebootEspWithReason(String reason){
    Serial.println(reason);
    delay(1000);
    ESP.restart();
}

void performUpdate(Stream &updateSource, size_t updateSize) {
   if (Update.begin(updateSize)) {      
      size_t written = Update.writeStream(updateSource);
      if (written == updateSize) {
         Serial.println("Written : " + String(written) + " successfully");
      }
      else {
         Serial.println("Written only : " + String(written) + "/" + String(updateSize) + ". Retry?");
      }
      if (Update.end()) {
         Serial.println("OTA done!");
         if (Update.isFinished()) {
            Serial.println(Update.hasError());
            Serial.println(Update.isRunning());
            Serial.println(Update.rollBack());
            rebootEspWithReason("Update successfully completed. Rebooting.");
         }  
         else {
            Serial.println("Update not finished? Something went wrong!");
         }
      }
      else {
         Serial.println("Error Occurred. Error #: " + String(Update.getError()));
      }

   }
   else
   {
      Serial.println("Not enough space to begin OTA");
   }
}

void updateFromFS(fs::FS &fs) {
   File updateBin = fs.open("/update.bin");
   if (updateBin) {
      if(updateBin.isDirectory()){
         Serial.println("Error, update.bin is not a file");
         updateBin.close();
         return;
      }

      size_t updateSize = updateBin.size();

      if (updateSize > 0) {
         Serial.println("Try to start update");
         performUpdate(updateBin, updateSize);
      }
      else {
         Serial.println("Error, file is empty");
      }

      updateBin.close();
    
      // whe finished remove the binary from sd card to indicate end of the process
     // fs.remove("/update.bin");      
   }
   else {
      Serial.println("Could not load update.bin from sd root");
   }
}

extern "C" void app_main()
{
    initArduino();
    pinMode(4, OUTPUT);
    digitalWrite(4, HIGH);
    
	Serial.begin(115200);
	
    if(!SD_MMC.begin()){
        Serial.println("Card Mount Failed");
        return;
    }
    uint8_t cardType = SD_MMC.cardType();

    if(cardType == CARD_NONE){
        Serial.println("No SD_MMC card attached");
        return;
    }

    Serial.print("SD_MMC Card Type: ");
    if(cardType == CARD_MMC){
        Serial.println("MMC");
    } else if(cardType == CARD_SD){
        Serial.println("SDSC");
    } else if(cardType == CARD_SDHC){
        Serial.println("SDHC");
    } else {
        Serial.println("UNKNOWN");
    }

    uint64_t cardSize = SD_MMC.cardSize() / (1024 * 1024);
    Serial.printf("SD_MMC Card Size: %lluMB\n", cardSize);

    updateFromFS(SD_MMC);

    while (1) {
        vTaskDelay(1);
    }
}

But when i build this project i get following error message

FAILED: blink.elf
cmd.exe /C "cd . && C:\Users\MW\Documents\.espressif\tools\xtensa-esp32-elf\esp-2021r2-8.4.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-g++.exe -mlongcalls -Wno-frame-address  @CMakeFiles\blink.elf.rsp -o blink.elf  && cd ."
c:/users/mw/documents/.espressif/tools/xtensa-esp32-elf/esp-2021r2-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/arduino/libarduino.a(MD5Builder.cpp.obj):(.literal._ZN10MD5Builder5beginEv+0x0): undefined reference to `MD5Init'
c:/users/mw/documents/.espressif/tools/xtensa-esp32-elf/esp-2021r2-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/arduino/libarduino.a(MD5Builder.cpp.obj):(.literal._ZN10MD5Builder3addEPht+0x0): undefined reference to `MD5Update'
c:/users/mw/documents/.espressif/tools/xtensa-esp32-elf/esp-2021r2-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/arduino/libarduino.a(MD5Builder.cpp.obj):(.literal._ZN10MD5Builder9calculateEv+0x0): undefined reference to `MD5Final'
c:/users/mw/documents/.espressif/tools/xtensa-esp32-elf/esp-2021r2-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/arduino/libarduino.a(MD5Builder.cpp.obj): in function `MD5Builder::begin()':
c:\users\mw\documents\projects\blink\build/../components/arduino/cores/esp32/MD5Builder.cpp:32: undefined reference to `MD5Init'
c:/users/mw/documents/.espressif/tools/xtensa-esp32-elf/esp-2021r2-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/arduino/libarduino.a(MD5Builder.cpp.obj): in function `MD5Builder::add(unsigned char*, unsigned short)':
c:\users\mw\documents\projects\blink\build/../components/arduino/cores/esp32/MD5Builder.cpp:37: undefined reference to `MD5Update'
c:/users/mw/documents/.espressif/tools/xtensa-esp32-elf/esp-2021r2-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/arduino/libarduino.a(MD5Builder.cpp.obj): in function `MD5Builder::calculate()':
c:\users\mw\documents\projects\blink\build/../components/arduino/cores/esp32/MD5Builder.cpp:97: undefined reference to `MD5Final'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
ninja failed with exit code 1

Does anybody knows what the problem may be?

ESP-IDF: 4.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions