add -B "brick my radio" option, make -W option more conservative

pull/3/head
sq5bpf 2023-05-25 22:08:32 +02:00
rodzic f671e72d46
commit ee8c83ef17
2 zmienionych plików z 39 dodań i 22 usunięć

28
README
Wyświetl plik

@ -26,7 +26,7 @@ gives more verbosity.
Read configuration: Read configuration:
sq5bpf@chronos:~/k5prog$ ./k5prog -r -v sq5bpf@chronos:~/k5prog$ ./k5prog -r -v
Quansheng UV-K5 EEPROM programmer v0.1 (c) 2023 Jacek Lipkowski <sq5bpf@lipkowski.org> Quansheng UV-K5 EEPROM programmer v0.2 (c) 2023 Jacek Lipkowski <sq5bpf@lipkowski.org>
k5_prepare: try 0 k5_prepare: try 0
****** Connected to firmware version: [k5_2.01.23] ****** Connected to firmware version: [k5_2.01.23]
@ -37,36 +37,44 @@ The eeprom contents are written to the file k5_eeprom.raw, this can be
changed with the -f option. changed with the -f option.
Write configuration from file k5_eeprom.raw: Write configuration from file k5_eeprom.raw:
sq5bpf@chronos:~/chirp/k5prog$ ./k5prog -w -v sq5bpf@chronos:~/chirp/k5prog$ ./k5prog -w -v
Quansheng UV-K5 EEPROM programmer v0.1 (c) 2023 Jacek Lipkowski <sq5bpf@lipkowski.org> Quansheng UV-K5 EEPROM programmer v0.2 (c) 2023 Jacek Lipkowski <sq5bpf@lipkowski.org>
k5_prepare: try 0 k5_prepare: try 0
****** Connected to firmware version: [k5_2.01.23] ****** Connected to firmware version: [k5_2.01.23]
Read file k5_eeprom.raw success Read file k5_eeprom.raw success
Sucessfuly wrote eeprom Sucessfuly wrote eeprom
The -w option writes only the memory blocks which are written by the original The -w option writes only the memory blocks which are written by the original
radio software, in the same order. radio software, in the same order.
The -W option writes all memory, possibly allowing overwriting of calibration The -W option is a bit more brave, it writes all memory upto 0x1d00. I _think_
data (if there is any) or other data which may be critical to the proper that the radio has calibration data above this address, but of course this is
functioning of your radio. I have used this on my radio, and it still works not certain, because this knowledge is a result of reverse engineering, and not
but please be extra-careful. information from the manufacturer.
The -B option is the "brick my radio" mode. It writes all memory, possibly
allowing overwriting of calibration data (if there is any) or other data which
may be critical to the proper functioning of your radio. I have used this on
my radio, and it still works but please be extra-careful.
Other configuration options are: Other configuration options are:
Quansheng UV-K5 EEPROM programmer v0.1 (c) 2023 Jacek Lipkowski <sq5bpf@lipkowski.org> Quansheng UV-K5 EEPROM programmer v0.2 (c) 2023 Jacek Lipkowski <sq5bpf@lipkowski.org>
cmdline opts: cmdline opts:
-f <file> filename that contains the eeprom dump (default: k5_eeprom.raw) -f <file> filename that contains the eeprom dump (default: k5_eeprom.raw)
-r read eeprom -r read eeprom
-w write eeprom like the original software does (warning: may brick your radio) -w write eeprom like the original software does
-W write all eeprom (even bigger warning: this is sure to brick your radio!) -W write most of the eeprom (but without what i think is calibration data)
-B write ALL of the eeprom (the "brick my radio" mode)
-p <port> device name (default: /dev/ttyUSB0) -p <port> device name (default: /dev/ttyUSB0)
-s <speed> serial speed (default: 38400, the UV-K5 doesn't accept any other speed) -s <speed> serial speed (default: 38400, the UV-K5 doesn't accept any other speed)
-h print this help -h print this help

Wyświetl plik

