diff --git a/.gitignore b/.gitignore index 51d02f0..3455007 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ -make_array rtl8710_flasher.bin rtl8710_flasher.elf rtl8710.ocd dump.bin - +trash/ \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..19f8b15 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,15 @@ +{ + "files.associations": { + "*.rmd": "markdown", + "stdio.h": "c", + "spi_flash.h": "c", + "rtl8710.h": "c", + "random": "c", + "array": "c", + "string": "c", + "string_view": "c", + "span": "c", + "string.h": "c", + "chrono": "c" + } +} \ No newline at end of file diff --git a/Makefile b/Makefile index 26bfc5c..d7f5153 100644 --- a/Makefile +++ b/Makefile @@ -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.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 diff --git a/README.md b/README.md index c3e5135..557e4b7 100644 --- a/README.md +++ b/README.md @@ -1,45 +1,113 @@ # RTL-8710 openocd support -OpenOCD support for RTL8710 and integrated flash. + +OpenOCD support for RTL8710 and integrated flash. +Uses and links against ROM functions, they're there anyway so whatever, we get a smaller flasher binary and codebase this way too. + ## pins: + ### SWD -* SWDIO: GE3 -* SWCLK: GE4 + +- SWDIO: GE3 +- SWCLK: GE4 + ### JTAG -* TRST: GE0 -* TDI: GE1 -* TDO: GE2 -* TMS: GE3 -* TCK: GE4 + +- TRST: GE0 +- TDI: GE1 +- TDO: GE2 +- TMS: GE3 +- TCK: GE4 + ## building: + ``` make ``` -## available OpenOCD commands: -### rtl8710_flash_read_id -read and parse the jedec id bytes from flash -### rtl8710_flash_read_mac -read MAC address from flash memory at 0xA088 -### rtl8710_flash_mass_erase -erase whole flash -### rtl8710_flash_read [filename] [offset] [size] -dump (size) bytes from flash offset (offset) to file (filename) -### rtl8710_flash_write [filename] [offset] -write file (filename) to flash offset (offset) -### rtl8710_flash_verify [filename] [offset] -compare file (filename) with flash offset (offset) -### rtl8710_flash_auto_erase [1/0] -set auto_erase option on/off. flash sectors will be autoerased when writing -### rtl8710_flash_auto_verify [1/0] -set auto_verify option on/off. each block of data will be auto verified when writing -## examples: -``` -openocd -f interface/stlink-v2-1.cfg -f rtl8710.ocd -c "init" -c "reset halt" -c "rtl8710_flash_read_id" -c "rtl8710_flash_read dump.bin 0 1048576" -c "shutdown" -``` -``` -openocd -f interface/stlink-v2-1.cfg -f 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" + +# RTL8710 OpenOCD Commands + +### Core Functions + +- `rtl8710_flasher_init` + init flasher, loads firmware and reads flash ID to determine capacity + +- `rtl8710_flasher_mrw [reg]` + reads 32-bit value from specified register + +- `rtl8710_flasher_wait` + polls control register at `buffer + 0x00` until operation completes + +- `rtl8710_flasher_load_block [filename] [offset] [length]` + loads data block from file into buffer at `buffer + 0x20` + +- `rtl8710_flasher_block [command] [offset] [len]` + internal function for read/write/verify operations. Command must be `"read"`, `"write"` or `"verify"` + +### Block Operations + +- `rtl8710_flasher_read_block [offset] [len]` + reads block from flash into buffer + +- `rtl8710_flasher_write_block [offset] [len]` + writes buffer contents to flash + +- `rtl8710_flasher_verify_block [offset] [len]` + verifies flash contents against buffer + +### Flash Commands + +- `rtl8710_flash_read_id` + reads JEDEC ID and displays manufacturer ID, memory type and capacity + +- `rtl8710_flash_read_mac` + reads MAC address from flash offset `0xA088` + +- `rtl8710_flash_erase [type] [offset]` + erases flash memory. Type must be `"mass"` or `"sector"`. For sector erase, specify offset + +- `rtl8710_flash_mass_erase` + performs mass erase of entire flash chip + +- `rtl8710_flash_sector_erase [offset]` + erases single sector at specified offset + +- `rtl8710_flash_read [filename] [offset] [size]` + reads `size` bytes from flash at `offset` to `filename` + +- `rtl8710_flash_write [filename] [offset]` + writes file to flash at `offset`, using configured buffer size chunks + +- `rtl8710_flash_verify [filename] [offset]` + verifies flash contents against file at `offset`, using configured buffer size chunks + +### Configuration + +- `rtl8710_flash_auto_erase [1/0]` + enables/disables automatic sector erase before write operations + +- `rtl8710_flash_auto_verify [1/0]` + enables/disables automatic verification after write operations + +### System Control + +- `rtl8710_reboot` + triggers system reboot by writing `0x05FA0007` to AIRCR register @ `0xE000ED0C` + +## Example Usage + +```bash +# Read 1MB from flash +openocd -f interface/stlink-v2-1.cfg -f rtl8710.ocd -c "init" -c "reset halt" \ + -c "rtl8710_flash_read_id" -c "rtl8710_flash_read dump.bin 0 1048576" -c "shutdown" + +# write to flash with auto erase/verify +openocd -f interface/stlink-v2-1.cfg -f 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" ``` + # About -RTL8710 OpenOCD support is created by Rebane (rebane@alkohol.ee) + +RTL8710 OpenOCD support based on work by Rebane (rebane@alkohol.ee) This document and the attached source code is released under GPLv2. - diff --git a/TODO.txt b/TODO.txt index cbd6bb2..4d892a9 100644 --- a/TODO.txt +++ b/TODO.txt @@ -2,4 +2,4 @@ TESTING better documentation error handling timeout handling - +-work-area-phys, cpu/flasher tcl split sucks \ No newline at end of file diff --git a/export-rom_symbol_v01.txt b/export-rom_symbol_v01.txt new file mode 100644 index 0000000..5ab1c0c --- /dev/null +++ b/export-rom_symbol_v01.txt @@ -0,0 +1,1427 @@ +SECTIONS +{ + __vectors_table = 0x0; + Reset_Handler = 0x101; + NMI_Handler = 0x115; + HardFault_Handler = 0x119; + MemManage_Handler = 0x12d; + BusFault_Handler = 0x131; + UsageFault_Handler = 0x135; + VSprintf = 0x201; + DiagPrintf = 0x4dd; + DiagSPrintf = 0x509; + DiagSnPrintf = 0x535; + prvDiagPrintf = 0x7ed; + prvDiagSPrintf = 0x821; + UARTIMG_Write = 0x855; + UARTIMG_Download = 0x901; + _memcmp = 0x991; + _memcpy = 0x9c5; + _memset = 0xa7d; + DumpForOneBytes = 0xae9; + CmdRomHelp = 0xc69; + CmdDumpWord = 0xccd; + CmdWriteWord = 0xd7d; + CmdFlash = 0xdd1; + CmdEfuse = 0x12c1; + CmdDumpByte = 0x1775; + CmdDumpHalfWord = 0x17c9; + CmdWriteByte = 0x1881; + SramReadWriteCpy = 0x18c1; + SramReadWriteTest = 0x19f9; + CmdSRamTest = 0x1ac9; + GetRomCmdNum = 0x1b59; + Rand = 0x1b5d; + Rand_Arc4 = 0x1bdd; + RandBytes_Get = 0x1c0d; + Isspace = 0x1c59; + Strtoul = 0x1c6d; + ArrayInitialize = 0x1d15; + GetArgc = 0x1d29; + GetArgv = 0x1d55; + UartLogCmdExecute = 0x1db1; + UartLogShowBackSpace = 0x1e49; + UartLogRecallOldCmd = 0x1e7d; + UartLogHistoryCmd = 0x1eb1; + UartLogCmdChk = 0x1f2d; + UartLogIrqHandle = 0x2035; + RtlConsolInit = 0x2101; + RtlConsolTaskRom = 0x218d; + RtlExitConsol = 0x21b9; + RtlConsolRom = 0x2205; + BKUP_Write = 0x2249; + BKUP_Read = 0x226d; + BKUP_Set = 0x228d; + BKUP_Clear = 0x22b9; + NCO32K_Init = 0x22e9; + EXT32K_Cmd = 0x2349; + NCO8M_Init = 0x2365; + NCO8M_Cmd = 0x23bd; + ISO_Set = 0x23d9; + PLL0_Set = 0x23f1; + PLL1_Set = 0x2409; + PLL2_Set = 0x2421; + PLL3_Set = 0x2439; + XTAL0_Set = 0x2451; + XTAL1_Set = 0x2469; + XTAL2_Set = 0x2481; + XTAL_ClkGet = 0x2499; + CPU_ClkSet = 0x24b1; + CPU_ClkGet = 0x24c5; + OSC32K_Calibration = 0x24e5; + OSC32K_Cmd = 0x25f9; + OSC8M_Get = 0x2631; + rtl_cryptoEngine_SrcDesc_Show = 0x2641; + rtl_cryptoEngine_info = 0x27f1; + rtl_cryptoEngine_init = 0x2949; + rtl_crypto_md5_init = 0x2975; + rtl_crypto_md5_process = 0x29b1; + rtl_crypto_md5 = 0x2a09; + rtl_crypto_sha1_init = 0x2a2d; + rtl_crypto_sha1_process = 0x2a69; + rtl_crypto_sha1 = 0x2a9d; + rtl_crypto_sha2_init = 0x2ac1; + rtl_crypto_sha2_process = 0x2b15; + rtl_crypto_sha2 = 0x2b4d; + rtl_crypto_hmac_md5_init = 0x2b71; + rtl_crypto_hmac_md5_process = 0x2bd1; + rtl_crypto_hmac_md5 = 0x2c0d; + rtl_crypto_hmac_sha1_init = 0x2c31; + rtl_crypto_hmac_sha1_process = 0x2c91; + rtl_crypto_hmac_sha1 = 0x2cc9; + rtl_crypto_hmac_sha2_init = 0x2ced; + rtl_crypto_hmac_sha2_process = 0x2d65; + rtl_crypto_hmac_sha2 = 0x2da1; + rtl_crypto_aes_cbc_init = 0x2dc5; + rtl_crypto_aes_cbc_encrypt = 0x2dfd; + rtl_crypto_aes_cbc_decrypt = 0x2e45; + rtl_crypto_aes_ecb_init = 0x2e8d; + rtl_crypto_aes_ecb_encrypt = 0x2ec5; + rtl_crypto_aes_ecb_decrypt = 0x2ef5; + rtl_crypto_aes_ctr_init = 0x2f25; + rtl_crypto_aes_ctr_encrypt = 0x2f5d; + rtl_crypto_aes_ctr_decrypt = 0x2f99; + rtl_crypto_3des_cbc_init = 0x2fd5; + rtl_crypto_3des_cbc_encrypt = 0x300d; + rtl_crypto_3des_cbc_decrypt = 0x3055; + rtl_crypto_3des_ecb_init = 0x309d; + rtl_crypto_3des_ecb_encrypt = 0x30d5; + rtl_crypto_3des_ecb_decrypt = 0x311d; + rtl_crypto_des_cbc_init = 0x3165; + rtl_crypto_des_cbc_encrypt = 0x319d; + rtl_crypto_des_cbc_decrypt = 0x31f5; + rtl_crypto_des_ecb_init = 0x324d; + rtl_crypto_des_ecb_encrypt = 0x3285; + rtl_crypto_des_ecb_decrypt = 0x32dd; + SYSTIMER_Init = 0x3335; + SYSTIMER_TickGet = 0x33a1; + SYSTIMER_GetPassTime = 0x33c1; + DelayNop = 0x3401; + DelayUs = 0x3411; + DelayMs = 0x346d; + USOC_DongleSpecialCmd = 0x3481; + USOC_DongleCmd = 0x35d9; + USOC_DongleIsr = 0x35f9; + USOC_SIE_INTConfig = 0x3621; + USOC_SIE_INTClear = 0x3639; + USOC_PHY_Write = 0x3645; + USOC_PHY_Read = 0x3679; + USOC_PHY_Autoload = 0x36c1; + USOC_DongleInit = 0x37a5; + EFUSE_USER_Read = 0x386d; + EFUSE_USER1_Read = 0x3971; + EFUSE_USER2_Read = 0x397d; + EFUSE_USER3_Read = 0x3989; + EFUSE_RemainLength = 0x3995; + EFUSE_USER_Write = 0x3a21; + EFUSE_USER1_Write = 0x3bb1; + EFUSE_USER2_Write = 0x3bc1; + EFUSE_USER3_Write = 0x3bd1; + EFUSE_OTP_Read1B = 0x3be1; + EFUSE_OTP_Write1B = 0x3c01; + EFUSE_OTP_Read32B = 0x3c21; + EFUSE_OTP_Write32B = 0x3c4d; + EFUSE_RDP_EN = 0x3cad; + EFUSE_RDP_KEY = 0x3ccd; + EFUSE_OTF_KEY = 0x3cf9; + EFUSE_JTAG_OFF = 0x3d25; + PAD_DrvStrength = 0x3d45; + PAD_PullCtrl = 0x3d75; + Pinmux_Config = 0x3dc5; + Pinmux_ConfigGet = 0x3dfd; + Pinmux_Deinit = 0x3e19; + PINMUX_UART0_Ctrl = 0x3e39; + PINMUX_UART1_Ctrl = 0x3e81; + PINMUX_UARTLOG_Ctrl = 0x3ea9; + PINMUX_SPI0_Ctrl = 0x3ef9; + PINMUX_SPI1_Ctrl = 0x3f8d; + PINMUX_SPIF_Ctrl = 0x400d; + PINMUX_I2C0_Ctrl = 0x406d; + PINMUX_I2C1_Ctrl = 0x40e1; + PINMUX_SDIOD_Ctrl = 0x4151; + PINMUX_I2S0_Ctrl = 0x41e5; + PINMUX_SWD_Ctrl = 0x4265; + PINMUX_SWD_OFF = 0x42b5; + PINMUX_SWD_REG = 0x42d9; + PINMUX_Ctrl = 0x42fd; + SOCPS_BackupCPUClk = 0x4391; + SOCPS_RestoreCPUClk = 0x43b1; + SOCPS_BootFromPS = 0x43d1; + SOCPS_TrapPin = 0x43f1; + SOCPS_ANACKSel = 0x4411; + SOCPS_CLKCal = 0x442d; + SOCPS_SetWakeEvent = 0x4485; + SOCPS_ClearWakeEvent = 0x449d; + SOCPS_WakePinsCtrl = 0x44a9; + SOCPS_WakePinCtrl = 0x44d9; + SOCPS_WakePinClear = 0x4529; + SOCPS_GetANATimerParam = 0x4539; + SOCPS_SetANATimer = 0x4575; + SOCPS_SetReguWakepin = 0x45dd; + SOCPS_SetReguTimer = 0x4605; + SOCPS_PWROption = 0x46d9; + SOCPS_PWROptionExt = 0x46e5; + SOCPS_PWRMode = 0x46f9; + SOCPS_SNZMode = 0x4721; + SOCPS_DeepStandby = 0x473d; + SOCPS_DeepSleep = 0x4791; + SDIO_StructInit = 0x47d5; + SDIO_Init = 0x47f1; + SDIO_INTClear = 0x486d; + SDIO_INTConfig = 0x487d; + SDIO_RPWM1_Get = 0x4895; + SDIO_RPWM2_Get = 0x48a1; + SDIO_CPWM1_Set = 0x48ad; + SDIO_CPWM2_Set = 0x48c1; + SDIO_RXBD_RPTR_Get = 0x48dd; + SDIO_RXBD_WPTR_Set = 0x48e9; + SDIO_TXBD_WPTR_Get = 0x48f5; + SDIO_TXBD_RPTR_Set = 0x4901; + SDIO_DMA_Reset = 0x490d; + BOOT_ROM_Simulation = 0x4919; + USOC_BOOT_TXBD_Proc = 0x491d; + USOC_BOOT_Init = 0x4a3d; + USB_Boot_ROM = 0x4aa9; + USOC_CH_Cmd = 0x4b59; + USOC_Cmd = 0x4bb1; + USOC_PHY_Cmd = 0x4bf5; + USOC_MODE_Cfg = 0x4c09; + USOC_TXBD_SWIDX_Cfg = 0x4c25; + USOC_TXBD_SWIDX_Get = 0x4c2d; + USOC_TXBD_HWIDX_Get = 0x4c35; + USOC_RXBD_HWIDX_Get = 0x4c3d; + USOC_RXBD_SWIDX_Cfg = 0x4c45; + USOC_RXBD_SWIDX_Get = 0x4c4d; + USOC_StructInit = 0x4c55; + USOC_Init = 0x4c85; + USOC_SW_RST = 0x4d7d; + USOC_INTCfg = 0x4d91; + USOC_INTClr = 0x4d95; + USOC_INTGet = 0x4d9d; + USOC_MIT_Cfg = 0x4da1; + USOC_TXSTUCK_Cfg = 0x4dc5; + USOC_RXSTUCK_Cfg = 0x4de9; + USOC_POWER_On = 0x4e0d; + ADC_RXGDMA_Init = 0x4e9d; + ADC_SetAudio = 0x4f45; + ADC_SetAnalog = 0x4f61; + ADC_Cmd = 0x4fbd; + ADC_INTConfig = 0x5031; + ADC_SetOneShot = 0x5049; + ADC_SetComp = 0x50fd; + ADC_INTClear = 0x517d; + ADC_INTClearPendingBits = 0x5189; + ADC_GetISR = 0x5195; + ADC_Read = 0x51a1; + ADC_ReceiveBuf = 0x51ad; + ADC_InitStruct = 0x5205; + ADC_Init = 0x524d; + BOOT_ROM_ShowBuildInfo = 0x52ed; + BOOT_ROM_OTFCheck = 0x5335; + BOOT_ROM_InitFlash = 0x5345; + BOOT_ROM_FromFlash = 0x5405; + BOOT_ROM_InitUsb = 0x5511; + BOOT_ROM_Process = 0x553d; + BOOT_ROM_InitDebugFlg = 0x5605; + HalResetVsr = 0x5639; + Cache_Enable = 0x5811; + Cache_Flush = 0x5831; + Cache_Debug = 0x5851; + CRYPTO_AlignToBe32 = 0x58bd; + CRYPTO_MemDump = 0x58d5; + CRYPTO_GetAESKey = 0x599d; + CRYPTO_SetAESKey = 0x5cb5; + CRYPTO_SetSecurityMode = 0x5d29; + CRYPTO_Init = 0x5f5d; + CRYPTO_DeInit = 0x60b9; + CRYPTO_Reset = 0x6101; + CRYPTO_Process = 0x6129; + CRYPTO_CipherInit = 0x6a11; + CRYPTO_CipherEncrypt = 0x6a35; + CRYPTO_CipherDecrypt = 0x6a61; + CRYPTO_SetCheckSumEn = 0x6a95; + CRYPTO_GetCheckSumData = 0x6ab1; + LOGUART_StructInit = 0x6abd; + LOGUART_Init = 0x6ad5; + LOGUART_PutChar = 0x6b15; + LOGUART_GetChar = 0x6b49; + LOGUART_GetIMR = 0x6b65; + LOGUART_SetIMR = 0x6b71; + LOGUART_WaitBusy = 0x6b7d; + DIAG_UartInit = 0x6b9d; + DIAG_UartReInit = 0x6c25; + EFUSE_PowerSwitchROM = 0x6c49; + EFUSE_OneByteReadROM = 0x6d65; + EFUSE_OneByteWriteROM = 0x6e0d; + EFUSE_PG_Packet = 0x6e29; + EFUSE_LogicalMap_Read = 0x7091; + EFUSE_LogicalMap_Write = 0x71f5; + FLASH_SetSpiMode = 0x73dd; + FLASH_RxCmd = 0x7465; + FLASH_WaitBusy = 0x74cd; + FLASH_RxData = 0x754d; + FLASH_TxCmd = 0x75cd; + FLASH_WriteEn = 0x763d; + FLASH_TxData12B = 0x7661; + FLASH_SetStatus = 0x7735; + FLASH_Erase = 0x7755; + FLASH_DeepPowerDown = 0x77f5; + FLASH_SetStatusBits = 0x784d; + FLASH_Calibration = 0x791d; + FLASH_StructInit_Micron = 0x7a65; + FLASH_StructInit_MXIC = 0x7af5; + FLASH_StructInit_GD = 0x7b81; + FLASH_StructInit = 0x7c11; + FLASH_Init = 0x7ca1; + FLASH_ClockDiv = 0x7d15; + FLASH_CalibrationInit = 0x7d99; + FLASH_Calibration500MPSCmd = 0x7db1; + FLASH_CalibrationPhase = 0x7dcd; + FLASH_CalibrationPhaseIdx = 0x7e59; + FLASH_CalibrationNewCmd = 0x7e6d; + FLASH_CalibrationNew = 0x7ea9; + GDMA_StructInit = 0x80dd; + GDMA_SetLLP = 0x80f9; + GDMA_ClearINTPendingBit = 0x8191; + GDMA_ClearINT = 0x81d5; + GDMA_INTConfig = 0x8211; + GDMA_Cmd = 0x8259; + GDMA_Init = 0x828d; + GDMA_ChCleanAutoReload = 0x83c1; + GDMA_SetSrcAddr = 0x83f9; + GDMA_GetSrcAddr = 0x8411; + GDMA_GetDstAddr = 0x8429; + GDMA_SetDstAddr = 0x843d; + GDMA_SetBlkSize = 0x8459; + GDMA_GetBlkSize = 0x8489; + GDMA_ChnlRegister = 0x84a1; + GDMA_ChnlUnRegister = 0x8529; + GDMA_ChnlAlloc = 0x8591; + GDMA_ChnlFree = 0x8615; + GPIO_INTMode = 0x864d; + GPIO_INTConfig = 0x86e5; + GPIO_INTHandler = 0x8725; + GPIO_Direction = 0x8771; + GPIO_Init = 0x87a1; + GPIO_DeInit = 0x886d; + GPIO_ReadDataBit = 0x88c9; + GPIO_WriteBit = 0x88ed; + GPIO_PortDirection = 0x891d; + GPIO_PortRead = 0x893d; + GPIO_PortWrite = 0x894d; + GPIO_UserRegIrq = 0x8969; + I2C_StructInit = 0x899d; + I2C_SetSpeed = 0x89e5; + I2C_SetSlaveAddress = 0x8b3d; + I2C_CheckFlagState = 0x8b79; + I2C_INTConfig = 0x8bad; + I2C_ClearINT = 0x8be5; + I2C_ClearAllINT = 0x8c85; + I2C_Init = 0x8cad; + I2C_GetRawINT = 0x8dc9; + I2C_GetINT = 0x8df1; + I2C_MasterSendNullData = 0x8e19; + I2C_MasterSend = 0x8e65; + I2C_SlaveSend = 0x8ead; + I2C_ReceiveData = 0x8ed9; + I2C_MasterWrite = 0x8f05; + I2C_MasterReadDW = 0x8f89; + I2C_MasterRead = 0x9019; + I2C_SlaveWrite = 0x9089; + I2C_SlaveRead = 0x90f1; + I2C_MasterRepeatRead = 0x9141; + I2C_Cmd = 0x91c1; + I2C_PinMuxInit = 0x91fd; + I2C_PinMuxDeInit = 0x9255; + I2C_DMAControl = 0x92ad; + I2C_DmaMode1Config = 0x92e9; + I2C_DmaMode2Config = 0x9331; + I2C_TXGDMA_Init = 0x9375; + I2C_RXGDMA_Init = 0x9459; + I2C_Sleep_Cmd = 0x9521; + I2C_WakeUp = 0x95a1; + I2S_StructInit = 0x95e9; + I2S_Cmd = 0x9611; + I2S_TxDmaCmd = 0x962d; + I2S_RxDmaCmd = 0x9641; + I2S_INTConfig = 0x9655; + I2S_INTClear = 0x965d; + I2S_INTClearAll = 0x9665; + I2S_Init = 0x9671; + I2S_ISRGet = 0x97a9; + I2S_SetRate = 0x97b5; + I2S_SetWordLen = 0x9811; + I2S_SetChNum = 0x9839; + I2S_SetPageNum = 0x9861; + I2S_SetPageSize = 0x9895; + I2S_GetPageSize = 0x98a9; + I2S_SetDirection = 0x98b5; + I2S_SetDMABuf = 0x98dd; + I2S_TxPageBusy = 0x9905; + I2S_GetTxPage = 0x9911; + I2S_GetRxPage = 0x991d; + I2S_SetTxPageAddr = 0x9929; + I2S_GetTxPageAddr = 0x9939; + I2S_SetRxPageAddr = 0x9949; + I2S_GetRxPageAddr = 0x9959; + I2S_TxPageDMA_EN = 0x9969; + I2S_RxPageDMA_EN = 0x998d; + io_assert_failed = 0x99d9; + OTF_init = 0x99fd; + OTF_Cmd = 0x9a79; + OTF_Mask = 0x9a8d; + KEY_Request = 0x9add; + RDP_EN_Request = 0x9b21; + RCC_PeriphClockCmd = 0x9b65; + FUNC_HCI_COM = 0x9c95; + RTC_ByteToBcd2 = 0x9cad; + RTC_Bcd2ToByte = 0x9cc9; + RTC_ClokSource = 0x9cdd; + RTC_EnterInitMode = 0x9d19; + RTC_ExitInitMode = 0x9d51; + RTC_WaitForSynchro = 0x9d61; + RTC_BypassShadowCmd = 0x9da9; + RTC_StructInit = 0x9dd9; + RTC_Init = 0x9de5; + RTC_TimeStructInit = 0x9e7d; + RTC_SetTime = 0x9e8d; + RTC_GetTime = 0x9ff9; + RTC_SetAlarm = 0xa051; + RTC_AlarmStructInit = 0xa211; + RTC_GetAlarm = 0xa231; + RTC_AlarmCmd = 0xa2a1; + RTC_AlarmClear = 0xa2f5; + RTC_DayLightSavingConfig = 0xa305; + RTC_GetStoreOperation = 0xa355; + RTC_OutputConfig = 0xa365; + RTC_SmoothCalibConfig = 0xa39d; + SDIO_IsTimeout = 0xa459; + SDIOB_Init = 0xa481; + SDIOB_INTConfig = 0xa575; + SDIOB_DeInit = 0xa591; + SDIOB_H2C_WriteMem = 0xa5d9; + SDIOB_H2C_SetMem = 0xa605; + SDIOB_H2C_DataHandle = 0xa631; + SDIOB_H2C_DataReady = 0xa73d; + SDIOB_IRQ_Handler_BH = 0xa80d; + SDIOB_H2C_Task = 0xa8c9; + SDIO_Boot_Up = 0xa8e5; + SPI_DmaInit = 0xa91d; + SPI_DataHandle = 0xa9d1; + SPI_Boot_DmaRxIrqHandle = 0xaa01; + SPI_Boot_ROM = 0xaa5d; + SSI_StructInit = 0xabbd; + SSI_Cmd = 0xabf5; + SSI_INTConfig = 0xac09; + SSI_SetSclkPolarity = 0xac19; + SSI_SetSclkPhase = 0xac3d; + SSI_SetDataFrameSize = 0xac61; + SSI_SetReadLen = 0xac81; + SSI_SetBaudDiv = 0xacb1; + SSI_SetBaud = 0xaccd; + SSI_SetDmaEnable = 0xad2d; + SSI_SetDmaLevel = 0xad41; + SSI_SetIsrClean = 0xad49; + SSI_WriteData = 0xad65; + SSI_SetRxFifoLevel = 0xad6d; + SSI_SetTxFifoLevel = 0xad71; + SSI_ReadData = 0xad75; + SSI_GetRxCount = 0xad79; + SSI_GetTxCount = 0xad81; + SSI_GetStatus = 0xad89; + SSI_Writeable = 0xad8d; + SSI_Readable = 0xad9d; + SSI_GetDataFrameSize = 0xadad; + SSI_TXGDMA_Init = 0xadb9; + SSI_RXGDMA_Init = 0xaef9; + SSI_ReceiveData = 0xb021; + SSI_SendData = 0xb0b9; + SSI_Busy = 0xb165; + SSI_SetSlaveEnable = 0xb175; + SSI_Init = 0xb1ad; + SSI_GetIsr = 0xb235; + SSI_GetRawIsr = 0xb239; + SSI_GetSlaveEnable = 0xb23d; + SSI_PinmuxInit = 0xb241; + SSI_PinmuxDeInit = 0xb2a9; + SYSCFG0_Get = 0xb311; + SYSCFG0_CUTVersion = 0xb31d; + SYSCFG0_BDOption = 0xb32d; + SYSCFG1_Get = 0xb33d; + SYSCFG1_AutoLoadDone = 0xb349; + SYSCFG1_TRP_LDOMode = 0xb359; + SYSCFG1_TRP_UARTImage = 0xb369; + SYSCFG1_TRP_ICFG = 0xb37d; + SYSCFG2_Get = 0xb389; + SYSCFG2_ROMINFO_Get = 0xb395; + SYSCFG2_ROMINFO_Set = 0xb3a1; + RTIM_TimeBaseStructInit = 0xb3b5; + RTIM_Cmd = 0xb3cd; + RTIM_GetCount = 0xb42d; + RTIM_UpdateDisableConfig = 0xb475; + RTIM_ARRPreloadConfig = 0xb4c5; + RTIM_UpdateRequestConfig = 0xb515; + RTIM_PrescalerConfig = 0xb575; + RTIM_GenerateEvent = 0xb5a1; + RTIM_ChangePeriod = 0xb5f9; + RTIM_Reset = 0xb64d; + RTIM_CCStructInit = 0xb68d; + RTIM_CCxInit = 0xb6a1; + RTIM_CCRxMode = 0xb749; + RTIM_CCRxSet = 0xb785; + RTIM_CCRxGet = 0xb7dd; + RTIM_OCxPreloadConfig = 0xb80d; + RTIM_CCxPolarityConfig = 0xb85d; + RTIM_CCxCmd = 0xb8ad; + RTIM_SetOnePulseOutputMode = 0xb901; + RTIM_DMACmd = 0xb959; + RTIM_TXGDMA_Init = 0xb9a9; + RTIM_RXGDMA_Init = 0xba5d; + RTIM_INTConfig = 0xbb3d; + RTIM_INTClear = 0xbba9; + RTIM_TimeBaseInit = 0xbbed; + RTIM_DeInit = 0xbced; + RTIM_INTClearPendingBit = 0xbd41; + RTIM_GetFlagStatus = 0xbd81; + RTIM_GetINTStatus = 0xbded; + UART_DeInit = 0xbe61; + UART_StructInit = 0xbe69; + UART_BaudParaGet = 0xbe81; + UART_BaudParaGetFull = 0xbec9; + UART_SetBaud = 0xbf01; + UART_SetBaudExt = 0xbf71; + UART_SetRxLevel = 0xbfc1; + UART_RxCmd = 0xbfe9; + UART_Writable = 0xbffd; + UART_Readable = 0xc005; + UART_CharPut = 0xc00d; + UART_CharGet = 0xc011; + UART_ReceiveData = 0xc019; + UART_SendData = 0xc041; + UART_ReceiveDataTO = 0xc069; + UART_SendDataTO = 0xc0a9; + UART_RxByteCntClear = 0xc0e9; + UART_RxByteCntGet = 0xc0f5; + UART_BreakCtl = 0xc0fd; + UART_ClearRxFifo = 0xc111; + UART_Init = 0xc135; + UART_ClearTxFifo = 0xc1d1; + UART_INTConfig = 0xc1dd; + UART_IntStatus = 0xc1ed; + UART_ModemStatusGet = 0xc1f1; + UART_LineStatusGet = 0xc1f5; + UART_WaitBusy = 0xc1f9; + UART_PinMuxInit = 0xc221; + UART_PinMuxDeinit = 0xc289; + UART_TXDMAConfig = 0xc2f1; + UART_RXDMAConfig = 0xc301; + UART_TXDMACmd = 0xc315; + UART_RXDMACmd = 0xc329; + UART_TXGDMA_Init = 0xc33d; + UART_RXGDMA_Init = 0xc425; + UART_LPRxStructInit = 0xc501; + UART_LPRxInit = 0xc50d; + UART_LPRxBaudSet = 0xc575; + UART_LPRxMonitorCmd = 0xc5f1; + UART_LPRxpathSet = 0xc62d; + UART_LPRxIPClockSet = 0xc641; + UART_LPRxCmd = 0xc6b1; + UART_LPRxMonBaudCtrlRegGet = 0xc6c5; + UART_LPRxMonitorSatusGet = 0xc6c9; + UART_IrDAStructInit = 0xc6cd; + UART_IrDAInit = 0xc6e5; + UART_IrDACmd = 0xc7bd; + INT_SysOn = 0xc7d1; + INT_Wdg = 0xc811; + INT_Timer0 = 0xc855; + INT_Timer1 = 0xc899; + INT_Timer2 = 0xc8dd; + INT_Timer3 = 0xc921; + INT_SPI0 = 0xc965; + INT_GPIO = 0xc9a9; + INT_Uart0 = 0xc9ed; + INT_SPIFlash = 0xca31; + INT_Uart1 = 0xca75; + INT_Timer4 = 0xcab9; + INT_I2S0 = 0xcafd; + INT_Timer5 = 0xcb41; + INT_WlDma = 0xcb85; + INT_WlProtocol = 0xcbc9; + INT_IPSEC = 0xcc0d; + INT_SPI1 = 0xcc51; + INT_Peripheral = 0xcc95; + INT_Gdma0Ch0 = 0xccd9; + INT_Gdma0Ch1 = 0xcd1d; + INT_Gdma0Ch2 = 0xcd61; + INT_Gdma0Ch3 = 0xcda5; + INT_Gdma0Ch4 = 0xcde9; + INT_Gdma0Ch5 = 0xce2d; + INT_I2C0 = 0xce71; + INT_I2C1 = 0xceb5; + INT_Uartlog = 0xcef9; + INT_ADC = 0xcf3d; + INT_RDP = 0xcf81; + INT_RTC = 0xcfc5; + INT_Gdma1Ch0 = 0xd009; + INT_Gdma1Ch1 = 0xd051; + INT_Gdma1Ch2 = 0xd099; + INT_Gdma1Ch3 = 0xd0e1; + INT_Gdma1Ch4 = 0xd129; + INT_Gdma1Ch5 = 0xd171; + INT_USB = 0xd1b9; + INT_RXI300 = 0xd201; + INT_USB_SIE = 0xd249; + INT_SdioD = 0xd291; + INT_NMI = 0xd2d1; + INT_HardFault = 0xd305; + INT_MemManage = 0xd4b5; + INT_BusFault = 0xd4d5; + INT_UsageFault = 0xd4f5; + VECTOR_TableInit = 0xd515; + VECTOR_TableInitForOS = 0xd6c5; + VECTOR_IrqRegister = 0xd6d5; + VECTOR_IrqUnRegister = 0xd6f9; + VECTOR_IrqEn = 0xd715; + VECTOR_IrqDis = 0xd765; + WDG_Scalar = 0xd7a1; + WDG_Init = 0xd7e1; + WDG_IrqClear = 0xd7fd; + WDG_IrqInit = 0xd80d; + WDG_Cmd = 0xd83d; + WDG_Refresh = 0xd85d; + _strncpy = 0xd86d; + _strcpy = 0xd889; + prvStrCpy = 0xd899; + _strlen = 0xd8b1; + _strnlen = 0xd8c9; + prvStrLen = 0xd8fd; + _strcmp = 0xd919; + _strncmp = 0xd939; + prvStrCmp = 0xd985; + StrUpr = 0xd9b5; + prvAtoi = 0xd9d1; + prvStrtok = 0xda29; + prvStrStr = 0xda81; + _strsep = 0xdab9; + skip_spaces = 0xdaf5; + skip_atoi = 0xdb11; + _parse_integer_fixup_radix = 0xdb49; + _parse_integer = 0xdb9d; + simple_strtoull = 0xdc01; + simple_strtoll = 0xdc21; + simple_strtoul = 0xdc41; + simple_strtol = 0xdc49; + _vsscanf = 0xdc61; + _sscanf = 0xe1c9; + div_u64 = 0xe1e5; + div_s64 = 0xe1ed; + div_u64_rem = 0xe1f5; + div_s64_rem = 0xe205; + _strpbrk = 0xe215; + _strchr = 0xe241; + COMMPORT_GET_T = 0xe259; + COMMPORT_CLEAN_RX = 0xe289; + xModemDebugInit = 0xe2a5; + xModemDebug = 0xe2dd; + xModemInquiry = 0xe315; + xModemGetFirst = 0xe339; + xModemGetOthers = 0xe45d; + xModemRxFrame = 0xe691; + xModemHandshake = 0xe6d5; + xModemRxBuffer = 0xe945; + xmodem_log_close = 0xe9f5; + xmodem_log_open = 0xea01; + xmodem_uart_init = 0xea39; + xmodem_uart_deinit = 0xeb25; + xmodem_uart_port_init = 0xeb35; + xmodem_uart_port_deinit = 0xeb99; + xmodem_uart_readable = 0xebdd; + xmodem_uart_writable = 0xebf5; + xmodem_uart_getc = 0xec0d; + xmodem_uart_putc = 0xec35; + xmodem_uart_putdata = 0xec49; + aes_set_key = 0xec65; + aes_encrypt = 0xf021; + aes_decrypt = 0x10171; + AES_WRAP = 0x112b1; + AES_UnWRAP = 0x113fd; + crc32_get = 0x11549; + arc4_byte = 0x1157d; + rt_arc4_init = 0x115a5; + rt_arc4_crypt = 0x115e9; + rt_md5_init = 0x11df5; + rt_md5_append = 0x11e25; + rt_md5_final = 0x11ec9; + rt_md5_hmac = 0x11f21; + RC4 = 0x12061; + RC4_set_key = 0x1238d; + ROM_WIFI_ReadPowerValue = 0x1246d; + ROM_WIFI_EfuseParseTxPowerInfo = 0x1251d; + ROM_WIFI_8051Reset = 0x125c5; + ROM_WIFI_FWDownloadEnable = 0x125dd; + ROM_WIFI_BlockWrite = 0x12619; + ROM_WIFI_PageWrite = 0x12661; + ROM_WIFI_FillDummy = 0x12685; + ROM_WIFI_WriteFW = 0x126b1; + ROM_WIFI_FWFreeToGo = 0x1275d; + ROM_WIFI_InitLLTTable = 0x127f9; + ROM_WIFI_GetChnlGroup = 0x12879; + ROM_WIFI_BWMapping = 0x129f1; + ROM_WIFI_SCMapping = 0x12a19; + ROM_WIFI_FillTxdescSectype = 0x12a99; + ROM_WIFI_FillFakeTxdesc = 0x12ab9; + ROM_WIFI_32K_Cmd = 0x12b91; + ROM_WIFI_DISCONNECT = 0x12bc1; + ROM_WIFI_SET_TSF = 0x12bfd; + ROM_WIFI_BCN_FUNC = 0x12ca5; + ROM_WIFI_BSSID_SET = 0x12ccd; + ROM_WIFI_MACADDR_SET = 0x12d09; + ROM_WIFI_EnableInterrupt = 0x12d39; + ROM_WIFI_DisableInterrupt = 0x12d4d; + ROM_WIFI_RESUME_TxBeacon = 0x12d61; + ROM_WIFI_STOP_TXBeacon = 0x12d91; + ROM_WIFI_BCN_Interval = 0x12dc1; + ROM_WIFI_BCN_FUNC_Enable = 0x12dcd; + ROM_WIFI_INIT_BeaconParameters = 0x12de5; + ROM_WIFI_MEDIA_STATUS1 = 0x12e35; + ROM_WIFI_MEDIA_STATUS = 0x12e4d; + ROM_WIFI_SetBrateCfg = 0x12e61; + ROM_WIFI_BASIC_RATE = 0x12f69; + ROM_WIFI_CHECK_BSSID = 0x12fc9; + ROM_WIFI_RESP_SIFS = 0x12fe9; + ROM_WIFI_CAM_WRITE = 0x13001; + ROM_WIFI_ACM_CTRL = 0x13021; + ROM_WIFI_FIFO_CLEARN_UP = 0x13051; + ROM_WIFI_CHECK_TXBUF = 0x130b9; + ROM_WIFI_BCN_VALID = 0x130fd; + ROM_WIFI_PROMISC_Cmd = 0x13119; + ROM_WIFI_SetOpmodeAP = 0x13189; + ROM_WIFI_ReadChipVersion = 0x132a9; + ROM_WIFI_DumpChipInfo = 0x1330d; + ROM_WIFI_InitLxDma = 0x135b1; + ROM_WIFI_InitQueueReservedPage = 0x13671; + ROM_WIFI_InitTxBufferBoundary = 0x136f1; + ROM_WIFI_InitNormalChipRegPriority = 0x1373d; + ROM_WIFI_InitPageBoundary = 0x13789; + ROM_WIFI_InitTransferPageSize = 0x13795; + ROM_WIFI_InitDriverInfoSize = 0x137a1; + ROM_WIFI_InitNetworkType = 0x137ad; + ROM_WIFI_InitRCR = 0x137c5; + ROM_WIFI_InitAdaptiveCtrl = 0x13805; + ROM_WIFI_InitSIFS = 0x1383d; + ROM_WIFI_InitEDCA = 0x13865; + ROM_WIFI_InitRateFallback = 0x138a1; + ROM_WIFI_InitRetryFunction = 0x138c9; + ROM_WIFI_InitOperationMode = 0x138e5; + ROM_WIFI_InitBurstPktLen = 0x138f9; + phy_CalculateBitShift = 0x13905; + PHY_SetBBReg_8711B = 0x1391d; + PHY_QueryBBReg_8711B = 0x13921; + ROM_odm_QueryRxPwrPercentage = 0x13925; + ROM_odm_EVMdbToPercentage = 0x13931; + ROM_odm_SignalScaleMapping_8711B = 0x13935; + ROM_odm_FalseAlarmCounterStatistics = 0x13a11; + ROM_odm_SetEDCCAThreshold = 0x13d39; + ROM_odm_SetTRxMux = 0x13d61; + ROM_odm_SetCrystalCap = 0x13d89; + ROM_odm_GetDefaultCrytaltalCap = 0x13ded; + ROM_ODM_CfoTrackingReset = 0x13dfd; + ROM_odm_CfoTrackingFlow = 0x13e21; + rtw_get_bit_value_from_ieee_value = 0x14045; + rtw_is_cckrates_included = 0x14071; + rtw_is_cckratesonly_included = 0x140a5; + rtw_check_network_type = 0x140cd; + rtw_set_fixed_ie = 0x14155; + rtw_set_ie = 0x14175; + rtw_get_ie = 0x141a1; + rtw_set_supported_rate = 0x141b5; + rtw_get_rateset_len = 0x14229; + rtw_get_wpa_ie = 0x14245; + rtw_get_wpa2_ie = 0x142d1; + rtw_get_wpa_cipher_suite = 0x142e5; + rtw_get_wpa2_cipher_suite = 0x1434d; + rtw_parse_wpa_ie = 0x143b5; + rtw_parse_wpa2_ie = 0x14481; + rtw_get_sec_ie = 0x14535; + rtw_get_wps_ie = 0x145e5; + rtw_get_wps_attr = 0x14659; + rtw_get_wps_attr_content = 0x146f1; + rtw_ieee802_11_parse_elems = 0x14739; + str_2char2num = 0x14909; + key_2char2num = 0x14925; + convert_ip_addr = 0x1493d; + rom_psk_PasswordHash = 0x14a21; + rom_psk_CalcGTK = 0x14a59; + rom_psk_CalcPTK = 0x14ae9; + _htons_rom = 0x14bdd; + _ntohs_rom = 0x14be5; + _htonl_rom = 0x14bed; + _ntohl_rom = 0x14bf1; + Message_ReplayCounter_OC2LI = 0x14bf5; + Message_EqualReplayCounter = 0x14c35; + Message_SmallerEqualReplayCounter = 0x14c6d; + Message_LargerReplayCounter = 0x14cad; + Message_setReplayCounter = 0x14ce5; + INCLargeInteger = 0x14d15; + INCOctet16_INTEGER = 0x14d25; + INCOctet32_INTEGER = 0x14d8d; + SetEAPOL_KEYIV = 0x14df5; + CheckMIC = 0x14e89; + CalcMIC = 0x14f29; + DecWPA2KeyData_rom = 0x14f9d; + DecGTK = 0x15055; + GetRandomBuffer = 0x15119; + GenNonce = 0x15181; + ClientConstructEAPOL_2Of4Way = 0x151c5; + ClientConstructEAPOL_4Of4Way = 0x152cd; + ClientConstructEAPOL_2Of2Way = 0x1537d; + ClientConstructEAPOL_MICOf2Way = 0x15459; + psk_strip_rsn_pairwise = 0x1552d; + psk_strip_wpa_pairwise = 0x155c1; + wep_80211_encrypt = 0x1587d; + wep_80211_decrypt = 0x158e1; + tkip_micappendbyte = 0x15975; + rtw_secmicsetkey = 0x159b9; + rtw_secmicappend = 0x159f9; + rtw_secgetmic = 0x15a15; + rtw_seccalctkipmic = 0x15a89; + tkip_phase1 = 0x15b7d; + tkip_phase2 = 0x15ce5; + tkip_80211_encrypt = 0x15f01; + tkip_80211_decrypt = 0x15f91; + aes1_encrypt = 0x16055; + aesccmp_construct_mic_iv = 0x1625d; + aesccmp_construct_mic_header1 = 0x162b1; + aesccmp_construct_mic_header2 = 0x16321; + aesccmp_construct_ctr_preload = 0x163a5; + aes_80211_encrypt = 0x16429; + aes_80211_decrypt = 0x167f9; + cckrates_included = 0x16c39; + cckratesonly_included = 0x16c7d; + networktype_to_raid_ex_rom = 0x16ca9; + judge_network_type_rom = 0x16cf5; + ratetbl_val_2wifirate = 0x16d89; + is_basicrate_rom = 0x16d9d; + ratetbl2rateset_rom = 0x16dd5; + get_rate_set_rom = 0x16e3d; + UpdateBrateTbl_rom = 0x16e71; + UpdateBrateTblForSoftAP = 0x16ec9; + write_cam_rom = 0x16f0d; + HT_caps_handler_rom = 0x16fc1; + wifirate2_ratetbl_inx = 0x17015; + update_basic_rate = 0x170bd; + update_supported_rate = 0x170f5; + update_MCS_rate = 0x17125; + get_highest_rate_idx = 0x17131; + _sha1_process_message_block = 0x1714d; + _sha1_pad_message = 0x172d1; + rt_sha1_init = 0x1736d; + rt_sha1_update = 0x173b1; + rt_sha1_finish = 0x17429; + rt_hmac_sha1 = 0x17489; + rom_aes_128_cbc_encrypt = 0x175e5; + rom_aes_128_cbc_decrypt = 0x17669; + rom_rijndaelKeySetupEnc = 0x176ed; + rom_aes_decrypt_init = 0x177c1; + rom_aes_internal_decrypt = 0x17899; + rom_aes_decrypt_deinit = 0x17bdd; + rom_aes_encrypt_init = 0x17be9; + rom_aes_internal_encrypt = 0x17c01; + rom_aes_encrypt_deinit = 0x17f81; + bignum_init = 0x1963d; + bignum_deinit = 0x19665; + bignum_get_unsigned_bin_len = 0x19685; + bignum_get_unsigned_bin = 0x19689; + bignum_set_unsigned_bin = 0x19741; + bignum_cmp = 0x197f9; + bignum_cmp_d = 0x197fd; + bignum_add = 0x19825; + bignum_sub = 0x19835; + bignum_mul = 0x19845; + bignum_exptmod = 0x19855; + WPS_realloc = 0x19879; + os_zalloc = 0x198bd; + rom_hmac_sha256_vector = 0x198e1; + rom_hmac_sha256 = 0x199e1; + rom_sha256_vector = 0x19b3d; + CRYPTO_chacha_20 = 0x19d45; + rom_ed25519_gen_keypair = 0x1a1bd; + rom_ed25519_gen_signature = 0x1a1c1; + rom_ed25519_verify_signature = 0x1a1d9; + rom_ed25519_ge_double_scalarmult_vartime = 0x1c4c9; + rom_ed25519_ge_frombytes_negate_vartime = 0x1c8c1; + rom_ed25519_ge_p3_tobytes = 0x1d43d; + rom_ed25519_ge_scalarmult_base = 0x1d489; + rom_ed25519_ge_tobytes = 0x1d64d; + rom_ed25519_crypto_sign_seed_keypair = 0x1d699; + rom_ed25519_crypto_sign_verify_detached = 0x1d6f1; + rom_ed25519_sc_muladd = 0x1d9e5; + rom_ed25519_sc_reduce = 0x24175; + rom_ed25519_crypto_sign_detached = 0x26c25; + CRYPTO_poly1305_init = 0x270dd; + CRYPTO_poly1305_update = 0x271b5; + CRYPTO_poly1305_finish = 0x27245; + rom_sha512_starts = 0x28511; + rom_sha512_update = 0x28659; + rom_sha512_finish = 0x28661; + rom_sha512 = 0x288a9; + rom_sha512_hmac_starts = 0x288e1; + rom_sha512_hmac_update = 0x289a5; + rom_sha512_hmac_finish = 0x289ad; + rom_sha512_hmac_reset = 0x289fd; + rom_sha512_hmac = 0x28a19; + rom_sha512_hkdf = 0x28a51; + aes_test_alignment_detection = 0x28b59; + aes_mode_reset = 0x28bbd; + aes_ecb_encrypt = 0x28bc9; + aes_ecb_decrypt = 0x28c05; + aes_cbc_encrypt = 0x28c41; + aes_cbc_decrypt = 0x28dad; + aes_cfb_encrypt = 0x28f49; + aes_cfb_decrypt = 0x2920d; + aes_ofb_crypt = 0x294d5; + aes_ctr_crypt = 0x29769; + aes_encrypt_key128 = 0x29a79; + aes_encrypt_key192 = 0x29a95; + aes_encrypt_key256 = 0x29ab1; + aes_encrypt_key = 0x29ad1; + aes_decrypt_key128 = 0x29b41; + aes_decrypt_key192 = 0x29b5d; + aes_decrypt_key256 = 0x29b79; + aes_decrypt_key = 0x29b99; + aes_init = 0x29c09; + curve25519_donna = 0x2a939; + __rtl_dtoa_r_v1_00 = 0x2b7f1; + __rtl_ltoa_v1_00 = 0x2c7f9; + __rtl_ultoa_v1_00 = 0x2c885; + __rtl_dtoi_v1_00 = 0x2c8ed; + __rtl_dtoi64_v1_00 = 0x2c96d; + __rtl_dtoui_v1_00 = 0x2ca09; + __rtl_ftol_v1_00 = 0x2ca11; + __rtl_itof_v1_00 = 0x2ca75; + __rtl_itod_v1_00 = 0x2cb05; + __rtl_i64tod_v1_00 = 0x2cb71; + __rtl_uitod_v1_00 = 0x2cc4d; + __rtl_ftod_v1_00 = 0x2cd29; + __rtl_dtof_v1_00 = 0x2cde1; + __rtl_uitof_v1_00 = 0x2ce75; + __rtl_fadd_v1_00 = 0x2cf59; + __rtl_fsub_v1_00 = 0x2d259; + __rtl_fmul_v1_00 = 0x2d565; + __rtl_fdiv_v1_00 = 0x2d695; + __rtl_dadd_v1_00 = 0x2d809; + __rtl_dsub_v1_00 = 0x2de49; + __rtl_dmul_v1_00 = 0x2e4a1; + __rtl_ddiv_v1_00 = 0x2e7dd; + __rtl_dcmpeq_v1_00 = 0x2ed71; + __rtl_dcmplt_v1_00 = 0x2eded; + __rtl_dcmpgt_v1_00 = 0x2ee85; + __rtl_dcmple_v1_00 = 0x2ef95; + __rtl_fcmplt_v1_00 = 0x2f0a9; + __rtl_fcmpgt_v1_00 = 0x2f105; + __rtl_fpclassifyd = 0x2f1ad; + __rtl_close_v1_00 = 0x2f205; + __rtl_fstat_v1_00 = 0x2f219; + __rtl_isatty_v1_00 = 0x2f22d; + __rtl_lseek_v1_00 = 0x2f23d; + __rtl_open_v1_00 = 0x2f251; + __rtl_read_v1_00 = 0x2f265; + __rtl_write_v1_00 = 0x2f279; + __rtl_sbrk_v1_00 = 0x2f28d; + __rom_mallocr_init_v1_00 = 0x2f29d; + __rtl_free_r_v1_00 = 0x2f309; + __rtl_malloc_r_v1_00 = 0x2f521; + __rtl_realloc_r_v1_00 = 0x2f9f5; + __rtl_memalign_r_v1_00 = 0x2fdb5; + __rtl_valloc_r_v1_00 = 0x2fe81; + __rtl_pvalloc_r_v1_00 = 0x2fe8d; + __rtl_calloc_r_v1_00 = 0x2fea1; + __rtl_cfree_r_v1_00 = 0x2ff05; + __rtl_cos_f32_v1_00 = 0x2ff15; + __rtl_sin_f32_v1_00 = 0x300e9; + __rtl_fabs_v1_00 = 0x302ad; + __rtl_fabsf_v1_00 = 0x302b5; + __rtl_memchr_v1_00 = 0x302bd; + __rtl_memcmp_v1_00 = 0x30351; + __rtl_memcpy_v1_00 = 0x303b5; + __rtl_memmove_v1_00 = 0x3045d; + __rtl_memset_v1_00 = 0x30525; + __rtl_Balloc_v1_00 = 0x3061d; + __rtl_Bfree_v1_00 = 0x3066d; + __rtl_i2b_v1_00 = 0x30681; + __rtl_multadd_v1_00 = 0x30695; + __rtl_mult_v1_00 = 0x30721; + __rtl_pow5mult_v1_00 = 0x30855; + __rtl_hi0bits_v1_00 = 0x308f5; + __rtl_d2b_v1_00 = 0x30935; + __rtl_lshift_v1_00 = 0x309ed; + __rtl_cmp_v1_00 = 0x30a99; + __rtl_diff_v1_00 = 0x30ae1; + __rtl_sread_v1_00 = 0x30bb5; + __rtl_seofread_v1_00 = 0x30c01; + __rtl_swrite_v1_00 = 0x30c05; + __rtl_sseek_v1_00 = 0x30c75; + __rtl_sclose_v1_00 = 0x30cc1; + __rtl_sbrk_r_v1_00 = 0x30ced; + __rtl_strcat_v1_00 = 0x30d15; + __rtl_strchr_v1_00 = 0x30d59; + __rtl_strcmp_v1_00 = 0x30e25; + __rtl_strcpy_v1_00 = 0x30e99; + __rtl_strlen_v1_00 = 0x30ee5; + __rtl_strncat_v1_00 = 0x30f39; + __rtl_strncmp_v1_00 = 0x30f95; + __rtl_strncpy_v1_00 = 0x3102d; + __rtl_strsep_v1_00 = 0x31095; + __rtl_strstr_v1_00 = 0x3136d; + __rtl_strtok_v1_00 = 0x315a5; + __rtl__strtok_r_v1_00 = 0x315b5; + __rtl_strtok_r_v1_00 = 0x31619; + __rtl_fflush_r_v1_00 = 0x31ae9; + __rtl_vfprintf_r_v1_00 = 0x31f99; + polarssl_aes_init = 0x335b9; + aes_free = 0x335c9; + aes_setkey_enc = 0x335dd; + aes_setkey_dec = 0x33829; + aes_crypt_ecb = 0x339a1; + aes_crypt_cbc = 0x343d1; + aes_crypt_cfb128 = 0x34649; + aes_crypt_cfb8 = 0x346c9; + aes_crypt_ctr = 0x3474d; + arc4_init = 0x347b1; + arc4_free = 0x347bd; + arc4_setup = 0x347d1; + arc4_crypt = 0x3481d; + asn1_get_len = 0x34861; + asn1_get_tag = 0x34901; + asn1_get_bool = 0x34929; + asn1_get_int = 0x3495d; + asn1_get_mpi = 0x349a9; + asn1_get_bitstring = 0x349d1; + asn1_get_bitstring_null = 0x34a19; + asn1_get_sequence_of = 0x34a4d; + asn1_get_alg = 0x34ad1; + asn1_get_alg_null = 0x34b65; + asn1_free_named_data = 0x34ba5; + asn1_free_named_data_list = 0x34bcd; + asn1_find_named_data = 0x34bf5; + asn1_write_len = 0x34c25; + asn1_write_tag = 0x34c8d; + asn1_write_raw_buffer = 0x34ca9; + asn1_write_mpi = 0x34ccd; + asn1_write_null = 0x34d41; + asn1_write_oid = 0x34d6d; + asn1_write_algorithm_identifier = 0x34dc5; + asn1_write_bool = 0x34e21; + asn1_write_int = 0x34e65; + asn1_write_printable_string = 0x34ecd; + asn1_write_ia5_string = 0x34f25; + asn1_write_bitstring = 0x34f7d; + asn1_write_octet_string = 0x34fe5; + asn1_store_named_data = 0x3503d; + base64_encode = 0x35111; + base64_decode = 0x3523d; + mpi_init = 0x35e09; + mpi_free = 0x35e19; + mpi_grow = 0x35e55; + mpi_shrink = 0x35e79; + mpi_copy = 0x35f21; + mpi_swap = 0x35fa1; + mpi_safe_cond_assign = 0x35fcd; + mpi_safe_cond_swap = 0x36069; + mpi_lset = 0x3610d; + mpi_get_bit = 0x3614d; + mpi_set_bit = 0x3616d; + mpi_lsb = 0x361d5; + mpi_msb = 0x36215; + mpi_size = 0x36261; + mpi_read_binary = 0x3626d; + mpi_write_binary = 0x362f9; + mpi_shift_l = 0x36341; + mpi_shift_r = 0x363f1; + mpi_cmp_abs = 0x36475; + mpi_cmp_mpi = 0x36619; + mpi_cmp_int = 0x366f1; + mpi_add_abs = 0x3671d; + mpi_sub_abs = 0x3680d; + mpi_add_mpi = 0x3689d; + mpi_sub_mpi = 0x368ed; + mpi_add_int = 0x3693d; + mpi_sub_int = 0x36969; + mpi_mul_mpi = 0x36995; + mpi_read_string = 0x36ac5; + mpi_mul_int = 0x36c45; + mpi_div_mpi = 0x36c61; + mpi_div_int = 0x370ed; + mpi_mod_mpi = 0x37119; + mpi_mod_int = 0x3717d; + mpi_write_string = 0x3722d; + mpi_exp_mod = 0x37395; + mpi_gcd = 0x37915; + mpi_fill_random = 0x37a39; + mpi_inv_mod = 0x37c4d; + mpi_is_prime = 0x37f15; + mpi_gen_prime = 0x37f71; + ctr_drbg_free = 0x38285; + ctr_drbg_set_prediction_resistance = 0x382a1; + ctr_drbg_set_entropy_len = 0x382a5; + ctr_drbg_set_reseed_interval = 0x382a9; + ctr_drbg_update = 0x382ad; + ctr_drbg_reseed = 0x382c9; + ctr_drbg_init_entropy_len = 0x38341; + ctr_drbg_init = 0x38399; + ctr_drbg_random_with_add = 0x383ad; + ctr_drbg_random = 0x38469; + des_init = 0x388a5; + des_free = 0x388b1; + des3_init = 0x388c5; + des3_free = 0x388d5; + des_key_set_parity = 0x388e9; + des_key_check_key_parity = 0x38909; + des_key_check_weak = 0x38939; + des_setkey_enc = 0x38965; + des_setkey_dec = 0x3898d; + des3_set2key_enc = 0x389d9; + des3_set2key_dec = 0x38a25; + des3_set3key_enc = 0x38a71; + des3_set3key_dec = 0x38ab1; + des_crypt_ecb = 0x38af1; + des_crypt_cbc = 0x38d09; + des3_crypt_ecb = 0x38f99; + des3_crypt_cbc = 0x39401; + dhm_init = 0x39729; + dhm_read_params = 0x39731; + dhm_make_params = 0x3978d; + dhm_read_public = 0x398c1; + dhm_make_public = 0x398e9; + dhm_calc_secret = 0x399ad; + dhm_free = 0x39ba1; + dhm_parse_dhm = 0x39c01; + ecdh_gen_public = 0x39cc5; + ecdh_compute_shared = 0x39cc9; + ecdh_init = 0x39d2d; + ecdh_free = 0x39d39; + ecdh_make_params = 0x39d81; + ecdh_read_params = 0x39e05; + ecdh_get_params = 0x39e2d; + ecdh_make_public = 0x39e79; + ecdh_read_public = 0x39ed1; + ecdh_calc_secret = 0x39f01; + ecdsa_sign = 0x3a041; + ecdsa_sign_det = 0x3a1c5; + ecdsa_verify = 0x3a2a9; + ecdsa_write_signature = 0x3a431; + ecdsa_write_signature_det = 0x3a46d; + ecdsa_read_signature = 0x3a4a5; + ecdsa_genkey = 0x3a531; + ecdsa_init = 0x3a565; + ecdsa_free = 0x3a591; + ecdsa_from_keypair = 0x3a5bd; + ecp_curve_list = 0x3aee5; + ecp_curve_info_from_grp_id = 0x3aeed; + ecp_curve_info_from_tls_id = 0x3af0d; + ecp_curve_info_from_name = 0x3af31; + ecp_point_init = 0x3af61; + ecp_group_init = 0x3af81; + ecp_keypair_init = 0x3af8d; + ecp_point_free = 0x3afb1; + ecp_group_free = 0x3afd1; + ecp_keypair_free = 0x3b03d; + ecp_copy = 0x3b05d; + ecp_group_copy = 0x3b08d; + ecp_set_zero = 0x3b095; + ecp_is_zero = 0x3ba61; + ecp_point_read_string = 0x3ba75; + ecp_point_write_binary = 0x3baa5; + ecp_point_read_binary = 0x3bb4d; + ecp_tls_read_point = 0x3bbc1; + ecp_tls_write_point = 0x3bbf5; + ecp_group_read_string = 0x3bc25; + ecp_tls_read_group = 0x3bc95; + ecp_tls_write_group = 0x3bcf1; + ecp_add = 0x3bd39; + ecp_sub = 0x3bd65; + ecp_check_pubkey = 0x3bddd; + ecp_check_privkey = 0x3bf8d; + ecp_mul = 0x3bff5; + ecp_gen_keypair = 0x3c565; + ecp_gen_key = 0x3c669; + ecp_use_known_dp = 0x3d741; + hmac_drbg_update = 0x3daa9; + hmac_drbg_init_buf = 0x3db41; + hmac_drbg_reseed = 0x3db91; + hmac_drbg_init = 0x3dc09; + hmac_drbg_set_prediction_resistance = 0x3dc81; + hmac_drbg_set_entropy_len = 0x3dc85; + hmac_drbg_set_reseed_interval = 0x3dc89; + hmac_drbg_random_with_add = 0x3dc8d; + hmac_drbg_random = 0x3dd4d; + hmac_drbg_free = 0x3dd61; + md_list = 0x3dd7d; + md_info_from_string = 0x3dd85; + md_info_from_type = 0x3de59; + md_init = 0x3de9d; + md_free = 0x3dea5; + md_init_ctx = 0x3dec5; + md_free_ctx = 0x3defd; + md_starts = 0x3df09; + md_update = 0x3df29; + md_finish = 0x3df49; + md = 0x3df69; + md_file = 0x3df89; + md_hmac_starts = 0x3dfa1; + md_hmac_update = 0x3dfc1; + md_hmac_finish = 0x3dfe1; + md_hmac_reset = 0x3e001; + md_hmac = 0x3e021; + md_process = 0x3e049; + md5_init = 0x3e301; + md5_free = 0x3e309; + md5_starts = 0x3e31d; + md5_process = 0x3e34d; + md5_update = 0x3ed51; + md5_finish = 0x3ed59; + md5 = 0x3ee11; + md5_hmac_starts = 0x3ee75; + md5_hmac_update = 0x3ef51; + md5_hmac_finish = 0x3ef59; + md5_hmac_reset = 0x3efbd; + md5_hmac = 0x3eff1; + oid_get_attr_short_name = 0x3f071; + oid_get_x509_ext_type = 0x3f0b1; + oid_get_extended_key_usage = 0x3f0f1; + oid_get_sig_alg_desc = 0x3f131; + oid_get_sig_alg = 0x3f149; + oid_get_oid_by_sig_alg = 0x3f169; + oid_get_pk_alg = 0x3f1a1; + oid_get_oid_by_pk_alg = 0x3f1e1; + oid_get_ec_grp = 0x3f219; + oid_get_oid_by_ec_grp = 0x3f259; + oid_get_cipher_alg = 0x3f291; + oid_get_md_alg = 0x3f2d1; + oid_get_oid_by_md = 0x3f311; + oid_get_pkcs12_pbe_alg = 0x3f349; + oid_get_numeric_string = 0x3f391; + pem_init = 0x3f649; + pem_read_buffer = 0x3f651; + pem_free = 0x3f955; + pem_write_buffer = 0x3f97d; + pk_init = 0x3fa81; + pk_free = 0x3fa8d; + pk_info_from_type = 0x3faad; + pk_init_ctx = 0x3fae1; + pk_init_ctx_rsa_alt = 0x3fb11; + pk_can_do = 0x3fb69; + pk_verify = 0x3fb79; + pk_verify_ext = 0x3fbc9; + pk_sign = 0x3fc8d; + pk_decrypt = 0x3fce9; + pk_encrypt = 0x3fd15; + pk_get_size = 0x3fd41; + pk_debug = 0x3fd51; + pk_get_name = 0x3fd79; + pk_get_type = 0x3fd8d; + pk_write_pubkey = 0x40181; + pk_write_pubkey_der = 0x40201; + pk_write_key_der = 0x402dd; + pk_write_pubkey_pem = 0x404f5; + pk_write_key_pem = 0x40545; + rsa_init = 0x4065d; + rsa_set_padding = 0x40679; + rsa_check_pubkey = 0x40685; + rsa_check_privkey = 0x406e1; + rsa_public = 0x409a5; + rsa_private = 0x40a25; + rsa_rsaes_oaep_encrypt = 0x40c29; + rsa_rsaes_pkcs1_v15_encrypt = 0x40d31; + rsa_pkcs1_encrypt = 0x40e19; + rsa_rsaes_oaep_decrypt = 0x40e59; + rsa_rsaes_pkcs1_v15_decrypt = 0x40fbd; + rsa_pkcs1_decrypt = 0x410c1; + rsa_rsassa_pss_sign = 0x4110d; + rsa_rsassa_pkcs1_v15_sign = 0x41271; + rsa_pkcs1_sign = 0x41389; + rsa_rsassa_pss_verify_ext = 0x413c9; + rsa_rsassa_pss_verify = 0x41575; + rsa_rsassa_pkcs1_v15_verify = 0x415a5; + rsa_pkcs1_verify = 0x41709; + rsa_free = 0x41765; + rsa_gen_key = 0x417d5; + rsa_copy = 0x4198d; + sha1_init = 0x41a9d; + sha1_free = 0x41aa5; + sha1_starts = 0x41ab9; + sha1_process = 0x41aed; + sha1_update = 0x42e15; + sha1_finish = 0x42e1d; + sha1 = 0x42ee5; + sha1_hmac_starts = 0x42f51; + sha1_hmac_update = 0x43039; + sha1_hmac_finish = 0x43041; + sha1_hmac_reset = 0x430b5; + sha1_hmac = 0x430f1; + sha256_init = 0x43139; + sha256_free = 0x43141; + sha256_starts = 0x43155; + sha256_process = 0x431e5; + sha256_update = 0x4513d; + sha256_finish = 0x45145; + sha256 = 0x4524d; + sha256_hmac_starts = 0x45325; + sha256_hmac_update = 0x45475; + sha256_hmac_finish = 0x4547d; + sha256_hmac_reset = 0x45569; + sha256_hmac = 0x45601; + sha512_init = 0x45651; + sha512_free = 0x4565d; + sha512_starts = 0x45671; + sha512_process = 0x457b9; + sha512_update = 0x46879; + sha512_finish = 0x46881; + sha512 = 0x46ac9; + sha512_hmac_starts = 0x46b11; + sha512_hmac_update = 0x46bd9; + sha512_hmac_finish = 0x46be1; + sha512_hmac_reset = 0x46c35; + sha512_hmac = 0x46c51; + UartLogRomCmdTable = 0x46ca0; + XTAL_CLK = 0x46e10; + CpkClkTbl_FPAG = 0x46e50; + CpkClkTbl_ASIC = 0x46e68; + ROM_IMG1_VALID_PATTEN = 0x46e90; + __AES_rcon = 0x46e98; + __AES_Te4 = 0x46ec0; + SpicCalibrationPattern = 0x472c0; + NEW_CALIBREATION_DIV = 0x472c8; + NEW_CALIBREATION_DATA = 0x472e4; + GDMA_IrqNum = 0x47344; + I2C_DEV_TABLE = 0x47350; + spi_clk_pin = 0x47370; + SPI_DEV_TABLE = 0x47374; + PWM_GDMA_HSx = 0x47394; + TIM_DMA_CCx = 0x473ac; + TIM_IT_CCx = 0x473c4; + TIMx = 0x473dc; + TIMx_irq = 0x473f4; + BAUDRATE_TABLE_40M = 0x4740c; + UART_DEV_TABLE = 0x475bc; + RTW_WPA_OUI_TYPE = 0x4b270; + WPA_CIPHER_SUITE_NONE = 0x4b274; + WPA_CIPHER_SUITE_WEP40 = 0x4b278; + WPA_CIPHER_SUITE_TKIP = 0x4b27c; + WPA_CIPHER_SUITE_CCMP = 0x4b280; + WPA_CIPHER_SUITE_WEP104 = 0x4b284; + RSN_CIPHER_SUITE_NONE = 0x4b288; + RSN_CIPHER_SUITE_WEP40 = 0x4b28c; + RSN_CIPHER_SUITE_TKIP = 0x4b290; + RSN_CIPHER_SUITE_CCMP = 0x4b294; + RSN_CIPHER_SUITE_WEP104 = 0x4b298; + RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X = 0x4b2a8; + RSN_AUTH_KEY_MGMT_UNSPEC_802_1X = 0x4b2ac; + RSN_VERSION_BSD = 0x4b2b0; + rom_e_rtw_msgp_str_ = 0x4b2b4; + rtw_basic_rate_mix = 0x4b9a8; + rtw_basic_rate_ofdm = 0x4b9b0; + rtw_basic_rate_cck = 0x4b9b4; + REALTEK_96B_IE = 0x4b9b8; + AIRGOCAP_OUI = 0x4b9c0; + REALTEK_OUI = 0x4b9c4; + RALINK_OUI = 0x4b9c8; + MARVELL_OUI = 0x4b9cc; + CISCO_OUI = 0x4b9d0; + BROADCOM_OUI3 = 0x4b9d4; + BROADCOM_OUI2 = 0x4b9d8; + BROADCOM_OUI1 = 0x4b9dc; + ARTHEROS_OUI2 = 0x4b9e0; + ARTHEROS_OUI1 = 0x4b9e4; + rom_wps_rcons = 0x4b9e8; + rom_wps_Te0 = 0x4b9f4; + rom_wps_Td4s = 0x4bdf4; + rom_wps_Td0 = 0x4bef4; + sha512_info = 0x5850c; + sha384_info = 0x5854c; + sha256_info = 0x5858c; + sha224_info = 0x585cc; + sha1_info = 0x5860c; + md5_info = 0x5864c; + rsa_alt_info = 0x58d28; + ecdsa_info = 0x58d54; + eckeydh_info = 0x58d80; + eckey_info = 0x58dac; + rsa_info = 0x58dd8; + __rom_bss_start__ = 0x10000000; + NewVectorTable = 0x10000000; + UserIrqFunTable = 0x10000100; + UserIrqDataTable = 0x10000200; + ConfigDebugClose = 0x10000300; + CfgSysDebugWarn = 0x10000304; + CfgSysDebugInfo = 0x10000308; + CfgSysDebugErr = 0x1000030c; + ConfigDebugWarn = 0x10000310; + ConfigDebugInfo = 0x10000314; + ConfigDebugErr = 0x10000318; + sector_addr = 0x1000031c; + _rtl_impure_ptr = 0x10000338; + ArgvArray = 0x1000033c; + pUartLogCtl = 0x10000364; + UartLogBuf = 0x10000368; + UartLogCtl = 0x100003e8; + UartLogHistoryBuf = 0x10000408; + NCO32K_Enable = 0x10000684; + g_rtl_cipherEngine = 0x100006a0; + DONGLE_InitStruct = 0x10000ba0; + EFUSE_MAP = 0x10000ba4; + USOC_BOOT_TXBD = 0x10000da4; + USOC_BOOT_RXBD = 0x10000db4; + USB_RXBuff = 0x10000dc4; + USB_TXBuff = 0x10000dcc; + ADC_AnaparAd = 0x10000dd4; + flash_init_para = 0x10000dec; + NEW_CALIBREATION_END = 0x10000e44; + GDMA_Reg = 0x10000e4c; + PortA_IrqHandler = 0x10000e50; + PortA_IrqData = 0x10000ed0; + IC_FS_SCL_HCNT_TRIM = 0x10000f50; + IC_FS_SCL_LCNT_TRIM = 0x10000f54; + I2C_SLAVEWRITE_PATCH = 0x10000f58; + i2s_cur_tx_page = 0x10000f5c; + i2s_cur_rx_page = 0x10000f60; + i2s_page_num = 0x10000f64; + i2s_txpage_entry = 0x10000f68; + i2s_rxpage_entry = 0x10000f78; + TXBDAddrAligned = 0x10000f88; + H2C_Buff = 0x10000f90; + SPI_RECV_Buff = 0x10000f94; + spi_boot_recv_done = 0x10000f98; + UART_StateRx = 0x10000f9c; + UART_StateTx = 0x10000fa8; + xMCtrl = 0x10000fb8; + XComUARTx = 0x10000fc4; + FalseAlmCnt = 0x10000fc8; + ROMInfo = 0x10001008; + DM_CfoTrack = 0x10001020; + rom_wlan_ram_map = 0x10001048; + rom_libgloss_ram_map = 0x10001050; + __rtl_errno = 0x100014b4; + rom_ssl_ram_map = 0x100014b8; + __rom_bss_end__ = 0x100014f8; +} \ No newline at end of file diff --git a/generate_ocd.sh b/generate_ocd.sh new file mode 100755 index 0000000..73723b4 --- /dev/null +++ b/generate_ocd.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +if [ $# -ne 1 ]; then + echo "Usage: $0 " >&2 + exit 1 +fi + +printf "set rtl8710_flasher_firmware_ptr %s\n" "$FIRMWARE_ADDRESS" +printf "set rtl8710_flasher_buffer %s\n" "$BUFFER_ADDRESS" +printf "set rtl8710_flasher_buffer_size %s\n" "$BUFFER_SIZE" +printf "set rtl8710_flasher_sector_size %s\n" "$FLASH_SECTOR_SIZE" +printf "\n" + +printf "set rtl8710_flasher_code [list \\\n" +hexdump -v -e '1/4 "0x%08x "' "$1" +printf "]\n\n" diff --git a/make_array.c b/make_array.c deleted file mode 100644 index 86e2620..0000000 --- a/make_array.c +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include -#include - -int main(){ - ssize_t i, l; - uint32_t value, index; - uint8_t buffer[24]; - index = 0; - while(1){ - l = read(0, buffer, 24); - if(l < 1)break; - printf("\t"); - for(i = 0; i < l; i += 4){ - value = ((uint32_t)buffer[i + 0] << 0) | ((uint32_t)buffer[i + 1] << 8) | ((uint32_t)buffer[i + 2] << 16) | ((uint32_t)buffer[i + 3] << 24); - if(i)printf(" "); - printf("%d 0x%08X", index++, (unsigned int)value); - } - printf("\n"); - } -} - diff --git a/mask.h b/mask.h deleted file mode 100644 index 1ef49e7..0000000 --- a/mask.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef _MASK_H_ -#define _MASK_H_ - -#include - -#define mask8(mask, value) ((((uint8_t)(value)) << __builtin_ctz((mask))) & ((uint8_t)(mask))) -#define mask8_set(target, mask, value) do{ (target) = ((target) & ~((uint8_t)(mask))) | mask8(mask, value); }while(0) -#define mask8_get(target, mask) (((target) & ((uint8_t)(mask))) >> __builtin_ctz((mask))) - -#define mask16(mask, value) ((((uint16_t)(value)) << __builtin_ctz((mask))) & ((uint16_t)(mask))) -#define mask16_set(target, mask, value) do{ (target) = ((target) & ~((uint16_t)(mask))) | mask16(mask, value); }while(0) -#define mask16_get(target, mask) (((target) & ((uint16_t)(mask))) >> __builtin_ctz((mask))) - -#define mask32(mask, value) ((((uint32_t)(value)) << __builtin_ctz((mask))) & ((uint32_t)(mask))) -#define mask32_set(target, mask, value) do{ (target) = ((target) & ~((uint32_t)(mask))) | mask32(mask, value); }while(0) -#define mask32_get(target, mask) (((target) & ((uint32_t)(mask))) >> __builtin_ctz((mask))) - -#endif - diff --git a/rtl8710.h b/rtl8710.h deleted file mode 100644 index c9fde98..0000000 --- a/rtl8710.h +++ /dev/null @@ -1,289 +0,0 @@ -#ifndef _RTL8710_H_ -#define _RTL8710_H_ - -#include - -typedef struct{ - volatile uint32_t CTRLR0; - volatile uint32_t CTRLR1; - volatile uint32_t SSIENR; - volatile uint32_t MWCR; - volatile uint32_t SER; - volatile uint32_t BAUDR; - volatile uint32_t TXFTLR; - volatile uint32_t RXFTLR; - volatile uint32_t TXFLR; - volatile uint32_t RXFLR; - volatile uint32_t SR; - volatile uint32_t IMR; - volatile uint32_t ISR; - volatile uint32_t RISR; - volatile uint32_t TXOICR; - volatile uint32_t RXOICR; - volatile uint32_t RXUICR; - volatile uint32_t MSTICR; - volatile uint32_t ICR; - volatile uint32_t DMACR; - volatile uint32_t DMATDLR; - volatile uint32_t DMARDLR; - volatile uint32_t IDR; - volatile uint32_t SSI_COMP_VERSION; - union{ - struct{ - union{ - volatile uint8_t DR; - volatile uint8_t DR8; - }; - uint8_t RESERVED1[3]; - }__attribute__((packed)); - struct{ - volatile uint16_t DR16; - uint16_t RESERVED2[1]; - }__attribute__((packed)); - volatile uint32_t DR32; - }; - uint32_t RESERVED3[31]; - volatile uint32_t READ_FAST_SINGLE; - volatile uint32_t READ_DUAL_DATA; - volatile uint32_t READ_DUAL_ADDR_DATA; - volatile uint32_t READ_QUAD_DATA; - union{ - volatile uint32_t READ_QUAD_ADDR_DATA; - volatile uint32_t RX_SAMPLE_DLY; - }; - volatile uint32_t WRITE_SIGNLE; - volatile uint32_t WRITE_DUAL_DATA; - volatile uint32_t WRITE_DUAL_ADDR_DATA; - volatile uint32_t WRITE_QUAD_DATA; - volatile uint32_t WRITE_QUAD_ADDR_DATA; - volatile uint32_t WRITE_ENABLE; - volatile uint32_t READ_STATUS; - volatile uint32_t CTRLR2; - volatile uint32_t FBAUDR; - volatile uint32_t ADDR_LENGTH; - volatile uint32_t AUTO_LENGTH; - volatile uint32_t VALID_CMD; - volatile uint32_t FLASE_SIZE; - volatile uint32_t FLUSH_FIFO; -}__attribute__((packed)) SPI_TypeDef; - -#define SPI_FLASH ((SPI_TypeDef *)0x40006000) - -// SPI_CTRLR0 -#define SPI_CTRLR0_FRF (((uint32_t)0x03) << 4) -#define SPI_CTRLR0_SCPH (((uint32_t)0x01) << 6) -#define SPI_CTRLR0_SCPOL (((uint32_t)0x01) << 7) -#define SPI_CTRLR0_TMOD (((uint32_t)0x03) << 8) -#define SPI_CTRLR0_SLV_OE (((uint32_t)0x01) << 10) -#define SPI_CTRLR0_SRL (((uint32_t)0x01) << 11) -#define SPI_CTRLR0_CFS (((uint32_t)0x0F) << 12) -#define SPI_CTRLR0_ADDR_CH (((uint32_t)0x03) << 16) -#define SPI_CTRLR0_DATA_CH (((uint32_t)0x03) << 18) -#define SPI_CTRLR0_CMD_CH (((uint32_t)0x03) << 20) -#define SPI_CTRLR0_FAST_RD (((uint32_t)0x01) << 22) -#define SPI_CTRLR0_SHIFT_CK_MTIMES (((uint32_t)0x1F) << 23) - -// SPI_SER -#define SPI_SER_SS0 (((uint32_t)0x01) << 0) -#define SPI_SER_SS1 (((uint32_t)0x01) << 1) -#define SPI_SER_SS2 (((uint32_t)0x01) << 2) - -// SPI_SR -#define SPI_SR_SSI (((uint32_t)0x01) << 0) -#define SPI_SR_TFNF (((uint32_t)0x01) << 1) -#define SPI_SR_TFE (((uint32_t)0x01) << 2) -#define SPI_SR_RFNE (((uint32_t)0x01) << 3) -#define SPI_SR_RFF (((uint32_t)0x01) << 4) -#define SPI_SR_TXE (((uint32_t)0x01) << 5) - -typedef struct{ - volatile uint32_t PEON_PWR_CTRL; // 0x0200 - volatile uint32_t PON_ISO_CTRL; // 0x0204 - uint32_t RESERVED1[2]; - volatile uint32_t SOC_FUNC_EN; // 0x0210 - volatile uint32_t SOC_HCI_COM_FUNC_EN; // 0x0214 - volatile uint32_t SOC_PERI_FUNC0_EN; // 0x0218 - volatile uint32_t SOC_PERI_FUNC1_EN; // 0x021C - volatile uint32_t SOC_PERI_DB_FUNC0_EN; // 0x0220 - uint32_t RESERVED2[3]; - volatile uint32_t PESOC_CLK_CTRL; // 0x0230 - volatile uint32_t PESOC_PERI_CLK_CTRL0; // 0x0234 - volatile uint32_t PESOC_PERI_CLK_CTRL1; // 0x0238 - volatile uint32_t PESOC_CLK_CTRL3; // 0x023C - volatile uint32_t PESOC_HCI_CLK_CTRL0; // 0x0240 - volatile uint32_t PESOC_COM_CLK_CTRL1; // 0x0244 - volatile uint32_t PESOC_HW_ENG_CLK_CTRL; // 0x0248 - uint32_t RESERVED3[1]; - volatile uint32_t PESOC_CLK_SEL; // 0x0250 - uint32_t RESERVED4[6]; - volatile uint32_t SYS_ANACK_CAL_CTRL; // 0x026C - volatile uint32_t OSC32K_CTRL; // 0x0270 - volatile uint32_t OSC32K_REG_CTRL0; // 0x0274 - volatile uint32_t OSC32K_REG_CTRL1; // 0x0278 - volatile uint32_t THERMAL_METER_CTRL; // 0x027C - volatile uint32_t UART_MUX_CTRL; // 0x0280 - volatile uint32_t SPI_MUX_CTRL; // 0x0284 - volatile uint32_t I2C_MUX_CTRL; // 0x0288 - volatile uint32_t I2S_MUX_CTRL; // 0x028C - uint32_t RESERVED5[4]; - volatile uint32_t HCI_PINMUX_CTRL; // 0x02A0 - volatile uint32_t WL_PINMUX_CTRL; // 0x02A4 - volatile uint32_t BT_PINMUX_CTRL; // 0x02A8 - volatile uint32_t PWM_PINMUX_CTRL; // 0x02AC - uint32_t RESERVED6[4]; - volatile uint32_t CPU_PERIPHERAL_CTRL; // 0x02C0 - uint32_t RESERVED7[7]; - volatile uint32_t HCI_CTRL_STATUS_0; // 0x02E0 - volatile uint32_t HCI_CTRL_STATUS_1; // 0x02E4 - uint32_t RESERVED8[6]; - volatile uint32_t PESOC_MEM_CTRL; // 0x0300 - volatile uint32_t PESOC_SOC_CTRL; // 0x0304 - volatile uint32_t PESOC_PERI_CTRL; // 0x0308 - uint32_t RESERVED9[5]; - volatile uint32_t GPIO_SHTDN_CTRL; // 0x0320 - volatile uint32_t GPIO_DRIVING_CTRL; // 0x0324 - uint32_t RESERVED10[2]; - volatile uint32_t GPIO_PULL_CTRL0; // 0x0330 - volatile uint32_t GPIO_PULL_CTRL1; // 0x0334 - volatile uint32_t GPIO_PULL_CTRL2; // 0x0338 - volatile uint32_t GPIO_PULL_CTRL3; // 0x033C - volatile uint32_t GPIO_PULL_CTRL4; // 0x0340 - volatile uint32_t GPIO_PULL_CTRL5; // 0x0344 - volatile uint32_t GPIO_PULL_CTRL6; // 0x0348 - uint32_t RESERVED11[5]; - volatile uint32_t PERI_PWM0_CTRL; // 0x0360 - volatile uint32_t PERI_PWM1_CTRL; // 0x0364 - volatile uint32_t PERI_PWM2_CTRL; // 0x0368 - volatile uint32_t PERI_PWM3_CTRL; // 0x036C - volatile uint32_t PERI_TIM_EVT_CTRL; // 0x0370 - volatile uint32_t PERI_EGTIM_CTRL; // 0x0374 - uint32_t RESERVED12[30]; - volatile uint32_t PEON_CFG; // 0x03F0 - volatile uint32_t PEON_STATUS; // 0x03F4 -}__attribute__((packed)) PERI_ON_TypeDef; - -#define PERI_ON ((PERI_ON_TypeDef *)0x40000200) - -// PERI_ON_SOC_FUNC_EN -#define PERI_ON_SOC_FUNC_EN_FUN (((uint32_t)0x01) << 0) -#define PERI_ON_SOC_FUNC_EN_OCP (((uint32_t)0x01) << 1) -#define PERI_ON_SOC_FUNC_EN_LXBUS (((uint32_t)0x01) << 2) -#define PERI_ON_SOC_FUNC_EN_FLASH (((uint32_t)0x01) << 4) -#define PERI_ON_SOC_FUNC_EN_MEM_CTRL (((uint32_t)0x01) << 6) -#define PERI_ON_SOC_FUNC_EN_CPU (((uint32_t)0x01) << 8) -#define PERI_ON_SOC_FUNC_EN_LOG_UART (((uint32_t)0x01) << 12) -#define PERI_ON_SOC_FUNC_EN_GDMA0 (((uint32_t)0x01) << 13) -#define PERI_ON_SOC_FUNC_EN_GDMA1 (((uint32_t)0x01) << 14) -#define PERI_ON_SOC_FUNC_EN_GTIMER (((uint32_t)0x01) << 16) -#define PERI_ON_SOC_FUNC_EN_SECURITY_ENGINE (((uint32_t)0x01) << 20) - -// PERI_ON_SOC_PERI_FUNC1_EN -#define PERI_ON_SOC_PERI_FUNC1_EN_ADC0 (((uint32_t)0x01) << 0) -#define PERI_ON_SOC_PERI_FUNC1_EN_DAC0 (((uint32_t)0x01) << 4) -#define PERI_ON_SOC_PERI_FUNC1_EN_DAC1 (((uint32_t)0x01) << 5) -#define PERI_ON_SOC_PERI_FUNC1_EN_GPIO (((uint32_t)0x01) << 8) - -// PERI_ON_PESOC_CLK_CTRL -#define PERI_ON_CLK_CTRL_CKE_OCP (((uint32_t)0x01) << 0) -#define PERI_ON_CLK_CTRL_CKE_PLFM (((uint32_t)0x01) << 2) -#define PERI_ON_CLK_CTRL_ACTCK_TRACE_EN (((uint32_t)0x01) << 4) -#define PERI_ON_CLK_CTRL_SLPCK_TRACE_EN (((uint32_t)0x01) << 5) -#define PERI_ON_CLK_CTRL_ACTCK_VENDOR_REG_EN (((uint32_t)0x01) << 6) -#define PERI_ON_CLK_CTRL_SLPCK_VENDOR_REG_EN (((uint32_t)0x01) << 7) -#define PERI_ON_CLK_CTRL_ACTCK_FLASH_EN (((uint32_t)0x01) << 8) -#define PERI_ON_CLK_CTRL_SLPCK_FLASH_EN (((uint32_t)0x01) << 9) -#define PERI_ON_CLK_CTRL_ACTCK_SDR_EN (((uint32_t)0x01) << 10) -#define PERI_ON_CLK_CTRL_SLPCK_SDR_EN (((uint32_t)0x01) << 11) -#define PERI_ON_CLK_CTRL_ACTCK_LOG_UART_EN (((uint32_t)0x01) << 12) -#define PERI_ON_CLK_CTRL_SLPCK_LOG_UART_EN (((uint32_t)0x01) << 13) -#define PERI_ON_CLK_CTRL_ACTCK_TIMER_EN (((uint32_t)0x01) << 14) -#define PERI_ON_CLK_CTRL_SLPCK_TIMER_EN (((uint32_t)0x01) << 15) -#define PERI_ON_CLK_CTRL_ACTCK_GDMA0_EN (((uint32_t)0x01) << 16) -#define PERI_ON_CLK_CTRL_SLPCK_GDMA0_EN (((uint32_t)0x01) << 17) -#define PERI_ON_CLK_CTRL_ACTCK_GDMA1_EN (((uint32_t)0x01) << 18) -#define PERI_ON_CLK_CTRL_SLPCK_GDMA1_EN (((uint32_t)0x01) << 19) -#define PERI_ON_CLK_CTRL_ACTCK_GPIO_EN (((uint32_t)0x01) << 24) -#define PERI_ON_CLK_CTRL_SLPCK_GPIO_EN (((uint32_t)0x01) << 25) -#define PERI_ON_CLK_CTRL_ACTCK_BTCMD_EN (((uint32_t)0x01) << 28) -#define PERI_ON_CLK_CTRL_SLPCK_BTCMD_EN (((uint32_t)0x01) << 29) - -// PERI_ON_CPU_PERIPHERAL_CTRL -#define PERI_ON_CPU_PERIPHERAL_CTRL_SPI_FLASH_PIN_EN (((uint32_t)0x01) << 0) -#define PERI_ON_CPU_PERIPHERAL_CTRL_SPI_FLASH_PIN_SEL (((uint32_t)0x03) << 1) -#define PERI_ON_CPU_PERIPHERAL_CTRL_SDR_PIN_EN (((uint32_t)0x01) << 4) -#define PERI_ON_CPU_PERIPHERAL_CTRL_TRACE_PIN_EN (((uint32_t)0x01) << 17) -#define PERI_ON_CPU_PERIPHERAL_CTRL_LOG_UART_PIN_EN (((uint32_t)0x01) << 20) -#define PERI_ON_CPU_PERIPHERAL_CTRL_LOG_UART_IR_EN (((uint32_t)0x01) << 21) -#define PERI_ON_CPU_PERIPHERAL_CTRL_LOG_UART_PIN_SEL (((uint32_t)0x03) << 22) - -typedef struct{ - union{ - volatile uint32_t RBR; - volatile uint32_t THR; - volatile uint32_t DLL; - volatile uint32_t RBR_THR_DLL; - }; - union{ - volatile uint32_t IER; - volatile uint32_t DLH; - volatile uint32_t IER_DLH; - }; - union{ - volatile uint32_t IIR; - volatile uint32_t FCR; - volatile uint32_t IIR_FCR; - }; - volatile uint32_t LCR; - volatile uint32_t MCR; - volatile uint32_t LSR; - volatile uint32_t MSR; - uint32_t RESERVED1[24]; - volatile uint32_t USR; -}__attribute__((packed)) LOG_UART_TypeDef; - -#define LOG_UART ((LOG_UART_TypeDef *)0x40003000) - -// LOG_UART_IER -#define LOG_UART_IER_ERBFI (((uint32_t)0x01) << 0) -#define LOG_UART_IER_ETBEI (((uint32_t)0x01) << 1) -#define LOG_UART_IER_ELSI (((uint32_t)0x01) << 2) -#define LOG_UART_IER_EDSSI (((uint32_t)0x01) << 3) - -// LOG_UART_FCR -#define LOG_UART_FCR_FIFOE (((uint32_t)0x01) << 0) -#define LOG_UART_FCR_RFIFOR (((uint32_t)0x01) << 1) -#define LOG_UART_FCR_XFIFOR (((uint32_t)0x01) << 2) -#define LOG_UART_FCR_DMAM (((uint32_t)0x01) << 3) -#define LOG_UART_FCR_TET (((uint32_t)0x03) << 4) -#define LOG_UART_FCR_RT (((uint32_t)0x03) << 6) - -// LOG_UART_LCR -#define LOG_UART_LCR_DLS (((uint32_t)0x03) << 0) -#define LOG_UART_LCR_STOP (((uint32_t)0x01) << 2) -#define LOG_UART_LCR_PEN (((uint32_t)0x01) << 3) -#define LOG_UART_LCR_EPS (((uint32_t)0x01) << 4) -#define LOG_UART_LCR_STICK_PAR (((uint32_t)0x01) << 5) -#define LOG_UART_LCR_BC (((uint32_t)0x01) << 6) -#define LOG_UART_LCR_DLAB (((uint32_t)0x01) << 7) - -// LOG_UART_MCR -#define LOG_UART_MCR_DTR (((uint32_t)0x01) << 0) -#define LOG_UART_MCR_RTS (((uint32_t)0x01) << 1) -#define LOG_UART_MCR_OUT1 (((uint32_t)0x01) << 2) -#define LOG_UART_MCR_OUT2 (((uint32_t)0x01) << 3) -#define LOG_UART_MCR_LOOPBACK (((uint32_t)0x01) << 4) -#define LOG_UART_MCR_AFCE (((uint32_t)0x01) << 5) - -// LOG_UART_LSR -#define LOG_UART_LSR_DR (((uint32_t)0x01) << 0) -#define LOG_UART_LSR_OE (((uint32_t)0x01) << 1) -#define LOG_UART_LSR_PE (((uint32_t)0x01) << 2) -#define LOG_UART_LSR_FE (((uint32_t)0x01) << 3) -#define LOG_UART_LSR_BI (((uint32_t)0x01) << 4) -#define LOG_UART_LSR_THRE (((uint32_t)0x01) << 5) -#define LOG_UART_LSR_TEMT (((uint32_t)0x01) << 6) -#define LOG_UART_LSR_RFE (((uint32_t)0x01) << 7) -#define LOG_UART_LSR_ADDR_RCVD (((uint32_t)0x01) << 8) - -#endif - diff --git a/rtl8710.ld b/rtl8710.ld index 5b8537d..00f4855 100644 --- a/rtl8710.ld +++ b/rtl8710.ld @@ -1,19 +1,33 @@ -MEMORY{ - tcm (rwx) : ORIGIN = 0x1FFF0000, LENGTH = 64k - ram (rwx) : ORIGIN = 0x10000000, LENGTH = 448k +/* from https://github.com/ambiot/amb1_sdk/blob/master/project/realtek_amebaz_va0_example/GCC-RELEASE/export-rom_symbol_v01.txt */ +INCLUDE "export-rom_symbol_v01.txt" + +MEMORY { + ram (rwx) : ORIGIN = _RAM_ORIGIN, LENGTH = _RAM_SIZE } -PROVIDE(STACK_TOP = 0x1FFF0000 + 64k); +ASSERT(_RAM_ORIGIN + _RAM_SIZE <= _WORK_AREA_START, "Firmware overlaps with OpenOCD work area!") -SECTIONS{ - .text : { __text_beg__ = . ; *(.vectors*) *(.header) *(.text) *(.text*) *(.rodata) *(.rodata*) *(.glue_7) *(.glue_7t) *(.eh_frame) *(.ARM.extab*) . = ALIGN(4); __text_end__ = . ; } >ram - .data : { . = ALIGN(4); __data_beg__ = . ; *(.ram_vectors) *(.data) *(.data*) *(.ram_func) . = ALIGN(4); __data_end__ = . ; } >ram - .bss : { . = ALIGN(4); __bss_beg__ = . ; *(.bss) *(COMMON) . = ALIGN(4); __bss_end__ = . ; } >ram - __exidx_start = .; - .ARM.exidx : { ___exidx_start = . ; *(.ARM.exidx*) ; ___exidx_end = . ; } >ram - __exidx_end = .; - .ARM.extab : { *(.ARM.extab*) } >ram - . = ALIGN(4); - end = .; PROVIDE (end = .); +SECTIONS { + .text : { + *(.vectors) + *(.text*) + *(.rodata*) + . = ALIGN(4); + } > ram + + .data : { + . = ALIGN(4); + *(.data*) + . = ALIGN(4); + } > ram + + .bss : { + . = ALIGN(4); + *(.bss*) + *(COMMON) + . = ALIGN(4); + } > ram + + end = .; + __end__ = .; } - diff --git a/rtl8710_cpu.tcl b/rtl8710_cpu.tcl index 9c97f04..ee4a01c 100644 --- a/rtl8710_cpu.tcl +++ b/rtl8710_cpu.tcl @@ -24,17 +24,20 @@ if { [info exists CPUTAPID] } { set _CPUTAPID 0x2ba01477 } -swj_newdap $_CHIPNAME cpu -irlen 4 -expected-id $_CPUTAPID +swd newdap $_CHIPNAME cpu -irlen 4 -expected-id $_CPUTAPID set _TARGETNAME $_CHIPNAME.cpu -target create $_TARGETNAME cortex_m -endian $_ENDIAN -chain-position $_TARGETNAME +dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu +target create $_TARGETNAME cortex_m -endian $_ENDIAN -dap $_CHIPNAME.dap -$_TARGETNAME configure -work-area-phys 0x10001000 -work-area-size $_WORKAREASIZE -work-area-backup 0 +# todo: get work area from makefile +$_TARGETNAME configure -work-area-phys 0x10001500 -work-area-size $_WORKAREASIZE -work-area-backup 0 -adapter_khz 500 -adapter_nsrst_delay 100 +adapter speed 4000 +adapter srst delay 100 if {![using_hla]} { cortex_m reset_config sysresetreq } +$_TARGETNAME configure -event reset-init {amebaz_init} diff --git a/rtl8710_flasher.c b/rtl8710_flasher.c index faa62dc..6d4cc2b 100644 --- a/rtl8710_flasher.c +++ b/rtl8710_flasher.c @@ -1,121 +1,111 @@ -/* - * - * Copyright (C) 2016 Rebane, rebane@alkohol.ee - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin - * Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - */ +/* SPDX-License-Identifier: GPL-2.0 */ -#include "rtl8710.h" +#include "rtl8710_flasher.h" + +#include #include -#include "spi_flash.h" +#include -#define MEM_START (*(volatile uint32_t *)(BUFFER_ADDRESS + 0x00)) -#define MEM_COMMAND (*(volatile uint32_t *)(BUFFER_ADDRESS + 0x04)) -#define MEM_STATUS (*(volatile uint32_t *)(BUFFER_ADDRESS + 0x08)) -#define MEM_PARAM (*(volatile uint32_t *)(BUFFER_ADDRESS + 0x0C)) -#define MEM_OFFSET (*(volatile uint32_t *)(BUFFER_ADDRESS + 0x10)) -#define MEM_LEN (*(volatile uint32_t *)(BUFFER_ADDRESS + 0x14)) -#define MEM_DATA ((volatile uint8_t *)(BUFFER_ADDRESS + 0x20)) +#define printf DiagPrintf -#define COMMAND_READ_ID 0 -#define COMMAND_MASS_ERASE 1 -#define COMMAND_SECTOR_ERASE 2 -#define COMMAND_READ 3 -#define COMMAND_WRITE 4 -#define COMMAND_VERIFY 5 - -int __attribute__((section(".vectors"))) main(){ - uint32_t p, i, l; - uint8_t read_buffer[16]; - - __asm__("cpsid f"); - - PERI_ON->PESOC_CLK_CTRL |= PERI_ON_CLK_CTRL_ACTCK_GPIO_EN | PERI_ON_CLK_CTRL_SLPCK_GPIO_EN; // enable gpio peripheral clock - PERI_ON->SOC_PERI_FUNC1_EN |= PERI_ON_SOC_PERI_FUNC1_EN_GPIO; // enable gpio peripheral - - PERI_ON->GPIO_SHTDN_CTRL = 0xFF; - PERI_ON->GPIO_DRIVING_CTRL = 0xFF; - - spi_flash_init(); - - // read jedec info - spi_flash_wait_busy(); - MEM_PARAM = spi_flash_jedec_id(); - spi_flash_wait_busy(); - - while(1){ - MEM_START = 0x00000000; - while(MEM_START == 0x00000000); - if(MEM_COMMAND == COMMAND_READ_ID){ - MEM_PARAM = 0x00000000; - spi_flash_wait_busy(); - MEM_PARAM = spi_flash_jedec_id(); - spi_flash_wait_busy(); - }else if(MEM_COMMAND == COMMAND_MASS_ERASE){ - spi_flash_wait_busy(); - spi_flash_cmd(0x06); - spi_flash_wait_wel(); - spi_flash_cmd(0xC7); - spi_flash_wait_busy(); - spi_flash_cmd(0x04); - spi_flash_wait_busy(); - }else if(MEM_COMMAND == COMMAND_SECTOR_ERASE){ - spi_flash_wait_busy(); - spi_flash_cmd(0x06); - spi_flash_wait_wel(); - spi_flash_sector_erase(MEM_OFFSET); - spi_flash_wait_busy(); - spi_flash_cmd(0x04); - spi_flash_wait_busy(); - }else if(MEM_COMMAND == COMMAND_READ){ - spi_flash_wait_busy(); - p = MEM_OFFSET; - for(i = 0; i < MEM_LEN; i += 16, p += 16){ - spi_flash_read(p, (void *)&MEM_DATA[i], 16); - } - spi_flash_wait_busy(); - }else if(MEM_COMMAND == COMMAND_WRITE){ - for(p = 0; p < MEM_LEN; p += 256){ - spi_flash_wait_busy(); - spi_flash_cmd(0x06); - spi_flash_wait_wel(); - spi_flash_write((MEM_OFFSET + p), (void *)&MEM_DATA[p], 256); - spi_flash_wait_busy(); - spi_flash_cmd(0x04); - spi_flash_wait_busy(); - } - }else if(MEM_COMMAND == COMMAND_VERIFY){ - spi_flash_wait_busy(); - for(p = 0; p < MEM_LEN; p += 16){ - spi_flash_read((MEM_OFFSET + p), read_buffer, 16); - l = MEM_LEN - p; - if(l > 16)l = 16; - for(i = 0; i < l; i++){ - if(read_buffer[i] != MEM_DATA[p + i]){ - break; - } - } - if(i < l){ - MEM_STATUS = 0x00000001; - MEM_PARAM = p; - break; - } - spi_flash_wait_busy(); - } - }else{ - MEM_STATUS = 0x00000001; - } - } +static void print_flash_info(const uint8_t *flash_id) { + printf("[FLASH] Device ID: %02X %02X %02X\n", flash_id[0], flash_id[1], + flash_id[2]); + printf("[FLASH] Vendor: 0x%08X\n", flash_init_para.vendor_id); + printf("[FLASH] Config: Mode=%d, Clock=%d, ReadCmd=0x%02X\n", + flash_init_para.current_mode, flash_init_para.clock_div, + flash_init_para.current_read_cmd); + printf("[FLASH] Timing: SampleDelay=%d, DummyCycles=[%d,%d,%d]\n", + flash_init_para.read_sample_delay, + flash_init_para.read_dummy_cycles[0], + flash_init_para.read_dummy_cycles[1], + flash_init_para.read_dummy_cycles[2]); } +int __attribute__((section(".vectors"))) main(void) { + __asm__ volatile("cpsid if"); + + uint8_t flash_id[4] = {0}; + + // sometimes we boot up and the ROM already inits flash? + if (PERI_ON_SOC_FUNC_EN & FLASH_PERIPH_BIT) { + printf("[FLASHER] Flash peripheral already enabled...?\n"); + } + + RCC_PeriphClockCmd(FLASH_PERIPH_BIT, FLASH_CLOCK_BIT, 0); + FLASH_ClockDiv(0); + RCC_PeriphClockCmd(FLASH_PERIPH_BIT, FLASH_CLOCK_BIT, 1); + + PINMUX_Ctrl(10, 0, 1); + FLASH_StructInit_GD(&flash_init_para); + FLASH_Init(2); + + FLASH_RxCmd(flash_init_para.cmd_read_id, 3, flash_id); + print_flash_info(flash_id); + + /* clear block protection */ + FLASH_SetStatusBits(0x1c, 0); + printf("[FLASH] Block protection cleared\n"); + + while (1) { + FLASH_CONTROL->start = 0; + while (!FLASH_CONTROL->start) __asm__("nop"); + + switch (FLASH_CONTROL->cmd) { + case CMD_READ_ID: + FLASH_RxCmd(flash_init_para.cmd_read_id, 4, flash_id); + FLASH_CONTROL->param = *(uint32_t *)flash_id; + break; + + case CMD_MASS_ERASE: + FLASH_Erase(0, 0); + printf("[FLASHER] Full chip erase completed\n"); + break; + + case CMD_SECTOR_ERASE: + FLASH_Erase(2, FLASH_CONTROL->offset); + break; + + case CMD_READ: + for (uint32_t i = 0; i < FLASH_CONTROL->len; i += 4) { + volatile uint32_t *flash_addr = + (volatile uint32_t *)(SPI_FLASH_BASE + FLASH_CONTROL->offset + i); + uint32_t *dest = (uint32_t *)&FLASH_CONTROL->data[i]; + *dest = *flash_addr; + } + break; + + case CMD_WRITE: + printf("[FLASHER] Starting write of %d bytes at offset 0x%08X\n", + FLASH_CONTROL->len, FLASH_CONTROL->offset); + + for (uint32_t offset = 0; offset < FLASH_CONTROL->len; offset += 4) { + uint32_t write_addr = FLASH_CONTROL->offset + offset; + FLASH_TxData12B(write_addr, 4, + (uint8_t *)&FLASH_CONTROL->data[offset]); + } + + printf("[FLASHER] Write completed successfully\n"); + break; + + case CMD_VERIFY: + for (uint32_t i = 0; i < FLASH_CONTROL->len; i += VERIFY_CHUNK_SIZE) { + size_t bytes_to_compare = MIN(4, FLASH_CONTROL->len - i); + const void *flash_addr = + (const void *)(SPI_FLASH_BASE + FLASH_CONTROL->offset + i); + + if (memcmp(flash_addr, (const void *)&FLASH_CONTROL->data[i], + bytes_to_compare) != 0) { + FLASH_CONTROL->status = 1; + FLASH_CONTROL->param = i; + break; + } + } + break; + + default: + FLASH_CONTROL->status = 1; + break; + } + } +} \ No newline at end of file diff --git a/rtl8710_flasher.h b/rtl8710_flasher.h new file mode 100644 index 0000000..20cc1a2 --- /dev/null +++ b/rtl8710_flasher.h @@ -0,0 +1,132 @@ +#ifndef _RTL8710_FLASHER_H_ +#define _RTL8710_FLASHER_H_ + +#include +#include + +#define __always_long_call __attribute__((long_call)) +#define __packed __attribute__((packed)) + +#define MIN(a, b) ((a) < (b) ? (a) : (b)) +#define BIT(x) (1 << (x)) + +#define READ_CHUNK_SIZE 32 +#define VERIFY_CHUNK_SIZE 32 +#define WRITE_CHUNK_SIZE 256 + +#define SPI_FLASH_BASE 0x08000000 +#define PERI_ON_BASE 0x40000200 + +#define PERI_ON_SOC_FUNC_EN (*(volatile uint32_t *)(PERI_ON_BASE + 0x10)) + +#define FLASH_PERIPH_BIT BIT(4) +#define FLASH_CLOCK_BIT BIT(8) + +/* Flash control structure */ +typedef struct __packed { + volatile uint32_t start; /* 0x00: Control register */ + volatile uint32_t cmd; /* 0x04: Command register */ + volatile uint32_t status; /* 0x08: Status register */ + volatile uint32_t param; /* 0x0C: Parameter/ID register */ + volatile uint32_t offset; /* 0x10: Flash offset */ + volatile uint32_t len; /* 0x14: Length field */ + volatile uint32_t reserved; /* 0x18: Padding to maintain 0x20 data offset */ + volatile uint32_t reserved2; /* 0x1C: Padding to maintain 0x20 data offset */ + volatile uint8_t data[]; /* 0x20: Data buffer */ +} flash_control_t; + +#define FLASH_CONTROL ((flash_control_t *)BUFFER_ADDRESS) + +/* Flash commands */ +typedef enum { + CMD_READ_ID = 0, /* Read Flash ID and capacity */ + CMD_MASS_ERASE = 1, /* Erase entire flash */ + CMD_SECTOR_ERASE = 2, /* Erase 4KB sector at offset */ + CMD_READ = 3, /* Read data into buffer */ + CMD_WRITE = 4, /* Write buffer to flash */ + CMD_VERIFY = 5, /* Verify buffer against flash */ + CMD_MAX = 6 /* For bounds checking */ +} flash_command_t; + +typedef struct { + /* Device identification */ + uint32_t vendor_id; /* Flash vendor ID = 5 */ + + /* Operating mode configuration */ + uint8_t current_mode; /* Current SPI mode (0=single, 1=dual, 2=quad) = 1 */ + uint8_t clock_div; /* SPI clock divider (spi_clk = oc_clk/(2*div)) = 1 */ + uint8_t boot_clock_div; /* Boot-time SPI clock divider = 4 */ + uint32_t current_read_cmd; /* Active read command = 3 */ + + /* Status register bits */ + uint32_t quad_enable_bit; /* Status bit for quad mode = 512 */ + uint32_t busy_bit; /* Write-in-progress status bit = 1 */ + uint32_t write_enable_bit; /* Write enable latch bit = 2 */ + uint32_t has_status2_reg; /* Whether status register 2 exists = 1 */ + + /* Timing configuration */ + uint8_t read_sample_delay; /* Read sampling delay = 1 */ + uint8_t read_dummy_cycles[3]; /* Dummy cycles for different modes = {0,4,6} */ + + /* Read commands */ + uint32_t read_dual_out; /* Dual output read = 0x3B */ + uint32_t read_dual_io; /* Dual I/O read = 0xBB */ + uint32_t read_quad_out; /* Quad output read = 0x6B */ + uint32_t read_quad_io; /* Quad I/O read = 0xEB */ + + /* Write commands */ + uint32_t write_dual_data; /* Dual data write = 0 */ + uint32_t write_dual_addr; /* Dual address/data write = 0 */ + uint32_t write_quad_data; /* Quad data write = 0 */ + uint32_t write_quad_addr; /* Quad address/data write = 32 */ + + /* Valid command masks */ + uint32_t dual_mode_commands; /* Valid commands in dual mode = 516 */ + uint32_t quad_mode_commands; /* Valid commands in quad mode = 784 */ + + /* Basic flash commands */ + uint8_t cmd_write_enable; /* Write enable = 0x06 */ + uint8_t cmd_read_id; /* Read identification = 0x9F */ + uint8_t cmd_read_status; /* Read status register = 0x05 */ + uint8_t cmd_read_status2; /* Read status register 2 = 0x35 */ + uint8_t cmd_write_status; /* Write status register = 0x01 */ + uint8_t cmd_write_status2; /* Write status register 2 = 0x00 */ + + /* Erase commands */ + uint8_t cmd_erase_chip; /* Chip erase = 0x60 */ + uint8_t cmd_erase_block; /* 64KB block erase = 0xD8 */ + uint8_t cmd_erase_sector; /* 4KB sector erase = 0x20 */ + + /* Power management */ + uint8_t cmd_release_powerdown; /* Exit power down = 0xAB */ + uint8_t cmd_enter_powerdown; /* Enter power down = 0xB9 */ + + /* Debug */ + uint8_t debug_enable; /* Enable debug output = 0 */ + uint8_t phase_shift_idx; /* Phase shift calibration index = 0 */ +} FLASH_InitTypeDef; + +/* external ROM bloat */ +extern FLASH_InitTypeDef flash_init_para; +extern __always_long_call uint32_t DiagPrintf(const char *fmt, ...); + +__always_long_call void RCC_PeriphClockCmd(uint32_t APBPeriph, + uint32_t APBPeriph_Clock, + uint8_t NewState); + +__always_long_call void PINMUX_Ctrl(uint32_t Function, uint32_t PinLocation, + bool Operation); + +__always_long_call void FLASH_Erase(uint32_t EraseType, uint32_t Address); +__always_long_call void FLASH_SetStatusBits(uint32_t SetBits, + uint32_t NewState); +// __always_long_call void FLASH_WriteEn(void); +__always_long_call void FLASH_RxCmd(uint8_t cmd, uint32_t read_len, + uint8_t *read_data); +__always_long_call void FLASH_TxData12B(uint32_t StartAddr, + uint8_t DataPhaseLen, uint8_t *pData); +__always_long_call void FLASH_StructInit_GD(void *FLASH_InitStruct); +__always_long_call uint8_t FLASH_Init(uint8_t SpicBitMode); +__always_long_call uint32_t FLASH_ClockDiv(uint8_t Div); + +#endif /* _RTL8710_FLASHER_H_ */ \ No newline at end of file diff --git a/rtl8710_flasher.tcl b/rtl8710_flasher.tcl index b0ea0b4..10e01ef 100644 --- a/rtl8710_flasher.tcl +++ b/rtl8710_flasher.tcl @@ -14,183 +14,195 @@ set rtl8710_flasher_auto_verify 0 set rtl8710_flasher_auto_erase_sector 0xFFFFFFFF proc rtl8710_flasher_init {} { - global rtl8710_flasher_firmware_ptr - global rtl8710_flasher_buffer - global rtl8710_flasher_capacity - global rtl8710_flasher_ready - global rtl8710_flasher_code + global rtl8710_flasher_ready rtl8710_flasher_firmware_ptr + global rtl8710_flasher_buffer rtl8710_flasher_capacity + global rtl8710_flasher_code - if {[expr {$rtl8710_flasher_ready == 0}]} { - echo "initializing RTL8710 flasher" - halt - mww [expr {$rtl8710_flasher_buffer + 0x08}] 0x00000000 - mww [expr {$rtl8710_flasher_buffer + 0x00}] 0x00000001 - array2mem rtl8710_flasher_code 32 $rtl8710_flasher_firmware_ptr [array size rtl8710_flasher_code] - reg faultmask 0x01 - reg sp 0x20000000 - reg pc $rtl8710_flasher_firmware_ptr - resume - rtl8710_flasher_wait - set id [rtl8710_flasher_mrw [expr {$rtl8710_flasher_buffer + 0x0C}]] - set rtl8710_flasher_capacity [expr {2 ** [expr {($id >> 16) & 0xFF}]}] - set rtl8710_flasher_ready 1 - echo "RTL8710 flasher initialized" - } - return "" + if {!$rtl8710_flasher_ready} { + set buf_ctrl [expr {$rtl8710_flasher_buffer + 0x00}] + set buf_status [expr {$rtl8710_flasher_buffer + 0x08}] + set buf_id [expr {$rtl8710_flasher_buffer + 0x0C}] + + halt + # init buffer control regs + mww $buf_status 0 + mww $buf_ctrl 1 + + # load and start flasher + write_memory $rtl8710_flasher_firmware_ptr 32 $rtl8710_flasher_code + reg faultmask 1 + reg sp 0x1003ef00 + reg pc $rtl8710_flasher_firmware_ptr + resume + rtl8710_flasher_wait + + set id [rtl8710_flasher_mrw $buf_id] + set rtl8710_flasher_capacity [expr {1 << (($id >> 16) & 0xFF)}] + set rtl8710_flasher_ready 1 + } } proc rtl8710_flasher_mrw {reg} { - set value "" - mem2array value 32 $reg 1 - return $value(0) + read_memory $reg 32 1 } proc rtl8710_flasher_wait {} { - global rtl8710_flasher_buffer - while {[rtl8710_flasher_mrw [expr {$rtl8710_flasher_buffer + 0x00}]]} { } + global rtl8710_flasher_buffer + set addr [expr {$rtl8710_flasher_buffer + 0x00}] + while {[rtl8710_flasher_mrw $addr]} {} } -proc rtl8710_flasher_load_block {local_filename offset len} { - global rtl8710_flasher_buffer - load_image $local_filename [expr {$rtl8710_flasher_buffer + 0x20 - $offset}] bin [expr {$rtl8710_flasher_buffer + 0x20}] $len +proc rtl8710_flasher_load_block {local_filename offset length} { + global rtl8710_flasher_buffer + set buffer_addr [expr {$rtl8710_flasher_buffer + 0x20}] + load_image $local_filename [expr {$buffer_addr - $offset}] bin $buffer_addr $length +} + +proc rtl8710_flasher_block {command offset len} { + global rtl8710_flasher_buffer + global rtl8710_flasher_command_read rtl8710_flasher_command_write rtl8710_flasher_command_verify + + # select command type + switch $command { + "read" {set cmd_type $rtl8710_flasher_command_read} + "write" {set cmd_type $rtl8710_flasher_command_write} + "verify" {set cmd_type $rtl8710_flasher_command_verify} + default {error "Unknown command type: $command"} + } + + mww [expr {$rtl8710_flasher_buffer + 0x04}] $cmd_type + mww [expr {$rtl8710_flasher_buffer + 0x08}] 0x00000000 + mww [expr {$rtl8710_flasher_buffer + 0x10}] $offset + mww [expr {$rtl8710_flasher_buffer + 0x14}] $len + mww [expr {$rtl8710_flasher_buffer + 0x00}] 0x00000001 + rtl8710_flasher_wait + + set status [rtl8710_flasher_mrw [expr {$rtl8710_flasher_buffer + 0x08}]] + if {[expr {$status > 0}]} { + if {$command eq "verify"} { + set status [rtl8710_flasher_mrw [expr {$rtl8710_flasher_buffer + 0x0C}]] + set status [expr {$status + $offset}] + } + error "$command error, offset $status" + } } proc rtl8710_flasher_read_block {offset len} { - global rtl8710_flasher_buffer - global rtl8710_flasher_command_read - mww [expr {$rtl8710_flasher_buffer + 0x04}] $rtl8710_flasher_command_read - mww [expr {$rtl8710_flasher_buffer + 0x08}] 0x00000000 - mww [expr {$rtl8710_flasher_buffer + 0x10}] $offset - mww [expr {$rtl8710_flasher_buffer + 0x14}] $len - mww [expr {$rtl8710_flasher_buffer + 0x00}] 0x00000001 - rtl8710_flasher_wait - set status [rtl8710_flasher_mrw [expr {$rtl8710_flasher_buffer + 0x08}]] - if {[expr {$status > 0}]} { - error "read error, offset $offset" - } + rtl8710_flasher_block "read" $offset $len } proc rtl8710_flasher_write_block {offset len} { - global rtl8710_flasher_buffer - global rtl8710_flasher_command_write - mww [expr {$rtl8710_flasher_buffer + 0x04}] $rtl8710_flasher_command_write - mww [expr {$rtl8710_flasher_buffer + 0x08}] 0x00000000 - mww [expr {$rtl8710_flasher_buffer + 0x10}] $offset - mww [expr {$rtl8710_flasher_buffer + 0x14}] $len - mww [expr {$rtl8710_flasher_buffer + 0x00}] 0x00000001 - rtl8710_flasher_wait - set status [rtl8710_flasher_mrw [expr {$rtl8710_flasher_buffer + 0x08}]] - if {[expr {$status > 0}]} { - error "write error, offset $offset" - } + rtl8710_flasher_block "write" $offset $len } proc rtl8710_flasher_verify_block {offset len} { - global rtl8710_flasher_buffer - global rtl8710_flasher_command_verify - mww [expr {$rtl8710_flasher_buffer + 0x04}] $rtl8710_flasher_command_verify - mww [expr {$rtl8710_flasher_buffer + 0x08}] 0x00000000 - mww [expr {$rtl8710_flasher_buffer + 0x10}] $offset - mww [expr {$rtl8710_flasher_buffer + 0x14}] $len - mww [expr {$rtl8710_flasher_buffer + 0x00}] 0x00000001 - rtl8710_flasher_wait - set status [rtl8710_flasher_mrw [expr {$rtl8710_flasher_buffer + 0x08}]] - if {[expr {$status > 0}]} { - set status [rtl8710_flasher_mrw [expr {$rtl8710_flasher_buffer + 0x0C}]] - set status [expr {$status + $offset}] - error "verify error, offset $status" - } + rtl8710_flasher_block "verify" $offset $len } proc rtl8710_flash_read_id {} { - global rtl8710_flasher_buffer - global rtl8710_flasher_capacity - global rtl8710_flasher_command_read_id - rtl8710_flasher_init - mww [expr {$rtl8710_flasher_buffer + 0x04}] $rtl8710_flasher_command_read_id - mww [expr {$rtl8710_flasher_buffer + 0x08}] 0x00000000 - mww [expr {$rtl8710_flasher_buffer + 0x00}] 0x00000001 - rtl8710_flasher_wait - set id [rtl8710_flasher_mrw [expr {$rtl8710_flasher_buffer + 0x0C}]] - set manufacturer_id [format "0x%02X" [expr {$id & 0xFF}]] - set memory_type [format "0x%02X" [expr {($id >> 8) & 0xFF}]] - set memory_capacity [expr {2 ** [expr {($id >> 16) & 0xFF}]}] - echo "manufacturer ID: $manufacturer_id, memory type: $memory_type, memory capacity: $memory_capacity bytes" + global rtl8710_flasher_buffer rtl8710_flasher_capacity + global rtl8710_flasher_command_read_id + + rtl8710_flasher_init + + # send read ID command + mww [expr {$rtl8710_flasher_buffer + 0x04}] $rtl8710_flasher_command_read_id + mww [expr {$rtl8710_flasher_buffer + 0x08}] 0 + mww [expr {$rtl8710_flasher_buffer + 0x00}] 1 + rtl8710_flasher_wait + + set id [rtl8710_flasher_mrw [expr {$rtl8710_flasher_buffer + 0x0C}]] + + set manufacturer_id [format "0x%02X" [expr {$id & 0xFF}]] + set memory_type [format "0x%02X" [expr {($id >> 8) & 0xFF}]] + set memory_capacity [expr {2 ** (($id >> 16) & 0xFF)}] + + echo "manufacturer ID: $manufacturer_id, memory type: $memory_type, memory capacity: $memory_capacity bytes" +} + +proc rtl8710_flash_erase {type {offset 0}} { + global rtl8710_flasher_buffer + global rtl8710_flasher_command_mass_erase rtl8710_flasher_command_sector_erase + + rtl8710_flasher_init + + if {$type eq "mass"} { + set cmd $rtl8710_flasher_command_mass_erase + } elseif {$type eq "sector"} { + set cmd $rtl8710_flasher_command_sector_erase + mww [expr {$rtl8710_flasher_buffer + 0x10}] $offset + } else { + error "Unknown erase type: $type" + } + + mww [expr {$rtl8710_flasher_buffer + 0x04}] $cmd + mww [expr {$rtl8710_flasher_buffer + 0x08}] 0 + mww [expr {$rtl8710_flasher_buffer + 0x00}] 1 + rtl8710_flasher_wait } proc rtl8710_flash_mass_erase {} { - global rtl8710_flasher_buffer - global rtl8710_flasher_command_mass_erase - rtl8710_flasher_init - mww [expr {$rtl8710_flasher_buffer + 0x04}] $rtl8710_flasher_command_mass_erase - mww [expr {$rtl8710_flasher_buffer + 0x08}] 0x00000000 - mww [expr {$rtl8710_flasher_buffer + 0x00}] 0x00000001 - rtl8710_flasher_wait + rtl8710_flash_erase "mass" } proc rtl8710_flash_sector_erase {offset} { - global rtl8710_flasher_buffer - global rtl8710_flasher_command_sector_erase - rtl8710_flasher_init - mww [expr {$rtl8710_flasher_buffer + 0x04}] $rtl8710_flasher_command_sector_erase - mww [expr {$rtl8710_flasher_buffer + 0x08}] 0x00000000 - mww [expr {$rtl8710_flasher_buffer + 0x10}] $offset - mww [expr {$rtl8710_flasher_buffer + 0x00}] 0x00000001 - rtl8710_flasher_wait + rtl8710_flash_erase "sector" $offset } proc rtl8710_flash_read {local_filename loc size} { - global rtl8710_flasher_buffer - global rtl8710_flasher_buffer_size - rtl8710_flasher_init - for {set offset 0} {$offset < $size} {set offset [expr {$offset + $rtl8710_flasher_buffer_size}]} { - set len [expr {$size - $offset}] - if {[expr {$len > $rtl8710_flasher_buffer_size}]} { - set len $rtl8710_flasher_buffer_size - } - set flash_offset [expr {$loc + $offset}] - echo "read offset $flash_offset" - rtl8710_flasher_read_block $flash_offset $len - dump_image /tmp/_rtl8710_flasher.bin [expr {$rtl8710_flasher_buffer + 0x20}] $len - exec dd conv=notrunc if=/tmp/_rtl8710_flasher.bin "of=$local_filename" bs=1 "seek=$offset" + global rtl8710_flasher_buffer rtl8710_flasher_buffer_size + rtl8710_flasher_init + + set tmp "/tmp/_rtl8710_flasher.bin" + for {set offset 0} {$offset < $size} {set offset [expr {$offset + $rtl8710_flasher_buffer_size}]} { + set len [expr {($size - $offset) < $rtl8710_flasher_buffer_size ? ($size - $offset) : $rtl8710_flasher_buffer_size}] + set flash_offset [expr {$loc + $offset}] + echo "read $flash_offset" + rtl8710_flasher_read_block $flash_offset $len + dump_image $tmp [expr {$rtl8710_flasher_buffer + 0x20}] $len + exec dd conv=notrunc if=$tmp of=$local_filename bs=1 seek=$offset echo "read $len bytes" - } + } + file delete -force $tmp } proc rtl8710_flash_write {local_filename loc} { - global rtl8710_flasher_buffer_size - global rtl8710_flasher_sector_size - global rtl8710_flasher_auto_erase - global rtl8710_flasher_auto_verify - global rtl8710_flasher_auto_erase_sector - rtl8710_flasher_init - set sector 0 - set size [file size $local_filename] - for {set offset 0} {$offset < $size} {set offset [expr {$offset + $rtl8710_flasher_buffer_size}]} { - set len [expr {$size - $offset}] - if {[expr {$len > $rtl8710_flasher_buffer_size}]} { - set len $rtl8710_flasher_buffer_size - } - set flash_offset [expr {$loc + $offset}] - echo "write offset $flash_offset" - rtl8710_flasher_load_block $local_filename $offset $len - if {[expr {$rtl8710_flasher_auto_erase != 0}]} { - for {set i $flash_offset} {$i < [expr {$flash_offset + $len}]} {incr i} { - set sector [expr {$i / $rtl8710_flasher_sector_size}] - if {[expr {$rtl8710_flasher_auto_erase_sector != $sector}]} { - echo "erase sector $sector" - rtl8710_flash_sector_erase [expr {$sector * $rtl8710_flasher_sector_size}] - set rtl8710_flasher_auto_erase_sector $sector - } - } - } - rtl8710_flasher_write_block $flash_offset $len - echo "wrote $len bytes" - if {[expr {$rtl8710_flasher_auto_verify != 0}]} { - echo "verify offset $flash_offset" - rtl8710_flasher_verify_block $flash_offset $len - } - } + global rtl8710_flasher_buffer_size rtl8710_flasher_sector_size + global rtl8710_flasher_auto_erase rtl8710_flasher_auto_verify + global rtl8710_flasher_auto_erase_sector + + rtl8710_flasher_init + set size [file size $local_filename] + + for {set offset 0} {$offset < $size} {set offset [expr {$offset + $rtl8710_flasher_buffer_size}]} { + set len [expr {($size - $offset) < $rtl8710_flasher_buffer_size ? ($size - $offset) : $rtl8710_flasher_buffer_size}] + set flash_offset [expr {$loc + $offset}] + + echo "write offset $flash_offset" + rtl8710_flasher_load_block $local_filename $offset $len + + if {$rtl8710_flasher_auto_erase} { + set start_sector [expr {$flash_offset / $rtl8710_flasher_sector_size}] + set end_sector [expr {($flash_offset + $len - 1) / $rtl8710_flasher_sector_size}] + + # erase any new sectors we encounter + for {set sector $start_sector} {$sector <= $end_sector} {incr sector} { + if {$rtl8710_flasher_auto_erase_sector != $sector} { + echo "erase sector $sector" + rtl8710_flash_sector_erase [expr {$sector * $rtl8710_flasher_sector_size}] + set rtl8710_flasher_auto_erase_sector $sector + } + } + } + + rtl8710_flasher_write_block $flash_offset $len + echo "wrote $len bytes" + + if {$rtl8710_flasher_auto_verify} { + echo "verify offset $flash_offset" + rtl8710_flasher_verify_block $flash_offset $len + } + } } proc rtl8710_flash_verify {local_filename loc} { @@ -210,43 +222,28 @@ proc rtl8710_flash_verify {local_filename loc} { } } + proc rtl8710_flash_read_mac {} { - global rtl8710_flasher_mac_address_offset - global rtl8710_flasher_buffer - rtl8710_flasher_init - rtl8710_flasher_read_block $rtl8710_flasher_mac_address_offset 6 - set mac "" - mem2array mac 8 [expr {$rtl8710_flasher_buffer + 0x20}] 6 - set res "MAC address: " - append res [format %02X $mac(0)] - append res ":" [format %02X $mac(1)] - append res ":" [format %02X $mac(2)] - append res ":" [format %02X $mac(3)] - append res ":" [format %02X $mac(4)] - append res ":" [format %02X $mac(5)] - echo $res + global rtl8710_flasher_mac_address_offset rtl8710_flasher_buffer + + rtl8710_flasher_init + rtl8710_flasher_read_block $rtl8710_flasher_mac_address_offset 6 + + set mac [read_memory [expr {$rtl8710_flasher_buffer + 0x20}] 8 6] + set mac_str [join [lmap byte $mac {format %02X $byte}] ":"] + echo "MAC address: $mac_str" } proc rtl8710_flash_auto_erase {on} { - global rtl8710_flasher_auto_erase - if {[expr {$on != 0}]} { - set rtl8710_flasher_auto_erase 1 - echo "auto erase on" - } else { - set rtl8710_flasher_auto_erase 0 - echo "auto erase off" - } + global rtl8710_flasher_auto_erase + set rtl8710_flasher_auto_erase [expr {$on != 0}] + echo "auto erase [expr {$on ? "on" : "off"}]" } proc rtl8710_flash_auto_verify {on} { - global rtl8710_flasher_auto_verify - if {[expr {$on != 0}]} { - set rtl8710_flasher_auto_verify 1 - echo "auto verify on" - } else { - set rtl8710_flasher_auto_verify 0 - echo "auto verify off" - } + global rtl8710_flasher_auto_verify + set rtl8710_flasher_auto_verify [expr {$on != 0}] + echo "auto verify [expr {$on ? "on" : "off"}]" } proc rtl8710_reboot {} { diff --git a/script/rtl8710.ocd b/script/rtl8710.ocd index 2a3f1c5..3e9112b 100644 --- a/script/rtl8710.ocd +++ b/script/rtl8710.ocd @@ -1,8 +1,3 @@ -# -# OpenOCD script for RTL8710 -# Copyright (C) 2016 Rebane, rebane@alkohol.ee -# - source [find target/swj-dp.tcl] if { [info exists CHIPNAME] } { @@ -29,70 +24,29 @@ if { [info exists CPUTAPID] } { set _CPUTAPID 0x2ba01477 } -swj_newdap $_CHIPNAME cpu -irlen 4 -expected-id $_CPUTAPID +swd newdap $_CHIPNAME cpu -irlen 4 -expected-id $_CPUTAPID set _TARGETNAME $_CHIPNAME.cpu -target create $_TARGETNAME cortex_m -endian $_ENDIAN -chain-position $_TARGETNAME +dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu +target create $_TARGETNAME cortex_m -endian $_ENDIAN -dap $_CHIPNAME.dap -$_TARGETNAME configure -work-area-phys 0x10001000 -work-area-size $_WORKAREASIZE -work-area-backup 0 +# todo: get work area from makefile +$_TARGETNAME configure -work-area-phys 0x10001500 -work-area-size $_WORKAREASIZE -work-area-backup 0 -adapter_khz 500 -adapter_nsrst_delay 100 +adapter speed 4000 +adapter srst delay 100 if {![using_hla]} { cortex_m reset_config sysresetreq } -set rtl8710_flasher_firmware_ptr 0x10001000 +$_TARGETNAME configure -event reset-init {amebaz_init} +set rtl8710_flasher_firmware_ptr 0x10001500 set rtl8710_flasher_buffer 0x10008000 -set rtl8710_flasher_buffer_size 262144 +set rtl8710_flasher_buffer_size 204800 set rtl8710_flasher_sector_size 4096 -array set rtl8710_flasher_code { - 0 0xB671B57F 1 0x25FF4B58 2 0x6B196B1A 3 0x7040F042 4 0x69D96318 5 0xF4414E55 - 6 0x69D97480 7 0xF8D361DC 8 0xF8C32120 9 0xF8D35120 10 0xF8C31124 11 0x47B05124 - 12 0x47B04E4F 13 0x47984B4F 14 0x60104A4F 15 0x484F47B0 16 0x60012100 17 0x2C006804 - 18 0x4D4DD0FC 19 0xB93E682E 20 0x60264C49 21 0x47B04E46 22 0x47984B46 23 0xE7ED6020 - 24 0x2B01682B 25 0x4E42D109 26 0x4C4647B0 27 0x47A02006 28 0x47904A45 29 0x47A020C7 - 30 0x682AE00D 31 0xD10E2A02 32 0x47B04E3B 33 0x20064C3F 34 0x483F47A0 35 0x493F4780 - 36 0x68084D3F 37 0x47B047A8 38 0x47A02004 39 0x6828E7CE 40 0xD1132803 41 0x47A04C32 - 42 0x24004838 43 0x4E396805 44 0x68311960 45 0xD206428C 46 0x4B384A37 47 0x221018A1 - 48 0x34104798 49 0x4D2AE7F3 50 0xE7B847A8 51 0x29046829 52 0x2400D11B 53 0x6806482F - 54 0xD2B042B4 55 0x47A84D24 56 0x20064E28 57 0x4B2847B0 58 0x49284798 59 0x680A4B2A - 60 0x18A018E1 61 0xF44F4B2A 62 0x47987280 63 0x200447A8 64 0xF50447B0 65 0x47A87480 - 66 0x682CE7E4 67 0xD1232C05 68 0x47984B17 69 0x4D1F2400 70 0x4294682A 71 0x481BD28F - 72 0x68012210 73 0x18604E1D 74 0x47B04669 75 0x1B19682B 76 0xBF282910 77 0x23002110 - 78 0xD011428B 79 0xF81D4A16 80 0x18A05003 81 0x42B55CC6 82 0x3301D101 83 0x4A15E7F4 - 84 0x60112101 85 0xE7726054 86 0x25014E12 87 0xE76E6035 88 0x47A84D03 89 0xE7D63410 - 90 0x40000200 91 0x100011BD 92 0x100013DD 93 0x10001289 94 0x1000800C 95 0x10008000 - 96 0x10008004 97 0x1000130D 98 0x100013ED 99 0x10008010 100 0x10001335 101 0x10008014 - 102 0x10008020 103 0x10001221 104 0x10001375 105 0x10008008 106 0x6A5A4B03 107 0xD0FB0512 - 108 0x0060F893 109 0xBF004770 110 0x40006000 111 0x6B194B17 112 0xF4416B1A 113 0x63187040 - 114 0x69186919 115 0x0110F041 116 0xF8D36119 117 0x220000C0 118 0x0106F020 119 0x00C0F8D3 - 120 0x10C0F8C3 121 0x00C0F8D3 122 0x0101F040 123 0x00C0F8D3 124 0x10C0F8C3 125 0x43BCF503 - 126 0x609A6899 127 0x20016AD9 128 0x691962DA 129 0x69596118 130 0x61592102 131 0x619A6999 - 132 0x61DA69D9 133 0x64DA6CD9 134 0xBF004770 135 0x40000200 136 0x460EB570 137 0xB34A4614 - 138 0xF3C04B15 139 0x681A4507 140 0x7240F44F 141 0x685A601A 142 0xF3C02103 143 0x2C102207 - 144 0x2410BF28 145 0x605CB2C0 146 0x1060F883 147 0x5060F883 148 0xF8832101 149 0xF8832060 - 150 0x689A0060 151 0x60992500 152 0x47984B08 153 0x35015570 154 0x42A2B2AA 155 0x4804D3F8 - 156 0xF0116A81 157 0xD1FA0301 158 0x60836881 159 0xBD704620 160 0x40006000 161 0x100011A9 - 162 0x4C10B5F8 163 0x68232003 164 0x7340F44F 165 0x68636023 166 0x60602101 167 0x68A3229F - 168 0x60A14D0B 169 0x2060F884 170 0x460647A8 171 0x460747A8 172 0x040347A8 173 0x2707EA43 - 174 0x0006EA47 175 0x4B036AA1 176 0x0201F011 177 0x6899D1FA 178 0xBDF8609A 179 0x40006000 - 180 0x100011A9 181 0x4C0BB510 182 0x68232001 183 0x7340F44F 184 0x68636023 185 0x60602105 - 186 0x60A068A2 187 0xF8844A06 188 0x47901060 189 0x4B036AA1 190 0x0201F011 191 0x6899D1FA - 192 0xBD10609A 193 0x40006000 194 0x100011A9 195 0x21014B08 196 0xF44F681A 197 0x601A7280 - 198 0x6099689A 199 0x0060F883 200 0x48036A9A 201 0x0101F012 202 0x6883D1FA 203 0x47706081 - 204 0x40006000 205 0x21014B0E 206 0xF44F681A 207 0x601A7280 208 0x2220689A 209 0xF8836099 - 210 0xF3C02060 211 0xF3C04107 212 0xB2C02207 213 0x1060F883 214 0x2060F883 215 0x0060F883 - 216 0x4A036A99 217 0x0001F011 218 0x6893D1FA 219 0x47706090 220 0x40006000 221 0xB36AB530 - 222 0x25014B17 223 0xF44F681C 224 0x601C7480 225 0x2402689C 226 0xF883609D 227 0xF3C04060 - 228 0xF3C04507 229 0xB2C02407 230 0x5060F883 231 0x7F80F5B2 232 0xF44FBF28 233 0xF8837280 - 234 0xF8834060 235 0x20000060 236 0x4C095C0D 237 0xF8843001 238 0xB2855060 239 0xD3F74295 - 240 0x07496A99 241 0x6AA0D5FC 242 0xF0104B03 243 0xD1FA0101 244 0x60996898 245 0xBD304610 - 246 0x40006000 247 0x4B02B508 248 0x07C04798 249 0xBD08D4FB 250 0x100012D5 251 0x4B04B508 - 252 0xF0004798 253 0xB2C10002 254 0xD0F82900 255 0xBF00BD08 256 0x100012D5 -} +set rtl8710_flasher_code [list \n0x489fe92d 0x2300b673 0xf04f9303 0x4e604380 0x3210f8d3 0x0f10f013 0x485ed001 0x4c5e47b0 0x4f5f4d5e 0xf44f2200 0x20107180 0x4b5d47a0 0x47982000 0xf44f2201 0x20107180 0x220147a0 0x4b592100 0x200a4c59 0x4b594798 0x47984628 0x20024b58 0xf8954798 0xaa030049 0x47a02103 0x300ef89d 0x200df89d 0x100cf89d 0x47b04852 0x48526829 0x68ab47b0 0x7929796a 0x47b04850 0x7f6a7feb 0x93007f29 0x7fab484e 0x4b4e47b0 0x201c2100 0x484d4798 0x46a147b0 0xf04f4c4c 0xf8c40a00 0x6823a000 0x6863b193 0xd86c2b05 0xf852a201 0xbf00f023 0x100015d5 0x100015e5 0x100015f3 0x10001619 0x1000161d 0x10001685 0xe7e8bf00 0x0049f895 0x2104aa03 0x9b0347c8 0xe7de60e3 0x46082100 0x47984b3a 0x47b0483a 0x6921e7d7 0x20024b37 0xe7d24798 0xf1026922 0x58d16200 0x5280f103 0x4200f502 0x62113304 0x429a6962 0xe7c4d8f2 0xe7f92300 0x482f6961 0xf8df6922 0x47b0b0bc 0x0800f04f 0x45436963 0x482cd801 0x6920e7db 0x0207eb08 0x21044440 0xf10847d8 0xe7f10804 0x0820f108 0x45436963 0x6963d9a7 0x0308eba3 0xbf982b04 0x69206962 0xf1004b21 0xbf946000 0x0208eba2 0xeb082204 0x44400107 0x28004798 0x2301d0e6 0xf8c460a3 0xe78e800c 0x0800f04f 0x2301e7e0 0xe78860a3 0x000004dd 0x10001748 0x00009b65 0x10000dec 0x10008020 0x00007d15 0x000042fd 0x00007465 0x00007b81 0x00007ca1 0x10001778 0x1000179b 0x100017b3 0x100017e6 0x0000784d 0x1000181e 0x10008000 0x00007755 0x10001840 0x10001865 0x00007661 0x1000189c 0x100016ed 0xb4302a03 0xea41d912 0x07a40400 0x460b4684 0x4619d121 0xf8534660 0xf85c4b04 0x42a55b04 0x3a04d119 0xd8f42a03 0x46194660 0xb17a1e54 0x39011e43 0xe0011902 0xd009429a 0x0f01f813 0xcf01f811 0xd0f74560 0x000ceba0 0x4770bc30 0xbc302000 0x1e544770 0xbf00e7ea 0x414c465b 0x52454853 0x6c46205d 0x20687361 0x69726570 0x72656870 0x61206c61 0x6165726c 0x65207964 0x6c62616e 0x2e2e6465 0x000a3f2e 0x414c465b 0x205d4853 0x69766544 0x49206563 0x25203a44 0x20583230 0x58323025 0x32302520 0x5b000a58 0x53414c46 0x56205d48 0x6f646e65 0x30203a72 0x38302578 0x5b000a58 0x53414c46 0x43205d48 0x69666e6f 0x4d203a67 0x3d65646f 0x202c6425 0x636f6c43 0x64253d6b 0x6552202c 0x6d436461 0x78303d64 0x58323025 0x465b000a 0x4853414c 0x6954205d 0x676e696d 0x6153203a 0x656c706d 0x616c6544 0x64253d79 0x7544202c 0x43796d6d 0x656c6379 0x255b3d73 0x64252c64 0x5d64252c 0x465b000a 0x4853414c 0x6c42205d 0x206b636f 0x746f7270 0x69746365 0x63206e6f 0x7261656c 0x000a6465 0x414c465b 0x52454853 0x7546205d 0x63206c6c 0x20706968 0x73617265 0x6f632065 0x656c706d 0x0a646574 0x4c465b00 0x45485341 0x53205d52 0x74726174 0x20676e69 0x74697277 0x666f2065 0x20642520 0x65747962 0x74612073 0x66666f20 0x20746573 0x30257830 0x000a5838 0x414c465b 0x52454853 0x7257205d 0x20657469 0x706d6f63 0x6574656c 0x75732064 0x73656363 0x6c756673 0x000a796c ] set rtl8710_flasher_command_read_id 0 set rtl8710_flasher_command_mass_erase 1 @@ -110,183 +64,195 @@ set rtl8710_flasher_auto_verify 0 set rtl8710_flasher_auto_erase_sector 0xFFFFFFFF proc rtl8710_flasher_init {} { - global rtl8710_flasher_firmware_ptr - global rtl8710_flasher_buffer - global rtl8710_flasher_capacity - global rtl8710_flasher_ready - global rtl8710_flasher_code + global rtl8710_flasher_ready rtl8710_flasher_firmware_ptr + global rtl8710_flasher_buffer rtl8710_flasher_capacity + global rtl8710_flasher_code - if {[expr {$rtl8710_flasher_ready == 0}]} { - echo "initializing RTL8710 flasher" - halt - mww [expr {$rtl8710_flasher_buffer + 0x08}] 0x00000000 - mww [expr {$rtl8710_flasher_buffer + 0x00}] 0x00000001 - array2mem rtl8710_flasher_code 32 $rtl8710_flasher_firmware_ptr [array size rtl8710_flasher_code] - reg faultmask 0x01 - reg sp 0x20000000 - reg pc $rtl8710_flasher_firmware_ptr - resume - rtl8710_flasher_wait - set id [rtl8710_flasher_mrw [expr {$rtl8710_flasher_buffer + 0x0C}]] - set rtl8710_flasher_capacity [expr {2 ** [expr {($id >> 16) & 0xFF}]}] - set rtl8710_flasher_ready 1 - echo "RTL8710 flasher initialized" - } - return "" + if {!$rtl8710_flasher_ready} { + set buf_ctrl [expr {$rtl8710_flasher_buffer + 0x00}] + set buf_status [expr {$rtl8710_flasher_buffer + 0x08}] + set buf_id [expr {$rtl8710_flasher_buffer + 0x0C}] + + halt + # init buffer control regs + mww $buf_status 0 + mww $buf_ctrl 1 + + # load and start flasher + write_memory $rtl8710_flasher_firmware_ptr 32 $rtl8710_flasher_code + reg faultmask 1 + reg sp 0x1003ef00 + reg pc $rtl8710_flasher_firmware_ptr + resume + rtl8710_flasher_wait + + set id [rtl8710_flasher_mrw $buf_id] + set rtl8710_flasher_capacity [expr {1 << (($id >> 16) & 0xFF)}] + set rtl8710_flasher_ready 1 + } } proc rtl8710_flasher_mrw {reg} { - set value "" - mem2array value 32 $reg 1 - return $value(0) + read_memory $reg 32 1 } proc rtl8710_flasher_wait {} { - global rtl8710_flasher_buffer - while {[rtl8710_flasher_mrw [expr {$rtl8710_flasher_buffer + 0x00}]]} { } + global rtl8710_flasher_buffer + set addr [expr {$rtl8710_flasher_buffer + 0x00}] + while {[rtl8710_flasher_mrw $addr]} {} } -proc rtl8710_flasher_load_block {local_filename offset len} { - global rtl8710_flasher_buffer - load_image $local_filename [expr {$rtl8710_flasher_buffer + 0x20 - $offset}] bin [expr {$rtl8710_flasher_buffer + 0x20}] $len +proc rtl8710_flasher_load_block {local_filename offset length} { + global rtl8710_flasher_buffer + set buffer_addr [expr {$rtl8710_flasher_buffer + 0x20}] + load_image $local_filename [expr {$buffer_addr - $offset}] bin $buffer_addr $length +} + +proc rtl8710_flasher_block {command offset len} { + global rtl8710_flasher_buffer + global rtl8710_flasher_command_read rtl8710_flasher_command_write rtl8710_flasher_command_verify + + # select command type + switch $command { + "read" {set cmd_type $rtl8710_flasher_command_read} + "write" {set cmd_type $rtl8710_flasher_command_write} + "verify" {set cmd_type $rtl8710_flasher_command_verify} + default {error "Unknown command type: $command"} + } + + mww [expr {$rtl8710_flasher_buffer + 0x04}] $cmd_type + mww [expr {$rtl8710_flasher_buffer + 0x08}] 0x00000000 + mww [expr {$rtl8710_flasher_buffer + 0x10}] $offset + mww [expr {$rtl8710_flasher_buffer + 0x14}] $len + mww [expr {$rtl8710_flasher_buffer + 0x00}] 0x00000001 + rtl8710_flasher_wait + + set status [rtl8710_flasher_mrw [expr {$rtl8710_flasher_buffer + 0x08}]] + if {[expr {$status > 0}]} { + if {$command eq "verify"} { + set status [rtl8710_flasher_mrw [expr {$rtl8710_flasher_buffer + 0x0C}]] + set status [expr {$status + $offset}] + } + error "$command error, offset $status" + } } proc rtl8710_flasher_read_block {offset len} { - global rtl8710_flasher_buffer - global rtl8710_flasher_command_read - mww [expr {$rtl8710_flasher_buffer + 0x04}] $rtl8710_flasher_command_read - mww [expr {$rtl8710_flasher_buffer + 0x08}] 0x00000000 - mww [expr {$rtl8710_flasher_buffer + 0x10}] $offset - mww [expr {$rtl8710_flasher_buffer + 0x14}] $len - mww [expr {$rtl8710_flasher_buffer + 0x00}] 0x00000001 - rtl8710_flasher_wait - set status [rtl8710_flasher_mrw [expr {$rtl8710_flasher_buffer + 0x08}]] - if {[expr {$status > 0}]} { - error "read error, offset $offset" - } + rtl8710_flasher_block "read" $offset $len } proc rtl8710_flasher_write_block {offset len} { - global rtl8710_flasher_buffer - global rtl8710_flasher_command_write - mww [expr {$rtl8710_flasher_buffer + 0x04}] $rtl8710_flasher_command_write - mww [expr {$rtl8710_flasher_buffer + 0x08}] 0x00000000 - mww [expr {$rtl8710_flasher_buffer + 0x10}] $offset - mww [expr {$rtl8710_flasher_buffer + 0x14}] $len - mww [expr {$rtl8710_flasher_buffer + 0x00}] 0x00000001 - rtl8710_flasher_wait - set status [rtl8710_flasher_mrw [expr {$rtl8710_flasher_buffer + 0x08}]] - if {[expr {$status > 0}]} { - error "write error, offset $offset" - } + rtl8710_flasher_block "write" $offset $len } proc rtl8710_flasher_verify_block {offset len} { - global rtl8710_flasher_buffer - global rtl8710_flasher_command_verify - mww [expr {$rtl8710_flasher_buffer + 0x04}] $rtl8710_flasher_command_verify - mww [expr {$rtl8710_flasher_buffer + 0x08}] 0x00000000 - mww [expr {$rtl8710_flasher_buffer + 0x10}] $offset - mww [expr {$rtl8710_flasher_buffer + 0x14}] $len - mww [expr {$rtl8710_flasher_buffer + 0x00}] 0x00000001 - rtl8710_flasher_wait - set status [rtl8710_flasher_mrw [expr {$rtl8710_flasher_buffer + 0x08}]] - if {[expr {$status > 0}]} { - set status [rtl8710_flasher_mrw [expr {$rtl8710_flasher_buffer + 0x0C}]] - set status [expr {$status + $offset}] - error "verify error, offset $status" - } + rtl8710_flasher_block "verify" $offset $len } proc rtl8710_flash_read_id {} { - global rtl8710_flasher_buffer - global rtl8710_flasher_capacity - global rtl8710_flasher_command_read_id - rtl8710_flasher_init - mww [expr {$rtl8710_flasher_buffer + 0x04}] $rtl8710_flasher_command_read_id - mww [expr {$rtl8710_flasher_buffer + 0x08}] 0x00000000 - mww [expr {$rtl8710_flasher_buffer + 0x00}] 0x00000001 - rtl8710_flasher_wait - set id [rtl8710_flasher_mrw [expr {$rtl8710_flasher_buffer + 0x0C}]] - set manufacturer_id [format "0x%02X" [expr {$id & 0xFF}]] - set memory_type [format "0x%02X" [expr {($id >> 8) & 0xFF}]] - set memory_capacity [expr {2 ** [expr {($id >> 16) & 0xFF}]}] - echo "manufacturer ID: $manufacturer_id, memory type: $memory_type, memory capacity: $memory_capacity bytes" + global rtl8710_flasher_buffer rtl8710_flasher_capacity + global rtl8710_flasher_command_read_id + + rtl8710_flasher_init + + # send read ID command + mww [expr {$rtl8710_flasher_buffer + 0x04}] $rtl8710_flasher_command_read_id + mww [expr {$rtl8710_flasher_buffer + 0x08}] 0 + mww [expr {$rtl8710_flasher_buffer + 0x00}] 1 + rtl8710_flasher_wait + + set id [rtl8710_flasher_mrw [expr {$rtl8710_flasher_buffer + 0x0C}]] + + set manufacturer_id [format "0x%02X" [expr {$id & 0xFF}]] + set memory_type [format "0x%02X" [expr {($id >> 8) & 0xFF}]] + set memory_capacity [expr {2 ** (($id >> 16) & 0xFF)}] + + echo "manufacturer ID: $manufacturer_id, memory type: $memory_type, memory capacity: $memory_capacity bytes" +} + +proc rtl8710_flash_erase {type {offset 0}} { + global rtl8710_flasher_buffer + global rtl8710_flasher_command_mass_erase rtl8710_flasher_command_sector_erase + + rtl8710_flasher_init + + if {$type eq "mass"} { + set cmd $rtl8710_flasher_command_mass_erase + } elseif {$type eq "sector"} { + set cmd $rtl8710_flasher_command_sector_erase + mww [expr {$rtl8710_flasher_buffer + 0x10}] $offset + } else { + error "Unknown erase type: $type" + } + + mww [expr {$rtl8710_flasher_buffer + 0x04}] $cmd + mww [expr {$rtl8710_flasher_buffer + 0x08}] 0 + mww [expr {$rtl8710_flasher_buffer + 0x00}] 1 + rtl8710_flasher_wait } proc rtl8710_flash_mass_erase {} { - global rtl8710_flasher_buffer - global rtl8710_flasher_command_mass_erase - rtl8710_flasher_init - mww [expr {$rtl8710_flasher_buffer + 0x04}] $rtl8710_flasher_command_mass_erase - mww [expr {$rtl8710_flasher_buffer + 0x08}] 0x00000000 - mww [expr {$rtl8710_flasher_buffer + 0x00}] 0x00000001 - rtl8710_flasher_wait + rtl8710_flash_erase "mass" } proc rtl8710_flash_sector_erase {offset} { - global rtl8710_flasher_buffer - global rtl8710_flasher_command_sector_erase - rtl8710_flasher_init - mww [expr {$rtl8710_flasher_buffer + 0x04}] $rtl8710_flasher_command_sector_erase - mww [expr {$rtl8710_flasher_buffer + 0x08}] 0x00000000 - mww [expr {$rtl8710_flasher_buffer + 0x10}] $offset - mww [expr {$rtl8710_flasher_buffer + 0x00}] 0x00000001 - rtl8710_flasher_wait + rtl8710_flash_erase "sector" $offset } proc rtl8710_flash_read {local_filename loc size} { - global rtl8710_flasher_buffer - global rtl8710_flasher_buffer_size - rtl8710_flasher_init - for {set offset 0} {$offset < $size} {set offset [expr {$offset + $rtl8710_flasher_buffer_size}]} { - set len [expr {$size - $offset}] - if {[expr {$len > $rtl8710_flasher_buffer_size}]} { - set len $rtl8710_flasher_buffer_size - } - set flash_offset [expr {$loc + $offset}] - echo "read offset $flash_offset" - rtl8710_flasher_read_block $flash_offset $len - dump_image /tmp/_rtl8710_flasher.bin [expr {$rtl8710_flasher_buffer + 0x20}] $len - exec dd conv=notrunc if=/tmp/_rtl8710_flasher.bin "of=$local_filename" bs=1 "seek=$offset" + global rtl8710_flasher_buffer rtl8710_flasher_buffer_size + rtl8710_flasher_init + + set tmp "/tmp/_rtl8710_flasher.bin" + for {set offset 0} {$offset < $size} {set offset [expr {$offset + $rtl8710_flasher_buffer_size}]} { + set len [expr {($size - $offset) < $rtl8710_flasher_buffer_size ? ($size - $offset) : $rtl8710_flasher_buffer_size}] + set flash_offset [expr {$loc + $offset}] + echo "read $flash_offset" + rtl8710_flasher_read_block $flash_offset $len + dump_image $tmp [expr {$rtl8710_flasher_buffer + 0x20}] $len + exec dd conv=notrunc if=$tmp of=$local_filename bs=1 seek=$offset echo "read $len bytes" - } + } + file delete -force $tmp } proc rtl8710_flash_write {local_filename loc} { - global rtl8710_flasher_buffer_size - global rtl8710_flasher_sector_size - global rtl8710_flasher_auto_erase - global rtl8710_flasher_auto_verify - global rtl8710_flasher_auto_erase_sector - rtl8710_flasher_init - set sector 0 - set size [file size $local_filename] - for {set offset 0} {$offset < $size} {set offset [expr {$offset + $rtl8710_flasher_buffer_size}]} { - set len [expr {$size - $offset}] - if {[expr {$len > $rtl8710_flasher_buffer_size}]} { - set len $rtl8710_flasher_buffer_size - } - set flash_offset [expr {$loc + $offset}] - echo "write offset $flash_offset" - rtl8710_flasher_load_block $local_filename $offset $len - if {[expr {$rtl8710_flasher_auto_erase != 0}]} { - for {set i $flash_offset} {$i < [expr {$flash_offset + $len}]} {incr i} { - set sector [expr {$i / $rtl8710_flasher_sector_size}] - if {[expr {$rtl8710_flasher_auto_erase_sector != $sector}]} { - echo "erase sector $sector" - rtl8710_flash_sector_erase [expr {$sector * $rtl8710_flasher_sector_size}] - set rtl8710_flasher_auto_erase_sector $sector - } - } - } - rtl8710_flasher_write_block $flash_offset $len - echo "wrote $len bytes" - if {[expr {$rtl8710_flasher_auto_verify != 0}]} { - echo "verify offset $flash_offset" - rtl8710_flasher_verify_block $flash_offset $len - } - } + global rtl8710_flasher_buffer_size rtl8710_flasher_sector_size + global rtl8710_flasher_auto_erase rtl8710_flasher_auto_verify + global rtl8710_flasher_auto_erase_sector + + rtl8710_flasher_init + set size [file size $local_filename] + + for {set offset 0} {$offset < $size} {set offset [expr {$offset + $rtl8710_flasher_buffer_size}]} { + set len [expr {($size - $offset) < $rtl8710_flasher_buffer_size ? ($size - $offset) : $rtl8710_flasher_buffer_size}] + set flash_offset [expr {$loc + $offset}] + + echo "write offset $flash_offset" + rtl8710_flasher_load_block $local_filename $offset $len + + if {$rtl8710_flasher_auto_erase} { + set start_sector [expr {$flash_offset / $rtl8710_flasher_sector_size}] + set end_sector [expr {($flash_offset + $len - 1) / $rtl8710_flasher_sector_size}] + + # erase any new sectors we encounter + for {set sector $start_sector} {$sector <= $end_sector} {incr sector} { + if {$rtl8710_flasher_auto_erase_sector != $sector} { + echo "erase sector $sector" + rtl8710_flash_sector_erase [expr {$sector * $rtl8710_flasher_sector_size}] + set rtl8710_flasher_auto_erase_sector $sector + } + } + } + + rtl8710_flasher_write_block $flash_offset $len + echo "wrote $len bytes" + + if {$rtl8710_flasher_auto_verify} { + echo "verify offset $flash_offset" + rtl8710_flasher_verify_block $flash_offset $len + } + } } proc rtl8710_flash_verify {local_filename loc} { @@ -306,43 +272,28 @@ proc rtl8710_flash_verify {local_filename loc} { } } + proc rtl8710_flash_read_mac {} { - global rtl8710_flasher_mac_address_offset - global rtl8710_flasher_buffer - rtl8710_flasher_init - rtl8710_flasher_read_block $rtl8710_flasher_mac_address_offset 6 - set mac "" - mem2array mac 8 [expr {$rtl8710_flasher_buffer + 0x20}] 6 - set res "MAC address: " - append res [format %02X $mac(0)] - append res ":" [format %02X $mac(1)] - append res ":" [format %02X $mac(2)] - append res ":" [format %02X $mac(3)] - append res ":" [format %02X $mac(4)] - append res ":" [format %02X $mac(5)] - echo $res + global rtl8710_flasher_mac_address_offset rtl8710_flasher_buffer + + rtl8710_flasher_init + rtl8710_flasher_read_block $rtl8710_flasher_mac_address_offset 6 + + set mac [read_memory [expr {$rtl8710_flasher_buffer + 0x20}] 8 6] + set mac_str [join [lmap byte $mac {format %02X $byte}] ":"] + echo "MAC address: $mac_str" } proc rtl8710_flash_auto_erase {on} { - global rtl8710_flasher_auto_erase - if {[expr {$on != 0}]} { - set rtl8710_flasher_auto_erase 1 - echo "auto erase on" - } else { - set rtl8710_flasher_auto_erase 0 - echo "auto erase off" - } + global rtl8710_flasher_auto_erase + set rtl8710_flasher_auto_erase [expr {$on != 0}] + echo "auto erase [expr {$on ? "on" : "off"}]" } proc rtl8710_flash_auto_verify {on} { - global rtl8710_flasher_auto_verify - if {[expr {$on != 0}]} { - set rtl8710_flasher_auto_verify 1 - echo "auto verify on" - } else { - set rtl8710_flasher_auto_verify 0 - echo "auto verify off" - } + global rtl8710_flasher_auto_verify + set rtl8710_flasher_auto_verify [expr {$on != 0}] + echo "auto verify [expr {$on ? "on" : "off"}]" } proc rtl8710_reboot {} { diff --git a/spi_flash.c b/spi_flash.c deleted file mode 100644 index d17d92e..0000000 --- a/spi_flash.c +++ /dev/null @@ -1,146 +0,0 @@ -/* - * - * Copyright (C) 2016 Rebane, rebane@alkohol.ee - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin - * Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - */ - -#include "spi_flash.h" -#include "rtl8710.h" -#include "mask.h" - -static void spi_flash_send(uint8_t byte){ - // while(!(SPI_FLASH->SR & SPI_SR_TFNF)); - SPI_FLASH->DR = byte; -} - -static uint8_t spi_flash_recv(){ - while(!(SPI_FLASH->RXFLR & 0x0FFF)); - return(SPI_FLASH->DR); -} - -void spi_flash_init(){ - PERI_ON->PESOC_CLK_CTRL |= PERI_ON_CLK_CTRL_ACTCK_FLASH_EN | PERI_ON_CLK_CTRL_SLPCK_FLASH_EN; // enable spi flash peripheral clock - PERI_ON->SOC_FUNC_EN |= PERI_ON_SOC_FUNC_EN_FLASH; // enable spi flash peripheral - mask32_set(PERI_ON->CPU_PERIPHERAL_CTRL, PERI_ON_CPU_PERIPHERAL_CTRL_SPI_FLASH_PIN_SEL, 0); // select spi flash pinout (0 - internal) - PERI_ON->CPU_PERIPHERAL_CTRL |= PERI_ON_CPU_PERIPHERAL_CTRL_SPI_FLASH_PIN_EN; // enable spi flash pins - - SPI_FLASH->SSIENR = 0; // disable SPI FLASH operation - SPI_FLASH->IMR = 0; // disable all interrupts - SPI_FLASH->SER = SPI_SER_SS0; // use first "slave select" pin - SPI_FLASH->BAUDR = 2; // baud rate, default value - SPI_FLASH->TXFTLR = 0; // tx fifo threshold - SPI_FLASH->RXFTLR = 0; // rx fifo threshold - SPI_FLASH->DMACR = 0; // disable DMA -} - -uint16_t spi_flash_read(uint32_t address, void *buf, uint16_t count){ - uint16_t i; - if(!count)return(0); - if(count > 16)count = 16; - SPI_FLASH->CTRLR0 = mask32(SPI_CTRLR0_TMOD, 3) | mask32(SPI_CTRLR0_CMD_CH, 0) | mask32(SPI_CTRLR0_ADDR_CH, 0) | mask32(SPI_CTRLR0_DATA_CH, 0); - SPI_FLASH->CTRLR1 = count; - - spi_flash_send(0x03); // flash command "read" - spi_flash_send((address >> 16) & 0xFF); // address * 3 - spi_flash_send((address >> 8) & 0xFF); - spi_flash_send((address >> 0) & 0xFF); - - SPI_FLASH->SSIENR = 1; - - for(i = 0; i < count; i++){ - ((uint8_t *)buf)[i] = spi_flash_recv(); - } - while(SPI_FLASH->SR & SPI_SR_SSI); - SPI_FLASH->SSIENR = 0; - return(count); -} - -uint32_t spi_flash_jedec_id(){ - uint32_t id; - SPI_FLASH->CTRLR0 = mask32(SPI_CTRLR0_TMOD, 3) | mask32(SPI_CTRLR0_CMD_CH, 0) | mask32(SPI_CTRLR0_ADDR_CH, 0) | mask32(SPI_CTRLR0_DATA_CH, 0); - SPI_FLASH->CTRLR1 = 3; - - SPI_FLASH->SSIENR = 1; - spi_flash_send(0x9F); // jedec id - id = spi_flash_recv(); - id |= ((uint32_t)spi_flash_recv() << 8); - id |= ((uint32_t)spi_flash_recv() << 16); - while(SPI_FLASH->SR & SPI_SR_SSI); - SPI_FLASH->SSIENR = 0; - return(id); -} - -uint8_t spi_flash_status(){ - uint8_t status; - SPI_FLASH->CTRLR0 = mask32(SPI_CTRLR0_TMOD, 3) | mask32(SPI_CTRLR0_CMD_CH, 0) | mask32(SPI_CTRLR0_ADDR_CH, 0) | mask32(SPI_CTRLR0_DATA_CH, 0); - SPI_FLASH->CTRLR1 = 1; - - SPI_FLASH->SSIENR = 1; - spi_flash_send(0x05); // read status - status = spi_flash_recv(); - while(SPI_FLASH->SR & SPI_SR_SSI); - SPI_FLASH->SSIENR = 0; - return(status); -} - -void spi_flash_cmd(uint8_t cmd){ - SPI_FLASH->CTRLR0 = mask32(SPI_CTRLR0_TMOD, 1) | mask32(SPI_CTRLR0_CMD_CH, 0) | mask32(SPI_CTRLR0_ADDR_CH, 0) | mask32(SPI_CTRLR0_DATA_CH, 0); - - SPI_FLASH->SSIENR = 1; - spi_flash_send(cmd); - while(SPI_FLASH->SR & SPI_SR_SSI); - SPI_FLASH->SSIENR = 0; -} - -void spi_flash_sector_erase(uint32_t address){ - SPI_FLASH->CTRLR0 = mask32(SPI_CTRLR0_TMOD, 1) | mask32(SPI_CTRLR0_CMD_CH, 0) | mask32(SPI_CTRLR0_ADDR_CH, 0) | mask32(SPI_CTRLR0_DATA_CH, 0); - - SPI_FLASH->SSIENR = 1; - spi_flash_send(0x20); // sector erase - spi_flash_send((address >> 16) & 0xFF); - spi_flash_send((address >> 8) & 0xFF); - spi_flash_send((address >> 0) & 0xFF); - while(SPI_FLASH->SR & SPI_SR_SSI); - SPI_FLASH->SSIENR = 0; -} - -uint16_t spi_flash_write(uint32_t address, const void *buf, uint16_t count){ - uint16_t i; - if(!count)return(0); - if(count > 256)count = 256; - SPI_FLASH->CTRLR0 = mask32(SPI_CTRLR0_TMOD, 1) | mask32(SPI_CTRLR0_CMD_CH, 0) | mask32(SPI_CTRLR0_ADDR_CH, 0) | mask32(SPI_CTRLR0_DATA_CH, 0); - - SPI_FLASH->SSIENR = 1; - spi_flash_send(0x02); // write - spi_flash_send((address >> 16) & 0xFF); - spi_flash_send((address >> 8) & 0xFF); - spi_flash_send((address >> 0) & 0xFF); - for(i = 0; i < count; i++){ - spi_flash_send(((uint8_t *)buf)[i]); - } - while(!(SPI_FLASH->SR & SPI_SR_TFE)); - while(SPI_FLASH->SR & SPI_SR_SSI); - SPI_FLASH->SSIENR = 0; - return(count); -} - -void spi_flash_wait_busy(){ - while(spi_flash_status() & 0x01); -} - -void spi_flash_wait_wel(){ - while(!(spi_flash_status() & 0x02)); -} - diff --git a/spi_flash.h b/spi_flash.h deleted file mode 100644 index 1538a8a..0000000 --- a/spi_flash.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * - * Copyright (C) 2016 Rebane, rebane@alkohol.ee - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin - * Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - */ - -#ifndef _SPI_FLASH_H_ -#define _SPI_FLASH_H_ - -#include - -void spi_flash_init(); -uint16_t spi_flash_read(uint32_t address, void *buf, uint16_t count); -uint16_t spi_flash_write(uint32_t address, const void *buf, uint16_t count); -uint32_t spi_flash_jedec_id(); -uint8_t spi_flash_status(); -void spi_flash_cmd(uint8_t cmd); -void spi_flash_sector_erase(uint32_t address); -void spi_flash_wait_busy(); -void spi_flash_wait_wel(); - -#endif -