Skip to content

Commit

Permalink
add custom offset for flash binaries (#957)
Browse files Browse the repository at this point in the history
  • Loading branch information
brianignacio5 committed May 4, 2023
1 parent e8da6fb commit 46484f6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
5 changes: 3 additions & 2 deletions src/espIdf/partition-table/partitionFlasher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { Progress, ProgressLocation, Uri, window } from "vscode";
import { readParameter } from "../../idfConfiguration";
import { Logger } from "../../logger/logger";
import { appendIdfAndToolsToPath, spawn } from "../../utils";
import { OutputChannel } from "../../logger/outputChannel";

export async function flashBinaryToPartition(
offset: string,
Expand Down Expand Up @@ -50,7 +51,7 @@ export async function flashBinaryToPartition(
"esptool.py"
);

await spawn(
const flashingOutput = await spawn(
pythonBinPath,
[esptoolPath, "-p", serialPort, "write_flash", offset, binPath],
{
Expand All @@ -64,7 +65,7 @@ export async function flashBinaryToPartition(
} catch (error) {
let msg = error.message
? error.message
: "Error getting partitions from device";
: "Error flashing binary to device";
Logger.errorNotify(msg, error);
}
}
Expand Down
40 changes: 30 additions & 10 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2188,26 +2188,46 @@ export async function activate(context: vscode.ExtensionContext) {
if (!binPath) {
return;
}
let items = [];
const partitionsInDevice = partitionTableTreeDataProvider.getChildren();
if (!partitionsInDevice) {
vscode.window.showInformationMessage("No partition found");
return;
}
let items = [];
for (let devicePartition of partitionsInDevice) {
const item = {
label: devicePartition.name,
target: devicePartition.offset,
description: devicePartition.description,
};
items.push(item);
} else {
for (let devicePartition of partitionsInDevice) {
const item = {
label: devicePartition.name,
target: devicePartition.offset,
description: devicePartition.description,
};
items.push(item);
}
}
items.push({
label: "Custom offset",
target: "custom",
description: "Enter a custom offset",
});
const partitionAction = await vscode.window.showQuickPick(items, {
placeHolder: "Select a partition to use",
});
if (!partitionAction) {
return;
}
if (partitionAction.target === "custom") {
const customOffset = await vscode.window.showInputBox({
placeHolder: "Enter custom partition table offset",
value: "",
validateInput: (text) => {
return /^(0x[0-9a-fA-F]+|[0-9]+)$/i.test(text)
? null
: "The value is not a valid hexadecimal number";
},
});
if (!customOffset) {
return;
}
partitionAction.target = customOffset;
}
await flashBinaryToPartition(
partitionAction.target,
binPath.fsPath,
Expand Down
1 change: 1 addition & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export function spawn(
let buff = Buffer.alloc(0);
const sendToOutputChannel = (data: Buffer) => {
buff = Buffer.concat([buff, data]);
OutputChannel.append(data.toString());
};
return new Promise((resolve, reject) => {
options.cwd = options.cwd || path.resolve(path.join(__dirname, ".."));
Expand Down

0 comments on commit 46484f6

Please sign in to comment.