Ejemplo n.º 1
0
    def test_aprom_convert(self):
        with open("testdata/helloworld.bin", "rb") as apromfile:
            aprom_data = bytearray(apromfile.read())
            aprom = evic.APROM(aprom_data)
            aprom_unencrypted = evic.APROM(aprom.convert())

            assert aprom_data == aprom_unencrypted.convert()
Ejemplo n.º 2
0
    def test_aprom_verify(self):
        with open("testdata/helloworld.bin", "rb") as apromfile:
            aprom = evic.APROM(apromfile.read())
            aprom_unencrypted = evic.APROM(aprom.convert())

            aprom_unencrypted.verify(['E052'], 106)

            with pytest.raises(evic.APROMError):
                aprom_unencrypted.verify(['W007'], 106)
                aprom_unencrypted.verify(['E052'], 999)
Ejemplo n.º 3
0
def upload_ldrom(inputfile):
    """Upload an LDROM image to the device."""

    dev = evic.HIDTransfer()

    # Connect the device
    connect(dev)

    # Print the USB info of the device
    print_usb_info(dev)

    # Read the data flash
    dataflash = read_dataflash(dev, False)

    # Get the device info
    device_info = dev.devices.get(dataflash.product_id,
                                  DeviceInfo("Unknown device", None, None))

    # Print the device information
    print_device_info(device_info, dataflash)

    # Read the LDROM image
    ldrom = evic.APROM(inputfile.read())

    # Write data flash to the device
    with handle_exceptions(IOError):
        # Write LDROM to the device
        click.echo("Writing LDROM...", nl=False)
        dev.write_ldrom(ldrom)
Ejemplo n.º 4
0
def convert(inputfile, output):
    """Decrypt/encrypt an APROM image."""

    binfile = evic.APROM(inputfile.read())

    with handle_exceptions(IOError):
        click.echo("Writing APROM image...", nl=False)
        output.write(binfile.convert())
        os.chmod(output.name, os.stat(inputfile.name).st_mode)
Ejemplo n.º 5
0
def upload(inputfile, encrypted, dataflashfile, noverify):
    """Upload an APROM image to the device."""

    dev = evic.HIDTransfer()

    # Connect the device
    connect(dev)

    # Print the USB info of the device
    print_usb_info(dev)

    # Read the data flash
    verify = 'dataflash' not in noverify
    dataflash = read_dataflash(dev, verify)
    dataflash_original = copy.deepcopy(dataflash)

    # Print the device information
    print_device_info(dev, dataflash)

    # Read the APROM image
    aprom = evic.APROM(inputfile.read())
    if encrypted:
        aprom = evic.APROM(aprom.convert())

    # Verify the APROM image
    if 'aprom' not in noverify:
        with handle_exceptions(evic.APROMError):
            click.echo("Verifying APROM...", nl=False)
            aprom.verify(dev.supported_product_ids[dataflash.product_id],
                         dataflash.hw_version)

    # Are we using a data flash file?
    if dataflashfile:
        buf = bytearray(dataflashfile.read())
        # We used to store the checksum inside the file
        if len(buf) == 2048:
            checksum = struct.unpack("=I", bytes(buf[0:4]))[0]
            dataflash = evic.DataFlash(buf[4:], 0)
        else:
            checksum = sum(buf)
            dataflash = evic.DataFlash(buf, 0)
        if 'dataflash' not in noverify:
            verify_dataflash(dataflash, checksum)

    # We want to boot to LDROM on restart
    if not dev.ldrom:
        dataflash.bootflag = 1

    # Flashing Presa firmware requires HW version <=1.03 on type A devices
    if b'W007' in aprom.data and dataflash.product_id == 'E052' \
            and dataflash.hw_version in [106, 108, 109, 111]:
        click.echo("Changing HW version to 1.03...", nl=False)
        dataflash.hw_version = 103
        click.secho("OK", fg='green', bold=True)

    # Write data flash to the device
    with handle_exceptions(IOError):
        if dataflash.array != dataflash_original.array:
            click.echo("Writing data flash...", nl=False)
            sleep(0.1)
            dev.write_dataflash(dataflash)
            click.secho("OK", fg='green', bold=True)

        # We should only restart if we're not in LDROM
        if not dev.ldrom:
            # Restart
            click.echo("Restarting the device...", nl=False)
            dev.reset()
            sleep(2)
            click.secho("OK", fg='green', nl=False, bold=True)
            # Reconnect
            connect(dev)

        # Write APROM to the device
        click.echo("Writing APROM...", nl=False)
        dev.write_aprom(aprom)