Create Protected Models to Conceal Contents and Generate HDL Code - MATLAB & Simulink (original) (raw)

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:

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:

When you create a protected model:

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:

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:

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, clickProtect.

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, seeProtect Models to Conceal Contents (Embedded Coder).
  3. To generate HDL code for a model that references the protected model, selectHDL 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 theIdentifier 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, clickCreate.

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 aModel block. The Simulation mode forModel blocks that reference a protected model is set toAccelerator. 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 toHDLCodeGeneration. For example, run these commands to protect the referenced modelhdlcoder_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 .

Protected model report for hdlcoder_referenced_model_gain

The report contains:

To generate a report when using the Simulink.ModelReference.protect function, set Report totrue.

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 . 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 modelhdlcoder_referenced_model_gain.slxp that is referenced by thehdlcoder_protected_model_parent_harness model:

  1. Authorize the protected modelhdlcoder_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 themakehdl function.
    makehdl('hdlcoder_protected_model_parent_harness/DUT')

See Also

Tools

Functions

Topics