Skip to content

[hw] rom_ctrl added to mocha#389

Open
KolosKoblasz-Semify wants to merge 6 commits intolowRISC:mainfrom
KolosKoblasz-Semify:kk_rom_ctrl
Open

[hw] rom_ctrl added to mocha#389
KolosKoblasz-Semify wants to merge 6 commits intolowRISC:mainfrom
KolosKoblasz-Semify:kk_rom_ctrl

Conversation

@KolosKoblasz-Semify
Copy link
Copy Markdown
Collaborator

  1. existing source files vendored in
  2. rom_ctrl integrated at topl level, AXI and TL busnetwork extended
  3. new smoketest written for reading rom init values
  4. xbar_peri regenerated include new rom_ctrl_regs TL interface

@KolosKoblasz-Semify KolosKoblasz-Semify marked this pull request as ready for review March 27, 2026 14:55
@KolosKoblasz-Semify KolosKoblasz-Semify changed the title rom_ctrl added to mocha [hw] rom_ctrl added to mocha Mar 30, 2026
Copy link
Copy Markdown
Collaborator

@marnovandermaas marnovandermaas left a comment

Choose a reason for hiding this comment

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

Some initial comments from my end. Please also have a look at the CI failures.

Comment thread hw/top_chip/ip/xbar_peri/xbar_peri.hjson Outdated
Comment thread hw/top_chip/ip/xbar_peri/xbar_peri.hjson Outdated
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why did you move this file?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The .hjson file is relocated now because I found counter intuitive to store the "source" file for IP generation in the generated folder.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think it is better not to have this code churn right now. You can do this in a separate PR after this if you feel strongly about it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Reverted.

Comment thread hw/vendor/lowrisc_ip.vendor.hjson Outdated
Comment on lines +33 to +34
{from: "hw/ip/rom_ctrl", to: "ip/rom_ctrl", patch_dir: "rom_ctrl"}, // ROM Control.
{from: "hw/ip/kmac", to: "ip/kmac", patch_dir: "kmac"}, // kmac.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Adding the patch directories should be in the same commit as where you add them to the vendor.hjson file.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed. IPs and vendoring script committed at the same time

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is still not fixed. You reference the rom_ctrl and kmac patch directories before they are created.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

There are no rom_ctrl and kmac patch files/directories. Shall I remove them from the lowrisc_ip.vendor.hjson file?

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.

If there is no patch needed for kmac and rom_ctrl, you can remove the patch_dir option for them in lowrisc_ip.vendor.hjson

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

patch_dirs removed

Comment thread hw/top_chip/dv/tb/tb.sv Outdated
Comment thread hw/top_chip/rtl/top_pkg.sv Outdated
Comment thread hw/top_chip/rtl/top_chip_system.sv Outdated
Comment thread sw/device/lib/hal/mocha.c Outdated
Comment thread sw/device/lib/hal/rom_ctrl.c Outdated
Comment thread sw/device/tests/rom_ctrl/mem_init_file.vmem
@KolosKoblasz-Semify KolosKoblasz-Semify force-pushed the kk_rom_ctrl branch 3 times, most recently from 71fd63b to e3eebff Compare April 1, 2026 09:23
Copy link
Copy Markdown
Contributor

@ziuziakowska ziuziakowska left a comment

Choose a reason for hiding this comment

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

Just some nits on the software.

Something to consider might also be modelling the ROM as a const char * instead of a void * typedef, as that could prevent writing through the pointer (although I believe that should cause a fault anyway).

Comment thread sw/device/tests/rom_ctrl/smoketest.c Outdated
Comment thread sw/device/lib/hal/rom_ctrl.h Outdated
Comment thread sw/device/lib/hal/CMakeLists.txt Outdated
Comment thread sw/device/tests/rom_ctrl/smoketest.c Outdated
Comment thread sw/device/tests/rom_ctrl/smoketest.c Outdated
Copy link
Copy Markdown
Contributor

@raylau1 raylau1 left a comment

Choose a reason for hiding this comment

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

Thanks for adding this, I have added some comment.

Comment thread hw/top_chip/dv/tb/tb.sv Outdated
Comment thread hw/top_chip/dv/verilator/top_chip_verilator.sv Outdated
Comment thread hw/top_chip/dv/verilator/top_chip_verilator.vlt Outdated
Comment thread hw/top_chip/dv/top_chip_sim_cfg.hjson Outdated
Comment thread hw/top_chip/rtl/top_chip_system.sv Outdated
Comment thread hw/top_chip/rtl/top_chip_system.sv Outdated
Comment thread hw/top_chip/rtl/top_chip_system.sv Outdated
Comment thread hw/top_chip/rtl/top_chip_system.sv Outdated
Comment thread hw/top_chip/rtl/top_chip_system.sv Outdated
Comment thread sw/device/tests/CMakeLists.txt Outdated
@KolosKoblasz-Semify KolosKoblasz-Semify force-pushed the kk_rom_ctrl branch 2 times, most recently from e72eb24 to 555b922 Compare April 7, 2026 13:42
@raylau1

This comment was marked as resolved.

@KolosKoblasz-Semify

This comment was marked as resolved.

