Xilinx / systemctlm-cosim-demo

QEMU libsystemctlm-soc co-simulation demos.
https://xilinx-wiki.atlassian.net/wiki/spaces/A/pages/862421112/Co-simulation
Other
131 stars 47 forks source link

QEMU hangs after connection from SystemC (zynq_demo) #7

Closed rick-heig closed 4 years ago

rick-heig commented 4 years ago

Hello. I am trying to run the co-simulation demo but QEMU hangs after connection from the demo.

Running in QEMU before the device tree import works fine, with the new device tree QEMU does indeed wait for a connection from SystemC (through remote port) as expected.

petalinux-boot --qemu --kernel --dtb ./system.dtb --qemu-args "-machine-path ./qemu-tmp -icount 1 -sync-quantum 1000"
INFO: sourcing build tools
INFO: The image provided is a zImage
INFO: Set QEMU tftp to /opt/pkg/projects/zynq_project/images/linux 
INFO: TCP PORT is free 
INFO: Starting arm QEMU
INFO:  qemu-system-aarch64 -M arm-generic-fdt-7series -machine linux=on   -serial mon:stdio -serial /dev/null -display none -kernel /opt/pkg/projects/zynq_project/build/qemu_image.elf -gdb tcp::9000 -dtb ./system.dtb  -net nic,netdev=eth0 -netdev user,id=eth0,tftp=/opt/pkg/projects/zynq_project/images/linux -net nic -device loader,addr=0xf8000008,data=0xDF0D,data-len=4 -device loader,addr=0xf8000140,data=0x00500801,data-len=4 -device loader,addr=0xf800012c,data=0x1ed044d,data-len=4 -device loader,addr=0xf8000108,data=0x0001e008,data-len=4 -device loader,addr=0xF8000910,data=0xF,data-len=0x4  -machine-path ./qemu-tmp -icount 1 -sync-quantum 10000  
qemu-system-aarch64: Failed to connect socket ./qemu-tmp/qemu-rport-_cosim@0: Connection refused
qemu-system-aarch64: info: QEMU waiting for connection on: disconnected:unix:./qemu-tmp/qemu-rport-_cosim@0,server

Then I launch the zynq_demo :

LD_LIBRARY_PATH=/usr/local/systemc-2.3.2/lib-linux64/ ./zynq_demo unix:/opt/pkg/projects/zynq_project/qemu-tmp/qemu-rport-_cosim@0 10000

        SystemC 2.3.2-Accellera --- Apr  7 2020 10:52:59
        Copyright (c) 1996-2017 by all Contributors,
        ALL RIGHTS RESERVED
open socket
connect to /opt/pkg/projects/zynq_project/qemu-tmp/qemu-rport-_cosim@0

It connects and runs

From here QEMU output two extra lines :

qemu-system-aarch64: warning: vlan 0 is not connected to host network
rom: requested regions overlap (rom bootloader. free=0x0000000000a76998, addr=0x0000000000000000)

Note : These lines are also output during normal execution (without co-sim and the modified device tree).

But then QEMU hangs and does not advance further... I checked zynq_demo with GDB, the code executed up to sc_start(1, SC_US); between the reset toggles

    /* Pull the reset signal.  */
    top->rst.write(true);
    sc_start(1, SC_US);   <------ Here
    top->rst.write(false);

which was was called and the simulation is actually waiting on

...
#3  0x00007ffff7888ad1 in sc_core::sc_prim_channel_registry::async_suspend() ()
   from /usr/local/systemc-2.3.2/lib-linux64/libsystemc-2.3.2.so
#4  0x00007ffff786f21c in sc_core::sc_simcontext::simulate(sc_core::sc_time const&) ()
   from /usr/local/systemc-2.3.2/lib-linux64/libsystemc-2.3.2.so
#5  0x00007ffff786f695 in sc_core::sc_start(sc_core::sc_time const&, sc_core::sc_starvation_policy) ()
   from /usr/local/systemc-2.3.2/lib-linux64/libsystemc-2.3.2.so
#6  0x000055555558271c in sc_core::sc_start (p=sc_core::SC_RUN_TO_TIME, unit=sc_core::SC_US, duration=1)
    at /usr/local/systemc-2.3.2/include/sysc/kernel/sc_simcontext.h:105
#7  sc_main (argc=3, argv=<optimized out>) at zynq_demo.cc:118

Then nothings happens until I quit the zynq_demo with Ctrl-C at which point QEMU outputs a final line :

qemu-system-aarch64: /cosim@0: Disconnected clk=10000 ns

I could not go past this stage.

I went through all the documentation I could find, the README on this github, the doc on https://github.com/Xilinx/libsystemctlm-soc and UG1169 https://www.xilinx.com/support/documentation/sw_manuals/xilinx2019_2/ug1169-xilinx-qemu.pdf The wiki https://xilinx-wiki.atlassian.net/wiki/spaces/A/pages/18842109/QEMU+SystemC+and+TLM+CoSimulation And even this external source http://users.ece.utexas.edu/~gerstl/ee382m_f18/labs/QEMU_SystemC_Tutorial.htm

It would be appreciated if anyone had insights in what is going wrong or how to debug this.

Thanks it is appreciated.

edgarigl commented 4 years ago

Hi Rick,

Could you please try adding a clock to zynq_demo.cc? Something like the following:

diff --git a/zynq_demo.cc b/zynq_demo.cc index cb5ae69..7845555 100644 --- a/zynq_demo.cc +++ b/zynq_demo.cc @@ -49,6 +49,7 @@ using namespace std;

SC_MODULE(Top) {

edgarigl commented 4 years ago

Hi, I've pushed a fix for this now. Let me know if it works for you!

Cheers, Edgar

rick-heig commented 4 years ago

Hello.

Thank you for your solution, that was it, once the clock was added the co-simulation did run.

I was able to boot my Linux kernel and also was able to query the "debugdev" from Linux (through devmem).

Thank you for your time ! Best regards. Rick

edgarigl commented 4 years ago

Great, thanks for letting me know!