open-ameba/RTL00_SDKV35a/flasher.mk

336 lines
13 KiB
Makefile
Raw Normal View History

2016-11-09 00:56:41 +00:00
# RTL8710 Flasher v0.0.alfa
# pvvx 21.09.2016
2017-05-12 23:29:53 +00:00
include userset.mk
include $(SDK_PATH)paths.mk
2016-11-09 00:56:41 +00:00
#---------------------------
#FLASHER = stlink-v2-1
FLASHER = stlink-v2
#FLASHER ?= Jlink
#JLINK_PATH ?= D:/MCU/SEGGER/JLink_V612i/
2016-11-09 00:56:41 +00:00
#---------------------------
# 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
# For verbose make
ifeq ("$(V)","1")
Q :=
vecho := @true
else
Q := @
vecho := @echo
endif
2016-11-09 00:56:41 +00:00
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
2017-03-04 10:24:48 +00:00
# COMPILED_BOOT if defined -> extract image1, boot head in elf
COMPILED_BOOT=1
# COMPILED_BOOT_BIN if !defined -> use source startup boot
#COMPILED_BOOT_BIN=1
2016-11-09 00:56:41 +00:00
# PADDINGSIZE defined -> image2 OTA
PADDINGSIZE =44k
NMAPFILE = $(OBJ_DIR)/$(TARGET).nmap
#FLASHER_PATH ?= flasher/
2017-03-24 15:24:37 +00:00
#RAM_IMAGE?= $(BIN_DIR)/ram.bin
2017-03-04 10:24:48 +00:00
2016-11-09 00:56:41 +00:00
RAM1_IMAGE ?= $(BIN_DIR)/ram_1.bin
RAM1P_IMAGE ?= $(BIN_DIR)/ram_1.p.bin
2017-03-11 03:10:30 +00:00
RAM1R_IMAGE ?= $(BIN_DIR)/ram_1.r.bin
2016-11-09 00:56:41 +00:00
RAM2_IMAGE = $(BIN_DIR)/ram_2.bin
RAM2P_IMAGE = $(BIN_DIR)/ram_2.p.bin
RAM2NS_IMAGE = $(BIN_DIR)/ram_2.ns.bin
2017-03-04 10:24:48 +00:00
RAM3_IMAGE = $(BIN_DIR)/sdram.bin
RAM3P_IMAGE = $(BIN_DIR)/sdram.p.bin
2016-11-09 00:56:41 +00:00
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
2017-04-03 07:32:32 +00:00
.PHONY: genbin1 genbin23 flashburn reset test readfullflash flashwebfs flash_OTA
.NOTPARALLEL: all mp genbin1 genbin23 flashburn reset test readfullflash _endgenbin flashwebfs flash_OTA
2016-11-09 00:56:41 +00:00
all: $(ELFFILE) $(OTA_IMAGE) $(FLASH_IMAGE) _endgenbin
mp: $(ELFFILE) $(OTA_IMAGE) $(FLASH_IMAGE) _endgenbin
genbin1: $(ELFFILE) $(RAM1P_IMAGE)
genbin23: $(ELFFILE) $(OTA_IMAGE) $(FLASH_IMAGE) _endgenbin
2017-04-03 07:32:32 +00:00
2016-11-09 00:56:41 +00:00
_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 "==========================================================="
2017-04-03 07:32:32 +00:00
ifeq ($(FLASHER_TYPE), Jlink)
reset:
2017-04-09 16:14:49 +00:00
@$(JLINK_PATH)$(JLINK_EXE) -Device CORTEX-M3 -If SWD -Speed 1000 $(FLASHER_PATH)RTL_Reset.JLinkScript
2017-04-03 07:32:32 +00:00
runram:
2017-04-09 16:14:49 +00:00
@$(JLINK_PATH)$(JLINK_EXE) -Device CORTEX-M3 -If SWD -Speed 1000 $(FLASHER_PATH)RTL_RunRAM.JLinkScript
2017-04-03 07:32:32 +00:00
readfullflash:
2017-04-09 16:14:49 +00:00
@$(JLINK_PATH)$(JLINK_EXE) -Device CORTEX-M3 -If SWD -Speed 1000 $(FLASHER_PATH)RTL_FFlash.JLinkScript
2017-04-03 07:32:32 +00:00
2016-11-09 00:56:41 +00:00
flashburn:
2017-04-03 07:32:32 +00:00
@echo define call1>$(FLASHER_PATH)flash_file.jlink
@echo SetFirwareSize build/bin/ram_all.bin>>$(FLASHER_PATH)flash_file.jlink
@echo end>>$(FLASHER_PATH)flash_file.jlink
@echo define call2>>$(FLASHER_PATH)flash_file.jlink
@echo FlasherWrite build/bin/ram_all.bin 0 '$$'Image1Size>>$(FLASHER_PATH)flash_file.jlink
@echo end>>$(FLASHER_PATH)flash_file.jlink
@echo define call3>>$(FLASHER_PATH)flash_file.jlink
@echo FlasherWrite build/bin/ram_all.bin '$$'Image2Addr '$$'Image2Size>>$(FLASHER_PATH)flash_file.jlink
@echo end>>$(FLASHER_PATH)flash_file.jlink
2017-04-09 16:14:49 +00:00
@cmd /K start $(JLINK_PATH)$(JLINK_GDBSRV) -device Cortex-M3 -if SWD -ir -endian little -speed 1000
2017-04-03 07:32:32 +00:00
@$(GDB) -x $(FLASHER_PATH)gdb_wrflash.jlink
2017-04-09 16:14:49 +00:00
#@taskkill /F /IM $(JLINK_GDBSRV)
2017-04-03 07:32:32 +00:00
flashwebfs:
2017-05-12 23:29:53 +00:00
@echo define call1>$(FLASHER_PATH)file_info.jlink
@echo set '$$'ImageSize = $(shell printf '0x%X\n' $$(stat --printf="%s" $(BIN_DIR)/WEBFiles.bin))>>$(FLASHER_PATH)file_info.jlink
@echo set '$$'ImageAddr = 0x0D0000>>$(FLASHER_PATH)file_info.jlink
@echo end>>$(FLASHER_PATH)file_info.jlink
@echo define call2>>$(FLASHER_PATH)file_info.jlink
@echo FlasherWrite $(BIN_DIR)/WEBFiles.bin '$$'ImageAddr '$$'ImageSize>>$(FLASHER_PATH)file_info.jlink
@echo end>>$(FLASHER_PATH)file_info.jlink
@cmd /K start $(JLINK_PATH)$(JLINK_GDBSRV) -device Cortex-M3 -if SWD -ir -endian little -speed 1000
@$(GDB) -x $(FLASHER_PATH)gdb_wrfile.jlink
#@taskkill /F /IM $(JLINK_GDBSRV)
flashespfs:
2017-04-09 16:14:49 +00:00
@echo define call1>$(FLASHER_PATH)file_info.jlink
@echo set '$$'ImageSize = $(shell printf '0x%X\n' $$(stat --printf="%s" $(BIN_DIR)/webpages.espfs))>>$(FLASHER_PATH)file_info.jlink
2017-04-03 07:32:32 +00:00
@echo set '$$'ImageAddr = 0x0D0000>>$(FLASHER_PATH)file_info.jlink
2017-04-09 16:14:49 +00:00
@echo end>>$(FLASHER_PATH)file_info.jlink
@echo define call2>>$(FLASHER_PATH)file_info.jlink
2017-04-03 07:32:32 +00:00
@echo FlasherWrite $(BIN_DIR)/webpages.espfs '$$'ImageAddr '$$'ImageSize>>$(FLASHER_PATH)file_info.jlink
@echo end>>$(FLASHER_PATH)file_info.jlink
2017-04-09 16:14:49 +00:00
@cmd /K start $(JLINK_PATH)$(JLINK_GDBSRV) -device Cortex-M3 -if SWD -ir -endian little -speed 1000
2017-04-03 07:32:32 +00:00
@$(GDB) -x $(FLASHER_PATH)gdb_wrfile.jlink
2017-04-09 16:14:49 +00:00
#@taskkill /F /IM $(JLINK_GDBSRV)
2017-04-03 07:32:32 +00:00
2017-05-12 23:29:53 +00:00
2017-04-03 07:32:32 +00:00
flash_OTA:
2017-04-09 16:14:49 +00:00
@cmd /K start $(JLINK_PATH)$(JLINK_GDBSRV) -device Cortex-M3 -if SWD -ir -endian little -speed 1000
2017-04-03 07:32:32 +00:00
@$(GDB) -x $(FLASHER_PATH)gdb_ota.jlink
2017-04-09 16:14:49 +00:00
#@taskkill /F /IM $(JLINK_GDBSRV)
2017-04-03 07:32:32 +00:00
else
flashburn:
@$(OPENOCD) -f interface/$(FLASHER).cfg -c "transport select swd" -f $(FLASHER_PATH)rtl8710.ocd -c "init" -c "adapter_khz $(FLASHER_SPEED)" -c "reset halt" \
-c "rtl8710_flash_auto_erase 1" -c "rtl8710_flash_auto_verify 1" \
-c "rtl8710_flash_write $(RAM1P_IMAGE) 0" \
-c "rtl8710_flash_write $(RAM2P_IMAGE) 0xb000" \
-c "rtl8710_reboot" -c "reset run" -c shutdown
flashimage2p:
@$(OPENOCD) -f interface/$(FLASHER).cfg -c "transport select swd" -f $(FLASHER_PATH)rtl8710.ocd -c "init" -c "adapter_khz $(FLASHER_SPEED)" -c "reset halt" \
-c "rtl8710_flash_auto_erase 1" -c "rtl8710_flash_auto_verify 1" \
-c "rtl8710_flash_write $(RAM2P_IMAGE) 0xb000" \
-c "rtl8710_reboot" -c "reset run" -c shutdown
flashwebfs:
@$(OPENOCD) -f interface/$(FLASHER).cfg -c "transport select swd" -f $(FLASHER_PATH)rtl8710.ocd -c "init" -c "adapter_khz $(FLASHER_SPEED)" -c "reset halt" \
-c "rtl8710_flash_auto_erase 1" -c "rtl8710_flash_auto_verify 1" \
2017-05-12 23:29:53 +00:00
-c "rtl8710_flash_write $(BIN_DIR)/WEBFiles.bin 0xd0000" \
2017-04-03 07:32:32 +00:00
-c "rtl8710_reboot" -c "reset run" -c shutdown
2017-05-12 23:29:53 +00:00
flashespfs:
@$(OPENOCD) -f interface/$(FLASHER).cfg -c "transport select swd" -f $(FLASHER_PATH)rtl8710.ocd -c "init" -c "adapter_khz $(FLASHER_SPEED)" -c "reset halt" \
-c "rtl8710_flash_auto_erase 1" -c "rtl8710_flash_auto_verify 1" \
-c "rtl8710_flash_write $(BIN_DIR)/webpages.espfs 0xd0000" \
-c "rtl8710_reboot" -c "reset run" -c shutdown
2016-11-09 00:56:41 +00:00
reset:
2017-04-09 16:14:49 +00:00
# @$(JLINK_PATH)$(JLINK_EXE) -Device CORTEX-M3 -If SWD -Speed $(FLASHER_SPEED) flasher/RTLreset.JLinkScript
2017-04-03 07:32:32 +00:00
@$(OPENOCD) -f interface/$(FLASHER).cfg -c "transport select swd" -f $(FLASHER_PATH)rtl8710.ocd -c "init" -c "adapter_khz $(FLASHER_SPEED)" -c "reset halt" \
-c "rtl8710_reboot" -c shutdown
2016-11-09 00:56:41 +00:00
runram:
2017-04-09 16:14:49 +00:00
# @$(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)
2017-04-03 07:32:32 +00:00
@$(OPENOCD) -f interface/$(FLASHER).cfg -c "transport select swd" -f $(FLASHER_PATH)rtl8710.ocd -c "init" -c "adapter_khz $(FLASHER_SPEED)" -c "reset halt" \
-c "load_image $(RAM1R_IMAGE) 0x10000bc8 bin" \
-c "load_image $(RAM2_IMAGE) 0x10006000 bin" \
-c "mww 0x40000210 0x20200113" \
-c "reset run" -c shutdown
2016-11-09 00:56:41 +00:00
2017-04-03 07:32:32 +00:00
endif
2016-11-09 00:56:41 +00:00
$(NMAPFILE): $(ELFFILE)
@echo "==========================================================="
@echo "Build names map file"
@echo $@
@$(NM) $< | sort > $@
# @echo "==========================================================="
2017-03-04 10:24:48 +00:00
$(FLASH_IMAGE): $(RAM1P_IMAGE) $(RAM2P_IMAGE) $(RAM3P_IMAGE)
2016-11-09 00:56:41 +00:00
@echo "==========================================================="
@echo "Make Flash image ($(FLASH_IMAGE))"
# @echo "==========================================================="
@mkdir -p $(BIN_DIR)
@rm -f $(FLASH_IMAGE)
@cat $(RAM1P_IMAGE) > $(FLASH_IMAGE)
# @chmod 777 $(FLASH_IMAGE)
ifdef PADDINGSIZE
@$(PADDING) $(PADDINGSIZE) 0xFF $(FLASH_IMAGE)
endif
@cat $(RAM2P_IMAGE) >> $(FLASH_IMAGE)
2017-03-04 10:24:48 +00:00
@cat $(RAM3P_IMAGE) >> $(FLASH_IMAGE)
2016-11-09 00:56:41 +00:00
# @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)
@cat $(RAM2NS_IMAGE) > $(OTA_IMAGE)
2017-03-04 10:24:48 +00:00
@cat $(RAM3P_IMAGE) >> $(OTA_IMAGE)
2016-11-09 00:56:41 +00:00
# @chmod 777 $(OTA_IMAGE)
@$(CHCKSUM) $(OTA_IMAGE) || true
# @echo "==========================================================="
$(RAM1P_IMAGE): $(ELFFILE) $(NMAPFILE)
@echo "==========================================================="
2017-03-11 03:10:30 +00:00
@echo "Create image1r ($(RAM1R_IMAGE))"
2016-11-09 00:56:41 +00:00
# @echo "===========================================================" .bootloader
ifdef COMPILED_BOOT
@mkdir -p $(BIN_DIR)
2017-03-11 03:10:30 +00:00
@rm -f $(RAM1_IMAGE) $(RAM1R_IMAGE)
2017-03-04 10:24:48 +00:00
ifdef COMPILED_BOOT_BIN
2016-11-09 00:56:41 +00:00
@$(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))
2017-03-04 10:24:48 +00:00
ifdef COMPILED_BOOT_BIN
2016-11-09 00:56:41 +00:00
$(OBJCOPY) --change-section-address .boot.head=0x10000ba8 -j .boot.head -j .bootloader -Obinary $(ELFFILE) $(RAM1P_IMAGE)
2017-03-04 10:24:48 +00:00
else
2017-03-24 15:24:37 +00:00
# $(OBJCOPY) -j .rom_ram -Obinary $(ELFFILE) $(RAM_IMAGE)
$(Q) $(OBJCOPY) -j .ram.start.table -j .ram_image1.text -Obinary $(ELFFILE) $(RAM1R_IMAGE)
$(Q) $(PICK) 0x$(RAM1_START_ADDR) 0x$(RAM1_END_ADDR) $(RAM1R_IMAGE) $(RAM1P_IMAGE) head+reset_offset 0x0B000
2016-11-09 00:56:41 +00:00
endif
else
$(error "BOOT-image size = 0")
# $(error Flasher: COMPILE_BOOT = No)
endif
else
2017-03-11 03:10:30 +00:00
@if [ -s $(RAM1R_IMAGE) ]; then echo "Use external $(RAM1R_IMAGE)!"; fi
2016-11-09 00:56:41 +00:00
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 "==========================================================="
$(Q) mkdir -p $(BIN_DIR)
$(Q) rm -f $(RAM2_IMAGE) $(RAM2NS_IMAGE)
$(Q) $(eval RAM2_START_ADDR = $(shell grep __ram_image2_text $(NMAPFILE) | grep _start__ | awk '{print $$1}'))
$(Q) $(eval RAM2_END_ADDR = $(shell grep __ram_image2_text $(NMAPFILE) | grep _end__ | awk '{print $$1}'))
2016-11-09 00:56:41 +00:00
$(if $(RAM2_START_ADDR),,$(error "Not found __ram_image2_text_start__!"))
$(if $(RAM2_END_ADDR),,$(error "Not found __ram_image2_text_end__!"))
$(Q) $(OBJCOPY) -j .image2.start.table -j .ram_image2.text -j .ram_image2.rodata -j .ram.data -Obinary $(ELFFILE) $(RAM2_IMAGE)
$(Q) $(PICK) 0x$(RAM2_START_ADDR) 0x$(RAM2_END_ADDR) $(RAM2_IMAGE) $(RAM2NS_IMAGE) body+reset_offset
2016-11-09 00:56:41 +00:00
$(RAM3_IMAGE): $(ELFFILE) $(NMAPFILE)
@echo "==========================================================="
@echo "Create image3 (SDRAM, $(RAM3P_IMAGE))"
# @echo "==========================================================="
@mkdir -p $(BIN_DIR)
@rm -f $(RAM3_IMAGE) $(RAM3P_IMAGE)
2016-12-04 10:41:40 +00:00
@$(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}'))
2016-11-09 00:56:41 +00:00
$(if $(RAM3_START_ADDR),,$(error "Not found __sdram_data_start__!"))
$(if $(RAM3_END_ADDR),,$(error "Not found __sdram_data_end__!"))
2017-03-04 10:24:48 +00:00
#ifneq ($(RAM3_START_ADDR),$(RAM3_END_ADDR))
2016-12-04 10:41:40 +00:00
@echo $(RAM3_START_ADDR) $(RAM3_END_ADDR)
$(Q) $(OBJCOPY) -j .image3 -j .sdr_text -j .sdr_rodata -j .sdr_data -Obinary $(ELFFILE) $(RAM3_IMAGE)
$(Q) $(PICK) 0x$(RAM3_START_ADDR) 0x$(RAM3_END_ADDR) $(RAM3_IMAGE) $(RAM3P_IMAGE) body+reset_offset
2017-03-04 10:24:48 +00:00
#else
# @rm -f $(RAM3_IMAGE) $(RAM3P_IMAGE)
# @echo "SDRAM not used (size = 0)"
#endif
2016-11-09 00:56:41 +00:00
$(ELFFILE):
$(error Falsher: file $@ not found)
clean:
@rm -f $(BIN_DIR)/*.bin