Centralize location of memory pools

This commit centralizes the location of memory pools and adds an
associated script (scripts/get_memory_map.sh) to read the memory map.
This commit is contained in:
Rickey Fehr
2025-09-21 13:14:22 -07:00
parent 72c0a6c4a9
commit 06cd13a17f
9 changed files with 70 additions and 36 deletions
+36
View File
@@ -0,0 +1,36 @@
#!/usr/bin/env bash
set -euo pipefail
# Run this from the root directory of the project, not the scripts directory
POOL_DEF_FILE='./include/pools.def'
ELF_FILE='./build/balatro-gba.elf'
READELF='/opt/devkitpro/devkitARM/bin/arm-none-eabi-readelf'
get_pool_names() {
grep POOL_ENTRY "$POOL_DEF_FILE" | sed -n 's@.*(\(.*\)).*@\1@p' | sed 's@,@@g' | cut -d ' ' -f 1
}
TOTAL_BYTES=0
echo "--------------------------------------------"
printf "%-16s| %-10s | %s\n" "Object" "location" "size"
echo "--------------------------------------------"
for name in $(get_pool_names); do
output="$( \
"$READELF" -sW "$ELF_FILE" | \
grep "${name}_" | \
grep OBJECT | \
grep storage | sed -E 's@ +@ @g; s@^ @@' \
)"
location="$(cut -d ' ' -f 2 <<< $output)"
size="$(cut -d ' ' -f 3 <<< $output)"
TOTAL_BYTES=$(( TOTAL_BYTES + size ))
printf "%-16s| 0x%s | %-8u\n" "$name" "$location" "$size"
done
echo "--------------------------------------------"
echo Total bytes used: $TOTAL_BYTES