Skip to content
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

Stub already running detection #136

Merged
merged 1 commit into from
May 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/esploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ export class ESPLoader {
private terminal?: IEspLoaderTerminal;
private romBaudrate = 115200;
private debugLogging = false;
private syncStubDetected = false;

/**
* Create a new ESPLoader to perform serial communication
Expand Down Expand Up @@ -576,6 +577,10 @@ export class ESPLoader {

try {
const resp = await this.command(0x08, cmd, undefined, undefined, 100);
// ROM bootloaders send some non-zero "val" response. The flasher stub sends 0.
// If we receive 0 then it probably indicates that the chip wasn't or couldn't be
// reset properly and esptool is talking to the flasher stub.
this.syncStubDetected = this.syncStubDetected && resp[0] === 0;
return resp;
} catch (e) {
this.debug("Sync err " + e);
Expand Down Expand Up @@ -617,6 +622,7 @@ export class ESPLoader {
await this._sleep(50);
}
this.transport.slipReaderEnabled = true;
this.syncStubDetected = true;
i = 7;
while (i--) {
try {
Expand Down Expand Up @@ -1140,6 +1146,11 @@ export class ESPLoader {
* @returns {ROM} The Chip ROM
*/
async runStub(): Promise<ROM> {
if (this.syncStubDetected) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we verify that the version of the stub that's running is the same as the version that we would upload ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not according to what the stub_flasher code does here
https://github.com/espressif/esptool/blob/master/flasher_stub/stub_flasher.c#L240

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair, this follows the esptool.py approach 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any chance this can be merged? This is the last piece of work that the ExpressLRS project needs for it's web-flasher to be on the mainline of esptool-js.

this.info("Stub is already running. No upload is necessary.");
return this.chip;
}

this.info("Uploading stub...");
let decoded = atob(this.chip.ROM_TEXT);
let chardata = decoded.split("").map(function (x) {
Expand Down
Loading