Skip to content

Commit 27c8acf

Browse files
authored
IEP-1613 Encrypted Flash: regular flash command is not separated from encrypted-flash command (#1301)
* feat: added a flash encryption feature * fix: removed code duplication and added more logs * feat: run -E in serail monitor after flash * feat: added the flash encryption checbox * fix: remove the dead code * feat: updating the flash documantation * fix: fix for image not show in rst * fix: trying to fix warning note * fix: fixed typo in bundle.property flash_command
1 parent f1f10a7 commit 27c8acf

File tree

16 files changed

+190
-41
lines changed

16 files changed

+190
-41
lines changed

bundles/com.espressif.idf.core/OSGI-INF/l10n/bundle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ openocd_scripts = OPENOCD_SCRIPTS represents the value specified in environment
77
jtag_flash_args = JTAG_FLASH_ARGS dynamically converts ${JTAG_FLASH_ARGS} into a command line with -c and -f options. These options are generated based on the current launch target, configuring settings like flash voltage and specifying configuration files for the JTAG interface and target device.
88
gdb_client_executable = GDB_CLIENT_EXECUTABLE is a dynamic variable that is replaced during the debug session with the appropriate toolchain path automatically based on the selected target.
99
serial_port = serial_port is a dynamic variable that is replaced by the serial port specified in the launch target
10+
flash_command = Specifies which idf.py flash command should be executed, depending on whether flash encryption is enabled (e.g., "flash" or "encrypted-flash").

bundles/com.espressif.idf.core/plugin.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,5 +275,10 @@ config-only component and an interface library is created instead."
275275
name="serial_port"
276276
resolver="com.espressif.idf.core.variable.UartVariableResolver">
277277
</variable>
278+
<variable
279+
description="%flash_command"
280+
name="flash_command"
281+
resolver="com.espressif.idf.core.variable.UartVariableResolver">
282+
</variable>
278283
</extension>
279284
</plugin>

bundles/com.espressif.idf.core/src/com/espressif/idf/core/IDFConstants.java

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,22 @@ public interface IDFConstants
3939
* idf python file
4040
*/
4141
String IDF_PYTHON_SCRIPT = "idf.py"; //$NON-NLS-1$
42-
42+
4343
/**
4444
* idf.py list targets
4545
*/
46-
String IDF_LIST_TARGETS_CMD = "--list-targets"; //$NON-NLS-1$
47-
46+
String IDF_LIST_TARGETS_CMD = "--list-targets"; //$NON-NLS-1$
47+
4848
/**
4949
* idf_monitor python file
5050
*/
5151
String IDF_MONITOR_PYTHON_SCRIPT = "idf_monitor.py"; //$NON-NLS-1$
52-
52+
5353
/**
5454
* idf sysviewtrace_proc script file
5555
*/
5656
String IDF_SYSVIEW_TRACE_SCRIPT = "sysviewtrace_proc.py"; //$NON-NLS-1$
57-
57+
5858
/**
5959
* idf app_trace_folder
6060
*/
@@ -64,17 +64,17 @@ public interface IDFConstants
6464
* idf tools file
6565
*/
6666
String IDF_TOOLS_SCRIPT = "idf_tools.py"; //$NON-NLS-1$
67-
67+
6868
/**
6969
* idf_monitor.py
7070
*/
7171
String IDF_MONITOR_SCRIPT = "idf_monitor.py"; //$NON-NLS-1$
72-
72+
7373
/**
7474
* idf size file
7575
*/
7676
String IDF_SIZE_SCRIPT = "idf_size.py"; //$NON-NLS-1$
77-
77+
7878
/**
7979
* idf tools.json file for installable tools
8080
*/
@@ -84,9 +84,11 @@ public interface IDFConstants
8484
* <IDF_PATH>/tools
8585
*/
8686
String TOOLS_FOLDER = "tools"; //$NON-NLS-1$
87-
87+
8888
String FLASH_CMD = "flash"; //$NON-NLS-1$
8989

90+
String FLASH_ENCRYPTED_CMD = "encrypted-flash"; //$NON-NLS-1$
91+
9092
/**
9193
* <IDF_PATH>/tools/cmake
9294
*/
@@ -106,7 +108,7 @@ public interface IDFConstants
106108
* Json config menu file name
107109
*/
108110
String KCONFIG_MENUS_JSON = "kconfig_menus.json"; //$NON-NLS-1$
109-
111+
110112
/**
111113
* sdk config json file
112114
*/
@@ -130,28 +132,28 @@ public interface IDFConstants
130132
String TOOLS_INSTALL_CMD = "install"; //$NON-NLS-1$
131133

132134
String TOOLS_INSTALL_ALL_CMD = "all"; //$NON-NLS-1$
133-
135+
134136
String TOOLS_INSTALL_PYTHON_CMD = "install-python-env"; //$NON-NLS-1$
135-
137+
136138
String TOOLS_LIST_CMD = "list"; //$NON-NLS-1$
137139

138140
String TOOLS_EXPORT_FORMAT_KEYVALUE = "key-value"; //$NON-NLS-1$
139141

140142
String TOOLS_EXPORT_CMD_FORMAT = "--format"; //$NON-NLS-1$
141143

142144
String TOOLS_EXPORT_CMD_FORMAT_VAL = TOOLS_EXPORT_CMD_FORMAT + "=" + TOOLS_EXPORT_FORMAT_KEYVALUE; //$NON-NLS-1$
143-
145+
144146
String PYTHON_CMD = "python"; //$NON-NLS-1$
145-
147+
146148
String PYTHON3_CMD = "python3"; //$NON-NLS-1$
147149

148150
/**
149151
* <IDF_PATH>/components
150152
*/
151153
String COMPONENTS_FOLDER = "components"; //$NON-NLS-1$
152-
154+
153155
String ESP_CORE_DUMP_FOLDER = "espcoredump"; //$NON-NLS-1$
154-
156+
155157
String ESP_CORE_DUMP_SCRIPT = "espcoredump.py"; //$NON-NLS-1$
156158

157159
/**
@@ -172,13 +174,13 @@ public interface IDFConstants
172174
String ESP_TOOL_CHIP_ID_CMD = "chip_id"; //$NON-NLS-1$
173175

174176
String ESP_TOOL_ERASE_FLASH_CMD = "erase_flash"; //$NON-NLS-1$
175-
177+
176178
String ESP_WRITE_FLASH_CMD = "write_flash"; //$NON-NLS-1$
177179

178180
/**
179181
* Property to store project custom build directory
180182
*/
181183
String BUILD_DIR_PROPERTY = "idf.buildDirectory.property"; //$NON-NLS-1$
182-
184+
183185
String PROECT_DESCRIPTION_JSON = "project_description.json"; //$NON-NLS-1$
184186
}

bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/IDFLaunchConstants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ public final class IDFLaunchConstants
1919
public static final String SERIAL_MONITOR_ENCODING = "SERIAL_MONITOR_ENCODING"; //$NON-NLS-1$
2020
public static final String BUILD_FOLDER_PATH = "com.espressif.idf.launch.serial.core.idfBuildFolderPath"; //$NON-NLS-1$
2121
public static final String OPENOCD_USB_LOCATION = "OPENOCD_USB_ADAPTER_LOCATION"; //$NON-NLS-1$
22+
public static final String FLASH_ENCRYPTION_ENABLED = "com.espressif.idf.launch.FLASH_ENCRYPTION_ENABLED"; //$NON-NLS-1$
23+
2224
}

bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/IDFUtil.java

Lines changed: 59 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -717,37 +717,80 @@ public static void updateEspressifPrefPageOpenocdPath()
717717

718718
public static String getCurrentTarget()
719719
{
720-
IProject project = null;
720+
IProject project = getProjectFromActiveLaunchConfig();
721+
if (project == null)
722+
{
723+
Logger.log(Messages.IDFUtil_CantFindProjectMsg);
724+
return null;
725+
}
726+
return new SDKConfigJsonReader(project).getValue("IDF_TARGET"); //$NON-NLS-1$
727+
}
728+
729+
public static boolean isFlashEncrypted()
730+
{
731+
ILaunchConfiguration configuration;
732+
try
733+
{
734+
configuration = getActiveLaunchConfiguration();
735+
736+
return configuration != null
737+
&& configuration.getAttribute(IDFLaunchConstants.FLASH_ENCRYPTION_ENABLED, false);
738+
}
739+
catch (CoreException e)
740+
{
741+
Logger.log(e);
742+
}
743+
744+
return false;
745+
}
746+
747+
/**
748+
* Returns the active project from the currently selected launch configuration.
749+
*/
750+
public static IProject getProjectFromActiveLaunchConfig()
751+
{
721752
try
722753
{
723-
ILaunchBarManager launchBarManager = IDFCorePlugin.getService(ILaunchBarManager.class);
724-
ILaunchConfiguration activeConfig = launchBarManager.getActiveLaunchConfiguration();
725-
if (activeConfig == null || activeConfig.getMappedResources() == null)
754+
ILaunchConfiguration activeConfig = getActiveLaunchConfiguration();
755+
if (activeConfig == null)
726756
{
727-
Logger.log(Messages.IDFUtil_CantFindProjectMsg);
728-
return StringUtil.EMPTY;
757+
return null;
758+
}
759+
760+
IResource[] resources = activeConfig.getMappedResources();
761+
if (resources == null || resources.length == 0)
762+
{
763+
Logger.log("No mapped resources in active launch configuration."); //$NON-NLS-1$
764+
return null;
729765
}
730-
project = activeConfig.getMappedResources()[0].getProject();
731-
Logger.log("Project:: " + project); //$NON-NLS-1$
766+
767+
IProject project = resources[0].getProject();
768+
Logger.log("Active project: " + project); //$NON-NLS-1$
769+
return project;
732770
}
733771
catch (CoreException e)
734772
{
735773
Logger.log(e);
774+
return null;
736775
}
737-
return new SDKConfigJsonReader(project).getValue("IDF_TARGET"); //$NON-NLS-1$
738776
}
739777

