lowRISC / lowRISC/opentitan

[util/design] Questions on Generating OTP vmem Files with Known Token Values

Open
#27,487 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
SystemVerilog
Stars
3.6k
Forks
1.1k
Avg merge
2d 22h
Merged PRs (30d)
141

Description

### Description

Firstly, I apologize if this is the wrong place to ask questions. I'm not sure if this is a bug or if I'm missing something due to being new to OpenTitan.

I have noticed that `util/design/gen-otp-img.py` reads from `hw/top_earlgrey/data/otp/BUILD` to generate `.vmem` files for the initial OTP state for simulation, such as the RMA image that is used as the default for Verilator tests.

Hence, my goal is to generate an OTP image with the life cycle state as Dev and with the RMA token as a known value, such that I can simulate a valid life cycle transition end-to-end without relying on backdoor writes.

Some of the configurations in `hw/top_earlgrey/data/otp/BUILD` seem to support setting transition tokens to known values instead of random, such as `otp_json_fixed_secret0` below:
```
otp_json(
name = "otp_json_fixed_secret0",
partitions = [
otp_partition(
name = "SECRET0",
items = {
# These match their cSHAKE-128 (w/ "LC_CTRL" customization string)
# preimage counterpart of: 0x1111_1111_1111_1111_1111_1111_1111_1111,
# which is hardcoded into the test that use this overlay.
# The script that generated this token is:
# //sw/host/tests/manuf/manuf_cp_device_info_flash_wr:gen_test_exit_token
"TEST_UNLOCK_TOKEN": "0xde0a1f1e0d6a649fd35fadb75ec82674",
"TEST_EXIT_TOKEN": "0xde0a1f1e0d6a649fd35fadb75ec82674",
},
lock = True,
),
],
)
```

Therefore, my approach was to modify the `otp_json_dev` entry and define more partitions containing transition tokens with the same value, as below.
```
otp_json(
name = "otp_json_dev",
partitions = [
otp_partition(
name = "LIFE_CYCLE",
count = "7",
state = "DEV",
),
otp_partition(
name = "SECRET0",
items = {
"TEST_UNLOCK_TOKEN": "0xde0a1f1e0d6a649fd35fadb75ec82674",
"TEST_EXIT_TOKEN": "0xde0a1f1e0d6a649fd35fadb75ec82674",
},
),
otp_partition(
name = "SECRET2",
items = {
"RMA_TOKEN": "0xde0a1f1e0d6a649fd35fadb75ec82674",
},
),
],
seed = "85452983286950371191603618368782861611109037138182535346147818831008789508651",
)
```

However, observing the generated vmem file, populating the transition token fields with different values in the build script did not change their values. The only time I observed the tokens in the vmem file changing was when I modified the seed, which suggests that the transition tokens are being randomly generated (with the values that I provided being ignored).

Furthermore, adding `lock = True` to the `SECRET0` and `SECRET2` partitions did not change the result, either. I would greatly appreciate some pointers on how I could get these values to be scrambled and then placed in the vmem file :)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with util/design/gen-otp-img.py and the otp_json_dev definition in hw/top_earlgrey/data/otp/BUILD. Trace how SECRET0 and SECRET2 transition-token fields, partition locks, and the seed are handled during generation. Done means establishing and documenting a supported configuration that produces the requested token values in the generated .vmem image, or clearly identifying the limitation.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
build-system, embedded-iot, security
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.