@@ -778,7 +778,7 @@ def _assign_new_offset(rom_start, start, new_offset, region_name):
778
778
newstart = rom_start + integer (new_offset , 0 )
779
779
if newstart < start :
780
780
raise ConfigException (
781
- "Can not place % region inside previous region" % region_name )
781
+ "Can not place %r region inside previous region" % region_name )
782
782
return newstart
783
783
784
784
def _generate_bootloader_build (self , rom_memories ):
@@ -797,8 +797,19 @@ def _generate_bootloader_build(self, rom_memories):
797
797
if part .minaddr () != rom_start :
798
798
raise ConfigException ("bootloader executable does not "
799
799
"start at 0x%x" % rom_start )
800
- part_size = (part .maxaddr () - part .minaddr ()) + 1
801
- part_size = Config ._align_ceiling (rom_start + part_size , self .sectors ) - rom_start
800
+
801
+ # find the last valid address that's within rom_end and use that
802
+ # to compute the bootloader size
803
+ end_address = None
804
+ for start , stop in part .segments ():
805
+ if (stop < rom_end ):
806
+ end_address = stop
807
+ else :
808
+ break
809
+ if end_address == None :
810
+ raise ConfigException ("bootloader segments don't fit within rom region" )
811
+ part_size = Config ._align_ceiling (end_address , self .sectors ) - rom_start
812
+
802
813
yield Region ("bootloader" , rom_start , part_size , False ,
803
814
filename )
804
815
start = rom_start + part_size
@@ -809,9 +820,14 @@ def _generate_bootloader_build(self, rom_memories):
809
820
start , region = self ._make_header_region (
810
821
start , self .target .header_format )
811
822
yield region ._replace (filename = self .target .header_format )
823
+
812
824
if self .target .restrict_size is not None :
813
825
new_size = int (self .target .restrict_size , 0 )
814
826
new_size = Config ._align_floor (start + new_size , self .sectors ) - start
827
+
828
+ if self .target .app_offset :
829
+ start = self ._assign_new_offset (rom_start , start , self .target .app_offset , "application" )
830
+
815
831
yield Region ("application" , start , new_size , True , None )
816
832
start += new_size
817
833
if self .target .header_format and not self .target .bootloader_img :
@@ -821,9 +837,7 @@ def _generate_bootloader_build(self, rom_memories):
821
837
start , region = self ._make_header_region (
822
838
start , self .target .header_format )
823
839
yield region
824
- if self .target .app_offset :
825
- start = self ._assign_new_offset (
826
- rom_start , start , self .target .app_offset , "application" )
840
+
827
841
yield Region ("post_application" , start , rom_end - start ,
828
842
False , None )
829
843
else :
@@ -832,7 +846,7 @@ def _generate_bootloader_build(self, rom_memories):
832
846
rom_start , start , self .target .app_offset , "application" )
833
847
yield Region ("application" , start , rom_end - start ,
834
848
True , None )
835
- if start > rom_start + rom_size :
849
+ if start > rom_end :
836
850
raise ConfigException ("Not enough memory on device to fit all "
837
851
"application regions" )
838
852
0 commit comments