740-
public static IProject getProjectFromActiveLaunchConfig() throws CoreException
778+
private static ILaunchConfiguration getActiveLaunchConfiguration() throws CoreException
741779
{
742-
final ILaunchBarManager launchBarManager = IDFCorePlugin.getService(ILaunchBarManager.class);
743-
ILaunchConfiguration launchConfiguration = launchBarManager.getActiveLaunchConfiguration();
744-
IResource[] mappedResources = launchConfiguration.getMappedResources();
745-
if (mappedResources != null && mappedResources[0].getProject() != null)
780+
ILaunchBarManager launchBarManager = IDFCorePlugin.getService(ILaunchBarManager.class);
781+
if (launchBarManager == null)
746782
{
747-
return mappedResources[0].getProject();
783+
Logger.log("LaunchBarManager service not found."); //$NON-NLS-1$
784+
return null;
748785
}
749786

750-
return null;
787+
ILaunchConfiguration activeConfig = launchBarManager.getActiveLaunchConfiguration();
788+
if (activeConfig == null)
789+
{
790+
Logger.log("No active launch configuration."); //$NON-NLS-1$
791+
return null;
792+
}
793+
return activeConfig;
751794
}
752795

753796
public static String getGitExecutablePathFromSystem()

bundles/com.espressif.idf.core/src/com/espressif/idf/core/variable/UartDynamicVariable.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
public enum UartDynamicVariable
44
{
5-
SERIAL_PORT("serial_port"); //$NON-NLS-1$
5+
SERIAL_PORT("serial_port"), //$NON-NLS-1$
6+
FLASH_COMMAND("flash_command"); //$NON-NLS-1$
67

78
private String value;
89

bundles/com.espressif.idf.core/src/com/espressif/idf/core/variable/UartVariableResolver.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
import org.eclipse.launchbar.core.ILaunchBarManager;
1010
import org.eclipse.launchbar.core.target.ILaunchTarget;
1111

12+
import com.espressif.idf.core.IDFConstants;
1213
import com.espressif.idf.core.IDFCorePlugin;
1314
import com.espressif.idf.core.LaunchBarTargetConstants;
1415
import com.espressif.idf.core.logging.Logger;
16+
import com.espressif.idf.core.util.IDFUtil;
1517
import com.espressif.idf.core.util.StringUtil;
1618

1719
public class UartVariableResolver implements IDynamicVariableResolver
@@ -34,6 +36,7 @@ private String resolveForDynamicEnum(UartDynamicVariable enumVariable)
3436
return switch (enumVariable)
3537
{
3638
case SERIAL_PORT -> getSerialPort(); // $NON-NLS-1$
39+
case FLASH_COMMAND -> IDFUtil.isFlashEncrypted() ? IDFConstants.FLASH_ENCRYPTED_CMD : IDFConstants.FLASH_CMD;
3740
};
3841
}
3942

