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

Commit

Permalink
Add unlock methon via CFG_ROM_READ (ch58x, ...)
Browse files Browse the repository at this point in the history
  • Loading branch information
COKPOWEHEU committed Jun 15, 2024
1 parent 38619f8 commit 45f80d4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# SPDX-License-Identifier: GPL-2.0-only
VERSION = 0.1.0
VERSION = 0.1.1
NAME := wch-isp

# Install paths
Expand Down
24 changes: 17 additions & 7 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,6 @@ uint32_t port_speed = 0;
char *dev_name = NULL;
char *filename = NULL;
char *optionstr = NULL;
const char optstr_unlock_RDPR[] = "RDPR=0xA5";
wch_if_debug debug_func = NULL;
wch_if_match match_func = match_rtsdtr;
uint32_t writeaddr = 0;
Expand Down Expand Up @@ -910,17 +909,28 @@ int main(int argc, char **argv){
wch_info_regs_import(info, dev.optionbytes, sizeof(dev.optionbytes)/sizeof(dev.optionbytes[0]));

if(run_flags.cmd == COMMAND_UNLOCK){
optionstr = NULL;
wch_regs_t *reg = NULL;
wch_bitfield_t *rdpr = NULL;
wch_bitfield_t *bits = NULL;
char res = dev_read_options(&dev);
if(!res){fprintf(stderr, "Reading option bytes from MCU: failed\n"); break;}
wch_info_regs_import(info, dev.optionbytes, sizeof(dev.optionbytes)/sizeof(dev.optionbytes[0]));
reg = wch_bitfield_byname(info, "RDPR", &rdpr);
if(reg!=NULL && rdpr != NULL){
uint32_t val = wch_bitfield_val(rdpr, reg->curval);
//Unlock via RDPR (set to 0xA5)
reg = wch_bitfield_byname(info, "RDPR", &bits);
if(reg!=NULL && bits != NULL){
uint32_t val = wch_bitfield_val(bits, reg->curval);
if(val == 0xA5){printf("Device is already unlocked; Do nothing\n"); break;}
optionstr = (char*)optstr_unlock_RDPR;
}else{
optionstr = "RDPR=0xA5";
}
//Unlock via CFG_ROM_READ (set to 1)
reg = wch_bitfield_byname(info, "CFG_ROM_READ", &bits);
if(reg!=NULL && bits != NULL){
uint32_t val = wch_bitfield_val(bits, reg->curval);
if(val == 1){printf("Device is already unlocked; Do nothing\n"); break;}
optionstr = "CFG_ROM_READ=1";
}

if(optionstr == NULL){
printf("The unlocking method is unknown for this device; Do nothing\n");
break;
}
Expand Down

0 comments on commit 45f80d4

Please sign in to comment.