Skip to content

Commit 71a20b8

Browse files
Redo ESP32 partitions.csv parsing (#62)
Support comments ('#'), -K and -M modifiers, don't skip 1st line, and match on the "type" and note "name" fields. Match "LittleFS" type, too. Fixes #61
1 parent 24e2afd commit 71a20b8

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "arduino-littlefs-upload",
33
"displayName": "arduino-littlefs-upload",
44
"description": "Build and uploads LittleFS filesystems for the Arduino-Pico RP2040 core, ESP8266 core, or ESP32 core under Arduino IDE 2.2.1 or higher",
5-
"version": "1.2.1",
5+
"version": "1.3.0",
66
"engines": {
77
"vscode": "^1.82.0"
88
},

src/extension.ts

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,21 @@ function color(
9292
}m${text}${resetStyle}`;
9393
}
9494

95-
95+
function fancyParseInt(str: string) : number {
96+
var up = str.toUpperCase().trim();
97+
if (up == "") {
98+
return 0;
99+
}
100+
if (up.indexOf('0X') >= 0) {
101+
return parseInt(str, 16);
102+
} else if (up.indexOf('K') >= 0) {
103+
return 1024 * parseInt(up.substring(0, up.indexOf('K')));
104+
} else if (up.indexOf('M') >= 0) {
105+
return 1024 * 1024 * parseInt(up.substring(0, up.indexOf('M')));
106+
} else {
107+
return parseInt(str);
108+
}
109+
}
96110

97111
// Execute a command and display it's output in the terminal
98112
async function runCommand(exe : string, opts : any[]) {
@@ -253,17 +267,33 @@ export function activate(context: vscode.ExtensionContext) {
253267
}
254268
let partitionData = fs.readFileSync(partitionFile, 'utf8');
255269
let partitionDataArray = partitionData.split("\n");
256-
for (var i = 1; i < partitionDataArray.length; i++){
270+
var lastend = 0x8000 + 0xc00;
271+
for (var i = 0; i < partitionDataArray.length; i++){
272+
var line = partitionDataArray[i];
273+
if (line.indexOf('#') >= 0) {
274+
line = line.substring(0, line.indexOf('#'));
275+
}
257276
var partitionEntry = partitionDataArray[i].split(",");
258-
if (partitionEntry[0].includes("spiffs")) {
259-
fsStart = parseInt(partitionEntry[3], 16); // Partition Offset
260-
fsEnd = fsStart + parseInt(partitionEntry[4], 16); // Partition Length
277+
if (partitionEntry.length > 4) {
278+
var offset = fancyParseInt(partitionEntry[3]);
279+
var length = fancyParseInt(partitionEntry[4]);
280+
if (offset == 0) {
281+
offset = lastend;
282+
}
283+
lastend = offset + length;
284+
var parttype = partitionEntry[2].toUpperCase().trim();
285+
if ((parttype == "SPIFFS") || (parttype == "LITTLEFS")) {
286+
fsStart = offset;
287+
fsEnd = length;
288+
}
261289
}
262290
}
263291
if (!fsStart || !fsEnd) {
264292
writeEmitter.fire(red("\r\n\r\nERROR: Partition entry not found in csv file!\r\n"));
265293
return;
266294
}
295+
writeEmitter.fire(blue(" Start: ") + green("0x" + fsStart.toString(16)) + "\r\n");
296+
writeEmitter.fire(blue(" End: ") + green("0x" + fsEnd.toString(16)) + "\r\n");
267297

268298
uploadSpeed = Number(arduinoContext.boardDetails.buildProperties["upload.speed"]);
269299
// Fixed for ESP32

0 commit comments

Comments
 (0)