Obscure referenced model contents to hide intellectual property
Simulink.ModelReference.protect(
creates
a protected model from the specified model
)model
. It
places the protected model in the current working folder. The protected
model has the same name as the source model. It has the extension .slxp
.
Simulink.ModelReference.protect(
uses additional options specified by one or more model
,Name,Value
)Name,Value
pair arguments.
[
creates
a harness model for the protected model. It returns the handle of
the harnessed model in harnessHandle
] = Simulink.ModelReference.protect(model
,'Harness
',true)harnessHandle
.
[~ ,
returns
a cell array that includes the names of base workspace variables used
by the protected model.neededVars
] = Simulink.ModelReference.protect(model
)
Protect a referenced model and place the protected model in the current working folder.
sldemo_mdlref_bus;
model= 'sldemo_mdlref_counter_bus'
Simulink.ModelReference.protect(model);
A protected model named sldemo_mdlref_counter_bus.slxp
is
created. The protected model file is placed in the current working
folder.
Protect a referenced model and place the protected model in a specified folder.
sldemo_mdlref_bus; model= 'sldemo_mdlref_counter_bus' Simulink.ModelReference.protect(model,'Path','C:\Work');
A protected model named sldemo_mdlref_counter_bus.slxp
is
created. The protected model file is placed in C:\Work
.
Protect a referenced model, generate code for it in normal mode, and obfuscate the code.
sldemo_mdlref_bus; model= 'sldemo_mdlref_counter_bus' Simulink.ModelReference.protect(model,'Path','C:\Work','Mode','CodeGeneration',... 'ObfuscateCode',true);
A protected model named sldemo_mdlref_counter_bus.slxp
is
created. The protected model file is placed in the C:\Work
folder.
The protected model runs as a child of the parent model. The code
generated for the protected model is obfuscated by the software.
Protect a referenced model, and generate HDL code for it in normal mode.
parent_model= 'hdlcoder_protected_model_parent_harness'; reference_model_to_protect = 'hdlcoder_referenced_model_gain'; Simulink.ModelReference.protect(reference_model_to_protect, ... 'Mode','HDLCodeGeneration')
A protected model named
hdlcoder_referenced_model_gain.slxp
is created. The
protected model file is placed in the same folder as the parent model and
the referenced model. The protected model runs as a child of the parent
model.
Set the hdl option to true
with
Mode set to CodeGeneration
to
enable both C code generation and HDL code generation support for a
protected model that you create.
parent_model= 'hdlcoder_protected_model_parent_harness'; reference_model_to_protect = 'hdlcoder_referenced_model_gain'; Simulink.ModelReference.protect(reference_model_to_protect, ... 'Mode','CodeGeneration','hdl',true)
Control code visibility by allowing users to view only binary files and headers in the code generated for a protected model.
sldemo_mdlref_bus; model= 'sldemo_mdlref_counter_bus' Simulink.ModelReference.protect(model,'Mode','CodeGeneration','OutputFormat',... 'CompiledBinaries');
A protected model named sldemo_mdlref_counter_bus.slxp
is
created. The protected model file is placed in the current working
folder. Users can view only binary files and headers in the code generated
for the protected model.
Create a harness model for a protected model and generate an HTML report.
sldemo_mdlref_bus; modelPath= 'sldemo_mdlref_bus/CounterA' [harnessHandle] = Simulink.ModelReference.protect(modelPath,'Path','C:\Work',... 'Harness',true,'Report',true);
A protected model named sldemo_mdlref_counter_bus.slxp
is
created, along with an untitled harness model. The protected model
file is placed in the C:\Work
folder. The folder
also contains an HTML report. The handle of the harness model is returned
in harnessHandle
.
model
— Model nameModel name, specified as a string or character vector. It contains the name of a model or the path name of a Model block that references the model to be protected.
Specify optional
comma-separated pairs of Name,Value
arguments. Name
is
the argument name and Value
is the corresponding value.
Name
must appear inside quotes. You can specify several name and value
pair arguments in any order as
Name1,Value1,...,NameN,ValueN
.
'Mode','CodeGeneration','OutputFormat','Binaries','ObfuscateCode',true
specifies
that obfuscated code be generated for the protected model. It also
specifies that only binary files and headers in the generated code
be visible to users of the protected model.'Harness'
— Option to create a harness modelOption to create a harness model, specified as a Boolean value.
Example: 'Harness',true
'Mode'
— Model protection mode'Normal'
(default) | 'Accelerator'
| 'CodeGeneration'
| 'HDLCodeGeneration'
| 'ViewOnly'
Model protection mode. Specify one of the following values:
'Normal'
: If the top model is running
in 'Normal'
mode, the protected model runs as a
child of the top model.
'Accelerator'
: The top model can
run in 'Normal'
, 'Accelerator'
,
or 'Rapid Accelerator'
mode.
'CodeGeneration'
: The top model
can run in 'Normal'
, 'Accelerator'
,
or 'Rapid Accelerator'
mode and support code generation.
'HDLCodeGeneration'
: The top model can run
in 'Normal'
,
'Accelerator'
, or 'Rapid
Accelerator'
mode and support HDL code generation.
(Requires HDL Coder™ license)
'ViewOnly'
: Turns off Simulate
and Generate code functionality modes. Turns on the read-only view
mode.
Example: 'Mode','Accelerator'
'CodeInterface'
— Interface through which generated code is accessed by Model block'Model reference'
(default) | 'Top model'
Applies only if the system target file (SystemTargetFile
) is set to an
ERT-based system target file (for example, ert.tlc
).
Requires Embedded
Coder® license.
Specify one of the following values:
'Model reference'
: 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. In addition, users can run Model block SIL/PIL simulations
with the protected model.
'Top model'
: Code access through
the standalone interface. Users of the protected model can run Model
block SIL/PIL simulations with the protected model.
Example: 'CodeInterface','Top model'
'ObfuscateCode'
— Option to obfuscate generated codeOption to obfuscate generated code, specified as a Boolean value. Applicable only when code generation during protection is enabled. Obfuscation is not supported for HDL code generation.
Example: 'ObfuscateCode',true
'Path'
— Folder for protected modelFolder for protected model, specified as a string or character vector.
Example: 'Path','C:\Work'
'Report'
— Option to generate a reportOption to generate a report, specified as a Boolean value.
To view the report, right-click the protected-model badge icon
and select Display Report. Or, call the Simulink.ProtectedModel.open
function with
the report
option.
The report is generated in HTML format. It includes information on the environment, functionality, and interface for the protected model.
Example: 'Report',true
'hdl'
— Option to generate HDL codeOption to generate HDL code, specified as a Boolean value.
This option requires HDL Coder license. When you enable this option, make sure that you
specify the Mode. You can set this option to
true
in conjunction with the
Mode set to CodeGeneration
to enable both C code and HDL code generation support for the protected
model.
If you want to enable only simulation and HDL code generation support,
but not C code generation, set Mode to
HDLCodeGeneration
. You do not have to set the
hdl option to true
.
Example: 'hdl',true
'OutputFormat'
— Protected code visibility'CompiledBinaries'
(default) | 'MinimalCode'
| 'AllReferencedHeaders'
This argument affects the output only when you specify Mode
as 'Accelerator'
or 'CodeGeneration
.
When you specify Mode
as 'Normal'
,
only a MEX-file is part of the output package.
Protected code visibility. This argument determines what part of the code generated for a protected model is visible to users. Specify one of the following values:
'CompiledBinaries'
: Only binary
files and headers are visible.
'MinimalCode'
: Includes only the minimal
header files required to build the code with the chosen build
settings. All code in the build
folder is visible. Users can inspect the code in the protected
model report and recompile it for their purposes.
'AllReferencedHeaders'
: Includes header
files found on the include path. All
code in the build folder is
visible. All headers referenced
by the code are also visible.
Example: 'OutputFormat','AllReferencedHeaders'
'Webview'
— Option to include a Web viewOption to include a read-only view of protected model, specified as a Boolean value.
To open the Web view of a protected model, use one of the following methods:
Right-click the protected-model badge icon and select Show Web view.
Use the Simulink.ProtectedModel.open
function.
For example, to display the Web view for protected model sldemo_mdlref_counter
,
you can call:
Simulink.ProtectedModel.open('sldemo_mdlref_counter', 'webview');
Double-click the .slxp
protected
model file in the Current Folder browser.
In the Block Parameter dialog box for the protected model, click Open Model.
Example: 'Webview',true
'Encrypt'
— Option to encrypt protected modelOption to encrypt a protected model, specified as a Boolean value. Applicable when you have specified a password during protection, or by using the following methods:
Password for read-only view of model: Simulink.ModelReference.ProtectedModel.setPasswordForView
Password for simulation: Simulink.ModelReference.ProtectedModel.setPasswordForSimulation
Password for code generation: Simulink.ModelReference.ProtectedModel.setPasswordForCodeGeneration
Password for HDL code generation: Simulink.ModelReference.ProtectedModel.setPasswordForHDLCodeGeneration
Example: 'Encrypt',true
'CustomPostProcessingHook'
— Option to add postprocessing function for protected model filesOption to add a postprocessing function for protected model
files, specified as a function handle. The function accepts a Simulink.ModelReference.ProtectedModel.HookInfo
object
as an input variable. This object provides information on the source
code files and other files generated during protected model creation.
It also provides information on exported symbols that you must not
modify. Prior to packaging the protected model, the postprocessing
function is called.
For a protected model with a top model interface, the Simulink.ModelReference.ProtectedModel.HookInfo
object
cannot provide information on exported symbols.
Example: 'CustomPostProcessingHook',@(protectedMdlInf)myHook(protectedMdlInf)
'Modifiable'
— Option to create a modifiable protected modelOption to create a modifiable protected model, specified as a Boolean value. To use this option:
Add a password for modification by using the Simulink.ModelReference.ProtectedModel.setPasswordForModify
function. If a password has not been added at the time that
you create the modifiable protected model, you are prompted
to create one.
Modify the options of your protected model by first
providing the modification password by using the Simulink.ModelReference.ProtectedModel.setPasswordForModify
function. Then use the Simulink.ModelReference.modifyProtectedModel
function to make your option changes.
Example: 'Modifiable',true
'Callbacks'
— Option to specify protected model callbacksOption to specify callbacks for a protected model, specified
as a cell array of Simulink.ProtectedModel.Callback
objects.
Example: 'Callbacks',{pmcallback_sim, pmcallback_cg}
'Sign'
— Option to sign with digital certificateThe digital certificate to use to sign a protected model, specified as
a character vector or string scalar. If the certificate file is
password-protected, use the Simulink.ModelReference.ProtectedModel.setPasswordForCertificate
function to provide the password before you use the certificate.
Example: 'Sign','my_certificate.pfx'
harnessHandle
— Handle of the harness modelHandle of the harness model, returned as a double or 0
,
depending on the value of Harness
.
If Harness
is true
, the value is the handle of the
harness model. Otherwise, the value is 0
.
neededVars
— Names of base workspace variablesNames of base workspace variables that the protected model uses, returned as a cell array.
The cell array can also include variables that the protected model does not use.
Protect Models to Conceal Contents (Simulink Coder)
Simulink.ModelReference.ProtectedModel.clearPasswords
| Simulink.ModelReference.ProtectedModel.clearPasswordsForModel
| Simulink.ModelReference.ProtectedModel.setPasswordForCodeGeneration
| Simulink.ModelReference.ProtectedModel.setPasswordForHDLCodeGeneration
| Simulink.ModelReference.ProtectedModel.setPasswordForModify
| Simulink.ModelReference.ProtectedModel.setPasswordForSimulation
| Simulink.ModelReference.ProtectedModel.setPasswordForView
| Simulink.ModelReference.modifyProtectedModel