Main Content

Protect Models to Conceal Contents

When you want to share a model with a third-party without revealing intellectual property, protect the model. Protecting a model conceals 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.

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.

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

  • Simulink®creates and stores a protected version of the model in a file that has the same name as the source model, with an.slxpextension.

  • The original model file, with the.slxextension, does not change. If you protect the model through aModelblock, thatModelblock 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.

This example shows how to create a protected model from a referenced model for read-only viewing, simulation, or code generation.

Prepare the Parent Model

Configure theModelblocks in the parent model to refer to the original referenced model. This step prevents theModelblocks from becoming protected references when you create the protected model.

  1. Open the parent model that references the model you want to protect. For this example, open the modelsldemo_mdlref_basic.

  2. To run the workflow, create a local copy of the modelsldemo_mdlref_counterthat you want to protect. You can then create a local copy of the parent modelsldemo_mdlref_basic. You must save the parent model in the same folder as the referenced model.

  3. Open thesldemo_mdlref_basicmodel that you saved locally. Make sure that theModelblocksCounterA,CounterB, andCounterCreference thesldemo_mdlref_countermodel that you saved locally.

  4. For eachModelblock, open the Block Parameters dialog box and specify the extension.slxin theModel namefield. When both the model and the protected model exist in the same folder,.slxptakes precedence over.slx. If you do not specify an extension, then the originalModelblock in the model refers to the protected model instead of the original model. ClickOK.

Protect the Referenced Model

  1. In thesldemo_mdlref_basicmodel, click any of the threeModelblocks. On the Simulink ToolstripModel Blocktab, clickProtect.

    Create Protected Model dialog box

  2. In the Create Protected Model dialog box, select theSimulateandUse generated codecheck 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.

  3. If you have Embedded Coder and specify an ERT-based system target file (for example,ert.tlc) for the model, theCode interfacefield is visible.

    In this example,sldemo_mdlref_basicdoes not specify an ERT-based system target file, therefore theCode interfaceoptions are not available in the Create Protected Model dialog box.

    From theCode interfacedrop-down list, select one of these options:

    • 模型参考— 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 runModelblock SIL/PIL simulations with the protected model.

    • Top model— Specifies code access through the standalone interface. Users of the protected model can runModelblock SIL/PIL simulations with the protected model.

  4. From theContent typelist, selectObfuscated source codeto conceal the source code purpose and logic of the protected model. For more information on the model protection options, seeContent type.

  5. Expand theTunable parameters for simulation部分并选择你想要的参数,the protected model user to be able to tune during simulation.

    For code generation, parameters with non-auto storage classes are tunable. For more information, seeStorage Classes for Parameters and Signals Used in Model Blocks.

  6. In theDestination folderbox, specify the folder path for the protected model. The default value is the current working folder.

  7. To automatically collect, create, and package supporting files with the protected model, setContentstoProtected Model (.slxp) and dependencies in a project.

    Note

    Before sharing the project, check whether the project contains the necessary supporting files. If supporting files are missing, simulating or generating code for the related harness model can help identify them. Add the missing dependencies to the project and update the harness model as needed.

  8. SettingContentstoProtected Model (.slxp) and dependencies in a project选择Create harness model for protected modelcheck box. The harness model is included in the project and provides an isolated environment for theModelblock that references the protected model.

    Harness model with model block that references the protected model sldemo_mdlref_counter.slxp.

  9. To further customize your protected model, you can:

  10. ClickCreate.

    A project archive (.mlproj) that contains the protected model, harness model, and supporting files appears in the specified destination folder. To test the protected model, extract the contents of the project archive by double-clicking it in the Current Folder browser and specifying the destination folder. Alternatively, right-click on the project archive and clickExtract Here. The project opens, and the extracted files are in a new folder named after the project archive.

  11. 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 selectDisplay Report.

    Protected Model report for sldemo_mdlref_counter.

    The report contains:

    • ASummary, including the following tables:

      • Environment, providing the Simulink version and other product versions and the platform used to create the protected model.

      • Supported functionality, reportingOn,Off, orOn 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.

    • AnInterface Report, including model interface information such as input and output specifications, exported function information, interface parameters, and data stores.

    The report does not contain other sections that appear in a code generation report for non-protected models, such as a code metrics report and traceability report, because these reports include more information about the model's design.

  12. You can test the protected model to compare it to the original model. For more information, seeTest Protected Models.

  13. 使用防ected model in a model hierarchy, reference it through aModelblock such as the one included in the harness model. TheSimulation modeforModelblocks that reference a protected model is set toAccelerator. You cannot change the mode. For more information, seeReference Protected Models from Third Parties.

Other Methods of Protecting Models

To create a protected model from the current model, use one of these options:

  • On the Simulink ToolstripSimulationtab, click theSavebutton arrow, then selectProtected Model.

  • On the Simulink ToolstripC Codetab, click theSharebutton arrow, then selectGenerate Protected Model.

To programmatically create a protected model, use theSimulink.ModelReference.protectfunction.

Protected Model Requirements and Limitations

When you create a protected model, consider these following requirements:

  • You must have aSimulink Coder™or HDL 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 model protection process does not preserve callbacks. For more information on creating callbacks for use with a protected model, see为保护模型定义回调

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

  • If your model includes a non-inlined S-function, use a unique name for the .MEX file. If there is a name conflict with a different .MEX file on the MATLAB path, you cannot simulate the protected model.

我列出的模型必须满足要求nModel Reference Requirements and Limitations.

Code Generation Requirements and Limitations

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.

  • The protected model must not include non-inlined S-functions.

  • Do not select theCode Generation > Verification > Measure function execution timecheck 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 theContent typeof 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
    Binaries
    • Binaries

    • Obfuscated source code

    Binarieswith'ObfuscateCode'set to'false'
    • Binaries

    • Binarieswith'ObfuscateCode'set to'false'

    • Obfuscated source code

    • Readable source code

    Obfuscated source code
    • Obfuscated source code

    Readable source code
    • Obfuscated source code

    • Readable source code

    When theContent typeof the protected parent model and protected referenced models do not match, code generation applies theContent typethat provides the higher level of protection. For example, a protected parent model set forBinariesgeneratesBinariesfor protected referenced models that are set toObfuscated source code. A protected parent model set forReadable source codegeneratesObfuscated source codefor protected referenced models that are set toObfuscated source code.

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.

Nested Protected Model Requirements and Limitations

To enable a recipient of your protected model to protect a model that references it, your protected model must:

  • Support accelerator mode. You must selectSimulatein the Create Protected Model dialog box or set“模式”to'Accelerator'or'CodeGeneration'using theSimulink.ModelReference.protectfunction.

  • Use the default'CodeInterface'setting:'Model reference'.

  • Not use password protection for simulation.

  • Not have callbacks.

  • Support without password protection the operations that the protected parent model is intended to support.

  • Use aContent typethat is compatible with the intendedContent typeof the protected parent model if the protected parent model is intended to support code generation. For a list of compatibleContent typeoptions, see the table in the preceding section.

  • Use the same compiler as the protected parent model is intended to use.

  • 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 referenced protected model must meet the preceding requirements.

When you protect a model that references a protected model, you must specify the tunable parameters of the referenced protected model as tunable for the model you are protecting.

Note

A protected model that you create with theUse generated HDL codeoption 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, seeProtected Model Restrictions for HDL Code Generation(HDL Coder).

Related Topics

Baidu
map