NabuCasa / esp-web-flasher

A web serial package for updating your ESP bootloader via the browser.
https://nabucasa.github.io/esp-web-flasher/
MIT License
43 stars 16 forks source link

Fix chip detection for ESP8266 #27

Closed conradopoole closed 3 years ago

conradopoole commented 3 years ago

Changed keys of CHIP_DETECT_MAGIC_VALUES to Strings as the new magic value being added is a negative one and cannot be used as a key.

TD-er commented 3 years ago

Isn't this just a matter of a value being interpreted as 32 bit signed value? So casting it to an unsigned value before trying to create a negative hex value sounds a lot more usable. Not even sure if negative hex values should even exist, so it feels like it may break in some implementation.

conradopoole commented 3 years ago

Isn't this just a matter of a value being interpreted as 32 bit signed value? So casting it to an unsigned value before trying to create a negative hex value sounds a lot more usable. Not even sure if negative hex values should even exist, so it feels like it may break in some implementation.

I think javascript uses by default 64 bit singed, I'm not sure. In any case, it's the unpack/pack functions in the utils.ts that do the conversions... but I don't really fully understand how they work, so perhaps you are right and the original magic value that esptool uses to identify ESP8266, 0xfff0c101, might not be read and interpreted correctly...

The actual integer being read is -999167 which happens to be the decimal from signed 2's complement value for 0xfff0c101.

When I used to have the CHIP_DETECT_MAGIC_VALUES with integer keys, it would not find that key, probably because it is a negative integer.... I'm going to think a bit more about it to try and get that toHex function to return the signed 2 compliment value....

TD-er commented 3 years ago

If it uses 64 bit values and you try to convert a negative value into HEX, you should get a lot of leading FF values. Strange thing is though, that there are other values in that file which are close to 2^32 in value, so why are those read correct?

balloob commented 3 years ago

@TD-er I am going to merge this fix and release so that we fix ESP8266 devices. If S3 doesn't work, let's address that in another PR. @conradopoole has ordered a couple of ESPs so we can better test moving forward.