|
17 | 17 | # along with this program; if not, write to the Free Software |
18 | 18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
19 | 19 |
|
| 20 | +import os |
20 | 21 | import yaml |
21 | 22 | from snagrecover.utils import ( |
22 | 23 | cli_error, |
@@ -93,6 +94,22 @@ def check_soc_model(soc_model: str): |
93 | 94 | return None |
94 | 95 |
|
95 | 96 |
|
| 97 | +def complete_fw_paths(fw_config: dict, this_file_path: str) -> None: |
| 98 | + paths_relative_to_conf = fw_config.pop("paths-relative-to", "CWD") |
| 99 | + if paths_relative_to_conf == "CWD": |
| 100 | + return |
| 101 | + elif paths_relative_to_conf == "THIS_FILE": |
| 102 | + path_relative_to = os.path.dirname(this_file_path) |
| 103 | + else: |
| 104 | + path_relative_to = path_relative_to_conf |
| 105 | + |
| 106 | + for binary in fw_config.keys(): |
| 107 | + if "path" in fw_config[binary]: |
| 108 | + fw_config[binary]["path"] = os.path.join( |
| 109 | + path_relative_to, fw_config[binary]["path"] |
| 110 | + ) |
| 111 | + |
| 112 | + |
96 | 113 | def init_config(args: list): |
97 | 114 | # this is the only time that config.recovery_config should be modified! |
98 | 115 | # get soc model |
@@ -138,11 +155,13 @@ def init_config(args: list): |
138 | 155 | # get firmware configs |
139 | 156 | for path in args.firmware_file: |
140 | 157 | with open(path, "r") as file: |
141 | | - fw_configs = {**fw_configs, **yaml.safe_load(file)} |
142 | | - if not isinstance(fw_configs, dict): |
143 | | - cli_error( |
144 | | - f"firmware config passed to CLI did not evaluate to dict: {fw_configs}" |
145 | | - ) |
| 158 | + fw_config_file = yaml.safe_load(file) |
| 159 | + if not isinstance(fw_config_file, dict): |
| 160 | + cli_error( |
| 161 | + f"firmware config passed to CLI did not evaluate to dict: {fw_config_file}" |
| 162 | + ) |
| 163 | + complete_fw_paths(fw_config_file, path) |
| 164 | + fw_configs = {**fw_configs, **fw_config_file} |
146 | 165 | recovery_config["firmware"] = fw_configs |
147 | 166 |
|
148 | 167 | # store input arguments in config |
|
0 commit comments