Skip to content

Commit f21eec5

Browse files
committed
Work for non-psram builds
This is more or less a complete re-organization of the code. * Use the actual byte size of the .bin file as the flash size, as the algorithm for packing sections into the flash is complicated * Match each section to a data region & find the high water mark in the region * Report on all the RAM regions, separately Note that elftools is a requirement of esp-idf and so does not need to be listed in our requirements.txt.
1 parent c931e5d commit f21eec5

File tree

2 files changed

+48
-45
lines changed

2 files changed

+48
-45
lines changed

ports/esp32s2/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,11 +316,11 @@ esp-idf-stamp: $(BUILD)/esp-idf/config/sdkconfig.h
316316
$(BUILD)/firmware.elf: $(OBJ) | esp-idf-stamp
317317
$(STEPECHO) "LINK $@"
318318
$(Q)$(CC) -o $@ $(LDFLAGS) $^ -Wl,--start-group $(ESP_IDF_COMPONENTS_EXPANDED) $(BINARY_BLOBS) $(MBEDTLS_COMPONENTS_LINK_EXPANDED) build-$(BOARD)/esp-idf/esp-idf/newlib/libnewlib.a -Wl,--end-group -u newlib_include_pthread_impl -Wl,--start-group $(LIBS) -Wl,--end-group build-$(BOARD)/esp-idf/esp-idf/pthread/libpthread.a -u __cxx_fatal_exception
319-
$(Q)$(SIZE) $@ | $(PYTHON3) tools/build_memory_info.py $(BUILD)/esp-idf/sdkconfig
320319

321-
$(BUILD)/circuitpython-firmware.bin: $(BUILD)/firmware.elf
320+
$(BUILD)/circuitpython-firmware.bin: $(BUILD)/firmware.elf | tools/build_memory_info.py
322321
$(STEPECHO) "Create $@"
323322
$(Q)esptool.py --chip esp32s2 elf2image $(FLASH_FLAGS) --elf-sha256-offset 0xb0 -o $@ $^
323+
$(Q)$(PYTHON3) tools/build_memory_info.py $< $(BUILD)/esp-idf/sdkconfig $@
324324

325325
$(BUILD)/firmware.bin: $(BUILD)/circuitpython-firmware.bin | esp-idf-stamp
326326
$(Q)$(PYTHON) ../../tools/join_bins.py $@ 0x1000 $(BUILD)/esp-idf/bootloader/bootloader.bin 0x8000 $(BUILD)/esp-idf/partition_table/partition-table.bin 0x10000 $(BUILD)/circuitpython-firmware.bin

ports/esp32s2/tools/build_memory_info.py

Lines changed: 46 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,72 +5,75 @@
55
#
66
# SPDX-License-Identifier: MIT
77

8+
import os
89
import re
910
import sys
1011

11-
# Handle size constants with K or M suffixes (allowed in .ld but not in Python).
12-
K_PATTERN = re.compile(r"([0-9]+)[kK]")
13-
K_REPLACE = r"(\1*1024)"
14-
15-
M_PATTERN = re.compile(r"([0-9]+)[mM]")
16-
M_REPLACE = r"(\1*1024*1024)"
12+
from elftools.elf.elffile import ELFFile
1713

1814
print()
1915

20-
text = 0
21-
data = 0
22-
bss = 0
23-
# stdin is the linker output.
24-
for line in sys.stdin:
25-
# Uncomment to see linker output.
26-
# print(line)
27-
line = line.strip()
28-
if not line.startswith("text"):
29-
text, data, bss = map(int, line.split()[:3])
16+
internal_memory = [
17+
# Name, Start, Length
18+
("RTC Fast Memory", (0x3FF9_E000, 0x4007_0000), 8 * 1024),
19+
("RTC Slow Memory", (0x5000_0000,), 8 * 1024),
20+
("Internal SRAM 0", (0x3FFB_0000, 0x4002_0000), 32 * 1024),
21+
("Internal SRAM 1", (0x3FFB_8000, 0x4002_8000), 288 * 1024),
22+
]
3023

3124

3225
def partition_size(arg):
3326
if "4MB" in arg:
34-
return "1408K"
27+
return 1408 * 1024
3528
else:
36-
return "2048K"
29+
return 2048 * 1024
30+
31+
32+
def align(n, m):
33+
return m * ((n + m - 1) // m)
34+
35+
36+
regions = dict((name, 0) for name, _, _ in internal_memory)
3737

38+
# This file is the elf
39+
with open(sys.argv[1], "rb") as stream:
40+
elffile = ELFFile(stream)
41+
for section in elffile.iter_sections():
42+
start = section["sh_addr"]
43+
size = section["sh_size"]
44+
offset = section["sh_offset"]
45+
if not size or not start:
46+
continue
47+
for name, starts, length in internal_memory:
48+
for mem_start in starts:
49+
mem_end = mem_start + length
50+
if start >= mem_start and start < mem_end:
51+
regions[name] = max(regions.get(name, 0), size)
52+
# print("# putting %s in %s (start=0x%x, size=%d)" % (section.name, name, start, size))
3853

39-
regions = {}
40-
# This file is the linker script.
41-
with open(sys.argv[1], "r") as f:
54+
# This file is the sdkconfig
55+
with open(sys.argv[2], "r") as f:
4256
for line in f:
4357
line = line.strip()
44-
if line.startswith("CONFIG_SPIRAM_SIZE"):
45-
regions["RAM"] = line.split("=")[-1]
4658
if line.startswith("CONFIG_PARTITION_TABLE_FILENAME"):
47-
regions["FLASH_FIRMWARE"] = partition_size(line.split("=")[-1])
59+
firmware_region = int(partition_size(line.split("=")[-1]))
4860

49-
for region in regions:
50-
space = regions[region]
51-
if "/*" in space:
52-
space = space.split("/*")[0]
53-
space = K_PATTERN.sub(K_REPLACE, space)
54-
space = M_PATTERN.sub(M_REPLACE, space)
55-
regions[region] = int(eval(space))
61+
# This file is the bin
62+
used_flash = os.stat(sys.argv[3]).st_size
5663

57-
firmware_region = regions["FLASH_FIRMWARE"]
58-
ram_region = regions["RAM"]
59-
60-
used_flash = data + text
6164
free_flash = firmware_region - used_flash
62-
used_ram = data + bss
63-
free_ram = ram_region - used_ram
6465
print(
65-
"{} bytes used, {} bytes free in flash firmware space out of {} bytes ({}kB).".format(
66+
"{:7} bytes used, {:7} bytes free in flash firmware space out of {} bytes ({}kB).".format(
6667
used_flash, free_flash, firmware_region, firmware_region / 1024
6768
)
6869
)
69-
print(
70-
"{} bytes used, {} bytes free in ram for stack and heap out of {} bytes ({}kB).".format(
71-
used_ram, free_ram, ram_region, ram_region / 1024
72-
)
73-
)
70+
for name, mem_start, length in internal_memory:
71+
if name in regions:
72+
print(
73+
"{:7} bytes used, {:7} bytes free in '{}' out of {} bytes ({}kB).".format(
74+
regions[name], length - regions[name], name, length, length / 1024
75+
)
76+
)
7477
print()
7578

7679
# Check that we have free flash space. GCC doesn't fail when the text + data

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy