You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: main.cpp
+46-9Lines changed: 46 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -140,6 +140,10 @@ struct range {
140
140
to = other.clamp(to);
141
141
}
142
142
143
+
boolintersects(const range& other) const {
144
+
return !(other.from >= to || other.to < from);
145
+
}
146
+
143
147
};
144
148
145
149
// ranges should not overlap
@@ -248,6 +252,8 @@ struct _settings {
248
252
struct {
249
253
bool verify = false;
250
254
bool execute = false;
255
+
bool no_overwrite = false;
256
+
bool no_overwrite_force = false;
251
257
} load;
252
258
253
259
struct {
@@ -363,6 +369,8 @@ struct load_command : public cmd {
363
369
group get_cli() override {
364
370
return (
365
371
(
372
+
option('n', "--no-overwrite").set(settings.load.no_overwrite) % "When writing flash data, do not overwrite an existing program in flash. If picotool cannot determine the size/presence of the program in flash, the command fails" +
373
+
option('N', "--no-overwrite-unsafe").set(settings.load.no_overwrite_force) % "When writing flash data, do not overwrite an existing program in flash. If picotool cannot determine the size/presence of the program in flash, the load continues anyway" +
366
374
option('v', "--verify").set(settings.load.verify) % "Verify the data was written correctly" +
367
375
option('x', "--execute").set(settings.load.execute) % "Attempt to execute the downloaded file as a program after the load"
fail(ERROR_FORMAT, "File to load contained an invalid memory range 0x%08x-0x%08x", mem_range.from,
1728
1755
mem_range.to);
1729
1756
}
1757
+
if (settings.load.no_overwrite && mem_range.intersects(flash_binary_range)) {
1758
+
if (flash_binary_end_unknown) {
1759
+
if (!settings.load.no_overwrite_force) {
1760
+
fail(ERROR_NOT_POSSIBLE, "-n option specified, but the size/presence of an existing flash binary could not be detected; aborting. Consider using the -N option");
1761
+
}
1762
+
} else {
1763
+
fail(ERROR_NOT_POSSIBLE, "-n option specified, and the loaded data range clashes with the existing flash binary range %08x->%08x",
1764
+
flash_binary_range.from, flash_binary_range.to);
1765
+
}
1766
+
}
1730
1767
}
1731
1768
for (auto mem_range : ranges) {
1732
1769
enum memory_type type = get_memory_type(mem_range.from);
0 commit comments