Merge pull request #186 from Mculover666/master

add errcode support for ota
This commit is contained in:
Supowang
2020-06-24 15:06:51 +08:00
committed by GitHub
8 changed files with 127 additions and 34 deletions

View File

@@ -145,7 +145,7 @@
<SetRegEntry> <SetRegEntry>
<Number>0</Number> <Number>0</Number>
<Key>ST-LINKIII-KEIL_SWO</Key> <Key>ST-LINKIII-KEIL_SWO</Key>
<Name>-U303030303030303030303031 -O10446 -SF4000 -C0 -A0 -I0 -HNlocalhost -HP7184 -P1 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0STM32L4xx_256.FLM -FS08000000 -FL040000 -FP0($$Device:STM32L431RCTx$CMSIS\Flash\STM32L4xx_256.FLM)</Name> <Name>-U51FF68064965575333151687 -O10446 -SF10000 -C0 -A0 -I0 -HNlocalhost -HP7184 -P1 -N00("ARM CoreSight SW-DP (ARM Core") -D00(2BA01477) -L00(0) -TO131090 -TC10000000 -TT10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0STM32L4xx_256.FLM -FS08000000 -FL07800 -FP0($$Device:STM32L431RCTx$CMSIS\Flash\STM32L4xx_256.FLM)</Name>
</SetRegEntry> </SetRegEntry>
</TargetDriverDllRegistry> </TargetDriverDllRegistry>
<Breakpoint> <Breakpoint>
@@ -245,6 +245,38 @@
<ExecCommand></ExecCommand> <ExecCommand></ExecCommand>
<Expression></Expression> <Expression></Expression>
</Bp> </Bp>
<Bp>
<Number>6</Number>
<Type>0</Type>
<LineNumber>65</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>0</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>0</BreakIfRCount>
<Filename>..\Src\main.c</Filename>
<ExecCommand></ExecCommand>
<Expression></Expression>
</Bp>
<Bp>
<Number>7</Number>
<Type>0</Type>
<LineNumber>120</LineNumber>
<EnabledFlag>0</EnabledFlag>
<Address>0</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>0</BreakIfRCount>
<Filename>..\..\..\..\..\..\components\ota\common\partition\ota_partition.c</Filename>
<ExecCommand></ExecCommand>
<Expression></Expression>
</Bp>
</Breakpoint> </Breakpoint>
<WatchWindow1> <WatchWindow1>
<Ww> <Ww>
@@ -310,7 +342,7 @@
<pMultCmdsp></pMultCmdsp> <pMultCmdsp></pMultCmdsp>
<DebugDescription> <DebugDescription>
<Enable>1</Enable> <Enable>1</Enable>
<EnableFlashSeq>1</EnableFlashSeq> <EnableFlashSeq>0</EnableFlashSeq>
<EnableLog>0</EnableLog> <EnableLog>0</EnableLog>
<Protocol>2</Protocol> <Protocol>2</Protocol>
<DbgClock>10000000</DbgClock> <DbgClock>10000000</DbgClock>
@@ -340,7 +372,7 @@
<Group> <Group>
<GroupName>Application/User</GroupName> <GroupName>Application/User</GroupName>
<tvExp>0</tvExp> <tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel> <cbSel>0</cbSel>
<RteFlg>0</RteFlg> <RteFlg>0</RteFlg>
@@ -700,7 +732,7 @@
<Group> <Group>
<GroupName>Hardware</GroupName> <GroupName>Hardware</GroupName>
<tvExp>0</tvExp> <tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel> <cbSel>0</cbSel>
<RteFlg>0</RteFlg> <RteFlg>0</RteFlg>
@@ -1196,7 +1228,7 @@
<Group> <Group>
<GroupName>ota_common</GroupName> <GroupName>ota_common</GroupName>
<tvExp>0</tvExp> <tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel> <cbSel>0</cbSel>
<RteFlg>0</RteFlg> <RteFlg>0</RteFlg>

View File

