I just wanted to start a thread about some links and guides to start bare metal programming on raspberry pi to give you a head start.
First of all some links which helped me alot to get a "feeling" for arm cpus. !
-----------------------
https://github.com/dwelch67/raspberrypi/
From here you should grab the bootloader 4 and have a look at the other sources.
]https://gitorious.org/lambdapi/lambdapi
LambdaPi very interessting for most people to get a bit started on bare metal
http://balau82.wordpress.com/2010/02/28 ... sing-qemu/
Explanation of LD scripts and all to compile a bare metal.
http://wiki.osdev.org/ARM_Overview
An overview of the CPU we are talking about. OSDev is the site for the best infos on coding an Operating System. And another Info for you: Did you know the ARM Cpu cant divide nor make modulo?

-----------------------
What you need to code bare metal (Windows):
- Windows ->
Cygwin
http://www.cygwin.com/
Cross Compiler
https://launchpad.net/gcc-arm-embedded
Something for the UART like this:
http://www.ebay.de/itm/USB-2-0-to-UART- ... 2c65c24878
The bootloader 4 from the link above.
+ Editor (Notepad+, ...)
------------------------
Our first code:
Linker script: (raspi.ld) (can be used for any purpose), the ENTRY(xxxx) is the starting point for your code.
Code: Select all
ENTRY(asm_start)
MEMORY
{
ram : ORIGIN = 0x8000, LENGTH = 0x10000000
}
SECTIONS
{
.text : {
*(.text)
} > ram
.data : { *(.data) } > ram
__bss_start__ = .;
.bss : { *(.bss) } > ram
__bss_end__ = .;
}
Code: Select all
.text
.global asm_start
.global exc_stack
.global supervisor_sp
asm_start:
# initialize Stack pointer for exception modes
mrs r4, cpsr
bic r4, r4, #0x1f
#FIQ Mode
orr r3, r4, #0x11
msr cpsr_c, r3
ldr sp, =exc_stack
#IRQ Mode
orr r3, r4, #0x12
msr cpsr_c, r3
ldr sp, =exc_stack
#ABORT Mode
orr r3, r4, #0x17
msr cpsr_c, r3
ldr sp, =exc_stack
#UNDEFINED Mode
orr r3, r4, #0x1b
msr cpsr_c, r3
ldr sp, =exc_stack
# switch to supervisor mode
orr r3, r4, #0x13
msr cpsr_c, r3
ldr sp, =temp_stack
#
# Create the first stack frame.
#
mov fp, #0
mov ip, sp
push {fp, ip, lr, pc}
sub fp, ip, #4
bl not_main
.globl dummy
dummy:
bx lr
.space 0x100
temp_stack:
.space 1024
exc_stack:
supervisor_sp:
.space 4
Code: Select all
__attribute__((no_instrument_function)) void not_main(void)
{
UINT32 sel = READ32(GPFSEL1);
sel &= ~(0b111 << 18);
sel |= (0b001 << 18);
WRITE32(GPFSEL1,sel);
while(1)
{
WRITE32(GPCLR0, 1<<16);
for (int i = 0; i < 0x100000; i++) ;
WRITE32(GPSET0, 1<<16);
for (int i = 0; i < 0x100000; i++) ;
}
}
and now the makefile (written by tufti, its real cool and does everything!!)
Code: Select all
ARCH = arm-none-eabi
CC = ${ARCH}-gcc
CPP = ${ARCH}-g++
AS = ${ARCH}-as
LD = ${ARCH}-ld
AR = ${ARCH}-ar
OBJCOPY = ${ARCH}-objcopy
PLATFORM = raspi
# Release Version -> Optimize
#CFLAGS = -O3 -std=gnu99 -Werror -D__$(PLATFORM)__ -DRASPBERRY_PI
#ASFLAGS =
CFLAGS = -O0 -g -std=gnu99 -Werror -D__$(PLATFORM)__ -DRASPBERRY_PI -fno-builtin
ASFLAGS = -g
CFLAGS_FOR_TARGET = -mcpu=arm1176jzf-s
ASFLAGS_FOR_TARGET = -mcpu=arm1176jzf-s
LDFLAGS = -nostdlib -static --error-unresolved-symbols
MODULES := raspi
SRC_DIR := $(addprefix src/,$(MODULES))
INC_DIR := $(addsuffix /include,$(SRC_DIR))
BUILD_DIR := $(addsuffix /build,$(SRC_DIR))
ASRC := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.s))
AOBJ := $(ASRC:.s=.o)
CSRC := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.c))
COBJ := $(CSRC:.c=.o)
INCLUDES := -Isrc $(addprefix -I,$(SRC_DIR) $(INC_DIR))
vpath %.c $(SRC_DIR)
vpath %.cpp $(SRC_DIR)
vpath %.s $(SRC_DIR)
%.o: %.c
$(CC) $(CFLAGS_FOR_TARGET) $(INCLUDES) $(CFLAGS) -c -o $*.o $<
%.o: %.s
$(AS) $(ASFLAGS_FOR_TARGET) $(INCLUDES) $(ASFLAGS) -o $*.o $<
OBJ = $(AOBJ) $(COBJ)
bin/kernel.img: bin/kernel.elf
${OBJCOPY} -O binary $< $@
bin/kernel.elf: raspi.ld $(OBJ)
${LD} ${LDFLAGS} $(OBJ) -Map bin/kernel.map -o $@ -T raspi.ld
clean:
rm -f bin/*.elf bin/*.img bin/*.map $(OBJ)
NOTE: If you have more than one directory the make should compile, just add it to the "MODULES " with a blank in between: MODULES := raspi raspisourcecodeexample2
So with these three code snippets and the tools from above you should be ready to dig in to the bare metal programming. The makefile, the linkerscript and the asm part can be kept as they are.