Merge branch 'bugfix/partition_md5_backward_compatibility' into 'master'
partition_table: Optionally disable the MD5 checksum in partition tables See merge request idf/esp-idf!1958
This commit is contained in:
commit
ab82ce3da4
4 changed files with 23 additions and 3 deletions
|
@ -62,6 +62,15 @@ config PHY_DATA_OFFSET
|
||||||
default PARTITION_TABLE_CUSTOM_PHY_DATA_OFFSET if PARTITION_TABLE_CUSTOM
|
default PARTITION_TABLE_CUSTOM_PHY_DATA_OFFSET if PARTITION_TABLE_CUSTOM
|
||||||
default 0xf000 # this is the factory app offset used by the default tables
|
default 0xf000 # this is the factory app offset used by the default tables
|
||||||
|
|
||||||
|
config PARTITION_TABLE_MD5
|
||||||
|
bool "Generate an MD5 checksum for the partition table"
|
||||||
|
default y
|
||||||
|
help
|
||||||
|
Generate an MD5 checksum for the partition table for protecting the
|
||||||
|
integrity of the table. The generation should be turned off for legacy
|
||||||
|
bootloaders which cannot recognize the MD5 checksum in the partition
|
||||||
|
table.
|
||||||
|
|
||||||
endmenu
|
endmenu
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,8 +8,12 @@
|
||||||
#
|
#
|
||||||
.PHONY: partition_table partition_table-flash partition_table-clean
|
.PHONY: partition_table partition_table-flash partition_table-clean
|
||||||
|
|
||||||
|
ifneq ("$(CONFIG_PARTITION_TABLE_MD5)", "y")
|
||||||
|
MD5_OPT ?= "--disable-md5sum"
|
||||||
|
endif
|
||||||
|
|
||||||
# NB: gen_esp32part.py lives in the sdk/bin/ dir not component dir
|
# NB: gen_esp32part.py lives in the sdk/bin/ dir not component dir
|
||||||
GEN_ESP32PART := $(PYTHON) $(COMPONENT_PATH)/gen_esp32part.py -q
|
GEN_ESP32PART := $(PYTHON) $(COMPONENT_PATH)/gen_esp32part.py -q $(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
|
||||||
|
|
|
@ -35,6 +35,7 @@ MD5_PARTITION_BEGIN = b"\xEB\xEB" + b"\xFF" * 14 # The first 2 bytes are like ma
|
||||||
__version__ = '1.0'
|
__version__ = '1.0'
|
||||||
|
|
||||||
quiet = False
|
quiet = False
|
||||||
|
md5sum = True
|
||||||
|
|
||||||
def status(msg):
|
def status(msg):
|
||||||
""" Print status message to stderr """
|
""" Print status message to stderr """
|
||||||
|
@ -123,7 +124,7 @@ class PartitionTable(list):
|
||||||
raise InputError("Partition table length must be a multiple of 32 bytes")
|
raise InputError("Partition table length must be a multiple of 32 bytes")
|
||||||
if data == b'\xFF'*32:
|
if data == b'\xFF'*32:
|
||||||
return result # got end marker
|
return result # got end marker
|
||||||
if data[:2] == MD5_PARTITION_BEGIN[:2]: #check only the magic number part
|
if md5sum and data[:2] == MD5_PARTITION_BEGIN[:2]: #check only the magic number part
|
||||||
if data[16:] == md5.digest():
|
if data[16:] == md5.digest():
|
||||||
continue # the next iteration will check for the end marker
|
continue # the next iteration will check for the end marker
|
||||||
else:
|
else:
|
||||||
|
@ -135,6 +136,7 @@ class PartitionTable(list):
|
||||||
|
|
||||||
def to_binary(self):
|
def to_binary(self):
|
||||||
result = b"".join(e.to_binary() for e in self)
|
result = b"".join(e.to_binary() for e in self)
|
||||||
|
if md5sum:
|
||||||
result += MD5_PARTITION_BEGIN + hashlib.md5(result).digest()
|
result += MD5_PARTITION_BEGIN + hashlib.md5(result).digest()
|
||||||
if len(result )>= MAX_PARTITION_LENGTH:
|
if len(result )>= MAX_PARTITION_LENGTH:
|
||||||
raise InputError("Binary partition table length (%d) longer than max" % len(result))
|
raise InputError("Binary partition table length (%d) longer than max" % len(result))
|
||||||
|
@ -345,8 +347,10 @@ def parse_int(v, keywords={}):
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
global quiet
|
global quiet
|
||||||
|
global md5sum
|
||||||
parser = argparse.ArgumentParser(description='ESP32 partition table utility')
|
parser = argparse.ArgumentParser(description='ESP32 partition table utility')
|
||||||
|
|
||||||
|
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')
|
||||||
|
|
||||||
|
@ -358,6 +362,7 @@ def main():
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
quiet = args.quiet
|
quiet = args.quiet
|
||||||
|
md5sum = not args.disable_md5sum
|
||||||
input = args.input.read()
|
input = args.input.read()
|
||||||
input_is_binary = input[0:2] == PartitionDefinition.MAGIC_BYTES
|
input_is_binary = input[0:2] == PartitionDefinition.MAGIC_BYTES
|
||||||
if input_is_binary:
|
if input_is_binary:
|
||||||
|
|
|
@ -153,6 +153,8 @@ MD5 checksum
|
||||||
|
|
||||||
The binary format of the partition table contains an MD5 checksum computed based on the partition table. This checksum is used for checking the integrity of the partition table during the boot.
|
The binary format of the partition table contains an MD5 checksum computed based on the partition table. This checksum is used for checking the integrity of the partition table during the boot.
|
||||||
|
|
||||||
|
The MD5 checksum generation can be disabled by the ``--disable-md5sum`` option of ``gen_esp32part.py`` or by the :ref:`CONFIG_PARTITION_TABLE_MD5` option. This is useful for example when one uses a legacy bootloader which cannot process MD5 checksums and the boot fails with the error message ``invalid magic number 0xebeb``.
|
||||||
|
|
||||||
Flashing the partition table
|
Flashing the partition table
|
||||||
----------------------------
|
----------------------------
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue