mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-31 03:07:21 +02:00
ldgen: allow checking mappings
This commit is contained in:
committed by
Angus Gratton
parent
fa7126b628
commit
04f6830b09
@ -80,7 +80,6 @@ class PlacementRule():
|
|||||||
def do_section_expansion(rule, section):
|
def do_section_expansion(rule, section):
|
||||||
if section in rule.get_section_names():
|
if section in rule.get_section_names():
|
||||||
sections_in_obj = sections_infos.get_obj_sections(rule.archive, rule.obj)
|
sections_in_obj = sections_infos.get_obj_sections(rule.archive, rule.obj)
|
||||||
|
|
||||||
expansions = fnmatch.filter(sections_in_obj, section)
|
expansions = fnmatch.filter(sections_in_obj, section)
|
||||||
return expansions
|
return expansions
|
||||||
|
|
||||||
@ -254,11 +253,18 @@ class GenerationModel:
|
|||||||
|
|
||||||
DEFAULT_SCHEME = "default"
|
DEFAULT_SCHEME = "default"
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, check_mappings=False, check_mapping_exceptions=None):
|
||||||
self.schemes = {}
|
self.schemes = {}
|
||||||
self.sections = {}
|
self.sections = {}
|
||||||
self.mappings = {}
|
self.mappings = {}
|
||||||
|
|
||||||
|
self.check_mappings = check_mappings
|
||||||
|
|
||||||
|
if check_mapping_exceptions:
|
||||||
|
self.check_mapping_exceptions = check_mapping_exceptions
|
||||||
|
else:
|
||||||
|
self.check_mapping_exceptions = []
|
||||||
|
|
||||||
def _add_mapping_rules(self, archive, obj, symbol, scheme_name, scheme_dict, rules):
|
def _add_mapping_rules(self, archive, obj, symbol, scheme_name, scheme_dict, rules):
|
||||||
# Use an ordinary dictionary to raise exception on non-existing keys
|
# Use an ordinary dictionary to raise exception on non-existing keys
|
||||||
temp_dict = dict(scheme_dict)
|
temp_dict = dict(scheme_dict)
|
||||||
@ -338,6 +344,14 @@ class GenerationModel:
|
|||||||
try:
|
try:
|
||||||
if not (obj == Mapping.MAPPING_ALL_OBJECTS and symbol is None and
|
if not (obj == Mapping.MAPPING_ALL_OBJECTS and symbol is None and
|
||||||
scheme_name == GenerationModel.DEFAULT_SCHEME):
|
scheme_name == GenerationModel.DEFAULT_SCHEME):
|
||||||
|
|
||||||
|
if self.check_mappings and mapping.name not in self.check_mapping_exceptions:
|
||||||
|
if not obj == Mapping.MAPPING_ALL_OBJECTS:
|
||||||
|
obj_section = sections_infos.get_obj_sections(archive, obj)
|
||||||
|
if not obj_section:
|
||||||
|
message = "'%s\:%s' not found" % (archive, obj)
|
||||||
|
raise GenerationException(message, mapping)
|
||||||
|
|
||||||
self._add_mapping_rules(archive, obj, symbol, scheme_name, scheme_dictionary, mapping_rules)
|
self._add_mapping_rules(archive, obj, symbol, scheme_name, scheme_dictionary, mapping_rules)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
message = GenerationException.UNDEFINED_REFERENCE + " to scheme '" + scheme_name + "'."
|
message = GenerationException.UNDEFINED_REFERENCE + " to scheme '" + scheme_name + "'."
|
||||||
@ -623,9 +637,12 @@ class SectionsInfo(dict):
|
|||||||
return results
|
return results
|
||||||
|
|
||||||
def get_obj_sections(self, archive, obj):
|
def get_obj_sections(self, archive, obj):
|
||||||
|
res = []
|
||||||
|
try:
|
||||||
stored = self.sections[archive]
|
stored = self.sections[archive]
|
||||||
|
|
||||||
# Parse the contents of the sections file
|
# Parse the contents of the sections file on-demand,
|
||||||
|
# save the result for later
|
||||||
if not isinstance(stored, dict):
|
if not isinstance(stored, dict):
|
||||||
parsed = self._get_infos_from_file(stored)
|
parsed = self._get_infos_from_file(stored)
|
||||||
stored = dict()
|
stored = dict()
|
||||||
@ -634,6 +651,17 @@ class SectionsInfo(dict):
|
|||||||
stored[content.object] = sections
|
stored[content.object] = sections
|
||||||
self.sections[archive] = stored
|
self.sections[archive] = stored
|
||||||
|
|
||||||
for obj_key in stored.keys():
|
try:
|
||||||
if obj_key == obj + ".o" or obj_key == obj + ".c.obj":
|
res = stored[obj + ".o"]
|
||||||
return stored[obj_key]
|
except KeyError:
|
||||||
|
try:
|
||||||
|
res = stored[obj + ".c.obj"]
|
||||||
|
except KeyError:
|
||||||
|
try:
|
||||||
|
res = stored[obj + ".cpp.obj"]
|
||||||
|
except KeyError:
|
||||||
|
res = stored[obj + ".S.obj"]
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return res
|
||||||
|
@ -75,6 +75,18 @@ def main():
|
|||||||
"--kconfig", "-k",
|
"--kconfig", "-k",
|
||||||
help="IDF Kconfig file")
|
help="IDF Kconfig file")
|
||||||
|
|
||||||
|
argparser.add_argument(
|
||||||
|
"--check-mapping",
|
||||||
|
help="Perform a check if a mapping (archive, obj, symbol) exists",
|
||||||
|
action='store_true'
|
||||||
|
)
|
||||||
|
|
||||||
|
argparser.add_argument(
|
||||||
|
"--check-mapping-exceptions",
|
||||||
|
help="Mappings exempted from check",
|
||||||
|
type=argparse.FileType("r")
|
||||||
|
)
|
||||||
|
|
||||||
argparser.add_argument(
|
argparser.add_argument(
|
||||||
"--env", "-e",
|
"--env", "-e",
|
||||||
action='append', default=[],
|
action='append', default=[],
|
||||||
@ -98,6 +110,12 @@ def main():
|
|||||||
kconfig_file = args.kconfig
|
kconfig_file = args.kconfig
|
||||||
objdump = args.objdump
|
objdump = args.objdump
|
||||||
|
|
||||||
|
check_mapping = args.check_mapping
|
||||||
|
if args.check_mapping_exceptions:
|
||||||
|
check_mapping_exceptions = [line.strip() for line in args.check_mapping_exceptions]
|
||||||
|
else:
|
||||||
|
check_mapping_exceptions = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
sections_infos = SectionsInfo()
|
sections_infos = SectionsInfo()
|
||||||
for library in libraries_file:
|
for library in libraries_file:
|
||||||
@ -107,7 +125,7 @@ def main():
|
|||||||
dump.name = library
|
dump.name = library
|
||||||
sections_infos.add_sections_info(dump)
|
sections_infos.add_sections_info(dump)
|
||||||
|
|
||||||
generation_model = GenerationModel()
|
generation_model = GenerationModel(check_mapping, check_mapping_exceptions)
|
||||||
|
|
||||||
_update_environment(args) # assign args.env and args.env_file to os.environ
|
_update_environment(args) # assign args.env and args.env_file to os.environ
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user