Raspberry Pi Bare Bones: Difference between revisions

Updates QEMU information and notes addresses for raspi2 emulation.
[unchecked revision][unchecked revision]
(Fixed minor bug where delays register could underflow. Marking the register used as an output register fixes it.)
(Updates QEMU information and notes addresses for raspi2 emulation.)
Line 129:
{
// The GPIO registers base address.
GPIO_BASE = 0x20200000, // 0x3F200000 for raspi2 and raspi3
 
// The offsets for reach register.
Line 140:
 
// The base address for UART.
UART0_BASE = 0x20201000, // 0x3F201000 for raspi 2 and raspi3
 
// The offsets for reach register for the UART.
Line 249:
 
Notice how we wish to use the common C function strlen, but this function is part of the C standard library that we don't have available. Instead, we rely on the freestanding header <stddef.h> to provide size_t and we simply declare our own implementation of strlen. You will have to do this for every function you wish to use (as the freestanding headers only provide macros and data types).
 
The addresses for the GPIO and UART are offsets from the peripheral base address, which is 0x20000000 for raspi1 and 0x3F000000 for raspi2 and raspi3. You can find the addresses of registers and how to use them in the bcm2835 manual.
 
Compile using:
Line 380 ⟶ 382:
=== Testing your operating system (QEMU) ===
 
QEMU supports emulating raspberry pi 2 with the machine type "raspi2". At the time of writing this feature is not available in most package managers but can be found in the latest qemu source found here: https://github.com/qemu/qemu
Although vanilla QEMU does not yet support the RaspberryPi hardware, there is [https://github.com/Torlus/qemu/tree/rpi a fork by Torlus] that emulates the RPi hardware sufficiently enough to get started with ARM kernel development. To build QEMU on linux, do as follows:
 
Check that your qemu install has qemu-system-arm and that it supports the option "-M raspi2". When testing in QEMU, be sure to use the raspi2 base addresses noted in the source code.
<source lang=text>
mkdir qemu-build
cd qemu-build
git clone https://github.com/Torlus/qemu/tree/rpi src
mkdir build
cd build
../src/configure --prefix=$YOURINSTALLLOCATION --target-list=arm-softmmu,arm-linux-user,armeb-linux-user --enable-sdl
make && sudo make install
</source>
 
With qemu you do not need to objcopy the kernel into a plain binary; QEMU also supports ELF kernels:
 
<source lang=text>
$YOURINSTALLLOCATION/bin/qemu-system-arm -kernel kernel.elf -cpu arm1176 -m 256 -M raspiraspi2 -serial stdio
</source>
 
Note that currently the QEMU "raspiraspi2" emulation may incorrectly load the kernel binaries at 0x10000 instead of 0x8000, so if you do not see any output, try adjusting the base address constant in the linker script.
 
== See Also ==
Anonymous user