[Libre-soc-bugs] [Bug 1073] Microwatt verilator sim - setting up chroot and documentation

bugzilla-daemon at libre-soc.org bugzilla-daemon at libre-soc.org
Fri Apr 28 15:57:02 BST 2023


https://bugs.libre-soc.org/show_bug.cgi?id=1073

--- Comment #7 from Andrey Miroshnikov <andrey at technepisteme.xyz> ---
(In reply to Andrey Miroshnikov from comment #2)
> On line #233 and #235 of the Makefile, the (generic?) options
> -gRAM_INIT_FILE as well as -gRESET_ADDRESS specify the RAM init file to be
> passed to ghdl, however I haven't found any documention on these options at
> all.

Figured out that "-g" prefixed arguments allow to pass parameters into the VHDL
module, so that's where RAM_INIT_FILE, and RESET_ADDRESS arguments go to.
Perhaps I should do a basic ghdl counter tutorial, like we have with nmigen, so
that devs actually know how to work with this. Even if we don't use VHDL
ourselves, still need to know how to access it for Microwatt.


(In reply to Luke Kenneth Casson Leighton from comment #6)
> such as "load the immediate address of a bootloader magic constant".
> 
> you'll find that in the Makefile there is a #define of the offset
> address, that *absolutely must* be encoded correctly to the
> address that you expect the binary to be uploaded to.  this #define
> goes into the linker script via some makefile target voodoo involving
> gcc -E (i think - something like that) which can do macro-substitution.

Searching for the "bootloader magic constant"...
In the Makefile for hello_world, there are no address offset parameters.
https://git.libre-soc.org/?p=microwatt.git;a=blob;f=hello_world/Makefile;h=dd51bd38f9ae428328cb8f0d2c3eea479068d997;hb=refs/heads/verilator_trace

Makefile provides a RESET_ADDRESS of 65280 (0xff00), because VHDL doesn't allow
passing integers bigger than 2^32 apparently. Then in top-generic.vhdl:
https://git.libre-soc.org/?p=microwatt.git;a=blob;f=fpga/top-generic.vhdl;h=0ce8456d0f781e858a4d70c8ffe46b90c119d216;hb=refs/heads/verilator_trace#l108
This integer is converted to an unsigned 48-bit number, and concatinated with
lower 16-bits. This gives the correct reset address of 0xff00_0000.

The RAM_INIT_FILE (in my case the hello_world binary) is passed to the
soc.vhdl, and then to wishbone_bram_wrapper.vhdl.
https://git.libre-soc.org/?p=microwatt.git;a=blob;f=soc.vhdl;h=b02fe12c6b9d2120c759c6bb3886bb8d6ad917ee;hb=refs/heads/verilator_trace
https://git.libre-soc.org/?p=microwatt.git;a=blob;f=wishbone_bram_wrapper.vhdl;h=4e3fb506dfecb66bb6bf165251957b5d2547f26d;hb=refs/heads/verilator_trace
Inside wishbone_bram_wrapper.vhdl, the main_bram module (with RAM_INIT_FILE) is
only generated if the SIM_MAIN_BRAM parameter is true. The Makefile sets it to
false by default, which would explain with the RAM is not actually initialised.

Setting SIM_MAIN_BRAM to true in the Makefile causes an error during "make
microwatt-verilator":
ERROR: vhdl import failed.
make: *** [Makefile:252: microwatt.v] Error 1

Earlier, this error occurs about multiple assignments in
wishbone_bram_wrapper.vhdl
wishbone_bram_wrapper.vhdl:23:9:error: multiple assignments for "wishbone_out"
offsets 0:63
        wishbone_out : out wishbone_slave_out;

I'm guessing I don't need this SIM_MAIN_BRAM parameter, why else would it be
disabled.


Another parameter I tried to change (after reverting SIM_MAIN_BRAM to false) is
SIM_BRAM_CHAINBOOT. In the Makefile it is set to 6291456 (0x600000, needed for
the linux image).
Setting it to 0, I get the following error:
error: override for generic "sim_bram_chainboot" is out of bounds
ERROR: vhdl import failed.
make: *** [Makefile:251: microwatt.v] Error 1

In soc.vhdl line #62, the default value is set to 0, so I don't know why it
complains about being out of bounds.


Other than this, I have not found any other offset values to adjust in the
Makefile for microwatt-verilator.

microwatt_soc.h (used for compiling PowerISA binaries to run) has some
potentially relevant parameters:
https://git.libre-soc.org/?p=microwatt.git;a=blob;f=include/microwatt_soc.h;h=989721b14e57781c3099b10936e6f91c7b69c767;hb=refs/heads/verilator_trace
MEMORY_BASE=0x0000_0000 /* "Main" memory alias, either BRAM or DRAM */
DRAM_BASE=0x4000_0000 /* DRAM if present */
BRAM_BASE=0x8000_0000 /* Internal BRAM */
Also there's an option if STANDALONE_MINI_BIOS is defined:
DRAM_INIT_BASE=0x0000_0000 /* alternative, for verilator simulation */
Otherwise
DRAM_INIT_BASE=0xff00_0000 /* Internal DRAM init firmware */

Also, after looking at IRC logs:
https://libre-soc.org/irclog/%23libre-soc.2022-01-26.log.html#t2022-01-26T19:24:55
Saw that a binary can be passed in to microwatt-verilator:
./microwatt-verilator tests/hello_world/hello_world.bin

However I'm still missing the correct offset setting, or something like that.
The bram.dump first few lines:
pc         ff000000 insn ffffffff msr 8000000000000001
pc         ff000004 insn ffffffff msr 8000000000000001
pc         ff000008 insn ffffffff msr 8000000000000001
                          rd @ 00000100 di         48000000 sel ff ...H....
                          rd @ 00000101 di                0 sel ff ........

Not sure where to go from here.

Is there a way to search for a string of text in all the email and IRC
archives? Your previous updates from 2021-2022 on Microwatt would be handy, and
I'd prefer not to go through months of IRC logs and emails by hand, if there's
a way to search it.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the libre-soc-bugs mailing list