Skip to content

Commit 2d1b6cb

Browse files
committed
Add logging during firmware update
1 parent fd6f508 commit 2d1b6cb

File tree

4 files changed

+90
-3
lines changed

4 files changed

+90
-3
lines changed

components/ocs_system/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ idf_component_register(
1010
"device_id.cpp"
1111
"device_info.cpp"
1212
"crc32_updater.cpp"
13+
"log_updater.cpp"
1314

1415
"target_esp32/clock.cpp"
1516
"target_esp32/rebooter.cpp"

components/ocs_system/crc32_updater.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ status::StatusCode Crc32Updater::begin(size_t total_size, uint32_t crc32) {
2828

2929
crc32_src_ = crc32;
3030

31-
ocs_logi(log_tag, "begin update process: total_size=%zu crc32=%lu", total_size,
32-
crc32);
33-
3431
const auto code = updater_.begin(total_size, crc32);
3532
if (code != status::StatusCode::OK) {
3633
return code;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Tendry Lab
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include "freertos/FreeRTOSConfig.h"
7+
8+
#include "ocs_core/log.h"
9+
#include "ocs_system/log_updater.h"
10+
11+
namespace ocs {
12+
namespace system {
13+
14+
LogUpdater::LogUpdater(IUpdater& updater, const char* log_tag)
15+
: log_tag_(log_tag)
16+
, updater_(updater) {
17+
}
18+
19+
status::StatusCode LogUpdater::begin(size_t total_size, uint32_t crc32) {
20+
ocs_logi(log_tag_.c_str(), "beginning firmware update: total_size=%zu crc32=%lu",
21+
total_size, crc32);
22+
23+
return updater_.begin(total_size, crc32);
24+
}
25+
26+
status::StatusCode LogUpdater::write(const uint8_t* buf, size_t len) {
27+
ocs_logd(log_tag_.c_str(), "writing firmware data: len=%zu", len);
28+
29+
return updater_.write(buf, len);
30+
}
31+
32+
status::StatusCode LogUpdater::commit() {
33+
ocs_logi(log_tag_.c_str(), "committing firmware update");
34+
35+
return updater_.commit();
36+
}
37+
38+
status::StatusCode LogUpdater::end() {
39+
ocs_logi(log_tag_.c_str(), "ending firmware update");
40+
41+
return updater_.end();
42+
}
43+
44+
} // namespace system
45+
} // namespace ocs
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Tendry Lab
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#pragma once
7+
8+
#include <string>
9+
10+
#include "ocs_core/noncopyable.h"
11+
#include "ocs_system/iupdater.h"
12+
13+
namespace ocs {
14+
namespace system {
15+
16+
class LogUpdater : public IUpdater, private core::NonCopyable<> {
17+
public:
18+
//! Initialize.
19+
//!
20+
//! @params
21+
//! - @p updater to perform the actual update process.
22+
//! - @p log_tag to use for logging.
23+
LogUpdater(IUpdater& updater, const char* log_tag);
24+
25+
//! Begin firmware update.
26+
status::StatusCode begin(size_t total_size, uint32_t crc32) override;
27+
28+
//! Write firmware data.
29+
status::StatusCode write(const uint8_t* buf, size_t len) override;
30+
31+
//! Commit firmware update.
32+
status::StatusCode commit() override;
33+
34+
//! End firmware update.
35+
status::StatusCode end() override;
36+
37+
private:
38+
const std::string log_tag_;
39+
40+
IUpdater& updater_;
41+
};
42+
43+
} // namespace system
44+
} // namespace ocs

0 commit comments

Comments
 (0)