lowRISC / lowRISC/opentitan

[silicon_creator] Consider refactoring the `FLASH_CTRL_MP_REGIONS` X-macro in flash_ctrl

Open
#24,514 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

SW:ROM SW:ROM_EXT Type:Cleanup
Dominant language
SystemVerilog
Stars
3.6k
Forks
1.1k
Avg merge
2d 22h
Merged PRs (30d)
141

Description

### Description

Consider refactoring the uses of the `FLASH_CTRL_MP_REGIONS` X-macros in the flash_ctrl driver.

Currently, these X-macros expand to a switch/case statement to cover adjusting the various properties of the flash memory protection region registers. The expansion use macro-pasting to generate the register index and field names (like `FLASH_CTRL_MP_REGION_##arg##_REG_RESVAL`. These values can probably be calculated from base register and an index rather than register pasting.

Each case of the switch-case includes a HARDENED_CHECK; it is probably sufficient to use hardened checks to ensure the index is in range before performing the index register calculation.

1. Examine the generated code for the `flash_ctrl_mp_region` functions with the current X-macro expansions.
2. Change the code to calculate the register offsets from the index. Examine the generated code from that method.
3. If the savings is significant, the code is cleaner and the hardening properties are maintained, use the index calculation method in favor of the X-macro method.

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 by examining the generated code for the flash_ctrl_mp_region functions and the FLASH_CTRL_MP_REGIONS X-macro expansions. Compare the generated code with index-based register-offset calculations, then use the index method only if it provides significant savings while preserving the hardened checks.

Written by the indexing model from the issue text.

Assessment

Domain
embedded-iot
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.