]> granicus.if.org Git - esp-idf/commitdiff
partition_table: Optionally disable the MD5 checksum in partition tables
authorRoland Dobai <dobai.roland@gmail.com>
Fri, 16 Feb 2018 10:12:16 +0000 (11:12 +0100)
committerRoland Dobai <dobai.roland@gmail.com>
Thu, 22 Feb 2018 06:46:41 +0000 (07:46 +0100)
components/partition_table/Kconfig.projbuild
components/partition_table/Makefile.projbuild
components/partition_table/gen_esp32part.py
docs/api-guides/partition-tables.rst

index a6176e0fd196b6e674a27fe3ae571e84b26145ef..09635d67a3e64f4822f0e985332f35f177116d38 100644 (file)
@@ -62,6 +62,15 @@ config PHY_DATA_OFFSET
        default PARTITION_TABLE_CUSTOM_PHY_DATA_OFFSET if PARTITION_TABLE_CUSTOM
        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
 
 
index a7d4f2ecde2b5f72cb5dec719fb64b6ccc878168..d1b7acdaa9408bef7fcacb80e547a71ab263eef1 100644 (file)
@@ -8,8 +8,12 @@
 #
 .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
-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
 PARTITION_TABLE_OFFSET := 0x8000
index 7b80cabf8fb1ff99cde5559aead3f84d4609e555..a8607f360ccd56af55f37148d2de3f56b921384b 100755 (executable)
@@ -35,6 +35,7 @@ MD5_PARTITION_BEGIN = b"\xEB\xEB" + b"\xFF" * 14 # The first 2 bytes are like ma
 __version__ = '1.0'
 
 quiet = False
+md5sum = True
 
 def status(msg):
     """ Print status message to stderr """
@@ -123,7 +124,7 @@ class PartitionTable(list):
                 raise InputError("Partition table length must be a multiple of 32 bytes")
             if data == b'\xFF'*32:
                 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():
                     continue # the next iteration will check for the end marker
                 else:
@@ -135,7 +136,8 @@ class PartitionTable(list):
 
     def to_binary(self):
         result = b"".join(e.to_binary() for e in self)
-        result += MD5_PARTITION_BEGIN + hashlib.md5(result).digest()
+        if md5sum:
+            result += MD5_PARTITION_BEGIN + hashlib.md5(result).digest()
         if len(result )>= MAX_PARTITION_LENGTH:
             raise InputError("Binary partition table length (%d) longer than max" % len(result))
         result += b"\xFF" * (MAX_PARTITION_LENGTH - len(result))  # pad the sector, for signing
@@ -345,8 +347,10 @@ def parse_int(v, keywords={}):
 
 def main():
     global quiet
+    global md5sum
     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('--quiet', '-q', help="Don't print status messages to stderr", action='store_true')
 
@@ -358,6 +362,7 @@ def main():
     args = parser.parse_args()
 
     quiet = args.quiet
+    md5sum = not args.disable_md5sum
     input = args.input.read()
     input_is_binary = input[0:2] == PartitionDefinition.MAGIC_BYTES
     if input_is_binary:
index ee88631232a15d21b8ad6cd21b8fc98d621a9252..2893dbcaaaa03e5e302b5f644e5e05ae3c23d889 100644 (file)
@@ -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 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
 ----------------------------