Example #1
0
    def _process_hex(cls, in_path):
        """This function returns a list of base addresses and a list of the binary data
        for each segment.
        """
        ihex = IntelHex(in_path)
        segments = ihex.segments()
        segments_start = [segment[0] for segment in segments]
        segments_data = [
            ihex.tobinarray(start=segment[0], end=segment[1] - 1)
            for segment in segments
        ]

        return segments_start, segments_data
Example #2
0
def merge_hex_executables(target, source, env):
    """Combine all hex files into a singular executable file."""
    output_name = str(target[0])

    hex_final = IntelHex()
    for image in source:
        file = str(image)
        root, ext = os.path.splitext(file)
        file_format = ext[1:]
        if file_format == 'elf':
            file = root + '.hex'
        hex_data = IntelHex(file)

        #merge will throw errors on mismatched Start Segment Addresses, which we don't need
        #See <https://stackoverflow.com/questions/26295776/what-are-the-intel-hex-records-type-03-or-05-doing-in-ihex-program-for-arm>
        hex_data.start_addr = None
        hex_final.merge(hex_data, overlap='error')

    with open(output_name, 'w') as outfile:
        hex_final.write_hex_file(outfile)
Example #3
0
def test_bootstrap_file(tmpdir):
    """Make sure we can create a bootstrap file"""
    olddir = os.getcwd()
    builddir = copy_folder('component_bootstrap', tmpdir)

    try:
        os.chdir(builddir)

        hexdata = IntelHex(os.path.join('build', 'output', 'test1.hex'))
        assert hexdata.segments() == [(0x10001014, 0x10001018)]

        assert not os.path.isfile(os.path.join('build', 'output', 'test2.hex'))

        err = subprocess.call(["iotile", "build"])
        assert err == 0

        hexdata = IntelHex(os.path.join('build', 'output', 'test_final.hex'))
        hexdata_dup = IntelHex(os.path.join('build', 'output', 'test_final_dup.hex'))
        assert hexdata.segments() == hexdata_dup.segments()
    finally:
        os.chdir(olddir)
Example #4
0
def _build_reflash_script_action(target, source, env):
    """Create a TRUB script containing tile and controller reflashes and/or sensorgraph

    If the app_info is provided, then the final source file will be a sensorgraph.
    All subsequent files in source must be in intel hex format. This is guaranteed
    by the ensure_image_is_hex call in build_update_script.
    """

    out_path = str(target[0])
    source = [str(x) for x in source]
    records = []

    #Update application firmwares
    if env['SLOTS'] is not None:
        for (controller, slot_id), image_path in zip(env['SLOTS'], source):
            hex_data = IntelHex(image_path)
            hex_data.padding = 0xFF

            offset = hex_data.minaddr()
            bin_data = bytearray(
                hex_data.tobinarray(offset, hex_data.maxaddr()))

            if controller:
                record = ReflashControllerRecord(bin_data, offset)
            else:
                record = ReflashTileRecord(slot_id, bin_data, offset)

            records.append(record)

    #Update sensorgraph
    if env['UPDATE_SENSORGRAPH']:
        sensor_graph_file = source[-1]
        sensor_graph = compile_sgf(sensor_graph_file)
        output = format_script(sensor_graph)
        records += UpdateScript.FromBinary(output).records

    #Update App and OS Tag
    os_info = env['OS_INFO']
    app_info = env['APP_INFO']
    if os_info is not None:
        os_tag, os_version = os_info
        records.append(SetDeviceTagRecord(os_tag=os_tag,
                                          os_version=os_version))
    if app_info is not None:
        app_tag, app_version = app_info
        records.append(
            SetDeviceTagRecord(app_tag=app_tag, app_version=app_version))

    script = UpdateScript(records)

    with open(out_path, "wb") as outfile:
        outfile.write(script.encode())