diff --git a/components/ocs_system/CMakeLists.txt b/components/ocs_system/CMakeLists.txt index 454843b1..6491ab34 100644 --- a/components/ocs_system/CMakeLists.txt +++ b/components/ocs_system/CMakeLists.txt @@ -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" diff --git a/components/ocs_system/crc32_updater.cpp b/components/ocs_system/crc32_updater.cpp index ea007074..2d04da14 100644 --- a/components/ocs_system/crc32_updater.cpp +++ b/components/ocs_system/crc32_updater.cpp @@ -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; diff --git a/components/ocs_system/log_updater.cpp b/components/ocs_system/log_updater.cpp new file mode 100644 index 00000000..0f1323d6 --- /dev/null +++ b/components/ocs_system/log_updater.cpp @@ -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 diff --git a/components/ocs_system/log_updater.h b/components/ocs_system/log_updater.h new file mode 100644 index 00000000..9577110b --- /dev/null +++ b/components/ocs_system/log_updater.h @@ -0,0 +1,44 @@ +/* + * SPDX-FileCopyrightText: 2025 Tendry Lab + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include + +#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