mirror of
https://github.com/thooge/esp32-nmea2000-obp60.git
synced 2025-12-14 14:33:07 +01:00
use chip id for all image checks
This commit is contained in:
@@ -10,8 +10,7 @@ import * as zip from "https://cdn.jsdelivr.net/npm/@zip.js/zip.js@2.7.29/+esm";
|
||||
const HDROFFSET = 288;
|
||||
const VERSIONOFFSET = 16;
|
||||
const NAMEOFFSET = 48;
|
||||
const CHIPOFFSET=NAMEOFFSET+64;
|
||||
const MINSIZE = HDROFFSET + CHIPOFFSET + 32;
|
||||
const MINSIZE = HDROFFSET + NAMEOFFSET + 32;
|
||||
const CHIPIDOFFSET=12; //2 bytes chip id here
|
||||
const imageMagic=0xe9; //at byte 0
|
||||
const imageCheckBytes = {
|
||||
@@ -22,6 +21,7 @@ import * as zip from "https://cdn.jsdelivr.net/npm/@zip.js/zip.js@2.7.29/+esm";
|
||||
};
|
||||
/**
|
||||
* map of our known chip ids to flash starts for full images
|
||||
* 0 - esp32 - starts at 0x1000
|
||||
* 9 - esp32s3 - starts at 0
|
||||
*/
|
||||
const FLASHSTART={
|
||||
@@ -47,8 +47,8 @@ import * as zip from "https://cdn.jsdelivr.net/npm/@zip.js/zip.js@2.7.29/+esm";
|
||||
let prfx=isFull?"full":"update";
|
||||
let startOffset=0;
|
||||
let flashStart=UPDATE_START;
|
||||
let chipId=getChipId(content);
|
||||
if (isFull){
|
||||
let chipId=getChipId(content);
|
||||
if (chipId < 0) throw new Error(prfx+"image: no valid chip id found");
|
||||
let flashStart=FLASHSTART[chipId];
|
||||
if (flashStart === undefined) throw new Error(prfx+"image: unknown chip id "+chipId);
|
||||
@@ -69,11 +69,10 @@ import * as zip from "https://cdn.jsdelivr.net/npm/@zip.js/zip.js@2.7.29/+esm";
|
||||
}
|
||||
let version = decodeFromBuffer(content, startOffset+ HDROFFSET + VERSIONOFFSET, 32);
|
||||
let fwtype = decodeFromBuffer(content, startOffset+ HDROFFSET + NAMEOFFSET, 32);
|
||||
let chip=decodeFromBuffer(content,startOffset+HDROFFSET+CHIPOFFSET,32);
|
||||
let rt = {
|
||||
fwtype: fwtype,
|
||||
version: version,
|
||||
chip:chip,
|
||||
chipId:chipId,
|
||||
flashStart: flashStart
|
||||
};
|
||||
return rt;
|
||||
@@ -133,22 +132,13 @@ import * as zip from "https://cdn.jsdelivr.net/npm/@zip.js/zip.js@2.7.29/+esm";
|
||||
hFrame.textContent='';
|
||||
let h=addEl('h2',undefined,hFrame,`ESP32 Install ${info}`)
|
||||
}
|
||||
const checkChip= async (chipFamily,data,isFull)=>{
|
||||
const checkChip= async (chipId,data,isFull)=>{
|
||||
let info=checkImage(data,isFull);
|
||||
if (info.chip && info.chip.match(/^@@/)){
|
||||
let chip=info.chip.substr(2);
|
||||
let compare=chipFamily.toLowerCase().replace(/[^a-z0-9]*/g,'');
|
||||
if (compare !== chip){
|
||||
let res=confirm("different chip signatures - image("+chip+"), chip ("+compare+")\nUse this image any way?");
|
||||
if (! res) throw new Error("user abort");
|
||||
}
|
||||
return;
|
||||
if (info.chipId != chipId){
|
||||
let res=confirm("different chip signatures - image("+chipId+"), chip ("+info.chipId+")\nUse this image any way?");
|
||||
if (! res) throw new Error("user abort");
|
||||
}
|
||||
//for now only ESP32/ESP32-S3
|
||||
if (chipFamily != "ESP32" && chipFamily != "ESP32-S3"){
|
||||
throw new Error(`unexpected chip family ${chipFamily}, expected ESP32/ESP32-S3`);
|
||||
}
|
||||
return;
|
||||
return info;
|
||||
}
|
||||
const baudRates=[1200,
|
||||
2400,
|
||||
@@ -339,7 +329,6 @@ import * as zip from "https://cdn.jsdelivr.net/npm/@zip.js/zip.js@2.7.29/+esm";
|
||||
await espInstaller.runFlash(
|
||||
true,
|
||||
fullData,
|
||||
vinfo.flashStart,
|
||||
version,
|
||||
checkChip
|
||||
)
|
||||
@@ -353,7 +342,6 @@ import * as zip from "https://cdn.jsdelivr.net/npm/@zip.js/zip.js@2.7.29/+esm";
|
||||
await espInstaller.runFlash(
|
||||
false,
|
||||
updateData,
|
||||
uinfo.flashStart,
|
||||
version,
|
||||
checkChip
|
||||
)
|
||||
|
||||
@@ -61,6 +61,7 @@ class ESPInstaller{
|
||||
this.base=import.meta.url.replace(/[^/]*$/,"install.php");
|
||||
this.consoleDevice=undefined;
|
||||
this.consoleReader=undefined;
|
||||
this.imageChipId=undefined;
|
||||
}
|
||||
/**
|
||||
* get an URL query parameter
|
||||
@@ -133,6 +134,7 @@ class ESPInstaller{
|
||||
this.espLoaderTerminal.writeLine(`chip: ${foundChip}`);
|
||||
await this.esploader.flash_id();
|
||||
this.chipFamily = this.esploader.chip.CHIP_NAME;
|
||||
this.imageChipId = this.esploader.chip.IMAGE_CHIP_ID;
|
||||
this.espLoaderTerminal.writeLine(`chipFamily: ${this.chipFamily}`);
|
||||
} catch (e) {
|
||||
this.disconnect();
|
||||
@@ -185,6 +187,10 @@ class ESPInstaller{
|
||||
this.checkConnected();
|
||||
return this.chipFamily;
|
||||
}
|
||||
getChipId(){
|
||||
this.checkConnected();
|
||||
return this.imageChipId;
|
||||
}
|
||||
/**
|
||||
* flass the device
|
||||
* @param {*} fileList : an array of entries {data:blob,address:number}
|
||||
@@ -236,7 +242,7 @@ class ESPInstaller{
|
||||
* @param {*} repo
|
||||
* @param {*} version
|
||||
* @param {*} assetName
|
||||
* @param {*} checkChip will be called with the found chip and the data and the isFull flag
|
||||
* @param {*} checkChip will be called with the found chipId and the data and the isFull flag
|
||||
* must return an info with the flashStart being set
|
||||
* @returns
|
||||
*/
|
||||
@@ -247,7 +253,7 @@ class ESPInstaller{
|
||||
if (!imageData || imageData.length == 0) {
|
||||
throw new Error(`no image data fetched`);
|
||||
}
|
||||
let info=await checkChip(this.getChipFamily(),imageData,isFull);
|
||||
let info=await checkChip(this.getChipId(),imageData,isFull);
|
||||
let fileList = [
|
||||
{ data: imageData, address: info.flashAddress }
|
||||
];
|
||||
@@ -267,20 +273,18 @@ class ESPInstaller{
|
||||
/**
|
||||
* directly run the flash
|
||||
* @param {*} isFull
|
||||
* @param {*} address
|
||||
* @param {*} imageData the data to be flashed
|
||||
* @param {*} version the info shown in the dialog
|
||||
* @param {*} checkChip will be called with the found chip and the data
|
||||
* @param {*} checkChip will be called with the found chipId and the data
|
||||
* must return an info with flashAddress
|
||||
* @returns
|
||||
*/
|
||||
async runFlash(isFull,imageData,address,version,checkChip){
|
||||
async runFlash(isFull,imageData,version,checkChip){
|
||||
try {
|
||||
await this.connect();
|
||||
if (checkChip) {
|
||||
await checkChip(this.getChipFamily(),imageData,isFull); //just check
|
||||
}
|
||||
let info= await checkChip(this.getChipId(),imageData,isFull); //just check
|
||||
let fileList = [
|
||||
{ data: imageData, address: address }
|
||||
{ data: imageData, address: info.flashAddress }
|
||||
];
|
||||
let txt = isFull ? "baseImage (all data will be erased)" : "update";
|
||||
if (!confirm(`ready to install ${version}\n${txt}`)) {
|
||||
|
||||
Reference in New Issue
Block a user