From f68de5128c6c6c12d2e90bd40de59cf37ac49098 Mon Sep 17 00:00:00 2001 From: songyanguang <345810377@qq.com> Date: Tue, 6 May 2025 18:32:46 +0800 Subject: [PATCH] ch32v208 add ota, need to debug --- .../arch/risc-v/ch32v208rbt6/Makefile | 5 +- .../XiZi_IIoT/arch/risc-v/ch32v208rbt6/boot.S | 4 + .../XiZi_IIoT/board/ch32v208rbt6/.defconfig | 349 ++++++++++++++++++ .../XiZi_IIoT/board/ch32v208rbt6/config.mk | 10 + .../board/ch32v208rbt6/link_application.ld | 225 +++++++++++ .../board/ch32v208rbt6/link_bootloader.ld | 224 +++++++++++ .../ch32v208rbt6/third_party_driver/Makefile | 4 + .../third_party_driver/ModuleConfig.c | 2 + .../third_party_driver/common/Makefile | 5 + .../third_party_driver/common/common.c | 65 ++++ .../third_party_driver/common/ymodem.c | 54 +++ .../third_party_driver/include/boot_for_ota.h | 34 ++ .../third_party_driver/include/common.h | 36 ++ .../include/flash_for_ota.h | 40 ++ .../third_party_driver/include/ymodem.h | 56 +++ .../third_party_driver/ota/Makefile | 3 + .../third_party_driver/ota/boot_for_ota.c | 133 +++++++ .../third_party_driver/ota/flash_for_ota.c | 258 +++++++++++++ Ubiquitous/XiZi_IIoT/script.sh | 6 + 19 files changed, 1512 insertions(+), 1 deletion(-) create mode 100644 Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/.defconfig create mode 100644 Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/link_application.ld create mode 100644 Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/link_bootloader.ld create mode 100755 Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/common/Makefile create mode 100644 Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/common/common.c create mode 100644 Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/common/ymodem.c create mode 100644 Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/include/boot_for_ota.h create mode 100644 Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/include/common.h create mode 100644 Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/include/flash_for_ota.h create mode 100644 Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/include/ymodem.h create mode 100644 Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ota/Makefile create mode 100644 Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ota/boot_for_ota.c create mode 100644 Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ota/flash_for_ota.c create mode 100755 Ubiquitous/XiZi_IIoT/script.sh diff --git a/Ubiquitous/XiZi_IIoT/arch/risc-v/ch32v208rbt6/Makefile b/Ubiquitous/XiZi_IIoT/arch/risc-v/ch32v208rbt6/Makefile index ca8a90e5a..e63075d80 100644 --- a/Ubiquitous/XiZi_IIoT/arch/risc-v/ch32v208rbt6/Makefile +++ b/Ubiquitous/XiZi_IIoT/arch/risc-v/ch32v208rbt6/Makefile @@ -1,4 +1,7 @@ -SRC_FILES := boot.S interrupt.c tick.c switch.S prepare_rhwstack.c interrupt_switch.S ble_task_scheduler.S +SRC_FILES := boot.S interrupt.c tick.c switch.S prepare_rhwstack.c interrupt_switch.S +ifeq ($(CONFIG_BSP_USING_BLE),y) +SRC_FILES += ble_task_scheduler.S +endif SRC_DIR := Core User Debug # interrupt_switch.S include $(KERNEL_ROOT)/compiler.mk diff --git a/Ubiquitous/XiZi_IIoT/arch/risc-v/ch32v208rbt6/boot.S b/Ubiquitous/XiZi_IIoT/arch/risc-v/ch32v208rbt6/boot.S index 4fea969ad..871086a72 100644 --- a/Ubiquitous/XiZi_IIoT/arch/risc-v/ch32v208rbt6/boot.S +++ b/Ubiquitous/XiZi_IIoT/arch/risc-v/ch32v208rbt6/boot.S @@ -268,7 +268,11 @@ handle_reset: csrw mtvec, t0 jal SystemInit +#ifdef __BOOTLOADER /* BOOT */ + la t0, ota_entry +#else /* APP */ la t0, entry +#endif /* BOOT */ csrw mepc, t0 mret diff --git a/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/.defconfig b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/.defconfig new file mode 100644 index 000000000..2652dea46 --- /dev/null +++ b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/.defconfig @@ -0,0 +1,349 @@ +# +# Automatically generated file; DO NOT EDIT. +# XiZi_IIoT Project Configuration +# +CONFIG_BOARD_CH32V208RBT6=y +CONFIG_ARCH_RISCV=y + +# +# ch32v208rbt6 feature +# +CONFIG_BSP_USING_UART=y +CONFIG_BSP_USING_UART1=y +CONFIG_SERIAL_BUS_NAME_1="uart1" +CONFIG_SERIAL_DRV_NAME_1="uart1_drv" +CONFIG_SERIAL_1_DEVICE_NAME_0="uart1_dev1" +# CONFIG_BSP_USING_ETH is not set +# CONFIG_BSP_USING_ADC is not set +# CONFIG_BSP_USING_BLE is not set +# CONFIG_BSP_USING_CAN is not set +# CONFIG_BSP_USING_RS485 is not set +CONFIG_BSP_USING_LTE=y +CONFIG_LTE_BUS_NAME="lte" +CONFIG_LTE_DRV_NAME="lte_drv" +CONFIG_LTE_DEVICE_NAME_1="lte_dev1" + +# +# Hardware feature +# +CONFIG_RESOURCES_SERIAL=y +CONFIG_SERIAL_USING_DMA=y +CONFIG_SERIAL_RB_BUFSZ=128 + +# +# Kernel feature +# + +# +# separate compile(choose none for compile once) +# +# CONFIG_SEPARATE_COMPILE is not set +# CONFIG_COMPILER_APP is not set +# CONFIG_APP_STARTUP_FROM_SDCARD is not set +CONFIG_APP_STARTUP_FROM_FLASH=y +# CONFIG_COMPILER_KERNEL is not set + +# +# Memory Management +# +# CONFIG_KERNEL_MEMBLOCK is not set +CONFIG_MEM_ALIGN_SIZE=8 +# CONFIG_MEM_EXTERN_SRAM is not set +CONFIG_MM_PAGE_SIZE=4096 + +# +# Using small memory allocator +# +CONFIG_KERNEL_SMALL_MEM_ALLOC=y +CONFIG_SMALL_NUMBER_32B=64 +CONFIG_SMALL_NUMBER_64B=32 + +# +# Task feature +# +CONFIG_USER_APPLICATION=y +# CONFIG_TASK_ISOLATION is not set +# CONFIG_KERNEL_CAPABILITY is not set + +# +# Inter-Task communication +# +CONFIG_KERNEL_SEMAPHORE=y +CONFIG_KERNEL_MUTEX=y +CONFIG_KERNEL_EVENT=y +CONFIG_KERNEL_MESSAGEQUEUE=y +CONFIG_KERNEL_SOFTTIMER=y +CONFIG_SCHED_POLICY_RR_REMAINSLICE=y +# CONFIG_SCHED_POLICY_RR is not set +# CONFIG_SCHED_POLICY_FIFO is not set +# CONFIG_KTASK_PRIORITY_8 is not set +CONFIG_KTASK_PRIORITY_32=y +# CONFIG_KTASK_PRIORITY_256 is not set +CONFIG_KTASK_PRIORITY_MAX=32 +CONFIG_TICK_PER_SECOND=100 +CONFIG_KERNEL_STACK_OVERFLOW_CHECK=y +CONFIG_IDLE_KTASK_STACKSIZE=512 +CONFIG_ZOMBIE_KTASK_STACKSIZE=512 + +# +# Kernel Console +# +CONFIG_KERNEL_CONSOLE=y +CONFIG_KERNEL_BANNER=y +CONFIG_KERNEL_CONSOLEBUF_SIZE=128 + +# +# Kernel Hook +# +# CONFIG_KERNEL_HOOK is not set + +# +# Command shell +# +CONFIG_TOOL_SHELL=y +CONFIG_SHELL_ENTER_CR=y +CONFIG_SHELL_ENTER_LF=y +CONFIG_SHELL_ENTER_CR_AND_LF=y +# CONFIG_SHELL_ENTER_CRLF is not set + +# +# Set shell user control +# +CONFIG_SHELL_DEFAULT_USER="letter" +CONFIG_SHELL_DEFAULT_USER_PASSWORD="" +CONFIG_SHELL_LOCK_TIMEOUT=10000 + +# +# Set shell config param +# +CONFIG_SHELL_TASK_STACK_SIZE=1024 +CONFIG_SHELL_TASK_PRIORITY=20 +CONFIG_SHELL_MAX_NUMBER=5 +CONFIG_SHELL_PARAMETER_MAX_NUMBER=8 +CONFIG_SHELL_HISTORY_MAX_NUMBER=5 +CONFIG_SHELL_PRINT_BUFFER=128 +CONFIG_SHELL_HELP_SHOW_PERMISSION=y +# CONFIG_SHELL_HELP_LIST_USER is not set +CONFIG_SHELL_HELP_LIST_VAR=y +# CONFIG_SHELL_HELP_LIST_KEY is not set + +# +# Kernel data structure Manage +# +CONFIG_KERNEL_QUEUEMANAGE=y +CONFIG_KERNEL_WORKQUEUE=y +CONFIG_WORKQUEUE_KTASK_STACKSIZE=2048 +CONFIG_WORKQUEUE_KTASK_PRIORITY=23 +CONFIG_QUEUE_MAX=16 +CONFIG_KERNEL_WAITQUEUE=y +CONFIG_KERNEL_DATAQUEUE=y +# CONFIG_KERNEL_CIRCULAR_AREA is not set +# CONFIG_KERNEL_AVL_TREE is not set + +# +# Kernel components init +# +CONFIG_KERNEL_COMPONENTS_INIT=y +CONFIG_ENV_INIT_KTASK_STACK_SIZE=2048 +CONFIG_KERNEL_USER_MAIN=y +CONFIG_NAME_NUM_MAX=32 +# CONFIG_KERNEL_DEBUG is not set +# CONFIG_ARCH_SMP is not set + +# +# hash table config +# +CONFIG_ID_HTABLE_SIZE=16 +CONFIG_ID_NUM_MAX=128 +# CONFIG_KERNEL_TEST is not set + +# +# Kernel Lib +# +CONFIG_LIB=y +CONFIG_LIB_POSIX=y +CONFIG_LIB_NEWLIB=y +# CONFIG_LIB_MUSLLIB is not set +# CONFIG_LIB_OTHER is not set + +# +# C++ features +# +# CONFIG_LIB_CPLUSPLUS is not set + +# +# File system +# +CONFIG_FS_VFS=y +# CONFIG_VFS_USING_WORKDIR is not set +CONFIG_FS_VFS_DEVFS=y +# CONFIG_FS_VFS_FATFS is not set +# CONFIG_FS_CH376 is not set +# CONFIG_FS_LWEXT4 is not set + +# +# Tool feature +# + +# +# OTA function +# +CONFIG_TOOL_USING_OTA=y +# CONFIG_MCUBOOT_BOOTLOADER is not set +CONFIG_MCUBOOT_APPLICATION=y +CONFIG_OTA_BY_PLATFORM=y +# CONFIG_OTA_BY_TCPSERVER is not set + +# +# Flash area address and size configuration. +# +CONFIG_CHIP_FLAH_BASE=0x08000000 +CONFIG_XIUOS_FLAH_ADDRESS=0x60100000 +CONFIG_BAKUP_FLAH_ADDRESS=0x60300000 +CONFIG_DOWN_FLAH_ADDRESS=0x08038000 +CONFIG_FLAG_FLAH_ADDRESS=0x08077000 +CONFIG_APP_FLASH_SIZE=0x00100000 +CONFIG_OTA_RX_TIMEOUT=600 +CONFIG_OTA_FRAME_SIZE=2048 + +# +# APP_Framework +# + +# +# Framework +# +CONFIG_TRANSFORM_LAYER_ATTRIUBUTE=y +CONFIG_ADD_XIZI_FEATURES=y +# CONFIG_ADD_NUTTX_FEATURES is not set +# CONFIG_ADD_RTTHREAD_FEATURES is not set +# CONFIG_SUPPORT_SENSOR_FRAMEWORK is not set +CONFIG_SUPPORT_CONNECTION_FRAMEWORK=y +# CONFIG_CONNECTION_FRAMEWORK_DEBUG is not set +# CONFIG_CONNECTION_INDUSTRIAL_NETWORK is not set +# CONFIG_CONNECTION_INDUSTRIAL_FIELDBUS is not set +# CONFIG_CONNECTION_INDUSTRIAL_WLAN is not set +# CONFIG_CONNECTION_ADAPTER_LORA is not set +CONFIG_CONNECTION_ADAPTER_4G=y +CONFIG_ADAPTER_EC801E=y +CONFIG_ADAPTER_4G_EC801E="ec801e" +# CONFIG_ADAPTER_EC801E_DRIVER_EXTUART is not set +CONFIG_ADAPTER_EC801E_DRIVER="/dev/lte_dev1" +# CONFIG_ADAPTER_EC200T is not set +# CONFIG_ADAPTER_EC200A is not set +# CONFIG_ADAPTER_GM800TF is not set +# CONFIG_CONNECTION_ADAPTER_NB is not set +# CONFIG_CONNECTION_ADAPTER_WIFI is not set +# CONFIG_CONNECTION_ADAPTER_ETHERNET is not set +# CONFIG_CONNECTION_ADAPTER_BLUETOOTH is not set +# CONFIG_CONNECTION_ADAPTER_ZIGBEE is not set +# CONFIG_CONNECTION_ADAPTER_5G is not set +# CONFIG_SUPPORT_KNOWING_FRAMEWORK is not set +# CONFIG_SUPPORT_CONTROL_FRAMEWORK is not set + +# +# Security +# +# CONFIG_CRYPTO is not set +# CONFIG_MBEDTLS is not set + +# +# Applications +# + +# +# config stack size and priority of main task +# +CONFIG_MAIN_KTASK_STACK_SIZE=1024 +CONFIG_MAIN_KTASK_PRIORITY=16 + +# +# test app +# +# CONFIG_USER_TEST is not set + +# +# connection app +# +# CONFIG_APPLICATION_CONNECTION is not set + +# +# control app +# + +# +# knowing app +# +# CONFIG_APPLICATION_KNOWING is not set + +# +# sensor app +# +# CONFIG_APPLICATION_SENSOR is not set +# CONFIG_USING_EMBEDDED_DATABASE_APP is not set +# CONFIG_APP_USING_WEBNET is not set +# CONFIG_APPLICATION_WEBSERVER is not set + +# +# app lib +# +CONFIG_APP_SELECT_NEWLIB=y +# CONFIG_APP_SELECT_OTHER_LIB is not set + +# +# lib using cJSON +# +# CONFIG_LIB_USING_CJSON is not set + +# +# lib using queue +# +# CONFIG_LIB_USING_QUEUE is not set + +# +# lib using LVGL +# +# CONFIG_LIB_LV is not set + +# +# lvgl image display parameter settings +# +CONFIG_LVGL_WIDTH=320 +CONFIG_LVGL_HEIGHT=320 + +# +# lib using embedded_database +# +# CONFIG_USING_EMBEDDED_DATABASE is not set + +# +# lib using LoRaWan +# +# CONFIG_LIB_USING_LORAWAN is not set + +# +# lib using MQTT +# +CONFIG_LIB_USING_MQTT=y +CONFIG_XIUOS_PLATFORM=y +# CONFIG_ALIBABA_PLATFORM is not set + +# +# xiuos platform mqtt connection parameter configuration. +# +CONFIG_CLIENTID="D001" +CONFIG_USERNAME="xiuosiot" +CONFIG_PASSWORD="xiuosiot" +CONFIG_PLATFORM_SERVERIP="115.238.53.59" +CONFIG_PLATFORM_SERVERPORT="1883" +# CONFIG_USING_DOWNLOAD_JSON is not set + +# +# lib using JerryScript +# +# CONFIG_LIB_USING_JERRYSCRIPT is not set + +# +# lib using SQLite +# +# CONFIG_LIB_USING_SQLITE is not set diff --git a/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/config.mk b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/config.mk index 7cd2dab34..bc895ea8f 100644 --- a/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/config.mk +++ b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/config.mk @@ -4,7 +4,14 @@ export MARCH := rv32imac_zicsr export CFLAGS := -march=$(MARCH) -mabi=ilp32 -msmall-data-limit=8 -msave-restore -Os -g export AFLAGS := -march=$(MARCH) -mabi=ilp32 -x assembler-with-cpp -ggdb + +ifeq ($(CONFIG_MCUBOOT_BOOTLOADER),y) +export LFLAGS := -march=$(MARCH) -mabi=ilp32 -nostartfiles -Wl,--gc-sections,-Map=XiZi-ch32v208vct6.map,-cref,-u,_start -T $(BSP_ROOT)/link_bootloader.ld +else ifeq ($(CONFIG_MCUBOOT_APPLICATION),y) +export LFLAGS := -march=$(MARCH) -mabi=ilp32 -nostartfiles -Wl,--gc-sections,-Map=XiZi-ch32v208vct6.map,-cref,-u,_start -T $(BSP_ROOT)/link_application.ld +else export LFLAGS := -march=$(MARCH) -mabi=ilp32 -nostartfiles -Wl,--gc-sections,-Map=XiZi-ch32v208vct6.map,-cref,-u,_start -T $(BSP_ROOT)/link.ld +endif # export CFLAGS := -march=$(MARCH) -mabi=ilp32 -msmall-data-limit=8 -msave-restore -Os -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -fno-common -g -std=gnu99 # export AFLAGS := -march=$(MARCH) -mabi=ilp32 -x assembler-with-cpp -ggdb @@ -17,6 +24,9 @@ export CXXFLAGS := -fmessage-length=0 -fsigned-char -ffunction-sections -fdata- export CROSS_COMPILE ?=/opt/riscv64-toolchain/bin/riscv64-unknown-elf- export DEFINES := -DHAVE_CCONFIG_H -DHAVE_SIGINFO +ifeq ($(CONFIG_MCUBOOT_BOOTLOADER),y) +export DEFINES += -D__BOOTLOADER +endif export LINK_WCH_NET := $(KERNEL_ROOT)/board/ch32v208rbt6/third_party_driver/ethernet/libwchnet.a export LINK_WCH_BLE := $(KERNEL_ROOT)/board/ch32v208rbt6/third_party_driver/ble/lib/libwchble.a diff --git a/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/link_application.ld b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/link_application.ld new file mode 100644 index 000000000..9371cfc8e --- /dev/null +++ b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/link_application.ld @@ -0,0 +1,225 @@ +ENTRY( _start ) + +__stack_size = 2048; + +PROVIDE( _stack_size = __stack_size ); + + +MEMORY +{ +/* CH32V20x_D6 - CH32V203F6-CH32V203G6-CH32V203K6-CH32V203C6 */ +/* + FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 32K + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 10K +*/ + +/* CH32V20x_D6 - CH32V203K8-CH32V203C8-CH32V203G8-CH32V203F8 */ +/* + FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 64K + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 20K +*/ + +/* CH32V20x_D8 - CH32V203RB + CH32V20x_D8W - CH32V208x + FLASH + RAM supports the following configuration + FLASH-128K + RAM-64K + FLASH-144K + RAM-48K + FLASH-160K + RAM-32K +*/ + /*FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 448K*/ + FLASH (rx) : ORIGIN = 0x00038000, LENGTH = 248K + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 48K +} + + +SECTIONS +{ + + .init : + { + _sinit = .; + . = ALIGN(4); + KEEP(*(SORT_NONE(.init))) + . = ALIGN(4); + _einit = .; + } >FLASH AT>FLASH + + .vector : + { + *(.vector); + . = ALIGN(64); + } >FLASH AT>FLASH + + .highcode : + { + . = ALIGN(4); + *(.highcode); + *(.highcode.*); + . = ALIGN(4); + } >FLASH AT>FLASH + + .text : + { + . = ALIGN(4); + EXCLUDE_FILE (*wchble.a) *(.text .text*) + *(.text) + *(.text.*) + *(.rodata) + *(.rodata*) + *(.sdata2.*) + *(.glue_7) + *(.glue_7t) + *(.gnu.linkonce.t.*) + . = ALIGN(4); + + /* section information for shell */ + . = ALIGN(4); + _shell_command_start = .; + KEEP (*(shellCommand)) + _shell_command_end = .; + . = ALIGN(4); + + PROVIDE(__ctors_start__ = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array)) + PROVIDE(__ctors_end__ = .); + + . = ALIGN(4); + __isrtbl_idx_start = .; + KEEP(*(.isrtbl.idx)) + __isrtbl_start = .; + KEEP(*(.isrtbl)) + __isrtbl_end = .; + . = ALIGN(4); + + PROVIDE(g_service_table_start = ABSOLUTE(.)); + KEEP(*(.g_service_table)) + PROVIDE(g_service_table_end = ABSOLUTE(.)); + + *(.gnu.linkonce.t.*) + } >FLASH AT>FLASH + + .fini : + { + KEEP(*(SORT_NONE(.fini))) + . = ALIGN(4); + } >FLASH AT>FLASH + + PROVIDE( _etext = . ); + PROVIDE( _eitcm = . ); + + .preinit_array : + { + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array)) + PROVIDE_HIDDEN (__preinit_array_end = .); + } >FLASH AT>FLASH + + .init_array : + { + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*))) + KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors)) + PROVIDE_HIDDEN (__init_array_end = .); + } >FLASH AT>FLASH + + .fini_array : + { + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*))) + KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors)) + PROVIDE_HIDDEN (__fini_array_end = .); + } >FLASH AT>FLASH + + .ctors : + { + /* gcc uses crtbegin.o to find the start of + the constructors, so we make sure it is + first. Because this is a wildcard, it + doesn't matter if the user does not + actually link against crtbegin.o; the + linker won't look for a file to match a + wildcard. The wildcard also means that it + doesn't matter which directory crtbegin.o + is in. */ + KEEP (*crtbegin.o(.ctors)) + KEEP (*crtbegin?.o(.ctors)) + /* We don't want to include the .ctor section from + the crtend.o file until after the sorted ctors. + The .ctor section from the crtend file contains the + end of ctors marker and it must be last */ + KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + } >FLASH AT>FLASH + + .dtors : + { + KEEP (*crtbegin.o(.dtors)) + KEEP (*crtbegin?.o(.dtors)) + KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + } >FLASH AT>FLASH + + .dalign : + { + . = ALIGN(4); + PROVIDE(_data_vma = .); + } >RAM AT>FLASH + + .dlalign : + { + . = ALIGN(4); + PROVIDE(_data_lma = .); + } >FLASH AT>FLASH + + .data : + { + *(.gnu.linkonce.r.*) + *(.data .data.*) + *(.gnu.linkonce.d.*) + . = ALIGN(8); + PROVIDE( __global_pointer$ = . + 0x800 ); + *(.sdata .sdata.*) + *(.sdata2.*) + *(.gnu.linkonce.s.*) + . = ALIGN(8); + *(.srodata.cst16) + *(.srodata.cst8) + *(.srodata.cst4) + *(.srodata.cst2) + *(.srodata .srodata.*) + . = ALIGN(4); + PROVIDE( _edata = .); + } >RAM AT>FLASH + + .bss : + { + . = ALIGN(4); + PROVIDE( _sbss = .); + *(.sbss*) + *(.gnu.linkonce.sb.*) + *(.bss*) + *(.gnu.linkonce.b.*) + *(COMMON*) + . = ALIGN(4); + PROVIDE( _ebss = .); + } >RAM AT>FLASH + + PROVIDE( _end = _ebss); + PROVIDE( end = . ); + + .stack ORIGIN(RAM) + LENGTH(RAM) - __stack_size : + { + PROVIDE( _heap_end = . ); + . = ALIGN(4); + PROVIDE(_susrstack = . ); + . = . + __stack_size; + PROVIDE( _eusrstack = .); + } >RAM + +} + + + diff --git a/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/link_bootloader.ld b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/link_bootloader.ld new file mode 100644 index 000000000..2ae093e9a --- /dev/null +++ b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/link_bootloader.ld @@ -0,0 +1,224 @@ +ENTRY( _start ) + +__stack_size = 2048; + +PROVIDE( _stack_size = __stack_size ); + + +MEMORY +{ +/* CH32V20x_D6 - CH32V203F6-CH32V203G6-CH32V203K6-CH32V203C6 */ +/* + FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 32K + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 10K +*/ + +/* CH32V20x_D6 - CH32V203K8-CH32V203C8-CH32V203G8-CH32V203F8 */ +/* + FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 64K + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 20K +*/ + +/* CH32V20x_D8 - CH32V203RB + CH32V20x_D8W - CH32V208x + FLASH + RAM supports the following configuration + FLASH-128K + RAM-64K + FLASH-144K + RAM-48K + FLASH-160K + RAM-32K +*/ + FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 224K + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 64K +} + + +SECTIONS +{ + + .init : + { + _sinit = .; + . = ALIGN(4); + KEEP(*(SORT_NONE(.init))) + . = ALIGN(4); + _einit = .; + } >FLASH AT>FLASH + + .vector : + { + *(.vector); + . = ALIGN(64); + } >FLASH AT>FLASH + + .highcode : + { + . = ALIGN(4); + *(.highcode); + *(.highcode.*); + . = ALIGN(4); + } >FLASH AT>FLASH + + .text : + { + . = ALIGN(4); + EXCLUDE_FILE (*wchble.a) *(.text .text*) + *(.text) + *(.text.*) + *(.rodata) + *(.rodata*) + *(.sdata2.*) + *(.glue_7) + *(.glue_7t) + *(.gnu.linkonce.t.*) + . = ALIGN(4); + + /* section information for shell */ + . = ALIGN(4); + _shell_command_start = .; + KEEP (*(shellCommand)) + _shell_command_end = .; + . = ALIGN(4); + + PROVIDE(__ctors_start__ = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array)) + PROVIDE(__ctors_end__ = .); + + . = ALIGN(4); + __isrtbl_idx_start = .; + KEEP(*(.isrtbl.idx)) + __isrtbl_start = .; + KEEP(*(.isrtbl)) + __isrtbl_end = .; + . = ALIGN(4); + + PROVIDE(g_service_table_start = ABSOLUTE(.)); + KEEP(*(.g_service_table)) + PROVIDE(g_service_table_end = ABSOLUTE(.)); + + *(.gnu.linkonce.t.*) + } >FLASH AT>FLASH + + .fini : + { + KEEP(*(SORT_NONE(.fini))) + . = ALIGN(4); + } >FLASH AT>FLASH + + PROVIDE( _etext = . ); + PROVIDE( _eitcm = . ); + + .preinit_array : + { + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array)) + PROVIDE_HIDDEN (__preinit_array_end = .); + } >FLASH AT>FLASH + + .init_array : + { + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*))) + KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors)) + PROVIDE_HIDDEN (__init_array_end = .); + } >FLASH AT>FLASH + + .fini_array : + { + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*))) + KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors)) + PROVIDE_HIDDEN (__fini_array_end = .); + } >FLASH AT>FLASH + + .ctors : + { + /* gcc uses crtbegin.o to find the start of + the constructors, so we make sure it is + first. Because this is a wildcard, it + doesn't matter if the user does not + actually link against crtbegin.o; the + linker won't look for a file to match a + wildcard. The wildcard also means that it + doesn't matter which directory crtbegin.o + is in. */ + KEEP (*crtbegin.o(.ctors)) + KEEP (*crtbegin?.o(.ctors)) + /* We don't want to include the .ctor section from + the crtend.o file until after the sorted ctors. + The .ctor section from the crtend file contains the + end of ctors marker and it must be last */ + KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + } >FLASH AT>FLASH + + .dtors : + { + KEEP (*crtbegin.o(.dtors)) + KEEP (*crtbegin?.o(.dtors)) + KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + } >FLASH AT>FLASH + + .dalign : + { + . = ALIGN(4); + PROVIDE(_data_vma = .); + } >RAM AT>FLASH + + .dlalign : + { + . = ALIGN(4); + PROVIDE(_data_lma = .); + } >FLASH AT>FLASH + + .data : + { + *(.gnu.linkonce.r.*) + *(.data .data.*) + *(.gnu.linkonce.d.*) + . = ALIGN(8); + PROVIDE( __global_pointer$ = . + 0x800 ); + *(.sdata .sdata.*) + *(.sdata2.*) + *(.gnu.linkonce.s.*) + . = ALIGN(8); + *(.srodata.cst16) + *(.srodata.cst8) + *(.srodata.cst4) + *(.srodata.cst2) + *(.srodata .srodata.*) + . = ALIGN(4); + PROVIDE( _edata = .); + } >RAM AT>FLASH + + .bss : + { + . = ALIGN(4); + PROVIDE( _sbss = .); + *(.sbss*) + *(.gnu.linkonce.sb.*) + *(.bss*) + *(.gnu.linkonce.b.*) + *(COMMON*) + . = ALIGN(4); + PROVIDE( _ebss = .); + } >RAM AT>FLASH + + PROVIDE( _end = _ebss); + PROVIDE( end = . ); + + .stack ORIGIN(RAM) + LENGTH(RAM) - __stack_size : + { + PROVIDE( _heap_end = . ); + . = ALIGN(4); + PROVIDE(_susrstack = . ); + . = . + __stack_size; + PROVIDE( _eusrstack = .); + } >RAM + +} + + + diff --git a/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/Makefile b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/Makefile index e963f22e5..9a0b3b26e 100644 --- a/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/Makefile +++ b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/Makefile @@ -22,4 +22,8 @@ endif ifeq ($(CONFIG_BSP_USING_LTE),y) SRC_DIR += lte endif +ifeq ($(CONFIG_TOOL_USING_OTA),y) + SRC_DIR += ota + SRC_DIR += common +endif include $(KERNEL_ROOT)/compiler.mk diff --git a/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ModuleConfig.c b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ModuleConfig.c index d47601343..9645dfc55 100644 --- a/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ModuleConfig.c +++ b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ModuleConfig.c @@ -102,6 +102,7 @@ void CFG_READ(u32 StartAddr, u8 *Buffer, u32 Length) { } } +#ifdef BSP_USING_BLE /** * @brief 尝试使用配置通过4G连接到服务器,并且蓝牙响应连接状态报文。 * @param requestId 蓝牙请求报文ID @@ -531,6 +532,7 @@ void startParseBleRequestTask(uint8_t *request) { PrivTaskCreate(&parseBleRequestThread, &parseBleRequestTaskAttr, parseBleRequest, &parseBleRequestTaskArgs); PrivTaskStartup(&parseBleRequestThread); } +#endif /* BSP_USING_BLE */ /** * @brief 命令行显示配置信息 diff --git a/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/common/Makefile b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/common/Makefile new file mode 100755 index 000000000..5fe2493d6 --- /dev/null +++ b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/common/Makefile @@ -0,0 +1,5 @@ +ifeq ($(CONFIG_TOOL_USING_OTA),y) + SRC_FILES += common.c ymodem.c +endif + +include $(KERNEL_ROOT)/compiler.mk diff --git a/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/common/common.c b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/common/common.c new file mode 100644 index 000000000..93b9e905c --- /dev/null +++ b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/common/common.c @@ -0,0 +1,65 @@ + +/* +* Copyright (c) 2020 AIIT XUOS Lab +* XiUOS is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ + +/** +* @file: common.c +* @brief: file common.c +* @version: 1.0 +* @author: AIIT XUOS Lab +* @date: 2023/3/24 +*/ + +#include +#include "common.h" + + +/** + * @brief UartConfig + * @param None + * @retval None + */ +void UartConfig(void) +{ +} + + +/** + * @brief Print a string on the HyperTerminal + * @param s: The string to be printed + * @retval None + */ +void Serial_PutString(uint8_t *s) +{ + KPrintf("%s", s); +} + +/** + * @brief Test to see if a key has been pressed on the HyperTerminal + * @param key: The key pressed + * @retval 1: Correct + * 0: Error + */ +uint32_t SerialKeyPressed(uint8_t *key) +{ + return 0; +} + +/** + * @brief Get a key from the HyperTerminal + * @param None + * @retval The Key Pressed + */ +uint8_t GetKey(void) +{ + return 0; +} diff --git a/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/common/ymodem.c b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/common/ymodem.c new file mode 100644 index 000000000..fed17995b --- /dev/null +++ b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/common/ymodem.c @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2020 AIIT XUOS Lab +* XiUOS is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ + +/** +* @file: ymodem.c +* @brief: file ymodem.c +* @version: 1.0 +* @author: AIIT XUOS Lab +* @date: 2023/3/24 +*/ +#include +#include "ymodem.h" +#include "string.h" +#include "flash_for_ota.h" + +uint8_t tab_1024[1024] ={0}; +uint8_t FileName[FILE_NAME_LENGTH]; + + + +/******************************************************************************* +* 函 数 名: Ymodem_Receive +* 功能描述: 使用ymodem协议接收文件 +* 形 参: buf:数据buffer + addr:下载flash起始地址 + timeout:超时时间 +* 返 回 值: 文件的大小 +*******************************************************************************/ +int32_t Ymodem_Receive(uint8_t *buf, const uint32_t addr) +{ + int32_t size = 0; + return size; +} + +/******************************************************************************* +* 函 数 名: SerialDownload +* 功能描述: 通过串口下载文件 +* 形 参: addr:存储文件的flash起始地址 +* 返 回 值: 文件的大小 +*******************************************************************************/ +int32_t SerialDownload(const uint32_t addr) +{ + int32_t Size = 0; + return Size; +} diff --git a/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/include/boot_for_ota.h b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/include/boot_for_ota.h new file mode 100644 index 000000000..eabc70c47 --- /dev/null +++ b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/include/boot_for_ota.h @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2020 AIIT XUOS Lab +* XiUOS is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ + +/** +* @file boot_for_ota.h +* @brief support bootloader function +* @version 2.0 +* @author AIIT XUOS Lab +* @date 2023-11-20 +*/ + +#ifndef __BOOT_FOR_OTA_H__ +#define __BOOT_FOR_OTA_H__ + +#define IMAGE_IAP_START_ADD 0x08000000 +#define IMAGE_IAP_SIZE 224 * 1024 +#define IMAGE_A_START_ADD (IMAGE_IAP_START_ADD + IMAGE_IAP_SIZE) + +void mcuboot_bord_init(void); +void mcuboot_reset(void); +void mcuboot_jump(void); +void mcuboot_delay(uint32_t ms); + +#endif + diff --git a/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/include/common.h b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/include/common.h new file mode 100644 index 000000000..216d8e2b9 --- /dev/null +++ b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/include/common.h @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2020 AIIT XUOS Lab +* XiUOS is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ + +/** +* @file: common.h +* @brief: file common.h +* @version: 1.0 +* @author: AIIT XUOS Lab +* @date: 2023/3/24 +*/ + +#ifndef _COMMON_H +#define _COMMON_H + +#include + +enum { + kStatus_Success = 0, +}; + +void UartConfig(void); +uint32_t SerialKeyPressed(uint8_t *key); +uint8_t GetKey(void); +void SerialPutChar(uint8_t c); +void Serial_PutString(uint8_t *s); + +#endif diff --git a/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/include/flash_for_ota.h b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/include/flash_for_ota.h new file mode 100644 index 000000000..79aed412f --- /dev/null +++ b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/include/flash_for_ota.h @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2020 AIIT XUOS Lab +* XiUOS is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ + + +/** +* @file flash_for_ota.h +* @brief support flash function +* @version 2.0 +* @author AIIT XUOS Lab +* @date 2023-11-20 +*/ + +#ifndef __FLASH_FOR_OTA_H__ +#define __FLASH_FOR_OTA_H__ + +#include "common.h" + +#define FLASH_PAGE_FAST_SIZE 256 +#define FLASH_BLOCK_SIZE 4096 + +typedef int32_t status_t; + +void FLASH_Init(void); +void FLASH_DeInit(void); +status_t Flash_Erase(uint32_t start_addr, uint32_t imageSize); +status_t Flash_Write(uint32_t WriteAddr, uint8_t *pBuffer, uint32_t NumByteToWrite); +status_t Flash_Read(uint32_t addr, uint8_t *buf, uint32_t len); +status_t Flash_Copy(uint32_t srcAddr,uint32_t dstAddr, uint32_t imageSize); + +#endif + diff --git a/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/include/ymodem.h b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/include/ymodem.h new file mode 100644 index 000000000..d40b826fe --- /dev/null +++ b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/include/ymodem.h @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2020 AIIT XUOS Lab +* XiUOS is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ + +/** +* @file: ymodem.h +* @brief: file ymodem.h +* @version: 1.0 +* @author: AIIT XUOS Lab +* @date: 2023/3/24 +*/ + + +#ifndef _YMODEM_H_ +#define _YMODEM_H_ + +#include + +#define PACKET_SEQNO_INDEX (1) +#define PACKET_SEQNO_COMP_INDEX (2) + +#define PACKET_HEADER (3) +#define PACKET_TRAILER (2) +#define PACKET_OVERHEAD (PACKET_HEADER + PACKET_TRAILER) +#define PACKET_SIZE (128) +#define PACKET_1K_SIZE (1024) + +#define FILE_NAME_LENGTH (256) +#define FILE_SIZE_LENGTH (16) + +#define SOH (0x01) /* start of 128-byte data packet */ +#define STX (0x02) /* start of 1024-byte data packet */ +#define EOT (0x04) /* end of transmission */ +#define ACK (0x06) /* acknowledge */ +#define NAK (0x15) /* negative acknowledge */ +#define CA (0x18) /* two of these in succession aborts transfer */ +#define CRC16 (0x43) /* 'C' == 0x43, request 16-bit CRC */ + +#define ABORT1 (0x41) /* 'A' == 0x41, abort by user */ +#define ABORT2 (0x61) /* 'a' == 0x61, abort by user */ + +#define NAK_TIMEOUT (0x100000) +#define MAX_ERRORS (5) + +int32_t SerialDownload(const uint32_t addr); +int32_t Ymodem_Receive(uint8_t *buf, const uint32_t addr); + +#endif diff --git a/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ota/Makefile b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ota/Makefile new file mode 100644 index 000000000..982ca9cbc --- /dev/null +++ b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ota/Makefile @@ -0,0 +1,3 @@ +SRC_FILES := flash_for_ota.c boot_for_ota.c + +include $(KERNEL_ROOT)/compiler.mk diff --git a/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ota/boot_for_ota.c b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ota/boot_for_ota.c new file mode 100644 index 000000000..1c8ae1190 --- /dev/null +++ b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ota/boot_for_ota.c @@ -0,0 +1,133 @@ +/* +* Copyright (c) 2020 AIIT XUOS Lab +* XiUOS is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ + +/** +* @file boot_for_ota.c +* @brief support bootloader function +* @version 2.0 +* @author AIIT XUOS Lab +* @date 2023-11-20 +*/ + +#include +#include +#include "boot_for_ota.h" +#include "flash_for_ota.h" + +#include "board.h" + +#include +#include +#include +#include + +#include "HAL.h" +#include "adc.h" +#include "ch32v20x.h" +#include "connect_ble.h" +#include "connect_can.h" +#include "connect_ether.h" +#include "connect_lte.h" +#include "connect_rs485.h" +#include "connect_uart.h" +#include "core_riscv.h" +#include "config.h" +#include "xsconfig.h" + + +#ifdef TOOL_USING_OTA + +#define jumpApp ((void (*)(void))((int *)(IMAGE_A_START_ADD-0x08000000))) + + +static uint32_t _SysTick_Config(uint32_t ticks) { + // SystemCoreClockUpdate(); + NVIC_SetPriority(SysTicK_IRQn, 0x01); + NVIC_SetPriority(Software_IRQn, 0xf0); + NVIC_EnableIRQ(SysTicK_IRQn); + NVIC_EnableIRQ(Software_IRQn); + SysTick->CTLR = 0; + SysTick->SR = 0; + SysTick->CNT = 0; + SysTick->CMP = ticks - 1; + SysTick->CTLR = 0xF; + return 0; +} + +void mcuboot_bord_init(void) +{ + DISABLE_INTERRUPT(); + /* system irq table must be inited before initialization of Hardware irq */ + SysInitIsrManager(); + +// InitBoardHardware(); +// XiUOSStartup(); + + Delay_Init(); + USART_Printf_Init(115200); + /* System Tick Configuration */ + extern uint32_t SystemCoreClock; + _SysTick_Config(SystemCoreClock / TICK_PER_SECOND); + /* initialize memory system */ + InitBoardMemory(MEMORY_START_ADDRESS, (void *)MEMORY_END_ADDRESS); + +#ifdef BSP_USING_UART + InitHwUart(); + InstallConsole("uart1", SERIAL_DRV_NAME_1, SERIAL_1_DEVICE_NAME_0); + KPrintf("\nboot console init completed.\n"); + KPrintf("boot compiled on: %s at %s\n", __DATE__, __TIME__); +#endif + + void readRomConfiguration(void); + readRomConfiguration(); // 读取配置信息到外部变量CFG中 + + KPrintf("boot board initialization......\n"); + + /* + BOARD_ConfigMPU(); + BOARD_InitPins(); + BOARD_BootClockRUN(); + UartConfig(); + SysTick_Config(SystemCoreClock / TICK_PER_SECOND);*/ +} + +void mcuboot_reset(void) +{ + /* + __set_FAULTMASK(1); + NVIC_SystemReset();*/ +} + +void mcuboot_jump(void) +{ + KPrintf("boot jumpApp\n"); + jumpApp(); + /* + uint32_t addr = XIUOS_FLAH_ADDRESS; + + SCB->VTOR = addr; + asm volatile("LDR R0, %0" : : "m"(addr)); + asm volatile("LDR R0, [R0]"); + asm volatile("MOV SP, R0"); + + addr += 4; + asm volatile("LDR R0, %0" : : "m"(addr)); + asm volatile("LDR R0, [R0]"); + asm volatile("BX R0");*/ +} + +void mcuboot_delay(uint32_t ms) +{ +/* ImxrtMsDelay(ms);*/ +} + +#endif \ No newline at end of file diff --git a/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ota/flash_for_ota.c b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ota/flash_for_ota.c new file mode 100644 index 000000000..263063d92 --- /dev/null +++ b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ota/flash_for_ota.c @@ -0,0 +1,258 @@ +/* +* Copyright (c) 2020 AIIT XUOS Lab +* XiUOS is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ + +/** +* @file flash_for_ota.c +* @brief support flash function +* @version 2.0 +* @author AIIT XUOS Lab +* @date 2023-11-20 +*/ + +#include +#include +#include "flash_for_ota.h" +#include "ch32v20x_flash.h" + +#if 0 +uint8_t NorFlash_BUFFER[4096]; //4K buffer cache +uint8_t buffer[FLASH_PAGE_SIZE]; //256 bytes buffer cache +#endif + + + +/******************************************************************************* +* 函 数 名: FLASH_Init +* 功能描述: Flash接口初始化,需在进行Flash相关操作前进行调用 +* 形 参: 无 +* 返 回 值: 无 +*******************************************************************************/ +void FLASH_Init(void) +{ + #if 0 + /* Update LUT Table for Status, Write Enable, Erase and Program */ + ROM_FLEXSPI_NorFlash_UpdateLut(0, NOR_CMD_LUT_SEQ_IDX_READSTATUS, (const uint32_t *)FlashLookupTable.ReadStatus_Seq, 10U); + /* Use 30MHz Flexspi clock for safe operation */ + flexspi_clock_config(0, kFLEXSPISerialClk_30MHz, kFLEXSPIClk_DDR); + extern flexspi_nor_config_t Qspiflash_config; + flexspi_config_mcr1(0, &Qspiflash_config.memConfig); + flexspi_configure_dll(0, &Qspiflash_config.memConfig); + ROM_FLEXSPI_NorFlash_ClearCache(0); + #endif +} + + +/******************************************************************************* +* 函 数 名: FLASH_DeInit +* 功能描述: Flash接口反初始化,需在完成Flash相关操作后进行调用 +* 形 参: 无 +* 返 回 值: 无 +*******************************************************************************/ +void FLASH_DeInit(void) +{ + #if 0 + lookuptable_t clearlut; + memset(&clearlut, 0, sizeof(lookuptable_t)); + ROM_FLEXSPI_NorFlash_UpdateLut(0, NOR_CMD_LUT_SEQ_IDX_READSTATUS, (const uint32_t *)FlashLookupTable.ReadStatus_Seq, 10U); + /* Use 30MHz Flexspi clock for safe operation */ + flexspi_clock_config(0, kFLEXSPISerialClk_30MHz, kFLEXSPIClk_DDR); + #endif +} + +/******************************************************************************* +* 函 数 名: Flash_Erase +* 功能描述: 以扇区为擦除单位擦除Flash指定长度的空间,最终擦除的字节可能大于imageSize +* 形 参: start_addr:擦除区域起始地址 + imageSize:要擦除的字节数 +* 返 回 值: 如果函数执行成功,状态值为 kStatus_Success,否则状态值为其他错误码 +*******************************************************************************/ +status_t Flash_Erase(uint32_t start_addr, uint32_t imageSize) +{ + uint16_t i; + uint32_t pageNum = (imageSize%FLASH_PAGE_FAST_SIZE != 0)? (imageSize/FLASH_PAGE_FAST_SIZE + 1):(imageSize/FLASH_PAGE_FAST_SIZE); + + KPrintf("Flash_Erase start_addr=0x%x imageSize=0x%x\n", start_addr, imageSize); + KPrintf("Flash_Erase pageNum=%d\n", pageNum); + FLASH_Unlock_Fast(); + for(i = 0; i < pageNum; i++) + { + FLASH_ErasePage_Fast(start_addr + (i * FLASH_PAGE_FAST_SIZE)); + } + FLASH_Lock_Fast(); + + return (status_t)kStatus_Success; +} + +/******************************************************************************* +* 函 数 名: Flash_Write +* 功能描述: 写入W25QXX在指定地址开始写入指定长度的数据 +* 形 参: pBuffer:数据存储区 + WriteAddr:开始写入的地址 + NumByteToWrite:要写入的字节数(最大65535) +* 返 回 值: 如果函数执行成功,状态值为 kStatus_Success,否则状态值为其他错误码 +* 注 释: 该函数带擦除操作 +*******************************************************************************/ +status_t Flash_Write(uint32_t WriteAddr, uint8_t *pBuffer, uint32_t NumByteToWrite) +{ + uint8_t page_count; + uint32_t pageNum = (NumByteToWrite%FLASH_PAGE_FAST_SIZE != 0)? (NumByteToWrite/FLASH_PAGE_FAST_SIZE + 1):(NumByteToWrite/FLASH_PAGE_FAST_SIZE); + + FLASH_Unlock_Fast(); + for(page_count = 0; page_count < pageNum; page_count++) + { + FLASH_ProgramPage_Fast(WriteAddr + (page_count * FLASH_PAGE_FAST_SIZE), (uint32_t *)&pBuffer[page_count * FLASH_PAGE_FAST_SIZE]); + } + FLASH_Lock_Fast(); + + return (status_t)kStatus_Success; + +} + +/******************************************************************************* +* 函 数 名: Flash_Read +* 功能描述: 读Flash内容 +* 形 参: addr:读取区域起始地址 + buf:数据存储区 + len:要读取的字节数 +* 返 回 值: 如果函数执行成功,状态值为 kStatus_Success,否则状态值为其他错误码 +*******************************************************************************/ +status_t Flash_Read(uint32_t addr, uint8_t *buf, uint32_t len) +{ + uint32_t i; + for(i=0;i APP_FLASH_SIZE) + { + return (status_t)kStatus_Fail; + } + + status = Flash_Erase(dstAddr,imageSize); + if(status != kStatus_Success) + { + KPrintf("Erase flash 0x%08x failure !\r\n",dstAddr); + return status; + } + + PageNum = imageSize/FLASH_PAGE_SIZE; + Remain = imageSize%FLASH_PAGE_SIZE; + + for(i=0;i=SECTOR_SIZE) + { + status = Flash_Write(WriteAddr,dataBuff,dataLen); + if(status != kStatus_Success) + { + return status; + } + packetNum = 0; + dataLen = 0; + } + *FlashAddress += DataLength; + } + else + { + status = Flash_Write(WriteAddr,dataBuff,dataLen); + if(status != kStatus_Success) + { + return status; + } + packetNum = 0; + dataLen = 0; + } + return (status_t)kStatus_Success;; + #endif + return 0; +} diff --git a/Ubiquitous/XiZi_IIoT/script.sh b/Ubiquitous/XiZi_IIoT/script.sh new file mode 100755 index 000000000..2da11a0bd --- /dev/null +++ b/Ubiquitous/XiZi_IIoT/script.sh @@ -0,0 +1,6 @@ +#! /bin/env sh +export CROSS_COMPILE=/home/syg/data/ch32v208/xpack-riscv-none-elf-gcc-11.3.0-1/bin/riscv-none-elf- +make BOARD=ch32v208rbt6 distclean +make BOARD=ch32v208rbt6 menuconfig +make BOARD=ch32v208rbt6 +