Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move boot_aplx.s stack to bottom half of DTCM #139

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 2 additions & 18 deletions make/spinnaker_tools.mk
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ DEBUG := 1
# Set to 1 if making a library (advanced!)
LIB := 0

# Set to 1 if building scamp (advanced!)
SCAMP := 0

# Prefix for GNU tool binaries
GP := arm-none-eabi

Expand Down Expand Up @@ -61,7 +58,6 @@ SPINN_LIB_DIR = $(SPINN_DIRS)/lib
SPINN_INC_DIR = $(SPINN_DIRS)/include
SPINN_TOOLS_DIR = $(SPINN_DIRS)/tools
SPINN_MAKE_LIB_DIR = $(SPINN_DIRS)/make
SPINN_SCAMP_DIR = $(SPINN_DIRS)/scamp

# ------------------------------------------------------------------------------
# Tools
Expand All @@ -79,18 +75,11 @@ ifeq ($(GNU),1)
OTIME := -Ofast
ALL_WARNINGS := -Wall -Wextra

# scamp needs the stacks in a different address of DTCM
ifeq ($(SCAMP), 1)
LD_LNK := $(SPINN_SCAMP_DIR)/scamp-3.lnk
else
LD_LNK := $(SPINN_TOOLS_DIR)/sark.lnk
endif

ifeq ($(LIB), 1)
CFLAGS += -fdata-sections -ffunction-sections
LD := $(GP)-ld -i
else
LD := $(GP)-gcc -T$(LD_LNK) -Wl,-e,cpu_reset -Wl,-static -ffreestanding -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,--use-blx -nostartfiles -static
LD := $(GP)-gcc -T$(SPINN_TOOLS_DIR)/sark.lnk -Wl,-e,cpu_reset -Wl,-static -ffreestanding -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,--use-blx -nostartfiles -static
LFLAGS += -L $(SPINN_LIB_DIR)
endif

Expand All @@ -112,16 +101,11 @@ else
OTIME := -Otime
ALL_WARNINGS :=

# suppress linker warning about empty RW sections when building scamp
ifeq ($(SCAMP), 1)
LD_FLAG := --diag_suppress L6329W
endif

ifeq ($(LIB), 1)
CFLAGS += --split_sections
LD := armlink --partial
else
LD = armlink --scatter=$(SPINN_TOOLS_DIR)/sark.sct $(LD_FLAG) --remove --entry cpu_reset
LD = armlink --scatter=$(SPINN_TOOLS_DIR)/sark.sct $(LD_FLAGS) --remove --entry cpu_reset
endif

AR := armar -rsc
Expand Down
30 changes: 21 additions & 9 deletions scamp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

APP := scamp-3
override THUMB := 1
override SCAMP := 1
override LD_FLAGS := --diag_suppress L6329W
include ../make/spinnaker_tools.mk

SCAMP_OBJS = spinn_phy.o spinn_srom.o spinn_net.o scamp-app.o \
Expand All @@ -31,8 +31,8 @@ else
endif

# Create the boot file (default)
$(APP).boot: $(BUILD_DIR)boot_aplx.bin $(BUILD_DIR)$(APP)_boot.tab $(BUILD_DIR)$(APP).sv $(BUILD_DIR)sark_pad.aplx $(BUILD_DIR)$(APP).bin
cat $(BUILD_DIR)boot_aplx.bin $(BUILD_DIR)$(APP)_boot.tab $(BUILD_DIR)boot_aplx.bin $(BUILD_DIR)$(APP).sv $(BUILD_DIR)sark_pad.aplx $(BUILD_DIR)$(APP).bin > $(APP).boot
$(APP).boot: $(BUILD_DIR)scamp_boot_aplx.bin $(BUILD_DIR)boot_aplx.bin $(BUILD_DIR)$(APP)_boot.tab $(BUILD_DIR)$(APP).sv $(BUILD_DIR)sark_pad.aplx $(BUILD_DIR)$(APP).bin
cat $(BUILD_DIR)scamp_boot_aplx.bin $(BUILD_DIR)$(APP)_boot.tab $(BUILD_DIR)boot_aplx.bin $(BUILD_DIR)$(APP).sv $(BUILD_DIR)sark_pad.aplx $(BUILD_DIR)$(APP).bin > $(APP).boot
$(LS) $(APP).boot

