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 @@ -10,6 +10,7 @@ idf_component_register(
"device_id.cpp"
"device_info.cpp"
"crc32_updater.cpp"
"log_updater.cpp"

"target_esp32/clock.cpp"
"target_esp32/rebooter.cpp"
Expand Down
3 changes: 0 additions & 3 deletions components/ocs_system/crc32_updater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ status::StatusCode Crc32Updater::begin(size_t total_size, uint32_t crc32) {

crc32_src_ = crc32;

ocs_logi(log_tag, "begin update process: total_size=%zu crc32=%lu", total_size,
crc32);

const auto code = updater_.begin(total_size, crc32);
if (code != status::StatusCode::OK) {
return code;
Expand Down
45 changes: 45 additions & 0 deletions components/ocs_system/log_updater.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* SPDX-FileCopyrightText: 2025 Tendry Lab
* SPDX-License-Identifier: Apache-2.0
*/

#include "freertos/FreeRTOSConfig.h"

#include "ocs_core/log.h"
#include "ocs_system/log_updater.h"

namespace ocs {
namespace system {

LogUpdater::LogUpdater(IUpdater& updater, const char* log_tag)
: log_tag_(log_tag)
, updater_(updater) {
}

status::StatusCode LogUpdater::begin(size_t total_size, uint32_t crc32) {
ocs_logi(log_tag_.c_str(), "beginning firmware update: total_size=%zu crc32=%lu",
total_size, crc32);

return updater_.begin(total_size, crc32);
}

status::StatusCode LogUpdater::write(const uint8_t* buf, size_t len) {
ocs_logd(log_tag_.c_str(), "writing firmware data: len=%zu", len);

return updater_.write(buf, len);
}

status::StatusCode LogUpdater::commit() {
ocs_logi(log_tag_.c_str(), "committing firmware update");

return updater_.commit();
}

status::StatusCode LogUpdater::end() {
ocs_logi(log_tag_.c_str(), "ending firmware update");

return updater_.end();
}

} // namespace system
} // namespace ocs
44 changes: 44 additions & 0 deletions components/ocs_system/log_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 LogUpdater : public IUpdater, private core::NonCopyable<> {
public:
//! Initialize.
//!
//! @params
//! - @p updater to perform the actual update process.
//! - @p log_tag to use for logging.
LogUpdater(IUpdater& updater, const char* log_tag);

//! Begin firmware update.
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 log_tag_;

IUpdater& updater_;
};

} // namespace system
} // namespace ocs