Skip to content

Commit 62155f4

Browse files
committed
platform: calculate sketch size with NO_RELOC support
Signed-off-by: Gilberto Conti <g.conti@arduino.cc>
1 parent 020684c commit 62155f4

3 files changed

Lines changed: 54 additions & 3 deletions

File tree

extra/artifacts/_common.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ doc/
1616
cores/
1717
libraries/
1818
variants/_ldscripts/
19+
extra/check_size.sh

extra/check_size.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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

platform.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,12 @@ recipe.hooks.objcopy.postobjcopy.1.pattern="{runtime.tools.zephyr-sketch-tool.pa
143143
recipe.hooks.objcopy.postobjcopy.2.pattern="{runtime.tools.zephyr-sketch-tool.path}/zephyr-sketch-tool" {build.zsk_args.debug} {build.zsk_args.mode-{build.link_mode}} {build.zsk_args.startup-mode-{build.boot_mode}} "{build.path}/{build.project_name}.bin"
144144

145145
## Compute size
146-
recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf"
147-
recipe.size.regex.data=^(?:\.data|\.bss)\s+([0-9]+).*
148-
recipe.size.regex=^(?:\.data|\.text|\.rodata)\S*?\s+([0-9]+).*
146+
## Uses check_size.sh wrapper to dynamically handle CONFIG_LLEXT_RODATA_NO_RELOC:
147+
## When =y, .llext.* sections stay in flash (renamed to .flash.llext.* so regex.data skips them).
148+
## When =n, .llext.* sections are copied to LLEXT heap (counted by regex.data).
149+
recipe.size.pattern=bash "{runtime.platform.path}/extra/check_size.sh" "{compiler.path}{compiler.size.cmd}" "{build.path}/{build.project_name}.elf" "{build.variant.path}"
150+
recipe.size.regex.data=^(?:\.data|\.bss|\.text|\.rodata|\.llext\.)\S*?\s+([0-9]+).*
151+
recipe.size.regex=^(?:\.data|\.text|\.rodata|\.llext\.|\.flash\.llext\.)\S*?\s+([0-9]+).*
149152

150153
## Save output file
151154
recipe.output.tmp_file={build.project_name}.{upload.extension}

0 commit comments

Comments
 (0)