Pibben
Posts: 12
Joined: Wed Feb 11, 2015 11:53 am

Bare metal in qemu - serial port?

Thu Mar 31, 2016 6:41 am

I'm playing a bit with emulating raspberry pi 2 in qemu, using

https://github.com/0xabu/qemu/tree/raspi

.

Booting raspbian works fine and I can see the rpi's serial console on my console (using the -serial stdin argument to qemu). However, when I try a bare metal example that use the serial port, I get no printouts in my console. Am I wrong to expect it? Is the uart use din bare metal programming not "connected" to qemu serial output?

Thanks!

swarren
Posts: 45
Joined: Tue Mar 01, 2016 5:56 am

Re: Bare metal in qemu - serial port?

Thu Mar 31, 2016 6:29 pm

That's odd; I ran (RPi 2) U-Boot on that same qemu and the serial port worked just fine. You are passing your bare metal code to qemu as a firmware image not as a kernel image right? That affects load address (I assume 0 vs 0x8000), and perhaps whether any DT/ATAGS are written to memory over the top of your binary (I don't know whether the Pi qemu port is integrated with the regular qemu kernel/DT options yet or not).

Pibben
Posts: 12
Joined: Wed Feb 11, 2015 11:53 am

Re: Bare metal in qemu - serial port?

Thu Mar 31, 2016 6:42 pm

Thanks!

How do use it as firmware image? Here is my command line:

[code]qemu-system-arm -M raspi2 -kernel arm-tutorial-rpi/part-5/armc-016/scripts/kernel.img -serial stdio[/code]

swarren
Posts: 45
Joined: Tue Mar 01, 2016 5:56 am

Re: Bare metal in qemu - serial port?

Sat Apr 02, 2016 3:21 am

Code: Select all

-bios
is the option you want. Here's my full script:

Code: Select all

#!/bin/bash

# cd ~/git_wa/rpi
# qemu-img convert -O vhdx 2015-09-24-raspbian-jessie.img qemu09.vhd

#gdb="gdb --args"
gdb=

#qemu=/home/swarren/git_wa/qemu/build/arm-softmmu/qemu-system-arm
qemu=/home/swarren/git_wa/qemu-0xabu/build/arm-softmmu/qemu-system-arm

mach=raspi2
#mach=raspi

fw=
fw="-bios /home/swarren/git_wa/rpi/u-boot.git/build-rpi_2/u-boot.bin"

#kernel="-kernel /home/swarren/git_wa/rpi/firmware.git/boot/kernel7.img"
#kernel="-kernel /home/swarren/git_wa/rpi/tools.git/mkimage/kernel.img"
#kernel="-kernel /home/swarren/git_wa/rpi/u-boot.git/build-rpi/u-boot.bin"
#kernel="-kernel /home/swarren/git_wa/rpi/u-boot.git/build-rpi_2/u-boot.bin"
kernel=""

#append='-append "rw earlyprintk loglevel=8 console=ttyAMA0 root=/dev/mmcblk0p2"'
append=""

#sd="-drive file=/home/swarren/git_wa/rpi/2015-05-05-raspbian-wheezy.img,format=raw"
#sd="-drive file=/home/swarren/git_wa/rpi/2015-09-24-raspbian-jessie.img,format=raw"
sd="-drive file=/home/swarren/git_wa/rpi/2016-02-26-raspbian-jessie.img,format=raw"
#sd="-sd /home/swarren/git_wa/rpi/2015-05-05-raspbian-wheezy.img"
#sd="-sd /home/swarren/git_wa/rpi/2015-09-24-raspbian-jessie.img"
#sd="-drive file=/home/swarren/git_wa/rpi/qemu05.vhd"
#sd="-drive file=/home/swarren/git_wa/rpi/qemu09.vhd"
#sd="-sd /home/swarren/git_wa/rpi/qemu05.vhd"
#sd="-sd /home/swarren/git_wa/rpi/qemu09.vhd"

net=
#net="-usbdevice net"

extra=
#extra="-s -S"

#serial=mon:stdio # CTRL-C passed to VM
serial=stdio # CTRL-C aborts qemu

exec ${gdb} ${qemu} -M ${mach} ${fw} ${kernel} ${append} -serial ${serial} ${sd} ${net} ${extra}

Pibben
Posts: 12
Joined: Wed Feb 11, 2015 11:53 am

Re: Bare metal in qemu - serial port?

Sat Apr 02, 2016 3:56 am

Thank you!

Using the -bios option made the program run (i get stuff on the frame buffer), but there's still no serial output. I think I'm going to try another example...

Pibben
Posts: 12
Joined: Wed Feb 11, 2015 11:53 am

Re: Bare metal in qemu - serial port?

Fri Apr 08, 2016 6:53 am

I think I found the problem now. The non-working example used the AUX Mini UART (register 0x20215040 ...) and an example that actually works uses the PL011 UART (register 0x20201000 ...).

So I guess it's the PL011 that is "connected" to the Qemu serial output.

How are the UARTs connected on the actual board(s)?

swarren
Posts: 45
Joined: Tue Mar 01, 2016 5:56 am

Re: Bare metal in qemu - serial port?

Fri Apr 08, 2016 2:07 pm

On track HW, either UART can be connected to the GPIO headers. The GPIO HW module contains pinmux registers that control which UART is routed to which pins.

By default the VC FW connects the PL011 to the GPIO header pins on the Pi 0/1/2 and the mini UART on the Pi 3, although DT overlay options in config.txt can modify this behavior.

Return to “Bare metal, Assembly language”