-
Notifications
You must be signed in to change notification settings - Fork 7
/
flasher.mk
252 lines (218 loc) · 10.5 KB
/
flasher.mk
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# RTL8710 Flasher v0.0.alfa
# pvvx 21.09.2016
-include paths.mk
#---------------------------
#FLASHER = stlink-v2-1
#FLASHER = stlink-v2
FLASHER ?= Jlink
JLINK_PATH ?= D:/MCU/SEGGER/JLink_V610a/
#---------------------------
# Default
#---------------------------
# TARGET dirs
TARGET ?= build
OBJ_DIR ?= build/obj
BIN_DIR ?= build/bin
ELFFILE ?= $(OBJ_DIR)/$(TARGET).axf
#---------------------------
# Compilation tools
CROSS_COMPILE ?= $(GCC_PATH)arm-none-eabi-
AR ?= $(CROSS_COMPILE)ar
CC ?= $(CROSS_COMPILE)gcc
AS ?= $(CROSS_COMPILE)as
NM ?= $(CROSS_COMPILE)nm
LD ?= $(CROSS_COMPILE)gcc
GDB ?= $(CROSS_COMPILE)gdb
SIZE ?= $(CROSS_COMPILE)size
OBJCOPY ?= $(CROSS_COMPILE)objcopy
OBJDUMP ?= $(CROSS_COMPILE)objdump
# Make bunary tools
TOOLS_PATH ?= component/soc/realtek/8195a/misc/iar_utility/common/tools/
ifneq ($(shell uname), Linux)
EXE = .exe
endif
PICK = $(TOOLS_PATH)pick$(EXE)
PADDING = $(TOOLS_PATH)padding$(EXE)
CHCKSUM = $(TOOLS_PATH)checksum$(EXE)
# openocd tools
OPENOCD = $(OPENOCD_PATH)openocd
JLINK_GDB ?= JLinkGDBServer.exe
JLINK_EXE ?= JLink.exe
ifeq ($(FLASHER), Jlink)
# Jlink FLASHER_SPEED ..4000 kHz
FLASHER_SPEED = 3500
else
ifeq ($(FLASHER),stlink-v2)
# stlink-v2 FLASHER_SPEED ..1800 kHz
FLASHER_SPEED = 1800
else
# over FLASHER_SPEED ..500 kHz ?
FLASHER_SPEED = 500
endif
endif
# COMPILED_BOOT if defined -> extract image1, =1 boot head in elf, =2 boot head ?
#COMPILED_BOOT=1
# PADDINGSIZE defined -> image2 OTA
PADDINGSIZE =44k
NMAPFILE = $(OBJ_DIR)/$(TARGET).nmap
#FLASHER_PATH ?= flasher/
RAM1_IMAGE ?= $(BIN_DIR)/ram_1.bin
RAM1P_IMAGE ?= $(BIN_DIR)/ram_1.p.bin
RAM2_IMAGE = $(BIN_DIR)/ram_2.bin
RAM2P_IMAGE = $(BIN_DIR)/ram_2.p.bin
RAM2NS_IMAGE = $(BIN_DIR)/ram_2.ns.bin
RAM3_IMAGE = $(BIN_DIR)/ram_3.bin
RAM3P_IMAGE = $(BIN_DIR)/ram_3.p.bin
FLASH_IMAGE = $(BIN_DIR)/ram_all.bin
OTA_IMAGE = $(BIN_DIR)/ota.bin
#all: FLASH_IMAGE = $(BIN_DIR)/ram_all.bin
#all: OTA_IMAGE = $(BIN_DIR)/ota.bin
mp: FLASH_IMAGE = $(BIN_DIR)/ram_all_mp.bin
mp: OTA_IMAGE = $(BIN_DIR)/ota_mp.bin
TST_IMAGE = $(BIN_DIR)/ram_2.bin
LD_ADDRESS = 0x1000B000
ST_ADDRESS = 0x10006068
.PHONY: copybin1 genbin1 genbin23 flashburn reset test readfullflash
.NOTPARALLEL: all mp copybin1 genbin1 genbin23 flashburn reset test readfullflash _endgenbin
all: $(ELFFILE) $(OTA_IMAGE) $(FLASH_IMAGE) _endgenbin
mp: $(ELFFILE) $(OTA_IMAGE) $(FLASH_IMAGE) _endgenbin
copybin1:
cp $(patsubst sdk/%,$(SDK_PATH)%,$(BOOTS))/ram_1.r.bin $(BIN_DIR)/ram_1.r.bin
cp $(patsubst sdk/%,$(SDK_PATH)%,$(BOOTS))/ram_1.p.bin $(BIN_DIR)/ram_1.p.bin
# @chmod 777 $(OBJ_DIR)/ram_1.r.bin
@$(OBJCOPY) --rename-section .data=.loader.data,contents,alloc,load,readonly,data -I binary -O elf32-littlearm -B arm $(BIN_DIR)/ram_1.r.bin $(OBJ_DIR)/ram_1.r.o
genbin1: $(ELFFILE) $(RAM1P_IMAGE)
genbin23: $(ELFFILE) $(OTA_IMAGE) $(FLASH_IMAGE) _endgenbin
_endgenbin:
@echo "-----------------------------------------------------------"
@echo "Image ($(OTA_IMAGE)) size $(shell printf '%d\n' $$(( $$(stat --printf="%s" $(OTA_IMAGE)) )) ) bytes"
@echo "Image ($(FLASH_IMAGE)) size $(shell printf '%d\n' $$(( $$(stat --printf="%s" $(FLASH_IMAGE)) )) ) bytes"
@echo "==========================================================="
flashburn:
@$(OPENOCD) -f interface/$(FLASHER).cfg -c "adapter_khz $(FLASHER_SPEED)" -f $(FLASHER_PATH)rtl8710.ocd -c "init" -c "reset halt" -c "rtl8710_flash_auto_erase 1" -c "rtl8710_flash_auto_verify 1" -c "rtl8710_flash_write $(FLASH_IMAGE) 0" -c "rtl8710_reboot" -c "reset run" -c shutdown
# @$(JLINK_PATH)$(JLINK_GDB)
reset:
@$(JLINK_PATH)$(JLINK_EXE) -Device CORTEX-M3 -If SWD -Speed $(FLASHER_SPEED) flasher/RTLreset.JLinkScript
# @$(OPENOCD) -f interface/$(FLASHER).cfg -c "adapter_khz $(FLASHER_SPEED)" -f $(FLASHER_PATH)rtl8710.ocd -c "init" -c "reset halt" -c "rtl8710_reboot" -c shutdown
runram:
@start $(JLINK_PATH)$(JLINK_GDB) -device Cortex-M3 -if SWD -ir -endian little -speed $(FLASHER_SPEED)
@$(GDB) -x flasher/gdb_run_ram.jlink
@taskkill.exe -F -IM $(JLINK_GDB)
test:
@$(OPENOCD) -f interface/$(FLASHER).cfg -c "adapter_khz $(FLASHER_SPEED)" -f $(FLASHER_PATH)rtl8710.ocd -f $(FLASHER_PATH)cortex.ocd -c "init" -c "reset halt" -c "load_image $(TST_IMAGE) $(LD_ADDRESS) bin" -c "cortex_bootstrap $(ST_ADDRESS)" -c "shutdown"
readfullflash:
@rm -f $(BIN_DIR)/fullflash.bin
@start $(JLINK_PATH)$(JLINK_GDB) -device Cortex-M3 -if SWD -ir -endian little -speed $(FLASHER_SPEED)
@$(GDB) -x flasher/gdb_rdflash.jlink
@taskkill.exe -F -IM $(JLINK_GDB)
# @$(OPENOCD) -f interface/$(FLASHER).cfg -c "adapter_khz $(FLASHER_SPEED)" -f $(FLASHER_PATH)rtl8710.ocd -f $(FLASHER_PATH)cortex.ocd -c "init" -c "reset halt" -c "rtl8710_flash_read_id" -c "rtl8710_flash_read $(BIN_DIR)/fullflash.bin 0 1048576" -c "reset run" -c "shutdown"
if [ -s $(BIN_DIR)/fullflash.bin ]; then echo FullFlash = $(BIN_DIR)/fullflash.bin; fi
$(NMAPFILE): $(ELFFILE)
@echo "==========================================================="
@echo "Build names map file"
@echo $@
@$(NM) $< | sort > $@
# @echo "==========================================================="
$(FLASH_IMAGE): $(RAM1P_IMAGE) $(RAM2P_IMAGE) $(RAM3_IMAGE)
@echo "==========================================================="
@echo "Make Flash image ($(FLASH_IMAGE))"
# @echo "==========================================================="
@mkdir -p $(BIN_DIR)
@rm -f $(FLASH_IMAGE)
@if [ -s $(RAM3_IMAGE) ]; then $(PICK) 0x$(RAM3_START_ADDR) 0x$(RAM3_END_ADDR) $(RAM3_IMAGE) $(RAM3P_IMAGE) body+reset_offset; fi
@cat $(RAM1P_IMAGE) > $(FLASH_IMAGE)
# @chmod 777 $(FLASH_IMAGE)
ifdef PADDINGSIZE
@$(PADDING) $(PADDINGSIZE) 0xFF $(FLASH_IMAGE)
endif
@cat $(RAM2P_IMAGE) >> $(FLASH_IMAGE)
@if [ -s $(RAM3_IMAGE) ]; then cat $(RAM3P_IMAGE) >> $(FLASH_IMAGE); fi
# @echo "Image ($(FLASH_IMAGE)) size $(shell printf '%d\n' $$(( $$(stat --printf="%s" $(FLASH_IMAGE)) )) ) bytes"
# @echo "==========================================================="
# @rm $(BIN_DIR)/ram_*.p.bin
$(OTA_IMAGE): $(RAM2NS_IMAGE) $(RAM3_IMAGE)
@echo "==========================================================="
@echo "Make OTA image ($(OTA_IMAGE))"
@rm -f $(OTA_IMAGE)
@if [ -s $(RAM3_IMAGE) ]; then $(PICK) 0x$(RAM3_START_ADDR) 0x$(RAM3_END_ADDR) $(RAM3_IMAGE) $(RAM3P_IMAGE) body+reset_offset; fi
@cat $(RAM2NS_IMAGE) > $(OTA_IMAGE)
@if [ -s $(RAM3_IMAGE) ]; then cat $(RAM3P_IMAGE) >> $(OTA_IMAGE); fi
# @chmod 777 $(OTA_IMAGE)
@$(CHCKSUM) $(OTA_IMAGE) || true
# @echo "==========================================================="
$(RAM1P_IMAGE): $(ELFFILE) $(NMAPFILE)
@echo "==========================================================="
@echo "Create image1p ($(RAM1P_IMAGE))"
# @echo "===========================================================" .bootloader
ifdef COMPILED_BOOT
@mkdir -p $(BIN_DIR)
@rm -f $(RAM1_IMAGE) $(RAM1P_IMAGE)
ifeq ($(COMPILED_BOOT),1)
@$(eval RAM1_START_ADDR := $(shell grep _binary_build_bin_ram_1_r_bin_start $(NMAPFILE) | awk '{print $$1}'))
@$(eval RAM1_END_ADDR := $(shell grep _binary_build_bin_ram_1_r_bin_end $(NMAPFILE) | awk '{print $$1}'))
else
@$(eval RAM1_START_ADDR := $(shell grep __ram_image1_text_start__ $(NMAPFILE) | awk '{print $$1}'))
@$(eval RAM1_END_ADDR := $(shell grep __ram_image1_text_end__ $(NMAPFILE) | awk '{print $$1}'))
endif
$(if $(RAM1_START_ADDR),,$(error "Not found __ram_image1_text_start__!"))
$(if $(RAM1_END_ADDR),,$(error "Not found __ram_image1_text_end__!"))
ifeq ($(RAM1_START_ADDR),$(RAM1_END_ADDR))
ifneq ($(COMPILED_BOOT),1)
$(OBJCOPY) -j .ram.start.table -j .ram_image1.text -Obinary $(ELFFILE) $(RAM1_IMAGE)
$(PICK) 0x$(RAM1_START_ADDR) 0x$(RAM1_END_ADDR) $(RAM1_IMAGE) $(RAM1P_IMAGE) body+reset_offset
else
$(OBJCOPY) --change-section-address .boot.head=0x10000ba8 -j .boot.head -j .bootloader -Obinary $(ELFFILE) $(RAM1P_IMAGE)
endif
$(warning "Flasher: Use external $(RAM1_IMAGE)?")
else
$(error "BOOT-image size = 0")
# $(error Flasher: COMPILE_BOOT = No)
endif
else
@if [ -s $(RAM1P_IMAGE) ]; then echo "Use external $(RAM1P_IMAGE)!"; fi
endif
$(RAM2P_IMAGE): $(ELFFILE) $(NMAPFILE)
@echo "==========================================================="
@echo "Create image2p ($(RAM2P_IMAGE))"
# @echo "==========================================================="
@mkdir -p $(BIN_DIR)
@rm -f $(RAM2_IMAGE) $(RAM2P_IMAGE)
@$(eval RAM2_START_ADDR = $(shell grep __ram_image2_text $(NMAPFILE) | grep _start__ | awk '{print $$1}'))
@$(eval RAM2_END_ADDR = $(shell grep __ram_image2_text $(NMAPFILE) | grep _end__ | awk '{print $$1}'))
$(if $(RAM2_START_ADDR),,$(error "Not found __ram_image2_text_start__!"))
$(if $(RAM2_END_ADDR),,$(error "Not found __ram_image2_text_end__!"))
@$(OBJCOPY) -j .image2.start.table -j .ram_image2.text -j .ram_image2.rodata -j .ram.data -Obinary $(ELFFILE) $(RAM2_IMAGE)
@$(PICK) 0x$(RAM2_START_ADDR) 0x$(RAM2_END_ADDR) $(RAM2_IMAGE) $(RAM2P_IMAGE) body+reset_offset+sig
$(RAM2NS_IMAGE):$(ELFFILE) $(NMAPFILE)
@echo "==========================================================="
@echo "Create image2ns ($(RAM2NS_IMAGE))"
# @echo "==========================================================="
mkdir -p $(BIN_DIR)
rm -f $(RAM2_IMAGE) $(RAM2NS_IMAGE)
$(eval RAM2_START_ADDR = $(shell grep __ram_image2_text $(NMAPFILE) | grep _start__ | awk '{print $$1}'))
$(eval RAM2_END_ADDR = $(shell grep __ram_image2_text $(NMAPFILE) | grep _end__ | awk '{print $$1}'))
$(if $(RAM2_START_ADDR),,$(error "Not found __ram_image2_text_start__!"))
$(if $(RAM2_END_ADDR),,$(error "Not found __ram_image2_text_end__!"))
$(OBJCOPY) -j .image2.start.table -j .ram_image2.text -j .ram_image2.rodata -j .ram.data -Obinary $(ELFFILE) $(RAM2_IMAGE)
$(PICK) 0x$(RAM2_START_ADDR) 0x$(RAM2_END_ADDR) $(RAM2_IMAGE) $(RAM2NS_IMAGE) body+reset_offset
$(RAM3_IMAGE): $(ELFFILE) $(NMAPFILE)
@echo "==========================================================="
@echo "Create image3 (SDRAM, $(RAM3P_IMAGE))"
# @echo "==========================================================="
@mkdir -p $(BIN_DIR)
@rm -f $(RAM3_IMAGE) $(RAM3P_IMAGE)
@$(eval RAM3_START_ADDR = $(shell grep __sdram_data_ $(NMAPFILE) | grep _start__ | awk '{print $$1}'))
@$(eval RAM3_END_ADDR = $(shell grep __sdram_data_ $(NMAPFILE) | grep _end__ | awk '{print $$1}'))
$(if $(RAM3_START_ADDR),,$(error "Not found __sdram_data_start__!"))
$(if $(RAM3_END_ADDR),,$(error "Not found __sdram_data_end__!"))
@echo $(RAM3_START_ADDR) $(RAM3_END_ADDR)
#ifneq ($(RAM3_START_ADDR),$(RAM3_END_ADDR))
@$(OBJCOPY) -j .image3 -j .sdr_text -j .sdr_rodata -j .sdr_data -Obinary $(ELFFILE) $(RAM3_IMAGE)
#else
# @rm -f $(RAM3_IMAGE) $(RAM3P_IMAGE)
# @echo "SDRAM not used (size = 0)"
#endif
$(ELFFILE):
$(error Falsher: file $@ not found)
clean:
@rm -f $(BIN_DIR)/*.bin