Skip to content

Commit

Permalink
IEP-1033 esptool write_flash command in the IDE (#826)
Browse files Browse the repository at this point in the history
* feat: added write flash cmd
  • Loading branch information
sigmaaa authored Nov 27, 2023
1 parent 1e1cb7e commit dd24261
Show file tree
Hide file tree
Showing 10 changed files with 530 additions and 5 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ To get a quick understanding of ESP-IDF and Eclipse plugin features, check our s
* [ ESP-IDF master update](#updateEspIdfMaster)<br>
* [ Partition Table Editor UI for ESP-IDF](#partitionTableEditor)<br>
* [ NVS Table Editor](#nvsTableEditor)<br>
* [ Write Binary Data to Flash](#writeFlashBinary)<br>
* [ Changing Language ](#changeLanguage)<br>
* [ Wokwi Simulator](#wokwisimulator)<br>
</details>
Expand Down Expand Up @@ -780,6 +781,19 @@ Steps:

After all these steps, you should see `nvs.csv` and `nvs.bin` files in the project directory.

<a name ="writeFlashBinary"></a>
# Write Binary to Flash

Binary data can be written to the ESP’s flash chip via `ESP-IDF: Write Binary Data to Flash` command accessible by right click on the project in the project explorer:

<img width="344" alt="Screenshot 2023-10-16 at 10 51 52" src="https://github.com/espressif/idf-eclipse-plugin/assets/24419842/186c8498-d779-4771-af53-e5bf09e29502">

After clicking this command, the `Write Binary Data to Flash` dialog box will open. Editable default values ​​are provided for binary path and offset. The correct offset can be checked by looking at the partition table via `ESP-IDF: Partition Table Editor` or manually by opening the partitions.csv file

<img width="591" alt="Screenshot 2023-10-16 at 10 51 27" src="https://github.com/espressif/idf-eclipse-plugin/assets/24419842/46e24e89-a1ed-4169-8c92-1ba0b0089ea7">

After clicking on the `Flash` button the result of the flash command will be printed inside of this dialog.

# How to build locally

1. Install prerequisites Java 11+ and Maven.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ public interface IDFConstants

String ESP_TOOL_ERASE_FLASH_CMD = "erase_flash"; //$NON-NLS-1$

String ESP_WRITE_FLASH_CMD = "write_flash"; //$NON-NLS-1$

/**
* Property to store project custom build directory
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package com.espressif.idf.core.util;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -19,6 +20,7 @@ public class EspToolCommands
{
private Process chipInfoProcess;
private Process flashEraseProcess;
private Process writeFlashProcess;

public Process chipInformation(String port) throws Exception
{
Expand All @@ -34,9 +36,29 @@ public Process eraseFlash(String port) throws Exception
return flashEraseProcess;

Check warning on line 36 in bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/EspToolCommands.java

View workflow job for this annotation

GitHub Actions / spotbugs

THROWS_METHOD_THROWS_CLAUSE_BASIC_EXCEPTION

Method lists Exception in its throws clause.
Raw output
Method lists Exception in its throws clause.
When declaring a method, the types of exceptions in the throws clause should be the most specific. Therefore, using Exception in the throws clause would force the caller to either use it in its own throws clause, or use it in a try-catch block (when it does not necessarily contain any meaningful information about the thrown exception).

For more information, see the SEI CERT ERR07-J rule [https://wiki.sei.cmu.edu/confluence/display/java/ERR07-J.+Do+not+throw+RuntimeException%2C+Exception%2C+or+Throwable].
}

public Process writeFlash(String port, String path, String offset) throws IOException
{
destroyAnyChipInfoProcess();
writeFlashProcess = new ProcessBuilder(getWriteFlashCommand(port, path, offset)).start();
return writeFlashProcess;
}

private List<String> getWriteFlashCommand(String port, String path, String offset)
{
List<String> command = new ArrayList<>();
command.add(IDFUtil.getIDFPythonEnvPath());
command.add(IDFUtil.getEspToolScriptFile().getAbsolutePath());
command.add("-p"); //$NON-NLS-1$
command.add(port);
command.add(IDFConstants.ESP_WRITE_FLASH_CMD);
command.add(offset);
command.add(path);
return command;
}

private List<String> getChipInfoCommand(String port)
{
List<String> command = new ArrayList<String>();
List<String> command = new ArrayList<>();
command.add(IDFUtil.getIDFPythonEnvPath());
command.add(IDFUtil.getEspToolScriptFile().getAbsolutePath());
command.add("-p"); //$NON-NLS-1$
Expand All @@ -47,7 +69,7 @@ private List<String> getChipInfoCommand(String port)

private List<String> getFlashEraseCommand(String port)
{
List<String> command = new ArrayList<String>();
List<String> command = new ArrayList<>();
command.add(IDFUtil.getIDFPythonEnvPath());
command.add(IDFUtil.getEspToolScriptFile().getAbsolutePath());
command.add("-p"); //$NON-NLS-1$
Expand Down Expand Up @@ -81,4 +103,22 @@ public void killEraseFlashProcess()
flashEraseProcess.destroy();
}
}

public boolean checkActiveWriteFlashProcess()
{
if (writeFlashProcess != null)
{
return writeFlashProcess.isAlive();
}

return false;
}

public void killWriteFlashProcess()
{
if (writeFlashProcess != null)
{
writeFlashProcess.destroy();
}
}
}
6 changes: 4 additions & 2 deletions bundles/com.espressif.idf.ui/OSGI-INF/l10n/bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ command.label.PartitionTableEditor = ESP-IDF: Partition Table Editor
command.name.PartitionTableEditor = ESP-IDF: Partition Table Editor
command.label.nsvTableEditor = ESP-IDF: NVS Table Editor
command.name.nvsTableEditor = ESP-IDF: NVS Table Editor
command.tooltip.nvsTableEditor = NVS Editor can help you to easily edit NVS CSV, generate encrypted and non-encrypted partitions through GUI, without interacting directly with the csv files.
command.tooltip.nvsTableEditor = NVS Editor can help you to easily edit NVS CSV, generate encrypted and non-encrypted partitions through GUI, without interacting directly with the csv files.
build_hints.name = Build Hints
command.label.SbomCommandLabel = ESP-IDF: SBOM Tool
command.label.SbomCommandLabel = ESP-IDF: SBOM Tool
command.label.writeFlashCmdLbl = ESP-IDF: Write Binary Data to Flash
command.name.writeFlashCmdName = Write Binary Data to Flash
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions bundles/com.espressif.idf.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,23 @@
</iterate>
</visibleWhen>
</command>
<command
commandId="com.espressif.idf.ui.writeFlashCommand"
icon="icons/Write_Binary_Data_to_Flash.png"
label="%command.label.writeFlashCmdLbl"
style="push">
<visibleWhen
checkEnabled="false">
<iterate
ifEmpty="false"
operator="or">
<instanceof
value="org.eclipse.core.resources.IResource">
</instanceof>
</iterate>
</visibleWhen>
</command>

</menuContribution>
</extension>
<extension
Expand Down Expand Up @@ -543,6 +560,10 @@
id="com.espressif.idf.ui.nvsEditorCommand"
name="%command.name.nvsTableEditor">
</command>
<command
id="com.espressif.idf.ui.writeFlashCommand"
name="%command.name.writeFlashCmdName">
</command>
</extension>
<extension
point="org.eclipse.ui.handlers">
Expand Down Expand Up @@ -588,6 +609,10 @@
class="com.espressif.idf.ui.handlers.SbomCommandHandler"
commandId="com.espressif.idf.ui.sbom">
</handler>
<handler
class="com.espressif.idf.ui.handlers.WriteFlashCommandHandler"
commandId="com.espressif.idf.ui.writeFlashCommand">
</handler>
</extension>
<extension
point="org.eclipse.ui.commands">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ public class Messages extends NLS
public static String HintDetailsTitle;
public static String FilterMessage;
public static String HintsYmlNotFoundErrMsg;
public static String WriteFlashDialog_Bin_Path_Lbl;
public static String WriteFlashDialog_BinFileErrFormatErrMsg;
public static String WriteFlashDialog_Browse_Btn;
public static String WriteFlashDialog_ErrorExitCodeMsg;
public static String WriteFlashDialog_ErrorOutputMsg;
public static String WriteFlashDialog_Flash_Btn_Lbl;
public static String WriteFlashDialog_Offset_Lbl;
public static String WriteFlashDialog_OffsetErrMsg;
public static String WriteFlashDialog_Information_Msg;
public static String WriteFlashDialog_SerialPortErrMsg;
public static String WriteFlashDialog_Title;
public static String WriteFlashDialog_WritingBinsToFlashMsg0;

static
{
Expand Down
Loading

0 comments on commit dd24261

Please sign in to comment.