This repository has been archived by the owner on Jul 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
138 lines (110 loc) · 3.93 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# Copyright(C) 2020 Hex Five Security, Inc. - All Rights Reserved
#############################################################
# Platform definitions
#############################################################
BOARD ?= PFSC-LIM
ifeq ($(BOARD), PFSC-LIM)
ARCH := rv64
RISCV_ARCH := $(ARCH)imac
RISCV_ABI := lp64
MEM := lim
else ifeq ($(BOARD), PFSC-ENVM)
ARCH := rv64
RISCV_ARCH := $(ARCH)imac
RISCV_ABI := lp64
MEM := envm
else
$(error Unsupported board $(BOARD))
endif
#############################################################
# Arguments/variables available to all submakes
#############################################################
export BOARD
export RISCV_ARCH
export RISCV_ABI
export MEM
#############################################################
# Toolchain definitions
#############################################################
ifndef RISCV
$(error RISCV not set)
endif
export CROSS_COMPILE := $(abspath $(RISCV))/bin/riscv64-unknown-elf-
export CC := $(CROSS_COMPILE)gcc
export OBJDUMP := $(CROSS_COMPILE)objdump
export OBJCOPY := $(CROSS_COMPILE)objcopy
export GDB := $(CROSS_COMPILE)gdb
export AR := $(CROSS_COMPILE)ar
export LD := $(CROSS_COMPILE)ld
export STRIP := $(CROSS_COMPILE)strip
export SIZE := $(CROSS_COMPILE)size
#############################################################
# Rules for building the firmware image
#############################################################
.PHONY: all
all: clean
$(MAKE) -C apps/hart0
# $(MAKE) -C apps/hart1
# $(MAKE) -C apps/hart2
# $(MAKE) -C apps/hart3
# $(MAKE) -C apps/hart4
@srec_cat -o firmware.hex -I \
apps/hart0/hart0.hex -I 2> /dev/null
# apps/hart1/hart1.hex -I \
# apps/hart2/hart2.hex -I \
# apps/hart3/hart3.hex -I \
# apps/hart4/hart4.hex -I \
.PHONY: clean
clean:
$(MAKE) -C apps/hart0 clean
# $(MAKE) -C apps/hart1 clean
# $(MAKE) -C apps/hart2 clean
# $(MAKE) -C apps/hart3 clean
# $(MAKE) -C apps/hart4 clean
rm -f firmware.*
#############################################################
# Load to LIM (debug - boot mode 0)
#############################################################
ifeq ($(BOARD), PFSC-LIM)
ifndef OPENOCD
$(error OPENOCD not set)
endif
OPENOCD_BIN := $(abspath $(OPENOCD))/bin/openocd
OPENOCDARGS += --command 'set DEVICE MPFS'
OPENOCDARGS += --file '$(abspath $(OPENOCD))/share/openocd/scripts/board/microsemi-riscv.cfg'
GDB_PORT ?= 3333
GDB_LOAD_ARGS ?= -batch
GDB_LOAD_CMDS += -ex 'target extended-remote localhost:$(GDB_PORT)'
GDB_LOAD_CMDS += -ex 'monitor reset init'
GDB_LOAD_CMDS += -ex 'load'
GDB_LOAD_CMDS += -ex 'thread apply all set $$pc=0x08000000'
GDB_LOAD_CMDS += -ex 'monitor resume'
GDB_LOAD_CMDS += -ex 'monitor shutdown'
GDB_LOAD_CMDS += -ex 'quit'
.PHONY: load
load:
$(OPENOCD_BIN) $(OPENOCDARGS) & \
$(GDB) firmware.hex $(GDB_LOAD_ARGS) $(GDB_LOAD_CMDS)
endif
#############################################################
# Load to eNVM (production - boot mode 1)
#############################################################
ifeq ($(BOARD), PFSC-ENVM)
ifndef FPGENPROG
$(error FPGENPROG not set)
endif
ifndef SC_INSTALL_DIR
$(error SC_INSTALL_DIR not set)
endif
MPFS_BOOT_MODE_PROG := $(abspath $(SC_INSTALL_DIR))/extras/mpfs/mpfsBootmodeProgrammer.jar
.PHONY: load
load:
# Convert firmware.hex to firmware.elf as required by mpfsBootmodeProgrammer.jar
$(OBJCOPY) -S -I ihex -O binary firmware.hex firmware.bin
$(LD) -b binary -r -o firmware.tmp firmware.bin
$(OBJCOPY) --rename-section .data=.text --set-section-flags .data=alloc,code,load firmware.tmp
$(LD) firmware.tmp -T apps/hart0/bsp/hex2elf.ld -o firmware.elf
$(STRIP) -s firmware.elf
java -jar $(MPFS_BOOT_MODE_PROG) --bootmode 1 --die MPFS250T_ES --package FCVG484 firmware.elf
rm -rf bootmode1 firmware.tmp firmware.bin
endif