diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/Makefile b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/Makefile index e7c289a05..32f220b50 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/Makefile +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/Makefile @@ -39,4 +39,8 @@ ifeq ($(CONFIG_BSP_USING_WDT),y) SRC_DIR += wdt endif +ifeq ($(CONFIG_TOOL_USING_OTA),y) + SRC_DIR += ota +endif + include $(KERNEL_ROOT)/compiler.mk diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/Makefile b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/Makefile index 811164369..87aa9bf8b 100755 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/Makefile +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/Makefile @@ -5,7 +5,7 @@ ifeq ($(CONFIG_BSP_USING_SDIO),y) endif ifeq ($(CONFIG_TOOL_USING_OTA),y) - SRC_FILES += fsl_romapi.c flash.c mcuboot.c common.c ymodem.c + SRC_FILES += fsl_romapi.c flash.c common.c ymodem.c endif include $(KERNEL_ROOT)/compiler.mk diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/flash.c b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/flash.c index c032160de..00af3765d 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/flash.c +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/flash.c @@ -755,288 +755,3 @@ status_t NorFlash_Write_NoCheck(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t Num return (status_t)kStatus_Success; } - - -/******************************************************************************* -* 函 数 名: Flash_Erase -* 功能描述: 以扇区为擦除单位擦除Flash指定长度的空间,最终擦除的字节可能大于imageSize -* 形 参: start_addr:擦除区域起始地址 - imageSize:要擦除的字节数 -* 返 回 值: 如果函数执行成功,状态值为 kStatus_Success,否则状态值为其他错误码 -*******************************************************************************/ -status_t Flash_Erase(uint32_t start_addr, uint32_t imageSize) -{ - uint16_t i; - status_t status; - uint32_t sectorNum = (imageSize%SECTOR_SIZE != 0)? (imageSize/SECTOR_SIZE + 1):(imageSize/SECTOR_SIZE); - - for(i=0;i SECTOR_SIZE) - { - secRemain = SECTOR_SIZE;//下一个扇区还是写不完 - } - else - { - secRemain = NumByteToWrite;//下一个扇区可以写完了 - } - } - } - - 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) -{ - /* For FlexSPI Memory ReadBack, use IP Command instead of AXI command for security */ - if((addr >= 0x60000000) && (addr < 0x61000000)) - { - return FLASH_ReadBuf(addr, (void *)buf, len); - } - else - { - void* result = memcpy(buf, (void*)addr, len); - if(result == NULL) - { - return (status_t)kStatus_Fail; - } - else - { - return (status_t)kStatus_Success; - } - } -} - - -/******************************************************************************* -* 函 数 名: Flash_Copy -* 功能描述: 实现flash数据在分区之间的拷贝 -* 形 参: srcAddr:源flash的起始地址 - dstAddr:目标flash的起始地址; - imageSize:要拷贝的flash空间大小,单位为字节 -* 返 回 值: 如果函数执行成功,状态值为 kStatus_Success,否则状态值为其他错误码 -*******************************************************************************/ -status_t Flash_Copy(uint32_t srcAddr,uint32_t dstAddr, uint32_t imageSize) -{ - uint32_t PageNum, Remain, i; - status_t status; - - if((srcAddr == dstAddr) || imageSize > 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 diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/mcuboot.c b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/mcuboot.c deleted file mode 100644 index e3890c505..000000000 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/common/mcuboot.c +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2018-2020 NXP - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -/** -* @file mucboot.c -* @brief support bootloader function -* @version 2.0 -* @author AIIT XUOS Lab -* @date 2023-04-03 -*/ - -#include -#include -#include "common.h" -#include "mcuboot.h" -#include "flash.h" - -#ifdef TOOL_USING_OTA - -void mcuboot_bord_init(void) -{ - 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) -{ - 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"); -} - -extern void ImxrtMsDelay(uint32 ms); - -void mcuboot_delay(uint32_t ms) -{ - ImxrtMsDelay(ms); -} -#endif \ No newline at end of file diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/mcuboot.h b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/boot_for_ota.h similarity index 74% rename from Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/mcuboot.h rename to Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/boot_for_ota.h index f63aa1a8b..d3bb55912 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/mcuboot.h +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/boot_for_ota.h @@ -1,16 +1,9 @@ -/* - * Copyright 2018-2020 NXP - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - /** -* @file mcuboot.h +* @file boot_for_ota.h * @brief support bootloader function * @version 2.0 * @author AIIT XUOS Lab -* @date 2023-04-03 +* @date 2023-11-20 */ #ifndef __MCUBOOT_H__ diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/flash_for_ota.h b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/flash_for_ota.h new file mode 100644 index 000000000..020e8fa23 --- /dev/null +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/include/flash_for_ota.h @@ -0,0 +1,31 @@ +/** +* @file flash.h +* @brief support flexspi norflash function +* @version 2.0 +* @author AIIT XUOS Lab +* @date 2023-11-20 +*/ + +#ifndef __FLASH_H__ +#define __FLASH_H__ + +#include +#include +#include "fsl_romapi.h" +#include "flash.h" + +#define USE_HIGHT_SPEED_TRANS 1 + +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); + +#ifndef USE_HIGHT_SPEED_TRANS +status_t NOR_FLASH_Write(uint32_t* FlashAddress, uint8_t* Data ,uint16_t DataLength); +#else +status_t NOR_FLASH_Write(uint32_t* FlashAddress, uint8_t* Data ,uint16_t DataLength,uint8_t doneFlag); +#endif + +#endif + diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/ota/Kconfig b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/ota/Kconfig deleted file mode 100644 index e69de29bb..000000000 diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/ota/Makefile b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/ota/Makefile index e69de29bb..982ca9cbc 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/ota/Makefile +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/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/xidatong-arm32/third_party_driver/ota/boot_for_ota.c b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/ota/boot_for_ota.c index e69de29bb..53fa98dad 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/ota/boot_for_ota.c +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/ota/boot_for_ota.c @@ -0,0 +1,53 @@ +/** +* @file mucboot.c +* @brief support bootloader function +* @version 2.0 +* @author AIIT XUOS Lab +* @date 2023-11-20 +*/ + +#include +#include +#include "common.h" +#include "boot_for_ota.h" +#include "flash.h" + +#ifdef TOOL_USING_OTA + +void mcuboot_bord_init(void) +{ + 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) +{ + 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"); +} + +extern void ImxrtMsDelay(uint32 ms); + +void mcuboot_delay(uint32_t ms) +{ + ImxrtMsDelay(ms); +} +#endif \ No newline at end of file diff --git a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/ota/flash_for_ota.c b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/ota/flash_for_ota.c index e69de29bb..914934b66 100644 --- a/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/ota/flash_for_ota.c +++ b/Ubiquitous/XiZi_IIoT/board/xidatong-arm32/third_party_driver/ota/flash_for_ota.c @@ -0,0 +1,299 @@ +/** +* @file fsl_flash.c +* @brief support flexspi norflash function +* @version 2.0 +* @author AIIT XUOS Lab +* @date 2023-11-20 +*/ + +#include +#include "flash.h" +#include "flash_for_ota.h" +#include "MIMXRT1052.h" + +uint8_t NorFlash_BUFFER[4096]; //4K buffer cache +uint8_t buffer[FLASH_PAGE_SIZE]; //256 bytes buffer cache + +/******************************************************************************* +* 函 数 名: Flash_Erase +* 功能描述: 以扇区为擦除单位擦除Flash指定长度的空间,最终擦除的字节可能大于imageSize +* 形 参: start_addr:擦除区域起始地址 + imageSize:要擦除的字节数 +* 返 回 值: 如果函数执行成功,状态值为 kStatus_Success,否则状态值为其他错误码 +*******************************************************************************/ +status_t Flash_Erase(uint32_t start_addr, uint32_t imageSize) +{ + uint16_t i; + status_t status; + uint32_t sectorNum = (imageSize%SECTOR_SIZE != 0)? (imageSize/SECTOR_SIZE + 1):(imageSize/SECTOR_SIZE); + + for(i=0;i SECTOR_SIZE) + { + secRemain = SECTOR_SIZE;//下一个扇区还是写不完 + } + else + { + secRemain = NumByteToWrite;//下一个扇区可以写完了 + } + } + } + + 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) +{ + /* For FlexSPI Memory ReadBack, use IP Command instead of AXI command for security */ + if((addr >= 0x60000000) && (addr < 0x61000000)) + { + return FLASH_ReadBuf(addr, (void *)buf, len); + } + else + { + void* result = memcpy(buf, (void*)addr, len); + if(result == NULL) + { + return (status_t)kStatus_Fail; + } + else + { + return (status_t)kStatus_Success; + } + } +} + + +/******************************************************************************* +* 函 数 名: Flash_Copy +* 功能描述: 实现flash数据在分区之间的拷贝 +* 形 参: srcAddr:源flash的起始地址 + dstAddr:目标flash的起始地址; + imageSize:要拷贝的flash空间大小,单位为字节 +* 返 回 值: 如果函数执行成功,状态值为 kStatus_Success,否则状态值为其他错误码 +*******************************************************************************/ +status_t Flash_Copy(uint32_t srcAddr,uint32_t dstAddr, uint32_t imageSize) +{ + uint32_t PageNum, Remain, i; + status_t status; + + if((srcAddr == dstAddr) || imageSize > 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 diff --git a/Ubiquitous/XiZi_IIoT/tool/bootloader/ota/ota.c b/Ubiquitous/XiZi_IIoT/tool/bootloader/ota/ota.c index 33bccf32c..619686935 100644 --- a/Ubiquitous/XiZi_IIoT/tool/bootloader/ota/ota.c +++ b/Ubiquitous/XiZi_IIoT/tool/bootloader/ota/ota.c @@ -23,7 +23,7 @@ #include #include #include "shell.h" -#include "mcuboot.h" +#include "boot_for_ota.h" #include "ymodem.h" #include "ota.h"