@@ -10,14 +10,14 @@
<TargetName>TencentOS_tiny</TargetName> <TargetName>TencentOS_tiny</TargetName>
<ToolsetNumber>0x4</ToolsetNumber> <ToolsetNumber>0x4</ToolsetNumber>
<ToolsetName>ARM-ADS</ToolsetName> <ToolsetName>ARM-ADS</ToolsetName>
<pCCUsed>5060750::V5.06 update 6 (build 750)::ARMCC</pCCUsed> <pCCUsed>5060750::V5.06 update 6 (build 750)::.\ARMCC</pCCUsed>
<uAC6>0</uAC6> <uAC6>0</uAC6>
<TargetOption> <TargetOption>
<TargetCommonOption> <TargetCommonOption>
<Device>STM32L431RCTx</Device> <Device>STM32L431RCTx</Device>
<Vendor>STMicroelectronics</Vendor> <Vendor>STMicroelectronics</Vendor>
<PackID>Keil.STM32L4xx_DFP.2.0.0</PackID> <PackID>Keil.STM32L4xx_DFP.2.4.0</PackID>
<PackURL>http://www.keil.com/pack</PackURL> <PackURL>https://www.keil.com/pack/</PackURL>
<Cpu>IRAM(0x20000000-0x2000FFFF) IROM(0x8000000-0x803FFFF) CLOCK(8000000) FPU2 CPUTYPE("Cortex-M4")</Cpu> <Cpu>IRAM(0x20000000-0x2000FFFF) IROM(0x8000000-0x803FFFF) CLOCK(8000000) FPU2 CPUTYPE("Cortex-M4")</Cpu>
<FlashUtilSpec></FlashUtilSpec> <FlashUtilSpec></FlashUtilSpec>
<StartupFile></StartupFile> <StartupFile></StartupFile>
@@ -185,6 +185,7 @@
<uocXRam>0</uocXRam> <uocXRam>0</uocXRam>
<RvdsVP>2</RvdsVP> <RvdsVP>2</RvdsVP>
<RvdsMve>0</RvdsMve> <RvdsMve>0</RvdsMve>
<RvdsCdeCp>0</RvdsCdeCp>
<hadIRAM2>0</hadIRAM2> <hadIRAM2>0</hadIRAM2>
<hadIROM2>0</hadIROM2> <hadIROM2>0</hadIROM2>
<StupSel>8</StupSel> <StupSel>8</StupSel>
@@ -275,7 +276,7 @@
<OCR_RVCT4> <OCR_RVCT4>
<Type>1</Type> <Type>1</Type>
<StartAddress>0x8000000</StartAddress> <StartAddress>0x8000000</StartAddress>
<Size>0x40000</Size> <Size>0x7800</Size>
</OCR_RVCT4> </OCR_RVCT4>
<OCR_RVCT5> <OCR_RVCT5>
<Type>1</Type> <Type>1</Type>
@@ -351,7 +352,7 @@
<NoWarn>0</NoWarn> <NoWarn>0</NoWarn>
<uSurpInc>0</uSurpInc> <uSurpInc>0</uSurpInc>
<useXO>0</useXO> <useXO>0</useXO>
<uClangAs>0</uClangAs> <ClangAsOpt>4</ClangAsOpt>
<VariousControls> <VariousControls>
<MiscControls></MiscControls> <MiscControls></MiscControls>
<Define></Define> <Define></Define>
@@ -1034,4 +1035,19 @@
<files/> <files/>
</RTE> </RTE>
<LayerInfo>
<Layers>
<Layer>
<LayName>&lt;Project Info&gt;</LayName>
<LayDesc></LayDesc>
<LayUrl></LayUrl>
<LayKeys></LayKeys>
<LayCat></LayCat>
<LayLic></LayLic>
<LayTarg>0</LayTarg>
<LayPrjMark>1</LayPrjMark>
</Layer>
</Layers>
</LayerInfo>
</Project> </Project>

View File

