From f1b47b16c09ec1cad2203ad9e650376cb5b3da4d Mon Sep 17 00:00:00 2001 From: David Grayson Date: Sat, 31 Aug 2024 11:19:25 -0700 Subject: [PATCH] Only show one 'Loading' and one 'Verifying' progress bar when loading. This makes the output much shorter and more useful when loading a UF2 file that writes to many different memory ranges, which can happen if it contains a filesystem. Also, don't bother printing "OK": if the verification finished that means everything was OK. --- main.cpp | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/main.cpp b/main.cpp index b12e5cf..5154081 100644 --- a/main.cpp +++ b/main.cpp @@ -4256,11 +4256,13 @@ bool load_guts(picoboot::connection con, iostream_memory_access &file_access) { } } } - for (auto mem_range : ranges) { - enum memory_type type = get_memory_type(mem_range.from, model); - // new scope for progress bar - { - progress_bar bar("Loading into " + memory_names[type] + ": "); + size_t total_bytes = 0; + for (auto r : ranges) { total_bytes += r.to - r.from; } + { + progress_bar bar("Loading: "); + size_t loaded_bytes = 0; + for (auto mem_range : ranges) { + enum memory_type type = get_memory_type(mem_range.from, model); uint32_t batch_size = FLASH_SECTOR_ERASE_SIZE; bool ok = true; vector file_buf; @@ -4296,16 +4298,17 @@ bool load_guts(picoboot::connection con, iostream_memory_access &file_access) { raw_access.write_vector(base, file_buf); base += this_batch; } - bar.progress(base - mem_range.from, mem_range.to - mem_range.from); + bar.progress(base - mem_range.from + loaded_bytes, total_bytes); } + loaded_bytes += mem_range.to - mem_range.from; } } - for (auto mem_range : ranges) { - enum memory_type type = get_memory_type(mem_range.from, model); - if (settings.load.verify) { + if (settings.load.verify) { + progress_bar bar("Verifying: "); + size_t verified_bytes = 0; + for (auto mem_range : ranges) { bool ok = true; { - progress_bar bar("Verifying " + memory_names[type] + ": "); uint32_t batch_size = FLASH_SECTOR_ERASE_SIZE; vector file_buf; vector device_buf; @@ -4327,16 +4330,14 @@ bool load_guts(picoboot::connection con, iostream_memory_access &file_access) { } if (ok) { pos = base + this_batch; + bar.progress(pos - mem_range.from + verified_bytes, total_bytes); } - bar.progress(pos - mem_range.from, mem_range.to - mem_range.from); } } - if (ok) { - std::cout << " OK\n"; - } else { - std::cout << " FAILED\n"; + if (!ok) { fail(ERROR_VERIFICATION_FAILED, "The device contents did not match the file"); } + verified_bytes += mem_range.to - mem_range.from; } } if (settings.load.execute) {