-
- HidCommand c = {CMD_SETUP_WRITE};
- for (int i = 0; i < 240; i += 48) {
- memcpy(c.d.asBytes, block_buf + i, 48);
- c.arg[0] = i / 4;
- SendCommand_(&c);
- if (wait_for_ack() < 0)
- return -1;
+ UsbCommand c = {CMD_FINISH_WRITE, {address, 0, 0}};
+ memcpy(c.d.asBytes, block_buf, length);
+ SendCommand(&c);
+ int ret = wait_for_ack(&c);
+ if (ret && c.arg[0]) {
+ uint32_t lock_bits = c.arg[0] >> 16;
+ bool lock_error = c.arg[0] & AT91C_MC_LOCKE;
+ bool prog_error = c.arg[0] & AT91C_MC_PROGE;
+ bool security_bit = c.arg[0] & AT91C_MC_SECURITY;
+ printf("%s", lock_error ? " Lock Error\n" : "");
+ printf("%s", prog_error ? " Invalid Command or bad Keyword\n" : "");
+ printf("%s", security_bit ? " Security Bit is set!\n" : "");
+ printf(" Lock Bits: 0x%04x\n", lock_bits);