@@ -38,6 +38,8 @@ extern ota_flash_prop_t stm32l4_norflash_onchip_prop_ota;
int main(void) int main(void)
{ {
ota_err_t ret;
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init(); HAL_Init();
@@ -46,10 +48,10 @@ int main(void)
MX_USART2_UART_Init(); MX_USART2_UART_Init();
uint32_t partition_addr = 0x08024800; uint32_t partition_addr = 0x0803f800;
if (ota_env_init(OTA_UPDATE_IN_POSITION, partition_addr, &stm32l4_norflash_onchip_drv_ota, &stm32l4_norflash_onchip_prop_ota) < 0) { if ((ret = ota_env_init(OTA_UPDATE_IN_POSITION, partition_addr, &stm32l4_norflash_onchip_drv_ota, &stm32l4_norflash_onchip_prop_ota)) != OTA_ERR_NONE) {
printf("env init failed!\n"); printf("env init failed!OTA errcode = %d\n", ret);
return -1; return -1;
} }

View File

@@ -19,23 +19,25 @@
#include "ota_env.h" #include "ota_env.h"
#include "ota_partition.h" #include "ota_partition.h"
int ota_env_init(ota_updt_type_t updt_type, uint32_t partition_addr, ota_flash_drv_t *flash_drv, ota_flash_prop_t *flash_prop) ota_err_t ota_env_init(ota_updt_type_t updt_type, uint32_t partition_addr, ota_flash_drv_t *flash_drv, ota_flash_prop_t *flash_prop)
{ {
ota_err_t ret;
if (ota_flash_init(flash_drv, flash_prop) < 0) { if (ota_flash_init(flash_drv, flash_prop) < 0) {
return -1; return OTA_ERR_FLASH_INIT_FAIL;
} }
if (ota_partition_load(updt_type, partition_addr) < 0) { if ((ret = ota_partition_load(updt_type, partition_addr)) != OTA_ERR_NONE) {
return -1; return ret;
} }
if (tos_kv_init(ota_partition_start(OTA_PARTITION_KV), if (tos_kv_init(ota_partition_start(OTA_PARTITION_KV),
ota_partition_end(OTA_PARTITION_KV), ota_partition_end(OTA_PARTITION_KV),
(kv_flash_drv_t *)flash_drv, (kv_flash_drv_t *)flash_drv,
(kv_flash_prop_t *)flash_prop) != KV_ERR_NONE) { (kv_flash_prop_t *)flash_prop) != KV_ERR_NONE) {
return -1; return OTA_ERR_KV_FAIL;
} }
return 0; return OTA_ERR_NONE;
} }

View File

@@ -21,8 +21,9 @@
#include "stdint.h" #include "stdint.h"
#include "ota_flash.h" #include "ota_flash.h"
#include "ota_partition.h" #include "ota_partition.h"
#include "ota_err.h"
int ota_env_init(ota_updt_type_t updt_type, uint32_t partition_addr, ota_flash_drv_t *flash_drv, ota_flash_prop_t *flash_prop); ota_err_t ota_env_init(ota_updt_type_t updt_type, uint32_t partition_addr, ota_flash_drv_t *flash_drv, ota_flash_prop_t *flash_prop);
#endif /* _OTA_ENV_H_ */ #endif /* _OTA_ENV_H_ */

View File

@@ -26,30 +26,31 @@ static int partitions_verify(ota_pt_t *pts, int n)
for (i = 0; i < n; ++i) { for (i = 0; i < n; ++i) {
if (pts[i].start >= pts[i].end) { if (pts[i].start >= pts[i].end) {
return -1; return OTA_ERR_PARTITION_ADDR_FAIL;
} }
if (!ota_flash_size_is_aligned(pts[i].end - pts[i].start)) { if (!ota_flash_size_is_aligned(pts[i].end - pts[i].start)) {
return -1; return OTA_ERR_PARTITION_NOT_ALIGN;
} }
} }
return 0; return 0;
} }
int ota_partition_load(ota_updt_type_t updt_type, uint32_t partition_addr) ota_err_t ota_partition_load(ota_updt_type_t updt_type, uint32_t partition_addr)
{ {
uint8_t crc = 0; uint8_t crc = 0;
ota_pt_hdr_t hdr; ota_pt_hdr_t hdr;
ota_err_t ret;
memset(&ctrl, 0, sizeof(ota_pt_ctrl_t)); memset(&ctrl, 0, sizeof(ota_pt_ctrl_t));
if (ota_flash_read(partition_addr, &hdr, sizeof(ota_pt_hdr_t)) != 0) { if (ota_flash_read(partition_addr, &hdr, sizeof(ota_pt_hdr_t)) != 0) {
return -1; return OTA_ERR_PARTITION_READ_FAIL;
} }
if (hdr.magic != OTA_PARTITION_MAGIC) { if (hdr.magic != OTA_PARTITION_MAGIC) {
return -1; return OTA_ERR_PARTITION_MAGIC_NOT_SAME;
} }
ctrl.updt_type = updt_type; ctrl.updt_type = updt_type;
@@ -59,33 +60,33 @@ int ota_partition_load(ota_updt_type_t updt_type, uint32_t partition_addr)
if (updt_type == OTA_UPDATE_IN_POSITION) { if (updt_type == OTA_UPDATE_IN_POSITION) {
if (ota_flash_read(partition_addr + sizeof(ota_pt_hdr_t), &IP_PTS, sizeof(ota_ip_pts_t)) != 0) { if (ota_flash_read(partition_addr + sizeof(ota_pt_hdr_t), &IP_PTS, sizeof(ota_ip_pts_t)) != 0) {
return -1; return OTA_ERR_PARTITION_READ_FAIL;
} }
if (partitions_verify(IP_PTS_ARRAY, sizeof(IP_PTS) / sizeof(ota_pt_t)) != 0) { if ((ret = partitions_verify(IP_PTS_ARRAY, sizeof(IP_PTS) / sizeof(ota_pt_t))) != OTA_ERR_NONE) {
return -1; return ret;
} }
crc = partitions_crc(crc, IP_PTS_ARRAY, sizeof(IP_PTS) / sizeof(ota_pt_t)); crc = partitions_crc(crc, IP_PTS_ARRAY, sizeof(IP_PTS) / sizeof(ota_pt_t));
} else if (updt_type == OTA_UPDATE_PING_PONG) { } else if (updt_type == OTA_UPDATE_PING_PONG) {
if (ota_flash_read(partition_addr + sizeof(ota_pt_hdr_t), &PP_PTS, sizeof(ota_pp_pts_t)) != 0) { if (ota_flash_read(partition_addr + sizeof(ota_pt_hdr_t), &PP_PTS, sizeof(ota_pp_pts_t)) != 0) {
return -1; return OTA_ERR_PARTITION_READ_FAIL;
} }
if (partitions_verify(PP_PTS_ARRAY, sizeof(PP_PTS) / sizeof(ota_pt_t)) != 0) { if (partitions_verify(PP_PTS_ARRAY, sizeof(PP_PTS) / sizeof(ota_pt_t)) != 0) {
return -1; return ret;
} }
crc = partitions_crc(crc, PP_PTS_ARRAY, sizeof(PP_PTS) / sizeof(ota_pt_t)); crc = partitions_crc(crc, PP_PTS_ARRAY, sizeof(PP_PTS) / sizeof(ota_pt_t));
} else { } else {
return -1; return OTA_ERR_UPDT_TYPE_UNKOWN;
} }
if (crc != hdr.crc) { if (crc != hdr.crc) {
return -1; return OTA_ERR_PARTITION_CRC_FAIL;
} }
return 0; return OTA_ERR_NONE;
} }
uint32_t ota_partition_start(ota_pt_type_t pt_type) uint32_t ota_partition_start(ota_pt_type_t pt_type)

