71
71
"ETHERNET_HOST" ,
72
72
]
73
73
74
+ # List of all possible ram memories that can be available for a target
75
+ RAM_ALL_MEMORIES = ['IRAM1' , 'IRAM2' , 'IRAM3' , 'IRAM4' , 'SRAM_OC' , \
76
+ 'SRAM_ITC' , 'SRAM_DTC' , 'SRAM_UPPER' , 'SRAM_LOWER' ]
77
+
78
+ # List of all possible rom memories that can be available for a target
79
+ ROM_ALL_MEMORIES = ['IROM1' , 'PROGRAM_FLASH' , 'IROM2' ]
80
+
74
81
# Base class for all configuration exceptions
75
82
class ConfigException (Exception ):
76
83
"""Config system only exception. Makes it easier to distinguish config
@@ -610,24 +617,50 @@ def _get_mem_specs(self, memories, cmsis_part, exception_text):
610
617
continue
611
618
raise ConfigException (exception_text )
612
619
613
- @property
614
- def rom (self ):
615
- """Get rom information as a pair of start_addr, size"""
620
+ def get_all_active_memories (self , memory_list ):
621
+ """Get information of all available rom/ram memories in the form of dictionary
622
+ {Memory: [start_addr, size]}. Takes in the argument, a list of all available
623
+ regions within the ram/rom memory"""
616
624
# Override rom_start/rom_size
617
625
#
618
626
# This is usually done for a target which:
619
627
# 1. Doesn't support CMSIS pack, or
620
628
# 2. Supports TrustZone and user needs to change its flash partition
629
+
630
+ available_memories = {}
631
+ # Counter to keep track of ROM/RAM memories supported by target
632
+ active_memory_counter = 0
633
+ # Find which memory we are dealing with, RAM/ROM
634
+ active_memory = 'RAM' if any ('RAM' in mem_list for mem_list in memory_list ) else 'ROM'
621
635
cmsis_part = self ._get_cmsis_part ()
622
- rom_start , rom_size = self ._get_mem_specs (
623
- ["IROM1" , "PROGRAM_FLASH" ],
624
- cmsis_part ,
625
- "Not enough information in CMSIS packs to build a bootloader "
626
- "project"
627
- )
628
- rom_start = int (getattr (self .target , "mbed_rom_start" , False ) or rom_start , 0 )
629
- rom_size = int (getattr (self .target , "mbed_rom_size" , False ) or rom_size , 0 )
630
- return (rom_start , rom_size )
636
+ present_memories = set (cmsis_part ['memory' ].keys ())
637
+ valid_memories = set (memory_list ).intersection (present_memories )
638
+
639
+ for memory in valid_memories :
640
+ mem_start , mem_size = self ._get_mem_specs (
641
+ [memory ],
642
+ cmsis_part ,
643
+ "Not enough information in CMSIS packs to build a bootloader "
644
+ "project"
645
+ )
646
+ if memory == 'IROM1' or memory == 'PROGRAM_FLASH' :
647
+ mem_start = getattr (self .target , "mbed_rom_start" , False ) or mem_start
648
+ mem_size = getattr (self .target , "mbed_rom_size" , False ) or mem_size
649
+ memory = 'ROM'
650
+ elif (memory == 'IRAM1' or memory == 'SRAM_OC' or \
651
+ memory == 'SRAM_UPPER' ) and (not self .has_ram_regions ):
652
+ mem_start = getattr (self .target , "mbed_ram_start" , False ) or mem_start
653
+ mem_size = getattr (self .target , "mbed_ram_size" , False ) or mem_size
654
+ memory = 'RAM'
655
+ else :
656
+ active_memory_counter += 1
657
+ memory = active_memory + str (active_memory_counter )
658
+
659
+ mem_start = int (mem_start , 0 )
660
+ mem_size = int (mem_size , 0 )
661
+ available_memories [memory ] = [mem_start , mem_size ]
662
+
663
+ return available_memories
631
664
632
665
@property
633
666
def ram_regions (self ):
@@ -653,13 +686,13 @@ def regions(self):
653
686
if ((self .target .bootloader_img or self .target .restrict_size ) and
654
687
(self .target .mbed_app_start or self .target .mbed_app_size )):
655
688
raise ConfigException (
656
- "target.bootloader_img and target.restirct_size are "
689
+ "target.bootloader_img and target.restrict_size are "
657
690
"incompatible with target.mbed_app_start and "
658
691
"target.mbed_app_size" )
659
692
if self .target .bootloader_img or self .target .restrict_size :
660
- return self ._generate_bootloader_build (* self .rom )
693
+ return self ._generate_bootloader_build (self .get_all_active_memories ( ROM_ALL_MEMORIES ) )
661
694
else :
662
- return self ._generate_linker_overrides (* self .rom )
695
+ return self ._generate_linker_overrides (self .get_all_active_memories ( ROM_ALL_MEMORIES ) )
663
696
664
697
@staticmethod
665
698
def header_member_size (member ):
@@ -696,7 +729,8 @@ def _assign_new_offset(rom_start, start, new_offset, region_name):
696
729
"Can not place % region inside previous region" % region_name )
697
730
return newstart
698
731
699
- def _generate_bootloader_build (self , rom_start , rom_size ):
732
+ def _generate_bootloader_build (self , rom_memories ):
733
+ rom_start , rom_size = rom_memories .get ('ROM' )
700
734
start = rom_start
701
735
rom_end = rom_start + rom_size
702
736
if self .target .bootloader_img :
@@ -780,7 +814,8 @@ def report(self):
780
814
return {'app_config' : self .app_config_location ,
781
815
'library_configs' : map (relpath , self .processed_configs .keys ())}
782
816
783
- def _generate_linker_overrides (self , rom_start , rom_size ):
817
+ def _generate_linker_overrides (self , rom_memories ):
818
+ rom_start , rom_size = rom_memories .get ('ROM' )
784
819
if self .target .mbed_app_start is not None :
785
820
start = int (self .target .mbed_app_start , 0 )
786
821
else :
0 commit comments