bundles/com.espressif.idf.launch.serial.core/src/com/espressif/idf/launch/serial/internal/SerialFlashLaunchConfigDelegate.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ private void openSerialMonitor(ILaunchConfiguration configuration) throws CoreEx
225225
map.put(ITerminalsConnectorConstants.PROP_ENCODING, configuration.getAttribute(
226226
IDFLaunchConstants.SERIAL_MONITOR_ENCODING, WorkbenchEncoding.getWorkbenchDefaultEncoding()));
227227
map.put(ITerminalsConnectorConstants.PROP_FORCE_NEW, Boolean.FALSE);
228+
map.put(SerialSettings.ENCRYPTION_ATTR, IDFUtil.isFlashEncrypted());
228229
new SerialLauncherDelegate().execute(map, null);
229230
}
230231

bundles/com.espressif.idf.launch.serial.core/src/com/espressif/idf/launch/serial/util/ESPFlashUtil.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.espressif.idf.core.configparser.EspConfigParser;
3131
import com.espressif.idf.core.logging.Logger;
3232
import com.espressif.idf.core.util.IDFUtil;
33+
import com.espressif.idf.core.variable.UartDynamicVariable;
3334

3435
public class ESPFlashUtil
3536
{
@@ -75,7 +76,8 @@ public static String getParseableEspFlashCommand(String serialPort)
7576
.generateVariableExpression(IDFDynamicVariables.BUILD_DIR.name(), null));
7677
commands.add("-p"); //$NON-NLS-1$
7778
commands.add(serialPort);
78-
commands.add(IDFConstants.FLASH_CMD);
79+
commands.add(VariablesPlugin.getDefault().getStringVariableManager()
80+
.generateVariableExpression(UartDynamicVariable.FLASH_COMMAND.getValue(), null));
7981

8082
return String.join(" ", commands); //$NON-NLS-1$
8183
}

bundles/com.espressif.idf.launch.serial.ui/src/com/espressif/idf/launch/serial/ui/internal/CMakeMainTab2.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,14 @@
5454
import org.eclipse.swt.events.SelectionEvent;
5555
import org.eclipse.swt.layout.GridData;
5656
import org.eclipse.swt.layout.GridLayout;
57+
import org.eclipse.swt.program.Program;
5758
import org.eclipse.swt.widgets.Button;
5859
import org.eclipse.swt.widgets.Combo;
5960
import org.eclipse.swt.widgets.Composite;
6061
import org.eclipse.swt.widgets.Display;
6162
import org.eclipse.swt.widgets.Group;
6263
import org.eclipse.swt.widgets.Label;
64+
import org.eclipse.swt.widgets.Link;
6365
import org.eclipse.swt.widgets.Text;
6466
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
6567
import org.eclipse.ui.ide.IDEEncoding;
@@ -79,6 +81,7 @@
7981
@SuppressWarnings("restriction")
8082
public class CMakeMainTab2 extends GenericMainTab
8183
{
84+
private static final String DOCS_ESPRESSIF_FLASH_ENCRYPTION_HTML = "https://docs.espressif.com/projects/espressif-ide/en/latest/flashdevice.html#customize-flash-arguments"; //$NON-NLS-1$
8285
private static final String DEFAULT_JTAG_CONFIG_OPTIONS = String.format("-s ${%s} ${%s}", //$NON-NLS-1$
8386
OpenocdDynamicVariable.OPENOCD_SCRIPTS, JtagDynamicVariable.JTAG_FLASH_ARGS);
8487
private Combo flashOverComboButton;
@@ -94,6 +97,7 @@ public class CMakeMainTab2 extends GenericMainTab
9497
private TextWithButton dfuArgumentsField;
9598
private Button checkOpenSerialMonitorButton;
9699
private Combo fEncodingCombo;
100+
private Button flashEncryptionCheckbox;
97101

98102
public enum FlashInterface
99103
{
@@ -230,9 +234,27 @@ protected void createUartComposite(Composite parent)
230234
uartAgrumentsField = new TextWithButton(parent, SWT.WRAP | SWT.BORDER);
231235

232236
createArgumentComponent(defaultComposite, uartAgrumentsField);
237+
createFlashEncryptionCheckbox(defaultComposite);
233238
createVerticalSpacer(defaultComposite, 1);
234239
}
235240

241+
private void createFlashEncryptionCheckbox(Composite parent)
242+
{
243+
Group flashGroup = new Group(parent, SWT.NONE);
244+
flashGroup.setText(Messages.CMakeMainTab2_FlashEncryptionGroup);
245+
flashGroup.setLayout(new GridLayout(1, false));
246+
flashGroup.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
247+
248+
flashEncryptionCheckbox = new Button(flashGroup, SWT.CHECK);
249+
flashEncryptionCheckbox.setText(Messages.CMakeMainTab2_FlashEncryptionCheckbox);
250+
flashEncryptionCheckbox.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true));
251+
252+
Link flashEncryptionNote = new Link(flashGroup, SWT.WRAP);
253+
flashEncryptionNote.setText(Messages.CMakeMainTab2_FlashEncryptionNote);
254+
255+
flashEncryptionNote.addListener(SWT.Selection, e -> Program.launch(DOCS_ESPRESSIF_FLASH_ENCRYPTION_HTML));
256+
}
257+
236258
protected void createJtagflashComposite(Composite parent)
237259
{
238260

@@ -541,6 +563,8 @@ public void performApply(ILaunchConfigurationWorkingCopy configuration)
541563
wc.setAttribute(IDFLaunchConstants.OPEN_SERIAL_MONITOR, checkOpenSerialMonitorButton.getSelection());
542564
if (checkOpenSerialMonitorButton.getSelection())
543565
wc.setAttribute(IDFLaunchConstants.SERIAL_MONITOR_ENCODING, fEncodingCombo.getText());
566+
wc.setAttribute(IDFLaunchConstants.FLASH_ENCRYPTION_ENABLED, flashEncryptionCheckbox.getSelection());
567+
544568
wc.doSave();
545569
}
546570
catch (CoreException e)
@@ -553,13 +577,28 @@ public void performApply(ILaunchConfigurationWorkingCopy configuration)
553577
public void initializeFrom(ILaunchConfiguration configuration)
554578
{
555579
super.initializeFrom(configuration);
580+
updateFlashEncryptionGroup(configuration);
556581
updateStartSerialMonitorGroup(configuration);
557582
updateProjetFromConfig(configuration);
558583
updateFlashOverStatus(configuration);
559584
updateArgumentsWithDefaultFlashCommand(configuration);
560585
switchUI(FlashInterface.values()[flashOverComboButton.getSelectionIndex()]);
561586
}
562587

588+
private void updateFlashEncryptionGroup(ILaunchConfiguration configuration)
589+
{
590+
boolean isFlashEncryptionEnabled = false;
591+
try
592+
{
593+
isFlashEncryptionEnabled = configuration.getAttribute(IDFLaunchConstants.FLASH_ENCRYPTION_ENABLED, false);
594+
}
595+
catch (CoreException e)
596+
{
597+
Logger.log(e);
598+
}
599+
flashEncryptionCheckbox.setSelection(isFlashEncryptionEnabled);
600+
}
601+
563602
private void updateProjetFromConfig(ILaunchConfiguration configuration)
564603
{
565604
String projectName = StringUtil.EMPTY;

0 commit comments

Comments
 (0)