Skip to content

Instantly share code, notes, and snippets.

@willdurand

willdurand/Makefile Secret

Last active Jan 24, 2021
Embed
What would you like to do?
Minimal bare metal project for Raspberry Pi 2
.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
#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();
}
}
}
ENTRY(_start)
SECTIONS
{
. = 0x8000;
.text :
{
KEEP(*(.text.boot))
*(.text*)
}
.rodata :
{
*(.rodata*)
. = ALIGN(4K);
}
/DISCARD/ :
{
*(.comment)
}
}
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