Skip to content

Commit

Permalink
Merge branch 'espressif:master' into main_work
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason2866 authored Apr 7, 2024
2 parents 8d978f2 + 55b338a commit f849d1d
Show file tree
Hide file tree
Showing 16 changed files with 107 additions and 31 deletions.
13 changes: 13 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,19 @@ host_tests:
# some .coverage files in sub-directories are not collected on some runners, move them first
- find . -mindepth 2 -type f -name ".coverage*" -print -exec mv --backup=numbered {} . \;

host_tests_latest_python:
<<: *host_tests_template
image: python:3.12-bullseye
variables:
PYTEST_ADDOPTS: "-sv --junitxml=test/report.xml --color=yes"
script:
- pytest ${CI_PROJECT_DIR}/test/test_imagegen.py
- pytest ${CI_PROJECT_DIR}/test/test_espsecure.py
- pytest ${CI_PROJECT_DIR}/test/test_merge_bin.py
- pytest ${CI_PROJECT_DIR}/test/test_image_info.py
- pytest ${CI_PROJECT_DIR}/test/test_modules.py
- pytest ${CI_PROJECT_DIR}/test/test_espefuse.py --chip esp32

# A new job "host_test_hsm" is created for the test "test_espsecure_hsm.py" which runs an ubuntu image,
# because python-pkcs11 (v0.7.0) package is compiled using GLIBC_2.34 but docker image python:3.7-bullseye
# support versions only upto GLIBC_2.31.
Expand Down
13 changes: 13 additions & 0 deletions .mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[mypy]
# Disallows defining functions with incomplete type annotations
disallow_incomplete_defs = false
# Disallows defining functions without type annotations or with incomplete type annotations
disallow_untyped_defs = false
# Suppress error messages about imports that cannot be resolved
ignore_missing_imports = true
# Specifies the Python version used to parse and check the target program
python_version = 3.9
# Shows errors for missing return statements on some execution paths
warn_no_return = true
# Shows a warning when returning a value with type Any from a function declared with a non- Any return type
warn_return_any = true
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ repos:
- id: sphinx-lint
name: Lint RST files in docs folder using Sphinx Lint
files: ^((docs/en)/.*\.(rst|inc))|CONTRIBUTING.rst$
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.4.1 # the last version running on py3.7
hooks:
- id: mypy
additional_dependencies: [types-all]
# ignore wrapper scripts because of name colision with efuse/__init__.py etc.
exclude: test/|docs/|espefuse.py|espsecure.py|esptool.py
- repo: https://github.com/codespell-project/codespell
rev: v2.2.5
hooks:
Expand Down
5 changes: 3 additions & 2 deletions espefuse/efuse/base_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import esptool

from . import util
from typing import List


