Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Enabling UART1 on QEMU MPSoC
#1
The Zynq MPSoC has two standard UART controllers which, on REMUS and the actual chip, can be used for two independent serial connections. Unfortunately, the default configurations for QEMU in the Beta2 release actively disables the second UART. Fortunately, with a few minor modifications you can enable UART1 and setup QEMU to run so that serial port is connected to a telnet session (or pipe, pty, or file). 

At the high level, you need to enable UART1 in the dtb (device tree blob) that is passed to QEMU which tells it which devices to emulate, you need to update the dtb that is passed to Xen on boot to fix an interrupt issue, and finally you need to invoke QEMU with the options to redirect the input/output of UART1 to a device/file/pipe on your host.

This procedure assumes you have downloaded XZD and created a Xilinx MPSoC project.


1. Enable UART1 in QEMU dtb

a. Convert the QEMU dtb file to dts (device tree specification).

source <petalinux dir>/settings.sh

dtc -I dtb -O dts <project directory>/images/linux/xilinx-ronalado-arm.dtb  -o qemu.dts


b. Delete the line disabling UART1 in qemu.dts (file you just created). Search for serial@FF010000 in your favorite text editor and delete the offending text at line 1013. Save your changes.

  serial@0xFF010000 {

                        compatible = "xlnx,ps7-uart-1.00.a", "xlnx,xuartps";
                        current-speed = <0x1c200>;
                        interrupts = <0x16>;
                        port-number = <0x0>;
                        reg = <0x0 0xff010000 0x1000>;
                        xlnx,has-modem = <0x0>;
                        xlnx,uart-clk-freq-hz = <0x2faf080>;
                        clock-names = "ref_clk", "aper_clk";
                        clocks = <0x29 0x29>;
                        ttrig-polarity = <0x1>;
                        status = "disabled";
                };


c. Convert the modified dts file back to dtb.

dtc -I dts -O dtb qemu.dts -o <project directory>/images/linux/xilinx-ronalado-arm.dtb



2. Update the Xen dtb file

a. Edit the xen.dts file provided in the XZD, located at <XZD path>/dts/xen.dts, and change the UART1's interrupt from level triggered to edge triggered (line 363, change 0x4 to 0x1), and delete the text on 361. Save your changes.


  serial@ff010000 {
                        compatible = "cdns,uart-r1p8";
                        status = "disabled";
                        interrupt-parent = <0x1>;
                        interrupts = <0x0 0x16 0x1>;
                        reg = <0x0 0xff010000 0x1000>;
                        clock-names = "uart_clk", "pclk";
                        clocks = <0x2 0x2>;
                };


b. Rebuild the xen.dtb file.

$ cd <XZD directory>
$ make install-xen-dtb



3. Invoke QEMU with options to redirect UART1 to host device (in this case a telnet session)

a. Run standard QEMU to get default parameters. Copy the QEMU arguments.


$ cd <XZD directory>

$ make boot


Was PetaLinux settings.sh sourced? YES

touch /home/jarvis/CONFIDENTIAL_Zinq_Next_Gen_Hypervisor_2132/.running
# Note, this target won't ever finish until the device is powered off...
cd /home/jarvis/CONFIDENTIAL_Zinq_Next_Gen_Hypervisor_2132/Xilinx-ZynqMP && petalinux-boot --qemu --u-boot --qemu-args "-drive file=/home/jarvis/CONFIDENTIAL_Zinq_Next_Gen_Hypervisor_2132/Xilinx-ZynqMP/images/dom0.qcow,format=qcow2,id=sata-drive -device ide-drive,drive=sata-drive,bus=ahci@0xFD0C0000.0 -redir tcp:2222::22" | tee /home/jarvis/CONFIDENTIAL_Zinq_Next_Gen_Hypervisor_2132/.running && rm -f /home/jarvis/CONFIDENTIAL_Zinq_Next_Gen_Hypervisor_2132/.running
qemu_cmd=qemu-system-aarch64
--------------------------------------------------------------------
Xilinx QEMU Apr  9 2015 20:01:21.
--------------------------------------------------------------------
INFO: TCP PORT is free 
INFO: Starting aarch64 QEMU
INFO:  qemu-system-aarch64 -L /home/jarvis/CONFIDENTIAL_Zinq_Next_Gen_Hypervisor_2132/petalinux-v2015.SW_Beta2-final/etc/qemu -M arm-generic-fdt -device loader,addr=0xfd1a0104,data=0x8000000e,data-len=4   -serial mon:stdio -serial /dev/null -display none -device loader,file=/home/jarvis/CONFIDENTIAL_Zinq_Next_Gen_Hypervisor_2132/Xilinx-ZynqMP/images/linux/bl31.elf,cpu=0 -device loader,file=/home/jarvis/CONFIDENTIAL_Zinq_Next_Gen_Hypervisor_2132/Xilinx-ZynqMP/images/linux/u-boot.elf -gdb tcp::9000  -tftp /tftpboot -drive file=/home/jarvis/CONFIDENTIAL_Zinq_Next_Gen_Hypervisor_2132/Xilinx-ZynqMP/images/dom0.qcow,format=qcow2,id=sata-drive -device ide-drive,drive=sata-drive,bus=ahci@0xFD0C0000.0 -redir tcp:2222::22 -hw-dtb /home/jarvis/CONFIDENTIAL_Zinq_Next_Gen_Hypervisor_2132/Xilinx-ZynqMP/images/linux/xilinx-ronaldo-arm.dtb -pflash /home/jarvis/CONFIDENTIAL_Zinq_Next_Gen_Hypervisor_2132/Xilinx-ZynqMP/images/linux/nand0.qcow2 -pflash /home/jarvis/CONFIDENTIAL_Zinq_Next_Gen_Hypervisor_2132/Xilinx-ZynqMP/images/linux/nand0.qcow2


