From 0e06304d0ade0fbbb85a18a7aec164274f4eaf1e Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Fri, 8 Nov 2024 11:38:00 +0000 Subject: [PATCH 1/5] Align all progress bars --- main.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/main.cpp b/main.cpp index 64a0ae8..8f1774c 100644 --- a/main.cpp +++ b/main.cpp @@ -3930,7 +3930,15 @@ struct progress_bar { if (_percent != percent) { percent = _percent; unsigned int len = (width * percent) / 100; - std::cout << prefix << "[" << string(len, '=') << string(width-len, ' ') << "] " << std::to_string(percent) << "%\r" << std::flush; + // Align all bars with the longest possible prefix string + auto longest_mem = std::max_element( + std::begin(memory_names), std::end(memory_names), + [] (const auto & p1, const auto & p2) { + return p1.second.length() < p2.second.length(); + } + ); + string extra_space(string("Loading into " + longest_mem->second + ": ").length() - prefix.length(), ' '); + std::cout << prefix << extra_space << "[" << string(len, '=') << string(width-len, ' ') << "] " << std::to_string(percent) << "%\r" << std::flush; } } @@ -4106,7 +4114,7 @@ bool save_command::execute(device_map &devices) { enum memory_type type = get_memory_type(mem_range.from, model); bool ok = true; { - progress_bar bar("Verifying " + memory_names[type] + ": "); + progress_bar bar("Verifying " + memory_names[type] + ": "); uint32_t batch_size = FLASH_SECTOR_ERASE_SIZE; vector file_buf; vector device_buf; @@ -4355,7 +4363,7 @@ bool load_guts(picoboot::connection con, iostream_memory_access &file_access) { if (settings.load.verify) { bool ok = true; { - progress_bar bar("Verifying " + memory_names[type] + ": "); + progress_bar bar("Verifying " + memory_names[type] + ": "); uint32_t batch_size = FLASH_SECTOR_ERASE_SIZE; vector file_buf; vector device_buf; From cd65f0b8a7a0fa847e84bf162a09385c16e7c835 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Fri, 8 Nov 2024 13:09:33 +0000 Subject: [PATCH 2/5] Prevent saving/loading from unstriped SRAM --- main.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/main.cpp b/main.cpp index 8f1774c..5846861 100644 --- a/main.cpp +++ b/main.cpp @@ -97,7 +97,6 @@ typedef map>> auto memory_names = map{ {memory_type::sram, "RAM"}, - {memory_type::sram_unstriped, "Unstriped RAM"}, {memory_type::flash, "Flash"}, {memory_type::xip_sram, "XIP RAM"}, {memory_type::rom, "ROM"} @@ -4037,7 +4036,7 @@ bool save_command::execute(device_map &devices) { model_t model = get_model(raw_access); enum memory_type t1 = get_memory_type(start , model); enum memory_type t2 = get_memory_type(end, model); - if (t1 == invalid || t1 != t2) { + if (t1 != t2 || t1 == invalid || t1 == sram_unstriped) { fail(ERROR_NOT_POSSIBLE, "Save range crosses unmapped memory"); } uint32_t size = end - start; @@ -4272,7 +4271,7 @@ bool load_guts(picoboot::connection con, iostream_memory_access &file_access) { for (auto mem_range : ranges) { enum memory_type t1 = get_memory_type(mem_range.from, model); enum memory_type t2 = get_memory_type(mem_range.to, model); - if (t1 != t2 || t1 == invalid || t1 == rom) { + if (t1 != t2 || t1 == invalid || t1 == rom || t1 == sram_unstriped) { fail(ERROR_FORMAT, "File to load contained an invalid memory range 0x%08x-0x%08x", mem_range.from, mem_range.to); } @@ -4934,7 +4933,7 @@ bool verify_command::execute(device_map &devices) { for (auto mem_range : ranges) { enum memory_type t1 = get_memory_type(mem_range.from, model); enum memory_type t2 = get_memory_type(mem_range.to, model); - if (t1 != t2 || t1 == invalid) { + if (t1 != t2 || t1 == invalid || t1 == sram_unstriped) { fail(ERROR_NOT_POSSIBLE, "invalid memory range for verification %08x-%08x", mem_range.from, mem_range.to); } else { bool ok = true; From c76ca9f58f1c1f5d0e62c704b42d156eeed37b73 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Tue, 12 Nov 2024 12:45:03 +0000 Subject: [PATCH 3/5] Only calculate longest_mem_str once, when progress_bar is created --- main.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/main.cpp b/main.cpp index 5846861..b471d51 100644 --- a/main.cpp +++ b/main.cpp @@ -3922,6 +3922,14 @@ static picoboot::connection get_single_rp2350_bootsel_device_connection(device_m struct progress_bar { explicit progress_bar(string prefix, int width = 30) : prefix(std::move(prefix)), width(width) { + // Align all bars with the longest possible prefix string + auto longest_mem = std::max_element( + std::begin(memory_names), std::end(memory_names), + [] (const auto & p1, const auto & p2) { + return p1.second.length() < p2.second.length(); + } + ); + longest_mem_str = longest_mem->second; progress(0); } @@ -3929,14 +3937,7 @@ struct progress_bar { if (_percent != percent) { percent = _percent; unsigned int len = (width * percent) / 100; - // Align all bars with the longest possible prefix string - auto longest_mem = std::max_element( - std::begin(memory_names), std::end(memory_names), - [] (const auto & p1, const auto & p2) { - return p1.second.length() < p2.second.length(); - } - ); - string extra_space(string("Loading into " + longest_mem->second + ": ").length() - prefix.length(), ' '); + string extra_space(string("Loading into " + longest_mem_str + ": ").length() - prefix.length(), ' '); std::cout << prefix << extra_space << "[" << string(len, '=') << string(width-len, ' ') << "] " << std::to_string(percent) << "%\r" << std::flush; } } @@ -3952,6 +3953,7 @@ struct progress_bar { std::string prefix; int percent = -1; int width; + std::string longest_mem_str; }; #if HAS_LIBUSB From 617790db8ec7d44b415755c79c06ea237038a490 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Tue, 12 Nov 2024 12:45:58 +0000 Subject: [PATCH 4/5] Fix saving/verifying range to bin file When verifying the bin file was assumed to start at FLASH_START, so verification would fail if the range didn't start there --- main.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/main.cpp b/main.cpp index b471d51..9dab803 100644 --- a/main.cpp +++ b/main.cpp @@ -4000,6 +4000,9 @@ bool save_command::execute(device_map &devices) { } else { start = settings.from; end = settings.to; + // Set offset for verifying + settings.offset = start; + settings.offset_set = true; } if (end <= start) { fail(ERROR_ARGS, "Save range is invalid/empty"); From a9c2303eae75507af13d051fe82babd1a1861b5c Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Tue, 12 Nov 2024 13:57:41 +0000 Subject: [PATCH 5/5] Append extra_space to prefix --- main.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/main.cpp b/main.cpp index 9dab803..51ef24a 100644 --- a/main.cpp +++ b/main.cpp @@ -3921,7 +3921,7 @@ static picoboot::connection get_single_rp2350_bootsel_device_connection(device_m #endif struct progress_bar { - explicit progress_bar(string prefix, int width = 30) : prefix(std::move(prefix)), width(width) { + explicit progress_bar(string new_prefix, int width = 30) : width(width) { // Align all bars with the longest possible prefix string auto longest_mem = std::max_element( std::begin(memory_names), std::end(memory_names), @@ -3929,7 +3929,8 @@ struct progress_bar { return p1.second.length() < p2.second.length(); } ); - longest_mem_str = longest_mem->second; + string extra_space(string("Loading into " + longest_mem->second + ": ").length() - new_prefix.length(), ' '); + prefix = new_prefix + extra_space; progress(0); } @@ -3937,8 +3938,7 @@ struct progress_bar { if (_percent != percent) { percent = _percent; unsigned int len = (width * percent) / 100; - string extra_space(string("Loading into " + longest_mem_str + ": ").length() - prefix.length(), ' '); - std::cout << prefix << extra_space << "[" << string(len, '=') << string(width-len, ' ') << "] " << std::to_string(percent) << "%\r" << std::flush; + std::cout << prefix << "[" << string(len, '=') << string(width-len, ' ') << "] " << std::to_string(percent) << "%\r" << std::flush; } } @@ -3953,7 +3953,6 @@ struct progress_bar { std::string prefix; int percent = -1; int width; - std::string longest_mem_str; }; #if HAS_LIBUSB