From 2c74d21213e2bc017772a8b52c992baaae3eec45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Wed, 23 Jul 2025 13:39:34 +0200 Subject: [PATCH 1/2] snagrecover: config: Check if each fw_config is a dict instead of the final fw_configs fw_configs will always be a dictionnary, but individual ones might not. --- src/snagrecover/config.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/snagrecover/config.py b/src/snagrecover/config.py index bcb4f9e..f07c327 100644 --- a/src/snagrecover/config.py +++ b/src/snagrecover/config.py @@ -122,11 +122,12 @@ 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_configs = {**fw_configs, **fw_config_file} recovery_config["firmware"] = fw_configs # store input arguments in config From a3804c337b094f5417e09dca95132c6743986654 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Wed, 23 Jul 2025 13:42:14 +0200 Subject: [PATCH 2/2] snagrecover: config: Allow a 'paths-relative-to' key in the firmware configs paths-relative-to can be CWD, THIS_FILE, or a literal path. It defaults to CWD. The firmware configs will be patched accordingly: binary paths will be prefixed by either the current working directory (this is the old behaviour), the directory containing the firmware config file, or the literal path. --- src/snagrecover/config.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/snagrecover/config.py b/src/snagrecover/config.py index f07c327..7dda5cf 100644 --- a/src/snagrecover/config.py +++ b/src/snagrecover/config.py @@ -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") + if paths_relative_to_conf == "CWD": + path_relative_to = os.getcwd() + 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 @@ -127,6 +142,7 @@ def init_config(args: list): 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) fw_configs = {**fw_configs, **fw_config_file} recovery_config["firmware"] = fw_configs