From 551d8a8cfe187d09ab3c07fbdf6efcb4cafc58ab Mon Sep 17 00:00:00 2001 From: sq5bpf Date: Tue, 3 Oct 2023 11:01:40 +0200 Subject: [PATCH] add an option to flash files smaller than 50kB if the user knows what he's doing and bump version to 0.6 --- README | 2 +- k5prog.c | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/README b/README index 42669d5..c506d09 100644 --- a/README +++ b/README @@ -1,4 +1,4 @@ -k5prog - Quansheng UV-K5 EEPROM and flash programmer v0.5 +k5prog - Quansheng UV-K5 EEPROM and flash programmer v0.6 (c) 2023 Jacek Lipkowski This program can read and write the eeprom of Quansheng UV-K5. diff --git a/k5prog.c b/k5prog.c index 935dd6f..47c0091 100644 --- a/k5prog.c +++ b/k5prog.c @@ -1,4 +1,4 @@ -/* Quansheng UV-K5 EEPROM programmer v0.4 +/* Quansheng UV-K5 EEPROM programmer v0.6 * (c) 2023 Jacek Lipkowski * * This program can read and write the eeprom of Quansheng UVK5 Mark II @@ -50,7 +50,7 @@ #include #include "uvk5.h" -#define VERSION "Quansheng UV-K5 EEPROM programmer v0.5 (c) 2023 Jacek Lipkowski " +#define VERSION "Quansheng UV-K5 EEPROM programmer v0.6 (c) 2023 Jacek Lipkowski " #define MODE_NONE 0 #define MODE_READ 1 @@ -709,7 +709,7 @@ int k5_writeflash(int fd, unsigned char *buf, int len, int offset,int max_flash } /* we're still getting "i'm in flash mode packets", can happen after the first flash command, ignore it */ if ((cmd->cmd[0]==0x18)&&(cmd->cmd[1]==0x05)&&(cmd->cmd[2]==0x20)&&(cmd->cmd[3]==0x0)&&(cmd->cmd[4]==0x1)&&(cmd->cmd[5]==0x2)&&(cmd->cmd[6]==0x2)) { - if (verbose>1) printf("&&&&| ignoring \"i'm in flash mode\" packet\n"); + if (verbose>1) printf("&&&&| ignoring \"i'm in flash mode\" packet\n"); destroy_k5_struct(cmd); continue; } @@ -1007,8 +1007,11 @@ int main(int argc,char **argv) close(ffd); /* arbitrary limit do that someone doesn't flash some random short file */ - if (flash_length<50000) { + if ((i_know_what_im_doing<5)&&(flash_length<50000)) { fprintf(stderr,"Failed to read whole eeprom from file %s (read %i), file too short or some other error\n",file,flash_length); + if (flash_length>0) { + fprintf(stderr,"This failsafe is here so that people don't mistake config files with flash.\nIt can be ignored with an 'i know what i'm doing' value of at least 5\n"); + } exit(1); } if (verbose>0) { printf ("Read file %s success\n",flash_file); } @@ -1031,10 +1034,10 @@ int main(int argc,char **argv) exit(1); } - r=wait_flash_message(fd,10000); - if (!r) exit(0); + r=wait_flash_message(fd,10000); + if (!r) exit(0); - k5_send_flash_version_message(fd); + k5_send_flash_version_message(fd); for(i=write_offset; i