Variable interpolation is a technique used to dynamically insert the value of variables into strings or text.

The variable name in the JSON file must adhere to the string format, enclosed by double curly braces, and consist solely of alphanumeric and underscore characters (for example,

"(( VARIABLE_1 ))"

).

{
"address": "{{ VARIABLE_1 }}"
}

Setting variables via CLI

Variables can be set directly from the command line using the

--set

option. The variable name in the CLI command must correspond to the variable name specified in the JSON file. The value may contain any printable characters; however, the usage of quotes should be cautious.

$ edgeprotecttools run-config --input commands.json --set VARIABLE_1 0x12345678

The interpolation will result in the following:

(
"address": "0x12345678"
)

Note:

The variable interpolation does not modify the input JSON file. It will interpolate the variables only in the runtime.

Using symbol files for variable interpolation

In addition to the

--set

option, variables can be provided via symbol files using the

--symbol

and

--symbol-search

options:

  • --symbol <file>: Specify one or more symbol files containing variable definitions. Each file should provide a mapping of variable names to values.
  • --symbol-search <directory>: Specify one or more directories to search for symbol files. All valid symbol files found in the specified directories will be used for variable interpolation.

You can specify one or more symbol files using the

--symbol

option, or provide a directory containing multiple symbol files using the

--symbol-search

option. All variables from all discovered symbol files will be used for interpolation, provided their names are unique across all sources.

Symbol file structure

A symbol file is a JSON file that defines a mapping of variable names to their values. Each key in the file represents a variable name, and its value is the string to be interpolated. Variable names must consist only of alphanumeric characters and underscores.

Example symbol file:

{
"version":1,
"symbolInformation":[
{
"name":"CYMEM_CM33_0_S_extended_boot_reserved_START",
"value":"0x22000000"
},
{
"name":"CYMEM_CM33_0_S_extended_boot_reserved_C_START",
"value":"0x02000000"
}
]
}

Example usage:

# Set variables from a symbol file
$ edgeprotecttools run-config --input commands.json --symbol symbols.json

# Set variables from all symbol files in a directory
$ edgeprotecttools run-config --input commands.json --symbol-search ./symbols_dir

Combining variable sources

You may use

--set

,

--symbol

, and

--symbol-search

options simultaneously. All variables from these sources are merged for interpolation. Variable names must be unique across all sources.

This flexible approach allows you to manage variable interpolation efficiently, whether you prefer to define variables inline, in files, or by searching directories for symbol definitions.