mirror of
https://github.com/espressif/esp-idf
synced 2025-03-10 01:29:21 -04:00
partition_table: Check configured flash size fits in partition table
Check happens at build time, so flash size config may need to be changed. Also fixes MD5_OPT undefined warning, closes https://github.com/espressif/esp-idf/issues/1867
This commit is contained in:
parent
e3d404bb8f
commit
fa3205737f
@ -8,12 +8,20 @@
|
|||||||
#
|
#
|
||||||
.PHONY: partition_table partition_table-flash partition_table-clean
|
.PHONY: partition_table partition_table-flash partition_table-clean
|
||||||
|
|
||||||
|
MD5_OPT :=
|
||||||
ifneq ("$(CONFIG_PARTITION_TABLE_MD5)", "y")
|
ifneq ("$(CONFIG_PARTITION_TABLE_MD5)", "y")
|
||||||
MD5_OPT ?= "--disable-md5sum"
|
MD5_OPT := "--disable-md5sum"
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# NB: gen_esp32part.py lives in the sdk/bin/ dir not component dir
|
FLASHSIZE_OPT :=
|
||||||
GEN_ESP32PART := $(PYTHON) $(COMPONENT_PATH)/gen_esp32part.py -q $(MD5_OPT)
|
ifneq ("$(CONFIG_ESPTOOLPY_FLASHSIZE)", "")
|
||||||
|
FLASHSIZE_OPT := --flash-size $(CONFIG_ESPTOOLPY_FLASHSIZE)
|
||||||
|
endif
|
||||||
|
|
||||||
|
GEN_ESP32PART := $(PYTHON) $(COMPONENT_PATH)/gen_esp32part.py -q $(MD5_OPT) $(FLASHSIZE_OPT)
|
||||||
|
|
||||||
|
undefine FLASHSIZE_OPT # we don't need these any more, so take them out of global scope
|
||||||
|
undefine MD5_OPT
|
||||||
|
|
||||||
# Has a matching value in bootloader_support esp_flash_partitions.h
|
# Has a matching value in bootloader_support esp_flash_partitions.h
|
||||||
PARTITION_TABLE_OFFSET := 0x8000
|
PARTITION_TABLE_OFFSET := 0x8000
|
||||||
|
@ -114,6 +114,16 @@ class PartitionTable(list):
|
|||||||
raise InputError("Partition at 0x%x overlaps 0x%x-0x%x" % (p.offset, last.offset, last.offset+last.size-1))
|
raise InputError("Partition at 0x%x overlaps 0x%x-0x%x" % (p.offset, last.offset, last.offset+last.size-1))
|
||||||
last = p
|
last = p
|
||||||
|
|
||||||
|
def flash_size(self):
|
||||||
|
""" Return the size that partitions will occupy in flash
|
||||||
|
(ie the offset the last partition ends at)
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
last = sorted(self, reverse=True)[0]
|
||||||
|
except IndexError:
|
||||||
|
return 0 # empty table!
|
||||||
|
return last.offset + last.size
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_binary(cls, b):
|
def from_binary(cls, b):
|
||||||
md5 = hashlib.md5();
|
md5 = hashlib.md5();
|
||||||
@ -350,6 +360,8 @@ def main():
|
|||||||
global md5sum
|
global md5sum
|
||||||
parser = argparse.ArgumentParser(description='ESP32 partition table utility')
|
parser = argparse.ArgumentParser(description='ESP32 partition table utility')
|
||||||
|
|
||||||
|
parser.add_argument('--flash-size', help='Optional flash size limit, checks partition table fits in flash',
|
||||||
|
nargs='?', choices=[ '1MB', '2MB', '4MB', '8MB', '16MB' ])
|
||||||
parser.add_argument('--disable-md5sum', help='Disable md5 checksum for the partition table', default=False, action='store_true')
|
parser.add_argument('--disable-md5sum', help='Disable md5 checksum for the partition table', default=False, action='store_true')
|
||||||
parser.add_argument('--verify', '-v', help='Verify partition table fields', default=True, action='store_false')
|
parser.add_argument('--verify', '-v', help='Verify partition table fields', default=True, action='store_false')
|
||||||
parser.add_argument('--quiet', '-q', help="Don't print status messages to stderr", action='store_true')
|
parser.add_argument('--quiet', '-q', help="Don't print status messages to stderr", action='store_true')
|
||||||
@ -377,6 +389,14 @@ def main():
|
|||||||
status("Verifying table...")
|
status("Verifying table...")
|
||||||
table.verify()
|
table.verify()
|
||||||
|
|
||||||
|
if args.flash_size:
|
||||||
|
size_mb = int(args.flash_size.replace("MB", ""))
|
||||||
|
size = size_mb * 1024 * 1024 # flash memory uses honest megabytes!
|
||||||
|
table_size = table.flash_size()
|
||||||
|
if size < table_size:
|
||||||
|
raise InputError("Partitions defined in '%s' occupy %.1fMB of flash (%d bytes) which does not fit in configured flash size %dMB. Change the flash size in menuconfig under the 'Serial Flasher Config' menu." %
|
||||||
|
(args.input.name, table_size / 1024.0 / 1024.0, table_size, size_mb))
|
||||||
|
|
||||||
if input_is_binary:
|
if input_is_binary:
|
||||||
output = table.to_csv()
|
output = table.to_csv()
|
||||||
with sys.stdout if args.output == '-' else open(args.output, 'w') as f:
|
with sys.stdout if args.output == '-' else open(args.output, 'w') as f:
|
||||||
|
@ -3,3 +3,4 @@ CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_example.csv"
|
|||||||
CONFIG_PARTITION_TABLE_CUSTOM_APP_BIN_OFFSET=0x10000
|
CONFIG_PARTITION_TABLE_CUSTOM_APP_BIN_OFFSET=0x10000
|
||||||
CONFIG_PARTITION_TABLE_FILENAME="partitions_example.csv"
|
CONFIG_PARTITION_TABLE_FILENAME="partitions_example.csv"
|
||||||
CONFIG_APP_OFFSET=0x10000
|
CONFIG_APP_OFFSET=0x10000
|
||||||
|
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
|
||||||
|
@ -15,3 +15,6 @@ CONFIG_APP_OFFSET=0x10000
|
|||||||
# Enable FreeRTOS stats formatting functions, needed for 'tasks' command
|
# Enable FreeRTOS stats formatting functions, needed for 'tasks' command
|
||||||
CONFIG_FREERTOS_USE_TRACE_FACILITY=y
|
CONFIG_FREERTOS_USE_TRACE_FACILITY=y
|
||||||
CONFIG_FREERTOS_USE_STATS_FORMATTING_FUNCTIONS=y
|
CONFIG_FREERTOS_USE_STATS_FORMATTING_FUNCTIONS=y
|
||||||
|
|
||||||
|
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
|
||||||
|
|
||||||
|
@ -226,6 +226,14 @@ function run_tests()
|
|||||||
[ -f ${IDF_PATH}/.gitmodules_backup ] && mv ${IDF_PATH}/.gitmodules_backup ${IDF_PATH}/.gitmodules
|
[ -f ${IDF_PATH}/.gitmodules_backup ] && mv ${IDF_PATH}/.gitmodules_backup ${IDF_PATH}/.gitmodules
|
||||||
export PATH=$OLD_PATH
|
export PATH=$OLD_PATH
|
||||||
|
|
||||||
|
print_status "Build fails if partitions don't fit in flash"
|
||||||
|
cp sdkconfig sdkconfig.bak
|
||||||
|
sed -i "s/CONFIG_ESPTOOLPY_FLASHSIZE.\+//" sdkconfig # remove all flashsize config
|
||||||
|
echo "CONFIG_ESPTOOLPY_FLASHSIZE_1MB=y" >> sdkconfig # introduce undersize flash
|
||||||
|
make defconfig || failure "Failed to reconfigure with smaller flash"
|
||||||
|
( make 2>&1 | grep "does not fit in configured flash size 1MB" ) || failure "Build didn't fail with expected flash size failure message"
|
||||||
|
mv sdkconfig.bak sdkconfig
|
||||||
|
|
||||||
print_status "All tests completed"
|
print_status "All tests completed"
|
||||||
if [ -n "${FAILURES}" ]; then
|
if [ -n "${FAILURES}" ]; then
|
||||||
echo "Some failures were detected:"
|
echo "Some failures were detected:"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user