-
Notifications
You must be signed in to change notification settings - Fork 131
IEP-1613 Encrypted Flash: regular flash command is not separated from encrypted-flash command #1301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
0dbc6d1
bf79162
5f05e41
e99cb4d
67c24cc
4479c66
2e51f6a
9a16576
5ab81cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -717,37 +717,80 @@ public static void updateEspressifPrefPageOpenocdPath() | |
|
||
public static String getCurrentTarget() | ||
{ | ||
IProject project = null; | ||
IProject project = getProjectFromActiveLaunchConfig(); | ||
if (project == null) | ||
{ | ||
Logger.log(Messages.IDFUtil_CantFindProjectMsg); | ||
return null; | ||
} | ||
return new SDKConfigJsonReader(project).getValue("IDF_TARGET"); //$NON-NLS-1$ | ||
} | ||
sigmaaa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public static boolean isFlashEncrypted() | ||
{ | ||
ILaunchConfiguration configuration; | ||
try | ||
{ | ||
configuration = getActiveLaunchConfiguration(); | ||
|
||
return configuration != null | ||
&& configuration.getAttribute(IDFLaunchConstants.FLASH_ENCRYPTION_ENABLED, false); | ||
} | ||
catch (CoreException e) | ||
{ | ||
Logger.log(e); | ||
} | ||
|
||
return false; | ||
} | ||
Comment on lines
+729
to
+745
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainMake isFlashEncrypted resilient: fall back to sdkconfig (SECURE_FLASH_ENC_ENABLED) when launch attribute is absent Current logic relies solely on the launch attribute; if it’s unset, encryption may be incorrectly treated as disabled. Add a fallback to sdkconfig with tolerant boolean parsing. Apply: public static boolean isFlashEncrypted()
{
- ILaunchConfiguration configuration;
- try
- {
- configuration = getActiveLaunchConfiguration();
-
- return configuration != null
- && configuration.getAttribute(IDFLaunchConstants.FLASH_ENCRYPTION_ENABLED, false);
- }
- catch (CoreException e)
- {
- Logger.log(e);
- }
-
- return false;
+ try {
+ ILaunchConfiguration configuration = getActiveLaunchConfiguration();
+ boolean enabled = configuration != null
+ && configuration.getAttribute(IDFLaunchConstants.FLASH_ENCRYPTION_ENABLED, false);
+ if (enabled) {
+ return true;
+ }
+ // Fallback to sdkconfig if the launch attribute is absent/false
+ IProject project = getProjectFromActiveLaunchConfig();
+ if (project == null) {
+ return false;
+ }
+ String v = new SDKConfigJsonReader(project).getValue("SECURE_FLASH_ENC_ENABLED"); //$NON-NLS-1$
+ if (v == null) {
+ return false;
+ }
+ v = v.trim();
+ return "true".equalsIgnoreCase(v) || "1".equals(v) || "y".equalsIgnoreCase(v) || "yes".equalsIgnoreCase(v);
+ } catch (CoreException e) {
+ Logger.log(e);
+ return false;
+ }
} 🏁 Script executed: #!/bin/bash
# Verify that the launch attribute is actually set somewhere.
rg -nP -C2 'FLASH_ENCRYPTION_ENABLED'
# Heuristic: look for setAttribute calls touching it
rg -nP -C2 'setAttribute\(\s*IDFLaunchConstants\.FLASH_ENCRYPTION_ENABLED' Length of output: 3862 🏁 Script executed: #!/bin/bash
# Search for SDKConfigJsonReader class declaration
rg -n "class SDKConfigJsonReader"
# Search for any references to SDKConfigJsonReader
rg -n "SDKConfigJsonReader"
# Search for getProjectFromActiveLaunchConfig method
rg -n "getProjectFromActiveLaunchConfig"
# Verify getActiveLaunchConfiguration definition in IDFUtil.java
rg -n -C2 "getActiveLaunchConfiguration" bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/IDFUtil.java Length of output: 4611 Make isFlashEncrypted resilient: fallback to sdkconfig when launch attribute is absent Add a secondary lookup in isFlashEncrypted() to read SECURE_FLASH_ENC_ENABLED via SDKConfigJsonReader(project) whenever the FLASH_ENCRYPTION_ENABLED launch attribute is false or unset. Ensure getProjectFromActiveLaunchConfig() handles null, and update IDFUtilTest to mock SDKConfigJsonReader for this new path. 🤖 Prompt for AI Agents
|
||
|
||
/** | ||
* Returns the active project from the currently selected launch configuration. | ||
*/ | ||
public static IProject getProjectFromActiveLaunchConfig() | ||
{ | ||
try | ||
{ | ||
ILaunchBarManager launchBarManager = IDFCorePlugin.getService(ILaunchBarManager.class); | ||
ILaunchConfiguration activeConfig = launchBarManager.getActiveLaunchConfiguration(); | ||
if (activeConfig == null || activeConfig.getMappedResources() == null) | ||
ILaunchConfiguration activeConfig = getActiveLaunchConfiguration(); | ||
if (activeConfig == null) | ||
{ | ||
Logger.log(Messages.IDFUtil_CantFindProjectMsg); | ||
return StringUtil.EMPTY; | ||
return null; | ||
} | ||
|
||
IResource[] resources = activeConfig.getMappedResources(); | ||
if (resources == null || resources.length == 0) | ||
{ | ||
Logger.log("No mapped resources in active launch configuration."); //$NON-NLS-1$ | ||
return null; | ||
} | ||
project = activeConfig.getMappedResources()[0].getProject(); | ||
Logger.log("Project:: " + project); //$NON-NLS-1$ | ||
|
||
IProject project = resources[0].getProject(); | ||
Logger.log("Active project: " + project); //$NON-NLS-1$ | ||
return project; | ||
} | ||
catch (CoreException e) | ||
{ | ||
Logger.log(e); | ||
return null; | ||
} | ||
return new SDKConfigJsonReader(project).getValue("IDF_TARGET"); //$NON-NLS-1$ | ||
} | ||
|
||
public static IProject getProjectFromActiveLaunchConfig() throws CoreException | ||
private static ILaunchConfiguration getActiveLaunchConfiguration() throws CoreException | ||
{ | ||
final ILaunchBarManager launchBarManager = IDFCorePlugin.getService(ILaunchBarManager.class); | ||
ILaunchConfiguration launchConfiguration = launchBarManager.getActiveLaunchConfiguration(); | ||
IResource[] mappedResources = launchConfiguration.getMappedResources(); | ||
if (mappedResources != null && mappedResources[0].getProject() != null) | ||
ILaunchBarManager launchBarManager = IDFCorePlugin.getService(ILaunchBarManager.class); | ||
if (launchBarManager == null) | ||
{ | ||
return mappedResources[0].getProject(); | ||
Logger.log("LaunchBarManager service not found."); //$NON-NLS-1$ | ||
return null; | ||
} | ||
|
||
return null; | ||
ILaunchConfiguration activeConfig = launchBarManager.getActiveLaunchConfiguration(); | ||
if (activeConfig == null) | ||
{ | ||
Logger.log("No active launch configuration."); //$NON-NLS-1$ | ||
return null; | ||
} | ||
return activeConfig; | ||
} | ||
|
||
public static String getGitExecutablePathFromSystem() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,12 +54,14 @@ | |
import org.eclipse.swt.events.SelectionEvent; | ||
import org.eclipse.swt.layout.GridData; | ||
import org.eclipse.swt.layout.GridLayout; | ||
import org.eclipse.swt.program.Program; | ||
import org.eclipse.swt.widgets.Button; | ||
import org.eclipse.swt.widgets.Combo; | ||
import org.eclipse.swt.widgets.Composite; | ||
import org.eclipse.swt.widgets.Display; | ||
import org.eclipse.swt.widgets.Group; | ||
import org.eclipse.swt.widgets.Label; | ||
import org.eclipse.swt.widgets.Link; | ||
import org.eclipse.swt.widgets.Text; | ||
import org.eclipse.ui.dialogs.ElementListSelectionDialog; | ||
import org.eclipse.ui.ide.IDEEncoding; | ||
|
@@ -79,6 +81,7 @@ | |
@SuppressWarnings("restriction") | ||
public class CMakeMainTab2 extends GenericMainTab | ||
{ | ||
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$ | ||
private static final String DEFAULT_JTAG_CONFIG_OPTIONS = String.format("-s ${%s} ${%s}", //$NON-NLS-1$ | ||
OpenocdDynamicVariable.OPENOCD_SCRIPTS, JtagDynamicVariable.JTAG_FLASH_ARGS); | ||
private Combo flashOverComboButton; | ||
|
@@ -94,6 +97,7 @@ public class CMakeMainTab2 extends GenericMainTab | |
private TextWithButton dfuArgumentsField; | ||
private Button checkOpenSerialMonitorButton; | ||
private Combo fEncodingCombo; | ||
private Button flashEncryptionCheckbox; | ||
|
||
public enum FlashInterface | ||
{ | ||
|
@@ -230,9 +234,27 @@ protected void createUartComposite(Composite parent) | |
uartAgrumentsField = new TextWithButton(parent, SWT.WRAP | SWT.BORDER); | ||
|
||
createArgumentComponent(defaultComposite, uartAgrumentsField); | ||
createFlashEncryptionCheckbox(defaultComposite); | ||
createVerticalSpacer(defaultComposite, 1); | ||
} | ||
|
||
private void createFlashEncryptionCheckbox(Composite parent) | ||
{ | ||
Group flashGroup = new Group(parent, SWT.NONE); | ||
flashGroup.setText(Messages.CMakeMainTab2_FlashEncryptionGroup); | ||
flashGroup.setLayout(new GridLayout(1, false)); | ||
flashGroup.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); | ||
|
||
flashEncryptionCheckbox = new Button(flashGroup, SWT.CHECK); | ||
flashEncryptionCheckbox.setText(Messages.CMakeMainTab2_FlashEncryptionCheckbox); | ||
flashEncryptionCheckbox.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true)); | ||
|
||
Link flashEncryptionNote = new Link(flashGroup, SWT.WRAP); | ||
flashEncryptionNote.setText(Messages.CMakeMainTab2_FlashEncryptionNote); | ||
|
||
flashEncryptionNote.addListener(SWT.Selection, e -> Program.launch(DOCS_ESPRESSIF_FLASH_ENCRYPTION_HTML)); | ||
} | ||
|
||
Comment on lines
+241
to
+257
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Missing selection listener and visibility logic for the note. The note is always visible; there’s no linkage to the checkbox state. Add a listener to show/hide the note and relayout. Apply: - Link flashEncryptionNote = new Link(flashGroup, SWT.WRAP);
- flashEncryptionNote.setText(Messages.CMakeMainTab2_FlashEncryptionNote);
-
- flashEncryptionNote.addListener(SWT.Selection, e -> Program.launch(DOCS_ESPRESSIF_FLASH_ENCRYPTION_HTML));
+ flashEncryptionNote = new Link(flashGroup, SWT.WRAP);
+ flashEncryptionNote.setText(Messages.CMakeMainTab2_FlashEncryptionNote);
+ flashEncryptionNote.addListener(SWT.Selection, e -> Program.launch(DOCS_ESPRESSIF_FLASH_ENCRYPTION_HTML));
+ // Toggle note visibility with checkbox
+ flashEncryptionCheckbox.addListener(SWT.Selection, e -> refreshFlashEncryptionNoteVisibility(flashGroup));
+ refreshFlashEncryptionNoteVisibility(flashGroup); And declare a field: - private Button flashEncryptionCheckbox;
+ private Button flashEncryptionCheckbox;
+ private Link flashEncryptionNote; Add helper (outside changed ranges, shown for completeness): private void refreshFlashEncryptionNoteVisibility(Composite container) {
boolean visible = flashEncryptionCheckbox.getSelection();
flashEncryptionNote.setVisible(visible);
GridData gd = (GridData) flashEncryptionNote.getLayoutData();
if (gd == null) {
gd = new GridData(SWT.FILL, SWT.TOP, true, false);
flashEncryptionNote.setLayoutData(gd);
}
gd.exclude = !visible;
container.layout(true, true);
if (mainComposite != null) {
mainComposite.layout(true, true);
}
} 🤖 Prompt for AI Agents
|
||
protected void createJtagflashComposite(Composite parent) | ||
{ | ||
|
||
|
@@ -541,6 +563,8 @@ public void performApply(ILaunchConfigurationWorkingCopy configuration) | |
wc.setAttribute(IDFLaunchConstants.OPEN_SERIAL_MONITOR, checkOpenSerialMonitorButton.getSelection()); | ||
if (checkOpenSerialMonitorButton.getSelection()) | ||
wc.setAttribute(IDFLaunchConstants.SERIAL_MONITOR_ENCODING, fEncodingCombo.getText()); | ||
wc.setAttribute(IDFLaunchConstants.FLASH_ENCRYPTION_ENABLED, flashEncryptionCheckbox.getSelection()); | ||
|
||
wc.doSave(); | ||
} | ||
catch (CoreException e) | ||
|
@@ -553,13 +577,28 @@ public void performApply(ILaunchConfigurationWorkingCopy configuration) | |
public void initializeFrom(ILaunchConfiguration configuration) | ||
{ | ||
super.initializeFrom(configuration); | ||
updateFlashEncryptionGroup(configuration); | ||
updateStartSerialMonitorGroup(configuration); | ||
updateProjetFromConfig(configuration); | ||
updateFlashOverStatus(configuration); | ||
updateArgumentsWithDefaultFlashCommand(configuration); | ||
switchUI(FlashInterface.values()[flashOverComboButton.getSelectionIndex()]); | ||
} | ||
|
||
private void updateFlashEncryptionGroup(ILaunchConfiguration configuration) | ||
{ | ||
boolean isFlashEncryptionEnabled = false; | ||
try | ||
{ | ||
isFlashEncryptionEnabled = configuration.getAttribute(IDFLaunchConstants.FLASH_ENCRYPTION_ENABLED, false); | ||
} | ||
catch (CoreException e) | ||
{ | ||
Logger.log(e); | ||
} | ||
flashEncryptionCheckbox.setSelection(isFlashEncryptionEnabled); | ||
} | ||
|
||
private void updateProjetFromConfig(ILaunchConfiguration configuration) | ||
{ | ||
String projectName = StringUtil.EMPTY; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Encrypted command name likely incorrect; align with idf.py target "encrypted-app-flash".
idf.py exposes "encrypted-app" and "encrypted-app-flash" targets; "encrypted-flash" is not a known target. Using the wrong subcommand will fail at runtime. Recommend switching the value to "encrypted-app-flash" (keep the constant name if you want to minimize ripples), and audit call sites.
Apply:
To double-check usages and docs across the repo:
🏁 Script executed:
Length of output: 3520
Replace incorrect “encrypted-flash” constant and update UI tooltip
Also update the Messages.properties tooltip so it reflects the two valid targets (“flash” and “encrypted-app-flash”):
Audit any other references to “encrypted-flash” to ensure consistency.
📝 Committable suggestion
🤖 Prompt for AI Agents