@ -1,4 +1,4 @@
/* Quansheng UV-K5 EEPROM programmer v0.1 /* Quansheng UV-K5 EEPROM programmer v0.2
* (c) 2023 Jacek Lipkowski <sq5bpf@lipkowski.org> * (c) 2023 Jacek Lipkowski <sq5bpf@lipkowski.org>
* *
* This program can read and write the eeprom of Quansheng UVK5 Mark II * This program can read and write the eeprom of Quansheng UVK5 Mark II
@ -46,15 +46,17 @@
#include <stdint.h> #include <stdint.h>
#include "uvk5.h" #include "uvk5.h"
#define VERSION "Quansheng UV-K5 EEPROM programmer v0.1 (c) 2023 Jacek Lipkowski <sq5bpf@lipkowski.org>" #define VERSION "Quansheng UV-K5 EEPROM programmer v0.2 (c) 2023 Jacek Lipkowski <sq5bpf@lipkowski.org>"
#define MODE_NONE 0 #define MODE_NONE 0
#define MODE_READ 1 #define MODE_READ 1
#define MODE_WRITE 2 #define MODE_WRITE 2
#define MODE_WRITE_ALL 3 #define MODE_WRITE_MOST 3
#define MODE_WRITE_ALL 4
#define UVK5_EEPROM_SIZE 0x2000 #define UVK5_EEPROM_SIZE 0x2000
#define UVK5_EEPROM_SIZE_WITHOUT_CALIBRATION 0x1d00
#define UVK5_EEPROM_BLOCKSIZE 0x80 #define UVK5_EEPROM_BLOCKSIZE 0x80
#define UVK5_PREPARE_TRIES 10 #define UVK5_PREPARE_TRIES 10
@ -514,8 +516,9 @@ void helpme()
"cmdline opts:\n" "cmdline opts:\n"
"-f <file>\tfilename that contains the eeprom dump (default: " DEFAULT_FILE_NAME ")\n" "-f <file>\tfilename that contains the eeprom dump (default: " DEFAULT_FILE_NAME ")\n"
"-r \tread eeprom\n" "-r \tread eeprom\n"
"-w \twrite eeprom like the original software does (warning: may brick your radio)\n" "-w \twrite eeprom like the original software does\n"
"-W \twrite all eeprom (even bigger warning: this is sure to brick your radio!)\n" "-W \twrite most of the eeprom (but without what i think is calibration data)\n"
"-B \twrite ALL of the eeprom (the \"brick my radio\" mode)\n"
"-p <port>\tdevice name (default: " DEFAULT_SERIAL_PORT ")\n" "-p <port>\tdevice name (default: " DEFAULT_SERIAL_PORT ")\n"
"-s <speed>\tserial speed (default: 38400, the UV-K5 doesn't accept any other speed)\n" "-s <speed>\tserial speed (default: 38400, the UV-K5 doesn't accept any other speed)\n"
"-h \tprint this help\n" "-h \tprint this help\n"
@ -585,7 +588,7 @@ void parse_cmdline(int argc, char **argv)
* -v (verbose) * -v (verbose)
*/ */
while ((opt=getopt(argc,argv,"f:rwWp:s:hv"))!=EOF) while ((opt=getopt(argc,argv,"f:rwWBp:s:hv"))!=EOF)
{ {
switch (opt) switch (opt)
{ {
@ -603,6 +606,9 @@ void parse_cmdline(int argc, char **argv)
mode=MODE_WRITE; mode=MODE_WRITE;
break; break;
case 'W': case 'W':
mode=MODE_WRITE_MOST;
break;
case 'B':
mode=MODE_WRITE_ALL; mode=MODE_WRITE_ALL;
break; break;
case 'f': case 'f':
@ -668,9 +674,8 @@ int main(int argc,char **argv)
{ {
int fd,ffd; int fd,ffd;
unsigned char eeprom[UVK5_EEPROM_SIZE]; unsigned char eeprom[UVK5_EEPROM_SIZE];
int i; int i,r,j;
int r;
int j;
printf (VERSION "\n\n"); printf (VERSION "\n\n");
//debtest(); //debtest();
@ -728,6 +733,7 @@ int main(int argc,char **argv)
break; break;
case MODE_WRITE: case MODE_WRITE:
case MODE_WRITE_MOST:
case MODE_WRITE_ALL: case MODE_WRITE_ALL:
/* read file */ /* read file */
ffd=open(file,O_RDONLY); ffd=open(file,O_RDONLY);
@ -742,16 +748,19 @@ int main(int argc,char **argv)
} }
close(ffd); close(ffd);
if (verbose>0) { printf ("Read file %s success\n",file); } if (verbose>0) { printf ("Read file %s success\n",file); }
if (mode==MODE_WRITE_ALL) { if ((mode==MODE_WRITE_ALL) || (mode==MODE_WRITE_MOST)) {
j=UVK5_EEPROM_SIZE_WITHOUT_CALIBRATION;
if (mode==MODE_WRITE_ALL) j=UVK5_EEPROM_SIZE;
/* write to radio */ /* write to radio */
for(i=0;i<UVK5_EEPROM_SIZE; i=i+UVK5_EEPROM_BLOCKSIZE) { for(i=0;i<j; i=i+UVK5_EEPROM_BLOCKSIZE) {
if (!k5_writemem(fd,(unsigned char *)&eeprom[i],UVK5_EEPROM_BLOCKSIZE,i)) if (!k5_writemem(fd,(unsigned char *)&eeprom[i],UVK5_EEPROM_BLOCKSIZE,i))
{ {
fprintf(stderr,"Failed to write block 0x%4.4X\n",i); fprintf(stderr,"Failed to write block 0x%4.4X\n",i);
exit(1); exit(1);
} }
if (verbose>0) { if (verbose>0) {
printf("\rwrite block 0x%4.4X %i%%",i,(100*i/UVK5_EEPROM_SIZE)); printf("\rwrite block 0x%4.4X %i%%",i,(100*i/j));
fflush(stdout); fflush(stdout);
} }