View File

@@ -20,6 +20,7 @@
#include "crc8.h" #include "crc8.h"
#include "ota_image.h" #include "ota_image.h"
#include "ota_err.h"
#define OTA_PARTITION_INVALID (uint32_t)-1 #define OTA_PARTITION_INVALID (uint32_t)-1
@@ -128,7 +129,7 @@ typedef struct ota_partition_control_st {
ota_pts_t pts; ota_pts_t pts;
} ota_pt_ctrl_t; } ota_pt_ctrl_t;
int ota_partition_load(ota_updt_type_t updt_type, uint32_t partition_addr); ota_err_t ota_partition_load(ota_updt_type_t updt_type, uint32_t partition_addr);
uint32_t ota_partition_start(ota_pt_type_t pt_type); uint32_t ota_partition_start(ota_pt_type_t pt_type);

View File

@@ -0,0 +1,38 @@
/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#ifndef _OTA_ERR_H_
#define _OTA_ERR_H_
typedef enum ota_err_en {
OTA_ERR_NONE = 0u,
OTA_ERR_FLASH_INIT_FAIL = 1u,
OTA_ERR_PARTITION_READ_FAIL = 2u,
OTA_ERR_PARTITION_MAGIC_NOT_SAME,
OTA_ERR_PARTITION_ADDR_FAIL,
OTA_ERR_PARTITION_NOT_ALIGN,
OTA_ERR_PARTITION_CRC_FAIL,
OTA_ERR_UPDT_TYPE_UNKOWN,
OTA_ERR_KV_FAIL
} ota_err_t;
#endif /* _OTA_ERR_H_ */