Main Content

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:

  • Simulate a model that includes the protected model in normal, accelerator, rapid accelerator, or external mode.

  • Open a read-only web view of the model, including model contents and block parameters. Creating a read-only web view of the model requires a Simulink Report Generator™ license.

  • Generate HDL code for a model that includes the protected model.

  • Generate C and C++ code for a model that includes the protected model, if you have a Simulink Coder license.

  • Generate code for the protected model through the standalone interface, if you have an Embedded Coder license 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 Simulink.ModelReference.protect function.

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 .slxp extension.

  • 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.

  • 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.

    • Family

    • Device Name

    • Package Name

    • Speed value

    • Target frequency

  • The solver settings that you specify in the Solver pane of the Configuration Parameters dialog box must be Fixed-step and auto.

  • 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 multiple in 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 named hdlcoder_protected_model_parent_harness. To view the information overlays, in the Simulink Toolstrip, on the Modeling tab, click Update Model.

mdl = "hdlcoder_protected_model_parent_harness";
open_system(mdl)
set_param(mdl,SimulationCommand="Update")

Parent model

To navigate to the Model block in your parent model, double-click the Subsystem block named DUT. Then, double-click the Subsystem block named mynested. In this subsystem, a Model block references the model named hdlcoder_referenced_model_gain.

ss = "hdlcoder_protected_model_parent_harness/DUT/mynested";
open_system(ss)

Subsystem with Model block

Open the Property Inspector. Then, select the Model block. In this example, the Model name value includes the .slx extension. 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.

The Model block references the model named hdlcoder_referenced_model_gain.slx, which is the model that you want to protect. To view the referenced model, double-click the Model block or open the model named hdlcoder_referenced_model_gain in a separate window.

refmdl = "hdlcoder_referenced_model_gain";
open_system(refmdl)
set_param(refmdl,SimulationCommand="Update")

Referenced model

Protect the Referenced Model

Select the Model block. Then, in the Simulink Toolstrip, on the Model Block tab, click Protect.

The Protected Model Creator opens.

Protected Model Creator open for hdlcoder_referenced_model_gain

On the General tab, specify the functionality to support.

  1. Select Simulation. This option allows the protected model user to simulate the model that references the protected model.

    Tip

    The Protected Model Creator caches your settings for a model during a MATLAB session. If you close and reopen the dialog box, the settings persist. Passwords and tunable parameter selections are not cached. To restore the default settings, click Reset. (since R2023b)

  2. If you have Simulink Coder or Embedded Coder, you can specify additional settings such as enabling code generation support with password protection by selecting Code generation or specifying a Code interface. To learn more about these options, see Protect Models to Conceal Contents (Embedded Coder).

  3. To generate HDL code for a model that references the protected model, select HDL code generation. 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.

  4. Optionally, specify a custom text tag in the Identifier tag box. For example, to store file provenance information in a protected model, specify the job number, Git™ commit, or continuous integration system tag associated with creating the protected model. (since R2024b)

On the Save Options tab, specify where to save the protected model, whether to save the protected model in a project with its supporting files, and whether to create a harness model.

  1. In the Destination folder box, specify the folder path for the protected model. The default value is the current working folder.

  2. To automatically collect, create, and package supporting files with the protected model, select Package protected model with dependencies in a project. For this example, clear this option.

  3. To create a harness model for the protected model, select Create harness model for protected model. The harness model provides an isolated environment for the Model block that references the protected model. For this example, leave this option cleared.

When you finish configuring the protected model settings, click Create.

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 hdlsrc folder. 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 Protected Model Creator.

To create a protected model when using the Simulink.ModelReference.protect function, set Mode to HDLCodeGeneration. For example, run these commands to protect the referenced model hdlcoder_referenced_model_gain.

mdl = 'hdlcoder_referenced_model_gain';
Simulink.ModelReference.protect(mdl,'Mode','HDLCodeGeneration')

Protected Model Report

When you create the protected model from the Simulink Editor, a protected model report is generated and is 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.

Protected model report for hdlcoder_referenced_model_gain

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, Off, or On 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 supported targets.

  • 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 Simulink.ModelReference.protect function, set Report to true.

To get information about the protected model programmatically, use the slxpinfo function.

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 hdlcoder_protected_model_parent_harness model:

  1. Authorize the protected model hdlcoder_referenced_model_gain.slxp if you specified a password when creating the protected model.

  2. Generate HDL code for the DUT Subsystem from the context menu or by using the makehdl function.

    makehdl('hdlcoder_protected_model_parent_harness/DUT')

See Also

Tools

Functions

Related Topics