Add ARM basic bootloader build
This commit is contained in:
parent
47059c1c15
commit
d83d42fb60
32
arm/bootloader.ld
Normal file
32
arm/bootloader.ld
Normal file
@ -0,0 +1,32 @@
|
||||
MEMORY
|
||||
{
|
||||
ICTM (rwx) : ORIGIN = 0x00000000, LENGTH = 16384
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
.text :
|
||||
{
|
||||
KEEP(vector_table.o(.vector_table))
|
||||
|
||||
*(.text*)
|
||||
*(.rodata*)
|
||||
} > ICTM
|
||||
|
||||
.bss (NOLOAD) :
|
||||
{
|
||||
_bss_begin = .;
|
||||
*(.bss*)
|
||||
*(COMMON)
|
||||
_bss_end = .;
|
||||
} > ICTM
|
||||
|
||||
.data :
|
||||
{
|
||||
*(.data*)
|
||||
|
||||
__exidx_start = .;
|
||||
*(.exidx*)
|
||||
__exidx_end = .;
|
||||
} > ICTM
|
||||
}
|
13
arm/main.cc
Normal file
13
arm/main.cc
Normal file
@ -0,0 +1,13 @@
|
||||
#include <cstdint>
|
||||
|
||||
struct Gpio {
|
||||
volatile uint32_t data;
|
||||
};
|
||||
|
||||
#define gpio0 ((Gpio*) 0x40000000)
|
||||
|
||||
int main() {
|
||||
gpio0->data = 42;
|
||||
|
||||
while (true) {}
|
||||
}
|
25
arm/makefile
Normal file
25
arm/makefile
Normal file
@ -0,0 +1,25 @@
|
||||
CC = arm-none-eabi-gcc
|
||||
LD = arm-none-eabi-gcc
|
||||
CXX = arm-none-eabi-g++
|
||||
OBJCOPY = arm-none-eabi-objcopy
|
||||
|
||||
linker_script = bootloader.ld
|
||||
|
||||
CFLAGS = -march=armv6-m -g -ffunction-sections -fdata-sections -O2
|
||||
CXXFLAGS = $(CFLAGS) -std=c++20 -fno-exceptions
|
||||
LDFLAGS = -march=armv6-m -g --specs=nano.specs --specs=nosys.specs -Wl,--gc-sections -Wl,-T$(linker_script) -O2
|
||||
|
||||
all: bootloader.bin
|
||||
|
||||
%.bin: %.elf
|
||||
$(OBJCOPY) -O binary $< $@
|
||||
|
||||
bootloader.elf: main.o vector_table.o
|
||||
|
||||
%.elf:
|
||||
$(LD) $(LDFLAGS) -o $@ $^
|
||||
|
||||
.PHONY: clean
|
||||
|
||||
clean:
|
||||
rm -rf *.elf *.bin *.o
|
30
arm/vector_table.cc
Normal file
30
arm/vector_table.cc
Normal file
@ -0,0 +1,30 @@
|
||||
#include <cstdint>
|
||||
|
||||
extern "C" uint32_t _bss_begin, _bss_end;
|
||||
extern "C" int main();
|
||||
|
||||
namespace {
|
||||
|
||||
enum VectorTableEntry {
|
||||
StackPointer = 0,
|
||||
Reset = 1,
|
||||
};
|
||||
|
||||
void ResetHandler() {
|
||||
// clear .bss
|
||||
for (uint32_t* ptr = &_bss_begin; ptr < &_bss_end; ptr++) {
|
||||
*ptr = 0;
|
||||
}
|
||||
|
||||
main();
|
||||
|
||||
while(true) {}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
__attribute__((section(".vector_table")))
|
||||
uint32_t vector_table[16] = {
|
||||
[StackPointer] = 0x00010000,
|
||||
[Reset] = reinterpret_cast<uint32_t>(ResetHandler),
|
||||
};
|
Loading…
Reference in New Issue
Block a user