Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions docs/fw_binaries.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ explains what firmware and configuration options are needed for each SoC family.
A firmware configuration file for snagrecover has the following structure:

```
paths-relative-to: THIS_FILE
fw_1:
path: /path/to/fw_1
option1: value1
Expand All @@ -28,6 +29,20 @@ type of SoC you are using, you will probably want to configure your U-Boot build
so that it can interact with snagflash correctly after recovery (e.g. use DFU,
UMS or fastboot).

The key `paths-relative-to` is optional and indicates that paths to images are
relative to a specific path, either:

- `CWD`: the current working directory, e.g the default behaviour
- `THIS_FILE`: the directory containing the current configuration file
- a path to a directory.

If `THIS_FILE` or a path is specified, snagrecover will effectively join this
path and the images paths. `CWD` is actually a no-op and will keep the default
behaviour.
Absolute paths to images will not be modified by this option.

This is useful when distributing the configuration file alongside images.

## General tips on configuring U-Boot

In many cases, in can be necessary to build the recovery U-Boot yourself e.g.
Expand Down
27 changes: 22 additions & 5 deletions src/snagrecover/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -93,6 +94,20 @@ def check_soc_model(soc_model: str):
return None


def complete_fw_paths(fw_config: dict, this_file_path: str) -> None:
paths_relative_to_conf = fw_config.pop("paths-relative-to", "CWD")
if paths_relative_to_conf == "CWD":
return
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
Expand Down Expand Up @@ -138,11 +153,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}"
)
complete_fw_paths(fw_config_file, path)
fw_configs = {**fw_configs, **fw_config_file}
recovery_config["firmware"] = fw_configs

# store input arguments in config
Expand Down