|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# Copyright (c) Arduino s.r.l. and/or its affiliated companies |
| 4 | +# SPDX-License-Identifier: Apache-2.0 |
| 5 | +# |
| 6 | +# Wrapper for arm-zephyr-eabi-size that dynamically adjusts section |
| 7 | +# accounting based on CONFIG_LLEXT_RODATA_NO_RELOC. |
| 8 | +# |
| 9 | +# When CONFIG_LLEXT_RODATA_NO_RELOC=y (in loader/prj.conf or variant .conf): |
| 10 | +# .llext.rodata.noreloc stays in flash -> rename to .flash.llext.* so |
| 11 | +# regex.data won't count it against the LLEXT heap limit. |
| 12 | +# |
| 13 | +# When CONFIG_LLEXT_RODATA_NO_RELOC=n or unset: |
| 14 | +# .llext.rodata.noreloc is copied to LLEXT heap -> keep the name so |
| 15 | +# regex.data counts it against the heap limit. |
| 16 | +# |
| 17 | +# Usage (from platform.txt): |
| 18 | +# recipe.size.pattern=bash "{runtime.platform.path}/extra/check_size.sh" |
| 19 | +# "{compiler.path}{compiler.size.cmd}" "{build.path}/{build.project_name}.elf" |
| 20 | +# "{build.variant.path}" |
| 21 | +# |
| 22 | + |
| 23 | +SIZE_CMD="$1" |
| 24 | +ELF="$2" |
| 25 | +VARIANT_DIR="$3" |
| 26 | + |
| 27 | +output=$("$SIZE_CMD" -A "$ELF") |
| 28 | + |
| 29 | +# Check if RODATA_NO_RELOC is enabled in the loader or variant config. |
| 30 | +# The loader's prj.conf is two levels up from the variant dir (in the |
| 31 | +# platform root), but we also check the variant-specific .conf. |
| 32 | +PLATFORM_DIR=$(dirname "$(dirname "$VARIANT_DIR")") |
| 33 | +rodata_no_reloc=false |
| 34 | +for conf in "$PLATFORM_DIR/loader/prj.conf" "$VARIANT_DIR"/*.conf; do |
| 35 | + if [ -f "$conf" ] && grep -q "^CONFIG_LLEXT_RODATA_NO_RELOC=y" "$conf" 2>/dev/null; then |
| 36 | + rodata_no_reloc=true |
| 37 | + break |
| 38 | + fi |
| 39 | +done |
| 40 | + |
| 41 | +if $rodata_no_reloc; then |
| 42 | + # Rename .llext.* -> .flash.llext.* so regex.data won't match, |
| 43 | + # but regex (flash/program space) still matches via .flash.llext. |
| 44 | + echo "$output" | sed 's/^\.llext\./.flash.llext./' |
| 45 | +else |
| 46 | + echo "$output" |
| 47 | +fi |
0 commit comments