Skip to content

Commit

Permalink
feat w80xprog: added log color
Browse files Browse the repository at this point in the history
Signed-off-by: John Sanpe <[email protected]>
  • Loading branch information
sanpeqf committed Apr 30, 2024
1 parent 15b80c3 commit c51f361
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 67 deletions.
65 changes: 33 additions & 32 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,19 @@ options[] = {
static __bfdev_noreturn void
usage(void)
{
printf("Usage: w80xprog [options]...\n");
printf("\t-h, --help display this message\n");
printf("\t-p, --port <device> set device path\n");
printf("\t-s, --speed <freq> set link baudrate\n");
printf("\t-n, --nspeed <freq> set new baudrate\n");
printf("\t-o, --secboot entry secboot mode\n");
printf("\t-i, --info read the chip info\n");
printf("\t-f, --flash <file> flash chip with data from filename\n");
printf("\t-e, --erase <offset:size> erase the entire chip\n");
printf("\t-b, --bt <mac> set bluetooth mac address\n");
printf("\t-w, --wifi <mac> set wifi mac address\n");
printf("\t-g, --gain <gain> set power amplifier gain\n");
printf("\t-r, --reset reset chip after operate\n");
bfdev_log_err("Usage: w80xprog [options]...\n");
bfdev_log_err("\t-h, --help display this message\n");
bfdev_log_err("\t-p, --port <device> set device path\n");
bfdev_log_err("\t-s, --speed <freq> set link baudrate\n");
bfdev_log_err("\t-n, --nspeed <freq> set new baudrate\n");
bfdev_log_err("\t-o, --secboot entry secboot mode\n");
bfdev_log_err("\t-i, --info read the chip info\n");
bfdev_log_err("\t-f, --flash <file> flash chip with data from filename\n");
bfdev_log_err("\t-e, --erase <offset:size> erase the specific flash\n");
bfdev_log_err("\t-b, --bt <mac> set bluetooth mac address\n");
bfdev_log_err("\t-w, --wifi <mac> set wifi mac address\n");
bfdev_log_err("\t-g, --gain <gain> set power amplifier gain\n");
bfdev_log_err("\t-r, --reset reset chip after operate\n");
exit(1);
}

Expand Down Expand Up @@ -95,9 +95,10 @@ int main(int argc, char *const argv[])
flags = 0;
esize = 0;

printf("w80xprog v" __bfdev_stringify(PROJECT_VERSION) "\n");
printf("Copyright(c) 2021-2024 John Sanpe <[email protected]>\n");
printf("License GPLv2+: GNU GPL version 2 or later.\n\n");
bfdev_log_clr_level(&bfdev_log_default);
bfdev_log_notice("w80xprog v" __bfdev_stringify(PROJECT_VERSION) "\n");
bfdev_log_notice("Copyright(c) 2021-2024 John Sanpe <[email protected]>\n");
bfdev_log_notice("License GPLv2+: GNU GPL version 2 or later.\n\n");

for (;;) {
arg = getopt_long(argc, argv, "p:ois:n:f:e:b:w:g:rh", options, &optidx);
Expand Down Expand Up @@ -168,24 +169,24 @@ int main(int argc, char *const argv[])
retval = term_open(port);
if (retval) {
bfdev_errname(retval, &errname);
printf("Failed to open port: %s\n", errname);
bfdev_log_err("Failed to open port: %s\n", errname);
return retval;
}

retval = term_setup(speed, 8, 1, 'N');
if (retval) {
bfdev_errname(retval, &errname);
printf("Failed to setup port: %s\n", errname);
bfdev_log_err("Failed to setup port: %s\n", errname);
return retval;
}

term_rts(false);
term_reset(false);

if (flags & FLAG_SECBOOT) {
retval = entry_secboot();
if (retval) {
bfdev_errname(retval, &errname);
printf("Failed to entry secboot: %s\n", errname);
bfdev_log_err("Failed to entry secboot: %s\n", errname);
return retval;
}
}
Expand All @@ -194,14 +195,14 @@ int main(int argc, char *const argv[])
retval = serial_speed(nspeed);
if (retval) {
bfdev_errname(retval, &errname);
printf("Failed to set chip speed: %s\n", errname);
bfdev_log_err("Failed to set chip speed: %s\n", errname);
return retval;
}

retval = term_setspeed(nspeed);
if (retval) {
bfdev_errname(retval, &errname);
printf("Failed to set host speed: %s\n", errname);
bfdev_log_err("Failed to set host speed: %s\n", errname);
return retval;
}
}
Expand All @@ -210,7 +211,7 @@ int main(int argc, char *const argv[])
retval = chip_info();
if (retval) {
bfdev_errname(retval, &errname);
printf("Failed to read info: %s\n", errname);
bfdev_log_err("Failed to read info: %s\n", errname);
return retval;
}
}
Expand All @@ -219,7 +220,7 @@ int main(int argc, char *const argv[])
retval = spinor_erase(eidx, esize);
if (retval) {
bfdev_errname(retval, &errname);
printf("Failed to erase chip: %s\n", errname);
bfdev_log_err("Failed to erase chip: %s\n", errname);
return retval;
}
}
Expand All @@ -228,7 +229,7 @@ int main(int argc, char *const argv[])
retval = flash_bmac(bmac);
if (retval) {
bfdev_errname(retval, &errname);
printf("Failed to flash bt mac: %s\n", errname);
bfdev_log_err("Failed to flash bt mac: %s\n", errname);
return retval;
}
}
Expand All @@ -237,7 +238,7 @@ int main(int argc, char *const argv[])
retval = flash_wmac(wmac);
if (retval) {
bfdev_errname(retval, &errname);
printf("Failed to flash wifi mac: %s\n", errname);
bfdev_log_err("Failed to flash wifi mac: %s\n", errname);
return retval;
}
}
Expand All @@ -246,7 +247,7 @@ int main(int argc, char *const argv[])
retval = flash_gain(gain);
if (retval) {
bfdev_errname(retval, &errname);
printf("Failed to flash rf gain: %s\n", errname);
bfdev_log_err("Failed to flash rf gain: %s\n", errname);
return retval;
}
}
Expand All @@ -258,26 +259,26 @@ int main(int argc, char *const argv[])

