This commit is contained in:
2024-12-04 06:46:44 +06:00
parent a764880fe0
commit a521086d10
18 changed files with 2244 additions and 1115 deletions

View File

@@ -1,48 +1,76 @@
FIRMWARE_ADDRESS = 0x10001000
FIRMWARE_ADDRESS = 0x10001500
WORK_AREA_START = 0x10005000
BUFFER_ADDRESS = 0x10008000
BUFFER_SIZE = 262144
BUFFER_SIZE = 204800
FLASH_SECTOR_SIZE = 4096
RAM_SIZE = 15104
all:
arm-none-eabi-gcc -Wall -g -Os -mlittle-endian -mlong-calls -mthumb -mcpu=cortex-m3 -mfloat-abi=soft -mthumb-interwork -ffunction-sections -ffreestanding -fsingle-precision-constant -Wstrict-aliasing=0 -Wl,-T,rtl8710.ld -nostartfiles -nostdlib -u main -Wl,--section-start=.text=$(FIRMWARE_ADDRESS) -DBUFFER_ADDRESS=$(BUFFER_ADDRESS) rtl8710_flasher.c spi_flash.c -o rtl8710_flasher.elf
arm-none-eabi-objcopy -O binary rtl8710_flasher.elf rtl8710_flasher.bin
gcc make_array.c -o make_array
echo "#" >rtl8710.ocd
echo "# OpenOCD script for RTL8710" >>rtl8710.ocd
echo "# Copyright (C) 2016 Rebane, rebane@alkohol.ee" >>rtl8710.ocd
echo "#" >>rtl8710.ocd
echo >>rtl8710.ocd
cat rtl8710_cpu.tcl >>rtl8710.ocd
echo "set rtl8710_flasher_firmware_ptr $(FIRMWARE_ADDRESS)" >>rtl8710.ocd
echo "set rtl8710_flasher_buffer $(BUFFER_ADDRESS)" >>rtl8710.ocd
echo "set rtl8710_flasher_buffer_size $(BUFFER_SIZE)" >>rtl8710.ocd
echo "set rtl8710_flasher_sector_size $(FLASH_SECTOR_SIZE)" >>rtl8710.ocd
echo >>rtl8710.ocd
echo "array set rtl8710_flasher_code {" >>rtl8710.ocd
./make_array <rtl8710_flasher.bin >>rtl8710.ocd
echo "}" >>rtl8710.ocd
echo >>rtl8710.ocd
cat rtl8710_flasher.tcl >>rtl8710.ocd
cp rtl8710.ocd script/rtl8710.ocd
CC = arm-none-eabi-gcc
OBJCOPY = arm-none-eabi-objcopy
LD_FILE = rtl8710.ld
CFLAGS = -Wall -g -Os \
-mcpu=cortex-m4 -mthumb -mfloat-abi=soft \
-ffunction-sections -fdata-sections -flto \
-mlittle-endian -mlong-calls -mthumb-interwork \
-ffreestanding -fsingle-precision-constant \
-Wstrict-aliasing=0 -nostartfiles \
-Wl,-T,$(LD_FILE) -u main \
-Wl,--gc-sections \
-Wl,--defsym=_RAM_ORIGIN=$(FIRMWARE_ADDRESS) \
-Wl,--defsym=_RAM_SIZE=$(RAM_SIZE) \
-DBUFFER_ADDRESS=$(BUFFER_ADDRESS) \
-Wl,--defsym=_WORK_AREA_START=$(WORK_AREA_START)
SRC = rtl8710_flasher.c
TARGET = rtl8710_flasher
INTERFACE = stlink
OPENOCD_BASE=openocd -f interface/$(INTERFACE).cfg -f script/rtl8710.ocd -c "init" -c "reset" -c "halt"
# generate OpenOCD script with embedded flasher bin
script/rtl8710.ocd: $(TARGET).bin rtl8710_cpu.tcl rtl8710_flasher.tcl
cat rtl8710_cpu.tcl > $@
FIRMWARE_ADDRESS=$(FIRMWARE_ADDRESS) \
BUFFER_ADDRESS=$(BUFFER_ADDRESS) \
BUFFER_SIZE=$(BUFFER_SIZE) \
FLASH_SECTOR_SIZE=$(FLASH_SECTOR_SIZE) \
./generate_ocd.sh $< >> $@
cat rtl8710_flasher.tcl >> $@
$(TARGET).bin: $(TARGET).elf
$(OBJCOPY) -O binary $< $@
$(TARGET).elf: $(SRC)
$(CC) $(CFLAGS) $^ -o $@
clean:
rm -rf rtl8710_flasher.elf rtl8710_flasher.bin make_array rtl8710.ocd
rm -f $(TARGET).elf $(TARGET).bin script/rtl8710.ocd
test:
openocd -f interface/stlink-v2-1.cfg -f script/rtl8710.ocd -c "init" -c "reset halt" -c "rtl8710_flash_read_id" -c "shutdown"
$(OPENOCD_BASE) -c "rtl8710_flash_read_id" -c "shutdown"
mac:
openocd -f interface/stlink-v2-1.cfg -f script/rtl8710.ocd -c "init" -c "reset halt" -c "rtl8710_flash_read_mac" -c "shutdown"
$(OPENOCD_BASE) -c "rtl8710_flash_read_mac" -c "shutdown"
dump:
openocd -f interface/stlink-v2-1.cfg -f script/rtl8710.ocd -c "init" -c "reset halt" -c "rtl8710_flash_read_id" -c "rtl8710_flash_read dump.bin 0 1048576" -c "shutdown"
$(OPENOCD_BASE) -c "rtl8710_flash_read_id" -c "rtl8710_flash_read dump.bin 0 1048576" -c "shutdown"
full_erase:
$(OPENOCD_BASE) -c "rtl8710_flash_mass_erase" -c shutdown
restore:
openocd -f interface/stlink-v2-1.cfg -f script/rtl8710.ocd -c "init" -c "reset halt" -c "rtl8710_flash_auto_erase 1" -c "rtl8710_flash_auto_verify 1" -c "rtl8710_flash_write dump.bin 0" -c shutdown
$(OPENOCD_BASE) -c "rtl8710_flash_auto_erase 1" -c "rtl8710_flash_auto_verify 1" -c "rtl8710_flash_write dump.bin 0" -c shutdown
restore_nae:
$(OPENOCD_BASE) -c "rtl8710_flash_auto_erase 0" -c "rtl8710_flash_auto_verify 1" -c "rtl8710_flash_write dump.bin 0" -c shutdown
verify:
openocd -f interface/stlink-v2-1.cfg -f script/rtl8710.ocd -c "init" -c "reset halt" -c "rtl8710_flash_verify dump.bin 0" -c shutdown
$(OPENOCD_BASE) -c "rtl8710_flash_verify dump.bin 0" -c shutdown
reset:
openocd -f interface/stlink-v2-1.cfg -f script/rtl8710.ocd -c "init" -c "reset halt" -c "rtl8710_reboot" -c shutdown
$(OPENOCD_BASE) -c "rtl8710_reboot" -c shutdown
.PHONY: clean