Compare commits
8 Commits
94c9bc8740
...
56834c20fe
Author | SHA1 | Date | |
---|---|---|---|
56834c20fe | |||
|
e8d66b62bf | ||
|
b64ea900ec | ||
|
d4ebd0655a | ||
|
dd615d511b | ||
|
f82528a69a | ||
|
9bbb76e016 | ||
|
4d2ad0b1d6 |
20
.github/workflows/publish.yml
vendored
20
.github/workflows/publish.yml
vendored
@ -11,12 +11,12 @@ jobs:
|
||||
- uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 16
|
||||
registry-url: 'https://registry.npmjs.org'
|
||||
registry-url: "https://registry.npmjs.org"
|
||||
- name: Install dependencies and build 🔧
|
||||
run: npm ci && npm run build
|
||||
- name: Run lint
|
||||
- name: Run lint
|
||||
run: npm run lint
|
||||
- name: Run tests
|
||||
- name: Run tests
|
||||
run: npm run test
|
||||
- name: Package module
|
||||
run: npm pack
|
||||
@ -25,7 +25,7 @@ jobs:
|
||||
run: |
|
||||
[ ${GITHUB_REF:11} = $(node -p "require('./package.json').version") ]
|
||||
echo "version=${GITHUB_REF:11}" >> $GITHUB_OUTPUT
|
||||
- name: Upload npm package file
|
||||
- name: Upload package file
|
||||
uses: actions/upload-artifact@v1
|
||||
with:
|
||||
name: esptool-js-${{ steps.version.outputs.version }}.tgz
|
||||
@ -49,7 +49,17 @@ jobs:
|
||||
### Bug Fixes
|
||||
|
||||
<!-- Insert The Bug Fixes below as points, also add relevant links -->
|
||||
- name: Upload release
|
||||
id: upload-release-asset
|
||||
uses: actions/upload-release-asset@v1.0.1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: ./esptool-js-${{ steps.version.outputs.version }}.tgz
|
||||
asset_name: esptool-js-${{ steps.version.outputs.version }}.tgz
|
||||
asset_content_type: application/zip
|
||||
- name: Publish package on NPM 📦
|
||||
run: npm publish
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
|
15
.vscode/launch.json
vendored
Normal file
15
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "chrome",
|
||||
"request": "launch",
|
||||
"name": "Launch Chrome against localhost",
|
||||
"url": "http://localhost:8080",
|
||||
"webRoot": "${workspaceFolder}"
|
||||
}
|
||||
]
|
||||
}
|
BIN
binary_blob/boot_app0.bin
Normal file
BIN
binary_blob/boot_app0.bin
Normal file
Binary file not shown.
BIN
binary_blob/bootloader.bin
Normal file
BIN
binary_blob/bootloader.bin
Normal file
Binary file not shown.
BIN
binary_blob/opendtu-generic.bin
Normal file
BIN
binary_blob/opendtu-generic.bin
Normal file
Binary file not shown.
BIN
binary_blob/partitions.bin
Normal file
BIN
binary_blob/partitions.bin
Normal file
Binary file not shown.
@ -44,7 +44,7 @@
|
||||
</div>
|
||||
|
||||
<div id="files">
|
||||
<table class="table table-striped" id="fileTable">
|
||||
<!-- <table class="table table-striped" id="fileTable">
|
||||
<thead class="thead-light">
|
||||
<tr>
|
||||
<th>Flash Address</th>
|
||||
@ -54,8 +54,8 @@
|
||||
</thead>
|
||||
<tbody id="tableBody">
|
||||
</tbody>
|
||||
</table>
|
||||
<input class="btn btn-info btn-sm" type="button" id="addFile" value="Add File" />
|
||||
</table> -->
|
||||
<!-- <input class="btn btn-info btn-sm" type="button" id="addFile" value="Add File" /> -->
|
||||
<input class="btn btn-info btn-sm" type="button" id="programButton" value="Program" />
|
||||
</div>
|
||||
<output id="list"></output>
|
||||
|
411
index.js
411
index.js
@ -28,6 +28,7 @@ let transport;
|
||||
let chip = null;
|
||||
let esploader;
|
||||
let file1 = null;
|
||||
// let temp_bin_file = null;
|
||||
let connected = false;
|
||||
|
||||
disconnectButton.style.display = 'none';
|
||||
@ -51,8 +52,96 @@ function handleFileSelect(evt) {
|
||||
})(file);
|
||||
|
||||
reader.readAsBinaryString(file);
|
||||
|
||||
|
||||
}
|
||||
|
||||
function sleep(milliseconds) {
|
||||
const date = Date.now();
|
||||
let currentDate = null;
|
||||
do {
|
||||
currentDate = Date.now();
|
||||
} while (currentDate - date < milliseconds);
|
||||
}
|
||||
|
||||
|
||||
function SyncFileReader(file) {
|
||||
let self = this;
|
||||
let ready = false;
|
||||
let result = '';
|
||||
|
||||
const sleep = function (ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
self.readAsBinaryString = async function() {
|
||||
while (ready === false) {
|
||||
await sleep(100);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
const reader = new FileReader();
|
||||
reader.onloadend = function(evt) {
|
||||
result = evt.target.result;
|
||||
if( result ){
|
||||
console.log(result);
|
||||
}
|
||||
ready = true;
|
||||
};
|
||||
reader.readAsBinaryString(file);
|
||||
}
|
||||
|
||||
// function binary_reader_helper(file) {
|
||||
// var ready = false;
|
||||
// var result = '';
|
||||
|
||||
// var check = function() {
|
||||
// if (ready === true) {
|
||||
// // do what you want with the result variable
|
||||
// return;
|
||||
// }
|
||||
// setTimeout(check, 1000);
|
||||
// }
|
||||
|
||||
// check();
|
||||
|
||||
// var reader = new FileReader();
|
||||
// reader.onloadend = function(evt) {
|
||||
// // file is loaded
|
||||
// result = evt.target.result;
|
||||
|
||||
// ready = true;
|
||||
// };
|
||||
// reader.readAsBinaryString(file);
|
||||
|
||||
// return (' ' + reader.result).slice(1);
|
||||
|
||||
// // let reader = new FileReader();
|
||||
|
||||
// // reader.onload = function(evt) {
|
||||
|
||||
// // var bin = evt.target.result; //get file content
|
||||
|
||||
// // // do sth with text
|
||||
// // console.log(bin);
|
||||
|
||||
// // // temp_bin_file = (' ' + bin).slice(1);
|
||||
|
||||
// // // var li = document.createElement("li");
|
||||
// // // li.innerHTML = name;
|
||||
// // // ul.appendChild(li);
|
||||
// // };
|
||||
|
||||
// // reader.onloadend = () => {
|
||||
// // console.log("DONE", reader.readyState); // readyState will be 2
|
||||
// // };
|
||||
|
||||
|
||||
|
||||
|
||||
// }
|
||||
|
||||
let espLoaderTerminal = {
|
||||
clean() {
|
||||
term.clear();
|
||||
@ -119,54 +208,54 @@ eraseButton.onclick = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
addFile.onclick = () => {
|
||||
var rowCount = table.rows.length;
|
||||
var row = table.insertRow(rowCount);
|
||||
// addFile.onclick = () => {
|
||||
// var rowCount = table.rows.length;
|
||||
// var row = table.insertRow(rowCount);
|
||||
|
||||
//Column 1 - Offset
|
||||
var cell1 = row.insertCell(0);
|
||||
var element1 = document.createElement('input');
|
||||
element1.type = 'text';
|
||||
element1.id = 'offset' + rowCount;
|
||||
element1.value = '0x1000';
|
||||
cell1.appendChild(element1);
|
||||
// //Column 1 - Offset
|
||||
// var cell1 = row.insertCell(0);
|
||||
// var element1 = document.createElement('input');
|
||||
// element1.type = 'text';
|
||||
// element1.id = 'offset' + rowCount;
|
||||
// element1.value = '0x1000';
|
||||
// cell1.appendChild(element1);
|
||||
|
||||
// Column 2 - File selector
|
||||
var cell2 = row.insertCell(1);
|
||||
var element2 = document.createElement('input');
|
||||
element2.type = 'file';
|
||||
element2.id = 'selectFile' + rowCount;
|
||||
element2.name = 'selected_File' + rowCount;
|
||||
element2.addEventListener('change', handleFileSelect, false);
|
||||
cell2.appendChild(element2);
|
||||
// // Column 2 - File selector
|
||||
// var cell2 = row.insertCell(1);
|
||||
// var element2 = document.createElement('input');
|
||||
// element2.type = 'file';
|
||||
// element2.id = 'selectFile' + rowCount;
|
||||
// element2.name = 'selected_File' + rowCount;
|
||||
// element2.addEventListener('change', handleFileSelect, false);
|
||||
// cell2.appendChild(element2);
|
||||
|
||||
// Column 3 - Progress
|
||||
var cell3 = row.insertCell(2);
|
||||
cell3.classList.add('progress-cell');
|
||||
cell3.style.display = 'none';
|
||||
cell3.innerHTML = `<progress value="0" max="100"></progress>`;
|
||||
// // Column 3 - Progress
|
||||
// var cell3 = row.insertCell(2);
|
||||
// cell3.classList.add('progress-cell');
|
||||
// cell3.style.display = 'none';
|
||||
// cell3.innerHTML = `<progress value="0" max="100"></progress>`;
|
||||
|
||||
// Column 4 - Remove File
|
||||
var cell4 = row.insertCell(3);
|
||||
cell4.classList.add('action-cell');
|
||||
if (rowCount > 1) {
|
||||
var element4 = document.createElement('input');
|
||||
element4.type = 'button';
|
||||
var btnName = 'button' + rowCount;
|
||||
element4.name = btnName;
|
||||
element4.setAttribute('class', 'btn');
|
||||
element4.setAttribute('value', 'Remove'); // or element1.value = "button";
|
||||
element4.onclick = function () {
|
||||
removeRow(row);
|
||||
};
|
||||
cell4.appendChild(element4);
|
||||
}
|
||||
};
|
||||
// // Column 4 - Remove File
|
||||
// var cell4 = row.insertCell(3);
|
||||
// cell4.classList.add('action-cell');
|
||||
// if (rowCount > 1) {
|
||||
// var element4 = document.createElement('input');
|
||||
// element4.type = 'button';
|
||||
// var btnName = 'button' + rowCount;
|
||||
// element4.name = btnName;
|
||||
// element4.setAttribute('class', 'btn');
|
||||
// element4.setAttribute('value', 'Remove'); // or element1.value = "button";
|
||||
// element4.onclick = function () {
|
||||
// removeRow(row);
|
||||
// };
|
||||
// cell4.appendChild(element4);
|
||||
// }
|
||||
// };
|
||||
|
||||
function removeRow(row) {
|
||||
const rowIndex = Array.from(table.rows).indexOf(row);
|
||||
table.deleteRow(rowIndex);
|
||||
}
|
||||
// function removeRow(row) {
|
||||
// const rowIndex = Array.from(table.rows).indexOf(row);
|
||||
// table.deleteRow(rowIndex);
|
||||
// }
|
||||
|
||||
// to be called on disconnect - remove any stale references of older connections if any
|
||||
function cleanUp() {
|
||||
@ -255,39 +344,220 @@ function validate_program_inputs() {
|
||||
}
|
||||
|
||||
programButton.onclick = async () => {
|
||||
const alertMsg = document.getElementById('alertmsg');
|
||||
const err = validate_program_inputs();
|
||||
// const alertMsg = document.getElementById('alertmsg');
|
||||
// const err = validate_program_inputs();
|
||||
|
||||
if (err != 'success') {
|
||||
alertMsg.innerHTML = '<strong>' + err + '</strong>';
|
||||
alertDiv.style.display = 'block';
|
||||
return;
|
||||
}
|
||||
// if (err != 'success') {
|
||||
// alertMsg.innerHTML = '<strong>' + err + '</strong>';
|
||||
// alertDiv.style.display = 'block';
|
||||
// return;
|
||||
// }
|
||||
|
||||
// Hide error message
|
||||
alertDiv.style.display = 'none';
|
||||
// alertDiv.style.display = 'none';
|
||||
|
||||
let temp_bin_file = null;
|
||||
const fileArray = [];
|
||||
const progressBars = [];
|
||||
// const progressBars = [];
|
||||
|
||||
for (let index = 1; index < table.rows.length; index++) {
|
||||
const row = table.rows[index];
|
||||
// for (let index = 1; index < table.rows.length; index++) {
|
||||
// const row = table.rows[index];
|
||||
|
||||
const offSetObj = row.cells[0].childNodes[0];
|
||||
const offset = parseInt(offSetObj.value);
|
||||
// const offSetObj = row.cells[0].childNodes[0];
|
||||
// const offset = parseInt(offSetObj.value);
|
||||
|
||||
const fileObj = row.cells[1].childNodes[0];
|
||||
const progressBar = row.cells[2].childNodes[0];
|
||||
// const fileObj = row.cells[1].childNodes[0];
|
||||
// const progressBar = row.cells[2].childNodes[0];
|
||||
|
||||
progressBar.value = 0;
|
||||
progressBars.push(progressBar);
|
||||
// progressBar.value = 0;
|
||||
// progressBars.push(progressBar);
|
||||
|
||||
row.cells[2].style.display = 'initial';
|
||||
row.cells[3].style.display = 'none';
|
||||
// row.cells[2].style.display = 'initial';
|
||||
// row.cells[3].style.display = 'none';
|
||||
|
||||
fileArray.push({ data: fileObj.data, address: offset });
|
||||
// fileArray.push({ data: fileObj.data, address: offset });
|
||||
// }
|
||||
|
||||
// ###################################################################
|
||||
// ###################################################################
|
||||
|
||||
let response = await fetch("/binary_blob/bootloader.bin");
|
||||
|
||||
if(response.status != 200) {
|
||||
throw new Error("Server Error");
|
||||
}
|
||||
|
||||
// read response stream as text
|
||||
// let text_data = await response.text();
|
||||
let blob_data = await response.blob();
|
||||
|
||||
if(!blob_data) {
|
||||
throw new Error("Can't read file to flash as blob !")
|
||||
}
|
||||
|
||||
let file = new File( [blob_data], "bootloader.bin", {
|
||||
type: "text/plain",
|
||||
});
|
||||
|
||||
// let reader = new FileReader();
|
||||
|
||||
// reader.onload = (function (theFile) {
|
||||
// return function (e) {
|
||||
// file1 = e.target.result;
|
||||
// };
|
||||
// })(file);
|
||||
|
||||
// reader.onloadend = function (theFile){
|
||||
// file1 = this.result;
|
||||
// console.log(this.result);
|
||||
// };
|
||||
|
||||
console.log( file );
|
||||
|
||||
|
||||
let fileReader = new SyncFileReader(file);
|
||||
temp_bin_file = await fileReader.readAsBinaryString();
|
||||
|
||||
|
||||
|
||||
if( !temp_bin_file ){
|
||||
|
||||
temp_bin_file = await fileReader.readAsBinaryString();
|
||||
|
||||
if( temp_bin_file ){
|
||||
console.log( temp_bin_file );
|
||||
fileArray.push({ data: (' ' + temp_bin_file).slice(1) , address: 0x1000 });
|
||||
}
|
||||
}else{
|
||||
console.log( temp_bin_file );
|
||||
fileArray.push({ data: (' ' + temp_bin_file).slice(1) , address: 0x1000 });
|
||||
}
|
||||
|
||||
temp_bin_file = null;
|
||||
|
||||
|
||||
|
||||
// ###################################################################
|
||||
// ###################################################################
|
||||
|
||||
response = await fetch("/binary_blob/partitions.bin");
|
||||
|
||||
if(response.status != 200) {
|
||||
throw new Error("Server Error");
|
||||
}
|
||||
|
||||
blob_data = await response.blob();
|
||||
|
||||
if(!blob_data) {
|
||||
throw new Error("Can't read file to flash as blob !")
|
||||
}
|
||||
|
||||
file = new File( [blob_data], "partitions.bin", {
|
||||
type: "text/plain",
|
||||
});
|
||||
|
||||
|
||||
console.log( file );
|
||||
|
||||
fileReader = new SyncFileReader(file);
|
||||
temp_bin_file = await fileReader.readAsBinaryString();
|
||||
|
||||
if( !temp_bin_file ){
|
||||
|
||||
temp_bin_file = await fileReader.readAsBinaryString();
|
||||
|
||||
if( temp_bin_file ){
|
||||
console.log( temp_bin_file );
|
||||
fileArray.push({ data: (' ' + temp_bin_file).slice(1) , address: 0x8000 });
|
||||
}
|
||||
}else{
|
||||
console.log( temp_bin_file );
|
||||
fileArray.push({ data: (' ' + temp_bin_file).slice(1) , address: 0x8000 });
|
||||
}
|
||||
|
||||
temp_bin_file = null;
|
||||
|
||||
// ###################################################################
|
||||
// ###################################################################
|
||||
response = await fetch("/binary_blob/boot_app0.bin");
|
||||
|
||||
if(response.status != 200) {
|
||||
throw new Error("Server Error");
|
||||
}
|
||||
|
||||
blob_data = await response.blob();
|
||||
|
||||
if(!blob_data) {
|
||||
throw new Error("Can't read file to flash as blob !")
|
||||
}
|
||||
|
||||
file = new File( [blob_data], "boot_app0.bin", {
|
||||
type: "text/plain",
|
||||
});
|
||||
|
||||
console.log( file );
|
||||
|
||||
fileReader = new SyncFileReader(file);
|
||||
temp_bin_file = await fileReader.readAsBinaryString();
|
||||
|
||||
if( !temp_bin_file ){
|
||||
|
||||
temp_bin_file = await fileReader.readAsBinaryString();
|
||||
|
||||
if( temp_bin_file ){
|
||||
console.log( temp_bin_file );
|
||||
fileArray.push({ data: temp_bin_file , address: 0xe000 });
|
||||
}
|
||||
|
||||
}else{
|
||||
console.log( temp_bin_file );
|
||||
fileArray.push({ data: temp_bin_file , address: 0xe000 });
|
||||
}
|
||||
|
||||
temp_bin_file = null;
|
||||
|
||||
// ###################################################################
|
||||
// ###################################################################
|
||||
response = await fetch("/binary_blob/opendtu-generic.bin");
|
||||
|
||||
if(response.status != 200) {
|
||||
throw new Error("Server Error");
|
||||
}
|
||||
|
||||
blob_data = await response.blob();
|
||||
|
||||
if(!blob_data) {
|
||||
throw new Error("Can't read file to flash as blob !")
|
||||
}
|
||||
|
||||
file = new File( [blob_data], "opendtu-gernic.bin", {
|
||||
type: "text/plain",
|
||||
});
|
||||
|
||||
console.log( file );
|
||||
|
||||
fileReader = new SyncFileReader(file);
|
||||
temp_bin_file = await fileReader.readAsBinaryString();
|
||||
|
||||
|
||||
if( !temp_bin_file ){
|
||||
|
||||
temp_bin_file = await fileReader.readAsBinaryString();
|
||||
|
||||
if( temp_bin_file ){
|
||||
console.log( temp_bin_file );
|
||||
fileArray.push({ data: temp_bin_file , address: 0x10000 });
|
||||
}
|
||||
}else{
|
||||
console.log( temp_bin_file );
|
||||
fileArray.push({ data: temp_bin_file , address: 0x10000 });
|
||||
}
|
||||
|
||||
temp_bin_file = null;
|
||||
|
||||
sleep(3000)
|
||||
console.log(fileArray)
|
||||
|
||||
try {
|
||||
await esploader.write_flash(
|
||||
fileArray,
|
||||
@ -296,9 +566,7 @@ programButton.onclick = async () => {
|
||||
undefined,
|
||||
false,
|
||||
true,
|
||||
(fileIndex, written, total) => {
|
||||
progressBars[fileIndex].value = (written / total) * 100;
|
||||
},
|
||||
null,
|
||||
(image) => CryptoJS.MD5(CryptoJS.enc.Latin1.parse(image)),
|
||||
);
|
||||
} catch (e) {
|
||||
@ -306,11 +574,12 @@ programButton.onclick = async () => {
|
||||
term.writeln(`Error: ${e.message}`);
|
||||
} finally {
|
||||
// Hide progress bars and show erase buttons
|
||||
for (let index = 1; index < table.rows.length; index++) {
|
||||
table.rows[index].cells[2].style.display = 'none';
|
||||
table.rows[index].cells[3].style.display = 'initial';
|
||||
}
|
||||
// for (let index = 1; index < table.rows.length; index++) {
|
||||
// table.rows[index].cells[2].style.display = 'none';
|
||||
// table.rows[index].cells[3].style.display = 'initial';
|
||||
// }
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
addFile.onclick();
|
||||
// addFile.onclick();
|
||||
|
2398
package-lock.json
generated
2398
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "esptool-js",
|
||||
"version": "0.2.0",
|
||||
"version": "0.2.1",
|
||||
"module": "lib/index.js",
|
||||
"main": "lib/index.js",
|
||||
"types": "lib/index.d.ts",
|
||||
@ -26,6 +26,8 @@
|
||||
"url": "https://github.com/espressif/esptool-js/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"browser-sync": "^2.29.1",
|
||||
"lodash": "^4.17.21",
|
||||
"pako": "^2.1.0",
|
||||
"tslib": "^2.4.1"
|
||||
},
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { ESPError } from "./error";
|
||||
import { deflate } from "pako";
|
||||
import { Data, deflate, Inflate } from "pako";
|
||||
import { Transport } from "./webserial";
|
||||
import { ROM } from "./targets/rom";
|
||||
|
||||
async function magic2Chip(magic: number): Promise<ROM> {
|
||||
async function magic2Chip(magic: number): Promise<ROM | null> {
|
||||
switch (magic) {
|
||||
case 0x00f01d83: {
|
||||
const { ESP32ROM } = await import("./targets/esp32");
|
||||
@ -86,7 +86,7 @@ export class ESPLoader {
|
||||
|
||||
USB_JTAG_SERIAL_PID = 0x1001;
|
||||
|
||||
chip: ROM;
|
||||
chip!: ROM;
|
||||
IS_STUB: boolean;
|
||||
FLASH_WRITE_SIZE: number;
|
||||
|
||||
@ -98,7 +98,6 @@ export class ESPLoader {
|
||||
private debugLogging = false,
|
||||
) {
|
||||
this.IS_STUB = false;
|
||||
this.chip = null;
|
||||
this.FLASH_WRITE_SIZE = 0x4000;
|
||||
if (this.terminal) {
|
||||
this.terminal.clean();
|
||||
@ -189,7 +188,7 @@ export class ESPLoader {
|
||||
try {
|
||||
await this.transport.rawRead(200);
|
||||
} catch (e) {
|
||||
this.error(e);
|
||||
this.error((e as Error).message);
|
||||
}
|
||||
}
|
||||
|
||||
@ -328,7 +327,7 @@ export class ESPLoader {
|
||||
const res = await this.transport.read(1000);
|
||||
i += res.length;
|
||||
} catch (e) {
|
||||
this.debug(e);
|
||||
this.debug((e as Error).message);
|
||||
if (e instanceof Error) {
|
||||
keepReading = false;
|
||||
break;
|
||||
@ -344,7 +343,6 @@ export class ESPLoader {
|
||||
this.debug(resp[0].toString());
|
||||
return "success";
|
||||
} catch (error) {
|
||||
this.debug(error);
|
||||
if (error instanceof Error) {
|
||||
if (esp32r0_delay) {
|
||||
this.info("_", false);
|
||||
@ -381,9 +379,11 @@ export class ESPLoader {
|
||||
if (!detecting) {
|
||||
const chip_magic_value = (await this.read_reg(0x40001000)) >>> 0;
|
||||
this.debug("Chip Magic " + chip_magic_value.toString(16));
|
||||
this.chip = await magic2Chip(chip_magic_value);
|
||||
const chip = await magic2Chip(chip_magic_value);
|
||||
if (this.chip === null) {
|
||||
throw new ESPError(`Unexpected CHIP magic value ${chip_magic_value}. Failed to autodetect chip type.`);
|
||||
} else {
|
||||
this.chip = chip as ROM;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -768,7 +768,7 @@ export class ESPLoader {
|
||||
try {
|
||||
await this.transport.rawRead(500);
|
||||
} catch (e) {
|
||||
this.debug(e);
|
||||
this.debug((e as Error).message);
|
||||
}
|
||||
}
|
||||
|
||||
@ -912,7 +912,7 @@ export class ESPLoader {
|
||||
continue;
|
||||
}
|
||||
image = this._update_image_flash_params(image, address, flash_size, flash_mode, flash_freq);
|
||||
let calcmd5: string;
|
||||
let calcmd5: string | null = null;
|
||||
if (calculateMD5Hash) {
|
||||
calcmd5 = calculateMD5Hash(image);
|
||||
this.debug("Image MD5 " + calcmd5);
|
||||
@ -935,32 +935,39 @@ export class ESPLoader {
|
||||
const t1 = d.getTime();
|
||||
|
||||
let timeout = 5000;
|
||||
// Create a decompressor to keep track of the size of uncompressed data
|
||||
// to be written in each chunk.
|
||||
const inflate = new Inflate({ chunkSize: 1 });
|
||||
let total_len_uncompressed = 0;
|
||||
inflate.onData = function (chunk: Data): void {
|
||||
total_len_uncompressed += chunk.byteLength;
|
||||
};
|
||||
while (image.length > 0) {
|
||||
this.debug("Write loop " + address + " " + seq + " " + blocks);
|
||||
this.info(
|
||||
"Writing at 0x" +
|
||||
(address + seq * this.FLASH_WRITE_SIZE).toString(16) +
|
||||
(address + total_len_uncompressed).toString(16) +
|
||||
"... (" +
|
||||
Math.floor((100 * (seq + 1)) / blocks) +
|
||||
"%)",
|
||||
);
|
||||
const block = this.bstrToUi8(image.slice(0, this.FLASH_WRITE_SIZE));
|
||||
|
||||
if (compress) {
|
||||
/*
|
||||
let block_uncompressed = pako.inflate(block).length;
|
||||
//let len_uncompressed = block_uncompressed.length;
|
||||
bytes_written += block_uncompressed;
|
||||
if (this.timeout_per_mb(this.ERASE_WRITE_TIMEOUT_PER_MB, block_uncompressed) > 3000) {
|
||||
block_timeout = this.timeout_per_mb(this.ERASE_WRITE_TIMEOUT_PER_MB, block_uncompressed);
|
||||
} else {
|
||||
block_timeout = 3000;
|
||||
}*/ // XXX: Partial block inflate seems to be unsupported in Pako. Hardcoding timeout
|
||||
const block_timeout = 5000;
|
||||
const len_uncompressed_previous = total_len_uncompressed;
|
||||
inflate.push(block, false);
|
||||
const block_uncompressed = total_len_uncompressed - len_uncompressed_previous;
|
||||
let block_timeout = 3000;
|
||||
if (this.timeout_per_mb(this.ERASE_WRITE_TIMEOUT_PER_MB, block_uncompressed) > 3000) {
|
||||
block_timeout = this.timeout_per_mb(this.ERASE_WRITE_TIMEOUT_PER_MB, block_uncompressed);
|
||||
}
|
||||
if (this.IS_STUB === false) {
|
||||
// ROM code writes block to flash before ACKing
|
||||
timeout = block_timeout;
|
||||
}
|
||||
await this.flash_defl_block(block, seq, timeout);
|
||||
if (this.IS_STUB) {
|
||||
// Stub ACKs when block is received, then writes to flash while receiving the block after it
|
||||
timeout = block_timeout;
|
||||
}
|
||||
} else {
|
||||
|
@ -122,7 +122,7 @@ class Transport {
|
||||
packet = this.left_over;
|
||||
this.left_over = new Uint8Array(0);
|
||||
}
|
||||
if (typeof this.device.readable == "undefined") {
|
||||
if (this.device.readable == null) {
|
||||
return this.left_over;
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,8 @@
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"lib": ["ES2020", "DOM"],
|
||||
"importHelpers": true,
|
||||
"resolveJsonModule": true
|
||||
"resolveJsonModule": true,
|
||||
"strict": true
|
||||
},
|
||||
"include": ["src/**/*"]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user