Skip to content

Hello world!

Victor Correal Ramos edited this page May 2, 2020 · 9 revisions

In this section, the first objective is to display a Hello world missatge through UART communication. The working directory is here.

In order to achieve this objective, is needed to understand all the necessary code.

Booting process

There are a few important files to perform a boot:

  • boot.S : Is the first code to be runned, here be need to prepare some parameters and setups.
  • linker.ld : This file contains instructions for the compiler and define some memory regions.
  • kernel.c : here it is the main method, called by the boot.S

With this files correctly programmed, the linker puts the boot.S at the address 0x0 and the CPU starts running this file. When the setup is completed, the boot.S jumps to the kernel.c main method and here it's possible to interact with the memory positions and peripherals.

The GPIO interface

The next step is a lecture of the ARM-peripherals manual and design some interface to work with the GPIO pins and the UART module.

For every GPIO pin there are some predefined function, designed by the GPIO function select register(pg. 91 ). Also, there are particular register for read the actual value of a pin and set/clear a pin. For this particular case, the interface I designed is:

void setfunctionGPIO(int pin, const int F);
void setPin(int pin);
void clrPin(int pin);
enum level {LVL_HIGH, LVL_LOW};
level levelPin(int pin);

The UART module

With this interface, configure the UART module, with the manual instructions is quite simple. The uart_init method configures the UART module to 115200 Bauds.

Using the qemu-AArch64

The latest qemu version can emule a the behavior of a real Raspberry Pi but with some differences with the real Raspberry pi:

  1. Some peripherals don't exists (like the GPIO pins)
  2. The starting address for the boot section is the 0x80000 while the real hardware uses the 0x80000.
  3. The time is not quite realistic For this reason, there is conditional compilation in some regions of code and a specific linker for the Qemu. A script is in all the working folders for running the Qemu with the specific flags and emulate the Raspberry Pi.

gdb-multiarch

For debug the qemu, is necessary to compile with the -g flag and run the qemu with some flags. A script for a qemu debugging session (runDBG.sh) and a script for set the gdb debugger (gdbscript) with the qemu are written.

All together

For use this code in the real Raspberry pi, is necessary to compile all the code (with a Makefile) and put in the SD booting area the kernel8.img file. This file is where the Raspberry Pi boot.

Finally, a printf, string and bool definitions were added for get a better environment development.

Clone this wiki locally