b. Paste the QEMU invocation to a command prompt, replace the "-serial /dev/null" option with "-serial telnet::4444,server".

qemu-system-aarch64 -L /home/jarvis/CONFIDENTIAL_Zinq_Next_Gen_Hypervisor_2132/petalinux-v2015.SW_Beta2-final/etc/qemu -M arm-generic-fdt -device loader,addr=0xfd1a0104,data=0x8000000e,data-len=4   -serial mon:stdio -serial telnet::4444,server -display none -device loader,file=/home/jarvis/CONFIDENTIAL_Zinq_Next_Gen_Hypervisor_2132/Xilinx-ZynqMP/images/linux/bl31.elf,cpu=0 -device loader,file=/home/jarvis/CONFIDENTIAL_Zinq_Next_Gen_Hypervisor_2132/Xilinx-ZynqMP/images/linux/u-boot.elf -gdb tcp::9000  -tftp /tftpboot -drive file=/home/jarvis/CONFIDENTIAL_Zinq_Next_Gen_Hypervisor_2132/Xilinx-ZynqMP/images/dom0.qcow,format=qcow2,id=sata-drive -device ide-drive,drive=sata-drive,bus=ahci@0xFD0C0000.0 -redir tcp:2222::22 -hw-dtb /home/jarvis/CONFIDENTIAL_Zinq_Next_Gen_Hypervisor_2132/Xilinx-ZynqMP/images/linux/xilinx-ronaldo-arm.dtb -pflash /home/jarvis/CONFIDENTIAL_Zinq_Next_Gen_Hypervisor_2132/Xilinx-ZynqMP/images/linux/nand0.qcow2 -pflash /home/jarvis/CONFIDENTIAL_Zinq_Next_Gen_Hypervisor_2132/Xilinx-ZynqMP/images/linux/nand0.qcow2


Note the bolded text is what you can change for other redirection options (such as file:<path to file>, pipe:<path to pipe>, pty, etc). For more details see QEMU User Doc.

c. From another terminal, run telnet:

$ telnet localhost 4444

At this point, the QEMU should boot to a dom0 login prompt (user: root, pwd: root). From the dom0 shell, you will see that ttyPS0 was installed (ls /dev or dmesg | grep tty). Writing to or reading from /dev/ttyPS0 from the guest will result in reverse operation on the host device. For example, echo hello > /dev/ttyPS0 will cause "hello" to appear on the telnet terminal, and cat /dev/ttyPS0 will display strings of data entered in the telnet terminal after a newline (return) is entered.

From dom0:

[root@xilinx-dom0 ~]# dmesg | grep tty

[    4.225433] xuartps ff010000.serial: ttyPS0 at MMIO 0xff010000 (irq = 54, base_baud = 1562500) is a xuartps
[root@xilinx-dom0 ~]# echo hello > /dev/ttyPS0
[root@xilinx-dom0 ~]# cat /dev/ttyPS0
This data is coming from the telnet session
blah
asdfasd;gja;lsdgja;klgja;lksdgja;lkdfgja;lsdfkgjakl;gja;klgha;klghakl;dgal;ksdgjal;skghakl;gha;lskdgha;lskdgha;lsdkgha;lsgha;lsdghka;slgkha;sdklgha;slgkhas;lgkha;slgkha;sdlghka;gklhal;sdgkha;sgklhasd;gklahdg;lkhadg;khasd;ghklasd;gkahsd;gklahsd;gklahsdg;ahsdg;aklshdg;aklsdhg;alskdgh;aklsdgh;alsdkgha;sldkgha;sdlgh;alskdgh;asdghka;sdlgkha;sdlghka;sdghasdkl;gha;sdghka;sdklghas;dklgha;sldkgha;sdklgha;sdlgkha;sdlgha;sdlgkhasdl;gkhasdl;gkhas;dlgkhasdl;gkah
String is sent when enter/return/newline is typed in telnet session



From the host terminal:


$ telnet localhost 4444

Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
hello
This data is coming from the telnet session
blah

asdfasd;gja;lsdgja;klgja;lksdgja;lkdfgja;lsdfkgjakl;gja;klgha;klghakl;dgal;ksdgjal;skghakl;gha;lskdgha;lskdgha;lsdkgha;lsgha;lsdghka;slgkha;sdklgha;slgkhas;lgkha;slgkha;sdlghka;gklhal;sdgkha;sgklhasd;gklahdg;lkhadg;khasd;ghklasd;gkahsd;gklahsd;gklahsdg;ahsdg;aklshdg;aklsdhg;alskdgh;aklsdgh;alsdkgha;sldkgha;sdlgh;alskdgh;asdghka;sdlgkha;sdlghka;sdghasdkl;gha;sdghka;sdklghas;dklgha;sldkgha;sdklgha;sdlgkha;sdlgha;sdlgkhasdl;gkhasdl;gkhas;dlgkhasdl;gkah

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)