Skip to content

Commit

Permalink
Merge branch 'espressif:master' into release/v4
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason2866 authored Jan 7, 2024
2 parents b49ebee + e948993 commit b30358d
Show file tree
Hide file tree
Showing 24 changed files with 1,824 additions and 34 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/dev_release_esptool_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ jobs:
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
TWINE_NON_INTERACTIVE: true
run: |
DEV_VERSION=$(echo "${{ github.ref_name }}" | grep -oE 'dev[0-9]+' | sed 's/dev//')
python ci/patch_dev_release.py --dev-no ${DEV_VERSION} esptool/__init__.py
python ci/patch_dev_release.py --version ${{ github.ref_name }} esptool/__init__.py
git diff
python -m pip download esptool==$(python setup.py -V) && echo "Version ${{ github.ref_name }} already published, skipping..." && exit 1
Expand Down
2 changes: 2 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ include:
file: danger.yaml
run-danger-mr-linter:
stage: pre-check
variables:
ENABLE_CHECK_UPDATED_CHANGELOG: 'false'

# cache the pip download directory in all jobs
variables:
Expand Down
19 changes: 8 additions & 11 deletions ci/patch_dev_release.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
#
# SPDX-License-Identifier: GPL-2.0-or-later

import argparse
import re

LINE_RE = re.compile(r"^__version__ = ['\"]([^'\"]*)['\"]")
NEW_LINE = '__version__ = "{}"'
NEW_LINE = '__version__ = "{}"\n'


def get_new_version(old_version, dev_number):
assert old_version.endswith("-dev")
return old_version.replace("-dev", ".dev{}".format(dev_number), 1)
def patch_file(path, new_version):
assert ".dev" in new_version
new_version = new_version.lstrip("v")


def patch_file(path, dev_number):
with open(path, "r") as fin:
lines = fin.readlines()

for i, line in enumerate(lines, start=0):
m = LINE_RE.search(line)
if m:
old_version = m.group(1)
lines[i] = NEW_LINE.format(get_new_version(old_version, dev_number))
lines[i] = NEW_LINE.format(new_version)
break

with open(path, "w") as fout:
Expand All @@ -33,10 +30,10 @@ def main():
parser = argparse.ArgumentParser()
parser.add_argument("file", help="Path to script with __version__")
parser.add_argument(
"--dev-no", type=int, help="Number N to patch the version to '.devN'"
"--version", help="Development version specifier to patch the version to"
)
args = parser.parse_args()
patch_file(args.file, args.dev_no)
patch_file(args.file, args.version)


if __name__ == "__main__":
Expand Down
4 changes: 4 additions & 0 deletions espefuse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import espefuse.efuse.esp32 as esp32_efuse
import espefuse.efuse.esp32c2 as esp32c2_efuse
import espefuse.efuse.esp32c3 as esp32c3_efuse
import espefuse.efuse.esp32c5beta3 as esp32c5beta3_efuse
import espefuse.efuse.esp32c6 as esp32c6_efuse
import espefuse.efuse.esp32h2 as esp32h2_efuse
import espefuse.efuse.esp32h2beta1 as esp32h2beta1_efuse
Expand Down Expand Up @@ -49,6 +50,9 @@
"esp32c2": DefChip("ESP32-C2", esp32c2_efuse, esptool.targets.ESP32C2ROM),
"esp32c3": DefChip("ESP32-C3", esp32c3_efuse, esptool.targets.ESP32C3ROM),
"esp32c6": DefChip("ESP32-C6", esp32c6_efuse, esptool.targets.ESP32C6ROM),
"esp32c5beta3": DefChip(
"ESP32-C5(beta3)", esp32c5beta3_efuse, esptool.targets.ESP32C5BETA3ROM
),
"esp32h2": DefChip("ESP32-H2", esp32h2_efuse, esptool.targets.ESP32H2ROM),
"esp32p4": DefChip("ESP32-P4", esp32p4_efuse, esptool.targets.ESP32P4ROM),
"esp32h2beta1": DefChip(
Expand Down
3 changes: 3 additions & 0 deletions espefuse/efuse/esp32c5beta3/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import operations
from .emulate_efuse_controller import EmulateEfuseController
from .fields import EspEfuses
92 changes: 92 additions & 0 deletions espefuse/efuse/esp32c5beta3/emulate_efuse_controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# This file describes eFuses controller for ESP32-C5 beta3 chip
#
# SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
#
# SPDX-License-Identifier: GPL-2.0-or-later

import reedsolo

from .mem_definition import EfuseDefineBlocks, EfuseDefineFields, EfuseDefineRegisters
from ..emulate_efuse_controller_base import EmulateEfuseControllerBase, FatalError


class EmulateEfuseController(EmulateEfuseControllerBase):
"""The class for virtual efuse operation. Using for HOST_TEST."""

CHIP_NAME = "ESP32-C5(beta3)"
mem = None
debug = False

def __init__(self, efuse_file=None, debug=False):
self.Blocks = EfuseDefineBlocks
self.Fields = EfuseDefineFields()
self.REGS = EfuseDefineRegisters
super(EmulateEfuseController, self).__init__(efuse_file, debug)
self.write_reg(self.REGS.EFUSE_CMD_REG, 0)

""" esptool method start >>"""

def get_major_chip_version(self):
return 0

def get_minor_chip_version(self):
return 0

def get_crystal_freq(self):
return 40 # MHz (common for all chips)

def get_security_info(self):
return {
"flags": 0,
"flash_crypt_cnt": 0,
"key_purposes": 0,
"chip_id": 0,
"api_version": 0,
}

""" << esptool method end """

def handle_writing_event(self, addr, value):
if addr == self.REGS.EFUSE_CMD_REG:
if value & self.REGS.EFUSE_PGM_CMD:
self.copy_blocks_wr_regs_to_rd_regs(updated_block=(value >> 2) & 0xF)
self.clean_blocks_wr_regs()
self.check_rd_protection_area()
self.write_reg(addr, 0)
self.write_reg(self.REGS.EFUSE_CMD_REG, 0)
elif value == self.REGS.EFUSE_READ_CMD:
self.write_reg(addr, 0)
self.write_reg(self.REGS.EFUSE_CMD_REG, 0)
self.save_to_file()

def get_bitlen_of_block(self, blk, wr=False):
if blk.id == 0:
if wr:
return 32 * 8
else:
return 32 * blk.len
else:
if wr:
rs_coding = 32 * 3
return 32 * 8 + rs_coding
else:
return 32 * blk.len

def handle_coding_scheme(self, blk, data):
if blk.id != 0:
# CODING_SCHEME RS applied only for all blocks except BLK0.
coded_bytes = 12
data.pos = coded_bytes * 8
plain_data = data.readlist("32*uint:8")[::-1]
# takes 32 bytes
# apply RS encoding
rs = reedsolo.RSCodec(coded_bytes)
# 32 byte of data + 12 bytes RS
calc_encoded_data = list(rs.encode([x for x in plain_data]))
data.pos = 0
if calc_encoded_data != data.readlist("44*uint:8")[::-1]:
raise FatalError("Error in coding scheme data")
data = data[coded_bytes * 8 :]
if blk.len < 8:
data = data[(8 - blk.len) * 32 :]
return data
Loading

0 comments on commit b30358d

Please sign in to comment.