opentitan icon indicating copy to clipboard operation
opentitan copied to clipboard

Backdoor support for HWEXT does not work

Open Jacob-Levy opened this issue 5 years ago • 17 comments

When using HWEXT the backdoor is define as follow in the RAL file.

add_hdl_path_slice("u_reg.u_<reg_field>.qs", 0, 5, 0, "BkdrRegPathRtl");

This will not work since the 'qs' is not connected directly to the FFs that is in a different file, say u_reg_ext.

In my case there is a blocking logic between the FFs and the 'd' input too. I tried to change the path of the backdoor as follows, only to find out that the RAL is autogenerated on each run :(

add_hdl_path_slice("u_reg_ext.<reg_field>", 0, 5, 0, "BkdrRegPathRtl");

Most/all of the registers in the OT are not using HWEXT, but I have too in order to implement certain security features.

The modification to the RAL is simple 'awk', but dvsim does not have an option to run it after the generation of the RAL...

image

Jacob-Levy avatar Feb 03 '21 18:02 Jacob-Levy

Found a way to address the issue by modifying the the ‘regtool/reggen’ template file, uvm_reg.sv.tpl, that introduce the problem.

Change from:

% if f.hwaccess == HwAccess.NONE and f.swrdaccess == SwRdAccess.RD and f.swwraccess == SwWrAccess.NONE:
      // constant reg
      add_hdl_path_slice("${hier_path}u_reg.${reg_field_name}_qs", ${f.lsb}, ${field_size}, 0, "BkdrRegPathRtl");
  % else:
      add_hdl_path_slice("${hier_path}u_reg.u_${reg_field_name}.q${"s" if r.hwext else ""}", ${f.lsb}, ${field_size}, 0, "BkdrRegPathRtl");
  % endif

Change to:

% if f.hwaccess == HwAccess.NONE and f.swrdaccess == SwRdAccess.RD and f.swwraccess == SwWrAccess.NONE:
      // constant reg
      add_hdl_path_slice("${hier_path}u_reg.${reg_field_name}_qs", ${f.lsb}, ${field_size}, 0, "BkdrRegPathRtl");
  % elif r.hwext:
      add_hdl_path_slice("${hier_path}u_reg_ext.${reg_field_name}”, ${f.lsb}, ${field_size}, 0, "BkdrRegPathRtl");
  % else:
      add_hdl_path_slice("${hier_path}u_reg.u_${reg_field_name}.q”, ${f.lsb}, ${field_size}, 0, "BkdrRegPathRtl");
  % endif

This change generated the correct path for the backdoor.

add_hdl_path_slice("u_reg_ext.revid_ver", 0, 8, 0, "BkdrRegPathRtl");

Jacob-Levy avatar Feb 06 '21 10:02 Jacob-Levy

After browsing the OT database on how others implemented the HWEXT, my conclusion is that there is no common ground to implement the Backdoor for HWEXT within the regtool.

The option that is available is to clear the regtool definition and add the new definition that match the implementation of the HWEXT within the DV.

Jacob-Levy avatar Feb 08 '21 09:02 Jacob-Levy

There is an upgrade to the xxx_reg_pkg.sv that will help the implementation of the HWEXT.

At the moment the 'resval' value of each field of the HWEXT is not included in the package. I recommend adding this information to the package as a parameter so it can be used to reset the HWEXT registers.

For example:

  parameter logic  [8-1:0] AST_REVID_VER_DEFAULT    = 8'h1;
  parameter logic          AST_REVID_OV_DEFAULT     = 1'h0;

Jacob-Levy avatar Feb 08 '21 09:02 Jacob-Levy

Thank you Jacob for reporting the issue! @weicaiyang do you mind taking a look at this issue? I remembered we did not support backdoor for ext-regs.

cindychip avatar Feb 08 '21 16:02 cindychip

After browsing the OT database on how others implemented the HWEXT, my conclusion is that there is no common ground to implement the Backdoor for HWEXT within the regtool.

I agree. EXT is kinda special register type that gives huge flexibility to designers. It, contrary, means it is unlikely to be formalize as you implemented (having some logic on the D path). So, what OT team normally has excluded the EXT registers from RAL test set.

DV folks can reply the details. And would be great if we come up with good suggestion to formalize the backdoor for EXT. :)

eunchan avatar Feb 08 '21 17:02 eunchan

As Cindy and Euchan mentioned, it's unlikely to formalize backdoor support for HWEXT and generate the code. But I think we can manually update it after we build the RAL, if the register is connected an actually storage unit. If it's just connected to some wires with combination logic, backdoor deposit can't work as the wire doesn't hold value.

Here is an example that we modify the path in env_cfg::initialize, as the hierarchy path isn't same as we use in most of IPs. https://github.com/lowRISC/opentitan/blob/757d2105bbd4ffad93454d31b97bf04ba328deab/hw/ip/sram_ctrl/dv/env/sram_ctrl_env_cfg.sv#L28-L30

weicaiyang avatar Feb 08 '21 17:02 weicaiyang

This is what we are using to update the path.

function void update_external_reg_hdl_path();
  uvm_hdl_path_concat paths[$];
  string reg_name = get_name();
  bit reg_updated = 0;

  if ( reg_name == "revid" ) begin
    clear_hdl_path( "BkdrRegPathRtl" );
    // update hdl path of all fields in this register
    add_hdl_path_slice("u_reg_ext.revid_ver", 0, 8, 0, "BkdrRegPathRtl");
    add_hdl_path_slice("u_reg_ext.revid_ov", 31, 1, 0, "BkdrRegPathRtl");
    reg_updated = 1;
  end

  // More registers...

  if ( reg_updated == 0 ) begin
    print_hdl_path( "error - register not updated" );
    uvm_error(`gtn, $sformatf( "Error when updated %s backdoor paths\n", reg_name )); 
  end

endfunction

What about adding the 'resval' to the generated package file as a parameter (like the OFFSET)?

Jacob-Levy avatar Feb 08 '21 18:02 Jacob-Levy

What about adding the 'resval' to the generated package file as a parameter (like the OFFSET)?

Sorry, could you explain why you need this? If you need a reset value, get_reset can get it. Or do you want to set different types for reset value?

weicaiyang avatar Feb 08 '21 20:02 weicaiyang

It is not for DV. I need it for the design implementation of external logic. Since I am putting the value on 'resval' and the 'regtool' is not implementing the register.

See the following example at the u_reg_ext, where XXX_EXMP_FIELD_DEFAULT is the value from the 'resval' that need to be added to the xxx_reg_pkg.sv as a parameter:

import xxx_reg_pkg::* ;

//   F[field]: 4:0
logic [5-1:0] exmp_field;

logic exmp_field_qe;
assign exmp_field_qe = reg2hw.exmp.field.qe;
logic [5-1:0] exmp_field_q;
assign exmp_field_q = reg2hw.exmp.field.q;

always_ff @( posedge clk_i, negedge rst_ni ) begin
  if ( !rst_ni ) begin
    exmp_field <= XXX_EXMP_FIELD_DEFAULT;
  end else if ( exmp_field_qe && wren_en[0] ) begin
    exmp_field <= exmp_field_q;
  end
end

assign hw2reg.exmp.field.d = rden_en[0] ? exmp_field : 5'h00;

Jacob-Levy avatar Feb 08 '21 20:02 Jacob-Levy

@Jacob-Levy do you mean you use something like this, but it doesn't support?

    { name: "...",
     ...
      fields: [
        { bits: "",
          name: "",
          resval: "XXX_EXMP_FIELD_DEFAULT"
           ...

weicaiyang avatar Feb 08 '21 22:02 weicaiyang

Not exactly, the .hjson is fine. I noticed that the 'regtool' when ask to generating a define file (.h) will have the reset value as:

# define XXX_EXMP_FIELD_DEFAULT 0x0

What I asked that a parameter line will be added for each field 'resval' value (and field size) to the xxx_reg_pkd.sv as:

parameter [5-1:0] XXX_EXMP_FIELD_DEFAULT 5'h0

This way I can use it in the HDL of the HWEXT.

Jacob-Levy avatar Feb 09 '21 05:02 Jacob-Levy

Not exactly, the .hjson is fine. I noticed that the 'regtool' when ask to generating a define file (.h) will have the reset value as:

# define XXX_EXMP_FIELD_DEFAULT 0x0

What I asked that a parameter line will be added for each field 'resval' value (and field size) to the xxx_reg_pkd.sv as:

parameter [5-1:0] XXX_EXMP_FIELD_DEFAULT 5'h0

This way I can use it in the HDL of the HWEXT.

I feel it seems fine to add these parameters. Since it's in design, perhaps @eunchan knows better on this.

weicaiyang avatar Feb 09 '21 05:02 weicaiyang

Not exactly, the .hjson is fine. I noticed that the 'regtool' when ask to generating a define file (.h) will have the reset value as:

# define XXX_EXMP_FIELD_DEFAULT 0x0

What I asked that a parameter line will be added for each field 'resval' value (and field size) to the xxx_reg_pkd.sv as:

parameter [5-1:0] XXX_EXMP_FIELD_DEFAULT 5'h0

This way I can use it in the HDL of the HWEXT.

I like this idea. :) external register type does not have reset value in prim_subreg_ext but resval is there for DV/ SW purpose. Having same value in the design also makes designers' life easier.

One thing I want to note is: other registers except external are generated from hjson. External register does exists outside of the register package and the field in .hjson is to describe the behavior of the external, not generating from .hjson. But this resval changes the expectation, .hjson does change the external register's behavior. Not sure this concept would be helpful or not.

@tjaychen @msfschaffner @rswarbrick Could you please weigh in your opinion?

eunchan avatar Feb 11 '21 17:02 eunchan

Yep, I definitely like this (consistency is always good!). If no-one else has strong objections, I'll push up a PR to do this tomorrow.

rswarbrick avatar Feb 11 '21 17:02 rswarbrick

Thanks! Please let me know when you PR it and the PR get released. I will update my code to use it and test it.

Jacob-Levy avatar Feb 14 '21 06:02 Jacob-Levy

I've just pushed up something at the attached PR. Sorry, I was a little ambitious with "tomorrow" (doubly bad if you worked on Sunday :-/)

rswarbrick avatar Feb 15 '21 08:02 rswarbrick

Don't worry... I have generated my own package that include those parameters for the AST reg_ext. Once the release is done I will remove my package.

import ast_reg_pkg::* ;
import ast_reg_ext_pkg::* ;

Jacob-Levy avatar Feb 15 '21 08:02 Jacob-Levy