4141 unicode = str
4242PATH_OVERRIDES = set (["target.bootloader_img" ])
4343BOOTLOADER_OVERRIDES = set (["target.bootloader_img" , "target.restrict_size" ,
44+ "target.header_format" ,
4445 "target.mbed_app_start" , "target.mbed_app_size" ])
4546
4647# Base class for all configuration exceptions
@@ -568,6 +569,29 @@ def regions(self):
568569 raise ConfigException (
569570 "Bootloader build requested but no bootlader configuration" )
570571
572+ @staticmethod
573+ def _header_size (format ):
574+ size_in_bytes = 0
575+ for _ , _ , subtype , _ in format :
576+ try :
577+ size_in_bytes += int (subtype ) // 8
578+ except :
579+ if subtype == "CRCITT32" :
580+ size_in_bytes += 32 // 8
581+ elif subtype == "SHA256" :
582+ size_in_bytes += 256 // 8
583+ else :
584+ raise ValueError ("target.header_format: subtype %s is not "
585+ "understood" % subtype )
586+ return size_in_bytes
587+
588+ def _make_header_region (self , start , header_format ):
589+ size = self ._header_size (header_format )
590+ region = Region ("application_header" , start , size , False , None )
591+ start += size
592+ start = ((start + 7 ) // 8 ) * 8
593+ return (start , region )
594+
571595 def _generate_bootloader_build (self , rom_start , rom_size ):
572596 start = rom_start
573597 rom_end = rom_start + rom_size
@@ -588,11 +612,19 @@ def _generate_bootloader_build(self, rom_start, rom_size):
588612 yield Region ("bootloader" , rom_start , part_size , False ,
589613 filename )
590614 start = rom_start + part_size
615+ if self .target .header_format :
616+ start , region = self ._make_header_region (
617+ start , self .target .header_format )
618+ yield region
591619 if self .target .restrict_size is not None :
592620 new_size = int (self .target .restrict_size , 0 )
593621 new_size = Config ._align_floor (start + new_size , self .sectors ) - start
594622 yield Region ("application" , start , new_size , True , None )
595623 start += new_size
624+ if self .target .header_format :
625+ start , region = self ._make_header_region (
626+ start , self .target .header_format )
627+ yield region
596628 yield Region ("post_application" , start , rom_end - start ,
597629 False , None )
598630 else :
0 commit comments