imports: Make imports/ follow Chromium flashrom

This commit makes ap_wpsr follow the Chromium flashrom instead of
following the upstream flashrom database. This addresses inconsistencies
between the ap_wpsr and flashrom databases, which have led to issues
like the one described in b/340421736 in nissa factory branch.

This change simplifies development and reduces the risk of introducing
regressions when updating the flashrom databases, especially for factory
branches.

This change is intended to affect the main branch only, there will be
further changes related to modify the ap_wpsr imports/ in other factory
branches.

Imported from flashrom snapshot: b243d7fffc9885d18072f3e27ec2ebbd662101ba

BUG=b:362686439
TEST=change to ToT, diff the ap_wpsr and flashrom databases.

Cq-Depend: chromium:5808523
Cq-Depend: chromium:6017465
Cq-Depend: chromium:6017466
Cq-Depend: chromium:6005886
Cq-Depend: chromium:6011519
Cq-Depend: chromium:6022541
Change-Id: I888b4e21a900175be41f191c6c8f6dbe8399702e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/ap_wpsr/+/6096941
Tested-by: Hsuan Ting Chen <[email protected]>
Reviewed-by: Jian-Jia Su <[email protected]>
Commit-Queue: Hsuan Ting Chen <[email protected]>
6 files changed
tree: 6bc663191b672208c234521e5acad119b770f822
  1. imports/
  2. shim/
  3. COPYING
  4. DIR_METADATA
  5. main.c
  6. meson.build
  7. OWNERS
  8. README.md
README.md

ap_wpsr tool

The ap_wpsr tool was built to address specific requirements of AP RO verification that intends to measure SR contents for invariance after signature validation.

The tool leverages the flashrom SPI flash chips database to produce theoretical mask,value pairs for a given WP configuration (i.e. protection range start and length) and flash chip part name.

limitations

There are however some limitations. While the tool is pure logic (no side-effects) and intended to calculate values with reasonable fidelity there could however be inaccuracies.

These inaccuracies can be the result of any combination of the following factors:

  • Incorrect writeprotoct SR topology data within the database.
  • Duplicate chips or otherwise ambiguous chip identifiers (id or string name).
  • OTP fused values within the SPI flash chip itself.

A precise flash chip name is required to be cited physically on what chip is being worked with (and not via probing or other inferences). This precise name needs to be mapped to the corresponding name within the database to produce the tool output products. The output products must be cross-validated with the datasheet to ensure the products are consistent with expectations and any errors in the database are corrected with a patch back to the canonical flashrom flashchips database upstream.

usage

An example usage could be ./ap_wpsr -n "W25Q128.V" -s 0x40000 -l 0xFC0000.

finding chip names

The ap_wpsr tool needs to be given the name of the flashrom chip entry to use for calculating mask,value pairs. This name may not match the vendor name, for example the chip “W25Q128FVSIG” corresponds to a flashrom entry called “W25Q128.V”.

These steps should be followed to find the flashrom chip name for your chip:

  • Check the chip's datasheet to find the vendor and device ID values.
  • Inspect flashchips.h to find matching ID define macros.
  • Inspect flashchips.c to find the chip entry that uses those ID macros
  • If there are multiple flashrom chip entries with the same IDs, check all of them against the datasheet to find the correct one.
  • Finally, check that the chip entry has a reg_bits field and that it matches the datasheet exactly. Verify that all WP-related bits in the datasheet are included in reg_bits and vice versa.
  • If there are no matching chip entries, create one for the chip and send a patch to upstream flashrom for review.
  • Pass the matching entry's name to the tool via the -n option.

src structure

There are two key parts to the tool imports/ and shim/. The shim/ directory just contains enough symbols to allow linking of the imports/ source taken from upstream flashrom. The imports/ contains two key ingredients - the chip database and the writeprotection calculation code. These should be kept up to date by importing fresh copies from flashrom.