Skip to content

Commit

Permalink
Log summary, not every write/erase
Browse files Browse the repository at this point in the history
  • Loading branch information
danngreen committed Jul 1, 2024
1 parent 1152cd2 commit 3d8ce14
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 29 deletions.
10 changes: 8 additions & 2 deletions firmware/src/flash_loader/flash_loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ bool FlashLoader::check_flash_chip() {
}

bool FlashLoader::write_sectors(uint32_t base_addr, std::span<uint8_t> buffer) {
constexpr bool verbose_log = false;

//round up to smallest 4kB blocks that contains image
unsigned bytes_to_erase = (buffer.size() + 4095) & ~4095;

uint32_t addr = base_addr;

while (bytes_to_erase) {
pr_trace("Erasing 4k sector at 0x%x\n", (unsigned)addr);
if constexpr (verbose_log)
pr_dump("Erasing 4k sector at 0x%x\n", (unsigned)addr);

if (!flash.erase(mdrivlib::QSpiFlash::SECTOR, addr)) {
pr_err("ERROR: Flash failed to erase\n");
return false;
Expand All @@ -29,7 +33,9 @@ bool FlashLoader::write_sectors(uint32_t base_addr, std::span<uint8_t> buffer) {
bytes_to_erase -= 4096;
}

pr_trace("Writing 0x%x B to %x\n", buffer.size(), base_addr);
if constexpr (verbose_log)
pr_dump("Writing 0x%x B to %x\n", buffer.size(), base_addr);

if (!flash.write(buffer.data(), base_addr, buffer.size())) {
pr_err("ERROR: Flash failed to write\n");
return false;
Expand Down
29 changes: 13 additions & 16 deletions firmware/src/fw_update/firmware_writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ std::optional<IntercoreStorageMessage> FirmwareWriter::handle_message(const Inte
using enum IntercoreStorageMessage::FlashTarget;

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

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

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

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

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

if (not error_during_writes) {
pr_dbg("-> Flashing completed\n");
pr_trace("-> Flashing completed\n");
returnValue = {.message_type = FlashingOk};
} else {
pr_dbg("-> Flashing failed\n");
pr_trace("-> Flashing failed\n");
returnValue = {.message_type = FlashingFailed};
}
} else {
Expand All @@ -139,8 +139,7 @@ IntercoreStorageMessage FirmwareWriter::flashWifi(std::span<uint8_t> buffer, uin

IntercoreStorageMessage
FirmwareWriter::compareChecksumQSPI(uint32_t address, uint32_t length, Checksum_t checksum, uint32_t &bytesChecked) {

// Force checking QSPI flash block-by-block, so we can skip blocks,,
// Force checking QSPI flash block-by-block, so we can skip blocks
return {.message_type = ChecksumMismatch};
}

Expand Down Expand Up @@ -175,18 +174,16 @@ IntercoreStorageMessage FirmwareWriter::flashQSPI(std::span<uint8_t> buffer, uin
}
}

bool success = true;
if (data_matches)
pr_trace("Skipping sector at 0x%x, data matches\n", address + bytesWritten);
else
success = loader_.write_sectors(address + bytesWritten, buffer_to_write);

if (success) {
bytesWritten += num_bytes_to_write;
if (data_matches) {
pr_dump("Skipping sector at 0x%x, data matches\n", address + bytesWritten);
} else {
errorDetected = true;
break;
if (!loader_.write_sectors(address + bytesWritten, buffer_to_write)) {
errorDetected = true;
break;
}
}

bytesWritten += num_bytes_to_write;
}
} else {
errorDetected = true;
Expand Down
14 changes: 11 additions & 3 deletions firmware/src/fw_update/updater_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,18 @@ FirmwareUpdaterProxy::Status FirmwareUpdaterProxy::process() {
abortWithMessage("Error when comparing checksums");
break;

case FileStorageProxy::WifiExpanderNotConnected:
error_message = "No Wifi Expander: skipping " + manifest.files[current_file_idx].filename;
case FileStorageProxy::WifiExpanderNotConnected: {
error_message = "No Wifi Expander: skipping ";

auto full_path = manifest.files[current_file_idx].filename;
auto slash_pos = full_path.find_first_of("/");
if (slash_pos != std::string::npos)
error_message += full_path.substr(slash_pos + 1);
else
error_message += full_path;

proceedWithNextFile();
break;
} break;

default:
break;
Expand Down
16 changes: 8 additions & 8 deletions firmware/src/wifi/comm/wifi_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,18 @@ void sendBroadcast(std::span<uint8_t> payload) {
////////////////////////////////7

void init(PatchStorage *storage) {
printf("Initializing Wifi\n");
pr_info("Initializing Wifi\n");

patchStorage = storage;
}

void start() {
pr_dbg("Wifi: Starting RX\n");
pr_trace("Wifi: Starting RX\n");
BufferedUSART2::init();
}

void stop() {
pr_dbg("Wifi: Stopping RX\n");
pr_trace("Wifi: Stopping RX\n");
BufferedUSART2::deinit();
}

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

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

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

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

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

auto LocationToVolume = [](auto location) -> std::optional<Volume> {
switch (location) {
Expand Down Expand Up @@ -199,10 +199,10 @@ void handle_received_frame(uint8_t destination, std::span<uint8_t> payload) {
sendBroadcast(fbb.GetBufferSpan());
}
} else {
printf("Other option\n");
pr_trace("Other option\n");
}
} else {
printf("Invalid message\n");
pr_err("Invalid message\n");
}
}

Expand Down

0 comments on commit 3d8ce14

Please sign in to comment.