open-power/snap

SR10441909: xsim: writememh() works in combination with sformat() and readmemh() does not

Opened this issue · 9 comments

I have the folloging code in hardware/sim/nvme_lite/nvme_top_i.sv:

                static string wfname;
                $sformat(wfname, "SNAP_LBA_%h.bin", lba_addr);
                $writememh(wfname, axi_data);
                lba_addr += 1;

and the following code I use to read the data back:

                static string rfname;
                $sformat(rfname, "SNAP_LBA_%h.bin", lba_addr);
                $readmemh(rfname, axi_data);
                // FIXME Bug in xsim sformat, the fname version has problems, the fixed filename seems working OK.
                //   $readmemh("SNAP_LBA_0000000000000000.bin", axi_data);

The readmemh() works nicely for ncsim but fails badly for xsim. I tried different variants with fname, declared it static or not, changed from fname to rfname and wfname, all no success. It does not find the file.

The error looks like this:

nvme_operation: ddr=0000000200000000 lba=0000000000000000 num=00000001 cmd_type=1 cmd_action_id=0
nvme_write: ddr=0000000200000000 lba=0000000000000000 num=00000001
  read: axi_addr=0000000200000000 axi_data=fffffff700000008ffffffff00000000ffffffe700000018ffffffef00000010ffffffd700000028ffffffdf00000020ffffffc700000038ffffffcf00000030
  read: axi_addr=0000000200000040 axi_data=ffffffb700000048ffffffbf00000040ffffffa700000058ffffffaf00000050ffffff9700000068ffffff9f00000060ffffff8700000078ffffff8f00000070
  read: axi_addr=0000000200000080 axi_data=ffffff7700000088ffffff7f00000080ffffff6700000098ffffff6f00000090ffffff57000000a8ffffff5f000000a0ffffff47000000b8ffffff4f000000b0
  read: axi_addr=00000002000000c0 axi_data=ffffff37000000c8ffffff3f000000c0ffffff27000000d8ffffff2f000000d0ffffff17000000e8ffffff1f000000e0ffffff07000000f8ffffff0f000000f0
  read: axi_addr=0000000200000100 axi_data=fffffef700000108fffffeff00000100fffffee700000118fffffeef00000110fffffed700000128fffffedf00000120fffffec700000138fffffecf00000130
  read: axi_addr=0000000200000140 axi_data=fffffeb700000148fffffebf00000140fffffea700000158fffffeaf00000150fffffe9700000168fffffe9f00000160fffffe8700000178fffffe8f00000170
  read: axi_addr=0000000200000180 axi_data=fffffe7700000188fffffe7f00000180fffffe6700000198fffffe6f00000190fffffe57000001a8fffffe5f000001a0fffffe47000001b8fffffe4f000001b0
  read: axi_addr=00000002000001c0 axi_data=fffffe37000001c8fffffe3f000001c0fffffe27000001d8fffffe2f000001d0fffffe17000001e8fffffe1f000001e0fffffe07000001f8fffffe0f000001f0
nvme_operation: ddr=0000000200000200 lba=0000000000000000 num=00000001 cmd_type=0 cmd_action_id=0
nvme_read: ddr=0000000200000200 lba=0000000000000000 num=00000001
WARNING: File 8 referenced on /afs/vlsilab.boeblingen.ibm.com/proj/fpga/framework/haver/snap/hardware/sim/nvme_lite/nvme_top_i.sv at line 511 cannot be opened for reading. Please ensure that this file is available in the current working directory.
  write: axi_addr=0000000200000200 axi_data=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  write: axi_addr=0000000200000240 axi_data=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  write: axi_addr=0000000200000280 axi_data=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  write: axi_addr=00000002000002c0 axi_data=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  write: axi_addr=0000000200000300 axi_data=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  write: axi_addr=0000000200000340 axi_data=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  write: axi_addr=0000000200000380 axi_data=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  write: axi_addr=00000002000003c0 axi_data=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

It complains about the non existing file. But I think the tool lies, the file is there I checked it. But it has trouble to use the rfname string to identify the file correctly.

Using the fixed filename as in the comment makes it work, but does not work if we use LBAs different from 0, or course.

As there is no Xilinx SR yet, I changed the Label. I found a circumvention from another Xilinx user:
Instead of
string f = "SNAP%h.bin";
please try
reg [20*8:0] f;
f="SNAP%h.bin";
$readmemh(f, mem);

Another hint in stackoverflow was without specifying the format for the filename variable:
$readmemh($sformatf("SNAP%0d.bin",lba_adr), axi_data);

I tried $readmemh($sformatf("SNAP_LBA_%0d.bin",lba_adr),axi_data);.
It did not help

Regarding the previous suggestion: How should

f="SNAP%h.bin";

work? (What should the %h refer to?)

@fhaverkamp Adding a line

$display("fname is %s",  fname);

I made sure that the line

$sformat(fname,"SNAP_LBA_%h.bin", lba_addr);

actually is working ok.
So, it looks like the problem is with the $readmemh command itself.

The following version works with xsim. Joerg K. is trying out if that still works with ncsim.

                static logic [7:0] fname[128];
                $sformat(fname, "SNAP_LBA_%h.bin", lba_addr);
                $readmemh(fname, axi_data);

Circumvention can be the following change:
#770

Frank opened Xilinx SR10441909.