Skip to content

Commit cdf6228

Browse files
committed
Improve the way files are loaded.
- All verification should be done after all writing just in case the writing commands are misconfigured and have unintended side effects. - We should avoid printing numerous progress bars when loading a sparse file that writes to many separate areas of flash.
1 parent aeb3fec commit cdf6228

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

main.cpp

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,7 +1398,7 @@ void info_guts(memory_access &raw_access) {
13981398
string program_name, program_build_date, program_version, program_url, program_description;
13991399
string pico_board, sdk_version, boot2_name;
14001400
vector<string> program_features, build_attributes;
1401-
1401+
14021402
uint32_t binary_end = 0;
14031403

14041404
// do a pass first to find named groups
@@ -1839,11 +1839,14 @@ bool load_command::execute(device_map &devices) {
18391839
}
18401840
}
18411841

1842-
for (auto mem_range : ranges) {
1843-
enum memory_type type = get_memory_type(mem_range.from);
1844-
// new scope for progress bar
1845-
{
1846-
progress_bar bar("Loading into " + memory_names[type] + ": ");
1842+
size_t total_size = 0;
1843+
for (auto mem_range : ranges) { total_size += mem_range.to - mem_range.from; }
1844+
1845+
{
1846+
progress_bar bar("Loading: ");
1847+
size_t loaded_size = 0;
1848+
for (auto mem_range : ranges) {
1849+
enum memory_type type = get_memory_type(mem_range.from);
18471850
vector<uint8_t> file_buf;
18481851
vector<uint8_t> device_buf;
18491852
for (uint32_t base = mem_range.from; base < mem_range.to; ) {
@@ -1877,13 +1880,18 @@ bool load_command::execute(device_map &devices) {
18771880
raw_access.write_vector(base, file_buf);
18781881
base += this_batch;
18791882
}
1880-
bar.progress(base - mem_range.from, mem_range.to - mem_range.from);
1883+
loaded_size += this_batch;
1884+
bar.progress(loaded_size, total_size);
18811885
}
18821886
}
1883-
if (settings.load.verify) {
1887+
}
1888+
1889+
if (settings.load.verify) {
1890+
progress_bar bar("Verifying: ");
1891+
size_t verified_size = 0;
1892+
for (auto mem_range : ranges) {
18841893
bool ok = true;
18851894
{
1886-
progress_bar bar("Verifying " + memory_names[type] + ": ");
18871895
uint32_t batch_size = 0x8000;
18881896
vector<uint8_t> file_buf;
18891897
vector<uint8_t> device_buf;
@@ -1902,14 +1910,12 @@ bool load_command::execute(device_map &devices) {
19021910
}
19031911
if (ok) {
19041912
pos = base + this_batch;
1913+
verified_size += this_batch;
1914+
bar.progress(verified_size, total_size);
19051915
}
1906-
bar.progress(pos - mem_range.from, mem_range.to - mem_range.from);
19071916
}
19081917
}
1909-
if (ok) {
1910-
std::cout << " OK\n";
1911-
} else {
1912-
std::cout << " FAILED\n";
1918+
if (!ok) {
19131919
fail(ERROR_VERIFICATION_FAILED, "The device contents did not match the file");
19141920
}
19151921
}

0 commit comments

Comments
 (0)