Skip to content

Commit 3b15c40

Browse files
committed
fix: report proper sketch and loader sizes in CI packaging
1 parent d9d997e commit 3b15c40

5 files changed

Lines changed: 38 additions & 4 deletions

File tree

.github/workflows/package_core.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,15 @@ jobs:
117117
grep -i "warning:" $REPORT.stdout > $REPORT.warnings || true
118118
119119
# extract the memory usage table (from the header to the first non-% line)
120+
# override the size of the Flash with the size of the loader partition
121+
# and add the size of the sketch partition (not reported by Zephyr)
122+
LOADER_SIZE=$(( $(cat variants/${{ matrix.variant }}/syms-static.ld | grep '_loader_max_size' | cut -d '=' -f 2 | tr -d ') ;') ))
123+
SKETCH_SIZE=$(( $(cat variants/${{ matrix.variant }}/syms-static.ld | grep '_sketch_max_size' | cut -d '=' -f 2 | tr -d ') ;') ))
120124
cat $REPORT.stdout | sed -n '/^Memory region/,/^[^%]*$/p' | head -n -1 \
121125
| awk 'BEGIN {split("B KB MB GB", u); for(i in u) m[u[i]]=1024^(i-1)} /:/ {print "[\"" $1 "\"," $2*m[$3] "," $4*m[$5] "]"}' \
122-
| sort | jq -s > $REPORT.meminfo
126+
| sort \
127+
| jq -s "map((select(.[0] == \"FLASH:\") | .[2]) |= ${LOADER_SIZE}) + [ [ \"SKETCH:\", 0, ${SKETCH_SIZE} ] ]" > $REPORT.meminfo
128+
jq
123129
124130
- name: Package board artifacts
125131
if: ${{ !cancelled() }}

extra/build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ extra/gen_provides.py "${BUILD_DIR}/zephyr/zephyr.elf" -LF \
106106
"+kheap__system_heap" \
107107
"*sketch_base_addr=_sketch_start" \
108108
"*sketch_max_size=_sketch_max_size" \
109+
"*loader_max_size=_loader_max_size" \
109110
"malloc=__wrap_malloc" \
110111
"free=__wrap_free" \
111112
"realloc=__wrap_realloc" \

extra/ci_inspect_logs.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ def print_mem_report(artifact, artifact_boards):
412412
f_print("<th rowspan='2'>SoC</th>", end='')
413413
f_print("<th rowspan='2'>FLASH</th>", end='')
414414
f_print("<th rowspan='2'>RAM</th>", end='')
415+
f_print("<th rowspan='2'>User<br>sketch</th>", end='')
415416
f_print("<th colspan='2'>User heaps</th>", end='')
416417
f_print("<th colspan='2'>OS heaps</th>", end='')
417418
f_print("</tr>")
@@ -428,14 +429,15 @@ def print_mem_report(artifact, artifact_boards):
428429
f"<code>{soc}</code>",
429430
color_entry(BOARD_LOADERS[board].meminfo['FLASH']),
430431
color_entry(BOARD_LOADERS[board].meminfo['RAM']),
432+
f"${{{ BOARD_LOADERS[board].meminfo['SKETCH'][1] }}}$",
431433
f"${{{ BOARD_LOADERS[board].config.get('CONFIG_HEAP_MEM_POOL_SIZE', 0) }}}$",
432434
f"${{{ BOARD_LOADERS[board].config['CONFIG_SRAM_SIZE']*1024 - BOARD_LOADERS[board].meminfo['RAM'][0] }}}$",
433435
f"${{{ BOARD_LOADERS[board].config['CONFIG_LLEXT_HEAP_SIZE']*1024 }}}$",
434436
f"${{{ BOARD_LOADERS[board].config.get('CONFIG_MBEDTLS_HEAP_SIZE', '-') }}}$"
435437
]
436438

437439
f_print("<tr>")
438-
col_aligns = ['center', 'left', 'center', 'right', 'right', 'right', 'right', 'right', 'right']
440+
col_aligns = ['center', 'left', 'center', 'right', 'right', 'right', 'right', 'right', 'right', 'right']
439441
for index, cell in enumerate(row):
440442
f_print(f"<td align='{col_aligns[index]}'>\n\n{cell}\n\n</td>")
441443
f_print("</tr>")
@@ -444,7 +446,7 @@ def print_mem_report(artifact, artifact_boards):
444446
extra_data_present = False
445447
for soc in sorted(list(set([ ALL_BOARD_DATA[board]['soc'] for board in artifact_boards ]))):
446448
soc_boards = [ board for board in artifact_boards if ALL_BOARD_DATA[board]['soc'] == soc ]
447-
sorted_regions = sorted(r for r in REGIONS_BY_SOC[soc] if r not in ('FLASH', 'RAM'))
449+
sorted_regions = sorted(r for r in REGIONS_BY_SOC[soc] if r not in ('FLASH', 'RAM', 'SKETCH'))
448450
if not sorted_regions:
449451
continue
450452

