mirror of
https://github.com/im-tomu/foboot.git
synced 2024-09-20 02:40:09 +00:00
Merge pull request #148 from swillner/ram-boot
Add makefile options to simplify compiling for RAM boot
This commit is contained in:
commit
3684493f5e
@ -14,7 +14,7 @@ At start, **FBU** is loaded by the hardware. **FBU** will look for a special *F
|
|||||||
|
|
||||||
## Boot Flags
|
## Boot Flags
|
||||||
|
|
||||||
A series of *Boot Fags* determine how **FBU** and **FBM** hand over execution to the subsequent program.
|
A series of *Boot Flags* determines how **FBU** and **FBM** hand over execution to the subsequent program.
|
||||||
|
|
||||||
*Boot Flags* are indicated by the magic number `0xb469075a`, followed by a
|
*Boot Flags* are indicated by the magic number `0xb469075a`, followed by a
|
||||||
32-bit field, in the first 128 bytes of the binary.
|
32-bit field, in the first 128 bytes of the binary.
|
||||||
@ -28,6 +28,8 @@ struct {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
These can be provided when making the program (when using a Makefile as in `examples/riscv-blink`), e.g. `make LOAD_BOOT_CONFIG=0x00000020`.
|
||||||
|
|
||||||
| Bit Flag | Short Name | Description |
|
| Bit Flag | Short Name | Description |
|
||||||
| -------- | ------------ | ------------------------------------------------ |
|
| -------- | ------------ | ------------------------------------------------ |
|
||||||
| 00000001 | QPI_EN | Enable QPI mode on the SPI flash |
|
| 00000001 | QPI_EN | Enable QPI mode on the SPI flash |
|
||||||
@ -45,6 +47,8 @@ If the DFU bootloader encounters the magic number `0x17ab0f23` within the first
|
|||||||
|
|
||||||
Note that the value following the magic number indicates the offset where the program will be loaded to. This should be somewhere in RAM. `0x10001000` is a good value, and is guaranteed to not interfere with Foboot itself.
|
Note that the value following the magic number indicates the offset where the program will be loaded to. This should be somewhere in RAM. `0x10001000` is a good value, and is guaranteed to not interfere with Foboot itself.
|
||||||
|
|
||||||
|
When using a Makefile as in `examples/riscv-blink` you can provide the offset as in `make LOAD_RAM_ADDR=0x10001000`. This makes sure that the linker links the binary as one block.
|
||||||
|
|
||||||
## Magic Numbers
|
## Magic Numbers
|
||||||
|
|
||||||
| Value | Description |
|
| Value | Description |
|
||||||
|
@ -26,15 +26,29 @@ LD_DIR := $(BASE_DIR)/ld
|
|||||||
LDSCRIPT := $(BASE_DIR)/ld/linker.ld
|
LDSCRIPT := $(BASE_DIR)/ld/linker.ld
|
||||||
ADD_CFLAGS := -I$(BASE_DIR)/include -D__vexriscv__ -march=rv32i -mabi=ilp32
|
ADD_CFLAGS := -I$(BASE_DIR)/include -D__vexriscv__ -march=rv32i -mabi=ilp32
|
||||||
ADD_LFLAGS :=
|
ADD_LFLAGS :=
|
||||||
PACKAGE := example
|
PACKAGE := riscv-blink
|
||||||
|
|
||||||
LDSCRIPTS := $(LDSCRIPT) $(LD_DIR)/output_format.ld $(LD_DIR)/regions.ld
|
ifdef LOAD_RAM_ADDR
|
||||||
|
LDREGIONS := $(LD_DIR)/regions_ram.ld
|
||||||
|
ADD_CFLAGS += -DLOAD_RAM_ADDR=$(LOAD_RAM_ADDR)
|
||||||
|
ADD_LFLAGS += -Wl,--defsym=LOAD_RAM_ADDR=$(LOAD_RAM_ADDR)
|
||||||
|
else
|
||||||
|
LDREGIONS := $(LD_DIR)/regions.ld
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifdef LOAD_BOOT_CONFIG
|
||||||
|
ADD_CFLAGS += -DLOAD_BOOT_CONFIG=$(LOAD_BOOT_CONFIG)
|
||||||
|
endif
|
||||||
|
|
||||||
|
LDSCRIPTS := $(LDSCRIPT) $(LDREGIONS) $(LD_DIR)/output_format.ld
|
||||||
SRC_DIR := $(BASE_DIR)/src
|
SRC_DIR := $(BASE_DIR)/src
|
||||||
THIRD_PARTY := $(BASE_DIR)/third_party
|
THIRD_PARTY := $(BASE_DIR)/third_party
|
||||||
DBG_CFLAGS := -ggdb -g -DDEBUG -Wall
|
DBG_CFLAGS := -ggdb -g -DDEBUG -Wall
|
||||||
DBG_LFLAGS := -ggdb -g -Wall
|
DBG_LFLAGS := -ggdb -g -Wall
|
||||||
CFLAGS := $(ADD_CFLAGS) \
|
CFLAGS := $(ADD_CFLAGS) \
|
||||||
|
-D__vexriscv__ -march=rv32i -mabi=ilp32 \
|
||||||
-Wall -Wextra \
|
-Wall -Wextra \
|
||||||
|
-flto \
|
||||||
-ffunction-sections -fdata-sections -fno-common \
|
-ffunction-sections -fdata-sections -fno-common \
|
||||||
-fomit-frame-pointer -Os \
|
-fomit-frame-pointer -Os \
|
||||||
-march=rv32i \
|
-march=rv32i \
|
||||||
@ -42,8 +56,10 @@ CFLAGS := $(ADD_CFLAGS) \
|
|||||||
CXXFLAGS := $(CFLAGS) -std=c++11 -fno-rtti -fno-exceptions
|
CXXFLAGS := $(CFLAGS) -std=c++11 -fno-rtti -fno-exceptions
|
||||||
LFLAGS := $(CFLAGS) $(ADD_LFLAGS) -L$(LD_DIR) \
|
LFLAGS := $(CFLAGS) $(ADD_LFLAGS) -L$(LD_DIR) \
|
||||||
-nostartfiles \
|
-nostartfiles \
|
||||||
|
-nostdlib \
|
||||||
-Wl,--gc-sections \
|
-Wl,--gc-sections \
|
||||||
-Wl,--no-warn-mismatch \
|
-Wl,--no-warn-mismatch \
|
||||||
|
-Wl,--script=$(LDREGIONS) \
|
||||||
-Wl,--script=$(LDSCRIPT) \
|
-Wl,--script=$(LDSCRIPT) \
|
||||||
-Wl,--build-id=none
|
-Wl,--build-id=none
|
||||||
|
|
||||||
@ -64,7 +80,7 @@ ALL := all
|
|||||||
TARGET := $(PACKAGE).elf
|
TARGET := $(PACKAGE).elf
|
||||||
CLEAN := clean
|
CLEAN := clean
|
||||||
|
|
||||||
$(ALL): $(TARGET) $(PACKAGE).bin $(PACKAGE).ihex
|
$(ALL): $(TARGET) $(PACKAGE).bin $(PACKAGE).ihex $(PACKAGE).dfu
|
||||||
|
|
||||||
$(OBJECTS): | $(OBJ_DIR)
|
$(OBJECTS): | $(OBJ_DIR)
|
||||||
|
|
||||||
@ -76,7 +92,7 @@ $(PACKAGE).bin: $(TARGET)
|
|||||||
$(QUIET) echo " OBJCOPY $@"
|
$(QUIET) echo " OBJCOPY $@"
|
||||||
$(QUIET) $(OBJCOPY) -O binary $(TARGET) $@
|
$(QUIET) $(OBJCOPY) -O binary $(TARGET) $@
|
||||||
|
|
||||||
$(PACKAGE).dfu: $(TARGET)
|
$(PACKAGE).dfu: $(PACKAGE).bin
|
||||||
$(QUIET) echo " DFU $@"
|
$(QUIET) echo " DFU $@"
|
||||||
$(QUIET) $(COPY) $(PACKAGE).bin $@
|
$(QUIET) $(COPY) $(PACKAGE).bin $@
|
||||||
$(QUIET) dfu-suffix -v 1209 -p 70b1 -a $@
|
$(QUIET) dfu-suffix -v 1209 -p 70b1 -a $@
|
||||||
@ -106,7 +122,7 @@ $(OBJ_DIR)/%.o: %.S
|
|||||||
$(QUIET) echo " AS $< $(notdir $@)"
|
$(QUIET) echo " AS $< $(notdir $@)"
|
||||||
$(QUIET) $(CC) -x assembler-with-cpp -c $< $(CFLAGS) -o $@ -MMD
|
$(QUIET) $(CC) -x assembler-with-cpp -c $< $(CFLAGS) -o $@ -MMD
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean load
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(QUIET) echo " RM $(subst /,$(PATH_SEP),$(wildcard $(OBJ_DIR)/*.d))"
|
$(QUIET) echo " RM $(subst /,$(PATH_SEP),$(wildcard $(OBJ_DIR)/*.d))"
|
||||||
@ -116,4 +132,8 @@ clean:
|
|||||||
$(QUIET) echo " RM $(TARGET) $(PACKAGE).bin $(PACKAGE).symbol $(PACKAGE).ihex $(PACKAGE).dfu"
|
$(QUIET) echo " RM $(TARGET) $(PACKAGE).bin $(PACKAGE).symbol $(PACKAGE).ihex $(PACKAGE).dfu"
|
||||||
-$(QUIET) $(RM) $(TARGET) $(PACKAGE).bin $(PACKAGE).symbol $(PACKAGE).ihex $(PACKAGE).dfu
|
-$(QUIET) $(RM) $(TARGET) $(PACKAGE).bin $(PACKAGE).symbol $(PACKAGE).ihex $(PACKAGE).dfu
|
||||||
|
|
||||||
|
load: $(PACKAGE).dfu
|
||||||
|
$(QUIET) dfu-util -D $<
|
||||||
|
|
||||||
include $(wildcard $(OBJ_DIR)/*.d)
|
include $(wildcard $(OBJ_DIR)/*.d)
|
||||||
|
|
||||||
|
@ -3,8 +3,6 @@ ENTRY(_start)
|
|||||||
|
|
||||||
__DYNAMIC = 0;
|
__DYNAMIC = 0;
|
||||||
|
|
||||||
INCLUDE regions.ld
|
|
||||||
|
|
||||||
SECTIONS
|
SECTIONS
|
||||||
{
|
{
|
||||||
.text :
|
.text :
|
||||||
|
5
examples/riscv-blink/ld/regions_ram.ld
Normal file
5
examples/riscv-blink/ld/regions_ram.ld
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
MEMORY {
|
||||||
|
ram : ORIGIN = LOAD_RAM_ADDR, LENGTH = 0x00010000
|
||||||
|
}
|
||||||
|
REGION_ALIAS("rom", ram)
|
||||||
|
REGION_ALIAS("sram", ram)
|
@ -6,8 +6,14 @@
|
|||||||
|
|
||||||
_start:
|
_start:
|
||||||
j crt_init
|
j crt_init
|
||||||
|
#ifdef LOAD_RAM_ADDR
|
||||||
|
.word 0x17ab0f23
|
||||||
|
.word LOAD_RAM_ADDR
|
||||||
|
#endif
|
||||||
|
#ifdef LOAD_BOOT_CONFIG
|
||||||
.word 0xb469075a
|
.word 0xb469075a
|
||||||
.word 0x00000020
|
.word LOAD_BOOT_CONFIG
|
||||||
|
#endif
|
||||||
|
|
||||||
.section .text
|
.section .text
|
||||||
.global trap_entry
|
.global trap_entry
|
||||||
|
25
sw/Makefile
25
sw/Makefile
@ -37,7 +37,19 @@ ADD_LFLAGS :=
|
|||||||
PACKAGE := foboot
|
PACKAGE := foboot
|
||||||
endif
|
endif
|
||||||
|
|
||||||
LDSCRIPTS := $(LDSCRIPT) $(LD_DIR)/output_format.ld $(LD_DIR)/regions.ld
|
ifdef LOAD_RAM_ADDR
|
||||||
|
LDREGIONS := $(LD_DIR)/regions_ram.ld
|
||||||
|
ADD_CFLAGS += -DLOAD_RAM_ADDR=$(LOAD_RAM_ADDR)
|
||||||
|
ADD_LFLAGS += -Wl,--defsym=LOAD_RAM_ADDR=$(LOAD_RAM_ADDR)
|
||||||
|
else
|
||||||
|
LDREGIONS := $(LD_DIR)/regions.ld
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifdef LOAD_BOOT_CONFIG
|
||||||
|
ADD_CFLAGS += -DLOAD_BOOT_CONFIG=$(LOAD_BOOT_CONFIG)
|
||||||
|
endif
|
||||||
|
|
||||||
|
LDSCRIPTS := $(LDSCRIPT) $(LDREGIONS) $(LD_DIR)/output_format.ld
|
||||||
SRC_DIR := $(BASE_DIR)/src
|
SRC_DIR := $(BASE_DIR)/src
|
||||||
THIRD_PARTY := $(BASE_DIR)/third_party
|
THIRD_PARTY := $(BASE_DIR)/third_party
|
||||||
DBG_CFLAGS := -ggdb3 -DDEBUG -Wall
|
DBG_CFLAGS := -ggdb3 -DDEBUG -Wall
|
||||||
@ -56,6 +68,7 @@ LFLAGS := $(CFLAGS) $(ADD_LFLAGS) -L$(LD_DIR) \
|
|||||||
-nostdlib \
|
-nostdlib \
|
||||||
-Wl,--gc-sections \
|
-Wl,--gc-sections \
|
||||||
-Wl,--no-warn-mismatch \
|
-Wl,--no-warn-mismatch \
|
||||||
|
-Wl,--script=$(LDREGIONS) \
|
||||||
-Wl,--script=$(LDSCRIPT) \
|
-Wl,--script=$(LDSCRIPT) \
|
||||||
-Wl,--build-id=none
|
-Wl,--build-id=none
|
||||||
|
|
||||||
@ -76,7 +89,7 @@ ALL := all
|
|||||||
TARGET := $(PACKAGE).elf
|
TARGET := $(PACKAGE).elf
|
||||||
CLEAN := clean
|
CLEAN := clean
|
||||||
|
|
||||||
$(ALL): $(TARGET) $(PACKAGE).bin $(PACKAGE).ihex
|
$(ALL): $(TARGET) $(PACKAGE).bin $(PACKAGE).ihex $(PACKAGE).dfu
|
||||||
|
|
||||||
$(OBJECTS): | $(OBJ_DIR)
|
$(OBJECTS): | $(OBJ_DIR)
|
||||||
|
|
||||||
@ -88,7 +101,7 @@ $(PACKAGE).bin: $(TARGET)
|
|||||||
$(QUIET) echo " OBJCOPY $@"
|
$(QUIET) echo " OBJCOPY $@"
|
||||||
$(QUIET) $(OBJCOPY) -O binary $(TARGET) $@
|
$(QUIET) $(OBJCOPY) -O binary $(TARGET) $@
|
||||||
|
|
||||||
$(PACKAGE).dfu: $(TARGET)
|
$(PACKAGE).dfu: $(PACKAGE).bin
|
||||||
$(QUIET) echo " DFU $@"
|
$(QUIET) echo " DFU $@"
|
||||||
$(QUIET) $(COPY) $(PACKAGE).bin $@
|
$(QUIET) $(COPY) $(PACKAGE).bin $@
|
||||||
$(QUIET) dfu-suffix -v 1209 -p 70b1 -a $@
|
$(QUIET) dfu-suffix -v 1209 -p 70b1 -a $@
|
||||||
@ -118,7 +131,7 @@ $(OBJ_DIR)/%.o: %.S
|
|||||||
$(QUIET) echo " AS $< $(notdir $@)"
|
$(QUIET) echo " AS $< $(notdir $@)"
|
||||||
$(QUIET) $(CC) -x assembler-with-cpp -c $< $(CFLAGS) -o $@ -MMD
|
$(QUIET) $(CC) -x assembler-with-cpp -c $< $(CFLAGS) -o $@ -MMD
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean load
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(QUIET) echo " RM $(subst /,$(PATH_SEP),$(wildcard $(OBJ_DIR)/*.d))"
|
$(QUIET) echo " RM $(subst /,$(PATH_SEP),$(wildcard $(OBJ_DIR)/*.d))"
|
||||||
@ -128,4 +141,8 @@ clean:
|
|||||||
$(QUIET) echo " RM $(TARGET) $(PACKAGE).bin $(PACKAGE).symbol $(PACKAGE).ihex $(PACKAGE).dfu"
|
$(QUIET) echo " RM $(TARGET) $(PACKAGE).bin $(PACKAGE).symbol $(PACKAGE).ihex $(PACKAGE).dfu"
|
||||||
-$(QUIET) $(RM) $(TARGET) $(PACKAGE).bin $(PACKAGE).symbol $(PACKAGE).ihex $(PACKAGE).dfu
|
-$(QUIET) $(RM) $(TARGET) $(PACKAGE).bin $(PACKAGE).symbol $(PACKAGE).ihex $(PACKAGE).dfu
|
||||||
|
|
||||||
|
load: $(PACKAGE).dfu
|
||||||
|
$(QUIET) dfu-util -D $<
|
||||||
|
|
||||||
include $(wildcard $(OBJ_DIR)/*.d)
|
include $(wildcard $(OBJ_DIR)/*.d)
|
||||||
|
|
||||||
|
@ -3,8 +3,6 @@ ENTRY(_start)
|
|||||||
|
|
||||||
__DYNAMIC = 0;
|
__DYNAMIC = 0;
|
||||||
|
|
||||||
INCLUDE regions.ld
|
|
||||||
|
|
||||||
SECTIONS
|
SECTIONS
|
||||||
{
|
{
|
||||||
.text :
|
.text :
|
||||||
|
5
sw/ld/regions_ram.ld
Normal file
5
sw/ld/regions_ram.ld
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
MEMORY {
|
||||||
|
ram : ORIGIN = LOAD_RAM_ADDR, LENGTH = 0x00010000
|
||||||
|
}
|
||||||
|
REGION_ALIAS("rom", ram)
|
||||||
|
REGION_ALIAS("sram", ram)
|
10
sw/third_party/libbase/crt0-vexriscv.S
vendored
10
sw/third_party/libbase/crt0-vexriscv.S
vendored
@ -7,10 +7,20 @@
|
|||||||
_start:
|
_start:
|
||||||
j crt_init
|
j crt_init
|
||||||
nop
|
nop
|
||||||
|
#ifdef LOAD_RAM_ADDR
|
||||||
|
.word 0x17ab0f23
|
||||||
|
.word LOAD_RAM_ADDR
|
||||||
|
#else
|
||||||
nop
|
nop
|
||||||
nop
|
nop
|
||||||
|
#endif
|
||||||
|
#ifdef LOAD_BOOT_CONFIG
|
||||||
|
.word 0xb469075a
|
||||||
|
.word LOAD_BOOT_CONFIG
|
||||||
|
#else
|
||||||
nop
|
nop
|
||||||
nop
|
nop
|
||||||
|
#endif
|
||||||
nop
|
nop
|
||||||
nop
|
nop
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user