Booting Raspberry Pi 3: Difference between revisions

switched pre to source
[unchecked revision][unchecked revision]
No edit summary
(switched pre to source)
Line 2:
{{Spelling}}
{{FirstPerson}}
{{Rating|1}}
This is a tutorial on bare-metal OS development on the Raspberry Pi 3 (RPi 3).
 
Line 32 ⟶ 33:
There is also another file required to boot properly. A config.txt file must be supplied to provide configuration details for the device and the OS. Here are the only entries you need:
 
<source lang="ini">
<pre>
boot_delay=1
force_turbo=1
enable_uart=1
</presource>
 
More details about booting and configuration can be found at thse links.
Line 65 ⟶ 66:
 
'''The start address and alignment are for the RPi3. Use whatever is applicable to you.'''
<source lang="c">
<pre>
SECTIONS
{
Line 87 ⟶ 88:
}
}
</presource>
 
== Booting the Kernel ==
Line 93 ⟶ 94:
For the RPi 3, after the start.elf finishes, the CPU and SRAM have been enabled and control is given to the kernel image. But there are a few things we must do in order to set up a basic C environment. This is known as a bootstrap stage which initializes our OS and programming environment on startup and hands control to the kernel. Keep in mind that this is for a minimalistic development environment on a single core.
 
<source lang="asm">
<pre>
.section .boot
 
Line 104 ⟶ 105:
0: wfe
b 0b
</presource>
 
The mrs instruction loads data from specialty registers into a standard register. This special register in question is called the MPIDR or the Multiprocessor Affinity Register. Caring only about the first two bits only we use a bitwise and to weed out any core ID's that aren't zero. Then we apply the cbz instruction, which is a shorthand instruction for comparing the x0 register with 0 and branching if they are equal, i.e. core 0.
Line 110 ⟶ 111:
If the core ID is 0, we branch to another section that will initialize the environment and will hand control over to the kernel. For now, the C function for our kernel will simply by kern_main.
 
<source lang="asm">
<pre>
_init:
b kern_main
</presource>
 
== Writing the Kernel ==
Line 119 ⟶ 120:
The kernel is as simple as creating a kern_main function for the bootstrap stage to transfer control to. You notice that in start.S we have the program branch into the function. All we need to do is provide one.
 
<source lang="c">
<pre>
 
#include <stdbool.h>
Line 128 ⟶ 129:
while (true);
}
</presource>
 
== Conclusion ==
Anonymous user