Skip to content

Commit b6797fe

Browse files
committed
fix: report proper sketch and loader sizes in CI packaging
1 parent 82fcf33 commit b6797fe

5 files changed

Lines changed: 37 additions & 3 deletions

File tree

.github/workflows/package_core.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,15 @@ jobs:
114114
grep -i "warning:" $REPORT.stdout > $REPORT.warnings || true
115115
116116
# extract the memory usage table (from the header to the first non-% line)
117+
# override the size of the Flash with the size of the loader partition
118+
# and add the size of the sketch partition (not reported by Zephyr)
119+
LOADER_SIZE=$(( $(cat variants/${{ matrix.variant }}/syms-static.ld | grep '_loader_max_size' | cut -d '=' -f 2 | tr -d ') ;') ))
120+
SKETCH_SIZE=$(( $(cat variants/${{ matrix.variant }}/syms-static.ld | grep '_sketch_max_size' | cut -d '=' -f 2 | tr -d ') ;') ))
117121
cat $REPORT.stdout | sed -n '/^Memory region/,/^[^%]*$/p' | head -n -1 \
118122
| 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] "]"}' \
119-
| sort | jq -s > $REPORT.meminfo
123+
| sort \
124+
| jq -s "map((select(.[0] == \"FLASH:\") | .[2]) |= ${LOADER_SIZE}) + [ [ \"SKETCH:\", 0, ${SKETCH_SIZE} ] ]" > $REPORT.meminfo
125+
jq
120126
121127
- name: Package board artifacts
122128
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
@@ -394,6 +394,7 @@ def print_mem_report(artifact, artifact_boards):
394394
f_print("<th rowspan='2'>SoC</th>", end='')
395395
f_print("<th rowspan='2'>FLASH</th>", end='')
396396
f_print("<th rowspan='2'>RAM</th>", end='')
397+
f_print("<th rowspan='2'>User<br>sketch</th>", end='')
397398
f_print("<th colspan='2'>User heaps</th>", end='')
398399
f_print("<th colspan='2'>OS heaps</th>", end='')
399400
f_print("</tr>")
@@ -410,14 +411,15 @@ def print_mem_report(artifact, artifact_boards):
410411
f"<code>{soc}</code>",
411412
color_entry(BOARD_LOADERS[board].meminfo['FLASH']),
412413
color_entry(BOARD_LOADERS[board].meminfo['RAM']),
414+
f"${{{ BOARD_LOADERS[board].meminfo['SKETCH'] }}}$",
413415
f"${{{ BOARD_LOADERS[board].config.get('CONFIG_HEAP_MEM_POOL_SIZE', 0) }}}$",
414416
f"${{{ BOARD_LOADERS[board].config['CONFIG_SRAM_SIZE']*1024 - BOARD_LOADERS[board].meminfo['RAM'][0] }}}$",
415417
f"${{{ BOARD_LOADERS[board].config['CONFIG_LLEXT_HEAP_SIZE']*1024 }}}$",
416418
f"${{{ BOARD_LOADERS[board].config.get('CONFIG_MBEDTLS_HEAP_SIZE', '-') }}}$"
417419
]
418420

419421
f_print("<tr>")
420-
col_aligns = ['center', 'left', 'center', 'right', 'right', 'right', 'right', 'right', 'right']
422+
col_aligns = ['center', 'left', 'center', 'right', 'right', 'right', 'right', 'right', 'right', 'right']
421423
for index, cell in enumerate(row):
422424
f_print(f"<td align='{col_aligns[index]}'>\n\n{cell}\n\n</td>")
423425
f_print("</tr>")
@@ -426,7 +428,7 @@ def print_mem_report(artifact, artifact_boards):
426428
extra_data_present = False
427429
for soc in sorted(list(set([ ALL_BOARD_DATA[board]['soc'] for board in artifact_boards ]))):
428430
soc_boards = [ board for board in artifact_boards if ALL_BOARD_DATA[board]['soc'] == soc ]
429-
sorted_regions = sorted(r for r in REGIONS_BY_SOC[soc] if r not in ('FLASH', 'RAM'))
431+
sorted_regions = sorted(r for r in REGIONS_BY_SOC[soc] if r not in ('FLASH', 'RAM', 'SKETCH'))
430432
if not sorted_regions:
431433
continue
432434

extra/package_core.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ 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

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)