Create Protected Models to Conceal Contents and Generate HDL Code
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 referenced model. The protected model includes derived files to support the optional functionalities that you specify, such as support for C code generation or HDL code generation.
If you have a HDL Coder™ license, you can create a protected model with simulation and HDL code generation support. The protected model user can then generate HDL code for models that reference the protected model that you created. To enable C code generation support or specify additional options such as code interface, you must have a Simulink® Coder™ or Embedded Coder® license. To learn more about that workflow, see Protect Models to Conceal Contents.
How Model Protection Works
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 HDL code for a model that includes the protected model.
Generate C code for a model that includes the protected model, if you have Simulink 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.
How to Create a Protected Model
Create a protected model by using one of these options:
To create a protected model from a referenced model, select the Model block and on the Simulink Toolstrip Model Block tab, click the Protect button.
To create a protected model from the current model:
On the Simulink Toolstrip Apps tab, select HDL Coder. The HDL Code tab appears.
Select the Model block and on the HDL Code > Share tab, select Generate Protected Model.
To programmatically create a protected model, use the
When you create a protected model:
Simulink creates and stores a protected version of the model in a file that has the same name as the source model, with an
The original model file, with the
.slxextension, does not change. If you protect the model through a Model block, that Model block does not change.
Optionally, Simulink creates a project archive (
.mlproj) that contains the protected model, a harness model for the protected model, and additional supporting files.
If your protected model requires additional supporting files, such as base workspace definitions or a data dictionary, include these files with the model when you share the protected model. For more information, see Package and Share Protected Models.
General Protected Model Requirements and Limitations
When you create a protected model, consider these requirements:
You must have a HDL Coder or Simulink Coder license to create a protected model.
The model must be available on the MATLAB® path.
The model cannot have unsaved changes.
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 protected model name must not be modified. Renaming the model or changing the suffix makes the model unusable until you restore its original name and suffix.
The model must also meet all requirements listed in Model Reference Requirements and Limitations.
Protected Model Restrictions for HDL Code Generation
When you create a protected model that has HDL code generation support, these restrictions apply:
The protected model must use the same configuration parameters as the top level that it is referenced from.
In R2021b, HDL Coder enables a difference in the values of these parameters between the protected model and the top model so that you can simulate and generate HDL code for top model and protected models while retaining top model synthesis parameters settings.
The solver settings that you specify in the Solver pane of the Configuration Parameters dialog box must be
You must not enable these settings in the Configuration Parameters dialog box:
Generate parameterized HDL code from masked subsystem
Module name prefix
Use trigger signal as clock
Minimize clock enables
Scalarize vector ports
Allow clock-rate pipelining at DUT output ports
Models with multiple clock signals or the Clock inputs set to
multiplein the Configuration Parameters dialog box are not supported.
Models that contain model arguments are not supported.
HDL source code of the protected model cannot be obfuscated.
Nested protected models are not supported.
The protected model cannot have callbacks.
To learn more about limitations for C code generation, see Code Generation Requirements and Limitations.
Prepare the Parent Model
This example shows how you can protect a model that is referenced by a Model block in the parent model. Open the parent model
Navigate to the Model block in your parent model. If you double-click the
DUT Subsystem, and then open the
mynested Subsystem, you see a Model block that references the model
Open the Model block and make sure that a modelname with the extension
.slx is specified in the Model name field. When both the referenced model and the protected model exist in the same folder, the parent model references the protected model unless the extension is specified.
In this case, the Model block is referencing the model
hdlcoder_referenced_model_gain.slx, the model that you want to protect. Double-click the
Model block or open the model
hdlcoder_referenced_model_gain in a separate window.
Protect the Referenced Model
Select the Model block.
On the Simulink Toolstrip Model Block tab, click Protect.
In the Create Protected Model dialog box, select the Simulate dialog box. This option allows the protected model user to simulate the model that references the protected model.
If you have Simulink Coder or Embedded Coder, you can specify additional settings such as enabling code generation support with password protection by using the Use generated code check box or specifying a Code interface. To learn more about these options, see Protect Models to Conceal Contents (Embedded Coder).
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 can specify a unique password for this option. You cannot obfuscate the HDL source code for a protected model.
In the Destination folder box, specify the folder path for the protected model. The default value is the current working folder.
To automatically collect, create, and package supporting files with the protected model, set Contents to
Protected Model (.slxp) and dependencies in a project. In this example, set Contents to
Protected Model (.slxp) only.
To create a harness model for the protected model, select the Create harness model for protected model check box. The harness model provides an isolated environment for the Model block that references the protected model. In this example, leave the check box cleared.
HDL Coder checks compatibility of the model for HDL code generation then generates code for the model. The generated code file contents are in the
hdlsrcfolder. To learn about the files that are generated, see Package and Share Protected Models.
To use the protected model in a model hierarchy, reference it through a Model block. The Simulation mode for Model blocks that reference a protected model is set to
Accelerator. You cannot change the mode. For more information, see Reference Protected Models from Third Parties.
To learn more about the options, see Create Protected Model.
To create a protected model when using the
Simulink.ModelReference.protect function, set the
HDLCodeGeneration. For example, run this command to protect the
Simulink.ModelReference.protect('hdlcoder_referenced_model_gain', ... 'Mode','HDLCodeGeneration')
Protected Model Report
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, the Simulink Coder version, the HDL Coder version, and platform used to create the protected model.
Supported functionality, reporting
On with password protectionfor each possible functionality that the protected model supports. If you configure your protected model for multiple targets, this table includes a list of supported targets.
Licenses, listing licenses required to run the protected model.
An Interface Report, including model interface information such as input and output specifications, interface parameters, and data stores.
To generate a report when using the
Simulink.ModelReference.protect function, set the ‘
Generate HDL Code for Models Referencing Protected Model
If the protected model has simulation and HDL code generation support, the protected model user can simulate and generate HDL code from a model that references the protected model. You generate HDL code for a model that references a protected model in the same manner as how you would generate code for a regular model.
If the protected model is password-protected, before you generate code, right-click the protected model badge icon and select Authorize. You must then enter the password for each option. If the entered password matches the password that you specified when creating the protected model, the model is authorized. You can then generate HDL code for the model.
For example, to generate HDL code for the protected model
hdlcoder_referenced_model_gain.slxp that is referenced by the
Authorize the protected model
hdlcoder_referenced_model_gain.slxpif you specified a password when creating the protected model.
Generate HDL code for the DUT Subsystem from the context menu or by using the