-
Notifications
You must be signed in to change notification settings - Fork 28
config: Support MBED_ROM_START and friends #270
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add support for MBED_ROM_START, MBED_ROM_SIZE, MBED_RAM_START and MBED_RAM_SIZE in config system. |
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 |
---|---|---|
|
@@ -28,8 +28,8 @@ def prepare( | |
) -> dict: | ||
"""Prepare a config source for entry into the Config object. | ||
|
||
Extracts config and override settings from the source. Flattens these nested dictionaries out into lists of | ||
objects which are namespaced in the way the Mbed config system expects. | ||
Extracts memory, config and override settings from the source. Flattens these nested dictionaries out into | ||
lists of objects which are namespaced in the way the Mbed config system expects. | ||
|
||
Args: | ||
input_data: The raw config JSON object parsed from the config file. | ||
|
@@ -46,6 +46,11 @@ def prepare( | |
for key in data: | ||
data[key] = _sanitise_value(data[key]) | ||
|
||
memories = _extract_memories(namespace, data) | ||
|
||
if memories: | ||
data["memories"] = memories | ||
|
||
if "config" in data: | ||
data["config"] = _extract_config_settings(namespace, data["config"]) | ||
|
||
|
@@ -78,6 +83,31 @@ def __post_init__(self) -> None: | |
self.value = _sanitise_value(self.value) | ||
|
||
|
||
@dataclass | ||
class Memory: | ||
"""Representation of a defined RAM/ROM region.""" | ||
|
||
name: str | ||
namespace: str | ||
start: str | ||
size: str | ||
|
||
def __post_init__(self) -> None: | ||
"""Convert start and size to hex format strings.""" | ||
try: | ||
self.start = hex(int(self.start, 0)) | ||
except ValueError: | ||
raise ValueError( | ||
f"Value of MBED_{self.name}_START in {self.namespace}, {self.start} is invalid: must be an integer" | ||
) | ||
try: | ||
self.size = hex(int(self.size, 0)) | ||
except ValueError: | ||
raise ValueError( | ||
f"Value of MBED_{self.name}_SIZE in {self.namespace}, {self.size} is invalid: must be an integer" | ||
) | ||
|
||
|
||
@dataclass | ||
class Override: | ||
"""Representation of a config override. | ||
|
@@ -128,6 +158,27 @@ def _extract_config_settings(namespace: str, config_data: dict) -> List[ConfigSe | |
return settings | ||
|
||
|
||
def _extract_memories(namespace: str, data: dict) -> List[Memory]: | ||
memories = [] | ||
for mem in ["rom", "ram"]: | ||
start_attr = f"mbed_{mem}_start" | ||
size_attr = f"mbed_{mem}_size" | ||
start = data.get(start_attr) | ||
size = data.get(size_attr) | ||
|
||
if size is not None and start is not None: | ||
logger.debug(f"Extracting MBED_{mem.upper()} definitions in {namespace}: _START={start}, _SIZE={size}.") | ||
|
||
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. The line spacing here seems a little off. We should probably remove this blank line. |
||
memory = Memory(mem.upper(), namespace, start, size) | ||
memories.append(memory) | ||
elif start is not None or size is not None: | ||
raise ValueError( | ||
f"{size_attr.upper()} and {start_attr.upper()} must be defined together. Only " | ||
f"{'START' if start is not None else 'SIZE'} is defined in the lib {namespace}." | ||
) | ||
return memories | ||
|
||
|
||
def _extract_target_overrides( | ||
namespace: str, override_data: dict, allowed_target_labels: Iterable[str] | ||
) -> List[Override]: | ||
|
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
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.
Uh oh!
There was an error while loading. Please reload this page.