Merge branch 'master' into auto-boot

This commit is contained in:
Sven Willner 2020-08-05 15:43:44 +02:00 committed by GitHub
commit 348b658ae2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 78 additions and 15 deletions

View File

@ -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 |
@ -51,6 +53,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 |

View File

@ -26,19 +26,33 @@ 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
ifdef AUTOBOOT_TIMEOUT ifdef AUTOBOOT_TIMEOUT
ADD_CFLAGS += -DAUTOBOOT_TIMEOUT=$(AUTOBOOT_TIMEOUT) ADD_CFLAGS += -DAUTOBOOT_TIMEOUT=$(AUTOBOOT_TIMEOUT)
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 := -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 \
@ -46,8 +60,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
@ -68,7 +84,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)
@ -80,7 +96,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 $@
@ -110,7 +126,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))"
@ -120,4 +136,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)

View File

@ -3,8 +3,6 @@ ENTRY(_start)
__DYNAMIC = 0; __DYNAMIC = 0;
INCLUDE regions.ld
SECTIONS SECTIONS
{ {
.text : .text :

View File

@ -0,0 +1,5 @@
MEMORY {
ram : ORIGIN = LOAD_RAM_ADDR, LENGTH = 0x00010000
}
REGION_ALIAS("rom", ram)
REGION_ALIAS("sram", ram)

View File

@ -10,8 +10,14 @@ _start:
.word 0x4a6de3ac .word 0x4a6de3ac
.word AUTOBOOT_TIMEOUT .word AUTOBOOT_TIMEOUT
#endif #endif
#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

View File

@ -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)

View File

@ -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
View File

@ -0,0 +1,5 @@
MEMORY {
ram : ORIGIN = LOAD_RAM_ADDR, LENGTH = 0x00010000
}
REGION_ALIAS("rom", ram)
REGION_ALIAS("sram", ram)

View File

@ -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