# HG changeset patch # User Jim Unroe rock.unroe@gmail.com # Date 1405559320 14400 # Node ID b56d639ab6ab343d5e00b2480c60d4516929987a # Parent 3bab2acc2cf68e735e48138bf4871c2cd3fed85a [UV-5R] Prevent image upload when "special block" doesn't match
add code to compare the data image "special block" to the radio image "special block" and abort the upload if they don't match
#1773
diff -r 3bab2acc2cf6 -r b56d639ab6ab chirp/uv5r.py --- a/chirp/uv5r.py Mon Jul 14 20:10:30 2014 -0400 +++ b/chirp/uv5r.py Wed Jul 16 21:08:40 2014 -0400 @@ -369,6 +369,16 @@ print "_firmware_version_from_image: " + util.hexprint(version) return version
+def _special_block_from_data(data, special_block_start, special_block_stop): + special_block_tag = data[special_block_start:special_block_stop] + return special_block_tag + +def _special_block_from_image(radio): + special_block = _special_block_from_data(radio.get_mmap(), 0x0CFA, 0x0D01) + if CHIRP_DEBUG: + print "_special_block_from_image: " + util.hexprint(special_block) + return special_block + def _do_ident(radio, magic): serial = radio.pipe serial.setTimeout(1) @@ -436,6 +446,11 @@ version = block[48:64] return version
+def _get_radio_special_block(radio): + block = _read_block(radio, 0xCF0, 0x40) + special_block = block[2:9] + return special_block + def _ident_radio(radio): for magic in radio._idents: error = None @@ -488,13 +503,22 @@
image_version = _firmware_version_from_image(radio) radio_version = _get_radio_firmware_version(radio) - print "Image is %s" % repr(image_version) - print "Radio is %s" % repr(radio_version) + print "Image Version is %s" % repr(image_version) + print "Radio Version is %s" % repr(radio_version)
if not any(type in radio_version for type in BASETYPE_LIST): raise errors.RadioError("Unsupported firmware version: `%s'" % radio_version)
+ image_special_block = _special_block_from_image(radio) + radio_special_block = _get_radio_special_block(radio) + print "Image Special Block is " + util.hexprint(image_special_block) + print "Radio Special Block is " + util.hexprint(radio_special_block) + + if image_special_block != radio_special_block: + raise errors.RadioError("Image not supported by radio: `%s'" % + radio_special_block) + # Main block for i in range(0x08, 0x1808, 0x10): _send_block(radio, i - 0x08, radio.get_mmap()[i:i + 0x10])