Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions components/ocs_system/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ idf_component_register(
"target_esp32/native_updater.cpp"
"target_esp32/partition_updater.cpp"
"target_esp32/cache_updater.cpp"
"target_esp32/spiffs_updater.cpp"

REQUIRES
"esp_timer"
Expand Down
51 changes: 51 additions & 0 deletions components/ocs_system/target_esp32/spiffs_updater.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* SPDX-FileCopyrightText: 2025 Tendry Lab
* SPDX-License-Identifier: Apache-2.0
*/

#include "freertos/FreeRTOSConfig.h"

#include "esp_spiffs.h"

#include "ocs_core/log.h"
#include "ocs_system/target_esp32/spiffs_updater.h"

namespace ocs {
namespace system {

namespace {

const char* log_tag = "spiffs_updater";

} // namespace

SpiffsUpdater::SpiffsUpdater(IUpdater& updater, const char* partition_label)
: partition_label_(partition_label)
, updater_(updater) {
}

status::StatusCode SpiffsUpdater::begin(size_t total_size, uint32_t crc32) {
const auto err = esp_vfs_spiffs_unregister(partition_label_.c_str());
if (err != ESP_OK) {
ocs_loge(log_tag, "esp_vfs_spiffs_unregister(): %s", esp_err_to_name(err));

return status::StatusCode::Error;
}

return updater_.begin(total_size, crc32);
}

status::StatusCode SpiffsUpdater::write(const uint8_t* buf, size_t len) {
return updater_.write(buf, len);
}

status::StatusCode SpiffsUpdater::commit() {
return updater_.commit();
}

status::StatusCode SpiffsUpdater::end() {
return updater_.end();
}

} // namespace system
} // namespace ocs
44 changes: 44 additions & 0 deletions components/ocs_system/target_esp32/spiffs_updater.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* SPDX-FileCopyrightText: 2025 Tendry Lab
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include <string>

#include "ocs_core/noncopyable.h"
#include "ocs_system/iupdater.h"

namespace ocs {
namespace system {

class SpiffsUpdater : public IUpdater, private core::NonCopyable<> {
public:
//! Initialize.
//!
//! @params
//! - @p updater - to perform the actual update process.
//! - @p partition_label - SPIFFS partition label.
SpiffsUpdater(IUpdater& updater, const char* partition_label);

//! Unmount SPIFFS partition and begin the firmware update process.
status::StatusCode begin(size_t total_size, uint32_t crc32) override;

//! Write firmware data.
status::StatusCode write(const uint8_t* buf, size_t len) override;

//! Commit firmware update.
status::StatusCode commit() override;

//! End firmware update.
status::StatusCode end() override;

private:
const std::string partition_label_;

IUpdater& updater_;
};

} // namespace system
} // namespace ocs