espressif / esptool

Espressif SoC serial bootloader utility
https://docs.espressif.com/projects/esptool
GNU General Public License v2.0
5.48k stars 1.36k forks source link

Inconsistency of bit position reading pkg_version from ESP32-C2 (ESPTOOL-487) #759

Closed xingrz closed 2 years ago

xingrz commented 2 years ago

Operating System

macOS 12.4

Esptool Version

v4.1-15-g65f8614

Python Version

Python 3.9.13

Chip Description

ESP32-C2

Device Description

ESP8684-DevKitM-1

Hardware Configuration

No response

How is Esptool Run

Terminal (iTerm.app)

Full Esptool Command Line that Was Run

esptool.py --port /dev/cu.usbserial-14110 flash_id

Esptool Output

esptool.py v3.3.1
Serial port /dev/cu.usbserial-14110
Connecting....
Detecting chip type... ESP32-C2
Chip is ESP32-C2 (revision 1)
Features: Wi-Fi
Crystal is 40MHz
MAC: 10:97:bd:f1:e6:3c
Uploading stub...
Running stub...
Stub running...
Manufacturer: 5e
Device: 4016
Detected flash size: 4MB
Hard resetting via RTS pin...

More Information

esptool.py works well, actually. But after reviewing the code, I found something inconsistent.

According to esp_efuse_table.csv#L69 in ESP-IDF, the position of PKG_VERSION is at bit 54 of EFUSE_BLK2 (which is also EFUSE_RD_BLK2_DATA0_REG).

As we learn from efuse_reg.h#L312, the value of EFUSE_RD_BLK2_DATA0_REG is DR_REG_EFUSE_BASE + 0x40 and EFUSE_RD_BLK2_DATA1_REG is DR_REG_EFUSE_BASE + 0x44. So we can infer that the bit position of PKG_VERSION counting from 0x044 should be 22.

While in esp32c2.py#L55, we read the forth word (EFUSE_BASE + 0x044 plus 12 bytes) and right shifted 21 bits (considering the byte order, means moving the pointer right 21 bits). This is actually 12 bytes + 21 bits = 117 bits counting from 0x044, or bit 149 counting from EFUSE_BLK2.

https://github.com/espressif/esptool/blob/65f861420515217f7b5d209fce288808dc5b1943/esptool/targets/esp32c2.py#L52-L55

Other Steps to Reproduce

No response

I Have Read the Troubleshooting Guide

dobairoland commented 2 years ago

Thank you for your report!