When you want to share a model with a third-party without revealing intellectual property, protect the model. When you create a protected model, you conceal the implementation details of the original model by compiling it into a model reference. The protected model includes derived files to support the optional functionalities that you specify.
When you protect a model, you can allow the user of the protected model to:
Open a read-only web view of the model, including model contents and block parameters.
Simulate the model in accelerator (default), rapid accelerator, and normal modes.
Generate code for a model that includes the protected model.
Generate HDL code for a model that includes the protected model. To learn about creating protected models with HDL code generation support, see Create Protected Models to Conceal Contents and Generate HDL Code (HDL Coder).
Generate code for the protected model through the standalone interface, if you have Embedded Coder® and specify an ERT-based system target file for the model.
You can optionally password-protect each option. If you choose-password protection for one of these options, the software protects the supporting files by using AES-256 encryption.
When you create a protected model:
By default, Simulink® creates and stores a protected version of the model in the current
working folder. The protected model has the same name as the source model, with
The original model file, with the
.slx extension, does not
change. If you protect the model through a Model block, that
Model block does not change.
The protected model file consists of the model itself and supporting files, depending on the options that you select when you create the protected model.
Create a protected model by using one of these options:
The Model block context menu.
The Simulink Toolstrip Simulation tab. To create a protected model from the current model, from the Save list, select Protected Model.
The Simulink Toolstrip C Code tab. To create a protected model from the current model, from the Share list, select Generate Protected Model. To create a protected model from a referenced model, click the Model block that references the model that you want to protect, and select Generate Protected Model From Selected Model Block from the Share list.
If your protected model requires supporting files, such as base workspace definitions or a data dictionary, include these files with the model when you share it. For more information, see Package and Share Protected Models.
This example shows how to create a protected model for read-only viewing, simulation, or code generation by using the Model block context menu.
Configure the Model blocks in the parent model to refer to the original referenced model. This step prevents the Model blocks from becoming protected references when you create the protected model.
Open the parent model that references the model you want to protect. For
this example, open the model
To run the workflow, create a local copy of the model
sldemo_mdlref_counter that you want to protect. You
can then create a local copy of the parent model
sldemo_mdlref_basic. You must save the parent model
in the same folder as the referenced model.
sldemo_mdlref_basic model that you saved
locally. Make sure that the Model blocks
CounterC reference the
sldemo_mdlref_counter model that you saved
For each Model block, open the Block Parameters dialog box
and specify the extension
.slx in the Model
name field. When both the model and the protected model exist
in the same folder,
.slxp takes precedence over
.slx. If you do not specify an extension, then the
original Model block in the model refers to the protected
model instead of the original model. Click OK.
Right-click any of the three Model blocks. From the context menu, select Subsystem & Model Reference > Create Protected Model for Selected Model Block.
In the Create Protected Model dialog box, select the Simulate and Use generated code check boxes. These options allow the protected model user to simulate and generate code for a model that references the protected model. If you want to password-protect the functionality of the protected model, enter a password with a minimum of four characters. Each option can have a unique password.
If you have Embedded
Coder and specify an ERT-based system target file (for example,
ert.tlc) for the model, the Code
interface field is visible.
In this example,
sldemo_mdlref_basic does not specify
an ERT-based system target file, therefore the Code
interface options are not available in the Create Protected
Model dialog box.
From the Code interface drop-down list, select one of these options:
Model reference — Specifies
code access through the model reference code interface, which
allows use of the protected model within a model reference
hierarchy. Users of the protected model can generate code from a
parent model that contains the protected model. Users can run
Model block SIL/PIL simulations with the
Top model — Specifies code
access through the standalone interface. Users of the protected
model can run Model block SIL/PIL simulations
with the protected model.
From the Content type list, select
Obfuscated source code to conceal the source
code purpose and logic of the protected model. For more information on the
model protection options, see Content type.
If you have HDL Coder™, you can select the Use generated HDL code check box to generate HDL code for a model that references the protected model. If you want to password-protect this functionality of the protected model, you must specify a minimum of eight characters. You cannot obfuscate the HDL source code for a protected model.
In this example, the referenced model
data types. In the HDL Code Generation > Floating Point tab, set Library to
Floating Point and Latency Strategy to
ZERO. See also Create Protected Models to Conceal Contents and Generate HDL Code (HDL Coder).
In the Create protected model in field, specify the folder path for the protected model. The default value is the current working folder.
To create a harness model for the protected model, select the Create harness model for protected model check box. When you create the protected model, the harness model opens as a new, untitled model that contains only a Model block that references the protected model. To use the protected model, reference it through a Model block such as the one included in the harness model. For more information, see Reference Protected Models from Third Parties (Simulink).
To further customize your protected model, you can:
Click Create. An untitled harness model opens. You
can package the harness model with the protected model to share with a
third-party. They can copy the Model block from the harness
model to another model, where it is an interface to the protected model. The
Simulation mode for the Model block
is set to
Accelerator. You cannot change the
When you create the protected model from the Simulink Editor, a protected model report is generated and included as part of the protected model. For this example, to view the protected model report, double-click the protected model or right-click the protected-model badge icon on the block in the harness model and select Display Report.
The report contains:
A Summary, including the following tables:
Environment, providing the Simulink version and other product versions, and the platform used to create the protected model.
with password protection for each
possible functionality that the protected model
supports. If you configure your protected model for
multiple targets, this table includes a list of
Licenses, listing licenses required to run the protected model.
An Interface Report, including model interface information such as input and output specifications, exported function information, interface parameters, and data stores.
To generate a report when using the
function, set the ‘
Report’ option to
You can test the protected model to compare it to the original model. For more information, see Test Protected Models.
When you create a protected model, consider these following requirements:
You must have a Simulink Coder™ to create a protected model. You can also create a protected model if you have a HDL Coder license.
The model must be available on the MATLAB® path.
The model cannot have unsaved changes.
The model cannot use a noninlined S-function directly or indirectly.
The model uses the configuration that is active during protection. You cannot change the configuration of a protected model.
If the model contains variants, the protected model includes only the variant that is active during protection.
The model protection process does not preserve callbacks. For more information on creating callbacks for use with a protected model, see Define Callbacks for Protected Models
Do not rename the protected model or change its suffix. If you do so, the model is unusable until you restore its original name and suffix.
Use a unique name for the model and for models that it references. If a protected model references a model that shares a name with either a different protected model or a different model within the hierarchy of another protected model, there are limitations for using the protected models. If a top model references two protected models that have such a naming conflict, you cannot protect the top model, generate code for the top model, or simulate the top model in software-in-the-loop (SIL), processor-in-the-loop (PIL), or rapid accelerator modes.
The model must also meet the requirements listed in Model Reference Requirements and Limitations (Simulink).
To create a protected model that supports code generation, your model must meet these requirements:
The protected model must use normal, accelerator, software-in-the-loop (SIL), or processor-in-the-loop (PIL) modes and a single target.
Do not select the Code Generation > Verification > Measure function execution time check box. If you have this option selected when you protect your model, the software turns off the parameter and displays a warning.
Protected referenced models must support code generation without password protection.
The protected model must be compatible with the Content type of each protected referenced model. This table provides compatibility information.
Code Generation Content Type Compatibility
|Protected Parent Model Content Type||Compatible Protected Referenced Model Content Types|
When the Content type of the protected parent model
and protected referenced models do not match, code generation applies the
Content type that provides the higher level of
protection. For example, a protected parent model set for
Binaries for protected referenced models that
are set to
Obfuscated source code. A protected
parent model set for
Readable source code
Obfuscated source code for protected
referenced models that are set to
To avoid an error during code generation of a model that includes the protected model:
The protected model name must be unique from other model names in the same model reference hierarchy.
The interfaces must match.
The parameters must be compatible.
If your protected model is referenced by another model that is protected, your model must:
Support accelerator mode. You must select
Simulate in the Create Protected Model dialog
box or set
'CodeGeneration' by using the
Use the default
Not use password-protection for simulation.
Not have callbacks.
Support the operations that the protected parent model supports without password-protection.
Use a Content type that is compatible with the Content type of the protected parent model if the protected parent model will support code generation. For a list of compatible Content type options, see the table in the preceding section.
Not reference a model that shares a name with either a different protected model or a different model within the hierarchy of another protected model.
If the model that you want to protect references a protected model, the protected referenced model must meet the preceding requirements.
A protected model that you create with the Use generated HDL code option selected allows encryption and support for simulation and HDL code generation from a model that references the protected model. You cannot obfuscate the HDL source code, have callbacks, or use nested protected models with this option. To learn more about HDL code generation limitations, see Protected Model Restrictions for HDL Code Generation (HDL Coder).