Skip to content

Commit 27f20c7

Browse files
committed
Fetch RAM/ROM information from CMSIS pack and add as defines
RAM/ROM memory data of target is required for statistics and linker files, goal here is to fetch maximum 4 RAM/ROM regions from CMSIS pack and make them available for C/C++/Linker flags as defines
1 parent 8a5b9ff commit 27f20c7

File tree

2 files changed

+75
-24
lines changed

2 files changed

+75
-24
lines changed

tools/config/__init__.py

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@
7171
"ETHERNET_HOST",
7272
]
7373

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+
7481
# Base class for all configuration exceptions
7582
class ConfigException(Exception):
7683
"""Config system only exception. Makes it easier to distinguish config
@@ -610,24 +617,50 @@ def _get_mem_specs(self, memories, cmsis_part, exception_text):
610617
continue
611618
raise ConfigException(exception_text)
612619

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"""
616624
# Override rom_start/rom_size
617625
#
618626
# This is usually done for a target which:
619627
# 1. Doesn't support CMSIS pack, or
620628
# 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'
621635
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
631664

632665
@property
633666
def ram_regions(self):
@@ -653,13 +686,13 @@ def regions(self):
653686
if ((self.target.bootloader_img or self.target.restrict_size) and
654687
(self.target.mbed_app_start or self.target.mbed_app_size)):
655688
raise ConfigException(
656-
"target.bootloader_img and target.restirct_size are "
689+
"target.bootloader_img and target.restrict_size are "
657690
"incompatible with target.mbed_app_start and "
658691
"target.mbed_app_size")
659692
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))
661694
else:
662-
return self._generate_linker_overrides(*self.rom)
695+
return self._generate_linker_overrides(self.get_all_active_memories(ROM_ALL_MEMORIES))
663696

664697
@staticmethod
665698
def header_member_size(member):
@@ -696,7 +729,8 @@ def _assign_new_offset(rom_start, start, new_offset, region_name):
696729
"Can not place % region inside previous region" % region_name)
697730
return newstart
698731

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')
700734
start = rom_start
701735
rom_end = rom_start + rom_size
702736
if self.target.bootloader_img:
@@ -780,7 +814,8 @@ def report(self):
780814
return {'app_config': self.app_config_location,
781815
'library_configs': map(relpath, self.processed_configs.keys())}
782816

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')
784819
if self.target.mbed_app_start is not None:
785820
start = int(self.target.mbed_app_start, 0)
786821
else:

tools/toolchains/__init__.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
from ..notifier.term import TerminalNotifier
4141
from ..resources import FileType
4242
from ..memap import MemapParser
43-
from ..config import ConfigException
43+
from ..config import (ConfigException, RAM_ALL_MEMORIES, ROM_ALL_MEMORIES)
4444

4545

4646
#Disables multiprocessing if set to higher number than the host machine CPUs
@@ -732,13 +732,29 @@ def add_regions(self):
732732
", ".join(r.name for r in regions)
733733
))
734734
self._add_all_regions(regions, "MBED_RAM")
735+
736+
Region = namedtuple("Region", "name start size")
737+
738+
try:
739+
# Add all available ROM regions to build profile
740+
rom_available_regions = self.config.get_all_active_memories(ROM_ALL_MEMORIES)
741+
for key, value in rom_available_regions.items():
742+
rom_start, rom_size = value
743+
self._add_defines_from_region(
744+
Region("MBED_" + key, rom_start, rom_size),
745+
suffixes=["_START", "_SIZE"]
746+
)
747+
except ConfigException:
748+
pass
735749
try:
736-
rom_start, rom_size = self.config.rom
737-
Region = namedtuple("Region", "name start size")
738-
self._add_defines_from_region(
739-
Region("MBED_ROM", rom_start, rom_size),
740-
suffixes=["_START", "_SIZE"]
741-
)
750+
# Add all available RAM regions to build profile
751+
ram_available_regions = self.config.get_all_active_memories(RAM_ALL_MEMORIES)
752+
for key, value in ram_available_regions.items():
753+
ram_start, ram_size = value
754+
self._add_defines_from_region(
755+
Region("MBED_" + key, ram_start, ram_size),
756+
suffixes=["_START", "_SIZE"]
757+
)
742758
except ConfigException:
743759
pass
744760

0 commit comments

Comments
 (0)