From b52c764bf39174c6c89baaeb34bec488ee7804f0 Mon Sep 17 00:00:00 2001 From: "Michael (XIAO Xufeng)" Date: Fri, 30 Oct 2020 13:44:24 +0800 Subject: [PATCH] idf_size.py: add support for esp32c3 and risc-v --- tools/cmake/project.cmake | 8 ++++---- tools/find_build_apps/common.py | 1 - tools/idf_size.py | 25 ++++++++++++++++++++++--- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/tools/cmake/project.cmake b/tools/cmake/project.cmake index c7342be51b..8b47268f54 100644 --- a/tools/cmake/project.cmake +++ b/tools/cmake/project.cmake @@ -430,9 +430,9 @@ macro(project project_name) set(project_elf ${CMAKE_PROJECT_NAME}.elf) - # Create a dummy file to work around CMake requirement of having a source - # file while adding an executable - set(project_elf_src ${CMAKE_BINARY_DIR}/project_elf_src.c) + # Create a dummy file to work around CMake requirement of having a source file while adding an + # executable. This is also used by idf_size.py to detect the target + set(project_elf_src ${CMAKE_BINARY_DIR}/project_elf_src_${IDF_TARGET}.c) add_custom_command(OUTPUT ${project_elf_src} COMMAND ${CMAKE_COMMAND} -E touch ${project_elf_src} VERBATIM) @@ -470,7 +470,7 @@ macro(project project_name) idf_build_get_property(idf_path IDF_PATH) idf_build_get_property(python PYTHON) - set(idf_size ${python} ${idf_path}/tools/idf_size.py --target ${IDF_TARGET}) + set(idf_size ${python} ${idf_path}/tools/idf_size.py) if(DEFINED OUTPUT_JSON AND OUTPUT_JSON) list(APPEND idf_size "--json") endif() diff --git a/tools/find_build_apps/common.py b/tools/find_build_apps/common.py index 6f3feea0bd..51368c5ce8 100644 --- a/tools/find_build_apps/common.py +++ b/tools/find_build_apps/common.py @@ -264,7 +264,6 @@ class BuildItem(object): sys.executable, IDF_SIZE_PY, '--json', - '--target', self.target, '-o', size_json_fp, map_file ] diff --git a/tools/idf_size.py b/tools/idf_size.py index a4fc173a60..76625780e4 100755 --- a/tools/idf_size.py +++ b/tools/idf_size.py @@ -128,6 +128,17 @@ class MemRegions(object): return sorted([ MemRegDef(0x3FC88000, 0x8000 + 6 * 0x10000, MemRegions.DIRAM_ID, 0x40378000), ]) + elif target == 'esp32c3': + return sorted([ + MemRegDef(0x3FC80000, 0x60000, MemRegions.DIRAM_ID, 0x40380000), + + # MemRegDef(0x3FC80000, 0x20000, MemRegions.DIRAM_ID, 0x40380000), + # MemRegDef(0x3FCA0000, 0x20000, MemRegions.DIRAM_ID, 0x403A0000), + # MemRegDef(0x3FCC0000, 0x20000, MemRegions.DIRAM_ID, 0x403C0000), + + # Used by cache + MemRegDef(0x4037C000, 0x4000, MemRegions.IRAM_ID, 0), + ]) else: return None @@ -212,22 +223,30 @@ def load_memory_config(map_file): def detect_target_chip(map_file): - ''' Detect target chip based on the xtensa toolchain name in in the linker script part of the MAP file ''' + ''' Detect target chip based on the target archive name in the linker script part of the MAP file ''' scan_to_header(map_file, 'Linker script and memory map') - RE_TARGET = re.compile(r'^LOAD .*?/xtensa-([^-]+)-elf/') + RE_TARGET = re.compile(r'project_elf_src_(.*)\.c.obj') + # For back-compatible with make + RE_TARGET_MAKE = re.compile(r'^LOAD .*?/xtensa-([^-]+)-elf/') for line in map_file: m = RE_TARGET.search(line) if m: return m.group(1) + + m = RE_TARGET_MAKE.search(line) + if m: + return m.group(1) + line = line.strip() # There could be empty line(s) between the "Linker script and memory map" header and "LOAD lines". Therefore, # line stripping and length is checked as well. The "LOAD lines" are between START GROUP and END GROUP for # older MAP files. - if not line.startswith(('LOAD', 'START GROUP')) and len(line) > 0: + if not line.startswith(('LOAD', 'START GROUP', 'END GROUP')) and len(line) > 0: # This break is a failsafe to not process anything load_sections() might want to analyze. break + return None