class CheckArgValue(object):
Expand Down Expand Up @@ -441,8 +442,8 @@ class EspEfusesBase(object):
"""

_esp = None
blocks = []
efuses = []
blocks: List[EfuseBlockBase] = []
efuses: List = []
coding_scheme = None
force_write_always = None
batch_mode_cnt = 0
Expand Down
7 changes: 3 additions & 4 deletions espefuse/efuse/base_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,11 @@ def check_efuse_name(efuse_name, efuse_list):
)
burn.add_argument(
"name_value_pairs",
help="Name of efuse register and New value pairs to burn",
help="Name of efuse field and new value pairs to burn. EFUSE_NAME: "
"[{}].".format(", ".join([e.name for e in efuses.efuses])),
action=ActionEfuseValuePair,
nargs="+",
metavar="[EFUSE_NAME VALUE] [{} VALUE".format(
" VALUE] [".join([e.name for e in efuses.efuses])
),
metavar="[EFUSE_NAME VALUE]",
efuse_choices=[e.name for e in efuses.efuses]
+ [name for e in efuses.efuses for name in e.alt_names if name != ""],
efuses=efuses,
Expand Down
11 changes: 9 additions & 2 deletions espefuse/efuse/esp32c5/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,21 @@ def burn_key(esp, efuses, args, digest=None):
block = efuses.blocks[block_num]

if digest is None:
data = datafile.read()
if keypurpose == "ECDSA_KEY":
sk = espsecure.load_ecdsa_signing_key(datafile)
data = sk.to_string()
if len(data) == 24:
# the private key is 24 bytes long for NIST192p, and 8 bytes of padding
data = b"\x00" * 8 + data
else:
data = datafile.read()
else:
data = datafile

print(" - %s" % (efuse.name), end=" ")
revers_msg = None
if efuses[block.key_purpose_name].need_reverse(keypurpose):
revers_msg = "\tReversing byte order for AES-XTS hardware peripheral"
revers_msg = f"\tReversing byte order for {keypurpose} hardware peripheral"
data = data[::-1]
print(
"-> [{}]".format(
Expand Down
11 changes: 9 additions & 2 deletions espefuse/efuse/esp32c5beta3/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,21 @@ def burn_key(esp, efuses, args, digest=None):
block = efuses.blocks[block_num]

if digest is None:
data = datafile.read()
if keypurpose == "ECDSA_KEY":
sk = espsecure.load_ecdsa_signing_key(datafile)
data = sk.to_string()
if len(data) == 24:
# the private key is 24 bytes long for NIST192p, and 8 bytes of padding
data = b"\x00" * 8 + data
else:
data = datafile.read()
else:
data = datafile

print(" - %s" % (efuse.name), end=" ")
revers_msg = None
if efuses[block.key_purpose_name].need_reverse(keypurpose):
revers_msg = "\tReversing byte order for AES-XTS hardware peripheral"
revers_msg = f"\tReversing byte order for {keypurpose} hardware peripheral"
data = data[::-1]
print(
"-> [{}]".format(
Expand Down
3 changes: 2 additions & 1 deletion espefuse/efuse/esp32c61/mem_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# SPDX-License-Identifier: GPL-2.0-or-later

import os
from typing import List

import yaml

Expand Down Expand Up @@ -119,7 +120,7 @@ def __init__(self) -> None:
# if BLK_VERSION_MINOR is 1, these efuse fields are in BLOCK2
self.BLOCK2_CALIBRATION_EFUSES = []

self.CALC = []
self.CALC: List = []

dir_name = os.path.dirname(os.path.abspath(__file__))
dir_name, file_name = os.path.split(dir_name)
Expand Down
2 changes: 1 addition & 1 deletion espefuse/efuse/esp32c61/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def burn_key(esp, efuses, args, digest=None):

if digest is None:
if keypurpose == "ECDSA_KEY":
sk = espsecure._load_ecdsa_signing_key(datafile)
sk = espsecure.load_ecdsa_signing_key(datafile)
data = sk.to_string()
if len(data) == 24:
# the private key is 24 bytes long for NIST192p, and 8 bytes of padding
Expand Down
3 changes: 2 additions & 1 deletion espefuse/efuse/esp32h2beta1/mem_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import yaml

from ..mem_definition_base import EfuseBlocksBase, EfuseFieldsBase, EfuseRegistersBase
from typing import List


class EfuseDefineRegisters(EfuseRegistersBase):
Expand Down Expand Up @@ -115,7 +116,7 @@ def __init__(self) -> None:
# if BLK_VERSION_MAJOR is 1, these efuse fields are in BLOCK2
self.BLOCK2_CALIBRATION_EFUSES = []

self.CALC = []
self.CALC: List = []

dir_name = os.path.dirname(os.path.abspath(__file__))
dir_name, file_name = os.path.split(dir_name)
Expand Down
3 changes: 2 additions & 1 deletion espefuse/efuse/esp32p4/mem_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
EfuseFieldsBase,
EfuseRegistersBase,
)
from typing import List


class EfuseDefineRegisters(EfuseRegistersBase):
Expand Down Expand Up @@ -119,7 +120,7 @@ def __init__(self) -> None:
# if BLK_VERSION_MINOR is 1, these efuse fields are in BLOCK2
self.BLOCK2_CALIBRATION_EFUSES = []

self.CALC = []
self.CALC: List = []

dir_name = os.path.dirname(os.path.abspath(__file__))
dir_name, file_name = os.path.split(dir_name)
Expand Down
9 changes: 5 additions & 4 deletions espefuse/efuse/mem_definition_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# SPDX-License-Identifier: GPL-2.0-or-later

from collections import namedtuple
from typing import Optional, List


class EfuseRegistersBase(object):
Expand All @@ -19,9 +20,9 @@ class EfuseRegistersBase(object):


class EfuseBlocksBase(object):
BLOCKS = None
BLOCKS: Optional[List] = None
NamedtupleBlock = namedtuple(
"Block",
"NamedtupleBlock",
"name alias id rd_addr wr_addr write_disable_bit "
"read_disable_bit len key_purpose",
)
Expand Down Expand Up @@ -49,7 +50,7 @@ class Field:
word = None
pos = None
bit_len = 0
alt_names = []
alt_names: List[str] = []
type = ""
write_disable_bit = None
read_disable_bit = None
Expand All @@ -61,7 +62,7 @@ class Field:

class EfuseFieldsBase(object):
def __init__(self, e_desc) -> None:
self.ALL_EFUSES = []
self.ALL_EFUSES: List = []

def set_category_and_class_type(efuse, name):
def includes(name, names):
Expand Down
4 changes: 2 additions & 2 deletions esptool/bin_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import re
import struct
import tempfile
from typing import BinaryIO, Optional
from typing import IO, Optional

from esptool.intelhex import HexRecordError, IntelHex

Expand Down Expand Up @@ -43,7 +43,7 @@ def align_file_position(f, size):
f.seek(align, 1)


def intel_hex_to_bin(file: BinaryIO, start_addr: Optional[int] = None) -> BinaryIO:
def intel_hex_to_bin(file: IO[bytes], start_addr: Optional[int] = None) -> IO[bytes]:
"""Convert IntelHex file to temp binary file with padding from start_addr
If hex file was detected return temp bin file object; input file otherwise"""
INTEL_HEX_MAGIC = b":"
Expand Down
6 changes: 5 additions & 1 deletion esptool/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import struct
import sys
import time
from typing import Optional


from .config import load_config_file
from .reset import (
Expand Down Expand Up @@ -59,7 +61,7 @@
print(
"The installed version (%s) of pyserial appears to be too old for esptool.py "
"(Python interpreter %s). Check the README for installation instructions."
% (sys.VERSION, sys.executable)
% (serial.VERSION, sys.executable)
)
raise
except Exception:
Expand Down Expand Up @@ -185,6 +187,8 @@ class ESPLoader(object):

CHIP_NAME = "Espressif device"
IS_STUB = False
STUB_CLASS: Optional[object] = None
BOOTLOADER_IMAGE: Optional[object] = None

DEFAULT_PORT = "/dev/ttyUSB0"

Expand Down
4 changes: 3 additions & 1 deletion esptool/targets/esp32h2beta1.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from .esp32c3 import ESP32C3ROM
from ..util import FatalError, NotImplementedInROMError

from typing import List


class ESP32H2BETA1ROM(ESP32C3ROM):
CHIP_NAME = "ESP32-H2(beta1)"
Expand Down Expand Up @@ -66,7 +68,7 @@ class ESP32H2BETA1ROM(ESP32C3ROM):

FLASH_ENCRYPTED_WRITE_ALIGN = 16

MEMORY_MAP = []
MEMORY_MAP: List = []

FLASH_FREQUENCY = {
"48m": 0xF,
Expand Down
Loading

0 comments on commit f849d1d

Please sign in to comment.