Skip to content

Commit

Permalink
sw: change hex from words to bytes
Browse files Browse the repository at this point in the history
objcopy with --verilog-data-width produces inconsistent
byte ordering between different installs -> useless
  • Loading branch information
phsauter committed Sep 27, 2024
1 parent b0889fb commit b129d5c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ $(SW):
## Build the helloworld software
software: $(SW)

sw: $(SW)

.PHONY: software

##################
Expand Down
40 changes: 28 additions & 12 deletions rtl/tb_croc_soc.sv
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ module tb_croc_soc #(
string line;
bit [31:0] addr;
bit [31:0] data;
bit [7:0] byte_data;
int byte_count;

file = $fopen(filename, "r");
if (file == 0) begin
Expand All @@ -189,27 +191,41 @@ module tb_croc_soc #(
// line by line
while (!$feof(file)) begin
if ($fgets(line, file) == 0) begin
break;
break; // End of file
end
// lines starting with @ are addresses

// '@' indicates address
if (line[0] == "@") begin
status = $sscanf(line, "@%h", addr);
if (status != 1) begin
$fatal(1, "Error: Incorrect address line format in file %s", filename);
end
end else begin
// otherwise it contains space separated 32bit data blocks
while (line.len() > 0) begin
status = $sscanf(line, "%h", data); // extract one 32bit block
if (status != 1) begin
break; // No more data to read on this line
end
continue;
end

byte_count = 0;
data = 32'h0;

// Loop through the line to read bytes
while (line.len() > 0) begin
status = $sscanf(line, "%h", byte_data); // Extract one byte
if (status != 1) begin
break; // No more data to read on this line
end

// Shift in the byte to the correct position in the data word
data = {data[23:0], byte_data}; // Combine bytes into a 32-bit word
byte_count++;

// remove the byte from the line (2 numbers + 1 space)
line = line.substr(3, line.len()-1);

// write a complete word via jtag
if (byte_count == 4) begin
jtag_write_reg32(addr, data, 1'b0);
addr += 4;

// remove the processed 32-bit value from the line
line = line.substr(8 + 1, line.len()-1);
data = 32'h0;
byte_count = 0;
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion sw/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ $(BINDIR)/%.dump: $(BINDIR)/%.elf
$(RISCV_OBJDUMP) -D -s $< >$@

$(BINDIR)/%.hex: $(BINDIR)/%.elf
$(RISCV_OBJCOPY) --reverse-bytes 4 -O verilog --verilog-data-width 4 $< $@
$(RISCV_OBJCOPY) -O verilog $< $@

# keep dumps

Expand Down

0 comments on commit b129d5c

Please sign in to comment.