def erase_rpmb(flashable_path):
    assert os.path.exists(flashable_path)

    firehose_bin = qcomdl.get_firehose_bin(flashable_path)
    assert firehose_bin, "No firehose binary found"

    qcomdl.set_loglevel(qcomdl.QCOMDL_LOG_LEVEL_WARNING)

    edl = qcomdl.Edl()
    assert edl.connect()

    try:
        sahara = qcomdl.Sahara(edl)
        assert sahara.upload(firehose_bin)
        assert sahara.done()
        time.sleep(3)
        firehose = qcomdl.Firehose(edl)
        try:
            assert firehose.configure()
            assert firehose.ping()
            assert firehose.rpmb_erase()
        finally:
            firehose.soft_reset(qcomdl.FIREHOSE_DEFAULT_RESET_DELAY_SECS)
    finally:
        edl.disconnect()
def firehose(edl, firehose_bin):
    assert edl.connect()
    assert edl.isconnected()
    sahara = qcomdl.Sahara(edl)
    assert sahara.upload(firehose_bin)
    assert sahara.done()
    # obligatory sleep as firehose comes up
    logit("[Info] Sleeping 3 seconds while firehose comes up...")
    time.sleep(3)
    return qcomdl.Firehose(edl)
Beispiel #3
0
def sahara_diag(request, squid_device):
    assert squid_device.bootIntoDiagEDL()
    edl = qcomdl.Edl()
    assert edl.diag_connect()

    def _disconnect_edl():
        if edl.isconnected():
            edl.disconnect()

    request.addfinalizer(_disconnect_edl)
    sahara = qcomdl.Sahara(edl)
    assert sahara.enter_memory_debug()
    return sahara
def vip_firehose(squid_device, request, vip_firehose_bin):
    assert squid_device.bootIntoEDL()
    edl = qcomdl.Edl()

    def _disconnect_edl():
        if edl.isconnected():
            edl.disconnect()

    request.addfinalizer(_disconnect_edl)
    assert edl.connect()
    assert edl.isconnected()
    sahara = qcomdl.Sahara(edl)
    assert sahara.upload(vip_firehose_bin)
    assert sahara.done()
    # obligatory sleep as firehose comes up
    logit("[Info] Sleeping 3 seconds while firehose comes up...")
    time.sleep(3)
    return qcomdl.Firehose(edl)
Beispiel #5
0
def flash_vip(flashable_path, percent_progress_callback=DEFAULT_LOGGER.handle_percent):
    assert os.path.exists(flashable_path)
    qcomdl.set_loglevel(qcomdl.QCOMDL_LOG_LEVEL_WARNING)
    edl = qcomdl.Edl()
    assert edl.connect()
    try:
        sahara = qcomdl.Sahara(edl)
        assert sahara.upload(flashable_path, qcomdl.FIREHOSE_DEFAULT_VIP_BIN_APQ8039)
        assert sahara.done()
        time.sleep(3)
        firehose = qcomdl.Firehose(edl)
        vip_image_sectors = qcomdl.total_image_sectors_vip(flashable_path, qcomdl.FIREHOSE_DEFAULT_VIP_XML_FILENAME)
        firehose.register_percent_progress_callbacks(percent_progress_callback, vip_image_sectors)
        assert firehose.run_vip(flashable_path,
                                qcomdl.FIREHOSE_DEFAULT_VIP_XML_FILENAME,
                                qcomdl.FIREHOSE_DEFAULT_DIGEST_TABLE_FILENAME,
                                qcomdl.FIREHOSE_DEFAULT_CHAINED_DIGESTS_FILENAME)
    finally:
        edl.disconnect()
Beispiel #6
0
def flash(flashable_path, percent_progress_callback=DEFAULT_LOGGER.handle_percent):
    assert os.path.exists(flashable_path)
    qcomdl.set_loglevel(qcomdl.QCOMDL_LOG_LEVEL_WARNING)
    edl = qcomdl.Edl()
    assert edl.connect()
    try:
        firehose_bin = qcomdl.get_firehose_bin(flashable_path)
        assert firehose_bin, "No firehose binary found"

        sahara = qcomdl.Sahara(edl)
        assert sahara.upload(flashable_path, firehose_bin)
        assert sahara.done()
        time.sleep(3)
        firehose = qcomdl.Firehose(edl)
        image_sectors = qcomdl.total_image_sectors_non_vip(flashable_path, qcomdl.FIREHOSE_DEFAULT_PROGRAM_XML_FILENAME)
        firehose.register_percent_progress_callbacks(percent_progress_callback, image_sectors)
        try:
            assert firehose.program_from_file(flashable_path, qcomdl.FIREHOSE_DEFAULT_PROGRAM_XML_FILENAME, 0)
            assert firehose.patch_from_file(flashable_path, qcomdl.FIREHOSE_DEFAULT_PATCH_XML_FILENAME)
        finally:
            firehose.soft_reset(qcomdl.FIREHOSE_DEFAULT_RESET_DELAY_SECS)
    finally:
        edl.disconnect()
