Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align Saving, Loading and Verifying progress bars #170

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ typedef map<enum picoboot_device_result,vector<tuple<model_t, void *, void *>>>

auto memory_names = map<enum memory_type, string>{
{memory_type::sram, "RAM"},
{memory_type::sram_unstriped, "Unstriped RAM"},
{memory_type::flash, "Flash"},
{memory_type::xip_sram, "XIP RAM"},
{memory_type::rom, "ROM"}
Expand Down Expand Up @@ -3930,7 +3929,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();
}
);
will-v-pi marked this conversation as resolved.
Show resolved Hide resolved
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;
}
}

Expand Down Expand Up @@ -4029,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;
Expand Down Expand Up @@ -4106,7 +4113,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<uint8_t> file_buf;
vector<uint8_t> device_buf;
Expand Down Expand Up @@ -4264,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);
}
Expand Down Expand Up @@ -4355,7 +4362,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<uint8_t> file_buf;
vector<uint8_t> device_buf;
Expand Down Expand Up @@ -4926,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;
Expand Down
Loading