-
Notifications
You must be signed in to change notification settings - Fork 49
Allow a 'paths-relative-to' key in the firmware config #70
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
# along with this program; if not, write to the Free Software | ||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
|
||
import os | ||
import yaml | ||
from snagrecover.utils import ( | ||
cli_error, | ||
|
@@ -76,6 +77,20 @@ def check_soc_model(soc_model: str): | |
return None | ||
|
||
|
||
def patch_firmware_image_paths(fw_config: dict, this_file_path: str) -> dict: | ||
paths_relative_to_conf = fw_config.pop("paths-relative-to", "CWD") | ||
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. This is a user interface change, so it needs to be documented. You can describe this configuration option in docs/fw_binaries.md, in the introduction section. |
||
if paths_relative_to_conf == "CWD": | ||
path_relative_to = os.getcwd() | ||
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. As mentioned in your PR message, I'd prefer we didn't modify the path at all if "CWD" is specified. I'm pretty sure it wouldn't change anything but I'd rather not take an unnecessary risk. |
||
elif paths_relative_to_conf == "THIS_FILE": | ||
path_relative_to = os.path.dirname(this_file_path) | ||
else: | ||
path_relative_to = path_relative_to_conf | ||
|
||
for binary in fw_config.keys(): | ||
if "path" in fw_config[binary]: | ||
fw_config[binary]["path"] = os.path.join(path_relative_to, fw_config[binary]["path"]) | ||
|
||
|
||
def init_config(args: list): | ||
# this is the only time that config.recovery_config should be modified! | ||
# get soc model | ||
|
@@ -122,11 +137,13 @@ def init_config(args: list): | |
# get firmware configs | ||
for path in args.firmware_file: | ||
with open(path, "r") as file: | ||
fw_configs = {**fw_configs, **yaml.safe_load(file)} | ||
if not isinstance(fw_configs, dict): | ||
cli_error( | ||
f"firmware config passed to CLI did not evaluate to dict: {fw_configs}" | ||
) | ||
fw_config_file = yaml.safe_load(file) | ||
if not isinstance(fw_config_file, dict): | ||
cli_error( | ||
f"firmware config passed to CLI did not evaluate to dict: {fw_configs}" | ||
) | ||
fw_config_file = patch_firmware_image_paths(fw_config_file, path) | ||
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. nit: I'd prefer "complete_fw_paths()" |
||
fw_configs = {**fw_configs, **fw_config_file} | ||
recovery_config["firmware"] = fw_configs | ||
|
||
# store input arguments in config | ||
|
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.
This function doesn't actually need to return anything. It just modifies the dict in-place.