#!/usr/bin/env python

from sys import argv, exit
from time import sleep

if len(argv) < 2:
    print "usage: " + argv[0] + " <firehose_bin.mbn>"
    exit(1)

import qcomdl

firehose_bin = argv[1]

edl = qcomdl.Edl()
if edl.connect() == True:
    sahara = qcomdl.Sahara(edl)

    print "Uploading firehose"
    if sahara.upload(firehose_bin) == True and sahara.done() == True:
        print "sleeping 3 seconds while we await firehose to come up"
        sleep(3)

        firehose = qcomdl.Firehose(edl)
        if firehose.configure() == True:
            print "Configured with target: MemoryName=" + firehose.memory_name(
            ) + " TargetName=" + firehose.target_name()
            for i in range(10):
                print "Sending ping #" + str(i + 1)
                firehose.ping()
                sleep(0.5)
Beispiel #8
0
def main(argv=sys.argv):
    options, image_dir = get_args(argv)
    if not options or not image_dir:
        return False

    firehose_bin_path = os.path.join(image_dir, options.firehose_bin)
    program_xml_path = os.path.join(image_dir, options.program_xml)
    patch_xml_path = os.path.join(image_dir, options.patch_xml)

    for path in [firehose_bin_path, program_xml_path, patch_xml_path]:
        if not os.path.exists(path):
            print "Error: missing file: %s" % path
            return False

    if options.single_file:
        if options.single_start_sector:
            programs = [{
                "start_sector": options.single_start_sector,
                "physical_partition_number": options.single_partition_number,
                "filename": options.single_file,
            }]

        else:
            programs = filtered_programs(program_xml_path, None,
                                         [options.single_file])
            if not programs:
                print("No programs file entry found for file: %s" %
                      options.single_file)
                return False
    else:
        programs = filtered_programs(program_xml_path, options.labels,
                                     options.filenames)
        if not programs:
            print("No programs file entries found")
            return False

    if (options.labels or options.filenames) and not programs:
        print "Error: filtering labls/filenames returned an empty list of program files"
        return False

    edl = qcomdl.Edl()
    print "Connecting to EDL"
    if not edl.connect():
        return False

    try:
        sahara = qcomdl.Sahara(edl)

        if options.do_sahara_info:
            print "Dumping device info"
            print sahara.device_info()
            print "[+] Dumping debug data"
            print {'debug_data': sahara.read_debug_data()}

        print "Uploading firehose"
        if not sahara.upload(firehose_bin_path) == True or not sahara.done():
            return False

        print "Sleeping 3 seconds while firehose comes up"
        time.sleep(3)

        firehose = qcomdl.Firehose(edl)
        try:
            if options.dry_run:
                assert not options.do_erase
                firehose.cfg_set_skip_write(1)

            if not firehose.configure():
                return False

            print "Configured with MemoryName=%s TargetName=%s" % (
                firehose.memory_name(), firehose.target_name())

            if options.do_erase:
                firehose.erase(0)

            for pg in programs:
                full_path = os.path.join(image_dir, pg['filename'])
                ss = pg['start_sector']
                ppn = pg['physical_partition_number']
                print "Flashing %s at start-sector: %s - partition: %s" % (
                    full_path, ss, ppn)
                firehose.program(full_path, ss, ppn, 0)

            # TODO filter patch statements? for now we can just opt out of patching altogether
            if not options.dry_run and options.do_patch and not firehose.patch_from_file(
                    patch_xml_path):
                return False

        finally:
            firehose.soft_reset(0)
        return True
    finally:
        edl.disconnect()
def sahara(edl):
    assert edl.connect()
    assert edl.isconnected()
    return qcomdl.Sahara(edl)