Skip to content

Adding support to IAR compiler's default extension for elf files with cbuild-run #1808

@Hasnaoui-Youssef

Description

@Hasnaoui-Youssef

The issue arises when using a *.cbuild.yml file. In CMSIS-Toolbox, the IAR compiler's elf file extension is fixed to ".out" which is not a supported extension for pyOCD.

I would like to contribute but I have thought about two ways of doing this and I would like more insight about which approach to go for:

  1. Add "out" directly in the FileProgrammer class's _format_handler member
  2. Modify the output property of CbuildRun class to include the file's type, and then in the LoadSubcommand's invoke method, we pass the acquired value to the programmer. The code would look something like this :
    @property
    def output(self) -> Dict[str, Dict[str, Union[str, Optional[int]]]]:
        """@brief Set of loadable output files (file, offset)."""
         """same code above"""
        load_files = {}
        for f in loadable_files:
            # Get load offset (None if not specified)
            offset = f.get('load-offset')
            fileType = f.get('type')
            # Add filename and its offset and file type to return value
            load_files[f['file']] = {
                    "offset" : offset,
                    "type" : fileType,
            }
            LOG.debug("Loadable file: %s", f['file'])
        return load_files

And for the load command :

                # Look for a base address suffix. If the supplied argument including an address suffix
                # references an existing file, then the address suffix is not extracted.
                if "@" in filename and not file_path.exists():
                    filename, suffix = filename.rsplit("@", 1)
                    try:
                        base_address = int_base_0(suffix)
                    except ValueError:
                        LOG.error(f'Base address suffix "{suffix}" on file "{filename}" is not a valid integer address')
                        return 1
                else:
                    base_address = self._args.base_address
                    if base_address is None and self._args.cbuild_run:
                        base_address = cbuild_files[filename]["offset"]

                if self._args.cbuild_run:
                    self._args.format = cbuild_files[filename]["type"]

The first method is enough to solve the problem because the file extensions are hard coded in CMSIS-Toolbox and do not yet allow for custom file extensions, see the link.
However the second method feels more universal, regardless of the compiler and could be more flexible in the future if they decided to go with allowing users to customize file extensions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions