Skip to content

Commit 37fcbcf

Browse files
danngreenLnnrtS
authored andcommitted
Log summary, not every write/erase
1 parent 7917c2c commit 37fcbcf

File tree

4 files changed

+40
-29
lines changed

4 files changed

+40
-29
lines changed

firmware/src/flash_loader/flash_loader.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,17 @@ bool FlashLoader::check_flash_chip() {
1414
}
1515

1616
bool FlashLoader::write_sectors(uint32_t base_addr, std::span<uint8_t> buffer) {
17+
constexpr bool verbose_log = false;
18+
1719
//round up to smallest 4kB blocks that contains image
1820
unsigned bytes_to_erase = (buffer.size() + 4095) & ~4095;
1921

2022
uint32_t addr = base_addr;
2123

2224
while (bytes_to_erase) {
23-
pr_trace("Erasing 4k sector at 0x%x\n", (unsigned)addr);
25+
if constexpr (verbose_log)
26+
pr_dump("Erasing 4k sector at 0x%x\n", (unsigned)addr);
27+
2428
if (!flash.erase(mdrivlib::QSpiFlash::SECTOR, addr)) {
2529
pr_err("ERROR: Flash failed to erase\n");
2630
return false;
@@ -29,7 +33,9 @@ bool FlashLoader::write_sectors(uint32_t base_addr, std::span<uint8_t> buffer) {
2933
bytes_to_erase -= 4096;
3034
}
3135

32-
pr_trace("Writing 0x%x B to %x\n", buffer.size(), base_addr);
36+
if constexpr (verbose_log)
37+
pr_dump("Writing 0x%x B to %x\n", buffer.size(), base_addr);
38+
3339
if (!flash.write(buffer.data(), base_addr, buffer.size())) {
3440
pr_err("ERROR: Flash failed to write\n");
3541
return false;

firmware/src/fw_update/firmware_writer.cc

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ std::optional<IntercoreStorageMessage> FirmwareWriter::handle_message(const Inte
1616
using enum IntercoreStorageMessage::FlashTarget;
1717

1818
if (message.message_type == StartChecksumCompare) {
19-
pr_dbg("-> Compare with checksum %s at 0x%08x\n", message.checksum.c_str(), message.address);
2019

2120
if (message.flashTarget == WIFI) {
21+
pr_trace("-> Compare with checksum %s at 0x%08x\n", message.checksum.c_str(), message.address);
2222
return compareChecksumWifi(message.address, message.length, {message.checksum.data()});
2323

2424
} else if (message.flashTarget == QSPI) {
@@ -31,7 +31,7 @@ std::optional<IntercoreStorageMessage> FirmwareWriter::handle_message(const Inte
3131
}
3232

3333
} else if (message.message_type == StartFlashing) {
34-
pr_dbg("-> Start flashing to 0x%08x\n", message.address);
34+
pr_trace("-> Start flashing %u bytes to 0x%08x\n", message.buffer.size(), message.address);
3535
auto buf = std::span<uint8_t>{(uint8_t *)message.buffer.data(), message.buffer.size()};
3636

3737
if (message.flashTarget == WIFI) {
@@ -117,10 +117,10 @@ IntercoreStorageMessage FirmwareWriter::flashWifi(std::span<uint8_t> buffer, uin
117117
}
118118

119119
if (not error_during_writes) {
120-
pr_dbg("-> Flashing completed\n");
120+
pr_trace("-> Flashing completed\n");
121121
returnValue = {.message_type = FlashingOk};
122122
} else {
123-
pr_dbg("-> Flashing failed\n");
123+
pr_trace("-> Flashing failed\n");
124124
returnValue = {.message_type = FlashingFailed};
125125
}
126126
} else {
@@ -139,8 +139,7 @@ IntercoreStorageMessage FirmwareWriter::flashWifi(std::span<uint8_t> buffer, uin
139139

140140
IntercoreStorageMessage
141141
FirmwareWriter::compareChecksumQSPI(uint32_t address, uint32_t length, Checksum_t checksum, uint32_t &bytesChecked) {
142-
143-
// Force checking QSPI flash block-by-block, so we can skip blocks,,
142+
// Force checking QSPI flash block-by-block, so we can skip blocks
144143
return {.message_type = ChecksumMismatch};
145144
}
146145

@@ -175,18 +174,16 @@ IntercoreStorageMessage FirmwareWriter::flashQSPI(std::span<uint8_t> buffer, uin
175174
}
176175
}
177176

178-
bool success = true;
179-
if (data_matches)
180-
pr_trace("Skipping sector at 0x%x, data matches\n", address + bytesWritten);
181-
else
182-
success = loader_.write_sectors(address + bytesWritten, buffer_to_write);
183-
184-
if (success) {
185-
bytesWritten += num_bytes_to_write;
177+
if (data_matches) {
178+
pr_dump("Skipping sector at 0x%x, data matches\n", address + bytesWritten);
186179
} else {
187-
errorDetected = true;
188-
break;
180+
if (!loader_.write_sectors(address + bytesWritten, buffer_to_write)) {
181+
errorDetected = true;
182+
break;
183+
}
189184
}
185+
186+
bytesWritten += num_bytes_to_write;
190187
}
191188
} else {
192189
errorDetected = true;

firmware/src/fw_update/updater_proxy.cc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,18 @@ FirmwareUpdaterProxy::Status FirmwareUpdaterProxy::process() {
191191
abortWithMessage("Error when comparing checksums");
192192
break;
193193

194-
case FileStorageProxy::WifiExpanderNotConnected:
195-
error_message = "No Wifi Expander: skipping " + manifest.files[current_file_idx].filename;
194+
case FileStorageProxy::WifiExpanderNotConnected: {
195+
error_message = "No Wifi Expander: skipping ";
196+
197+
auto full_path = manifest.files[current_file_idx].filename;
198+
auto slash_pos = full_path.find_first_of("/");
199+
if (slash_pos != std::string::npos)
200+
error_message += full_path.substr(slash_pos + 1);
201+
else
202+
error_message += full_path;
203+
196204
proceedWithNextFile();
197-
break;
205+
} break;
198206

199207
default:
200208
break;

firmware/src/wifi/comm/wifi_interface.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,18 @@ void sendBroadcast(std::span<uint8_t> payload) {
8686
////////////////////////////////7
8787

8888
void init(PatchStorage *storage) {
89-
printf("Initializing Wifi\n");
89+
pr_info("Initializing Wifi\n");
9090

9191
patchStorage = storage;
9292
}
9393

9494
void start() {
95-
pr_dbg("Wifi: Starting RX\n");
95+
pr_trace("Wifi: Starting RX\n");
9696
BufferedUSART2::init();
9797
}
9898

9999
void stop() {
100-
pr_dbg("Wifi: Stopping RX\n");
100+
pr_trace("Wifi: Stopping RX\n");
101101
BufferedUSART2::deinit();
102102
}
103103

@@ -127,10 +127,10 @@ void handle_received_frame(uint8_t destination, std::span<uint8_t> payload) {
127127

128128
sendResponse(fbb.GetBufferSpan());
129129
} else {
130-
printf("Unexpected detection\n");
130+
pr_err("Unexpected detection\n");
131131
}
132132
} else if (auto switchMessage = message->content_as_Switch(); switchMessage) {
133-
printf("State: %u\n", switchMessage->state());
133+
pr_trace("State: %u\n", switchMessage->state());
134134

135135
// Just echo back raw
136136
sendResponse(payload);
@@ -149,7 +149,7 @@ void handle_received_frame(uint8_t destination, std::span<uint8_t> payload) {
149149

150150
auto filename = flatbuffers::GetStringView(uploadPatchMessage->filename());
151151

152-
printf("Received Patch of %u bytes for location %u\n", receivedPatchData.size(), destination);
152+
pr_info("Received Patch of %u bytes for location %u\n", receivedPatchData.size(), destination);
153153

154154
auto LocationToVolume = [](auto location) -> std::optional<Volume> {
155155
switch (location) {
@@ -199,10 +199,10 @@ void handle_received_frame(uint8_t destination, std::span<uint8_t> payload) {
199199
sendBroadcast(fbb.GetBufferSpan());
200200
}
201201
} else {
202-
printf("Other option\n");
202+
pr_trace("Other option\n");
203203
}
204204
} else {
205-
printf("Invalid message\n");
205+
pr_err("Invalid message\n");
206206
}
207207
}
208208

0 commit comments

Comments
 (0)