@raylau1

This comment was marked as resolved.

Copy link
Copy Markdown
Collaborator

@marnovandermaas marnovandermaas left a comment

Choose a reason for hiding this comment

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

Great work! Some more comments from my end before we can merge this.

Comment thread util/artefacts.py
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can you please change this back? It would be good not to have this code churn.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Reverted

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think it is better not to have this code churn right now. You can do this in a separate PR after this if you feel strongly about it.

Comment thread hw/top_chip/ip/xbar_peri/xbar_peri.hjson Outdated
Comment thread hw/vendor/lowrisc_ip.vendor.hjson Outdated
Comment on lines +33 to +34
{from: "hw/ip/rom_ctrl", to: "ip/rom_ctrl", patch_dir: "rom_ctrl"}, // ROM Control.
{from: "hw/ip/kmac", to: "ip/kmac", patch_dir: "kmac"}, // kmac.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is still not fixed. You reference the rom_ctrl and kmac patch directories before they are created.

Comment thread hw/top_chip/dv/tb/tb.sv
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

These changes are not currently tested in CI, have you tested these changes?

Comment thread hw/top_chip/rtl/top_chip_system.sv Outdated
Comment on lines +1069 to +1076
.BootRomInitFile ( RomInitFile ),
.AlertAsyncOn ( 1'b1 ),
.AlertSkewCycles ( 1 ),
.FlopToKmac ( 1'b0 ),
.RndCnstScrNonce ( '0 ),
.RndCnstScrKey ( '0 ),
.SecDisableScrambling ( 1'b1 ),
.MemSizeRom ( 32768 )
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: Align the closing parentheses for parameters.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Aligned

Comment thread hw/top_chip/rtl/top_chip_system.sv Outdated
.RndCnstScrNonce ( '0 ),
.RndCnstScrKey ( '0 ),
.SecDisableScrambling ( 1'b1 ),
.MemSizeRom ( 32768 )
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This should be calculated based on the length defined in top_pkg

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

fixed: top_pkg::RomCtrlMemLength used

Comment thread hw/top_chip/rtl/top_chip_system.sv Outdated
Comment on lines +1090 to +1091
.kmac_data_o (kmac_app_req[0]),
.kmac_data_i (kmac_app_rsp[0]),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'd rather leave these unconnected until we integrate KMAC

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed

mocha_add_test(NAME timer_smoketest SOURCES timer/smoketest.c LIBRARIES ${LIBS} FPGA)
mocha_add_test(NAME timer_interrupt_test SOURCES timer/interrupt.c LIBRARIES ${LIBS})
mocha_add_test(NAME uart_smoketest SOURCES uart/smoketest.c LIBRARIES ${LIBS})

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Don't remove this newline.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed

Comment thread util/verilator_runner.sh Outdated
Comment on lines +8 to +10
timeout 5m $ROOT_DIR/build/lowrisc_mocha_top_chip_verilator_0/sim-verilator/Vtop_chip_verilator \
$@ > /dev/null 2>&1
--rominit $ROOT_DIR/sw/device/tests/rom_ctrl/mem_init_file.vmem \
-E $@ > /dev/null 2>&1
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This looks wrong to me. You should make this change in tests.cmake I believe: 9affb1c

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Copy Markdown
Collaborator

@marnovandermaas marnovandermaas left a comment

Choose a reason for hiding this comment

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

Some more comments on the software side.

Comment thread sw/device/tests/rom_ctrl/smoketest.c Outdated
Comment on lines +18 to +19
//uint8_t address_length = 3;
//uint8_t data_length = 4;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we remove these comments?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Comented out code removed

Comment thread sw/device/tests/rom_ctrl/smoketest.c Outdated
Comment on lines +22 to +25
const uint32_t addresses[3] = { 0x00000000, 0x00004000, 0x00007FF0 };

// ROM Init values
const uint32_t expected_data[3][4] = { { 0xDEADBEEF, 0xCAFEBABE, 0x00000001, 0xEEEEEEEE },
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Since the [3] must be the same for both can we make a define for this value?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

defines used instead of numbers

 * rom_ctrl_regs if added to xbapr_peri cfg
 * kmac vendored in
 * lowrisc_ip.vendor.hjson modified
 * Apply patch on prim_xilinx_rom.sv. Vivado synth failed
   due to string type parameter.
 * axi bus network expanded to handle rom_ctrl data interface
 * xbar_peri module connected to rom_ctrl register interface
 * verilator rule exclusions added
 * Path to ROM init file added to tb.sv
 * clk and reset of the new axi bus and rom_ctrl fixed on top level
 * backdoor access for ROM config added
 * new testcase implemented among top level sw tests
 * the new test reads the compile time initialized ROM values
 * if any comparision fails (expected values differs from read value)
   test is terminated with an error
 * sw test files reformated to complie with clang format
 * fixed issues highlighted during PR review
 * xbar_peri IP regenerated with new paths during CI/CD tests
 * ROM backdoor init command added to sw regression tests
 * FPGA tests need ROM initialization to pass
 * RomInitFile argument and init file paths added to the
   nix/fpga.nix script
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.

4 participants