Skip to content

Commit 2187fca

Browse files
Upgrade to littleFS v2 and esptool.py
1 parent c978cb8 commit 2187fca

File tree

2 files changed

+40
-19
lines changed

2 files changed

+40
-19
lines changed

make.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ echo "lib_path: $lib_path"
1919
set -e
2020

2121
mkdir -p bin
22-
javac -target 1.8 -cp "$pde_path:$core_path:$lib_path" \
22+
javac -target 1.8 -source 1.8 -cp "$pde_path:$core_path:$lib_path" \
2323
-d bin src/ESP8266LittleFS.java
2424

2525
pushd bin

src/ESP8266LittleFS.java

+39-18
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ private void createAndUpload(){
209209
File espota = new File(platform.getFolder()+"/tools");
210210
File esptool = new File(platform.getFolder()+"/tools");
211211
String serialPort = PreferencesData.get("serial.port");
212+
String pythonCmd = PreferencesData.get("runtime.os").contentEquals("windows") ? "python.exe" : "python";
213+
String uploadCmd = "";
212214

213215
//make sure the serial port or IP is defined
214216
if (serialPort == null || serialPort.isEmpty()) {
@@ -217,6 +219,22 @@ private void createAndUpload(){
217219
return;
218220
}
219221

222+
// Find upload.py, don't fail if not present for backwards compat
223+
File uploadPyFile = new File(platform.getFolder()+"/tools", "upload.py");
224+
if (uploadPyFile.exists() && uploadPyFile.isFile()) {
225+
uploadCmd = uploadPyFile.getAbsolutePath();
226+
}
227+
// Find python.exe if present, don't fail if not found for backwards compat
228+
String[] paths = { platform.getFolder()+"/tools", platform.getFolder()+"/tools/python", PreferencesData.get("runtime.tools.python.path") };
229+
for (String s: paths) {
230+
File toolPyFile = new File(s, pythonCmd);
231+
if (toolPyFile.exists() && toolPyFile.isFile() && toolPyFile.canExecute()) {
232+
pythonCmd = toolPyFile.getAbsolutePath();
233+
break;
234+
}
235+
}
236+
// pythonCmd now points to either an installed exe with full path or just plain "python(.exe)"
237+
220238
//find espota if IP else find esptool
221239
if(serialPort.split("\\.").length == 4){
222240
isNetwork = true;
@@ -234,7 +252,7 @@ private void createAndUpload(){
234252
esptool = new File(platform.getFolder()+"/tools/esptool", esptoolCmd);
235253
if(!esptool.exists()){
236254
esptool = new File(PreferencesData.get("runtime.tools.esptool.path"), esptoolCmd);
237-
if (!esptool.exists()) {
255+
if (!esptool.exists() && uploadCmd.isEmpty()) {
238256
System.err.println();
239257
editor.statusError("LittleFS Error: esptool not found!");
240258
return;
@@ -279,10 +297,10 @@ private void createAndUpload(){
279297
}
280298

281299
editor.statusNotice("LittleFS Creating Image...");
282-
System.out.println("[LittleFS] data : "+dataPath);
283-
System.out.println("[LittleFS] size : "+((spiEnd - spiStart)/1024));
284-
System.out.println("[LittleFS] page : "+spiPage);
285-
System.out.println("[LittleFS] block : "+spiBlock);
300+
System.out.println("[LittleFS] data : "+dataPath);
301+
System.out.println("[LittleFS] size : "+((spiEnd - spiStart)/1024));
302+
System.out.println("[LittleFS] page : "+spiPage);
303+
System.out.println("[LittleFS] block : "+spiBlock);
286304

287305
try {
288306
if(listenOnProcess(new String[]{toolPath, "-c", dataPath, "-p", spiPage+"", "-b", spiBlock+"", "-s", (spiEnd - spiStart)+"", imagePath}) != 0) {
@@ -297,25 +315,28 @@ private void createAndUpload(){
297315
}
298316

299317
editor.statusNotice("LittleFS Uploading Image...");
300-
System.out.println("[LittleFS] upload : "+imagePath);
318+
System.out.println("[LittleFS] upload : "+imagePath);
301319

302320
if(isNetwork){
303-
String pythonCmd;
304-
if(PreferencesData.get("runtime.os").contentEquals("windows"))
305-
pythonCmd = "python.exe";
306-
else
307-
pythonCmd = "python";
308-
309-
System.out.println("[LittleFS] IP : "+serialPort);
321+
System.out.println("[LittleFS] IP : "+serialPort);
310322
System.out.println();
311323
sysExec(new String[]{pythonCmd, espota.getAbsolutePath(), "-i", serialPort, "-s", "-f", imagePath});
312324
} else {
313-
System.out.println("[LittleFS] address: "+uploadAddress);
314-
System.out.println("[LittleFS] reset : "+resetMethod);
315-
System.out.println("[LittleFS] port : "+serialPort);
316-
System.out.println("[LittleFS] speed : "+uploadSpeed);
325+
System.out.println("[LittleFS] address : "+uploadAddress);
326+
System.out.println("[LittleFS] reset : "+resetMethod);
327+
System.out.println("[LittleFS] port : "+serialPort);
328+
System.out.println("[LittleFS] speed : "+uploadSpeed);
329+
if (!uploadCmd.isEmpty()) {
330+
System.out.println("[SPIFFS] python : "+pythonCmd);
331+
System.out.println("[SPIFFS] uploader : "+uploadCmd);
332+
}
333+
317334
System.out.println();
318-
sysExec(new String[]{esptool.getAbsolutePath(), "-cd", resetMethod, "-cb", uploadSpeed, "-cp", serialPort, "-ca", uploadAddress, "-cf", imagePath});
335+
if (!uploadCmd.isEmpty()) {
336+
sysExec(new String[]{pythonCmd, uploadCmd, "--chip", "esp8266", "--port", serialPort, "--baud", uploadSpeed, "write_flash", uploadAddress, imagePath, "--end"});
337+
} else {
338+
sysExec(new String[]{esptool.getAbsolutePath(), "-cd", resetMethod, "-cb", uploadSpeed, "-cp", serialPort, "-ca", uploadAddress, "-cf", imagePath});
339+
}
319340
}
320341
}
321342

0 commit comments

Comments
 (0)