From 85880c1ce9c5f087c1176f60b9fc68112ffdb9ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Fri, 22 Apr 2022 19:36:23 +0200 Subject: [PATCH] Update project structure --- boards/wr3.json | 6 +- boards/wr3/bin/boot_all.bin | Bin 0 -> 4620 bytes boards/wr3/bin/descript.ion | 1 + boards/wr3/ld/export-rom_symbol_v01.txt | 1427 +++++++++++++++++ .../wr3/ld/rlx8711B-symbol-v02-img2_xip1.ld | 157 ++ .../ld/rlx8711B-symbol-v02-img2_xip1_2M.ld | 157 ++ .../wr3/ld/rlx8711B-symbol-v02-img2_xip2.ld | 157 ++ .../ld/rlx8711B-symbol-v02-img2_xip2_2M.ld | 157 ++ builder/frameworks/realtek-ambz-sdk.py | 101 +- builder/main.py | 11 +- fixups/realtek-ambz/app_start_patch.c | 118 ++ fixups/realtek-ambz/cmsis_ipsr.c | 9 + fixups/realtek-ambz/log_uart.c | 28 + fixups/realtek-ambz/wifi_mode.c | 4 + platform.json | 5 +- platform.py | 2 +- 16 files changed, 2273 insertions(+), 67 deletions(-) create mode 100644 boards/wr3/bin/boot_all.bin create mode 100644 boards/wr3/bin/descript.ion create mode 100644 boards/wr3/ld/export-rom_symbol_v01.txt create mode 100644 boards/wr3/ld/rlx8711B-symbol-v02-img2_xip1.ld create mode 100644 boards/wr3/ld/rlx8711B-symbol-v02-img2_xip1_2M.ld create mode 100644 boards/wr3/ld/rlx8711B-symbol-v02-img2_xip2.ld create mode 100644 boards/wr3/ld/rlx8711B-symbol-v02-img2_xip2_2M.ld create mode 100644 fixups/realtek-ambz/app_start_patch.c create mode 100644 fixups/realtek-ambz/cmsis_ipsr.c create mode 100644 fixups/realtek-ambz/log_uart.c create mode 100644 fixups/realtek-ambz/wifi_mode.c diff --git a/boards/wr3.json b/boards/wr3.json index 0f90f24..89ba24f 100644 --- a/boards/wr3.json +++ b/boards/wr3.json @@ -1,9 +1,13 @@ { "build": { "mcu": "rtl8710bn", + "family": "rtl8710", + "variant": "wr3", + "ldscript_sdk": "rlx8711B-symbol-v02-img2_xip1_2M.ld", "f_cpu": "125000000L", "amb_ota1_offset": "0x0800B000", - "amb_ota2_offset": "0x080D0000" + "amb_ota2_offset": "0x080D0000", + "amb_boot_all": "boot_all.bin" }, "frameworks": [ "realtek-ambz-sdk" diff --git a/boards/wr3/bin/boot_all.bin b/boards/wr3/bin/boot_all.bin new file mode 100644 index 0000000000000000000000000000000000000000..5160f9111c1aebc3226deace0acbdc2fcb966163 GIT binary patch literal 4620 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 yaQ;#i6q8`|nifFSI*1VOZJ^Z}iPjElsP(b@jw ROM + .rom.rodata : { } > ROM + .hal.rom.bss : { } > ROMBSS_RAM + + /* image1 entry, this section should in RAM and fixed address for ROM */ + .ram_image1.entry : + { + __ram_image1_text_start__ = .; + __ram_start_table_start__ = .; + KEEP(*(SORT(.image1.entry.data*))) + __ram_start_table_end__ = .; + + __image1_validate_code__ = .; + KEEP(*(.image1.validate.rodata*)) + KEEP(*(.image1.export.symb*)) + } > BOOTLOADER_RAM + + /* Add . to assign the start address of the section */ + /* to prevent the change of the start address by ld doing section alignment */ + .ram_image1.text . : + { + /* image1 text */ + *(.boot.ram.text*) + *(.boot.rodata*) + } > BOOTLOADER_RAM + + .ram_image1.data . : + { + __ram_image1_data_start__ = .; + KEEP(*(.boot.ram.data*)) + __ram_image1_data_end__ = .; + + __ram_image1_text_end__ = .; + } > BOOTLOADER_RAM + + .ram_image1.bss . : + { + __image1_bss_start__ = .; + KEEP(*(.boot.ram.bss*)) + KEEP(*(.boot.ram.end.bss*)) + __image1_bss_end__ = .; + } > BOOTLOADER_RAM + + .ram_image2.entry : + { + __ram_image2_text_start__ = .; + __image2_entry_func__ = .; + KEEP(*(SORT(.image2.entry.data*))) + + __image2_validate_code__ = .; + KEEP(*(.image2.validate.rodata*)) + + } > BD_RAM + + .ram_image2.text : + { + KEEP(*(.image2.ram.text*)) + } > BD_RAM + + .ram_image2.data : + { + __data_start__ = .; + *(.data*) + __data_end__ = .; + __ram_image2_text_end__ = .; + . = ALIGN(16); + } > BD_RAM + + .ram_image2.bss : + { + __bss_start__ = .; + *(.bss*) + *(COMMON) + } > BD_RAM + + .ram_image2.skb.bss : + { + *(.bdsram.data*) + __bss_end__ = .; + } > BD_RAM + + .ram_heap.data : + { + *(.bfsram.data*) + *(.heap.stdlib*) + + } > BD_RAM + + .ram_rdp.text : + { + __rom_top_4k_start_ = .; + __rdp_text_start__ = .; + KEEP(*(.rdp.ram.text*)) + KEEP(*(.rdp.ram.data*)) + __rdp_text_end__ = .; + . = ALIGN(16); + + } > RDP_RAM + + .xip_image1.text : + { + __flash_boot_text_start__ = .; + + *(.flashboot.text*) + + __flash_boot_text_end__ = .; + + . = ALIGN(16); + } > XIPBOOT + + .xip_image2.text : + { + __flash_text_start__ = .; + + *(.img2_custom_signature*) + + *(.text*) + *(.rodata*) + *(.debug_trace*) + + __flash_text_end__ = .; + + . = ALIGN (16); + } > XIP1 +} + +SECTIONS +{ + /* Bootloader symbol list */ + boot_export_symbol = 0x10002020; +} diff --git a/boards/wr3/ld/rlx8711B-symbol-v02-img2_xip1_2M.ld b/boards/wr3/ld/rlx8711B-symbol-v02-img2_xip1_2M.ld new file mode 100644 index 0000000..c95cd66 --- /dev/null +++ b/boards/wr3/ld/rlx8711B-symbol-v02-img2_xip1_2M.ld @@ -0,0 +1,157 @@ + + +ENTRY(Reset_Handler) + +INCLUDE "export-rom_symbol_v01.txt" + +MEMORY +{ + ROM (rx) : ORIGIN = 0x00000000, LENGTH = 0x80000 /* ROM: 512k */ + ROMBSS_RAM (rw) : ORIGIN = 0x10000000, LENGTH = 0x2000 /* ROM BSS RAM: 8K */ + BOOTLOADER_RAM (rwx) : ORIGIN = 0x10002000, LENGTH = 0x3000 /* BOOT Loader RAM: 12K */ + BD_RAM (rwx) : ORIGIN = 0x10005000, LENGTH = 0x39000 /* MAIN RAM: 228 */ + MSP_RAM (wx) : ORIGIN = 0x1003E000, LENGTH = 0x1000 /* MSP RAM: 4k */ + RDP_RAM (wx) : ORIGIN = 0x1003F000, LENGTH = 0xFF0 /* RDP RAM: 4k-0x10 */ + + XIPBOOT (rx) : ORIGIN = 0x08000000+0x20, LENGTH = 0x04000-0x20 /* XIPBOOT: 32k, 32 Bytes resvd for header*/ + XIPSYS (r) : ORIGIN = 0x08009000, LENGTH = 0x1000 /* XIPSYS: 4K system data in flash */ + XIPCAL (r) : ORIGIN = 0x0800A000, LENGTH = 0x1000 /* XIPCAL: 4K calibration data in flash */ + XIP1 (rx) : ORIGIN = 0x0800B000+0x20, LENGTH = 0xC5000-0x20 /* XIP1: 2*468k, 32 Bytes resvd for header */ + XIP2 (rx) : ORIGIN = 0x080D0000+0x20, LENGTH = 0xC5000-0x20 /* XIP2: 2*468k, 32 Bytes resvd for header */ +} + + + +SECTIONS +{ + .rom.text : { } > ROM + .rom.rodata : { } > ROM + .hal.rom.bss : { } > ROMBSS_RAM + + /* image1 entry, this section should in RAM and fixed address for ROM */ + .ram_image1.entry : + { + __ram_image1_text_start__ = .; + __ram_start_table_start__ = .; + KEEP(*(SORT(.image1.entry.data*))) + __ram_start_table_end__ = .; + + __image1_validate_code__ = .; + KEEP(*(.image1.validate.rodata*)) + KEEP(*(.image1.export.symb*)) + } > BOOTLOADER_RAM + + /* Add . to assign the start address of the section */ + /* to prevent the change of the start address by ld doing section alignment */ + .ram_image1.text . : + { + /* image1 text */ + *(.boot.ram.text*) + *(.boot.rodata*) + } > BOOTLOADER_RAM + + .ram_image1.data . : + { + __ram_image1_data_start__ = .; + KEEP(*(.boot.ram.data*)) + __ram_image1_data_end__ = .; + + __ram_image1_text_end__ = .; + } > BOOTLOADER_RAM + + .ram_image1.bss . : + { + __image1_bss_start__ = .; + KEEP(*(.boot.ram.bss*)) + KEEP(*(.boot.ram.end.bss*)) + __image1_bss_end__ = .; + } > BOOTLOADER_RAM + + .ram_image2.entry : + { + __ram_image2_text_start__ = .; + __image2_entry_func__ = .; + KEEP(*(SORT(.image2.entry.data*))) + + __image2_validate_code__ = .; + KEEP(*(.image2.validate.rodata*)) + + } > BD_RAM + + .ram_image2.text : + { + KEEP(*(.image2.ram.text*)) + } > BD_RAM + + .ram_image2.data : + { + __data_start__ = .; + *(.data*) + __data_end__ = .; + __ram_image2_text_end__ = .; + . = ALIGN(16); + } > BD_RAM + + .ram_image2.bss : + { + __bss_start__ = .; + *(.bss*) + *(COMMON) + } > BD_RAM + + .ram_image2.skb.bss : + { + *(.bdsram.data*) + __bss_end__ = .; + } > BD_RAM + + .ram_heap.data : + { + *(.bfsram.data*) + *(.heap.stdlib*) + + } > BD_RAM + + .ram_rdp.text : + { + __rom_top_4k_start_ = .; + __rdp_text_start__ = .; + KEEP(*(.rdp.ram.text*)) + KEEP(*(.rdp.ram.data*)) + __rdp_text_end__ = .; + . = ALIGN(16); + + } > RDP_RAM + + .xip_image1.text : + { + __flash_boot_text_start__ = .; + + *(.flashboot.text*) + + __flash_boot_text_end__ = .; + + . = ALIGN(16); + } > XIPBOOT + + .xip_image2.text : + { + __flash_text_start__ = .; + + *(.img2_custom_signature*) + + *(.text*) + *(.rodata*) + *(.debug_trace*) + + __flash_text_end__ = .; + + . = ALIGN (16); + } > XIP1 +} + +SECTIONS +{ + /* Bootloader symbol list */ + boot_export_symbol = 0x10002020; +} diff --git a/boards/wr3/ld/rlx8711B-symbol-v02-img2_xip2.ld b/boards/wr3/ld/rlx8711B-symbol-v02-img2_xip2.ld new file mode 100644 index 0000000..18395ae --- /dev/null +++ b/boards/wr3/ld/rlx8711B-symbol-v02-img2_xip2.ld @@ -0,0 +1,157 @@ + + +ENTRY(Reset_Handler) + +INCLUDE "export-rom_symbol_v01.txt" + +MEMORY +{ + ROM (rx) : ORIGIN = 0x00000000, LENGTH = 0x80000 /* ROM: 512k */ + ROMBSS_RAM (rw) : ORIGIN = 0x10000000, LENGTH = 0x2000 /* ROM BSS RAM: 8K */ + BOOTLOADER_RAM (rwx) : ORIGIN = 0x10002000, LENGTH = 0x3000 /* BOOT Loader RAM: 12K */ + BD_RAM (rwx) : ORIGIN = 0x10005000, LENGTH = 0x2B000 /* MAIN RAM: 228 */ + MSP_RAM (wx) : ORIGIN = 0x1003E000, LENGTH = 0x1000 /* MSP RAM: 4k */ + RDP_RAM (wx) : ORIGIN = 0x1003F000, LENGTH = 0xFF0 /* RDP RAM: 4k-0x10 */ + + XIPBOOT (rx) : ORIGIN = 0x08000000+0x20, LENGTH = 0x04000-0x20 /* XIPBOOT: 32k, 32 Bytes resvd for header*/ + XIPSYS (r) : ORIGIN = 0x08009000, LENGTH = 0x1000 /* XIPSYS: 4K system data in flash */ + XIPCAL (r) : ORIGIN = 0x0800A000, LENGTH = 0x1000 /* XIPCAL: 4K calibration data in flash */ + XIP1 (rx) : ORIGIN = 0x0800B000+0x20, LENGTH = 0x75000-0x20 /* XIP1: 468k, 32 Bytes resvd for header */ + XIP2 (rx) : ORIGIN = 0x08080000+0x20, LENGTH = 0x75000-0x20 /* XIP2: 468k, 32 Bytes resvd for header */ +} + + + +SECTIONS +{ + .rom.text : { } > ROM + .rom.rodata : { } > ROM + .hal.rom.bss : { } > ROMBSS_RAM + + /* image1 entry, this section should in RAM and fixed address for ROM */ + .ram_image1.entry : + { + __ram_image1_text_start__ = .; + __ram_start_table_start__ = .; + KEEP(*(SORT(.image1.entry.data*))) + __ram_start_table_end__ = .; + + __image1_validate_code__ = .; + KEEP(*(.image1.validate.rodata*)) + KEEP(*(.image1.export.symb*)) + } > BOOTLOADER_RAM + + /* Add . to assign the start address of the section */ + /* to prevent the change of the start address by ld doing section alignment */ + .ram_image1.text . : + { + /* image1 text */ + *(.boot.ram.text*) + *(.boot.rodata*) + } > BOOTLOADER_RAM + + .ram_image1.data . : + { + __ram_image1_data_start__ = .; + KEEP(*(.boot.ram.data*)) + __ram_image1_data_end__ = .; + + __ram_image1_text_end__ = .; + } > BOOTLOADER_RAM + + .ram_image1.bss . : + { + __image1_bss_start__ = .; + KEEP(*(.boot.ram.bss*)) + KEEP(*(.boot.ram.end.bss*)) + __image1_bss_end__ = .; + } > BOOTLOADER_RAM + + .ram_image2.entry : + { + __ram_image2_text_start__ = .; + __image2_entry_func__ = .; + KEEP(*(SORT(.image2.entry.data*))) + + __image2_validate_code__ = .; + KEEP(*(.image2.validate.rodata*)) + + } > BD_RAM + + .ram_image2.text : + { + KEEP(*(.image2.ram.text*)) + } > BD_RAM + + .ram_image2.data : + { + __data_start__ = .; + *(.data*) + __data_end__ = .; + __ram_image2_text_end__ = .; + . = ALIGN(16); + } > BD_RAM + + .ram_image2.bss : + { + __bss_start__ = .; + *(.bss*) + *(COMMON) + } > BD_RAM + + .ram_image2.skb.bss : + { + *(.bdsram.data*) + __bss_end__ = .; + } > BD_RAM + + .ram_heap.data : + { + *(.bfsram.data*) + *(.heap.stdlib*) + + } > BD_RAM + + .ram_rdp.text : + { + __rom_top_4k_start_ = .; + __rdp_text_start__ = .; + KEEP(*(.rdp.ram.text*)) + KEEP(*(.rdp.ram.data*)) + __rdp_text_end__ = .; + . = ALIGN(16); + + } > RDP_RAM + + .xip_image1.text : + { + __flash_boot_text_start__ = .; + + *(.flashboot.text*) + + __flash_boot_text_end__ = .; + + . = ALIGN(16); + } > XIPBOOT + + .xip_image2.text : + { + __flash_text_start__ = .; + + *(.img2_custom_signature*) + + *(.text*) + *(.rodata*) + *(.debug_trace*) + + __flash_text_end__ = .; + + . = ALIGN (16); + } > XIP2 +} + +SECTIONS +{ + /* Bootloader symbol list */ + boot_export_symbol = 0x10002020; +} diff --git a/boards/wr3/ld/rlx8711B-symbol-v02-img2_xip2_2M.ld b/boards/wr3/ld/rlx8711B-symbol-v02-img2_xip2_2M.ld new file mode 100644 index 0000000..8968224 --- /dev/null +++ b/boards/wr3/ld/rlx8711B-symbol-v02-img2_xip2_2M.ld @@ -0,0 +1,157 @@ + + +ENTRY(Reset_Handler) + +INCLUDE "export-rom_symbol_v01.txt" + +MEMORY +{ + ROM (rx) : ORIGIN = 0x00000000, LENGTH = 0x80000 /* ROM: 512k */ + ROMBSS_RAM (rw) : ORIGIN = 0x10000000, LENGTH = 0x2000 /* ROM BSS RAM: 8K */ + BOOTLOADER_RAM (rwx) : ORIGIN = 0x10002000, LENGTH = 0x3000 /* BOOT Loader RAM: 12K */ + BD_RAM (rwx) : ORIGIN = 0x10005000, LENGTH = 0x39000 /* MAIN RAM: 228 */ + MSP_RAM (wx) : ORIGIN = 0x1003E000, LENGTH = 0x1000 /* MSP RAM: 4k */ + RDP_RAM (wx) : ORIGIN = 0x1003F000, LENGTH = 0xFF0 /* RDP RAM: 4k-0x10 */ + + XIPBOOT (rx) : ORIGIN = 0x08000000+0x20, LENGTH = 0x04000-0x20 /* XIPBOOT: 32k, 32 Bytes resvd for header*/ + XIPSYS (r) : ORIGIN = 0x08009000, LENGTH = 0x1000 /* XIPSYS: 4K system data in flash */ + XIPCAL (r) : ORIGIN = 0x0800A000, LENGTH = 0x1000 /* XIPCAL: 4K calibration data in flash */ + XIP1 (rx) : ORIGIN = 0x0800B000+0x20, LENGTH = 0xC5000-0x20 /* XIP1: 2*468k, 32 Bytes resvd for header */ + XIP2 (rx) : ORIGIN = 0x080D0000+0x20, LENGTH = 0xC5000-0x20 /* XIP2: 2*468k, 32 Bytes resvd for header */ +} + + + +SECTIONS +{ + .rom.text : { } > ROM + .rom.rodata : { } > ROM + .hal.rom.bss : { } > ROMBSS_RAM + + /* image1 entry, this section should in RAM and fixed address for ROM */ + .ram_image1.entry : + { + __ram_image1_text_start__ = .; + __ram_start_table_start__ = .; + KEEP(*(SORT(.image1.entry.data*))) + __ram_start_table_end__ = .; + + __image1_validate_code__ = .; + KEEP(*(.image1.validate.rodata*)) + KEEP(*(.image1.export.symb*)) + } > BOOTLOADER_RAM + + /* Add . to assign the start address of the section */ + /* to prevent the change of the start address by ld doing section alignment */ + .ram_image1.text . : + { + /* image1 text */ + *(.boot.ram.text*) + *(.boot.rodata*) + } > BOOTLOADER_RAM + + .ram_image1.data . : + { + __ram_image1_data_start__ = .; + KEEP(*(.boot.ram.data*)) + __ram_image1_data_end__ = .; + + __ram_image1_text_end__ = .; + } > BOOTLOADER_RAM + + .ram_image1.bss . : + { + __image1_bss_start__ = .; + KEEP(*(.boot.ram.bss*)) + KEEP(*(.boot.ram.end.bss*)) + __image1_bss_end__ = .; + } > BOOTLOADER_RAM + + .ram_image2.entry : + { + __ram_image2_text_start__ = .; + __image2_entry_func__ = .; + KEEP(*(SORT(.image2.entry.data*))) + + __image2_validate_code__ = .; + KEEP(*(.image2.validate.rodata*)) + + } > BD_RAM + + .ram_image2.text : + { + KEEP(*(.image2.ram.text*)) + } > BD_RAM + + .ram_image2.data : + { + __data_start__ = .; + *(.data*) + __data_end__ = .; + __ram_image2_text_end__ = .; + . = ALIGN(16); + } > BD_RAM + + .ram_image2.bss : + { + __bss_start__ = .; + *(.bss*) + *(COMMON) + } > BD_RAM + + .ram_image2.skb.bss : + { + *(.bdsram.data*) + __bss_end__ = .; + } > BD_RAM + + .ram_heap.data : + { + *(.bfsram.data*) + *(.heap.stdlib*) + + } > BD_RAM + + .ram_rdp.text : + { + __rom_top_4k_start_ = .; + __rdp_text_start__ = .; + KEEP(*(.rdp.ram.text*)) + KEEP(*(.rdp.ram.data*)) + __rdp_text_end__ = .; + . = ALIGN(16); + + } > RDP_RAM + + .xip_image1.text : + { + __flash_boot_text_start__ = .; + + *(.flashboot.text*) + + __flash_boot_text_end__ = .; + + . = ALIGN(16); + } > XIPBOOT + + .xip_image2.text : + { + __flash_text_start__ = .; + + *(.img2_custom_signature*) + + *(.text*) + *(.rodata*) + *(.debug_trace*) + + __flash_text_end__ = .; + + . = ALIGN (16); + } > XIP2 +} + +SECTIONS +{ + /* Bootloader symbol list */ + boot_export_symbol = 0x10002020; +} diff --git a/builder/frameworks/realtek-ambz-sdk.py b/builder/frameworks/realtek-ambz-sdk.py index 4f206e6..5d2534c 100644 --- a/builder/frameworks/realtek-ambz-sdk.py +++ b/builder/frameworks/realtek-ambz-sdk.py @@ -5,18 +5,21 @@ env = DefaultEnvironment() platform = env.PioPlatform() board = env.BoardConfig() +mcu = board.get("build.mcu").upper() +family = board.get("build.family").upper() +variant = board.get("build.variant") +ldscript = board.get("build.ldscript_sdk") + SDK_DIR = platform.get_package_dir("framework-realtek-amb1") +BOARD_DIR = join(platform.get_dir(), "boards", variant) +FIXUPS_DIR = join(platform.get_dir(), "fixups", "realtek-ambz") assert isdir(SDK_DIR) +assert isdir(env.subst(BOARD_DIR)) +assert isdir(env.subst(FIXUPS_DIR)) ota1_offset = board.get("build.amb_ota1_offset") ota2_offset = board.get("build.amb_ota2_offset") - -# Firmware name -if env.get("PROGNAME", "program") == "program": - env.Replace(PROGNAME="firmware") -env.Replace( - PROGSUFFIX=".elf", -) +boot_all = board.get("build.amb_boot_all") # Outputs env.Replace( @@ -38,7 +41,8 @@ env.Replace( # Flags env.Replace( - CCFLAGS=[ + CFLAGS=[ + "-std=gnu99", "-mcpu=cortex-m4", "-mthumb", "-mfloat-abi=hard", @@ -47,19 +51,19 @@ env.Replace( "-w", "-O2", "-Wno-pointer-sign", - "-fno-common", - "-fmessage-length=0", - "-ffunction-sections", "-fdata-sections", - "-fomit-frame-pointer", + "-ffunction-sections", + "-fmessage-length=0", + "-fno-common", "-fno-short-enums", - "-std=gnu99", + "-fomit-frame-pointer", "-fsigned-char", ], CPPDEFINES=[ "M3", "CONFIG_PLATFORM_8711B", ("F_CPU", "166000000L"), + ("LWIP_TIMEVAL_PRIVATE", "0"), ], LINKFLAGS=[ "-mcpu=cortex-m4", @@ -169,18 +173,12 @@ sources = [ # app uart_adapter "+<" + SDK_DIR +"/component/common/application/uart_adapter/uart_adapter.c>", # cmsis - "+<" + SDK_DIR +"/component/soc/realtek/8711b/cmsis/device/app_start.c>", + # NOTE: a fixup is used instead, to remove default main() + # "+<" + SDK_DIR +"/component/soc/realtek/8711b/cmsis/device/app_start.c>", "+<" + SDK_DIR +"/component/soc/realtek/8711b/fwlib/ram_lib/startup.c>", "+<" + SDK_DIR +"/component/soc/realtek/8711b/cmsis/device/system_8195a.c>", # console - # "+<" + SDK_DIR +"/component/common/api/at_cmd/atcmd_lwip.c>", - # "+<" + SDK_DIR +"/component/common/api/at_cmd/atcmd_sys.c>", - # "+<" + SDK_DIR +"/component/common/api/at_cmd/atcmd_wifi.c>", - # "+<" + SDK_DIR +"/component/common/api/at_cmd/log_service.c>", - # "+<" + SDK_DIR +"/component/soc/realtek/8711b/app/monitor/ram/low_level_io.c>", - # "+<" + SDK_DIR +"/component/soc/realtek/8711b/app/monitor/ram/monitor.c>", - "+<" + SDK_DIR +"/component/soc/realtek/8711b/app/monitor/ram/rtl_consol.c>", - # "+<" + SDK_DIR +"/component/soc/realtek/8711b/app/monitor/ram/rtl_trace.c>", + "+<" + SDK_DIR +"/component/soc/realtek/8711b/app/monitor/ram/rtl_trace.c>", # network api wifi rtw_wpa_supplicant "+<" + SDK_DIR +"/component/common/api/wifi/rtw_wpa_supplicant/wpa_supplicant/wifi_eap_config.c>", "+<" + SDK_DIR +"/component/common/api/wifi/rtw_wpa_supplicant/wpa_supplicant/wifi_p2p_config.c>", @@ -349,36 +347,6 @@ sources = [ "+<" + SDK_DIR +"/component/soc/realtek/8711b/misc/rtl8710b_ota.c>", "+<" + SDK_DIR +"/component/soc/realtek/8711b/fwlib/ram_lib/rtl8710b_pinmapcfg.c>", "+<" + SDK_DIR +"/component/soc/realtek/8711b/fwlib/ram_lib/rtl8710b_sleepcfg.c>", - # utilities example - # "+<" + SDK_DIR +"/component/common/example/bcast/example_bcast.c>", - # "+<" + SDK_DIR +"/component/common/example/dct/example_dct.c>", - # "+<" + SDK_DIR +"/component/common/example/eap/example_eap.c>", - # "+<" + SDK_DIR +"/component/common/example/example_entry.c>", - # "+<" + SDK_DIR +"/component/common/example/get_beacon_frame/example_get_beacon_frame.c>", - # "+<" + SDK_DIR +"/component/common/example/high_load_memory_use/example_high_load_memory_use.c>", - # "+<" + SDK_DIR +"/component/common/example/http_client/example_http_client.c>", - # "+<" + SDK_DIR +"/component/common/example/httpc/example_httpc.c>", - # "+<" + SDK_DIR +"/component/common/example/httpd/example_httpd.c>", - # "+<" + SDK_DIR +"/component/common/example/http_download/example_http_download.c>", - # "+<" + SDK_DIR +"/component/common/example/mcast/example_mcast.c>", - # "+<" + SDK_DIR +"/component/common/example/mdns/example_mdns.c>", - # "+<" + SDK_DIR +"/component/common/example/mqtt/example_mqtt.c>", - # "+<" + SDK_DIR +"/component/common/example/nonblock_connect/example_nonblock_connect.c>", - # "+<" + SDK_DIR +"/component/common/example/rarp/example_rarp.c>", - # "+<" + SDK_DIR +"/component/common/example/sntp_showtime/example_sntp_showtime.c>", - # "+<" + SDK_DIR +"/component/common/example/socket_select/example_socket_select.c>", - # "+<" + SDK_DIR +"/component/common/example/socket_tcp_trx/example_socket_tcp_trx_1.c>", - # "+<" + SDK_DIR +"/component/common/example/socket_tcp_trx/example_socket_tcp_trx_2.c>", - # "+<" + SDK_DIR +"/component/common/example/ssl_download/example_ssl_download.c>", - # "+<" + SDK_DIR +"/component/common/example/ssl_server/example_ssl_server.c>", - # "+<" + SDK_DIR +"/component/common/example/tcp_keepalive/example_tcp_keepalive.c>", - # "+<" + SDK_DIR +"/component/common/example/uart_atcmd/example_uart_atcmd.c>", - # "+<" + SDK_DIR +"/component/common/example/wifi_mac_monitor/example_wifi_mac_monitor.c>", - # "+<" + SDK_DIR +"/component/common/example/wlan_fast_connect/example_wlan_fast_connect.c>", - # "+<" + SDK_DIR +"/component/common/example/wlan_scenario/example_wlan_scenario.c>", - # "+<" + SDK_DIR +"/component/common/example/websocket/example_wsclient.c>", - # "+<" + SDK_DIR +"/component/common/example/xml/example_xml.c>", - # "+<" + SDK_DIR +"/component/common/example/uart_firmware_update/example_uart_update.c>", # network - httpc "+<" + SDK_DIR +"/component/common/network/httpc/httpc_tls.c>", # network - httpd @@ -391,14 +359,22 @@ sources = [ # fmt: on ] +# Fixups +sources += [ + "+<" + FIXUPS_DIR + "/app_start_patch.c>", + "+<" + FIXUPS_DIR + "/cmsis_ipsr.c>", + "+<" + FIXUPS_DIR + "/log_uart.c>", + "+<" + FIXUPS_DIR + "/wifi_mode.c>", +] + # Libs & linker config env.Append( LIBPATH=[ # fmt: off join(SDK_DIR, "component", "soc", "realtek", "8711b", "misc", "bsp", "lib", "common", "GCC"), - # linker script path - join(SDK_DIR, "project", "realtek_amebaz_va0_example", "GCC-RELEASE"), # fmt: on + # linker script path + join(BOARD_DIR, "ld"), ], LIBS=[ "_platform", @@ -418,9 +394,7 @@ env.Append( ) env.Replace( LDSCRIPT_PATH=[ - # fmt: off - join(SDK_DIR, "project", "realtek_amebaz_va0_example", "GCC-RELEASE", "rlx8711B-symbol-v02-img2_xip1.ld"), - # fmt: on + join(BOARD_DIR, "ld", ldscript), ], ) @@ -565,15 +539,20 @@ actions.append(env.VerboseAction(package_ota, "Packaging OTA image - $IMG_OTA")) actions.append(env.VerboseAction("true", f"- OTA1 flash offset: {ota1_offset}")) actions.append(env.VerboseAction("true", f"- OTA2 flash offset: {ota2_offset}")) +# Clone env to ignore options from child projects +envsdk = env.Clone() + # SDK library target -target_sdk = env.BuildLibrary(join("$BUILD_DIR", "SDK"), SDK_DIR, sources) +target_sdk = envsdk.BuildLibrary( + join("$BUILD_DIR", "ambz_sdk"), + SDK_DIR, + sources, +) target_boot = env.StaticLibrary( join("$BUILD_DIR", "boot_all"), env.BinToObj( join("$BUILD_DIR", "boot_all.o"), - # fmt: off - join(SDK_DIR, "component", "soc", "realtek", "8711b", "misc", "bsp", "image", "boot_all.bin"), - # fmt: on + join(BOARD_DIR, "bin", boot_all), ), ) env.Prepend(LIBS=[target_sdk, target_boot]) diff --git a/builder/main.py b/builder/main.py index 2bc8e09..a1217b1 100644 --- a/builder/main.py +++ b/builder/main.py @@ -2,17 +2,22 @@ from SCons.Script import Default, DefaultEnvironment env = DefaultEnvironment() +# Firmware name +if env.get("PROGNAME", "program") == "program": + env.Replace(PROGNAME="firmware") +env.Replace(PROGSUFFIX=".elf") + env.Replace( - AR="arm-none-eabi-ar", + AR="arm-none-eabi-gcc-ar", AS="arm-none-eabi-gcc", CC="arm-none-eabi-gcc", CXX="arm-none-eabi-g++", - NM="arm-none-eabi-nm", + NM="arm-none-eabi-gcc-nm", LINK="arm-none-eabi-gcc", LD="arm-none-eabi-gcc", OBJCOPY="arm-none-eabi-objcopy", OBJDUMP="arm-none-eabi-objdump", - RANLIB="arm-none-eabi-ranlib", + # RANLIB="arm-none-eabi-gcc-ranlib", SIZETOOL="arm-none-eabi-size", ) diff --git a/fixups/realtek-ambz/app_start_patch.c b/fixups/realtek-ambz/app_start_patch.c new file mode 100644 index 0000000..7d12206 --- /dev/null +++ b/fixups/realtek-ambz/app_start_patch.c @@ -0,0 +1,118 @@ +/* + * Routines to access hardware + * + * Copyright (c) 2013 Realtek Semiconductor Corp. + * + * This module is a confidential and proprietary property of RealTek and + * possession or use of this module requires written permission of RealTek. + */ + +// NOTE: this file has the default main() function removed. + +#include "ameba_soc.h" +#include "build_info.h" + +#if (defined(CONFIG_POST_SIM)) +void Simulation_Init(void); +#endif + +#if defined(CONFIG_WIFI_NORMAL) && defined(CONFIG_NETWORK) +extern void init_rom_wlan_ram_map(void); +extern VOID wlan_network(VOID); +#endif + +#ifdef CONFIG_MBED_ENABLED +extern void __libc_fini_array (void); +extern void __libc_init_array (void); +extern void SVC_Handler (void); +extern void PendSV_Handler (void); +extern void SysTick_Handler (void); + +void APP_StartMbed(void) +{ + InterruptForOSInit((VOID*)SVC_Handler, + (VOID*)PendSV_Handler, + (VOID*)SysTick_Handler); + __asm ( + "ldr r0, =SystemInit\n" + "blx r0\n" + "ldr r0, =_start\n" + "bx r0\n" + ); + + for(;;); + +} +#endif + +void APP_InitTrace(void) +{ + u32 debug[4]; + +#if (defined(CONFIG_POST_SIM) || defined(CONFIG_CP)) + return; +#endif + + debug[LEVEL_ERROR] = BIT(MODULE_BOOT); + debug[LEVEL_WARN] = 0x0; + debug[LEVEL_INFO] = BIT(MODULE_BOOT); + debug[LEVEL_TRACE] = 0x0; + +#ifdef CONFIG_DEBUG_ERR_MSG + debug[LEVEL_ERROR] = 0xFFFFFFFF; +#endif +#ifdef CONFIG_DEBUG_WARN_MSG + debug[LEVEL_WARN] = 0xFFFFFFFF; +#endif +#ifdef CONFIG_DEBUG_INFO_MSG + debug[LEVEL_INFO] = 0xFFFFFFFF; +#endif + + LOG_MASK(debug); + + DBG_PRINTF(MODULE_BOOT, LEVEL_INFO, "APP_InitTrace: %x:%x:%x:%x\n",debug[0], debug[1], debug[2], debug[3]); + DBG_PRINTF(MODULE_BOOT, LEVEL_ERROR, "APP_InitTrace: %x:%x:%x:%x\n",debug[0], debug[1], debug[2], debug[3]); + +} + +extern void main(void); + +// The Main App entry point +void APP_Start(void) +{ +#if CONFIG_SOC_PS_MODULE + SOCPS_InitSYSIRQ(); +#endif + +#ifdef CONFIG_KERNEL +#ifdef PLATFORM_FREERTOS + InterruptForOSInit((VOID*)vPortSVCHandler, + (VOID*)xPortPendSVHandler, + (VOID*)xPortSysTickHandler); +#endif +#endif + +#ifdef CONFIG_MBED_ENABLED + APP_StartMbed(); +#else + +#if 0//def CONFIG_APP_DEMO +#ifdef PLATFORM_FREERTOS + xTaskCreate( (TaskFunction_t)main, "MAIN_APP__TASK", (2048 /4), (void *)NULL, (tskIDLE_PRIORITY + 1), NULL); + vTaskStartScheduler(); +#endif +#else +#if defined ( __ICCARM__ ) + __iar_cstart_call_ctors(NULL); +#endif + // force SP align to 8 byte not 4 byte (initial SP is 4 byte align) + __asm( + "mov r0, sp\n" + "bic r0, r0, #7\n" + "mov sp, r0\n" + ); + + main(); +#endif // end of #if CONFIG_APP_DEMO +#endif // end of else of "#ifdef CONFIG_MBED_ENABLED" +} diff --git a/fixups/realtek-ambz/cmsis_ipsr.c b/fixups/realtek-ambz/cmsis_ipsr.c new file mode 100644 index 0000000..a464e50 --- /dev/null +++ b/fixups/realtek-ambz/cmsis_ipsr.c @@ -0,0 +1,9 @@ +#include + +// for some reason, cmsis_os.c does not link properly when this method is inlined in core_cmFunc.h +// (or I am too stupid to understand this) +__attribute__((weak)) uint32_t __get_IPSR() +{ + uint32_t result; + asm volatile ("MRS %0, ipsr" : "=r" (result) ); +} diff --git a/fixups/realtek-ambz/log_uart.c b/fixups/realtek-ambz/log_uart.c new file mode 100644 index 0000000..1bdf5bd --- /dev/null +++ b/fixups/realtek-ambz/log_uart.c @@ -0,0 +1,28 @@ +#include "ameba_soc.h" +#include "osdep_service.h" + +// usage: +// extern int LOGUART_SetBaud(uint32_t BaudRate); + +int LOGUART_SetBaud(uint32_t BaudRate) +{ + UART_INTConfig(UART2_DEV, RUART_IER_ERBI | RUART_IER_ELSI, DISABLE); + UART_RxCmd(UART2_DEV, DISABLE); + + UART_SetBaud(UART2_DEV, BaudRate); + + UART_INTConfig(UART2_DEV, RUART_IER_ERBI | RUART_IER_ELSI, ENABLE); + UART_RxCmd(UART2_DEV, ENABLE); + + return 1; +} + +void LOGUART_SetBaud_FromFlash(void) +{ + // useless, nop +} + +void ReRegisterPlatformLogUart(void) +{ + // useless, nop +} diff --git a/fixups/realtek-ambz/wifi_mode.c b/fixups/realtek-ambz/wifi_mode.c new file mode 100644 index 0000000..56da3e1 --- /dev/null +++ b/fixups/realtek-ambz/wifi_mode.c @@ -0,0 +1,4 @@ +#include + +// wifi_mode is declared in atcmd_wifi.c, which is a part of the built-in trash console +rtw_mode_t wifi_mode = RTW_MODE_STA; diff --git a/platform.json b/platform.json index 09d36bc..4f1dadb 100644 --- a/platform.json +++ b/platform.json @@ -23,7 +23,10 @@ "toolchain-gccarmnoneeabi": { "type": "toolchain", "optionalVersions": [ - "~1.40804.0" + "~1.40804.0", + "~1.50401.0", + "~1.90301.0", + "~1.100301.0" ] } } diff --git a/platform.py b/platform.py index f9bdac0..1f4328b 100644 --- a/platform.py +++ b/platform.py @@ -5,5 +5,5 @@ class LibretuyaPlatform(PlatformBase): def configure_default_packages(self, options, targets): framework = options.get("pioframework")[0] if framework.startswith("realtek-ambz"): - self.packages["toolchain-gccarmnoneeabi"]["version"] = "~1.40804.0" + self.packages["toolchain-gccarmnoneeabi"]["version"] = "~1.50401.0" return super().configure_default_packages(options, targets)