Skip to content

Problem with FileSystem image (littlefs,bin) upload #8840

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
williamesp2015 opened this issue Feb 1, 2023 · 1 comment
Open

Problem with FileSystem image (littlefs,bin) upload #8840

williamesp2015 opened this issue Feb 1, 2023 · 1 comment

Comments

@williamesp2015
Copy link

williamesp2015 commented Feb 1, 2023

Platform

  • Hardware: [ESP-12|

  • Core Version: [latest git hash or date]

  • Development Env: Arduino

  • Operating System: Windows

  • Module: Generic ESP8266 Module

  • Flash Size: 4MB

Problem Description

I have problew with ESP8266 (ESP12) when I try to upload littlefs.bin to the ESP8266 (Littlefs) not spiffs) by my HTTPUpload. Always I get updateError, But I have no problewm with ESP32 using SPIFFS.

void update_file() {
  //https://github.com/dx4m/Xbox-EEPROM-Utility/blob/master/xbox_eeprom_utility/xbox_eeprom_utility.ino
    HTTPUpload &upload = server.upload();
  if (upload.status == UPLOAD_FILE_START) {
    String updatefile = upload.filename;
    Serial.println("Update started:");
    if (updatefile.endsWith("littlefs.bin")) {
#ifdef ESP32
      if (!Update.begin(UPDATE_SIZE_UNKNOWN, U_SPIFFS)) {
        Serial.println("error");
        updateError = true;
      }
#else
      String fsBlockSizeStr = String((int)&_FS_block);
      if(updatefile.indexOf(fsBlockSizeStr) < 0){
        Serial.printf("Update Error! Please download and install xeu.%s.littlefs.bin\n", fsBlockSizeStr.c_str());
        updateError = true;
        return;
      }
      size_t fsSize = ((size_t) &_FS_end - (size_t) &_FS_start);
      close_all_fs();
      if (!Update.begin(fsSize, U_FS)) {
        Serial.println("error");
        updateError = true;
      }
#endif
    }
    else {
#ifdef ESP32
      if(updatefile.endsWith("esp32.bin")){
        Serial.printf("Trying to flash %s\n", updatefile.c_str());
      }
      else{
        Serial.println(F("Error. Please flash any firmware. Make sure you use the right one."));
        updateError = true;
        return;
      }
#else
      if((updatefile.endsWith("firmware.bin")) || (updatefile.endsWith("1M.bin")) || (updatefile.endsWith("2M.bin")) || (updatefile.endsWith("4M.bin")) || (updatefile.endsWith("8M.bin"))){
        Serial.printf("Trying to flash %s\n", updatefile.c_str());
      }
      else{
        Serial.println(F("Error. Please flash any firmware.bin to xeu.board.8M.bin. Make sure you use the right one."));
        Serial.println(F("When you don't know which one, flash any 1M binary."));
        updateError = true;
        return;
      }
#endif
      unsigned int maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
      if (!Update.begin(maxSketchSpace, U_FLASH)) {
        Serial.println("error");
        updateError = true;
      }
    }
  }
  else if (upload.status == UPLOAD_FILE_WRITE && updateError == false) {
    if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) {
      Serial.println("upload error");
      updateError = true;
    }
    else {
      Serial.print(".");
    }
  }
  else if (upload.status = UPLOAD_FILE_END) {
    if (Update.end(true)) {
      Serial.println(" Flashing successfully");
      Serial.println("Rebooting now");
      delay(500);
#ifdef ESP32
      ESP.restart();
#else
      ESP.reset();
#endif
    }
  }
 }
@williamesp2015
Copy link
Author

williamesp2015 commented Feb 1, 2023

SOLVED BY THIS:

void update_file() {
  //https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer-impl.h
   //if (upload.name == "filesystem") 
   HTTPUpload &upload = server.upload();
if (upload.status == UPLOAD_FILE_START) {
String updatefile = upload.filename;
Serial.println("Update started:");
   if(updatefile.endsWith("littlefs.bin")){
          size_t fsSize = ((size_t)FS_end - (size_t)FS_start);
          close_all_fs();
          if (!Update.begin(fsSize, U_FS)){//start with max available size
           // if (_serial_output) Update.printError(Serial);
           Serial.println("error0");
            updateError = true;
          }
        } else {
          uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
          if (!Update.begin(maxSketchSpace, U_FLASH)){//start with max available size
           // _setUpdaterError();
           Serial.println("error");
            updateError = true;
          }
        }
      } else if(upload.status == UPLOAD_FILE_WRITE ) {//if(_authenticated && upload.status == UPLOAD_FILE_WRITE && !_updaterError.length()){
        
       // if (_serial_output) Serial.printf(".");
        if(Update.write(upload.buf, upload.currentSize) != upload.currentSize){
        //  _setUpdaterError();
        Serial.println("upload error2");
        updateError = true;
        }
      } else if (upload.status == UPLOAD_FILE_END)//if(_authenticated && upload.status == UPLOAD_FILE_END && !_updaterError.length()){
        {
        if(Update.end(true)){ //true to set the size to the current progress
          //if (_serial_output) Serial.printf("Update Success: %zu\nRebooting...\n", upload.totalSize);
           Serial.printf("Update Success: %zu\nRebooting...\n", upload.totalSize);
        } else {
         // _setUpdaterError();
         Serial.println("upload error3");
          updateError = true;
        }
        //if (_serial_output) Serial.setDebugOutput(false);
      } else if(upload.status == UPLOAD_FILE_ABORTED){//(_authenticated && upload.status == UPLOAD_FILE_ABORTED){
        Update.end();
        Serial.println("Update was aborted");
        //if (_serial_output) Serial.println("Update was aborted");
      }
      esp_yield();
 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant