Running idf.py size-components while using idf_as_lib

uday.sriranga
Posts: 4
Joined: Fri Apr 12, 2024 2:19 pm

Running idf.py size-components while using idf_as_lib

Postby uday.sriranga » Fri Apr 12, 2024 2:30 pm

Hi
I'm using the example code provided here (https://github.com/espressif/esp-idf/tr ... idf_as_lib) to build my application.
After building I want to run idf.py size , idf.py size-components. Both of them return error.

Code: Select all

udayms@pc:~/esp/esp-idf-v5.1.1/examples/build_system/cmake/idf_as_lib ((no branch))$ idf.py size-components 
Executing action: size-components
Running ninja in directory /home/udayms/esp/esp-idf-v5.1.1/examples/build_system/cmake/idf_as_lib/build
Executing "ninja all"...
[1/4] cd /home/udayms/esp/esp-idf-v5.1.1/examples/build_system/cmake/idf_as_lib/build/esp-idf/esptool_py && /home/uda...table/partition-table.bin /home/udayms/esp/esp-idf-v5.1.1/examples/build_system/cmake/idf_as_lib/build/idf_as_lib.binidf_as_lib.bin binary size 0x22fc0 bytes. Smallest app partition is 0x100000 bytes. 0xdd040 bytes (86%) free.
[1/1] cd /home/udayms/esp/esp-idf-v5.1.1/examples/build_system/cmake/idf_as_lib/build/bootloader/esp-idf/esptool_py &...bootloader 0x0 /home/udayms/esp/esp-idf-v5.1.1/examples/build_system/cmake/idf_as_lib/build/bootloader/bootloader.binBootloader binary size 0x5040 bytes. 0x2fc0 bytes (37%) free.
Running ninja in directory /home/udayms/esp/esp-idf-v5.1.1/examples/build_system/cmake/idf_as_lib/build
Executing "ninja size-components"...
ninja: error: unknown target 'size-components'
I did look into other example and figured out that '.map' file is needed.
As I'm new to CMake , I couldn't generate the .map file even after spending couple of hours on it.

It would be helpful if someone guide me to generate .map file or provide steps to enable idf.py size-components

uday.sriranga
Posts: 4
Joined: Fri Apr 12, 2024 2:19 pm

Re: Running idf.py size-components while using idf_as_lib

Postby uday.sriranga » Fri Apr 12, 2024 3:39 pm

I was able to generate a map file with following additions

Code: Select all

set(idf_size ${python} -m esp_idf_size)
set(mapfile "${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}.map")
target_link_options(${elf_file} PRIVATE "-Wl,--Map=${mapfile}")
and enable size-components command by

Code: Select all

add_custom_target(size-components
    COMMAND ${CMAKE_COMMAND}
    -D "IDF_SIZE_TOOL=${idf_size}"
    -D "IDF_SIZE_MODE=--archives"
    -D "MAP_FILE=${mapfile}"
    -D "OUTPUT_JSON=${OUTPUT_JSON}"
    -P "${idf_path}/tools/cmake/run_size_tool.cmake"
    DEPENDS ${mapfile}
    USES_TERMINAL
    VERBATIM
)
Now I got a new error

Executing "ninja size-components"...
[0/1] cd /u/tmp/bluefi/build && /usr/bin/cmake -D "IDF_SIZE_TOOL=/home/udayms/.espressif/python_env/idf5.1_py3.8_env/bin/python;-m;esp_idf_size" -D IDF_SIZE_MODE=--archives -D MAP_FILE=/u/tmp/bluefi/build/bluefi.map -D OUTPUT_JSON= -P /home/udayms/esp/esp-idf-v5.1.1/tools/cmake/run_size_tool.cmake
Traceback (most recent call last):
File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/home/udayms/.espressif/python_env/idf5.1_py3.8_env/lib/python3.8/site-packages/esp_idf_size/__main__.py", line 4, in <module>
main()
File "/home/udayms/.espressif/python_env/idf5.1_py3.8_env/lib/python3.8/site-packages/esp_idf_size/core.py", line 513, in main
detected_target, segments, sections = load_map_data(args.map_file)
File "/home/udayms/.espressif/python_env/idf5.1_py3.8_env/lib/python3.8/site-packages/esp_idf_size/core.py", line 237, in load_map_data
detected_chip = detect_target_chip(map_file)
File "/home/udayms/.espressif/python_env/idf5.1_py3.8_env/lib/python3.8/site-packages/esp_idf_size/core.py", line 301, in detect_target_chip
raise RuntimeError('Target not detected')
RuntimeError: Target not detected
CMake Error at /home/udayms/esp/esp-idf-v5.1.1/tools/cmake/run_size_tool.cmake:42 (message):

/home/udayms/.espressif/python_env/idf5.1_py3.8_env/bin/python;-m;esp_idf_size
failed


FAILED: CMakeFiles/size-components
cd /u/tmp/bluefi/build && /usr/bin/cmake -D "IDF_SIZE_TOOL=/home/udayms/.espressif/python_env/idf5.1_py3.8_env/bin/python;-m;esp_idf_size" -D IDF_SIZE_MODE=--archives -D MAP_FILE=/u/tmp/bluefi/build/bluefi.map -D OUTPUT_JSON= -P /home/udayms/esp/esp-idf-v5.1.1/tools/cmake/run_size_tool.cmake
ninja: build stopped: subcommand failed.

User avatar
ESP_Roland
Posts: 265
Joined: Tue Oct 09, 2018 10:28 am

Re: Running idf.py size-components while using idf_as_lib

Postby ESP_Roland » Mon Apr 15, 2024 6:06 am

Perhaps this is what you are missing:

Code: Select all

        # Add this symbol as a hint for esp_idf_size to guess the target name
        target_link_options(${project_elf} PRIVATE "-Wl,--defsym=IDF_TARGET_${idf_target}=0")

uday.sriranga
Posts: 4
Joined: Fri Apr 12, 2024 2:19 pm

Re: Running idf.py size-components while using idf_as_lib

Postby uday.sriranga » Tue Apr 16, 2024 4:46 am

Thanks ESP_Roland
This solved my issue

Who is online

Users browsing this forum: No registered users and 97 guests