SendCommandOLD: hid-flasher

This commit is contained in:
Philippe Teuwen 2019-04-19 02:10:52 +02:00
parent b68ccfa7b8
commit 128d90ca3c

View file

@ -260,8 +260,7 @@ fail:
// Get the state of the proxmark, backwards compatible // Get the state of the proxmark, backwards compatible
static int get_proxmark_state(uint32_t *state) { static int get_proxmark_state(uint32_t *state) {
PacketCommandOLD c = {CMD_DEVICE_INFO}; SendCommandOLD(CMD_DEVICE_INFO, 0, 0, 0, NULL, 0);
SendCommand(&c);
PacketResponseOLD resp; PacketResponseOLD resp;
ReceiveCommand(&resp); ReceiveCommand(&resp);
@ -303,20 +302,16 @@ static int enter_bootloader(void) {
if (state & DEVICE_INFO_FLAG_CURRENT_MODE_OS) { if (state & DEVICE_INFO_FLAG_CURRENT_MODE_OS) {
fprintf(stderr, "Entering bootloader...\n"); fprintf(stderr, "Entering bootloader...\n");
PacketCommandOLD c;
memset(&c, 0, sizeof(c));
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.
c.cmd = CMD_START_FLASH; SendCommandOLD(CMD_START_FLASH, 0, 0, 0, NULL, 0);
SendCommand(&c);
fprintf(stderr, "(Press and release the button only to abort)\n"); fprintf(stderr, "(Press and release the button only to abort)\n");
} 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
c.cmd = CMD_HARDWARE_RESET; SendCommandOLD(CMD_HARDWARE_RESET, 0, 0, 0, NULL, 0);
SendCommand(&c);
fprintf(stderr, "Press and hold down button NOW if your bootloader requires it.\n"); fprintf(stderr, "Press and hold down button NOW if your bootloader requires it.\n");
} }
fprintf(stderr, "Waiting for Proxmark3 to reappear on USB..."); fprintf(stderr, "Waiting for Proxmark3 to reappear on USB...");
@ -360,18 +355,11 @@ int flash_start_flashing(int enable_bl_writes) {
if (state & DEVICE_INFO_FLAG_UNDERSTANDS_START_FLASH) { if (state & DEVICE_INFO_FLAG_UNDERSTANDS_START_FLASH) {
// This command is stupid. Why the heck does it care which area we're // This command is stupid. Why the heck does it care which area we're
// flashing, as long as it's not the bootloader area? The mind boggles. // flashing, as long as it's not the bootloader area? The mind boggles.
PacketCommandOLD c = {CMD_START_FLASH};
if (enable_bl_writes) { if (enable_bl_writes) {
c.arg[0] = FLASH_START; SendCommandOLD(CMD_START_FLASH, FLASH_START, FLASH_END, START_FLASH_MAGIC, NULL, 0);
c.arg[1] = FLASH_END;
c.arg[2] = START_FLASH_MAGIC;
} else { } else {
c.arg[0] = BOOTLOADER_END; SendCommandOLD(CMD_START_FLASH,BOOTLOADER_END, FLASH_END, 0, NULL, 0);
c.arg[1] = FLASH_END;
c.arg[2] = 0;
} }
SendCommand(&c);
return wait_for_ack(); return wait_for_ack();
} else { } else {
fprintf(stderr, "Note: Your bootloader does not understand the new START_FLASH command\n"); fprintf(stderr, "Note: Your bootloader does not understand the new START_FLASH command\n");
@ -387,19 +375,13 @@ static int write_block(uint32_t address, uint8_t *data, uint32_t length) {
memset(block_buf, 0xFF, BLOCK_SIZE); memset(block_buf, 0xFF, BLOCK_SIZE);
memcpy(block_buf, data, length); memcpy(block_buf, data, length);
PacketCommandOLD c = {CMD_SETUP_WRITE};
for (int i = 0; i < 240; i += 48) { for (int i = 0; i < 240; i += 48) {
memcpy(c.d.asBytes, block_buf + i, 48); SendCommandOLD(CMD_SETUP_WRITE, i / 4, 0, 0, block_buf + i, 48);
c.arg[0] = i / 4;
SendCommand(&c);
if (wait_for_ack() < 0) if (wait_for_ack() < 0)
return -1; return -1;
} }
c.cmd = CMD_FINISH_WRITE; SendCommandOLD(CMD_FINISH_WRITE, address, 0, 0, block_buf + 240, 16);
c.arg[0] = address;
memcpy(c.d.asBytes, block_buf + 240, 16);
SendCommand(&c);
return wait_for_ack(); return wait_for_ack();
} }
@ -458,8 +440,7 @@ void flash_free(flash_file_t *ctx) {
// just reset the unit // just reset the unit
int flash_stop_flashing(void) { int flash_stop_flashing(void) {
PacketCommandOLD c = {CMD_HARDWARE_RESET}; SendCommandOLD(CMD_HARDWARE_RESET, 0, 0, 0, NULL, 0);
SendCommand(&c);
msleep(100); msleep(100);
return 0; return 0;
} }