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:
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
****** 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.
Write configuration from file k5_eeprom.raw:
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
****** Connected to firmware version: [k5_2.01.23]
Read file k5_eeprom.raw success
Sucessfuly wrote eeprom
The -w option writes only the memory blocks which are written by the original
radio software, in the same order.
The -W option 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.
The -W option is a bit more brave, it writes all memory upto 0x1d00. I _think_
that the radio has calibration data above this address, but of course this is
not certain, because this knowledge is a result of reverse engineering, and not
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:
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:
-f <file> filename that contains the eeprom dump (default: k5_eeprom.raw)
-r read eeprom
-w write eeprom like the original software does (warning: may brick your radio)
-W write all eeprom (even bigger warning: this is sure to brick your radio!)
-w write eeprom like the original software does
-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)
-s <speed> serial speed (default: 38400, the UV-K5 doesn't accept any other speed)
-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>
*
* This program can read and write the eeprom of Quansheng UVK5 Mark II
@ -46,15 +46,17 @@
#include <stdint.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_READ 1
#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_WITHOUT_CALIBRATION 0x1d00
#define UVK5_EEPROM_BLOCKSIZE 0x80
#define UVK5_PREPARE_TRIES 10
@ -514,8 +516,9 @@ void helpme()
"cmdline opts:\n"
"-f <file>\tfilename that contains the eeprom dump (default: " DEFAULT_FILE_NAME ")\n"
"-r \tread eeprom\n"
"-w \twrite eeprom like the original software does (warning: may brick your radio)\n"
"-W \twrite all eeprom (even bigger warning: this is sure to brick your radio!)\n"
"-w \twrite eeprom like the original software does\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"
"-s <speed>\tserial speed (default: 38400, the UV-K5 doesn't accept any other speed)\n"
"-h \tprint this help\n"
@ -585,7 +588,7 @@ void parse_cmdline(int argc, char **argv)
* -v (verbose)
*/
while ((opt=getopt(argc,argv,"f:rwWp:s:hv"))!=EOF)
while ((opt=getopt(argc,argv,"f:rwWBp:s:hv"))!=EOF)
{
switch (opt)
{
@ -603,6 +606,9 @@ void parse_cmdline(int argc, char **argv)
mode=MODE_WRITE;
break;
case 'W':
mode=MODE_WRITE_MOST;
break;
case 'B':
mode=MODE_WRITE_ALL;
break;
case 'f':
@ -668,9 +674,8 @@ int main(int argc,char **argv)
{
int fd,ffd;
unsigned char eeprom[UVK5_EEPROM_SIZE];
int i;
int r;
int j;
int i,r,j;
printf (VERSION "\n\n");
//debtest();
@ -728,6 +733,7 @@ int main(int argc,char **argv)
break;
case MODE_WRITE:
case MODE_WRITE_MOST:
case MODE_WRITE_ALL:
/* read file */
ffd=open(file,O_RDONLY);
@ -742,16 +748,19 @@ int main(int argc,char **argv)
}
close(ffd);
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 */
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))
{
fprintf(stderr,"Failed to write block 0x%4.4X\n",i);
exit(1);
}
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);
}