-
Notifications
You must be signed in to change notification settings - Fork 3k
Fetch ram/rom start/size #8607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Fetch ram/rom start/size #8607
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
27f20c7
Fetch RAM/ROM information from CMSIS pack and add as defines
aashishc1988 3956451
Fixing some corner cases
aashishc1988 1627968
Missed one change to convert into right data type
aashishc1988 ad736e9
Add RAM/ROM memory statistics to system stats structure
e3c4dae
Add tests to verify RAM/ROM sizes
0c594a4
The check for managed bootloader support should be in regions and we …
aashishc1988 329c553
ifdef ram/rom size/start in case they dont exist
aashishc1988 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,6 +71,14 @@ | |
"ETHERNET_HOST", | ||
] | ||
|
||
# List of all possible ram memories that can be available for a target | ||
RAM_ALL_MEMORIES = ['IRAM1', 'IRAM2', 'IRAM3', 'IRAM4', 'SRAM_OC', \ | ||
'SRAM_ITC', 'SRAM_DTC', 'SRAM_UPPER', 'SRAM_LOWER', \ | ||
'SRAM'] | ||
|
||
# List of all possible rom memories that can be available for a target | ||
ROM_ALL_MEMORIES = ['IROM1', 'PROGRAM_FLASH', 'IROM2'] | ||
|
||
# Base class for all configuration exceptions | ||
class ConfigException(Exception): | ||
"""Config system only exception. Makes it easier to distinguish config | ||
|
@@ -588,8 +596,6 @@ def sectors(self): | |
raise ConfigException("No sector info available") | ||
|
||
def _get_cmsis_part(self): | ||
if not getattr(self.target, "bootloader_supported", False): | ||
raise ConfigException("Bootloader not supported on this target.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got rid of this and added this to regions property |
||
if not hasattr(self.target, "device_name"): | ||
raise ConfigException("Bootloader not supported on this target: " | ||
"targets.json `device_name` not specified.") | ||
|
@@ -610,24 +616,68 @@ def _get_mem_specs(self, memories, cmsis_part, exception_text): | |
continue | ||
raise ConfigException(exception_text) | ||
|
||
@property | ||
def rom(self): | ||
"""Get rom information as a pair of start_addr, size""" | ||
def get_all_active_memories(self, memory_list): | ||
"""Get information of all available rom/ram memories in the form of dictionary | ||
{Memory: [start_addr, size]}. Takes in the argument, a list of all available | ||
regions within the ram/rom memory""" | ||
# Override rom_start/rom_size | ||
# | ||
# This is usually done for a target which: | ||
# 1. Doesn't support CMSIS pack, or | ||
# 2. Supports TrustZone and user needs to change its flash partition | ||
cmsis_part = self._get_cmsis_part() | ||
rom_start, rom_size = self._get_mem_specs( | ||
["IROM1", "PROGRAM_FLASH"], | ||
cmsis_part, | ||
"Not enough information in CMSIS packs to build a bootloader " | ||
"project" | ||
) | ||
rom_start = int(getattr(self.target, "mbed_rom_start", False) or rom_start, 0) | ||
rom_size = int(getattr(self.target, "mbed_rom_size", False) or rom_size, 0) | ||
return (rom_start, rom_size) | ||
|
||
available_memories = {} | ||
# Counter to keep track of ROM/RAM memories supported by target | ||
active_memory_counter = 0 | ||
# Find which memory we are dealing with, RAM/ROM | ||
active_memory = 'ROM' if any('ROM' in mem_list for mem_list in memory_list) else 'RAM' | ||
|
||
try: | ||
aashishc1988 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
cmsis_part = self._get_cmsis_part() | ||
except ConfigException: | ||
""" If the target doesn't exits in cmsis, but present in targets.json | ||
with ram and rom start/size defined""" | ||
if getattr(self.target, "mbed_ram_start") and \ | ||
getattr(self.target, "mbed_rom_start"): | ||
mem_start = int(getattr(self.target, "mbed_" + active_memory.lower() + "_start"), 0) | ||
mem_size = int(getattr(self.target, "mbed_" + active_memory.lower() + "_size"), 0) | ||
available_memories[active_memory] = [mem_start, mem_size] | ||
return available_memories | ||
else: | ||
raise ConfigException("Bootloader not supported on this target. " | ||
"ram/rom start/size not found in " | ||
"targets.json.") | ||
|
||
present_memories = set(cmsis_part['memory'].keys()) | ||
valid_memories = set(memory_list).intersection(present_memories) | ||
|
||
for memory in valid_memories: | ||
mem_start, mem_size = self._get_mem_specs( | ||
[memory], | ||
cmsis_part, | ||
"Not enough information in CMSIS packs to build a bootloader " | ||
"project" | ||
aashishc1988 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
if memory=='IROM1' or memory=='PROGRAM_FLASH': | ||
mem_start = getattr(self.target, "mbed_rom_start", False) or mem_start | ||
mem_size = getattr(self.target, "mbed_rom_size", False) or mem_size | ||
memory = 'ROM' | ||
elif memory == 'IRAM1' or memory == 'SRAM_OC' or \ | ||
memory == 'SRAM_UPPER' or memory == 'SRAM': | ||
if (self.has_ram_regions): | ||
continue | ||
mem_start = getattr(self.target, "mbed_ram_start", False) or mem_start | ||
mem_size = getattr(self.target, "mbed_ram_size", False) or mem_size | ||
memory = 'RAM' | ||
else: | ||
active_memory_counter += 1 | ||
memory = active_memory + str(active_memory_counter) | ||
|
||
mem_start = int(mem_start, 0) | ||
mem_size = int(mem_size, 0) | ||
available_memories[memory] = [mem_start, mem_size] | ||
|
||
return available_memories | ||
|
||
@property | ||
def ram_regions(self): | ||
|
@@ -649,17 +699,19 @@ def ram_regions(self): | |
|
||
@property | ||
def regions(self): | ||
if not getattr(self.target, "bootloader_supported", False): | ||
raise ConfigException("Bootloader not supported on this target.") | ||
"""Generate a list of regions from the config""" | ||
if ((self.target.bootloader_img or self.target.restrict_size) and | ||
(self.target.mbed_app_start or self.target.mbed_app_size)): | ||
raise ConfigException( | ||
"target.bootloader_img and target.restirct_size are " | ||
"target.bootloader_img and target.restrict_size are " | ||
aashishc1988 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"incompatible with target.mbed_app_start and " | ||
"target.mbed_app_size") | ||
if self.target.bootloader_img or self.target.restrict_size: | ||
return self._generate_bootloader_build(*self.rom) | ||
return self._generate_bootloader_build(self.get_all_active_memories(ROM_ALL_MEMORIES)) | ||
else: | ||
return self._generate_linker_overrides(*self.rom) | ||
return self._generate_linker_overrides(self.get_all_active_memories(ROM_ALL_MEMORIES)) | ||
|
||
@staticmethod | ||
def header_member_size(member): | ||
|
@@ -696,7 +748,8 @@ def _assign_new_offset(rom_start, start, new_offset, region_name): | |
"Can not place % region inside previous region" % region_name) | ||
return newstart | ||
|
||
def _generate_bootloader_build(self, rom_start, rom_size): | ||
def _generate_bootloader_build(self, rom_memories): | ||
rom_start, rom_size = rom_memories.get('ROM') | ||
start = rom_start | ||
rom_end = rom_start + rom_size | ||
if self.target.bootloader_img: | ||
|
@@ -780,7 +833,8 @@ def report(self): | |
return {'app_config': self.app_config_location, | ||
'library_configs': map(relpath, self.processed_configs.keys())} | ||
|
||
def _generate_linker_overrides(self, rom_start, rom_size): | ||
def _generate_linker_overrides(self, rom_memories): | ||
rom_start, rom_size = rom_memories.get('ROM') | ||
if self.target.mbed_app_start is not None: | ||
start = int(self.target.mbed_app_start, 0) | ||
else: | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,7 @@ | |
from ..notifier.term import TerminalNotifier | ||
from ..resources import FileType | ||
from ..memap import MemapParser | ||
from ..config import ConfigException | ||
from ..config import (ConfigException, RAM_ALL_MEMORIES, ROM_ALL_MEMORIES) | ||
|
||
|
||
#Disables multiprocessing if set to higher number than the host machine CPUs | ||
|
@@ -693,14 +693,19 @@ def mem_stats(self, map): | |
|
||
return None | ||
|
||
def _add_defines_from_region(self, region, suffixes=['_ADDR', '_SIZE']): | ||
def _add_defines_from_region(self, region, linker_define=False, suffixes=['_ADDR', '_SIZE']): | ||
for define in [(region.name.upper() + suffixes[0], region.start), | ||
(region.name.upper() + suffixes[1], region.size)]: | ||
define_string = "-D%s=0x%x" % define | ||
self.cc.append(define_string) | ||
self.cppc.append(define_string) | ||
self.flags["common"].append(define_string) | ||
|
||
if linker_define: | ||
ld_string = ("%s" % define[0], "0x%x" % define[1]) | ||
ld_string = self.make_ld_define(*ld_string) | ||
self.ld.append(ld_string) | ||
self.flags["ld"].append(ld_string) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding linker defines where needed. |
||
def _add_all_regions(self, region_list, active_region_name): | ||
for region in region_list: | ||
self._add_defines_from_region(region) | ||
|
@@ -719,26 +724,51 @@ def add_regions(self): | |
"""Add regions to the build profile, if there are any. | ||
""" | ||
if self.config.has_regions: | ||
regions = list(self.config.regions) | ||
self.notify.info("Using ROM region%s %s in this build." % ( | ||
"s" if len(regions) > 1 else "", | ||
", ".join(r.name for r in regions) | ||
)) | ||
self._add_all_regions(regions, "MBED_APP") | ||
try: | ||
regions = list(self.config.regions) | ||
self.notify.info("Using ROM region%s %s in this build." % ( | ||
"s" if len(regions) > 1 else "", | ||
", ".join(r.name for r in regions) | ||
)) | ||
self._add_all_regions(regions, "MBED_APP") | ||
except ConfigException: | ||
pass | ||
|
||
if self.config.has_ram_regions: | ||
regions = list(self.config.ram_regions) | ||
self.notify.info("Using RAM region%s %s in this build." % ( | ||
"s" if len(regions) > 1 else "", | ||
", ".join(r.name for r in regions) | ||
)) | ||
self._add_all_regions(regions, "MBED_RAM") | ||
try: | ||
regions = list(self.config.ram_regions) | ||
self.notify.info("Using RAM region%s %s in this build." % ( | ||
"s" if len(regions) > 1 else "", | ||
", ".join(r.name for r in regions) | ||
)) | ||
self._add_all_regions(regions, "MBED_RAM") | ||
except ConfigException: | ||
pass | ||
|
||
Region = namedtuple("Region", "name start size") | ||
|
||
try: | ||
# Add all available ROM regions to build profile | ||
rom_available_regions = self.config.get_all_active_memories(ROM_ALL_MEMORIES) | ||
for key, value in rom_available_regions.items(): | ||
rom_start, rom_size = value | ||
self._add_defines_from_region( | ||
Region("MBED_" + key, rom_start, rom_size), | ||
True, | ||
suffixes=["_START", "_SIZE"] | ||
) | ||
except ConfigException: | ||
pass | ||
try: | ||
rom_start, rom_size = self.config.rom | ||
Region = namedtuple("Region", "name start size") | ||
self._add_defines_from_region( | ||
Region("MBED_ROM", rom_start, rom_size), | ||
suffixes=["_START", "_SIZE"] | ||
) | ||
# Add all available RAM regions to build profile | ||
ram_available_regions = self.config.get_all_active_memories(RAM_ALL_MEMORIES) | ||
for key, value in ram_available_regions.items(): | ||
ram_start, ram_size = value | ||
self._add_defines_from_region( | ||
Region("MBED_" + key, ram_start, ram_size), | ||
True, | ||
suffixes=["_START", "_SIZE"] | ||
) | ||
except ConfigException: | ||
pass | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added SRAM