# Create the aplx file (optional)
Expand All @@ -48,11 +48,14 @@ install: $(APP).boot
install-aplx: $(APP).aplx
$(MV) $(APP).aplx ../tools/boot/scamp.aplx

# Build the SCAMP elf file - uses scatter file on ARM
$(BUILD_DIR)$(APP).elf: $(OBJS) $(SARK_LIB) $(BUILD_DIR)$(APP)_build.o $(APP).sct
# Build the SCAMP elf file - uses scamp-specific linker options
ifeq ($(GNU),1)
$(LD) $(OBJS) $(BUILD_DIR)$(APP)_build.o $(SARKLIB) -o $@
$(BUILD_DIR)$(APP).elf: $(OBJS) $(SARK_LIB) $(BUILD_DIR)$(APP)_build.o $(APP).lnk
$(GP)-gcc -T$(APP).lnk -Wl,-e,cpu_reset -Wl,-static -ffreestanding -fdata-sections \
-ffunction-sections -Wl,--gc-sections -Wl,--use-blx -nostartfiles -static \
$(OBJS) $(BUILD_DIR)$(APP)_build.o $(SARKLIB) -o $@
else
$(BUILD_DIR)$(APP).elf: $(OBJS) $(SARK_LIB) $(BUILD_DIR)$(APP)_build.o $(APP).sct
armlink --scatter=$(APP).sct --remove --entry cpu_reset $(OBJS) $(SARKLIB) \
$(BUILD_DIR)$(APP)_build.o --output $@
endif
Expand Down Expand Up @@ -88,16 +91,25 @@ $(BUILD_DIR)%.gas: %.s
$(MKDIR) $(BUILD_DIR)
$(SPINN_TOOLS_DIR)/arm2gas $< > $@

$(BUILD_DIR)boot_aplx.elf: $(BUILD_DIR)boot_aplx.gas $(BUILD_DIR)spinnaker.gas $(BUILD_DIR)sark.gas
$(BUILD_DIR)boot_aplx.elf: $(BUILD_DIR)boot_aplx.gas $(BUILD_DIR)spinnaker.gas $(BUILD_DIR)sark.gas $(APP).lnk
$(MKDIR) $(BUILD_DIR)
$(AS) -I $(BUILD_DIR) -o $(BUILD_DIR)boot_aplx.o $<
$(GP)-ld -Tboot.lnk -static --no-gc-sections --use-blx -nostartfiles $(BUILD_DIR)boot_aplx.o -o $@
$(GP)-ld -T$(APP).lnk -static --no-gc-sections --use-blx -nostartfiles $(BUILD_DIR)boot_aplx.o -o $@

$(BUILD_DIR)scamp_boot_aplx.elf: $(BUILD_DIR)boot_aplx.gas $(BUILD_DIR)spinnaker.gas $(BUILD_DIR)sark.gas $(APP).lnk
$(MKDIR) $(BUILD_DIR)
$(AS) --defsym SCAMP_BOOT_APLX=1 -I $(BUILD_DIR) -o $(BUILD_DIR)scamp_boot_aplx.o $<
$(GP)-ld -T$(APP).lnk -static --no-gc-sections --use-blx -nostartfiles $(BUILD_DIR)scamp_boot_aplx.o -o $@
else
$(BUILD_DIR)boot_aplx.elf: boot_aplx.s $(BUILD_DIR)spinnaker.s $(BUILD_DIR)sark.s
$(MKDIR) $(BUILD_DIR)
$(AS) -I $(BUILD_DIR) boot_aplx.s -o $(BUILD_DIR)boot_aplx.o
armlink --ro_base 0 -o $@ $(BUILD_DIR)boot_aplx.o