fd = open(file, O_RDONLY);
if (fd < 0) {
printf("Failed to open file\n");
bfdev_log_err("Failed to open file\n");
return fd;
}

retval = fstat(fd, &stat);
if (retval) {
printf("Failed to fstat file\n");
bfdev_log_err("Failed to fstat file\n");
return retval;
}

map = mmap(NULL, stat.st_size, PROT_READ, MAP_SHARED, fd, 0);
if (map == MAP_FAILED) {
printf("Failed to mmap file\n");
bfdev_log_err("Failed to mmap file\n");
return -BFDEV_ENOMEM;
}

retval = spinor_flash(map, stat.st_size);
if (retval) {
bfdev_errname(retval, &errname);
printf("Failed to flash chip: %s\n", errname);
bfdev_log_err("Failed to flash chip: %s\n", errname);
return retval;
}

Expand All @@ -289,7 +290,7 @@ int main(int argc, char *const argv[])
retval = chip_reset();
if (retval) {
bfdev_errname(retval, &errname);
printf("Failed to reset chip: %s\n", errname);
bfdev_log_err("Failed to reset chip: %s\n", errname);
return retval;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/term.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ term_setup(unsigned int speed, int databits, int stopbits, char parity)
}

int
term_rts(bool enable)
term_reset(bool enable)
{
unsigned int state;
int retval;
Expand Down
2 changes: 1 addition & 1 deletion src/term.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extern int
term_setup(unsigned int speed, int databits, int stopbits, char parity);

extern int
term_rts(bool enable);
term_reset(bool enable);

extern int
term_read(void *data, size_t len);
Expand Down
Loading

0 comments on commit c51f361

Please sign in to comment.