Skip to content
This repository has been archived by the owner on Feb 2, 2024. It is now read-only.

Commit

Permalink
Add support for BTVER 2.7 quirk for ISP_KEY setup
Browse files Browse the repository at this point in the history
Bootloader version 2.7 (and maybe later) doesn't response to the
set ISP_KEY command with a checksum of key. It simply returns 0.
  • Loading branch information
jmaselbas committed Jul 19, 2022
1 parent 7404236 commit 9fdfcbb
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions wch-isp.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ typedef uint32_t u32;
#define MAX_PACKET_SIZE 64
#define SECTOR_SIZE 1024

#define BTVER_2_6 0x0206
#define BTVER_2_7 0x0207

/*
* All readable and writable registers.
* - `RDPR`: Read Protection
Expand Down Expand Up @@ -445,16 +448,21 @@ isp_init(void)
memset(xor_key, sum, sizeof(xor_key));
xor_key[7] = xor_key[0] + dev_id;

/* send the isp key, the reply has a check sum of the xor_key used */
/* send the isp key */
cmd_isp_key(sizeof(isp_key), isp_key, &rsp);

/* do the same on our side */
for (sum = 0, i = 0; i < sizeof(xor_key); i++)
sum += xor_key[i];

/* verify that we both are using the same xor_key (thanks to the checksum) */
if (dev_btver >= BTVER_2_7) {
/* bootloader version 2.7 (and maybe onward) simply send zero */
sum = 0;
} else {
/* bootloader version 2.6 (and maybe prior versions) send back
* the a checksum of the xor_key. This response can be used to
* make sure we are in sync. */
for (sum = 0, i = 0; i < sizeof(xor_key); i++)
sum += xor_key[i];
}
if (rsp != sum)
die("failed set isp key, wrong checksum, got %x (exp %x)\n", rsp, sum);
die("failed set isp key, wrong reply, got %x (exp %x)\n", rsp, sum);
}

static void
Expand Down

0 comments on commit 9fdfcbb

Please sign in to comment.