extra/package_core.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,24 @@ for board in $EXCLUDED_BOARDS ; do
4949
# remove (even commented) lines for excluded boards
5050
sed -i "/^\(\s*#\s*\)\?${board}\./d" $TEMP_BOARDS
5151
done
52+
# set proper maximum sizes for included variants
53+
for variant in $INCLUDED_VARIANTS ; do
54+
board=$(echo ${BOARD_DETAILS} | jq -cr "map(select(.variant == \"${variant}\")) | .[0].board")
55+
# maximum sketch size: size of sketch partition (exact limit)
56+
# maximum data size: configured LLEXT heap size (larger bound, real limit is smaller)
57+
CODE_SIZE=$(( $(cat variants/${variant}/syms-static.ld | grep '_sketch_max_size' | cut -d '=' -f 2 | tr -d ');') ))
58+
DATA_SIZE=$(( 1024*$(cat firmwares/zephyr-${variant}.config | grep 'LLEXT_HEAP_SIZE' | cut -d '=' -f 2) ))
59+
sed -i -e "s/^${board}\.upload\.maximum_size=.*/${board}.upload.maximum_size=${CODE_SIZE}/" $TEMP_BOARDS
60+
sed -i -e "s/^${board}\.upload\.maximum_data_size=.*/${board}.upload.maximum_data_size=${DATA_SIZE}/" $TEMP_BOARDS
61+
done
5262
# remove multiple empty lines
5363
sed -i '/^$/N;/^\n$/D' $TEMP_BOARDS
5464

5565
# create a temporary platform.txt file with the correct version
5666
TEMP_PLATFORM=$(mktemp -p . | sed 's/\.\///')
5767
cat platform.txt > ${TEMP_PLATFORM}
5868
[ -z "$ARTIFACT_NAME" ] || sed -ie "s/^name=.*/name=${ARTIFACT_NAME}/" ${TEMP_PLATFORM}
59-
sed -ie "s/^version=.*/version=$(extra/get_core_version.sh)/" ${TEMP_PLATFORM}
69+
sed -i -e "s/^version=.*/version=$(extra/get_core_version.sh)/" ${TEMP_PLATFORM}
6070

6171
declutter_file() {
6272
# remove comments, whitespace at EOL, '/' dir terminators and empty lines

loader/main.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ LOG_MODULE_REGISTER(sketch);
2323
#include <zephyr/drivers/uart.h>
2424
#include <zephyr/usb/usb_device.h>
2525

26+
#include <zephyr/devicetree/fixed-partitions.h>
27+
2628
#define HEADER_LEN 16
2729

2830
struct sketch_header_v1 {
@@ -89,10 +91,23 @@ void llext_entry(void *arg0, void *arg1, void *arg2) {
8991
}
9092
#endif /* CONFIG_USERSPACE */
9193

94+
/* Export Flash parameters for use by core building scripts */
9295
__attribute__((retain)) const uintptr_t sketch_base_addr =
9396
DT_REG_ADDR(DT_GPARENT(DT_NODELABEL(user_sketch))) + DT_REG_ADDR(DT_NODELABEL(user_sketch));
9497
__attribute__((retain)) const uintptr_t sketch_max_size = DT_REG_SIZE(DT_NODELABEL(user_sketch));
9598

99+
#if DT_HAS_FIXED_PARTITION_LABEL(image_0)
100+
#define LOADER_MAX_SIZE DT_REG_SIZE(DT_NODE_BY_FIXED_PARTITION_LABEL(image_0))
101+
#elif CONFIG_FLASH_LOAD_SIZE > 0
102+
#define LOADER_MAX_SIZE CONFIG_FLASH_LOAD_SIZE
103+
#else
104+
#ifndef CONFIG_FLASH_LOAD_OFFSET
105+
#define CONFIG_FLASH_LOAD_OFFSET 0
106+
#endif
107+
#define LOADER_MAX_SIZE (DT_REG_SIZE(DT_NODELABEL(flash0)) - CONFIG_FLASH_LOAD_OFFSET)
108+
#endif
109+
__attribute__((retain)) const uintptr_t loader_max_size = LOADER_MAX_SIZE;
110+
96111
static int loader(const struct shell *sh) {
97112
const struct flash_area *fa;
98113
int rc;

0 commit comments

Comments
 (0)