Commit Graph

16 Commits

Author SHA1 Message Date
Christophe Dufaza 2b2a0e04b2 west: blobs: verify fetched blobs after downloading
Running 'west blobs fetch' does not verify the digest of downloaded files:
1. if the checksum of the previously downloaded file does match
   that in the blob metadata (status BLOB_PRESENT), do nothing
2. if the checksum of the previously downloaded file does not match
   that in the blob metadata (status BLOB_OUTDATED),
   download the "up to date" file
3. if the blob has not yet been downloaded (status BLOB_NOT_PRESENT),
   download it

None of the 2) and 3) code paths will verify that the checksum of the file
just downloaded actually matches the digest in the blob's metadata.

In the event that the metadata of a module is incorrect, then the user
will not notice anything, and may rely on an unexpected binary,
e.g. a static library for a different architecture.

According to the Binary Blobs documentation [1], the expected
behavior is to check the blob digest after downloading.

[1] Fetching blobs, Zephyr 3.6.0 (still applies to Zephyr 3.7.0rc3)
docs.zephyrproject.org/3.6.0/contribute/bin_blobs.html#fetching-blobs

Signed-off-by: Christophe Dufaza <chris@openmarl.org>
2024-07-30 18:29:39 +01:00
Christophe Dufaza ae9326c920 west: blobs: prefer constants to literals for blob status
Replace blob status literals with the corresponding
constants defined in zephyr_module.

Signed-off-by: Christophe Dufaza <chris@openmarl.org>
2024-07-30 18:29:39 +01:00
Carles Cufi 37ec117386 scripts: west: blobs: Check for existence of modules
Instead of blindly using the module names provided by the user via
command-line arguments, check if those actually exist in the current
manifest, and error out if any of them does not.

Fixes #73901.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2024-06-12 12:50:12 -04:00
Carles Cufi b662bc9093 scripts: modules: Move blob processing to zephyr_module.py
In preparation for the handling of taint flags in zephyr_module.py, move
blob-processing code from the west command to it.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2022-08-29 15:57:59 +02:00
Carles Cufi 25db534a07 west: blobs: Finally fix the --format option handling
Turns out that `Namespace.format` was not a good fix to the issue
described in f033040812, it was returning
the default format even when the user specified -f/--format.

Replace "getattr" with a simple logical operation.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2022-08-24 17:31:24 +02:00
Carles Cufi f033040812 west: blobs: Fix --format handling
There were two issues with the original commit
e04487cad2b98385c850fa478e1d1ca97bf0e836:

- getattr() doesn't seem to work properly with args
- Comparison between bound methods with "is" seems not to work, so
  replace it with a simpler string comparison

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2022-08-24 07:38:42 -07:00
Martí Bolívar 21214cc83f west blobs: decrease verbosity
Make some no-op log messages require 'west -v blobs ...'.

The current implementation won't scale as the number of blobs goes up.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2022-08-22 16:37:07 +00:00
Martí Bolívar e04487cad2 west blobs: fix --format handling
This option does not apply to 'west blobs clean' or 'west blobs
fetch'. Error out if it is given to either of those.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2022-08-22 16:37:07 +00:00
Martí Bolívar b4c4736fb0 west blobs: tweak --format help
Make it consistent with the usual argparse style by using lower case
and no period at the end.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2022-08-22 16:37:07 +00:00
Martí Bolívar a3f4edb127 west blobs: fix modules help
The help text is mixing up 'blobs' with 'modules', and doesn't
document the new behavior that uses all modules when nothing is
mentioned. Fix both issues.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2022-08-22 16:37:07 +00:00
Martí Bolívar 3b84dff0a5 west blobs: fix subcmd help
Without this patch, "west blobs -h" says:

  {list,fetch,clean} Select the sub-command to execute. Sub-commands
  available: - list: list binary blobs - fetch: fetch and store binary
  blobs - clean: remove fetched binary blobs

With this patch:

  {list,fetch,clean}    sub-command to execute

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2022-08-22 16:37:07 +00:00
Carles Cufi 0424509d6e west: blobs: Ensure that folder exists before fetching
The `<module>/zephyr/blobs/` folder, as well as any additional
sub-folders that might be required under `blobs/` may not exist when
fetching a blob. Ensure that the folder exists, create it if it doesn't.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2022-08-18 15:25:43 +00:00
Carles Cufi 5524f7a950 west: blobs: Add a clean sub-command
The new "clean" blobs sub-command deletes any blobs present on the
filesystem.

Also improve the help text for sub-commands.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2022-08-18 15:25:43 +00:00
Carles Cufi 02c95c64fe west: blobs: Rework the -m option
To align with other commands, such as "west update", convert the
accumulative -m option into an nargs="*"-type one that takes the list of
modules directly without a flag.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2022-08-18 15:25:43 +00:00
Carles Cufi 389af0885c west: blobs: Default to listing and fetching all blobs
Instead of both listing and fetching only the blobs in the
modules listed by the user in the command-line, default to
listing/fetching them all for ease-of-use and consistency with other
commands. Remove the --all options since it's meaningless now.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2022-08-18 15:25:43 +00:00
Carles Cufi 336aa9dc88 modules: Basic binary blob infrastructure
This patch introduces the basic infrastructure to list and fetch binary
blobs. This includes:

- The new 'blobs' extension command
- An implementation of the `west blobs list` command
  with custom formatting
- A very simple mechanism for loading fetchers
- A basic implementation of an HTTP fetcher

In order to ensure consistency among the west extension commands in the
main zephyr tree, we reuse a similar class factory pattern that is present
for ZephyrBinaryRunner instances in the ZephyrBlobFetcher case. This
could be achieved with a simpler mechanism, but opted for consistency
before simplicity.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2022-08-16 05:59:02 -07:00