Skip to content

Commit

Permalink
treewide: Simplify security island tb snippet
Browse files Browse the repository at this point in the history
  • Loading branch information
alex96295 committed Oct 11, 2023
1 parent 4623598 commit 5f18581
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 22 deletions.
2 changes: 1 addition & 1 deletion carfield.mk
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ SAFED_BINARY ?=
SECD_ROOT ?= $(shell $(BENDER) path opentitan)
SECD_BINARY ?=
SECD_BOOTMODE ?= 0
SECD_FLASH ?= $(SECD_ROOT)/sw/tests/carfield/flash_carfield_boot/bazel-out/flash_carfield_boot_signed8.vmem
SECD_IMAGE ?=

# PULP cluster
PULPD_ROOT ?= $(shell $(BENDER) path pulp_cluster)
Expand Down
49 changes: 28 additions & 21 deletions tb/carfield_tb.sv
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,25 @@ module tb_carfield_soc;
if (!$value$plusargs("SECURE_BOOT=%d", secure_boot)) secure_boot = 0;
if (!$value$plusargs("SECD_FLASH=%s", secd_flash_vmem)) secd_flash_vmem = "";
if (!$value$plusargs("SECD_BINARY=%s", secd_preload_elf)) secd_preload_elf = "";
if (!$value$plusargs("SECD_BOOTMODE=%d", secd_boot_mode)) secd_boot_mode = 0;
case(secd_boot_mode)
0: begin
// Go in secure bootmode to let the Security island be de-isolated and clocked after PoR
$display("[TB] %t - Entering secure boot mode for Security island after PoR (clock enable and de-isolation handled in HW)", $realtime);
fix.set_secure_boot(secure_boot);
fix.secd_vip.set_secd_boot_mode(2'b00);
if (secd_preload_elf != "") begin
if (!$value$plusargs("SECD_BOOTMODE=%d", secd_boot_mode)) secd_boot_mode = 0;

// set secure boot mode
fix.set_secure_boot(secure_boot);

// set bootmode
fix.secd_vip.set_secd_boot_mode(secd_boot_mode);

if (secd_preload_elf != "" || secd_flash_vmem != "") begin
// Wait for reset
fix.chs_vip.wait_for_reset();

// Writing max burst length in Hyperbus configuration registers to
// prevent the Verification IPs from triggering timing checks.
$display("[TB] INFO: Configuring Hyperbus through serial link.");
fix.chs_vip.slink_write_32(HyperbusTburstMax, 32'd128);

case(secd_boot_mode)
0: begin
// Wait before security island HW is initialized
repeat(10000)
@(posedge fix.clk);
Expand All @@ -232,20 +243,16 @@ module tb_carfield_soc;
fix.secd_vip.jtag_secd_data_preload();
fix.secd_vip.jtag_secd_wakeup(32'hE0000080);
fix.secd_vip.jtag_secd_wait_eoc();
end 1: begin
fix.secd_vip.spih_norflash_preload(secd_flash_vmem);
repeat(10000)
@(posedge fix.clk);
fix.secd_vip.jtag_secd_wait_eoc();
end default: begin
$fatal(1, "Unsupported boot mode %d (reserved)!", safed_boot_mode);
end
end 1: begin
// Go in secure bootmode to let the Security island be de-isolated and clocked after PoR
$display("[TB] %t - Entering secure boot mode for Security island after PoR (clock enable and de-isolation handled in HW)", $realtime);
fix.set_secure_boot(secure_boot);
fix.secd_vip.set_secd_boot_mode(2'b01);
fix.secd_vip.spih_norflash_preload(secd_flash_vmem);
repeat(10000)
@(posedge fix.clk);
fix.secd_vip.jtag_secd_wait_eoc();
end default: begin
$fatal(1, "Unsupported boot mode %d (reserved)!", safed_boot_mode);
end
endcase
endcase
end
end

// pulp cluster standalone
Expand Down

0 comments on commit 5f18581

Please sign in to comment.