From 6aa5f184295a90bcf53095122c0eab9dd170d565 Mon Sep 17 00:00:00 2001 From: liangkangnan Date: Sat, 1 Apr 2023 15:06:00 +0800 Subject: [PATCH] tools: add bootrom Signed-off-by: liangkangnan --- tools/bootrom/.gitignore | 6 ++++++ tools/bootrom/Makefile | 19 +++++++++++++++++++ tools/bootrom/README.md | 10 ++++++++++ tools/bootrom/bootrom.S | 10 ++++++++++ tools/bootrom/link.ld | 11 +++++++++++ 5 files changed, 56 insertions(+) create mode 100644 tools/bootrom/.gitignore create mode 100644 tools/bootrom/Makefile create mode 100644 tools/bootrom/README.md create mode 100644 tools/bootrom/bootrom.S create mode 100644 tools/bootrom/link.ld diff --git a/tools/bootrom/.gitignore b/tools/bootrom/.gitignore new file mode 100644 index 0000000..213f0be --- /dev/null +++ b/tools/bootrom/.gitignore @@ -0,0 +1,6 @@ +# Object files +*.o +*.bin +*.elf +*.mem +*.dump diff --git a/tools/bootrom/Makefile b/tools/bootrom/Makefile new file mode 100644 index 0000000..fd513ce --- /dev/null +++ b/tools/bootrom/Makefile @@ -0,0 +1,19 @@ +target := bootrom + +BIN2MEM := ../BinToMem.py + +RISCV_TOOLS_PATH := /opt/riscv32/bin +RISCV_TOOLS_PREFIX := riscv32-unknown-elf- + +GCC?=$(abspath $(RISCV_TOOLS_PATH)/$(RISCV_TOOLS_PREFIX)gcc) +OBJCOPY?=$(abspath $(RISCV_TOOLS_PATH)/$(RISCV_TOOLS_PREFIX)objcopy) +OBJDUMP?=$(abspath $(RISCV_TOOLS_PATH)/$(RISCV_TOOLS_PREFIX)objdump) + +all: + $(GCC) -Tlink.ld bootrom.S -march=rv32im -mabi=ilp32 -mcmodel=medlow -nostartfiles -nostdlib -static -Wl,--no-gc-sections -o $(target).elf + $(OBJCOPY) -O binary $(target).elf $(target).bin + $(OBJDUMP) -d $(target).elf --disassemble-all --disassemble-zeroes --section=.text --section=.text.startup --section=.text.init --section=.data > $(target).dump + $(BIN2MEM) $(target).bin $(target).mem + +clean: + rm -f *.img *.dump *.bin *.sv *.elf *.mem diff --git a/tools/bootrom/README.md b/tools/bootrom/README.md new file mode 100644 index 0000000..977dede --- /dev/null +++ b/tools/bootrom/README.md @@ -0,0 +1,10 @@ +Bootrom源码。 + +当从外部Flash启动时,需要先从此Bootrom启动(做一些初始化操作),然后通过Bootrom跳转到Flash地址空间,执行用户程序。 + +编译: + +``` +make +``` + diff --git a/tools/bootrom/bootrom.S b/tools/bootrom/bootrom.S new file mode 100644 index 0000000..3d35a5f --- /dev/null +++ b/tools/bootrom/bootrom.S @@ -0,0 +1,10 @@ + + .global entry + .option norvc +entry: + lui a0, 0x0200 + slli a0, a0, 0x4 + // jump to 0x02000000 + jalr a0 +loop: + j loop diff --git a/tools/bootrom/link.ld b/tools/bootrom/link.ld new file mode 100644 index 0000000..51c1c46 --- /dev/null +++ b/tools/bootrom/link.ld @@ -0,0 +1,11 @@ +OUTPUT_ARCH( "riscv" ) +ENTRY( entry ) +SECTIONS +{ + . = 0x01000000; + .text : + { + *(.text) + } + _end = .; +}