summaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
Diffstat (limited to 'hw')
-rw-r--r--hw/bsp/family_support.cmake90
-rw-r--r--hw/bsp/rp2040/family.cmake3
2 files changed, 92 insertions, 1 deletions
diff --git a/hw/bsp/family_support.cmake b/hw/bsp/family_support.cmake
index ad9a4f94d..0130fb656 100644
--- a/hw/bsp/family_support.cmake
+++ b/hw/bsp/family_support.cmake
@@ -267,6 +267,95 @@ function(family_add_linkermap TARGET)
VERBATIM)
endfunction()
+# Add membrowse target (installed with pip install membrowse)
+function(family_add_membrowse TARGET)
+ find_program(MEMBROWSE_EXE membrowse)
+ if (MEMBROWSE_EXE STREQUAL MEMBROWSE_EXE-NOTFOUND)
+ # force anyway, bash login shell will find it from pip install path
+ set(MEMBROWSE_EXE membrowse)
+ endif ()
+
+ set(OPTION "")
+ if (DEFINED MEMBROWSE_OPTION)
+ string(APPEND OPTION " ${MEMBROWSE_OPTION}")
+ endif ()
+
+ # For Ninja generator, extract all linker scripts from Ninja commands (with INCLUDE) and pass them to membrowse.
+ if (CMAKE_GENERATOR MATCHES "Ninja")
+ set(TARGET_ELF_PATH "$<TARGET_FILE_DIR:${TARGET}>/$<TARGET_FILE_NAME:${TARGET}>")
+ set(MEMBROWSE_LD_SCRIPTS_CMD
+ "ld_scripts=\"$(${CMAKE_MAKE_PROGRAM} -C ${CMAKE_BINARY_DIR} -t commands ${TARGET} | grep -oP '(?:-Wl,--script=|-T\\s*)\\K[A-Za-z0-9_./-]+\\.ld' | xargs)\"; \
+all_ld_scripts=\"\"; \
+pending_ld_scripts=\"$ld_scripts\"; \
+while [ -n \"$pending_ld_scripts\" ]; do \
+ next_pending=\"\"; \
+ for script in $pending_ld_scripts; do \
+ case \" $all_ld_scripts \" in *\" $script \"*) continue ;; esac; \
+ all_ld_scripts=\"$all_ld_scripts $script\"; \
+ script_dir=$(dirname \"$script\"); \
+ include_scripts=$(grep -hoP '^\\s*INCLUDE\\s+[<\"]?\\K[^\">[:space:]]+\\.ld' \"$script\" 2>/dev/null | xargs); \
+ for include_script in $include_scripts; do \
+ resolved_script=\"\"; \
+ if [ -f \"$include_script\" ]; then \
+ resolved_script=\"$include_script\"; \
+ elif [ -f \"$script_dir/$include_script\" ]; then \
+ resolved_script=\"$script_dir/$include_script\"; \
+ fi; \
+ if [ -n \"$resolved_script\" ]; then \
+ case \" $all_ld_scripts $next_pending \" in *\" $resolved_script \"*) ;; *) next_pending=\"$next_pending $resolved_script\" ;; esac; \
+ fi; \
+ done; \
+ done; \
+ pending_ld_scripts=\"$(echo \"$next_pending\" | xargs)\"; \
+done; \
+ld_scripts=\"$(echo \"$all_ld_scripts\" | xargs)\"")
+ set(MEMBROWSE_LD_DEFS_CMD
+ "ld_symbols=\"$(${CMAKE_MAKE_PROGRAM} -C ${CMAKE_BINARY_DIR} -t commands ${TARGET} | grep -oP '(?<=-Wl,--defsym=)[^[:space:]]+' | xargs)\"; \
+ld_defs=\"\"; \
+for symbol in $ld_symbols; do \
+ ld_defs=\"$ld_defs --def $symbol\"; \
+done; \
+ld_defs=\"$(echo \"$ld_defs\" | xargs)\"")
+ set(MEMBROWSE_PREPARE_CMD
+ "if [ -f \"${TARGET_ELF_PATH}\" ]; then \
+ ${MEMBROWSE_LD_SCRIPTS_CMD}; \
+ ${MEMBROWSE_LD_DEFS_CMD}; \
+ if [ \"$MEMBROWSE_UPLOAD\" = \"1\" ]; then \
+ MEMBROWSE_CMD=\"${MEMBROWSE_EXE} report ${OPTION} \\\"${TARGET_ELF_PATH}\\\" \\\"$ld_scripts\\\" $ld_defs --upload --github --target-name ${FAMILY}/${BOARD}/${TARGET} --api-key $ENV{MEMBROWSE_API_KEY}\"; \
+ else \
+ MEMBROWSE_CMD=\"${MEMBROWSE_EXE} report ${OPTION} \\\"${TARGET_ELF_PATH}\\\" \\\"$ld_scripts\\\" $ld_defs\"; \
+ fi; \
+else \
+ if [ \"$MEMBROWSE_UPLOAD\" = \"1\" ]; then \
+ MEMBROWSE_CMD=\"${MEMBROWSE_EXE} report ${OPTION} --identical --upload --github --target-name ${FAMILY}/${BOARD}/${TARGET} --api-key $ENV{MEMBROWSE_API_KEY}\"; \
+ else \
+ MEMBROWSE_CMD=\"${MEMBROWSE_EXE} report ${OPTION} --identical\"; \
+ fi; \
+fi; \
+echo \"$MEMBROWSE_CMD\"")
+
+ add_custom_target(${TARGET}-membrowse
+ DEPENDS ${TARGET}
+ COMMAND ${CMAKE_COMMAND} -E env MEMBROWSE_UPLOAD=0 bash -lc "${MEMBROWSE_PREPARE_CMD}; eval \"$MEMBROWSE_CMD\""
+ VERBATIM
+ )
+ set_property(TARGET ${TARGET}-membrowse PROPERTY FOLDER ${TARGET})
+
+ add_custom_target(${TARGET}-membrowse-upload
+ COMMAND ${CMAKE_COMMAND} -E env MEMBROWSE_UPLOAD=1 bash -lc "${MEMBROWSE_PREPARE_CMD}; eval \"$MEMBROWSE_CMD\""
+ VERBATIM
+ )
+
+ if (NOT TARGET examples-membrowse-upload)
+ add_custom_target(examples-membrowse-upload)
+ endif ()
+ add_dependencies(examples-membrowse-upload ${TARGET}-membrowse-upload)
+
+ set_property(TARGET ${TARGET}-membrowse-upload PROPERTY FOLDER ${TARGET})
+ endif ()
+endfunction()
+
+
#-------------------------------------------------------------
# Common Target Configure
# Most families use these settings except rp2040 and espressif
@@ -380,6 +469,7 @@ function(family_configure_common TARGET RTOS)
# Analyze size with bloaty and linkermap
family_add_bloaty(${TARGET})
family_add_linkermap(${TARGET})
+ family_add_membrowse(${TARGET})
endif ()
# run size after build
diff --git a/hw/bsp/rp2040/family.cmake b/hw/bsp/rp2040/family.cmake
index e617ab3ca..82d0034a1 100644
--- a/hw/bsp/rp2040/family.cmake
+++ b/hw/bsp/rp2040/family.cmake
@@ -250,9 +250,10 @@ function(family_configure_target TARGET RTOS)
family_flash_openocd(${TARGET})
family_flash_jlink(${TARGET})
- # Generate linkermap target and post build. LINKERMAP_OPTION can be set with -D to change default options
+ # Generate linkermap target and post build. LINKERMAP_OPTION can be set with -D to change default options
family_add_bloaty(${TARGET})
family_add_linkermap(${TARGET})
+ family_add_membrowse(${TARGET})
endfunction()