Beispiel #1
0
    def do_load(params, verify=True):
        if params[0] is not None and params[1] is not None:
            LOG.info("Checking firmware file...")
            records = validator.verify_firmware(params[1])
            if records is None:
                raise ValueError('Firmware file is corrupt or has no records, won\'t load')
            LOG.info("File OK, got %d records" % len(records))

            dev = CmdHandler.get_device(params[0])

            LOG.info("Converting records to memory pages...")
            header = records.pop(0)  # S0 Record
            termination = records.pop()  # S8 Record
            pagedata = pages.records_to_pages(records)
            pagelist = pagedata[0]
            LOG.info("Received %d pages" % len(pagelist))
            LOG.info("Loading firmware: '%s'" % str(header.data))

            last_page = None
            loaded_size = 0
            for page in pagelist:
                page_size = len(page.data)
                LOG.debug("%6d bytes to 0x%02x @ 0x%04x" % (page_size, page.page, page.address))
                dev.erase_and_write(page, erase=False if page.page == last_page else True, verify=verify)
                last_page = page.page
                loaded_size += page_size
                common.print_progress(float(loaded_size) / pagedata[1])

            sys.stdout.write("\r")
            sys.stdout.flush()
            LOG.info("Firmware loaded successfully")

            return True

        raise ValueError("Can't load sh*t captain, no file nor serial?!")
Beispiel #2
0
    def do_check(params):
        if params[1] is not None:
            if os.path.isfile(params[1]) and os.access(params[1], os.R_OK):
                LOG.info("Checking firmware...")
                records = validator.verify_firmware(params[1])
                if records:
                    LOG.info("Parsed %d records" % len(records))
                    if records[0].stype[0] == 'S0':
                        header = records[0].data if CmdHandler.is_ascii(records[0].data) else "[binary data]"
                        LOG.info("Header info: [%s]" % header)
                    else:
                        LOG.warning("No header...")
                    LOG.info("File OK")
                    return True
                else:
                    return False
            else:
                raise ValueError('Cannot find firmware file or no read access')

        raise ValueError('No firmware given')
Beispiel #3
0
    def do_check(params):
        if params[1] is not None:
            if os.path.isfile(params[1]) and os.access(params[1], os.R_OK):
                LOG.info("Checking firmware...")
                records = validator.verify_firmware(params[1])
                if records:
                    LOG.info("Parsed %d records" % len(records))
                    if records[0].stype[0] == 'S0':
                        header = records[0].data if CmdHandler.is_ascii(
                            records[0].data) else "[binary data]"
                        LOG.info("Header info: [%s]" % header)
                    else:
                        LOG.warning("No header...")
                    LOG.info("File OK")
                    return True
                else:
                    return False
            else:
                raise ValueError('Cannot find firmware file or no read access')

        raise ValueError('No firmware given')
Beispiel #4
0
    def do_load(params, verify=True):
        if params[0] is not None and params[1] is not None:
            LOG.info("Checking firmware file...")
            records = validator.verify_firmware(params[1])
            if records is None:
                raise ValueError(
                    'Firmware file is corrupt or has no records, won\'t load')
            LOG.info("File OK, got %d records" % len(records))

            dev = CmdHandler.get_device(params[0])

            LOG.info("Converting records to memory pages...")
            header = records.pop(0)  # S0 Record
            termination = records.pop()  # S8 Record
            pagedata = pages.records_to_pages(records)
            pagelist = pagedata[0]
            LOG.info("Received %d pages" % len(pagelist))
            LOG.info("Loading firmware: '%s'" % str(header.data))

            last_page = None
            loaded_size = 0
            for page in pagelist:
                page_size = len(page.data)
                LOG.debug("%6d bytes to 0x%02x @ 0x%04x" %
                          (page_size, page.page, page.address))
                dev.erase_and_write(
                    page,
                    erase=False if page.page == last_page else True,
                    verify=verify)
                last_page = page.page
                loaded_size += page_size
                common.print_progress(float(loaded_size) / pagedata[1])

            sys.stdout.write("\r")
            sys.stdout.flush()
            LOG.info("Firmware loaded successfully")

            return True

        raise ValueError("Can't load sh*t captain, no file nor serial?!")