Skip to content

[rtl] RRAM bkdr#30740

Open
gautschimi wants to merge 1 commit into
lowRISC:masterfrom
gautschimi:rram_ctrl_bkdr
Open

[rtl] RRAM bkdr#30740
gautschimi wants to merge 1 commit into
lowRISC:masterfrom
gautschimi:rram_ctrl_bkdr

Conversation

@gautschimi

@gautschimi gautschimi commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

As per RFC , Earlgrey will be extended with support for RRAM based non-volatile memory.

This PR adds the backdoor access to the RRAM. This is used in some DV tests to either preload the RRAM with the firmware, or to examine certain memory locations during a test.

This PR is based on #30412

@gautschimi
gautschimi marked this pull request as ready for review July 14, 2026 14:24
@gautschimi
gautschimi requested a review from a team as a code owner July 14, 2026 14:24
@gautschimi gautschimi self-assigned this Jul 14, 2026

@rswarbrick rswarbrick left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Various requests for documentation comments (sorry) but this looks like a sensible implementation.

localparam int unsigned RramDataWidth = rram_ctrl_pkg::DataWidth;
localparam int unsigned RramKeySize = rram_ctrl_pkg::KeySize;
localparam int unsigned RramAddrW = rram_ctrl_pkg::AddrW;
localparam int unsigned RramStagesPerCycle = RramDataWidth / rram_ctrl_pkg::GfMultCycles;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if this doesn't divide cleanly? (And do we care?)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its a requirement of the gfmultiplier hardware module. so it must be a clean division

localparam int unsigned RramAddrW = rram_ctrl_pkg::AddrW;
localparam int unsigned RramStagesPerCycle = RramDataWidth / rram_ctrl_pkg::GfMultCycles;
localparam int unsigned RramNumRoundsHalf = crypto_dpi_prince_pkg::NumRoundsHalf;
localparam int unsigned RramDataByteWidth = $clog2(RramDataWidth / 8);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if this doesn't divide cleanly? Do you want a +7 here? (Or maybe a check in the constructor? "These parameters don't make sense, so you can't make the class today")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RramDataWidth is always a multiple of a byte.

But I guess I can add a check to verify the parameters

Comment on lines +16 to +18
// Initialize the class instance.
// `extra_bits_per_subword` is the width of any additional metadata that is not captured in the
// secded package.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can all the arguments be documented? (Possibly just by pointing to the base class)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added. Most of them are actually not used

Comment on lines +45 to +46
mult_out = operand[RramDataWidth-1] ? (operand << 1) ^
rram_ctrl_pkg::ScrambleIPoly : (operand << 1);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that not everyone agrees about indentation, but this looks wrong to me: surely we shouldn't out-dent the middle of a ternary case?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks indeed horrible:) sorry, I will fix it!

end
endfunction

static function bit [RramDataWidth-1:0] rram_gf_mult2(bit [RramDataWidth-1:0] operand);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function needs a documentation comment (which should describe the operand argument as well as the point of the function)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just the inner part of the gfmultiplier. I also don't really know what it is doing in detail. I took it over from flash_ctrl

static function bit [RramStagesPerCycle-1:0][RramDataWidth-1:0] rram_gen_matrix(
bit [RramDataWidth-1:0] seed,
bit init);
bit [RramStagesPerCycle-1:0][RramDataWidth-1:0] matrix_out;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be nice to use a typedef for this type?


matrix_out[0] = init ? seed : rram_gf_mult2(seed);

matrix_out[RramStagesPerCycle-1:1] = '0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this line have any effect?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, removed

// Compute the tweak for the xex cipher. tweak = GfMult128(addr, addr_key)
static function bit [RramDataWidth-1:0] rram_galois_multiply(bit [RramKeySize-1:0] addr_key,
bit [RramAddrW-1:0] addr);
bit [RramStagesPerCycle-1:0][RramDataWidth-1:0] current_matrix;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That current_matrix and mult_out probably need their scopes moved to inside the loop?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes that would be cleaner. let me do that

return total_product;
endfunction

function bit [RramDataWidth-1:0] rram_scramble_data(bit [RramDataWidth-1:0] data,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function needs documenting.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

return scrambled_data ^ mask;
endfunction

function bit [RramDataWidth-1:0] rram_descramble_data(bit [RramDataWidth-1:0] data,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function needs documenting.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

This bkdr util is required to preload the RRAM or to examine certain
memory location during tests.

Signed-off-by: Michael Gautschi <mgautschi@lowrisc.org>
@gautschimi gautschimi added the CI:Rerun Rerun failed CI jobs label Jul 17, 2026
@github-actions github-actions Bot removed the CI:Rerun Rerun failed CI jobs label Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants