Add Rom config info getter and rom defines

* MBED_ROM_START = start of current rom (independent of BL modes)
 * MBED_ROM_SIZE = size of current rom (independent of BL modes)
pull/7133/head
Jimmy Brisson 2018-06-20 10:47:04 -05:00
parent 92abbb7599
commit 52e640fc1d
2 changed files with 35 additions and 19 deletions

View File

@ -593,6 +593,25 @@ class Config(object):
continue
raise ConfigException(exception_text)
@property
def rom(self):
"""Get rom information as a pair of start_addr, size"""
# 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)
@property
def ram_regions(self):
"""Generate a list of ram regions from the config"""
@ -614,30 +633,16 @@ class Config(object):
@property
def regions(self):
"""Generate a list of regions from the config"""
cmsis_part = self._get_cmsis_part()
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 "
"incompatible with target.mbed_app_start and "
"target.mbed_app_size")
rom_start, rom_size = self._get_mem_specs(
["IROM1", "PROMGRAM_FLASH"],
cmsis_part,
"Not enough information in CMSIS packs to build a bootloader project"
)
# 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
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)
if self.target.bootloader_img or self.target.restrict_size:
return self._generate_bootloader_build(rom_start, rom_size)
return self._generate_bootloader_build(*self.rom)
else:
return self._generate_linker_overrides(rom_start, rom_size)
return self._generate_linker_overrides(*self.rom)
@staticmethod
def header_member_size(member):

View File

@ -27,6 +27,7 @@ from os.path import (join, splitext, exists, relpath, dirname, basename, split,
from itertools import chain
from inspect import getmro
from copy import deepcopy
from collections import namedtuple
from abc import ABCMeta, abstractmethod
from distutils.spawn import find_executable
from multiprocessing import Pool, cpu_count
@ -39,6 +40,7 @@ from ..settings import MBED_ORG_USER, PRINT_COMPILER_OUTPUT_AS_LINK
from .. import hooks
from ..notifier.term import TerminalNotifier
from ..memap import MemapParser
from ..config import ConfigException
#Disables multiprocessing if set to higher number than the host machine CPUs
@ -1184,9 +1186,9 @@ class mbedToolchain:
return None
def _add_defines_from_region(self, region):
for define in [(region.name.upper() + "_ADDR", region.start),
(region.name.upper() + "_SIZE", region.size)]:
def _add_defines_from_region(self, region, 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)
@ -1223,6 +1225,15 @@ class mbedToolchain:
", ".join(r.name for r in regions)
))
self._add_all_regions(regions, "MBED_RAM")
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"]
)
except ConfigException:
pass
# Set the configuration data
def set_config_data(self, config_data):