$(BUILD_DIR)scamp_boot_aplx.elf: boot_aplx.s $(BUILD_DIR)spinnaker.s $(BUILD_DIR)sark.s
$(MKDIR) $(BUILD_DIR)
$(AS) --predefine "SCAMP_BOOT_APLX SETA 1" -I $(BUILD_DIR) boot_aplx.s -o $(BUILD_DIR)scamp_boot_aplx.o
armlink --ro_base 0 -o $@ $(BUILD_DIR)scamp_boot_aplx.o
endif

# Convert h file to s
Expand All @@ -121,7 +133,7 @@ tar:
scamp/scamp-boot.c scamp/scamp-isr.c scamp/scamp-del.c scamp/spinn_phy.h \
scamp/scamp.h scamp/spinn_net.h scamp/spinn_regs.h \
scamp/boot_aplx.s scamp/$(APP).c scamp/$(APP).sct scamp/sark.c \
scamp/Makefile scamp/mkpad scamp/mksv scamp/$(APP).lnk scamp/boot.lnk
scamp/Makefile scamp/mkpad scamp/mksv scamp/$(APP).lnk

clean:
$(RM) -r $(BUILD_DIR)* $(APP).boot
Expand Down
49 changes: 0 additions & 49 deletions scamp/boot.lnk

This file was deleted.

16 changes: 14 additions & 2 deletions scamp/boot_aplx.s
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@

entry

aplx_start mov sp, #DTCM_TOP ; Set up stack
aplx_start ldr sp, boot_stack_top ; Set up stack
adr r0, aplx_args ; APLX block in DTCM
ldm r0, {r0-r1, r4-r5} ; Get address & args
blx proc_aplx ; Go to loader

; When booting via bootROM, APLX table ends up in DTCM 128 bytes above
; start of image

aplx_args dcd DTCM_BASE + 0x8080 ; Address of APLX table
aplx_args dcd DTCM_BASE + (DTCM_SIZE / 2) + 128 ; Address of APLX table
dcd 0 ; Arg passed in r0 (app_id)

aplx_svc msr cpsr_c, #IMASK_ALL+MODE_SVC
Expand Down Expand Up @@ -113,6 +113,18 @@ aplx_exec ldr r0, [sp, #0] ; Get arg to r0
blx r1 ; Exec absolute
b aplx_loader ; r1 = address

; NOTE: this was added here to avoid disrupting
; hard-coded addresses elsewhere (e.g., mkaplx)
if :def: SCAMP_BOOT_APLX
; locate stack at top of bottom half of DTCM for SCAMP boot
boot_stack_top dcd DTCM_BASE + (DTCM_SIZE / 2)
else
; locate stack at top of DTCM for application boot
boot_stack_top dcd DTCM_TOP
endif

; make sure that the size of this code block is
; 128 bytes to keep the scamp.boot build correct
align 128
code32
aplx_end
Expand Down
1 change: 1 addition & 0 deletions scamp/scamp-3.lnk
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ SECTIONS

RO_DATA :
{
* (boot_aplx);
* (_alib_reset);
* (alib_*);
* (.text*);
Expand Down
4 changes: 2 additions & 2 deletions tools/mkaplx
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ if ($text)
if ($boot)
{
printf "\t\tdcd\tAPLX_RCOPY, 0x%08x, 0x%08x, 0x%08x\n", # boot_aplx
0x7f00, -128 & 0xffffffff, 128;
0x7f00, 128, 128;
printf "\t\tdcd\tAPLX_RCOPY, 0x%08x, 0x%08x, 0x%08x\n", # def_app
0x7000, 512-128-16, 3584;
printf "\t\tdcd\tAPLX_EXEC, 0x%08x, 0x%08x, 0x%08x\n", # dis. int.
Expand Down Expand Up @@ -212,7 +212,7 @@ else

if ($boot)
{
print pack "V4", $APLX_RCOPY, 0x7f00, -128, 128;
print pack "V4", $APLX_RCOPY, 0x7f00, 128, 128;
print pack "V4", $APLX_RCOPY, 0x7000, 512-128-16, 3584;
print pack "V4", $APLX_EXEC, 0x7f18, 0, 0;
print pack "V4", $APLX_RCOPY, 0xf5007f00, 384-128-48, 128;
Expand Down