diff --git a/components/esp_rom/README.md b/components/esp_rom/README.md index 7249c63301..0fdf37b098 100644 --- a/components/esp_rom/README.md +++ b/components/esp_rom/README.md @@ -73,4 +73,26 @@ As ROM functions are unique to each target, features are as well. For example, E ├── CMakeLists.txt ├── test_miniz.c └── ... // other ROM function unit tests -``` \ No newline at end of file +``` + +## Adding New Chip Support For Debugging + +1. Dump .rodata strings via `riscv32-esp-elf-readelf -p .rodata esp32c5_rev0_rom.elf` +2. Locate the build date in the output (e.g. `[ 23c4] Mar 29 2024`). +3. Get start address of .rodata section via `riscv32-esp-elf-readelf -S esp32c5_rev0_rom.elf | grep rodata` +4. Compute the absolute address by adding the offset from step 2 to the base address from step 3. +5. Verify with GDB: + ``` + riscv32-esp-elf-gdb esp32c5_rev0_rom.elf -ex "p (char*) 0x4004b3c4" --batch + $1 = 0x4004b3c4 "Mar 29 2024" + ``` +6. Update roms.json: + ``` + "esp32c5": [ + { + "rev": 0, + "build_date_str_addr": "0x4004b3c4", + "build_date_str": "Mar 29 2024" + } + ], + ``` diff --git a/components/esp_rom/gen_gdbinit.py b/components/esp_rom/gen_gdbinit.py index 652798005f..6e8d2b0007 100644 --- a/components/esp_rom/gen_gdbinit.py +++ b/components/esp_rom/gen_gdbinit.py @@ -7,8 +7,7 @@ import os import sys from textwrap import indent -IDF_PATH = os.getenv('IDF_PATH', '') -ROMS_JSON = os.path.join(IDF_PATH, 'tools', 'idf_py_actions', 'roms.json') # type: ignore +ROMS_JSON = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'roms.json') # Direct string extraction and comparison is not feasible due to: @@ -20,7 +19,7 @@ ROMS_JSON = os.path.join(IDF_PATH, 'tools', 'idf_py_actions', 'roms.json') # ty def get_rom_if_condition_str(date_addr: int, date_str: str) -> str: r = [] for i in range(0, len(date_str), 4): - value = hex(int.from_bytes(bytes(date_str[i:i + 4], 'utf-8'), 'little')) + value = hex(int.from_bytes(bytes(date_str[i : i + 4], 'utf-8'), 'little')) r.append(f'(*(int*) {hex(date_addr + i)}) == {value}') return 'if ' + ' && '.join(r) @@ -29,12 +28,13 @@ def generate_gdbinit_rom_add_symbols(target: str) -> str: base_ident = ' ' rom_elfs_dir = os.getenv('ESP_ROM_ELF_DIR') if not rom_elfs_dir: - raise EnvironmentError( - 'ESP_ROM_ELF_DIR environment variable is not defined. Please try to run IDF "install" and "export" scripts.') + raise OSError( + 'ESP_ROM_ELF_DIR environment variable is not defined. Please try to run IDF "install" and "export" scripts.' + ) if os.name == 'nt': # convert to posix-path for windows rom_elfs_dir = rom_elfs_dir.replace('\\', '/') - with open(ROMS_JSON, 'r') as f: + with open(ROMS_JSON) as f: roms = json.load(f) if target not in roms: msg_body = f'Warning: ROM ELF is not supported yet for "{target}".' # noqa: E713 diff --git a/tools/idf_py_actions/roms.json b/components/esp_rom/roms.json similarity index 100% rename from tools/idf_py_actions/roms.json rename to components/esp_rom/roms.json diff --git a/tools/idf_py_actions/roms_schema.json b/components/esp_rom/roms_schema.json similarity index 100% rename from tools/idf_py_actions/roms_schema.json rename to components/esp_rom/roms_schema.json diff --git a/components/esp_rom/test_esp_rom.py b/components/esp_rom/test_esp_rom.py index c59ec40f45..ab9e1f9018 100644 --- a/components/esp_rom/test_esp_rom.py +++ b/components/esp_rom/test_esp_rom.py @@ -9,22 +9,21 @@ import jsonschema from elftools.elf.elffile import ELFFile from idf_build_apps.constants import SUPPORTED_TARGETS -IDF_PATH = os.getenv('IDF_PATH', '') -ROMS_JSON = os.path.join(IDF_PATH, 'tools', 'idf_py_actions', 'roms.json') # type: ignore +ROMS_JSON = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'roms.json') def test_roms_validate_json() -> None: - with open(ROMS_JSON, 'r') as f: + with open(ROMS_JSON) as f: roms_json = json.load(f) json_schema_path = os.path.join(os.path.dirname(ROMS_JSON), 'roms_schema.json') - with open(json_schema_path, 'r') as f: + with open(json_schema_path) as f: schema_json = json.load(f) jsonschema.validate(roms_json, schema_json) def test_roms_check_supported_chips() -> None: - with open(ROMS_JSON, 'r') as f: + with open(ROMS_JSON) as f: roms_json = json.load(f) for chip in SUPPORTED_TARGETS: assert chip in roms_json, f'Have no ROM data for chip {chip}' @@ -43,7 +42,7 @@ def test_roms_validate_build_date() -> None: return result rom_elfs_dir = os.getenv('ESP_ROM_ELF_DIR', '') - with open(ROMS_JSON, 'r') as f: + with open(ROMS_JSON) as f: roms_json = json.load(f) for chip in roms_json: