-
-
Save willdurand/614ad3ad1cac0189691f67c0ac71b9e6 to your computer and use it in GitHub Desktop.
Minimal bare metal project for Raspberry Pi 2 - https://williamdurand.fr/2021/01/23/bare-metal-raspberry-pi-2-programming/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.section ".text.boot" | |
.globl _start | |
_start: | |
# Setup the stack. | |
mov sp, #0x8000 | |
bl kernel_main | |
halt: | |
wfe | |
b halt | |
.globl do_nothing | |
do_nothing: | |
bx lr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdint.h> | |
#define GPFSEL4 0x3F200010 | |
#define GPSET1 0x3F200020 | |
#define GPCLR1 0x3F20002C | |
extern void do_nothing(); | |
void kernel_main() { | |
*(volatile uint32_t *)GPFSEL4 &= ~(7 << 21); | |
*(volatile uint32_t *)GPFSEL4 |= 1 << 21; | |
while (1) { | |
*(volatile uint32_t *)GPSET1 = 1 << (47 - 32); | |
for (uint32_t i = 0; i < 0x100000; i++) { | |
do_nothing(); | |
} | |
*(volatile uint32_t *)GPCLR1 = 1 << (47 - 32); | |
for (uint32_t i = 0; i < 0x100000; i++) { | |
do_nothing(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ENTRY(_start) | |
SECTIONS | |
{ | |
. = 0x8000; | |
.text : | |
{ | |
KEEP(*(.text.boot)) | |
*(.text*) | |
} | |
.rodata : | |
{ | |
*(.rodata*) | |
. = ALIGN(4K); | |
} | |
/DISCARD/ : | |
{ | |
*(.comment) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
default: all | |
CFLAGS = -mcpu=cortex-a7 -ffreestanding -nostdlib -fno-builtin -Wall -Wextra | |
all: kernel7.img | |
kernel7.img: kernel.elf | |
arm-none-eabi-objcopy $< -O binary $@ | |
kernel.elf: boot.o kernel.o | |
arm-none-eabi-gcc $(CFLAGS) -T linker.ld -o $@ $^ | |
boot.o: boot.S | |
arm-none-eabi-gcc $(CFLAGS) -c $< -o $@ | |
kernel.o: kernel.c | |
arm-none-eabi-gcc $(CFLAGS) -c $< -o $@ | |
clean: | |
rm -f *.o *.img *.elf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment