Example #1
0
def read_firmware(com, device_param):
    """read firmware from target and tweak so that it can be written in standard
    Microchip format.  Certain words such as chip id and calibration for example
    need to be blanked."""
    prog_pages = icsp.read_program(com, device_param)
    data_pages = icsp.read_data(com, device_param)

    firmware = prog_pages + data_pages

    # Get config page data and tweak to read-only regions
    conf_data = icsp.read_config(com, device_param)
    conf_page = intelhex.Page(conf_data)

    # blank out any empty user ID locations
    for i in range(0, 4):
        if conf_page[i] == 0x3FFF:
            conf_page[i] = None

    # Blank out 0x04, reserved, revision and chip_id
    conf_page[4:7] = None
    # blank out calibration words
    conf_page[9:17] = None

    firmware[device_param['conf_page']] = conf_page

    return firmware
Example #2
0
def read_firmware(com, conf_page_num, prog_list, data_list):
    """read firmware from target and tweak so that it can be written in standard
    Microchip format.  Certain words such as chip id and calibration for example
    need to be blanked."""
    prog_pages = bload.read_program(com, prog_list)
    data_pages = bload.read_data(com, data_list)

    firmware = prog_pages + data_pages

    # Get config page data and tweak to read-only regions
    conf_data = bload.read_config(com)
    conf_page = intelhex.Page(conf_data)

    # Blank out 0x04, reserved, revision and chip_id
    conf_page[4:7] = None
    # blank out calibration words
    conf_page[9:17] = None

    # blank out any empty locations
    for i in range(intelhex.PAGELEN):
        if conf_page[i] == 0x3FFF:
            conf_page[i] = None

    firmware[conf_page_num] = conf_page

    return firmware
Example #3
0
def page1():
    p = intelhex.Page()
    p[1] = '    '
    p[2] = '4F2C'
    p[intelhex.PAGELEN - 1] = '9F6C'
    p[23] = 0x5f
    p[5:7] = '12345678'
    p[9] = 'FF3F'

    return p
Example #4
0
    def flash_write(self):
        """update a firmware page"""
        page_num = self.get_page_num()
        page = intelhex.Page(self.boot_data)

        # Remove NULL words
        for offset in range(0, len(page)):
            if page[offset] == 0xFFFF:
                page[offset] = None

        self.firmware[page_num] = page
Example #5
0
    def _program(self):
        # compute page, offset and latch address
        page_num, page_offset = divmod(self.word_address, intelhex.PAGELEN)
        word_offset = (page_offset // self._latch_count) * self._latch_count

        if not self.firmware[page_num]:
            self.firmware[page_num] = intelhex.Page()

        for bn in range(self._latch_count):
            if self.latch[bn] is not None:
                self.firmware[page_num][word_offset + bn] = self.latch[bn]

        self._clear_latches()
Example #6
0
def read_data(com, page_nums) -> intelhex.Hexfile:
    """Read all pages and create a list"""

    data_list = read_pages(com, b'F', page_nums)

    pages = intelhex.Hexfile()

    for page_num, data in zip(page_nums, data_list):
        if data:
            page = intelhex.Page(data)

            # Remove NULL words and force unused high word to 00
            for offset in range(0, len(page)):
                if page[offset] == 0x00FF:
                    page[offset] = None

            if any(page):
                pages[page_num] = page

    return pages
Example #7
0
def read_program(com, page_nums) -> intelhex.Hexfile:
    """Read all pages and create a list"""

    prog_list = read_pages(com, b'R', page_nums)

    pages = intelhex.Hexfile()

    for page_num, data in zip(page_nums, prog_list):
        if data:
            page = intelhex.Page(data)

            # Remove NULL words
            for offset in range(0, len(page)):
                if page[offset] == 0x3FFF:
                    page[offset] = None

            if any(page):
                pages[page_num] = page

    return pages
Example #8
0
def read_data(com: comm.Comm, device):
    """read all data pages"""
    pages = intelhex.Hexfile()

    # if data region is not defined then return an empty list
    if device['min_data'] or device['max_data']:
        page_nums = range(device['min_data'], device['max_data'] + 1)
        data_list = read_pages(com, CMD_READ_DATA, page_nums)

        for page_num, data in zip(page_nums, data_list):
            if data:
                page = intelhex.Page(data)

                for offset in range(0, len(page)):
                    if page[offset] == 0x00FF:
                        page[offset] = None

                if any(page):
                    pages[page_num] = page

    return pages
Example #9
0
def read_program(com: comm.Comm, device) -> intelhex.Hexfile:
    """read all program pages"""
    page_nums = range(0, device['max_page'] + 1)
    page_list = read_pages(com, CMD_READ_PAGE, page_nums)

    pages = intelhex.Hexfile()

    # Read all pages and create a list
    for page_num, data in zip(page_nums, page_list):
        if data:
            page = intelhex.Page(data)

            # Remove NULL words
            for offset in range(0, len(page)):
                if page[offset] == 0x3FFF:
                    page[offset] = None

            if any(page):
                pages[page_num] = page

    return pages
Example #10
0
def page2():
    q = intelhex.Page(
        '00308C0001308D002100EA3099001A1C172888018C1425238C1025231A28    '
        '00308C0001308D002100EA3099001A1C172888018C1425238C1025231A28    ')

    return q