Skip to content
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

Any filesystem (SD/SPIFFS/LittleFS/SD_MMC) #92

Merged
merged 55 commits into from
Sep 16, 2022

Conversation

tobozo
Copy link
Collaborator

@tobozo tobozo commented Sep 9, 2022


Discuss this PR here


Followup for #25, #47, #60, #74, #79, #91

Because this PR creates many new logical situations and I have only tested a few, this should be considered as untested code.

Other changes mentioned in #25 are still being backported and tested.

Functional changes

With this PR:

  • SPIFFS is removed from the library core and replaced with an optional fs::FS filesystem abstraction.
  • JSON Manifest accepts new keys spiffs, littlefs, fatfs holding path to filesystem image
  • When one of the new keys is set in the manifest, execOTA will also flash the spiffs partition with the provided filesystem image (which can also be signed)

⚠️ ESP32FOTA should detect when #include <LittleFS> (on any other filesystem) is included from the sketch, and automatically use that filesystem to verify certificate signatures. If no filesystem is detected, firmware signature check will always fail!

// include filesystem first !

//#include <SD.h>
//#include <SD_MMC.h>
//#include <SPIFFS.h>
#include <LittleFS.h>
//#include <PSRamFS.h>
#include <esp32fota.h>

Sketches using more than one filesystem or compiled with older versions of platformio or may need this new method:

    esp32FOTA.setCertFileSystem( &LittleFS ); // works with &SD, &SD_MMC, &SPIFFS

Also a new set of helper objects were added to handle the crypto assets in mixed situations:

// pick pubkey/rootca from filesystem
CryptoFileAsset( const char* path, fs::FS* filesystem ); 
// pick pubkey/rootca from progmem
CryptoMemAsset( const char* name, const char* bytes, size_t len );

Crypto asset usage with progmem:

// could also be a byte array
const char* rsa_key_pub = R"RSA_KEY(
-----BEGIN PUBLIC KEY-----
BlahBlahBlah ... My RSA Key ... BlahBlahBlah
BlahBlahBlah ... My RSA Key ... BlahBlahBlah
BlahBlahBlah ... My RSA Key ... BlahBlahBlah
-----END PUBLIC KEY-----
)RSA_KEY";

CryptoMemAsset *MyRSAKey = new CryptoMemAsset("RSA Public Key", rsa_key_pub, strlen(rsa_key_pub)+1 );

void setup()
{
     // ...
    esp32FOTA.setPubKey( MyRSAKey );

}

Crypto asset usage with filesystem (can be different for each file):

CryptoAsset* MyRSAKey = new CryptoFileAsset( "/path/to/public.key", &LittleFS  );
CryptoAsset* MyRootCA = new CryptoFileAsset( "/path/to/root_ca", &SD  );

void setup()
{
    // ....
    esp32FOTA.setPubKey( MyRSAKey );
    esp32FOTA.setRootCA( MyRootCA );
}

Other changes in the PR

  • This directive was added to prevent the latest espressif package from complaining at compilation:
  #pragma GCC diagnostic ignored "-Wmissing-field-initializers"
  • new private method debugPayloadVersion( const char* label, semver_t* version ) was added to remove redundancy in the code (also adds clarity and saves a few bytes)
  • @tuan-karma's compiler fix for semver was applied
  • cleaned up the includes list (compiles faster)
  • added example based on LittleFS

@chrisjoyce911 may I suggest you enable the Discussions tab of this repository and create a few discussion threads such as:

  • how to properly test the library (e.g. unit tests, github workflows, live/preprod tests, fixtures)
  • complex update scenarios (e.g. gz/tar/tgz, firmware.gz, firmware+spiffs.tar, json+firmware+spiffs.tgz)

Copy link
Owner

@chrisjoyce911 chrisjoyce911 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few small changes

@tobozo tobozo mentioned this pull request Sep 13, 2022
@tobozo
Copy link
Collaborator Author

tobozo commented Sep 14, 2022

Here's the deal for that new dispatched workflow:

image

⚠️ Workflow must be triggered manually after editing the default values for each field in the highlighted part of capture, other fields can work fine with their respective default values.

What this workflow does:

  • Build binaries for all examples in anyFS/test folder
  • Fetch Root CA and populate spiffs/littlefs/progmem if applicable
  • Create a JSON Manifest linking to every binary in the test suite
  • Bundle the compiled binaries and the manifest into a downloadable zip archive

The resulting zip archive is only available from the github action tab though, so publishing the binaries to the web server should be done manually.

@tobozo
Copy link
Collaborator Author

tobozo commented Sep 14, 2022

@chrisjoyce911 is there anything else that need to be resolved before this is squash & merged ?

@tobozo tobozo self-assigned this Sep 15, 2022
Copy link
Collaborator Author

@tobozo tobozo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resoved

@tobozo tobozo merged commit b3b95ee into chrisjoyce911:master Sep 16, 2022
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

Successfully merging this pull request may close these issues.

None yet

2 participants