Main Content

Generate and Package AUTOSAR Composition XML Descriptions and Component Code

If you have Simulink® Coder™ and Embedded Coder® software, from an AUTOSAR architecture model, you can:

  • Export composition and component AUTOSAR XML (ARXML) descriptions and generate component code.

  • Optionally, create a ZIP file to package build artifacts from the model hierarchy for relocation and integration.

  • Optionally, for architecture models configured for the AUTOSAR Classic Platform with an ECU configuration, export an ECU extract that maps the software components in a composition to an AUTOSAR ECU.

You can export an entire architecture model, a nested composition, or a single component. If you initiate an export that encompasses a composition, the export includes XML descriptions of the composition, component prototypes, and composition ports and connectors.

Configure Composition XML Options

To prepare for exporting ARXML files, examine and modify your XML options. XML options specified at the architecture model level are inherited during export by each component in the model.

To view XML options:

  1. Open an AUTOSAR architecture model.

    For example, to open the model autosar_tpc_composition, enter:


  2. From the Modeling tab, select Export > Configure XML Options. The XML Options dialog box opens.

    This dialog box shows XML options for the classic architecture model. Modifications you make to these options are inherited by every component in the hierarchy.

XML options for an AUTOSAR classic architecture model

The System Package option applies only to the composition level. If you export an ECU extract for a composition in a classic architecture model, System Package specifies the system package path to generate in the composition ARXML. For more information, see Export Composition ECU Extract.

In R2023a: XML option Exported XML File Packaging is supported for exporting architecture models.

Setting the Exported XML File Packaging parameter allows you to specify the granularity of XML file packaging for AUTOSAR elements created in Simulink. Selecting Single file exports XML into a single file. Selecting Modular exports XML into multiple files, named according to the type of information contained.

For more information about each XML option, see Configure AUTOSAR XML Options for classic architecture model options and Configure AUTOSAR Adaptive XML Options for adaptive architecture options.

Export Composition XML and Component Code

To export ARXML files and generate code for an architecture model:

  1. Open an architecture model.

    For this example, open the example classic model autosar_tpc_composition, enter:


  2. Export the architecture model.

    From the Modeling tab, select Export > Generate Code and ARXML. In the Export Composition dialog box:

    • Specify the name of the ZIP file to package the generated files in.

    • Optionally, specify a path to a folder to contain the exported ARXML files.

    • To export an ECU extract from a classic composition, select Export ECU extract. For more information, see Export Composition ECU Extract.

    To begin the export, click OK.

    As the architecture model builds, you can view the build log in the Diagnostic Viewer. First the component models build, each as a standalone top-model build. Then, composition ARXML is exported. When the build is complete, the current folder contains build folders for the architecture model and each component model in the hierarchy, and the specified ZIP file.

  3. Expand the ZIP file. Its content is organized in arxml and src folders.

  4. Examine the arxml folder.

    Each AUTOSAR component has component and implementation description files, while the architecture model has composition, datatype, interface, and timing description files. The composition file includes XML descriptions of the composition, component prototypes, and composition ports and connectors. The datatype and interface files aggregate elements from the entire architecture model hierarchy.


    Timing files are not generated for referenced compositions within the architecture model hierarchy.

  5. Examine the src folder.

    Each component model has a build folder that contains artifacts from a standalone model build.

To export a nested composition or a single component in an architecture model, use composition or component block cues or right-click options. For example, right-click a component block and select Export Component. Components exported from an architecture model inherit the XML options specified at the architecture model level.

When exporting an architecture model, AUTOSAR schema versions must match between the architecture model and the component models in the hierarchy. If export flags a version difference, fix the discrepancy in the component model or in the architecture model. To view the architecture model schema version, open the Configuration Parameters dialog box. In the Modeling tab, select Model Settings. In the dialog box, navigate to the AUTOSAR code generation options pane.

To export from an architecture model hierarchy programmatically, use the architecture function export. For example, to generate and package ARXML files and code for example model autosar_tpc_composition:

% Load AUTOSAR architecture model
archModel = autosar.arch.loadModel("autosar_tpc_composition");
% Export ARXML descriptions and code into ZIP file

Export Composition ECU Extract

You can export ECU extracts from compositions in an AUTOSAR classic architecture model. ECU extracts are an important input to AUTOSAR ECU configuration. In an AUTOSAR classic architecture, a top-level composition can model the software components mapped to one AUTOSAR ECU. To create a software description of the ECU-scoped system, you export an ECU extract from the composition.

In an open architecture model, you can export ARXML by using the Simulink Toolstrip, the software architecture canvas, or the export function. For example, from the Modeling tab, select Export > Generate Code and ARXML. In the Export Composition dialog box, select the option Export ECU extract. To begin the export, click OK.

To generate the ECU extract, the software automatically maps the software components in the composition to an ECU. If the composition contains nested compositions, the software uses a flattened version of the composition hierarchy, containing only components. For example, these function calls export an ECU extract for the AUTOSAR example architecture model autosar_tpc_composition, which contains a nested composition.

% Open and export AUTOSAR architecture model, generating ECU extract
archModel = 'autosar_tpc_composition';

The export function call generates the ECU extract into the file System.arxml, which is located in the composition folder. The ECU extract for autosar_tpc_composition maps components from both the top-level composition and a nested Sensors composition to one ECU.

        <SYSTEM-MAPPING UUID="...">
                <SWC-TO-ECU-MAPPING UUID="...">
                    <ECU-INSTANCE-REF DEST="ECU-INSTANCE">


To specify the AUTOSAR package path for the system package that contains the ECU extract, use the composition XML option System Package. To view the System Package path value, from the Modeling tab, select Export > Configure XML Options.

Alternatively, configure the AUTOSAR system package path by using the AUTOSAR property functions get and set.

arProps = autosar.api.getAUTOSARProperties('autosar_tpc_composition');
systemPackage = get(arProps,'XmlOptions','SystemPackage');

For more information about the hierarchical AUTOSAR package structure, see Configure AUTOSAR Packages.

Generate Report for AUTOSAR Software Architectures Using Simulink Report Generator

If you have System Composer™ and Simulink Report Generator™ licenses, you can generate a report for an AUTOSAR architecture model and its artifacts. For more information, see System Composer Report Generation for Software Architectures (System Composer).

See Also

| |

Related Topics