@@ -692,12 +692,13 @@ def _assign_new_offset(rom_start, start, new_offset, region_name):
692
692
newstart = rom_start + integer (new_offset , 0 )
693
693
if newstart < start :
694
694
raise ConfigException (
695
- "Can not place % region inside previous region" % region_name )
695
+ "Can not place %r region inside previous region" % region_name )
696
696
return newstart
697
697
698
698
def _generate_bootloader_build (self , rom_start , rom_size ):
699
699
start = rom_start
700
700
rom_end = rom_start + rom_size
701
+ max_app_addr = - 1
701
702
if self .target .bootloader_img :
702
703
if isabs (self .target .bootloader_img ):
703
704
filename = self .target .bootloader_img
@@ -710,8 +711,23 @@ def _generate_bootloader_build(self, rom_start, rom_size):
710
711
if part .minaddr () != rom_start :
711
712
raise ConfigException ("bootloader executable does not "
712
713
"start at 0x%x" % rom_start )
713
- part_size = (part .maxaddr () - part .minaddr ()) + 1
714
- part_size = Config ._align_ceiling (rom_start + part_size , self .sectors ) - rom_start
714
+ if len (part .segments ()) == 1 :
715
+ part_size = (part .maxaddr () - part .minaddr ()) + 1
716
+ part_size = Config ._align_ceiling (rom_start + part_size , self .sectors ) - rom_start
717
+ else :
718
+ # assume first segment is at start
719
+ # second at the end or outside ROM
720
+ # rest outside regular ROM
721
+ if part .segments ()[0 ][0 ] != 0x0 :
722
+ raise ConfigException ("bootloader segments not in order" )
723
+ part_size = part .segments ()[0 ][1 ] - part .segments ()[0 ][0 ]
724
+ part_size = Config ._align_ceiling (rom_start + part_size , self .sectors ) - rom_start
725
+ if part .segments ()[1 ][0 ] < rom_end and self .target .restrict_size is None :
726
+ if self .target .app_offset :
727
+ self .target .restrict_size = "0x%x" % (part .segments ()[1 ][0 ] - int (self .target .app_offset , 0 ))
728
+ else :
729
+ max_app_addr = part .segments ()[1 ][0 ]
730
+
715
731
yield Region ("bootloader" , rom_start , part_size , False ,
716
732
filename )
717
733
start = rom_start + part_size
@@ -722,9 +738,17 @@ def _generate_bootloader_build(self, rom_start, rom_size):
722
738
start , region = self ._make_header_region (
723
739
start , self .target .header_format )
724
740
yield region ._replace (filename = self .target .header_format )
741
+
742
+ if max_app_addr != - 1 and self .target .restrict_size is None and not self .target .app_offset :
743
+ self .target .restrict_size = "0x%x" % (max_app_addr - start )
744
+
725
745
if self .target .restrict_size is not None :
726
746
new_size = int (self .target .restrict_size , 0 )
727
747
new_size = Config ._align_floor (start + new_size , self .sectors ) - start
748
+
749
+ if self .target .app_offset :
750
+ start = self ._assign_new_offset (rom_start , start , self .target .app_offset , "application" )
751
+
728
752
yield Region ("application" , start , new_size , True , None )
729
753
start += new_size
730
754
if self .target .header_format and not self .target .bootloader_img :
@@ -734,9 +758,7 @@ def _generate_bootloader_build(self, rom_start, rom_size):
734
758
start , region = self ._make_header_region (
735
759
start , self .target .header_format )
736
760
yield region
737
- if self .target .app_offset :
738
- start = self ._assign_new_offset (
739
- rom_start , start , self .target .app_offset , "application" )
761
+
740
762
yield Region ("post_application" , start , rom_end - start ,
741
763
False , None )
742
764
else :
@@ -745,7 +767,7 @@ def _generate_bootloader_build(self, rom_start, rom_size):
745
767
rom_start , start , self .target .app_offset , "application" )
746
768
yield Region ("application" , start , rom_end - start ,
747
769
True , None )
748
- if start > rom_start + rom_size :
770
+ if start > rom_end :
749
771
raise ConfigException ("Not enough memory on device to fit all "
750
772
"application regions" )
751
773
0 commit comments