mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-19 21:03:48 -07:00
Use PrintAndLogEx in flasher
This commit is contained in:
parent
0a4b90ac20
commit
5c9c38ff71
5 changed files with 92 additions and 82 deletions
|
@ -544,12 +544,12 @@ bool OpenProxmark(void *port, bool wait_for_port, int timeout, bool flash_mode,
|
||||||
|
|
||||||
// check result of uart opening
|
// check result of uart opening
|
||||||
if (sp == INVALID_SERIAL_PORT) {
|
if (sp == INVALID_SERIAL_PORT) {
|
||||||
PrintAndLogEx(WARNING, _RED_("ERROR:") "invalid serial port " _YELLOW_("%s"), portname);
|
PrintAndLogEx(WARNING, "\n" _RED_("ERROR:") "invalid serial port " _YELLOW_("%s"), portname);
|
||||||
sp = NULL;
|
sp = NULL;
|
||||||
serial_port_name = NULL;
|
serial_port_name = NULL;
|
||||||
return false;
|
return false;
|
||||||
} else if (sp == CLAIMED_SERIAL_PORT) {
|
} else if (sp == CLAIMED_SERIAL_PORT) {
|
||||||
PrintAndLogEx(WARNING, _RED_("ERROR:") "serial port " _YELLOW_("%s") " is claimed by another process", portname);
|
PrintAndLogEx(WARNING, "\n" _RED_("ERROR:") "serial port " _YELLOW_("%s") " is claimed by another process", portname);
|
||||||
sp = NULL;
|
sp = NULL;
|
||||||
serial_port_name = NULL;
|
serial_port_name = NULL;
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -40,13 +40,13 @@ static int build_segs_from_phdrs(flash_file_t *ctx, FILE *fd, Elf32_Phdr *phdrs,
|
||||||
|
|
||||||
ctx->segments = calloc(sizeof(flash_seg_t) * num_phdrs, sizeof(uint8_t));
|
ctx->segments = calloc(sizeof(flash_seg_t) * num_phdrs, sizeof(uint8_t));
|
||||||
if (!ctx->segments) {
|
if (!ctx->segments) {
|
||||||
fprintf(stderr, "Out of memory\n");
|
PrintAndLogEx(ERR, "Out of memory");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
ctx->num_segs = 0;
|
ctx->num_segs = 0;
|
||||||
seg = ctx->segments;
|
seg = ctx->segments;
|
||||||
|
|
||||||
fprintf(stdout, "Loading usable ELF segments:\n");
|
PrintAndLogEx(NORMAL, "Loading usable ELF segments:");
|
||||||
for (int i = 0; i < num_phdrs; i++) {
|
for (int i = 0; i < num_phdrs; i++) {
|
||||||
if (le32(phdr->p_type) != PT_LOAD) {
|
if (le32(phdr->p_type) != PT_LOAD) {
|
||||||
phdr++;
|
phdr++;
|
||||||
|
@ -62,27 +62,27 @@ static int build_segs_from_phdrs(flash_file_t *ctx, FILE *fd, Elf32_Phdr *phdrs,
|
||||||
phdr++;
|
phdr++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
fprintf(stdout, "%d: V 0x%08x P 0x%08x (0x%08x->0x%08x) [%c%c%c] @0x%x\n",
|
PrintAndLogEx(NORMAL, "%d: V 0x%08x P 0x%08x (0x%08x->0x%08x) [%c%c%c] @0x%x",
|
||||||
i, vaddr, paddr, filesz, memsz,
|
i, vaddr, paddr, filesz, memsz,
|
||||||
(flags & PF_R) ? 'R' : ' ',
|
(flags & PF_R) ? 'R' : ' ',
|
||||||
(flags & PF_W) ? 'W' : ' ',
|
(flags & PF_W) ? 'W' : ' ',
|
||||||
(flags & PF_X) ? 'X' : ' ',
|
(flags & PF_X) ? 'X' : ' ',
|
||||||
offset);
|
offset);
|
||||||
if (filesz != memsz) {
|
if (filesz != memsz) {
|
||||||
fprintf(stderr, "Error: PHDR file size does not equal memory size\n"
|
PrintAndLogEx(ERR, "Error: PHDR file size does not equal memory size\n"
|
||||||
"(DATA+BSS PHDRs do not make sense on ROM platforms!)\n");
|
"(DATA+BSS PHDRs do not make sense on ROM platforms!)");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (paddr < last_end) {
|
if (paddr < last_end) {
|
||||||
fprintf(stderr, "Error: PHDRs not sorted or overlap\n");
|
PrintAndLogEx(ERR, "Error: PHDRs not sorted or overlap");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (paddr < FLASH_START || (paddr + filesz) > FLASH_END) {
|
if (paddr < FLASH_START || (paddr + filesz) > FLASH_END) {
|
||||||
fprintf(stderr, "Error: PHDR is not contained in Flash\n");
|
PrintAndLogEx(ERR, "Error: PHDR is not contained in Flash");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (vaddr >= FLASH_START && vaddr < FLASH_END && (flags & PF_W)) {
|
if (vaddr >= FLASH_START && vaddr < FLASH_END && (flags & PF_W)) {
|
||||||
fprintf(stderr, "Error: Flash VMA segment is writable\n");
|
PrintAndLogEx(ERR, "Error: Flash VMA segment is writable");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,11 +90,11 @@ static int build_segs_from_phdrs(flash_file_t *ctx, FILE *fd, Elf32_Phdr *phdrs,
|
||||||
// make extra space if we need to move the data forward
|
// make extra space if we need to move the data forward
|
||||||
data = calloc(filesz + BLOCK_SIZE, sizeof(uint8_t));
|
data = calloc(filesz + BLOCK_SIZE, sizeof(uint8_t));
|
||||||
if (!data) {
|
if (!data) {
|
||||||
fprintf(stderr, "Error: Out of memory\n");
|
PrintAndLogEx(ERR, "Error: Out of memory");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (fseek(fd, offset, SEEK_SET) < 0 || fread(data, 1, filesz, fd) != filesz) {
|
if (fseek(fd, offset, SEEK_SET) < 0 || fread(data, 1, filesz, fd) != filesz) {
|
||||||
fprintf(stderr, "Error while reading PHDR payload\n");
|
PrintAndLogEx(ERR, "Error while reading PHDR payload");
|
||||||
free(data);
|
free(data);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -113,17 +113,17 @@ static int build_segs_from_phdrs(flash_file_t *ctx, FILE *fd, Elf32_Phdr *phdrs,
|
||||||
uint32_t hole = this_offset - prev_seg->length;
|
uint32_t hole = this_offset - prev_seg->length;
|
||||||
uint8_t *new_data = calloc(new_length, sizeof(uint8_t));
|
uint8_t *new_data = calloc(new_length, sizeof(uint8_t));
|
||||||
if (!new_data) {
|
if (!new_data) {
|
||||||
fprintf(stderr, "Error: Out of memory\n");
|
PrintAndLogEx(ERR, "Error: Out of memory");
|
||||||
free(data);
|
free(data);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
memset(new_data, 0xff, new_length);
|
memset(new_data, 0xff, new_length);
|
||||||
memcpy(new_data, prev_seg->data, prev_seg->length);
|
memcpy(new_data, prev_seg->data, prev_seg->length);
|
||||||
memcpy(new_data + this_offset, data, filesz);
|
memcpy(new_data + this_offset, data, filesz);
|
||||||
fprintf(stderr, "Note: Extending previous segment from 0x%x to 0x%x bytes\n",
|
PrintAndLogEx(NORMAL, "Note: Extending previous segment from 0x%x to 0x%x bytes",
|
||||||
prev_seg->length, new_length);
|
prev_seg->length, new_length);
|
||||||
if (hole)
|
if (hole)
|
||||||
fprintf(stderr, "Note: 0x%x-byte hole created\n", hole);
|
PrintAndLogEx(NORMAL, "Note: 0x%x-byte hole created", hole);
|
||||||
free(data);
|
free(data);
|
||||||
free(prev_seg->data);
|
free(prev_seg->data);
|
||||||
prev_seg->data = new_data;
|
prev_seg->data = new_data;
|
||||||
|
@ -133,7 +133,7 @@ static int build_segs_from_phdrs(flash_file_t *ctx, FILE *fd, Elf32_Phdr *phdrs,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fprintf(stderr, "Warning: segment does not begin on a block boundary, will pad\n");
|
PrintAndLogEx(WARNING, "Warning: segment does not begin on a block boundary, will pad");
|
||||||
memmove(data + block_offset, data, filesz);
|
memmove(data + block_offset, data, filesz);
|
||||||
memset(data, 0xFF, block_offset);
|
memset(data, 0xFF, block_offset);
|
||||||
filesz += block_offset;
|
filesz += block_offset;
|
||||||
|
@ -158,19 +158,19 @@ static int check_segs(flash_file_t *ctx, int can_write_bl) {
|
||||||
flash_seg_t *seg = &ctx->segments[i];
|
flash_seg_t *seg = &ctx->segments[i];
|
||||||
|
|
||||||
if (seg->start & (BLOCK_SIZE - 1)) {
|
if (seg->start & (BLOCK_SIZE - 1)) {
|
||||||
fprintf(stderr, "Error: Segment is not aligned\n");
|
PrintAndLogEx(ERR, "Error: Segment is not aligned");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (seg->start < FLASH_START) {
|
if (seg->start < FLASH_START) {
|
||||||
fprintf(stderr, "Error: Segment is outside of flash bounds\n");
|
PrintAndLogEx(ERR, "Error: Segment is outside of flash bounds");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (seg->start + seg->length > FLASH_END) {
|
if (seg->start + seg->length > FLASH_END) {
|
||||||
fprintf(stderr, "Error: Segment is outside of flash bounds\n");
|
PrintAndLogEx(ERR, "Error: Segment is outside of flash bounds");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (!can_write_bl && seg->start < BOOTLOADER_END) {
|
if (!can_write_bl && seg->start < BOOTLOADER_END) {
|
||||||
fprintf(stderr, "Attempted to write bootloader but bootloader writes are not enabled\n");
|
PrintAndLogEx(ERR, "Attempted to write bootloader but bootloader writes are not enabled");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -187,52 +187,52 @@ int flash_load(flash_file_t *ctx, const char *name, int can_write_bl) {
|
||||||
|
|
||||||
fd = fopen(name, "rb");
|
fd = fopen(name, "rb");
|
||||||
if (!fd) {
|
if (!fd) {
|
||||||
fprintf(stderr, _RED_("Could not open file") "%s >>> ", name);
|
PrintAndLogEx(ERR, _RED_("Could not open file") "%s >>> ", name);
|
||||||
perror(NULL);
|
perror(NULL);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stdout, _BLUE_("Loading ELF file") _YELLOW_("%s") "\n", name);
|
PrintAndLogEx(NORMAL, _BLUE_("Loading ELF file") _YELLOW_("%s"), name);
|
||||||
|
|
||||||
if (fread(&ehdr, sizeof(ehdr), 1, fd) != 1) {
|
if (fread(&ehdr, sizeof(ehdr), 1, fd) != 1) {
|
||||||
fprintf(stderr, "Error while reading ELF file header\n");
|
PrintAndLogEx(ERR, "Error while reading ELF file header");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
if (memcmp(ehdr.e_ident, elf_ident, sizeof(elf_ident))
|
if (memcmp(ehdr.e_ident, elf_ident, sizeof(elf_ident))
|
||||||
|| le32(ehdr.e_version) != 1) {
|
|| le32(ehdr.e_version) != 1) {
|
||||||
fprintf(stderr, "Not an ELF file or wrong ELF type\n");
|
PrintAndLogEx(ERR, "Not an ELF file or wrong ELF type");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
if (le16(ehdr.e_type) != ET_EXEC) {
|
if (le16(ehdr.e_type) != ET_EXEC) {
|
||||||
fprintf(stderr, "ELF is not executable\n");
|
PrintAndLogEx(ERR, "ELF is not executable");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
if (le16(ehdr.e_machine) != EM_ARM) {
|
if (le16(ehdr.e_machine) != EM_ARM) {
|
||||||
fprintf(stderr, "Wrong ELF architecture\n");
|
PrintAndLogEx(ERR, "Wrong ELF architecture");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
if (!ehdr.e_phnum || !ehdr.e_phoff) {
|
if (!ehdr.e_phnum || !ehdr.e_phoff) {
|
||||||
fprintf(stderr, "ELF has no PHDRs\n");
|
PrintAndLogEx(ERR, "ELF has no PHDRs");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
if (le16(ehdr.e_phentsize) != sizeof(Elf32_Phdr)) {
|
if (le16(ehdr.e_phentsize) != sizeof(Elf32_Phdr)) {
|
||||||
// could be a structure padding issue...
|
// could be a structure padding issue...
|
||||||
fprintf(stderr, "Either the ELF file or this code is made of fail\n");
|
PrintAndLogEx(ERR, "Either the ELF file or this code is made of fail");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
num_phdrs = le16(ehdr.e_phnum);
|
num_phdrs = le16(ehdr.e_phnum);
|
||||||
|
|
||||||
phdrs = calloc(le16(ehdr.e_phnum) * sizeof(Elf32_Phdr), sizeof(uint8_t));
|
phdrs = calloc(le16(ehdr.e_phnum) * sizeof(Elf32_Phdr), sizeof(uint8_t));
|
||||||
if (!phdrs) {
|
if (!phdrs) {
|
||||||
fprintf(stderr, "Out of memory\n");
|
PrintAndLogEx(ERR, "Out of memory");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
if (fseek(fd, le32(ehdr.e_phoff), SEEK_SET) < 0) {
|
if (fseek(fd, le32(ehdr.e_phoff), SEEK_SET) < 0) {
|
||||||
fprintf(stderr, "Error while reading ELF PHDRs\n");
|
PrintAndLogEx(ERR, "Error while reading ELF PHDRs");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
if (fread(phdrs, sizeof(Elf32_Phdr), num_phdrs, fd) != num_phdrs) {
|
if (fread(phdrs, sizeof(Elf32_Phdr), num_phdrs, fd) != num_phdrs) {
|
||||||
fprintf(stderr, "Error while reading ELF PHDRs\n");
|
PrintAndLogEx(ERR, "Error while reading ELF PHDRs");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,7 +279,7 @@ static int get_proxmark_state(uint32_t *state) {
|
||||||
*state = resp.oldarg[0];
|
*state = resp.oldarg[0];
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, _RED_("Error:") "Couldn't get Proxmark3 state, bad response type: 0x%04x\n", resp.cmd);
|
PrintAndLogEx(ERR, _RED_("Error:") "Couldn't get Proxmark3 state, bad response type: 0x%04x", resp.cmd);
|
||||||
return -1;
|
return -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -298,18 +298,18 @@ static int enter_bootloader(char *serial_port_name) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (state & DEVICE_INFO_FLAG_CURRENT_MODE_OS) {
|
if (state & DEVICE_INFO_FLAG_CURRENT_MODE_OS) {
|
||||||
fprintf(stdout, _BLUE_("Entering bootloader...") "\n");
|
PrintAndLogEx(NORMAL, _BLUE_("Entering bootloader..."));
|
||||||
|
|
||||||
if ((state & DEVICE_INFO_FLAG_BOOTROM_PRESENT)
|
if ((state & DEVICE_INFO_FLAG_BOOTROM_PRESENT)
|
||||||
&& (state & DEVICE_INFO_FLAG_OSIMAGE_PRESENT)) {
|
&& (state & DEVICE_INFO_FLAG_OSIMAGE_PRESENT)) {
|
||||||
// New style handover: Send CMD_START_FLASH, which will reset the board
|
// New style handover: Send CMD_START_FLASH, which will reset the board
|
||||||
// and enter the bootrom on the next boot.
|
// and enter the bootrom on the next boot.
|
||||||
SendCommandOLD(CMD_START_FLASH, 0, 0, 0, NULL, 0);
|
SendCommandOLD(CMD_START_FLASH, 0, 0, 0, NULL, 0);
|
||||||
fprintf(stdout, "(Press and release the button only to abort)\n");
|
PrintAndLogEx(NORMAL, "(Press and release the button only to abort)");
|
||||||
} else {
|
} else {
|
||||||
// Old style handover: Ask the user to press the button, then reset the board
|
// Old style handover: Ask the user to press the button, then reset the board
|
||||||
SendCommandOLD(CMD_HARDWARE_RESET, 0, 0, 0, NULL, 0);
|
SendCommandOLD(CMD_HARDWARE_RESET, 0, 0, 0, NULL, 0);
|
||||||
fprintf(stdout, "Press and hold down button NOW if your bootloader requires it.\n");
|
PrintAndLogEx(NORMAL, "Press and hold down button NOW if your bootloader requires it.");
|
||||||
}
|
}
|
||||||
msleep(100);
|
msleep(100);
|
||||||
CloseProxmark();
|
CloseProxmark();
|
||||||
|
@ -318,15 +318,15 @@ static int enter_bootloader(char *serial_port_name) {
|
||||||
|
|
||||||
bool opened = OpenProxmark(serial_port_name, true, 60, true, FLASHMODE_SPEED);
|
bool opened = OpenProxmark(serial_port_name, true, 60, true, FLASHMODE_SPEED);
|
||||||
if (opened) {
|
if (opened) {
|
||||||
fprintf(stdout, " " _GREEN_("Found") "\n");
|
PrintAndLogEx(NORMAL, " " _GREEN_("Found"));
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stdout, _RED_("Error:") "Proxmark3 not found.\n");
|
PrintAndLogEx(ERR, _RED_("Error:") "Proxmark3 not found.");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, _RED_("Error:") "Unknown Proxmark3 mode\n");
|
PrintAndLogEx(ERR, _RED_("Error:") "Unknown Proxmark3 mode");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -334,7 +334,7 @@ static int wait_for_ack(PacketResponseNG *ack) {
|
||||||
WaitForResponse(CMD_UNKNOWN, ack);
|
WaitForResponse(CMD_UNKNOWN, ack);
|
||||||
|
|
||||||
if (ack->cmd != CMD_ACK) {
|
if (ack->cmd != CMD_ACK) {
|
||||||
printf("Error: Unexpected reply 0x%04x %s (expected ACK)\n",
|
PrintAndLogEx(ERR, "Error: Unexpected reply 0x%04x %s (expected ACK)",
|
||||||
ack->cmd,
|
ack->cmd,
|
||||||
(ack->cmd == CMD_NACK) ? "NACK" : ""
|
(ack->cmd == CMD_NACK) ? "NACK" : ""
|
||||||
);
|
);
|
||||||
|
@ -365,8 +365,8 @@ int flash_start_flashing(int enable_bl_writes, char *serial_port_name) {
|
||||||
}
|
}
|
||||||
return wait_for_ack(&resp);
|
return wait_for_ack(&resp);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, _RED_("Note: Your bootloader does not understand the new START_FLASH command") "\n");
|
PrintAndLogEx(ERR, _RED_("Note: Your bootloader does not understand the new START_FLASH command"));
|
||||||
fprintf(stderr, _RED_("It is recommended that you update your bootloader") "\n\n");
|
PrintAndLogEx(ERR, _RED_("It is recommended that you update your bootloader") "\n");
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -383,17 +383,17 @@ static int write_block(uint32_t address, uint8_t *data, uint32_t length) {
|
||||||
bool lock_error = resp.oldarg[0] & AT91C_MC_LOCKE;
|
bool lock_error = resp.oldarg[0] & AT91C_MC_LOCKE;
|
||||||
bool prog_error = resp.oldarg[0] & AT91C_MC_PROGE;
|
bool prog_error = resp.oldarg[0] & AT91C_MC_PROGE;
|
||||||
bool security_bit = resp.oldarg[0] & AT91C_MC_SECURITY;
|
bool security_bit = resp.oldarg[0] & AT91C_MC_SECURITY;
|
||||||
printf("%s", lock_error ? " Lock Error\n" : "");
|
PrintAndLogEx(NORMAL, "%s", lock_error ? " Lock Error" : "");
|
||||||
printf("%s", prog_error ? " Invalid Command or bad Keyword\n" : "");
|
PrintAndLogEx(NORMAL, "%s", prog_error ? " Invalid Command or bad Keyword" : "");
|
||||||
printf("%s", security_bit ? " Security Bit is set!\n" : "");
|
PrintAndLogEx(NORMAL, "%s", security_bit ? " Security Bit is set!" : "");
|
||||||
printf(" Lock Bits: 0x%04x\n", lock_bits);
|
PrintAndLogEx(NORMAL, " Lock Bits: 0x%04x", lock_bits);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write a file's segments to Flash
|
// Write a file's segments to Flash
|
||||||
int flash_write(flash_file_t *ctx) {
|
int flash_write(flash_file_t *ctx) {
|
||||||
fprintf(stdout, "Writing segments for file: %s\n", ctx->filename);
|
PrintAndLogEx(NORMAL, "Writing segments for file: %s", ctx->filename);
|
||||||
for (int i = 0; i < ctx->num_segs; i++) {
|
for (int i = 0; i < ctx->num_segs; i++) {
|
||||||
flash_seg_t *seg = &ctx->segments[i];
|
flash_seg_t *seg = &ctx->segments[i];
|
||||||
|
|
||||||
|
@ -401,7 +401,7 @@ int flash_write(flash_file_t *ctx) {
|
||||||
uint32_t blocks = (length + BLOCK_SIZE - 1) / BLOCK_SIZE;
|
uint32_t blocks = (length + BLOCK_SIZE - 1) / BLOCK_SIZE;
|
||||||
uint32_t end = seg->start + length;
|
uint32_t end = seg->start + length;
|
||||||
|
|
||||||
fprintf(stdout, " 0x%08x..0x%08x [0x%x / %u blocks]", seg->start, end - 1, length, blocks);
|
PrintAndLogEx(NORMAL, " 0x%08x..0x%08x [0x%x / %u blocks]", seg->start, end - 1, length, blocks);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
int block = 0;
|
int block = 0;
|
||||||
uint8_t *data = seg->data;
|
uint8_t *data = seg->data;
|
||||||
|
@ -413,8 +413,7 @@ int flash_write(flash_file_t *ctx) {
|
||||||
block_size = BLOCK_SIZE;
|
block_size = BLOCK_SIZE;
|
||||||
|
|
||||||
if (write_block(baddr, data, block_size) < 0) {
|
if (write_block(baddr, data, block_size) < 0) {
|
||||||
fprintf(stderr, " ERROR\n");
|
PrintAndLogEx(ERR, "Error writing block %d of %u", block, blocks);
|
||||||
fprintf(stderr, "Error writing block %d of %u\n", block, blocks);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -425,7 +424,7 @@ int flash_write(flash_file_t *ctx) {
|
||||||
fprintf(stdout, ".");
|
fprintf(stdout, ".");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
fprintf(stdout, _GREEN_("OK") "\n");
|
PrintAndLogEx(NORMAL, _GREEN_("OK"));
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -17,34 +17,35 @@
|
||||||
#include "flash.h"
|
#include "flash.h"
|
||||||
#include "comms.h"
|
#include "comms.h"
|
||||||
#include "usb_cmd.h"
|
#include "usb_cmd.h"
|
||||||
|
#include "ui.h"
|
||||||
|
|
||||||
#define MAX_FILES 4
|
#define MAX_FILES 4
|
||||||
|
|
||||||
void cmd_debug(PacketCommandOLD *c) {
|
void cmd_debug(PacketCommandOLD *c) {
|
||||||
// Debug
|
// Debug
|
||||||
printf("PacketCommandOLD length[len=%zu]\n", sizeof(PacketCommandOLD));
|
PrintAndLogEx(NORMAL, "PacketCommandOLD length[len=%zu]", sizeof(PacketCommandOLD));
|
||||||
printf(" cmd[len=%zu]: %016" PRIx64"\n", sizeof(c->cmd), c->cmd);
|
PrintAndLogEx(NORMAL, " cmd[len=%zu]: %016" PRIx64, sizeof(c->cmd), c->cmd);
|
||||||
printf(" arg0[len=%zu]: %016" PRIx64"\n", sizeof(c->arg[0]), c->arg[0]);
|
PrintAndLogEx(NORMAL, " arg0[len=%zu]: %016" PRIx64, sizeof(c->arg[0]), c->arg[0]);
|
||||||
printf(" arg1[len=%zu]: %016" PRIx64"\n", sizeof(c->arg[1]), c->arg[1]);
|
PrintAndLogEx(NORMAL, " arg1[len=%zu]: %016" PRIx64, sizeof(c->arg[1]), c->arg[1]);
|
||||||
printf(" arg2[len=%zu]: %016" PRIx64"\n", sizeof(c->arg[2]), c->arg[2]);
|
PrintAndLogEx(NORMAL, " arg2[len=%zu]: %016" PRIx64, sizeof(c->arg[2]), c->arg[2]);
|
||||||
printf(" data[len=%zu]: ", sizeof(c->d.asBytes));
|
PrintAndLogEx(NORMAL, " data[len=%zu]: ", sizeof(c->d.asBytes));
|
||||||
|
|
||||||
for (size_t i = 0; i < 16; i++)
|
for (size_t i = 0; i < 16; i++)
|
||||||
printf("%02x", c->d.asBytes[i]);
|
PrintAndLogEx(NORMAL, "%02x", c->d.asBytes[i]);
|
||||||
|
|
||||||
printf("...\n");
|
PrintAndLogEx(NORMAL, "...");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void usage(char *argv0) {
|
static void usage(char *argv0) {
|
||||||
fprintf(stdout, "Usage: %s <port> [-b] image.elf [image.elf...]\n\n", argv0);
|
PrintAndLogEx(NORMAL, "Usage: %s <port> [-b] image.elf [image.elf...]\n", argv0);
|
||||||
fprintf(stdout, "\t-b\tEnable flashing of bootloader area (DANGEROUS)\n\n");
|
PrintAndLogEx(NORMAL, "\t-b\tEnable flashing of bootloader area (DANGEROUS)\n");
|
||||||
fprintf(stdout, "\nExample:\n\n\t %s "SERIAL_PORT_H" armsrc/obj/fullimage.elf\n", argv0);
|
PrintAndLogEx(NORMAL, "\nExample:\n\n\t %s "SERIAL_PORT_H" armsrc/obj/fullimage.elf", argv0);
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
fprintf(stdout, "\nNote (Linux): if the flasher gets stuck in 'Waiting for Proxmark3 to reappear on <DEVICE>',\n");
|
PrintAndLogEx(NORMAL, "\nNote (Linux): if the flasher gets stuck in 'Waiting for Proxmark3 to reappear on <DEVICE>',");
|
||||||
fprintf(stdout, " you need to blacklist Proxmark3 for modem-manager - see wiki for more details:\n\n");
|
PrintAndLogEx(NORMAL, " you need to blacklist Proxmark3 for modem-manager - see wiki for more details:\n");
|
||||||
fprintf(stdout, " https://github.com/Proxmark/proxmark3/wiki/Gentoo Linux\n\n");
|
PrintAndLogEx(NORMAL, " https://github.com/Proxmark/proxmark3/wiki/Gentoo Linux\n");
|
||||||
fprintf(stdout, " https://github.com/Proxmark/proxmark3/wiki/Ubuntu Linux\n\n");
|
PrintAndLogEx(NORMAL, " https://github.com/Proxmark/proxmark3/wiki/Ubuntu Linux\n");
|
||||||
fprintf(stdout, " https://github.com/Proxmark/proxmark3/wiki/OSX\n\n");
|
PrintAndLogEx(NORMAL, " https://github.com/Proxmark/proxmark3/wiki/OSX\n");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,6 +57,14 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
memset(files, 0, sizeof(files));
|
memset(files, 0, sizeof(files));
|
||||||
|
|
||||||
|
session.supports_colors = false;
|
||||||
|
session.stdinOnTTY = isatty(STDIN_FILENO);
|
||||||
|
session.stdoutOnTTY = isatty(STDOUT_FILENO);
|
||||||
|
#if defined(__linux__) || (__APPLE__)
|
||||||
|
if (session.stdinOnTTY && session.stdoutOnTTY)
|
||||||
|
session.supports_colors = true;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (argc < 3) {
|
if (argc < 3) {
|
||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -74,7 +83,7 @@ int main(int argc, char **argv) {
|
||||||
if (res < 0)
|
if (res < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
fprintf(stderr, "\n");
|
PrintAndLogEx(NORMAL, "");
|
||||||
num_files++;
|
num_files++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,27 +91,27 @@ int main(int argc, char **argv) {
|
||||||
char *serial_port_name = argv[1];
|
char *serial_port_name = argv[1];
|
||||||
|
|
||||||
if (!OpenProxmark(serial_port_name, true, 60, true, FLASHMODE_SPEED)) {
|
if (!OpenProxmark(serial_port_name, true, 60, true, FLASHMODE_SPEED)) {
|
||||||
fprintf(stderr, "Could not find Proxmark3 on " _RED_("%s") ".\n\n", serial_port_name);
|
PrintAndLogEx(ERR, "Could not find Proxmark3 on " _RED_("%s") ".\n", serial_port_name);
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, _GREEN_("Found") "\n");
|
PrintAndLogEx(NORMAL, _GREEN_("Found"));
|
||||||
}
|
}
|
||||||
|
|
||||||
res = flash_start_flashing(can_write_bl, serial_port_name);
|
res = flash_start_flashing(can_write_bl, serial_port_name);
|
||||||
if (res < 0)
|
if (res < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
fprintf(stdout, "\n" _BLUE_("Flashing...")"\n");
|
PrintAndLogEx(NORMAL, "\n" _BLUE_("Flashing..."));
|
||||||
|
|
||||||
for (int i = 0; i < num_files; i++) {
|
for (int i = 0; i < num_files; i++) {
|
||||||
res = flash_write(&files[i]);
|
res = flash_write(&files[i]);
|
||||||
if (res < 0)
|
if (res < 0)
|
||||||
return -1;
|
return -1;
|
||||||
flash_free(&files[i]);
|
flash_free(&files[i]);
|
||||||
fprintf(stdout, "\n");
|
PrintAndLogEx(NORMAL, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stdout, _BLUE_("Resetting hardware...") "\n");
|
PrintAndLogEx(NORMAL, _BLUE_("Resetting hardware..."));
|
||||||
|
|
||||||
res = flash_stop_flashing();
|
res = flash_stop_flashing();
|
||||||
if (res < 0)
|
if (res < 0)
|
||||||
|
@ -110,6 +119,6 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
CloseProxmark();
|
CloseProxmark();
|
||||||
|
|
||||||
fprintf(stdout, _BLUE_("All done.") "\n\nHave a nice day!\n");
|
PrintAndLogEx(NORMAL, _BLUE_("All done.") "\n\nHave a nice day!");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
19
client/ui.c
19
client/ui.c
|
@ -28,6 +28,7 @@ bool showDemod = true;
|
||||||
|
|
||||||
pthread_mutex_t print_lock = PTHREAD_MUTEX_INITIALIZER;
|
pthread_mutex_t print_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||||
static const char *logfilename = "proxmark3.log";
|
static const char *logfilename = "proxmark3.log";
|
||||||
|
static void fPrintAndLog(FILE *stream, const char *fmt, ...);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
static float complex cexpf(float complex Z) {
|
static float complex cexpf(float complex Z) {
|
||||||
|
@ -74,10 +75,12 @@ void PrintAndLogEx(logLevel_t level, const char *fmt, ...) {
|
||||||
char *tmp_ptr = NULL;
|
char *tmp_ptr = NULL;
|
||||||
// {NORMAL, SUCCESS, INFO, FAILED, WARNING, ERR, DEBUG}
|
// {NORMAL, SUCCESS, INFO, FAILED, WARNING, ERR, DEBUG}
|
||||||
static const char *prefixes[7] = { "", "[+] ", "[=] ", "[-] ", "[!] ", "[!!] ", "[#] "};
|
static const char *prefixes[7] = { "", "[+] ", "[=] ", "[-] ", "[!] ", "[!!] ", "[#] "};
|
||||||
|
FILE* stream = stdout;
|
||||||
|
|
||||||
switch (level) {
|
switch (level) {
|
||||||
case ERR:
|
case ERR:
|
||||||
strncpy(prefix, _RED_("[!!]"), sizeof(prefix) - 1);
|
strncpy(prefix, _RED_("[!!]"), sizeof(prefix) - 1);
|
||||||
|
stream = stderr;
|
||||||
break;
|
break;
|
||||||
case FAILED:
|
case FAILED:
|
||||||
strncpy(prefix, _RED_("[-]"), sizeof(prefix) - 1);
|
strncpy(prefix, _RED_("[-]"), sizeof(prefix) - 1);
|
||||||
|
@ -104,7 +107,7 @@ void PrintAndLogEx(logLevel_t level, const char *fmt, ...) {
|
||||||
|
|
||||||
// no prefixes for normal
|
// no prefixes for normal
|
||||||
if (level == NORMAL) {
|
if (level == NORMAL) {
|
||||||
PrintAndLog("%s", buffer);
|
fPrintAndLog(stream, "%s", buffer);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,7 +117,7 @@ void PrintAndLogEx(logLevel_t level, const char *fmt, ...) {
|
||||||
|
|
||||||
// line starts with newline
|
// line starts with newline
|
||||||
if (buffer[0] == '\n')
|
if (buffer[0] == '\n')
|
||||||
PrintAndLog("");
|
fPrintAndLog(stream, "");
|
||||||
|
|
||||||
token = strtok_r(buffer, delim, &tmp_ptr);
|
token = strtok_r(buffer, delim, &tmp_ptr);
|
||||||
|
|
||||||
|
@ -129,14 +132,14 @@ void PrintAndLogEx(logLevel_t level, const char *fmt, ...) {
|
||||||
|
|
||||||
token = strtok_r(NULL, delim, &tmp_ptr);
|
token = strtok_r(NULL, delim, &tmp_ptr);
|
||||||
}
|
}
|
||||||
PrintAndLog("%s", buffer2);
|
fPrintAndLog(stream, "%s", buffer2);
|
||||||
} else {
|
} else {
|
||||||
snprintf(buffer2, sizeof(buffer2), "%s%s", prefix, buffer);
|
snprintf(buffer2, sizeof(buffer2), "%s%s", prefix, buffer);
|
||||||
PrintAndLog("%s", buffer2);
|
fPrintAndLog(stream, "%s", buffer2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintAndLog(const char *fmt, ...) {
|
static void fPrintAndLog(FILE *stream, const char *fmt, ...) {
|
||||||
char *saved_line;
|
char *saved_line;
|
||||||
int saved_point;
|
int saved_point;
|
||||||
va_list argptr;
|
va_list argptr;
|
||||||
|
@ -178,9 +181,9 @@ void PrintAndLog(const char *fmt, ...) {
|
||||||
|
|
||||||
bool filter_ansi = !session.supports_colors;
|
bool filter_ansi = !session.supports_colors;
|
||||||
memcpy_filter_ansi(buffer2, buffer, sizeof(buffer), filter_ansi);
|
memcpy_filter_ansi(buffer2, buffer, sizeof(buffer), filter_ansi);
|
||||||
printf("%s", buffer2);
|
fprintf(stream, "%s", buffer2);
|
||||||
printf(" "); // cleaning prompt
|
fprintf(stream, " "); // cleaning prompt
|
||||||
printf("\n");
|
fprintf(stream, "\n");
|
||||||
|
|
||||||
#ifdef RL_STATE_READCMD
|
#ifdef RL_STATE_READCMD
|
||||||
// We are using GNU readline. libedit (OSX) doesn't support this flag.
|
// We are using GNU readline. libedit (OSX) doesn't support this flag.
|
||||||
|
|
|
@ -42,7 +42,6 @@ void ShowGui(void);
|
||||||
void HideGraphWindow(void);
|
void HideGraphWindow(void);
|
||||||
void ShowGraphWindow(void);
|
void ShowGraphWindow(void);
|
||||||
void RepaintGraphWindow(void);
|
void RepaintGraphWindow(void);
|
||||||
void PrintAndLog(const char *fmt, ...);
|
|
||||||
void PrintAndLogOptions(const char *str[][2], size_t size, size_t space);
|
void PrintAndLogOptions(const char *str[][2], size_t size, size_t space);
|
||||||
void PrintAndLogEx(logLevel_t level, const char *fmt, ...);
|
void PrintAndLogEx(logLevel_t level, const char *fmt, ...);
|
||||||
void SetLogFilename(char *fn);
|
void SetLogFilename(char *fn);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue