diff --git a/doc/Huawei_IoT_Link_SDK_OTA_Developer_Guide.md b/doc/Huawei_IoT_Link_SDK_OTA_Developer_Guide.md new file mode 100644 index 000000000..35ab962b3 --- /dev/null +++ b/doc/Huawei_IoT_Link_SDK_OTA_Developer_Guide.md @@ -0,0 +1,221 @@ + +# Table of Contents + +1. [概述](#orgd5407db) +2. [升级文件二进制文件结构](#org98af6df) +3. [存储器接口](#orga1b2737) +4. [OTA管理接口](#org0858161) +5. [签名验证](#org0a38c46) +6. [Loader](#orgdef2ade) +7. [FOTA / SOTA](#org4d3947c) +8. [编译](#org8f1a0de) +9. [新平台适配](#org6b28673) + + + + + +# 概述 + +在应用升级过程中,无线下载更新(OTA)是一种常用,且方便的升级方式。Liteos采用的OTA升级方案基于LwM2M协议,实现了固件升级(FOTA)和软件升级(SOTA)两种升级方案。用户可根据自己的开发环境选择合适的升级方式。 +OTA功能代码结构如下图: + +![](./meta/IoT_Link/OTA/01.png) + + + +# 升级文件二进制文件结构 + +如图所示,升级压缩包中二进制文件如下图所示,FOTA与SOTA采用相同的固件格式。 + +- 签名校验值:长度256字节,对剩余文件进行hash计算后,并进行sha256加密后得到的签名密文。 + +![](./meta/IoT_Link/OTA/02.png) + +- 二进制信息:预留长度32字节,升级文件是全量升级文件或增量升级文件等信息。 +- 升级文件内容:经压缩后的升级文件,升级文件使用hdiffpatch算法对新、旧镜像进行运算生成的差分包,并使用lzma算法进行压缩。 + + + + +# 存储器接口 + +存储器结构代码位于iot\_link/sotrage目录下。存储器结构被划分为两部分,分别定义为存储设备(storage.c)与设备分区(partition.c)。 +存储设备定义的是系统中使用的不同类型存储器及接口,如内部flash,spi flash 或 nandflash等,所使用结构体如下: + + + typedef struct { + int id; + char *name; + uint32_t size; + + void (*init)(); + int (*read)(void *buf, int32_t len, uint32_t offset); + int (*write)(const uint8_t *buf, int32_t len, uint32_t offset); + int (*erase)(uint32_t offset, int32_t len); + int (*erase_write)(const void *buf, int32_t len, uint32_t offset); + }storage_device; + +设备分区定义了用户划分的分区信息,如下所示: + + + typedef struct _partition { + uint8_t dev_id; + char *name; + uint32_t start_addr; + uint32_t size; + }storage_partition; + +设备分区定义了一组外部使用的接口,系统中可以使用这组接口进行相应的读写等操作。 + + + int storage_partition_read(int part_id, uint8_t *buf, uint32_t len, uint32_t offset); + int storage_partition_write(int part_id, uint8_t *buf, uint32_t len, uint32_t offset); + int storage_partition_erase_write(int part_id, uint8_t *buf, uint32_t len, uint32_t offset); + int storage_partition_erase(int part_id, uint32_t offset, uint32_t len); + + + + +# OTA管理接口 + +系统中的OTA接口分为三个部分,OTA镜像接口、OTA包管理接口,OTA签名校验接口。 + +- OTA镜像接口: + +OTA镜像接口包括了OTA标志镜像和OTA二进制镜像。其中OTA标志存储了升级版本号、升级文件大小、当前OTA状态及OTA升级结果等信息,其结构如下: + + #pragma pack(1) + typedef struct + { + uint8_t ver[CN_OTA_VERSION_LEN]; + uint32_t ver_code; + uint32_t file_size; ///< the new bin file size + uint32_t blk_size; ///< the new bin block size + uint32_t blk_num; ///< the new bin block num + uint32_t blk_cur; + uint32_t file_off; ///< the current offet to write + uint32_t cur_state; ///< defined by en_ota_status_t + uint32_t ret_upgrade; ///< the upgrade,filled by the loader + uint32_t updater; ///< fota or sota + + uint32_t crc; ///< all the ota information computed + }ota_flag_t; + #pragma pack() + +在loader和app中维护的同一份OTA标志,APP中会根据下载进度更改cur\_state值,在loader中完成升级后会重置cur\_state值并填充升级结果到ret\_upgrade中,在进入app后将该结果上报至服务器。 +外部可调用以下接口进行OTA镜像读写操作: + + int ota_storage_bin_read(int offset, void *buf, int len); + int ota_storage_bin_write(int offset, void *msg, int len); + int ota_storage_flag_read(ota_flag_t *flag); + int ota_storage_flag_write(ota_flag_t *flag); + +- ota\_pack实现对接FOTA功能的接口封装。该文件内实现了以下接口: + + struct pack_storage_device_api_tag_s + { + int (*write_software)(pack_storage_device_api_s *thi, uint32_t offset, const uint8_t *buffer, uint32_t len); + int (*write_software_end)(pack_storage_device_api_s *thi, pack_download_result_e result, uint32_t total_len); + int (*active_software)(pack_storage_device_api_s *thi); + }; + +- Ota\_checksum实现了升级包签名验证接口。系统中可调用下面接口获取签名校验结果: + + int ota_pack_get_signature_verify_result(int sign_len, int file_len); + +若用户使用自己的公私钥对,可在此处更改prv\_public\_key为对应的公钥key值。 + + + + +# 签名验证 + +OTA升级包签名验证在下载完成后,发送执行升级命令阶段时执行。 + +收到执行命令后,系统首先将调用签名校验接口进行二进制文件签名校验,只有在验签通过后,才会执行后续的升级流程,否则会退出升级流程并上报升级失败到服务器。 + +SOTA在接收到EN\_PCP\_MSG\_EXCUTEUPDATE命令后,位于pcp.c文件中pcp\_handle\_msg函数。 +FOTA流程的签名校验放在了ota\_pack\_man\_software\_write\_end函数中。 + + + + +# Loader + +进入Loader后会在ota\_detection函数中读取OTA标志,检测当前OTA状态。若为UPDATING状态,则执行升级,否则跳转至APP。 + +增量升级过程首先会读取升级文件内容并解析出新、旧镜像大小及所使用的压缩插件等信息。 + +随后调用以下接口: + + hpatch_BOOL patch_decompress_with_cache(const hpatch_TStreamOutput* out_newData, + const hpatch_TStreamInput* oldData, + const hpatch_TStreamInput* compressedDiff, + hpatch_TDecompress* decompressPlugin, + TByte* temp_cache,TByte* temp_cache_end) + +执行还原差分镜像。 +其中接口参数out\_newData、oldData、compressedDiff,需要由用户定义并实现对应的镜像读写接口。 + + + + +# FOTA / SOTA + +FOTA和SOTA都是基于LwM2M协议实现的升级方案,区别是基于不同的对象。 + +FOTA使用的是协议中定义的固件对象升级方案,基于对象5实现。 + +SOTA使用自定义对象19,并使用了PCP协议作为数据传输协议。因此,在使用SOTA时需要将config.mk中的CONFIG\_PCP\_ENABLE选项使能并使用oc\_lwm2m\_ota\_demo。 + + + + +# 编译 + +实现OTA功能需要编译Loader镜像和App镜像。需要对编译选项进行修改: + +- Loader和App镜像大小定义在链接脚本中,当定义的镜像空间不足以容纳生成的镜像时,需要适当的调整其大小。Loader和app的链接脚本分别是os\_loader.ld和os\_loader.ld,在其中更改MEMORY中的FLASH大小,即可调节对应镜像空间。 +- 在Makefile文件中,将cfg\_seperate\_load\_mode值改为yes,使编译系统通过链接脚本构建目标文件。 +- Config.mk中,需要修改以下值: + + CONFIG_MQTT_ENABLE := n // config中默认使用的时mqtt,需将其关闭 + CONFIG_LWM2M_ENABLE := y // 使能lwm2m并选择使用的lwm2m实现类型 + CONFIG_LWM2M_TYPE := "wakaama_raw" + CONFIG_OC_LWM2M_ENABLE := y // 使能lwm2m的oc接口 + CONFIG_OC_LWM2M_TYPE := "atiny_lwm2m_raw" + CONFIG_OTA_ENABLE := y + CONFIG_PCP_ENABLE := y // 若使用SOTA,需使能该选项 + CONFIG_DEMO_TYPE := "oc_lwm2m_ota_demo" // 并使用该DEMO进行SOTA功能验证 + +- 编译loader:在GCC目录下的config.mk文件中,将CONFIG\_LOADER\_ENABLE和CONFIG\_OTA\_ENABLE的值改为y,进行loader镜像编译。 +- 编译APP:在config.mk文件中,将CONFIG\_LOADER\_ENABLE值改为n,同时需要使能CONFIG\_PCP\_ENABLE和CONFIG\_OTA\_ENABLE选项,进行App镜像编译。 + + + + +# 新平台适配 + +若用户需要在新平台上使用OTA升级功能,需要完成以下工作: + +- 完成存储器的定义。 + +用户需定义所使用的存储器类型接口及分区信息,并使用以下接口将其注册到系统中: + + + int storage_dev_install(storage_device *dev, uint32_t max_num); + int storage_partition_init(storage_partition *part, int32_t max_num); + +- 完成OTA镜像接口的定义。 + +用户需定义ota\_storage\_t中flag镜像与bin镜像的读写接口,并通过下面接口进行注册: + + int ota_storage_install(const ota_storage_t *device); + +对于FOTA系统,需要同时适配hal\_get\_ota\_opt函数,填充并返回ota\_opt\_s的read\_flash和write\_flash接口。 + +- 对于loader,需完成ota\_detection函数,实现ota状态检查及镜像的升级功能。 +- 在config.mk中定义CONFIG\_LOADER\_ENABLE值为y,进行Loader镜像的编译。将改值改为n,进行APP镜像的编译。 +- 在Makefile文件中将cfg\_seperate\_load\_mode赋值为yes,以使用对应的链接脚本来构建对应的执行文件。 + diff --git a/doc/meta/IoT_Link/OTA/01.png b/doc/meta/IoT_Link/OTA/01.png new file mode 100644 index 000000000..a7da783b0 Binary files /dev/null and b/doc/meta/IoT_Link/OTA/01.png differ diff --git a/doc/meta/IoT_Link/OTA/02.png b/doc/meta/IoT_Link/OTA/02.png new file mode 100644 index 000000000..d6f01443e Binary files /dev/null and b/doc/meta/IoT_Link/OTA/02.png differ diff --git a/iot_link/iot.mk b/iot_link/iot.mk index e1ad2a9cb..ef5296115 100644 --- a/iot_link/iot.mk +++ b/iot_link/iot.mk @@ -76,6 +76,9 @@ include $(iot_link_root)/upgrade_patch/upgrade_patch.mk include $(iot_link_root)/compression_algo/compression_algo.mk endif +#configure storage +include $(iot_link_root)/storage/storage.mk + iot_link_src = ${wildcard $(iot_link_root)/*.c} C_SOURCES += $(iot_link_src) diff --git a/iot_link/network/lwm2m/wakaama_raw/adapter/extend/observe_ext.c b/iot_link/network/lwm2m/wakaama_raw/adapter/extend/observe_ext.c index 335b8dae8..a99f7e0c0 100644 --- a/iot_link/network/lwm2m/wakaama_raw/adapter/extend/observe_ext.c +++ b/iot_link/network/lwm2m/wakaama_raw/adapter/extend/observe_ext.c @@ -210,11 +210,15 @@ uint8_t lwm2m_send_notify(lwm2m_context_t *contextP, lwm2m_observe_info_t *obser uri.objectId = LWM2M_FIRMWARE_UPDATE_OBJECT_ID; uri.instanceId = 0; uri.resourceId = RES_M_STATE; +#ifndef LWM2M_VERSION_1_0 + uri.resourceInstanceId = LWM2M_MAX_ID; +#endif // uri.flag = (LWM2M_URI_FLAG_OBJECT_ID | LWM2M_URI_FLAG_INSTANCE_ID | LWM2M_URI_FLAG_RESOURCE_ID); format = (lwm2m_media_type_t)observe_info->format; memset(&data, 0, sizeof(data)); data.id = uri.resourceId; + lwm2m_data_encode_int(firmware_update_state, &data); res = lwm2m_data_serialize(&uri, 1, &data, &format, &buffer); if (res < 0) diff --git a/iot_link/network/lwm2m/wakaama_raw/wakaama-master/core/liblwm2m.c b/iot_link/network/lwm2m/wakaama_raw/wakaama-master/core/liblwm2m.c index 07e855527..53d07dd57 100644 --- a/iot_link/network/lwm2m/wakaama_raw/wakaama-master/core/liblwm2m.c +++ b/iot_link/network/lwm2m/wakaama_raw/wakaama-master/core/liblwm2m.c @@ -494,6 +494,7 @@ int lwm2m_step(lwm2m_context_t * contextP, { case STATE_REGISTERED: contextP->state = STATE_READY; + lwm2m_notify_even(MODULE_LWM2M, STATE_REGISTERED, NULL, 0); break; case STATE_REG_FAILED: diff --git a/iot_link/network/mqtt/lite_mqtt/mqtt_port/mqtt_sinn_port.c b/iot_link/network/mqtt/lite_mqtt/mqtt_port/mqtt_sinn_port.c index 648bfa210..65638a603 100755 --- a/iot_link/network/mqtt/lite_mqtt/mqtt_port/mqtt_sinn_port.c +++ b/iot_link/network/mqtt/lite_mqtt/mqtt_port/mqtt_sinn_port.c @@ -345,6 +345,10 @@ static int __subscribe(void *handle,mqtt_al_subpara_t *para) ret = -1; goto exit; } + else + { + ret = 0; + } } else { diff --git a/iot_link/oc/oc_lwm2m/atiny_lwm2m_raw/atiny_fota_manager.c b/iot_link/oc/oc_lwm2m/atiny_lwm2m_raw/atiny_fota_manager.c index 42fd5167e..9e33de2af 100644 --- a/iot_link/oc/oc_lwm2m/atiny_lwm2m_raw/atiny_fota_manager.c +++ b/iot_link/oc/oc_lwm2m/atiny_lwm2m_raw/atiny_fota_manager.c @@ -36,7 +36,7 @@ #include "atiny_fota_state.h" #include #include "firmware_update.h" -#include "ota/package.h" +//#include "ota/package.h" struct atiny_fota_manager_tag_s { @@ -266,8 +266,8 @@ static int atiny_fota_manager_flag_write(const void* buf, int32_t len) int atiny_fota_manager_set_storage_device(atiny_fota_manager_s *thi) { int ret; - flag_op_s flag_op; - pack_params_s pack_param; +// flag_op_s flag_op; +// pack_params_s pack_param; ASSERT_THIS(return ATINY_ARG_INVALID); @@ -278,26 +278,26 @@ int atiny_fota_manager_set_storage_device(atiny_fota_manager_s *thi) return ret; } - flag_op.func_flag_read = atiny_fota_manager_flag_read; - flag_op.func_flag_write = atiny_fota_manager_flag_write; - (void)flag_init(&flag_op); - ret = flag_upgrade_init(); - if (ret != ATINY_OK) - { - ATINY_LOG(LOG_FATAL, "flag_upgrade_init fail"); - return ret; - } - - memcpy(&pack_param.ota_opt, &thi->ota_opt, sizeof(pack_param.ota_opt)); - pack_param.malloc = osal_malloc; - pack_param.free = osal_free; - pack_param.printf = printf; - ret = pack_init_device(&pack_param); - if (ret != ATINY_OK) - { - ATINY_LOG(LOG_FATAL, "pack_init_device fail"); - return ret; - } +// flag_op.func_flag_read = atiny_fota_manager_flag_read; +// flag_op.func_flag_write = atiny_fota_manager_flag_write; +// (void)flag_init(&flag_op); +// ret = flag_upgrade_init(); +// if (ret != ATINY_OK) +// { +// ATINY_LOG(LOG_FATAL, "flag_upgrade_init fail"); +// return ret; +// } + +// memcpy(&pack_param.ota_opt, &thi->ota_opt, sizeof(pack_param.ota_opt)); +// pack_param.malloc = osal_malloc; +// pack_param.free = osal_free; +// pack_param.printf = printf; +// ret = pack_init_device(&pack_param); +// if (ret != ATINY_OK) +// { +// ATINY_LOG(LOG_FATAL, "pack_init_device fail"); +// return ret; +// } thi->device = pack_get_device(); return atiny_fota_idle_state_int_report_result(&thi->idle_state); diff --git a/iot_link/oc/oc_lwm2m/atiny_lwm2m_raw/atiny_fota_manager.h b/iot_link/oc/oc_lwm2m/atiny_lwm2m_raw/atiny_fota_manager.h index 91c8051f0..e18367ca7 100644 --- a/iot_link/oc/oc_lwm2m/atiny_lwm2m_raw/atiny_fota_manager.h +++ b/iot_link/oc/oc_lwm2m/atiny_lwm2m_raw/atiny_fota_manager.h @@ -54,7 +54,7 @@ #include #include "liblwm2m.h" -#include "ota/package.h" +#include "ota_manager.h" #define array_size(a) (sizeof(a)/sizeof(*(a))) diff --git a/iot_link/oc/oc_lwm2m/atiny_lwm2m_raw/atiny_fota_state.c b/iot_link/oc/oc_lwm2m/atiny_lwm2m_raw/atiny_fota_state.c index 4b1f44681..fec83dca0 100644 --- a/iot_link/oc/oc_lwm2m/atiny_lwm2m_raw/atiny_fota_state.c +++ b/iot_link/oc/oc_lwm2m/atiny_lwm2m_raw/atiny_fota_state.c @@ -111,17 +111,15 @@ static int atiny_fota_idle_state_recv_notify_ack(atiny_fota_state_s *thi, data_s } -static int atiny_fota_idle_state_get_result(void) +static int atiny_fota_idle_state_get_result(int *res) { - upgrade_state_e state; - - if(flag_upgrade_get_result(&state) != ATINY_OK) - { - ATINY_LOG(LOG_ERR, "ota_check_update_state fail"); - return ATINY_ERR; - } - - return (OTA_SUCCEED == state) ? ATINY_OK : ATINY_ERR; + ota_flag_t flag; + if (ota_storage_flag_read(&flag) != ATINY_ERR){ + printf("%s: ret upgrade = %d\n", __func__, flag.ret_upgrade); + *res = flag.ret_upgrade; + return ATINY_OK; + } + return ATINY_ERR; } int atiny_fota_idle_state_int_report_result(atiny_fota_idle_state_s *thi) @@ -134,35 +132,32 @@ int atiny_fota_idle_state_int_report_result(atiny_fota_idle_state_s *thi) thi->report_flag = false; memset(&observe_info, 0, sizeof(lwm2m_observe_info_t)); - if(flag_read(FLAG_APP, &observe_info, sizeof(observe_info)) != ATINY_OK) - { - ATINY_LOG(LOG_ERR, "flag_write fail"); + if (ota_pack_observe_info_read(&observe_info, sizeof(observe_info)) != ATINY_OK) { + ATINY_LOG(LOG_ERR, "read observe info fail"); goto EXIT; } - if(0 == observe_info.tokenLen) { return ATINY_OK; } - ret = atiny_fota_idle_state_get_result(); + ret = atiny_fota_idle_state_get_result(&result); if(ret != ATINY_OK) { ATINY_LOG(LOG_ERR, "get_software_result fail"); } - result = ATINY_OK; - thi->report_result = ret; + // result = ATINY_OK; + thi->report_result = result; thi->report_flag = true; memcpy(&thi->observe_info, &observe_info, sizeof(thi->observe_info)); - ATINY_LOG(LOG_INFO, "need to rpt result %d", ret); + ATINY_LOG(LOG_ERR, "need to rpt result %d", result); EXIT: memset(&observe_info, 0, sizeof(observe_info)); - if(flag_write(FLAG_APP, &observe_info, sizeof(observe_info)) != ATINY_OK) - { - ATINY_LOG(LOG_ERR, "flag_write fail"); + if (ota_pack_observe_info_write(&observe_info, sizeof(observe_info)) != ATINY_OK) { + ATINY_LOG(LOG_ERR, "write observe info fail"); } - return result; + return ret; } static int atiny_fota_idle_state_report_result(atiny_fota_state_s *thi) @@ -174,7 +169,6 @@ static int atiny_fota_idle_state_report_result(atiny_fota_state_s *thi) ASSERT_THIS(return ATINY_ARG_INVALID); - if(!idle_stat->report_flag) { return ATINY_OK; @@ -188,7 +182,7 @@ static int atiny_fota_idle_state_report_result(atiny_fota_state_s *thi) atiny_fota_manager_get_data_cfg(thi->manager, &dataCfg); ret = lwm2m_send_notify(atiny_fota_manager_get_lwm2m_context(thi->manager), &idle_stat->observe_info, state, &dataCfg); - ATINY_LOG(LOG_INFO, "lwm2m_send_notify result %d, state %d", ret, state); + ATINY_LOG(LOG_ERR, "lwm2m_send_notify result %d, state %d", ret, state); return ret; } @@ -317,8 +311,7 @@ static int atiny_fota_downloaded_state_recv_notify_ack(atiny_fota_state_s *thi, goto EXIT_DOWNLOADED; } - if(flag_write(FLAG_APP, &observe_info, sizeof(observe_info)) != ATINY_OK) - { + if (ota_pack_observe_info_write(&observe_info, sizeof(observe_info)) != ATINY_OK) { ATINY_LOG(LOG_ERR, "flag_write fail"); goto EXIT_DOWNLOADED; } diff --git a/iot_link/oc/oc_lwm2m/atiny_lwm2m_raw/atiny_fota_state.h b/iot_link/oc/oc_lwm2m/atiny_lwm2m_raw/atiny_fota_state.h index 13c9f6cce..447554edd 100644 --- a/iot_link/oc/oc_lwm2m/atiny_lwm2m_raw/atiny_fota_state.h +++ b/iot_link/oc/oc_lwm2m/atiny_lwm2m_raw/atiny_fota_state.h @@ -52,10 +52,8 @@ #ifndef ATINY_FOTA_STATE_H_ #define ATINY_FOTA_STATE_H_ #include "atiny_fota_manager.h" -#include "log/atiny_log.h" #include "object_comm.h" -#include "flag_manager.h" -#include "upgrade_flag.h" +#include "ota_flag.h" diff --git a/iot_link/oc/oc_lwm2m/atiny_lwm2m_raw/atiny_lwm2m.mk b/iot_link/oc/oc_lwm2m/atiny_lwm2m_raw/atiny_lwm2m.mk index 427adb696..475bb2138 100644 --- a/iot_link/oc/oc_lwm2m/atiny_lwm2m_raw/atiny_lwm2m.mk +++ b/iot_link/oc/oc_lwm2m/atiny_lwm2m_raw/atiny_lwm2m.mk @@ -1,6 +1,7 @@ OC_LWM2M_AGENT_SRC = \ ${wildcard $(iot_link_root)/oc/oc_lwm2m/atiny_lwm2m_raw/*.c} +USE_FOTA = y ifeq ($(USE_FOTA), y) C_SOURCES += $(OC_LWM2M_AGENT_SRC) else @@ -13,4 +14,4 @@ endif OC_LWM2M_ATINY_INC = -I $(iot_link_root)/oc/oc_lwm2m/atiny_lwm2m_raw C_INCLUDES += $(OC_LWM2M_ATINY_INC) -C_DEFS += -D CONFIG_OC_LWM2M_AGENT_ENABLE=1 \ No newline at end of file +C_DEFS += -D CONFIG_OC_LWM2M_AGENT_ENABLE=1 -D CONFIG_FEATURE_FOTA diff --git a/iot_link/oc/oc_lwm2m/atiny_lwm2m_raw/firmware_update.c b/iot_link/oc/oc_lwm2m/atiny_lwm2m_raw/firmware_update.c index 414a69f07..4d0937461 100644 --- a/iot_link/oc/oc_lwm2m/atiny_lwm2m_raw/firmware_update.c +++ b/iot_link/oc/oc_lwm2m/atiny_lwm2m_raw/firmware_update.c @@ -34,7 +34,8 @@ #include "internals.h" #include -#include "ota/package.h" +//#include "ota/package.h" +#include "ota_manager.h" #include "firmware_update.h" #include @@ -61,11 +62,11 @@ static fw_update_record_t g_fw_update_record = {0}; static firmware_update_notify g_firmware_update_notify = NULL; static void *g_firmware_update_notify_param = NULL; -static void firmware_download_reply(lwm2m_transaction_t *transacP, +static void firmware_download_reply(lwm2m_context_t *contextP, lwm2m_transaction_t *transacP, void *message) { coap_packet_t *packet = (coap_packet_t *)message; - lwm2m_context_t *contextP = (lwm2m_context_t *)(transacP->userData); + // lwm2m_context_t *contextP = (lwm2m_context_t *)(transacP->userData); lwm2m_transaction_t *transaction; uint32_t len = 0; uint32_t block_num = 0; @@ -121,7 +122,7 @@ static void firmware_download_reply(lwm2m_transaction_t *transacP, goto failed_exit; } ret = coap_set_header_uri_path(transaction->message, g_ota_uri); - if(ret < 0 || NULL == transaction->message->uri_path) + if(ret < 0 || NULL == ((coap_packet_t*)transaction->message)->uri_path) { transaction_free(transaction); goto failed_exit; @@ -285,7 +286,7 @@ int start_firmware_download(lwm2m_context_t *contextP, char *uri, int uri_len; lwm2m_server_t *server; - if(!contextP || !uri || *uri == '\0' || !storage_device_p) + if(!contextP || !uri || *uri == '\0') //|| !storage_device_p) { ATINY_LOG(LOG_ERR, "invalid params"); return -1; @@ -329,7 +330,7 @@ int start_firmware_download(lwm2m_context_t *contextP, char *uri, return -1; } ret = coap_set_header_uri_path(transaction->message, g_ota_uri); - if(ret < 0 || NULL == transaction->message->uri_path) + if(ret < 0 || NULL == ((coap_packet_t*)transaction->message)->uri_path) { transaction_free(transaction); return -1; diff --git a/iot_link/ota/manager/ota_checksum.c b/iot_link/ota/manager/ota_checksum.c new file mode 100644 index 000000000..748b0485c --- /dev/null +++ b/iot_link/ota/manager/ota_checksum.c @@ -0,0 +1,159 @@ + +#include "mbedtls/md.h" +#include "mbedtls/pk.h" +#include "stdint.h" +#include "ota_flag.h" + +struct input_stream { + int start; + int end; +}; + +static struct input_stream calc_stream; +static uint8_t *hash_cache = NULL; +static uint8_t *sign_cache = NULL; + +#define HASH_LEN (32) + +static uint8_t prv_public_key[] = "-----BEGIN PUBLIC KEY-----\n" +"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAo1++6Iw1EgsZCUwBpg/i\n" +"NlEgIjaBwDqLABFTmnPFSW9KDwaffjd1xzRwWxUPaQqpq3UEzj7ZWJFx07uLar1+\n" +"ub9wRmv+fTUWwnuMnMZd14K7CXasFiwnvule+uEoomOytf9bx7E/8wFE+/IlYbQ/\n" +"62+tViPuClazV118lbG8moMVJfSBgdGavk65KFO03ZFP5HpP7yK968R/otOcJOCN\n" +"frq4WaeuqxCyv/MnGzxpmDp7kYrTejBlOH+czHSLPZlW1p8mzOUrVDCT3ngg0oHw\n" +"5pibPkfjjawioq1KCIMQNeAM/VtmpuKyDznHrgtLA1hOXeK7F63FEJ9T1Ib/00a5\n" +"PQIDAQAB\n" +"-----END PUBLIC KEY-----"; + +static int ota_pack_calc_stream_init(int sign_len, int file_size) +{ + + calc_stream.start = sign_len; + calc_stream.end = file_size; + + hash_cache = osal_malloc(HASH_LEN); + if (hash_cache == NULL) + return -1; + + + sign_cache = osal_malloc(sign_len); + if (sign_cache == NULL) { + osal_free(hash_cache); + return -1; + } + + memset(hash_cache, 0, 32); + memset(sign_cache, 0, 256); + return 0; +} + +static inline void ota_pack_calc_stream_deinit() +{ + calc_stream.start = 0; + calc_stream.end = 0; + + if (sign_cache) { + osal_free(sign_cache); + sign_cache = NULL; + } + + if (hash_cache) { + osal_free(hash_cache); + hash_cache = NULL; + } +} +static int ota_pack_read_stream(uint8_t *buf, int32_t buf_len) +{ + int read_len = 0; + if (calc_stream.end - calc_stream.start > buf_len) { + read_len = buf_len; + } else { + read_len = calc_stream.end - calc_stream.start; + } + + ota_storage_bin_read(calc_stream.start, buf, read_len); + + calc_stream.start += read_len; + + return read_len; + +} + +int ota_pack_calc_hash(uint8_t *hash_out) +{ + int ret; + int read_len; + mbedtls_md_context_t ctx; + const mbedtls_md_info_t *md_info; + unsigned char buf[1024]; + + if (hash_out == NULL) { + return -1; + } + + md_info = mbedtls_md_info_from_type(MBEDTLS_MD_SHA256); + if (md_info == NULL) { + return -1; + } + + mbedtls_md_init( &ctx ); + + if( ( ret = mbedtls_md_setup( &ctx, md_info, 0 ) ) != 0 ) + goto cleanup; + + if( ( ret = mbedtls_md_starts( &ctx ) ) != 0 ) + goto cleanup; + + + while ((read_len = ota_pack_read_stream(buf, sizeof(buf))) > 0) { + mbedtls_md_update( &ctx, buf, read_len ); + } + + mbedtls_md_finish(&ctx, hash_out); + + cleanup: + mbedtls_md_free( &ctx ); + return( ret ); +} + +static int ota_pack_verify_signature(uint8_t *hash, int32_t hash_len, uint8_t *sig, int32_t sig_len) +{ + int ret; + mbedtls_pk_context pk; + + //load public key + mbedtls_pk_init(&pk); + ret = mbedtls_pk_parse_public_key(&pk, prv_public_key, sizeof(prv_public_key)); + if (ret != 0) { + printf ("parse pk failed!, ret = %x\n", ret); + goto exit; + } + + if ((ret = mbedtls_pk_verify(&pk, MBEDTLS_MD_SHA256, hash, 0, sig, sig_len)) != 0) { + printf (" pk verify failed , ret = %x\n", -ret); + goto exit; + } + ret = 0; + + exit: + mbedtls_pk_free( &pk ); + return ret; +} + +int ota_pack_get_signature_verify_result(int sign_len, int file_len) +{ + int ret; + + ota_pack_calc_stream_init(sign_len, file_len); + ota_pack_calc_hash(hash_cache); + ota_storage_bin_read(0, sign_cache, sign_len); + + if ( (ret = ota_pack_verify_signature(hash_cache, 0, sign_cache, sign_len)) != 0) { + printf("ota Binary signature check failed!, ret = %x\n", ret); + } + + ota_pack_calc_stream_deinit(); + return ret; +} + + diff --git a/iot_link/ota/manager/ota_manager.h b/iot_link/ota/manager/ota_manager.h new file mode 100644 index 000000000..0329b024d --- /dev/null +++ b/iot_link/ota/manager/ota_manager.h @@ -0,0 +1,35 @@ +#ifndef OTA_MANAGER_H +#define OTA_MANAGER_H + +typedef struct pack_storage_device_api_tag_s pack_storage_device_api_s; + +typedef enum +{ + PACK_DOWNLOAD_OK, + PACK_DOWNLOAD_FAIL +}pack_download_result_e; + +struct pack_storage_device_api_tag_s +{ + int (*write_software)(pack_storage_device_api_s *thi, uint32_t offset, const uint8_t *buffer, uint32_t len); + int (*write_software_end)(pack_storage_device_api_s *thi, pack_download_result_e result, uint32_t total_len); + int (*active_software)(pack_storage_device_api_s *thi); +}; + +typedef struct +{ + pack_storage_device_api_s interface; + // pack_hardware_s hardware; + // pack_params_s params; + // pack_head_s head; + // pack_writer_s writer; + uint32_t total_len; + // ota_flash_type_e type; + int32_t init_flag; +} pack_storage_device_s; + +pack_storage_device_api_s *pack_get_device(void); + +int ota_pack_get_signature_verify_result(int sign_len, int file_len); + +#endif /* OTA_MANAGER_H */ diff --git a/iot_link/ota/manager/ota_pack.c b/iot_link/ota/manager/ota_pack.c new file mode 100644 index 000000000..0a8e898bc --- /dev/null +++ b/iot_link/ota/manager/ota_pack.c @@ -0,0 +1,73 @@ +#include +#include "ota_flag.h" +#include "ota_manager.h" +#include "flash_adaptor.h" +#include "common.h" + +int ota_pack_man_software_write(pack_storage_device_api_s *this, uint32_t offset, uint8_t *buf, uint32_t len) +{ + (void)this; + return ota_storage_bin_write(offset, buf, len); +} + +int ota_pack_man_software_write_end(pack_storage_device_api_s *this, pack_download_result_e result, uint32_t len) +{ + (void)this; + ota_flag_t flag; + int ret = OK; + + ota_storage_flag_read(&flag); + flag.updater = UPDATER_FOTA; + flag.file_size = len; + flag.cur_state = (result == PACK_DOWNLOAD_OK ? EN_OTA_STATUS_UPGRADING : EN_OTA_STATUS_IDLE); + + if (ota_pack_get_signature_verify_result(256, len) != 0) { + ret = ERR; + flag.cur_state = EN_OTA_STATUS_IDLE; + } + + flag.crc = calc_crc32(0, &flag, sizeof(flag) - sizeof(flag.crc)); + ota_storage_flag_write(&flag); + return ret; +} + +int ota_pack_man_active_software(pack_storage_device_api_s *thi) +{ + // printf("vaild actived\n"); + return OK; +} + +static void pack_man_init_pack_device(pack_storage_device_s *device) +{ + if (device->init_flag == 1) { + return; + } + + (void)memset(device, 0, sizeof(*device)); + + device->interface.write_software = ota_pack_man_software_write; + device->interface.write_software_end = ota_pack_man_software_write_end; + device->interface.active_software = ota_pack_man_active_software; + device->init_flag = 1; +} + +static pack_storage_device_s g_pack_man_storage_device; + +pack_storage_device_api_s *pack_get_device(void) +{ + pack_man_init_pack_device(&g_pack_man_storage_device); + return &g_pack_man_storage_device.interface; +} + +int ota_pack_observe_info_read(uint8_t *buf, uint32_t len) +{ + int ret = storage_partition_read(PART_RESERVED_INFO, buf, len, 0); + return ret == ERR ? ERR : OK; +} + +int ota_pack_observe_info_write(uint8_t *buf, uint32_t len) +{ + int ret = storage_partition_write(PART_RESERVED_INFO, buf, len, 0); + printf("%s return ret %d\n", __func__, ret); + return ret == ERR ? ERR : OK; +} diff --git a/iot_link/ota/ota.mk b/iot_link/ota/ota.mk index 81e2d991e..0d2d9542a 100644 --- a/iot_link/ota/ota.mk +++ b/iot_link/ota/ota.mk @@ -5,10 +5,11 @@ #we need the crc ifeq ($(CONFIG_OTA_ENABLE),y) - OTA_MODULE_SRC = ${wildcard $(iot_link_root)/ota/*.c} + OTA_MODULE_SRC = ${wildcard $(iot_link_root)/ota/*.c} \ + ${wildcard $(iot_link_root)/ota/manager/*.c} C_SOURCES += $(OTA_MODULE_SRC) - OTA_MODULE_INC = -I $(iot_link_root)/ota + OTA_MODULE_INC = -I $(iot_link_root)/ota -I $(iot_link_root)/ota/manager C_INCLUDES += $(OTA_MODULE_INC) C_DEFS += -D CONFIG_OTA_ENABLE=1 diff --git a/targets/N720/Src/main.c b/iot_link/ota/ota_api.h old mode 100755 new mode 100644 similarity index 70% rename from targets/N720/Src/main.c rename to iot_link/ota/ota_api.h index f46b114fe..76943ec80 --- a/targets/N720/Src/main.c +++ b/iot_link/ota/ota_api.h @@ -1,5 +1,5 @@ /*---------------------------------------------------------------------------- - * Copyright (c) <2016-2018>, + * Copyright (c) <2018>, * All rights reserved. * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: @@ -31,22 +31,56 @@ * Import, export and usage of Huawei LiteOS in any manner by you shall be in compliance with such * applicable export control laws and regulations. *---------------------------------------------------------------------------*/ -#include -#include +/**@defgroup agent AgentTiny + * @defgroup agenttiny Agenttiny Definition + * @ingroup agent + */ +#ifndef OTA_API_H +#define OTA_API_H -extern int link_main(void *args); +#include +#include -int main(void) +#ifdef __cplusplus +extern "C" { +#endif + + +typedef enum +{ + OTA_FULL_SOFTWARE, + OTA_DIFF_SOFTWARE, + OTA_UPDATE_INFO +} ota_flash_type_e; + + +typedef struct +{ + const char *rsa_N; /* RSA public key N, should valid all the time */ + const char *rsa_E; /* RSA public key E, should valid all the time */ +}ota_key_s; + +typedef enum +{ + OTA_DOWNLOAD_SUCCESS, + OTA_DOWNLOAD_FAIL +} ota_download_result_e; + + +typedef struct { - printf("HELLO NEW WORLD\n\r"); - link_main(NULL); - while(1) - { - sleep(1); ///< should hung the process - } - return 0; + int (*read_flash)(ota_flash_type_e type, void *buf, int32_t len, uint32_t location); + int (*write_flash)(ota_flash_type_e type, const void *buf, int32_t len, uint32_t location); + uint32_t flash_block_size; + ota_key_s key; +}ota_opt_s; + + +#ifdef __cplusplus } +#endif +#endif diff --git a/iot_link/ota/ota_flag.c b/iot_link/ota/ota_flag.c index 9bbe93c92..deb0f494a 100644 --- a/iot_link/ota/ota_flag.c +++ b/iot_link/ota/ota_flag.c @@ -114,3 +114,11 @@ int ota_storage_flag_write(ota_flag_t *flag) return ret; } +void ota_storage_flag_init() +{ + ota_flag_t flag; + memset(&flag, 0, sizeof(flag)); + + flag.crc = calc_crc32(0,&flag,sizeof(flag) - sizeof(flag.crc)); + ota_storage_flag_write(&flag); +} \ No newline at end of file diff --git a/iot_link/ota/ota_flag.h b/iot_link/ota/ota_flag.h index 161caa028..f52d7f1c0 100644 --- a/iot_link/ota/ota_flag.h +++ b/iot_link/ota/ota_flag.h @@ -44,6 +44,13 @@ #define CN_OTA_VERSION_LEN 32 +#define UPDATER_OTA ('O' << 16 | 'T' << 8 | 'A') +#define UPDATER_FOTA ('F' << 24 | UPDATER_OTA) +#define UPDATER_SOTA ('S' << 24 | UPDATER_OTA) + +#define OTA_HASH_LEN (32) +#define OTA_SIGNATURE_LEN (256) + typedef enum { EN_OTA_STATUS_IDLE = 0, @@ -66,6 +73,8 @@ typedef struct uint32_t file_off; ///< the current offet to write uint32_t cur_state; ///< defined by en_ota_status_t uint32_t ret_upgrade; ///< the upgrade,filled by the loader + uint32_t updater; ///< fota or sota + uint32_t crc; ///< all the ota information computed }ota_flag_t; #pragma pack() @@ -87,8 +96,8 @@ typedef struct }ota_storage_t; -int ota_storage_install(const ota_storage_t *device); -int ota_storage_uninstall(const ota_storage_t *device); +int ota_storage_install(const ota_storage_t *device); +int ota_storage_uninstall(const ota_storage_t *device); int ota_storage_bin_read(int offset, void *buf, int len); int ota_storage_bin_write(int offset, void *msg, int len); int ota_storage_flag_read(ota_flag_t *flag); diff --git a/iot_link/ota/pcp/pcp.c b/iot_link/ota/pcp/pcp.c index bbb7ca8e4..117cae584 100644 --- a/iot_link/ota/pcp/pcp.c +++ b/iot_link/ota/pcp/pcp.c @@ -398,6 +398,7 @@ static void pcp_cmd_upgrade(const pcp_head_t *head, const uint8_t *pbuf) return; } s_pcp_cb.record.cur_state = EN_OTA_STATUS_UPGRADING; + s_pcp_cb.record.updater = UPDATER_SOTA; pcp_save_flag(); pcp_send_response_code(EN_PCP_MSG_EXCUTEUPDATE, EN_PCP_RESPONSE_CODE_OK); @@ -445,7 +446,16 @@ static void pcp_handle_msg(uint8_t *msg, int msglen) case EN_PCP_MSG_EXCUTEUPDATE: ///< received the upgrade command, report the result when finish the upgrading pcp_cmd_upgrade(&pcp_head, pcp_data); - ///< we should do the reboot + + //ota binary signature check + if (ota_pack_get_signature_verify_result(OTA_SIGNATURE_LEN, s_pcp_cb.record.file_size) != 0) { + s_pcp_cb.record.cur_state = EN_OTA_STATUS_UPGRADED; + s_pcp_cb.record.ret_upgrade = EN_PCP_RESPONSE_CODE_FIRMWARENOTMATH; + pcp_save_flag(); + break; + } + + ///< we should do the reboot osal_task_sleep(5000); printf("downloaded, goto loader!!!\n"); osal_reboot(); @@ -492,7 +502,9 @@ static void pcp_handle_timeout(void) upgrade_ret.retcode = s_pcp_cb.record.ret_upgrade; memcpy(upgrade_ret.ver,s_pcp_cb.record.ver,CN_VER_LEN); ///< tell the server the result - pcp_send_msg(EN_PCP_MSG_NOTIFYSTATE,&upgrade_ret,sizeof(upgrade_ret)); + if (s_pcp_cb.record.updater == UPDATER_SOTA) { + pcp_send_msg(EN_PCP_MSG_NOTIFYSTATE,&upgrade_ret,sizeof(upgrade_ret)); + } break; default: break; @@ -599,7 +611,7 @@ int ota_pcp_init(int (*fn_pcp_send_msg)(void *msg,int len)) return ret; } - osal_task_create("pcp_main",pcp_entry,NULL,0x800,NULL,10); + osal_task_create("pcp_main",pcp_entry,NULL,0x1000,NULL,10); return 0; } diff --git a/iot_link/storage/partition.c b/iot_link/storage/partition.c new file mode 100644 index 000000000..048309d85 --- /dev/null +++ b/iot_link/storage/partition.c @@ -0,0 +1,87 @@ +#include "partition.h" +#include "storage.h" + +static const storage_partition *s_partition = NULL; +static int max_part_num = 0; +int storage_partition_init(storage_partition *part, int32_t max_num) +{ + if (part != NULL && s_partition == NULL) { + s_partition = part; + max_part_num = max_num; + return 0; + } + return -1; +} + +int storage_partition_deinit() +{ + if (s_partition != NULL) { + s_partition = NULL; + max_part_num = 0; + return 0; + } + return -1; +} + +int storage_partition_read(int part_id, uint8_t *buf, uint32_t len, uint32_t offset) +{ + storage_partition *sp; + + if (part_id >= max_part_num || buf == NULL) + return -1; + + sp = &s_partition[part_id]; + if ((offset + len) > (sp->start_addr + sp->size)) { + printf("%s:invalid args!\n", __func__); + return -1; + } + + return storage_device_read(sp->dev_id, buf, len, sp->start_addr + offset); +} + +int storage_partition_write(int part_id, uint8_t *buf, uint32_t len, uint32_t offset) +{ + storage_partition *sp; + + if (part_id >= max_part_num || buf == NULL) + return -1; + + sp = &s_partition[part_id]; + if ((offset + len) > (sp->start_addr + sp->size)) { + printf("%s:invalid args!\n", __func__); + return -1; + } + + return storage_device_write(sp->dev_id, buf, len, sp->start_addr + offset); +} + +int storage_partition_erase_write(int part_id, uint8_t *buf, uint32_t len, uint32_t offset) +{ + storage_partition *sp; + + if (part_id >= max_part_num || buf == NULL) + return -1; + + sp = &s_partition[part_id]; + if ((offset + len) > (sp->start_addr + sp->size)){ + printf("%s:invalid args!\n", __func__); + return -1; + } + return storage_device_erase_write(sp->dev_id, buf, len, sp->start_addr + offset); +} + +int storage_partition_erase(int part_id, uint32_t offset, uint32_t len) +{ + storage_partition *sp; + + if (part_id >= max_part_num) + return -1; + + sp = &s_partition[part_id]; + if ((offset + len) > (sp->start_addr + sp->size)){ + printf("%s:invalid args!\n", __func__); + return -1; + } + + return storage_device_erase(sp->dev_id, sp->start_addr + offset, len); +} \ No newline at end of file diff --git a/targets/N720/Src/iot_link_config.h b/iot_link/storage/partition.h old mode 100755 new mode 100644 similarity index 79% rename from targets/N720/Src/iot_link_config.h rename to iot_link/storage/partition.h index c105bb2df..51823fdf3 --- a/targets/N720/Src/iot_link_config.h +++ b/iot_link/storage/partition.h @@ -33,12 +33,26 @@ *---------------------------------------------------------------------------*/ /** * DATE AUTHOR INSTRUCTION - * 2019-07-27 14:52 zhangqianfu The first version + * 2019-09-16 18:48 zhangqianfu The first version * */ -#ifndef LITEOS_LAB_TARGETS_EC20_SRC_IOT_LINK_CONFIG_H_ -#define LITEOS_LAB_TARGETS_EC20_SRC_IOT_LINK_CONFIG_H_ +#include "storage.h" +#ifndef STORAGE_PARTITION_H +#define STORAGE_PARTITION_H +typedef struct _partition { + uint8_t dev_id; + char *name; + uint32_t start_addr; + uint32_t size; +}storage_partition; -#endif /* LITEOS_LAB_TARGETS_EC20_SRC_IOT_LINK_CONFIG_H_ */ +int storage_partition_read(int part_id, uint8_t *buf, uint32_t len, uint32_t offset); + +int storage_partition_write(int part_id, uint8_t *buf, uint32_t len, uint32_t offset); + +int storage_partition_erase_write(int part_id, uint8_t *buf, uint32_t len, uint32_t offset); + +int storage_partition_erase(int part_id, uint32_t offset, uint32_t len); +#endif /* STORAGE_PARTITION_H */ \ No newline at end of file diff --git a/iot_link/storage/storage.c b/iot_link/storage/storage.c new file mode 100644 index 000000000..148e277d0 --- /dev/null +++ b/iot_link/storage/storage.c @@ -0,0 +1,64 @@ +#include "storage.h" + +static const storage_device *s_device = NULL; +static uint32_t max_dev_num = 0; + +int storage_dev_install(storage_device *dev, uint32_t max_num) +{ + int i = 0; + if (dev != NULL && s_device == NULL) { + for (i = 0; i < max_num; i++) { + if (dev[i].init != NULL) { + dev[i].init(); + } + } + + s_device = dev; + max_dev_num = max_num; + return 0; + } + return -1; +} + +int storage_dev_uninstall() +{ + if (s_device != NULL) { + s_device = NULL; + max_dev_num = 0; + return 0; + } + return -1; +} + +int storage_device_erase(int dev_id, uint32_t addr, uint32_t len) +{ + if (dev_id < max_dev_num && s_device != NULL && s_device[dev_id].erase != NULL) { + return s_device[dev_id].erase(addr, len); + } + return -1; +} + +int storage_device_erase_write(int dev_id, uint8_t *buf, uint32_t len, uint32_t addr) +{ + if (dev_id < max_dev_num && s_device != NULL && s_device[dev_id].erase_write != NULL) { + return s_device[dev_id].erase_write(buf, len, addr); + } + return -1; +} + +int storage_device_write(int dev_id, uint8_t *buf, uint32_t len, uint32_t addr) +{ + if (dev_id < max_dev_num && s_device != NULL && s_device[dev_id].write != NULL) { + return s_device[dev_id].write(buf, len, addr); + } + return -1; +} + +int storage_device_read(int dev_id, uint8_t *buf, uint32_t len, uint32_t addr) +{ + + if (dev_id < max_dev_num && s_device != NULL && s_device[dev_id].read != NULL) { + return s_device[dev_id].read(buf, len, addr); + } + return -1; +} diff --git a/iot_link/storage/storage.h b/iot_link/storage/storage.h new file mode 100644 index 000000000..26356a087 --- /dev/null +++ b/iot_link/storage/storage.h @@ -0,0 +1,64 @@ +/*---------------------------------------------------------------------------- + * Copyright (c) <2018>, + * All rights reserved. + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *---------------------------------------------------------------------------*/ +/*---------------------------------------------------------------------------- + * Notice of Export Control Law + * =============================================== + * Huawei LiteOS may be subject to applicable export control laws and regulations, which might + * include those applicable to Huawei LiteOS of U.S. and the country in which you are located. + * Import, export and usage of Huawei LiteOS in any manner by you shall be in compliance with such + * applicable export control laws and regulations. + *---------------------------------------------------------------------------*/ +/** + * DATE AUTHOR INSTRUCTION + * 2019-09-16 18:48 zhangqianfu The first version + * + */ + +#ifndef SOTRAGE_SOTRAGE_H +#define SOTRAGE_SOTRAGE_H + +#include +#include + +typedef struct { + int id; + char *name; + uint32_t size; + + void (*init)(); + int (*read)(void *buf, int32_t len, uint32_t offset); + int (*write)(const uint8_t *buf, int32_t len, uint32_t offset); + int (*erase)(uint32_t offset, int32_t len); + int (*erase_write)(const void *buf, int32_t len, uint32_t offset); +}storage_device; + +int storage_dev_install(storage_device *dev, uint32_t max_num); +int storage_dev_uninstall(); +int storage_device_erase(int dev_id, uint32_t addr, uint32_t len); +int storage_device_erase_write(int dev_id, uint8_t *buf, uint32_t len, uint32_t addr); +int storage_device_write(int dev_id, uint8_t *buf, uint32_t len, uint32_t addr); +int storage_device_read(int dev_id, uint8_t *buf, uint32_t len, uint32_t addr); +#endif /* SOTRAGE_SOTRAGE_H */ \ No newline at end of file diff --git a/iot_link/storage/storage.mk b/iot_link/storage/storage.mk new file mode 100644 index 000000000..8f4215f26 --- /dev/null +++ b/iot_link/storage/storage.mk @@ -0,0 +1,5 @@ +STORAGE_MODULE_SRC = ${wildcard $(iot_link_root)/storage/*.c} +C_SOURCES += $(STORAGE_MODULE_SRC) + +STORAGE_MODULE_INC = -I $(iot_link_root)/storage +C_INCLUDES += $(STORAGE_MODULE_INC) diff --git a/targets/N720/GCC/Makefile b/targets/N720/GCC/Makefile deleted file mode 100755 index 13528133c..000000000 --- a/targets/N720/GCC/Makefile +++ /dev/null @@ -1,152 +0,0 @@ -########################################################################################################################## -# N720 GCC compiler Makefile -########################################################################################################################## - -# ------------------------------------------------ -# Generic Makefile (based on gcc) -# ------------------------------------------------ - -###################################### -# target -###################################### -TARGET = Huawei_LiteOS -###################################### -# building variables -###################################### -# debug build? -DEBUG = 1 -# optimization -OPT = -O0 -g - -GCC_VERSION=4.9.2 -####################################### -# binaries -####################################### -ifeq ($(CC), ) - PREFIX = - CC = $(PREFIX)gcc - AS = $(PREFIX)gcc -x assembler-with-cpp - OBJCOPY = $(PREFIX)objcopy - OBJDUMP = $(PREFIX)objdump - AR = $(PREFIX)ar - SZ = $(PREFIX)size - LD = $(PREFIX)ld - HEX = $(OBJCOPY) -O ihex - BIN = $(OBJCOPY) -O binary -S -endif - -PROJECTBASE = $(abspath $(CURDIR)) -TOP_DIR = $(abspath $(PROJECTBASE)/../../..) - -#this is for IoT Studio automatic generating kconfig compatibility -ifndef SDK_DIR - SDK_DIR=$(abspath $(PROJECTBASE)/../../..) -endif - -####################################### -# paths -####################################### -# firmware library path -PERIFLIB_PATH = - -# Build path -BUILD_DIR = build - -###################################### -#common variables for other module or components -C_SOURCES = -C_DEFS = -DMBEDTLS_DEBUG_C -C_INCLUDES = -LDFLAGS = -ASM_SOURCES_S = -AS_DEFS = -AS_INCLUDES = -PERIFLIB_SOURCES = - - -##########################LOAD THE SOURCES INCLUDES AND DEFINES################# -include $(PROJECTBASE)/config.mk - -MAIN_SRC := ${wildcard $(TOP_DIR)/targets/N720/Src/*.c} -C_SOURCES += $(MAIN_SRC) - -AT_INTERFACE_INC = \ - -I $(TOP_DIR)/targets/N720/Src/ - C_INCLUDES += $(AT_INTERFACE_INC) - -###################################### -# firmware library -###################################### - - - -####################################### -# CFLAGS -####################################### - - -# compile gcc flags -ASFLAGS = $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections - -CFLAGS = $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections - -LOCAL_CFLAGS = -march=armv7-a -mfpu=neon -g - - -ifeq ($(DEBUG), 1) -CFLAGS += -g -gdwarf-2 -endif - -# Generate dependency information -CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$@" - -# excluded unnecessary warnings -CFLAGS += -Wno-missing-braces - -####################################### -# LDFLAGS -####################################### - -# libraries -LIBS = -lc -lm -lpthread -lrt -#LIBS = -LDFLAGS = $(LIBS) - -# default action: build all -all: $(BUILD_DIR)/$(TARGET).elf - -####################################### -# build the application -####################################### -# list of objects -OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o))) -vpath %.c $(sort $(dir $(C_SOURCES))) -# list of ASM program objects -OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES_S:.S=.o))) -vpath %.S $(sort $(dir $(ASM_SOURCES_S))) - -$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR) - $(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@ - -$(BUILD_DIR)/%.o: %.S Makefile | $(BUILD_DIR) - $(AS) -c $(CFLAGS) $< -o $@ - -$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile - $(CC) $(OBJECTS) $(LDFLAGS) -o $@ - -$(BUILD_DIR): - mkdir $@ - -####################################### -# clean up -####################################### -clean: - -rm -fR .dep $(BUILD_DIR) - -####################################### -# dependencies -####################################### -#-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*) --include $(wildcard $(BUILD_DIR)/*.d) - -# *** EOF *** diff --git a/targets/N720/GCC/Makefile_demo b/targets/N720/GCC/Makefile_demo deleted file mode 100755 index 128bc1fe1..000000000 --- a/targets/N720/GCC/Makefile_demo +++ /dev/null @@ -1,152 +0,0 @@ -########################################################################################################################## -# STM32F429IGTx_FIRE GCC compiler Makefile -########################################################################################################################## - -# ------------------------------------------------ -# Generic Makefile (based on gcc) -# ------------------------------------------------ - -###################################### -# target -###################################### -TARGET = Huawei_LiteOS -###################################### -# building variables -###################################### -# debug build? -DEBUG = 1 -# optimization -OPT = -O0 -g - - -####################################### -# binaries -####################################### -PREFIX = -CC = $(PREFIX)gcc -AS = $(PREFIX)gcc -x assembler-with-cpp -OBJCOPY = $(PREFIX)objcopy -OBJDUMP = $(PREFIX)objdump -AR = $(PREFIX)ar -SZ = $(PREFIX)size -LD = $(PREFIX)ld -HEX = $(OBJCOPY) -O ihex -BIN = $(OBJCOPY) -O binary -S - - -PROJECTBASE = $(abspath $(CURDIR)) -TOP_DIR = $(abspath $(PROJECTBASE)/../../..) - - -####################################### -# paths -####################################### -# firmware library path -PERIFLIB_PATH = - -# Build path -BUILD_DIR = build - -###################################### -#common variables for other module or components -C_SOURCES = -C_DEFS = -DMBEDTLS_DEBUG_C -C_INCLUDES = -LDFLAGS = -ASM_SOURCES_S = -AS_DEFS = -AS_INCLUDES = -PERIFLIB_SOURCES = - - -##########################LOAD THE SOURCES INCLUDES AND DEFINES################# -include $(PROJECTBASE)/config.mk - -MAIN_SRC := ${wildcard $(TOP_DIR)/targets/EC20/Src/at_demo.c} -MAIN_SRC += ${wildcard $(TOP_DIR)/targets/EC20/Src/at_interface_mqtt.c} -C_SOURCES += $(MAIN_SRC) - -DEMO_INC = \ - -I $(TOP_DIR)/targets/EC20/Src/ - C_INCLUDES += $(DEMO_INC) - -###################################### -# firmware library -###################################### - - -####################################### -# CFLAGS -####################################### - - -INCLUDE_INC = \ - -I $(TOP_DIR)/include - C_INCLUDES += $(INCLUDE_INC) - -LWM2M_ATINY_INC = \ - -I $(TOP_DIR)/components/connectivity/agent_tiny/atiny_lwm2m - C_INCLUDES += $(LWM2M_ATINY_INC) - -# compile gcc flags -ASFLAGS = $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections - -CFLAGS = $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections - -ifeq ($(DEBUG), 1) -CFLAGS += -g -gdwarf-2 -endif - -# Generate dependency information -CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$@" - -# excluded unnecessary warnings -CFLAGS += -Wno-missing-braces - -####################################### -# LDFLAGS -####################################### - -# libraries -LIBS = -lc -lm -lpthread -LDFLAGS = $(LIBS) - -# default action: build all -all: $(BUILD_DIR)/$(TARGET).elf - -####################################### -# build the application -####################################### -# list of objects -OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o))) -vpath %.c $(sort $(dir $(C_SOURCES))) -# list of ASM program objects -OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES_S:.S=.o))) -vpath %.S $(sort $(dir $(ASM_SOURCES_S))) - -$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR) - $(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@ - -$(BUILD_DIR)/%.o: %.S Makefile | $(BUILD_DIR) - $(AS) -c $(CFLAGS) $< -o $@ - -$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile - $(CC) $(OBJECTS) $(LDFLAGS) -o $@ - $(SZ) $@ - -$(BUILD_DIR): - mkdir $@ - -####################################### -# clean up -####################################### -clean: - -rm -fR .dep $(BUILD_DIR) - -####################################### -# dependencies -####################################### -#-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*) --include $(wildcard $(BUILD_DIR)/*.d) - -# *** EOF *** diff --git a/targets/N720/GCC/config.mk b/targets/N720/GCC/config.mk deleted file mode 100755 index c815a0031..000000000 --- a/targets/N720/GCC/config.mk +++ /dev/null @@ -1,170 +0,0 @@ -#/*---------------------------------------------------------------------------- -# * Copyright (c) <2018>, -# * All rights reserved. -# * Redistribution and use in source and binary forms, with or without modification, -# * are permitted provided that the following conditions are met: -# * 1. Redistributions of source code must retain the above copyright notice, this list of -# * conditions and the following disclaimer. -# * 2. Redistributions in binary form must reproduce the above copyright notice, this list -# * of conditions and the following disclaimer in the documentation and/or other materials -# * provided with the distribution. -# * 3. Neither the name of the copyright holder nor the names of its contributors may be used -# * to endorse or promote products derived from this software without specific prior written -# * permission. -# * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# *---------------------------------------------------------------------------*/ -#/*---------------------------------------------------------------------------- -# * Notice of Export Control Law -# * =============================================== -# * Huawei LiteOS may be subject to applicable export control laws and regulations, which might -# * include those applicable to Huawei LiteOS of U.S. and the country in which you are located. -# * Import, export and usage of Huawei LiteOS in any manner by you shall be in compliance with such -# * applicable export control laws and regulations. -# *---------------------------------------------------------------------------*/ -#/** -# * DATE AUTHOR INSTRUCTION -# * 2019-04-28 15:00 zhangqianfu The first version -# * -# */ -### this is the template to tell you how to configure the iot_link, maybe -### not good enough, please give some advice if any idea -################################################################################ -### -### introduce each configuration variable function and which value it support -### and introduce you how to configure the sdk - -### y means yes and enable, while n means no and disable -### "none" means no one matched and you could build your own -### - -################################################################################ -########################OS SERVICE START######################################## - -#CONFIG_OS_TYPE , could be: "linux" "macos" "liteos", and you could select one -CONFIG_OS_TYPE := "linux" - -#CONFIG_ARCH_CPU_TYPE,could be "armv7-m" "armv6-m" "riscv32" "x86" "x86-64" -CONFIG_ARCH_CPU_TYPE := "x86-64" - -#CONFIG_SHELL_ENABLE , we supply a simple shell on the liteos,which depends the liteos,support: y n -CONFIG_SHELL_ENABLE := n - -#CONFIG_STIMER_ENABLE , we supply a simple softtimer on the osal,you could choose yes or no -CONFIG_STIMER_ENABLE := y - -#CONFIG_DRIVER_ENABLE , we supply a easy and simple driver framework for the sdk -#this option based on the liteos, so you must choose liteos -CONFIG_DRIVER_ENABLE := n - -#CONFIG_DRIVER_ENABLE , we supply a easy and simple at framework for the sdk -#this option based on the driver framework, so you must choose CONFIG_DRIVER_ENABLE -CONFIG_AT_ENABLE := n -########################OS SERVICE END########################################## - - -########################INDEPENDENT SERVICE START################################# - -#CONFIG_CJSON_ENABLE , we port the cJSON based on the osal,you could choose yes or no -CONFIG_CJSON_ENABLE := y - -########################INDEPENDENT SERVICE END################################# - - -########################NETWORK SERVICE START################################### - -#CONFIG_TCPIP_ENABLE , we build a sal for the tcpip functions, and you could choose yes or no -#you could build your own application based on the sal, which shielding the defference of -#variouse tcpip function.what's more, you could add your own tcpip stack to the sdk. -#and if this option is enabled, then you select one type for your program, we now -#CONFIG_TCPIP_TYPE could be:"lwip_socket" "linux_socket" "macos_socket" "esp8266_socket" "none" -CONFIG_TCPIP_ENABLE := y -CONFIG_TCPIP_TYPE := "linux_socket" - -#CONFIG_DTLS_ENABLE , we supply a DTLS AL (building),you could choose yes or no -#CONFIG_DTLS_TYPE, could be "mbedtls_psk" "mbedtls_cert" "none" - -CONFIG_DTLS_ENABLE := y -CONFIG_DTLS_TYPE := "mbedtls_cert" - -#CONFIG_MQTT_ENABLE, we build a mqtt abstraction, which shield the difference of -#the implement of mqtt. -#CONFIG_MQTT_TYPE could be "paho_mqtt" "none" -CONFIG_MQTT_ENABLE := y -CONFIG_MQTT_TYPE := "paho_mqtt" - -#CONFIG_LWM2M_ENABLE, we build a lwm2m abstraction, which shield the difference of -#the implement of lwm2m. -#CONFIG_LWM2M_TYPE could be "wakaama_lwm2m" "none" -CONFIG_LWM2M_ENABLE := n -CONFIG_LWM2M_TYPE := "wakaama_lwm2m" - -#CONFIG_COAP_ENABLE, we build a coap abstraction, which shield the difference of -#the implement of coap. -#CONFIG_COAP_TYPE could be "lite_coap" "none" -CONFIG_COAP_ENABLE := n -CONFIG_COAP_TYPE := "lite_coap" -########################NETWORK SERVICE END##################################### - - -########################OC SERVICE START######################################## -#CONFIG_OC_COAP_ENABLE, we build a oc coap abstraction for huawei OceanConnect service, -#which shield the difference of the implement of oc coap. -#CONFIG_OC_MQTT_TYPE could be "soft" "none" -CONFIG_OC_COAP_ENABLE := n -CONFIG_OC_COAP_TYPE := "soft" - -#CONFIG_OC_MQTT_ENABLE, we build a oc mqtt abstraction for huawei OceanConnect service, -#which shield the difference of the implement of oc mqtt. -#CONFIG_OC_MQTT_TYPE could be "soft" "ec20_oc" "none" -CONFIG_OC_MQTT_ENABLE := y -CONFIG_OC_MQTT_TYPE := "soft" - -#CONFIG_OC_LWM2M_ENABLE, we build a oc lwm2m abstraction for huawei OceanConnect service, -#which shield the difference of the implement of oc lwm2m. -#CONFIG_OC_MQTT_TYPE could be "soft" "boudica150_oc" "none" -CONFIG_OC_LWM2M_ENABLE := n -CONFIG_OC_LWM2M_TYPE := "soft" - -########################OC SERVICE END########################################## - -########################OTA SERVICE START####################################### -#if you want to use the ota, then please enable it -#warning: -#1, the loader maybe need ota -#2, the upgrade method need ota,now we only support the pcp mode - -CONFIG_OTA_ENABLE := n -CONFIG_PCP_ENABLE := n - -########################OTA SERVICE END######################################### - -########################STANDARD DEMO START##################################### -#we create many standard demos, which maybe hardware independent,may help you to -#create your own service,if the CONFIG_DEMO_ENABLE is enable and CONFIG_DEMO_TYPE -#is "none", then you should build a demo has the same name standard_app_demo_main.if you want -#to build a specified differnt name for your own demo, please make CONFIG_DEMO_ENABLE -#disable. -#warning: -#1, if you use the oc mqtt, then the tls must support cert mode -#2,if you use the oc lwm2m with encode mode,then the dtls must support psk mode - -#CONFIG_DEMO_TYPE could be "oc_coap_demo" "oc_dtls_coap_demo" "oc_dtls_lwm2m_bs_demo" "oc_dtls_lwm2m_demo" -#"oc_lwm2m_bs_demo" "oc_lwm2m_demo" "oc_lwm2m_ota_demo" "oc_tls_mqtt_bs_demo" "oc_tls_mqtt_demo" "stimer_demo" - -CONFIG_DEMO_ENABLE := y -CONFIG_DEMO_TYPE := "oc_tls_mqtt_bs_demo" - -#########################STANDARD DEMO END###################################### -include $(TOP_DIR)/iot_link/iot.mk - - diff --git a/targets/EC20/GCC/Makefile b/targets/QUALCOMM9X07/GCC/Makefile similarity index 92% rename from targets/EC20/GCC/Makefile rename to targets/QUALCOMM9X07/GCC/Makefile index 7c4cd2055..86a3c480a 100755 --- a/targets/EC20/GCC/Makefile +++ b/targets/QUALCOMM9X07/GCC/Makefile @@ -67,12 +67,11 @@ PERIFLIB_SOURCES = ##########################LOAD THE SOURCES INCLUDES AND DEFINES################# include $(PROJECTBASE)/config.mk -MAIN_SRC := ${wildcard $(TOP_DIR)/targets/EC20/Src/*.c} +MAIN_SRC := ${wildcard ../Src/*.c} C_SOURCES += $(MAIN_SRC) -AT_INTERFACE_INC = \ - -I $(TOP_DIR)/targets/EC20/Src/ - C_INCLUDES += $(AT_INTERFACE_INC) +AT_INTERFACE_INC = -I ../Src/ +C_INCLUDES += $(AT_INTERFACE_INC) ###################################### # firmware library @@ -83,8 +82,6 @@ AT_INTERFACE_INC = \ ####################################### # CFLAGS ####################################### - - # compile gcc flags ASFLAGS = $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections diff --git a/targets/EC20/GCC/config.mk b/targets/QUALCOMM9X07/GCC/config.mk similarity index 100% rename from targets/EC20/GCC/config.mk rename to targets/QUALCOMM9X07/GCC/config.mk diff --git a/targets/EC20/Src/iot_link_config.h b/targets/QUALCOMM9X07/Src/iot_link_config.h similarity index 100% rename from targets/EC20/Src/iot_link_config.h rename to targets/QUALCOMM9X07/Src/iot_link_config.h diff --git a/targets/EC20/Src/main.c b/targets/QUALCOMM9X07/Src/main.c similarity index 100% rename from targets/EC20/Src/main.c rename to targets/QUALCOMM9X07/Src/main.c diff --git a/targets/STM32F429IGTx_FIRE/GCC/project.mk b/targets/STM32F429IGTx_FIRE/GCC/project.mk index df039acfb..7395934b1 100644 --- a/targets/STM32F429IGTx_FIRE/GCC/project.mk +++ b/targets/STM32F429IGTx_FIRE/GCC/project.mk @@ -35,7 +35,8 @@ USER_SRC = \ $(TOP_DIR)/targets/STM32F429IGTx_FIRE/Src/net_driver.c \ $(TOP_DIR)/targets/STM32F429IGTx_FIRE/Src/flash_adaptor.c ifeq ($(CONFIG_OTA_ENABLE),y) -USER_SRC += $(TOP_DIR)/targets/STM32F429IGTx_FIRE/Src/ota_adaptor.c +USER_SRC += $(TOP_DIR)/targets/STM32F429IGTx_FIRE/Src/ota_adaptor.c \ + $(TOP_DIR)/targets/STM32F429GTx_FIRE/Src/ota_port.c endif ifeq ($(CONFIG_LOADER_ENABLE),y) USER_SRC += $(TOP_DIR)/targets/STM32F429IGTx_FIRE/Src/loader_main2.c diff --git a/targets/STM32F429IGTx_FIRE/Inc/board.h b/targets/STM32F429IGTx_FIRE/Inc/board.h index 90726332e..af1700776 100644 --- a/targets/STM32F429IGTx_FIRE/Inc/board.h +++ b/targets/STM32F429IGTx_FIRE/Inc/board.h @@ -56,14 +56,14 @@ extern "C" { // SPI flash address #define OTA_FLAG_ADDR1 0x00000000 #define OTA_FLAG_ADDR2 0x00004000 -#define MQTT_INFO_ADDR 0x00008000 -#define MQTT_INFO_SIZE 0x00008000 -#define OTA_IMAGE_DOWNLOAD_ADDR (MQTT_INFO_ADDR + MQTT_INFO_SIZE) -#define OTA_IMAGE_DOWNLOAD_SIZE 0x00040000 +#define RESERVED_INFO_ADDR 0x00008000 +#define RESERVED_INFO_SIZE 0x00008000 +#define OTA_IMAGE_DOWNLOAD_ADDR (RESERVED_INFO_ADDR + RESERVED_INFO_SIZE) +#define OTA_IMAGE_DOWNLOAD_SIZE 0x00080000 #define OTA_IMAGE_BCK_ADDR (OTA_IMAGE_DOWNLOAD_ADDR + OTA_IMAGE_DOWNLOAD_SIZE) -#define OTA_IMAGE_BCK_SIZE 0x00040000 +#define OTA_IMAGE_BCK_SIZE 0x00080000 #define OTA_IMAGE_DIFF_UPGRADE_ADDR (OTA_IMAGE_BCK_ADDR + OTA_IMAGE_BCK_SIZE) -#define OTA_IMAGE_DIFF_UPGRADE_SIZE 0x00040000 +#define OTA_IMAGE_DIFF_UPGRADE_SIZE 0x00080000 // Built in flash address #define OTA_DEFAULT_IMAGE_ADDR 0x08020000 diff --git a/targets/STM32F429IGTx_FIRE/Inc/flash_adaptor.h b/targets/STM32F429IGTx_FIRE/Inc/flash_adaptor.h index 6de3e197a..9a716045c 100644 --- a/targets/STM32F429IGTx_FIRE/Inc/flash_adaptor.h +++ b/targets/STM32F429IGTx_FIRE/Inc/flash_adaptor.h @@ -47,13 +47,28 @@ #if defined(__cplusplus) extern "C" { #endif +enum en_sotrage_dev { + INNER_FLASH = 0, + SPI_FLASH, +}; + +enum en_partition { + PART_LOADER, + PART_APP, + PART_OTA_FLAG1, + PART_OTA_FLAG2, + PART_RESERVED_INFO, + PART_OTA_IMG_DOWNLOAD, + PART_OTA_IMG_BACKUP, + PART_OTA_DIFF_UPGTADE, +}; void flash_adaptor_init(void); int flash_adaptor_write(uint32_t offset, const uint8_t *buffer, uint32_t len); int flash_adaptor_write_mqtt_info(const void *buffer, uint32_t len); int flash_adaptor_read_mqtt_info(void *buffer, uint32_t len); -int flash_spi2inner(uint32_t src, uint32_t dst, uint32_t len, uint8_t *cache, uint32_t cache_len); -int flash_inner2spi(uint32_t src, uint32_t dst, uint32_t len, uint8_t * cache, uint32_t cache_len); +int app_image_restore(uint32_t src, uint32_t dst, uint32_t data_len, uint32_t head_len,uint8_t *cache, uint32_t cache_len); +int app_image_backup(uint32_t src, uint32_t dst, uint32_t len, uint8_t * cache, uint32_t cache_len); #if defined(__cplusplus) diff --git a/targets/STM32F429IGTx_FIRE/Inc/ota_adaptor.h b/targets/STM32F429IGTx_FIRE/Inc/ota_adaptor.h index d649ddb71..fbde47c89 100644 --- a/targets/STM32F429IGTx_FIRE/Inc/ota_adaptor.h +++ b/targets/STM32F429IGTx_FIRE/Inc/ota_adaptor.h @@ -65,11 +65,12 @@ typedef enum { #pragma pack(1) typedef struct { uint8_t pack_type; - uint32_t pack_len; - uint8_t reserved[27]; -}ota_pack_info; + uint8_t reserved[31]; +}ota_binary_info; #pragma pack() +#define OTA_BINARY_OFFSET (OTA_SIGNATURE_LEN + sizeof(ota_binary_info)) + void hal_init_ota(void); void ota_update_upgrade_result(ota_flag_t *flag, uint32_t result); EN_PACKAGE_TYPE get_upgrade_type(); /* 0: full upgrade, 1: diff upgrade */ diff --git a/targets/STM32F429IGTx_FIRE/Inc/ota_port.h b/targets/STM32F429IGTx_FIRE/Inc/ota_port.h index 4170686d3..471acd5cf 100644 --- a/targets/STM32F429IGTx_FIRE/Inc/ota_port.h +++ b/targets/STM32F429IGTx_FIRE/Inc/ota_port.h @@ -38,8 +38,8 @@ #ifndef OTA_PORT_H #define OTA_PORT_H -#include "ota/package.h" -#include "ota/ota_api.h" +//#include "package.h" +#include "ota_api.h" diff --git a/targets/STM32F429IGTx_FIRE/Src/flash_adaptor.c b/targets/STM32F429IGTx_FIRE/Src/flash_adaptor.c index 42152ed85..266dc067a 100644 --- a/targets/STM32F429IGTx_FIRE/Src/flash_adaptor.c +++ b/targets/STM32F429IGTx_FIRE/Src/flash_adaptor.c @@ -32,17 +32,30 @@ * applicable export control laws and regulations. *---------------------------------------------------------------------------*/ -#include "flash_adaptor.h" -#include "hal_spi_flash.h" #include #include #include #include #include "common.h" +#include "hal_flash.h" +#include "hal_spi_flash.h" +#include "partition.h" +#include "flash_adaptor.h" #define FLASH_BLOCK_SIZE 0x1000 #define FLASH_BLOCK_MASK 0xfff +static storage_partition s_storage_part[] = { + {INNER_FLASH, "loader", 0x08000000, 0x00020000}, + {INNER_FLASH, "app", OTA_DEFAULT_IMAGE_ADDR, 0x000E0000}, + {SPI_FLASH, "ota_flag1", OTA_FLAG_ADDR1, 0x00004000}, + {SPI_FLASH, "ota_flag2", OTA_FLAG_ADDR2, 0x00004000}, + {SPI_FLASH, "reserved_info", RESERVED_INFO_ADDR, RESERVED_INFO_SIZE}, + {SPI_FLASH, "ota_download", OTA_IMAGE_DOWNLOAD_ADDR, OTA_IMAGE_DOWNLOAD_SIZE}, + {SPI_FLASH, "ota_backup", OTA_IMAGE_BCK_ADDR, OTA_IMAGE_BCK_SIZE}, + {SPI_FLASH, "ota_diff_uprade", OTA_IMAGE_DIFF_UPGRADE_ADDR, OTA_IMAGE_DIFF_UPGRADE_SIZE} +}; + int flash_adaptor_write(uint32_t offset, const uint8_t *buffer, uint32_t len) { int ret = ERR; @@ -55,7 +68,7 @@ int flash_adaptor_write(uint32_t offset, const uint8_t *buffer, uint32_t len) return ERR; } - if (len == FLASH_BLOCK_SIZE && (offset & FLASH_BLOCK_MASK == 0)) + if (len == FLASH_BLOCK_SIZE && ((offset & FLASH_BLOCK_MASK) == 0)) { ret = hal_spi_flash_erase_write(buffer, FLASH_BLOCK_SIZE, offset); if(ret != OK) @@ -95,22 +108,22 @@ int flash_adaptor_write(uint32_t offset, const uint8_t *buffer, uint32_t len) return ret; } -int flash_spi2inner(uint32_t src, uint32_t dst, uint32_t len, uint8_t *cache, uint32_t cache_len) +int app_image_restore(uint32_t src, uint32_t dst, uint32_t data_len, uint32_t head_len, uint8_t *cache, uint32_t cache_len) { - int rest_len = len; + int rest_len = data_len - head_len; int blk_size = 0; int off = 0; if (cache == NULL || cache_len == 0) return -1; - hal_flash_erase(dst, len); + storage_partition_erase(dst, 0, rest_len); while(rest_len > 0) { blk_size = rest_len > cache_len ? cache_len : rest_len; - if (hal_spi_flash_read(cache, blk_size, src + off) || - hal_flash_write(cache, blk_size, &dst)) + if (storage_partition_read(src, cache, blk_size, off + head_len) || + storage_partition_write(dst, cache, blk_size, off)) return -1; off += blk_size; @@ -119,7 +132,7 @@ int flash_spi2inner(uint32_t src, uint32_t dst, uint32_t len, uint8_t *cache, ui return 0; } -int flash_inner2spi(uint32_t src, uint32_t dst, uint32_t len, uint8_t * cache, uint32_t cache_len) +int app_image_backup(uint32_t src, uint32_t dst, uint32_t len, uint8_t * cache, uint32_t cache_len) { int rest_len = len; int blk_size = 0; @@ -128,10 +141,12 @@ int flash_inner2spi(uint32_t src, uint32_t dst, uint32_t len, uint8_t * cache, u if (cache == NULL || cache_len == 0) return -1; + storage_partition_erase(dst, 0, rest_len); + while(rest_len > 0) { blk_size = rest_len > cache_len ? cache_len : rest_len; - if (hal_flash_read(cache, blk_size, src + off) || - flash_adaptor_write(dst + off, cache, blk_size)) { + if (storage_partition_read(src, cache, blk_size, off) || + storage_partition_write(dst, cache, blk_size, off)) { return -1; } off += blk_size; @@ -140,32 +155,44 @@ int flash_inner2spi(uint32_t src, uint32_t dst, uint32_t len, uint8_t * cache, u return 0; } -void flash_adaptor_init(void) +static int hal_spi_flash_write_wrapper(const uint8_t *buf, int32_t len, uint32_t offset) { - hal_spi_flash_config(); + return flash_adaptor_write(offset, buf, len); } -int flash_adaptor_write_mqtt_info(const void *buffer, uint32_t len) +static int hal_flash_write_wrapper(const uint8_t *buf, int32_t len, uint32_t offset) { - if(len > MQTT_INFO_SIZE) - { - HAL_OTA_LOG("err offset len %lu", len); - return ERR; - } - - return flash_adaptor_write(MQTT_INFO_ADDR, (const uint8_t *)buffer, len); + return hal_flash_write(buf, len, &offset); } -int flash_adaptor_read_mqtt_info(void *buffer, uint32_t len) -{ - if(len > MQTT_INFO_SIZE) +static storage_device s_storage_dev[] = { { - HAL_OTA_LOG("err offset len %lu", len); - return ERR; - } - return hal_spi_flash_read(buffer, len, MQTT_INFO_ADDR); -} - + INNER_FLASH, + "inner_flash", + 1024 * 1024, + NULL, + hal_flash_read, + hal_flash_write_wrapper, + hal_flash_erase, + hal_flash_erase_write + }, + { + SPI_FLASH, + "spi_flash", + 256 * 1024 * 1024, + hal_spi_flash_config, + hal_spi_flash_read, + hal_spi_flash_write_wrapper, + hal_spi_flash_erase, + hal_spi_flash_erase_write, + } +}; +void flash_adaptor_init(void) +{ + hal_spi_flash_config(); + storage_dev_install(s_storage_dev, sizeof(s_storage_dev)/ sizeof(storage_device)); + storage_partition_init(s_storage_part, sizeof(s_storage_part)/ sizeof(storage_partition)); +} diff --git a/targets/STM32F429IGTx_FIRE/Src/loader_main2.c b/targets/STM32F429IGTx_FIRE/Src/loader_main2.c index 46e863bd7..25e1dce07 100644 --- a/targets/STM32F429IGTx_FIRE/Src/loader_main2.c +++ b/targets/STM32F429IGTx_FIRE/Src/loader_main2.c @@ -47,59 +47,51 @@ #include "flash_adaptor.h" #include "libHDiffPatch/HPatch/patch.h" #include "decompress_plugin_demo.h" +#include "partition.h" -static hpatch_BOOL _read_spi_flash_stream(const hpatch_TStreamInput *stream, hpatch_StreamPos_t read_pos, +static hpatch_BOOL _read_storage_partition_stream(const hpatch_TStreamInput *stream, hpatch_StreamPos_t read_pos, uint8_t * data, uint8_t * data_end) { - const uint32_t location = (const uint32_t)stream->streamImport; + const uint32_t part = (const uint32_t)stream->streamImport; if ((read_pos + data_end - data) <= stream->streamSize) { - int ret = hal_spi_flash_read(data, data_end - data, location + read_pos); + if (part == PART_OTA_IMG_DOWNLOAD) read_pos += OTA_BINARY_OFFSET; + int ret = storage_partition_read(part, data, data_end - data, read_pos); return hpatch_TRUE; } else { return hpatch_FALSE; } } -void downloadimg_as_hStreamInput(hpatch_TStreamInput *stream, uint32_t location, uint32_t len) +void downloadimg_as_hStreamInput(hpatch_TStreamInput *stream, uint32_t part, uint32_t len) { - stream->streamImport = (void*)location; + stream->streamImport = (void*)part; stream->streamSize = len; - stream->read = _read_spi_flash_stream; + stream->read = _read_storage_partition_stream; } -static hpatch_BOOL _write_spi_flash_stream(const hpatch_TStreamOutput *stream, hpatch_StreamPos_t write_pos, +static hpatch_BOOL _write_storage_partition_stream(const hpatch_TStreamOutput *stream, hpatch_StreamPos_t write_pos, const uint8_t *data, const uint8_t *data_end) { - const uint32_t location = (const uint32_t)stream->streamImport; + const uint32_t part = (const uint32_t)stream->streamImport; if (write_pos + (data_end - data) <= stream->streamSize) { - flash_adaptor_write(location + write_pos, data, data_end - data); + storage_partition_write(part, data, data_end - data, write_pos); return hpatch_TRUE; } else { return hpatch_FALSE; } } -void upgradeimg_as_hStreamOutput(hpatch_TStreamOutput *stream, uint32_t location, uint32_t len) +void upgradeimg_as_hStreamOutput(hpatch_TStreamOutput *stream, uint32_t part, uint32_t len) { - stream->streamImport = (void*)location; + stream->streamImport = (void*)part; stream->streamSize = len; - stream->read_writed = _read_spi_flash_stream; - stream->write = _write_spi_flash_stream; + stream->read_writed = _read_storage_partition_stream; + stream->write = _write_storage_partition_stream; } -static hpatch_BOOL _read_builtin_flash_stream(const hpatch_TStreamInput *stream, hpatch_StreamPos_t read_pos, - uint8_t *data, uint8_t *data_end) -{ - const uint32_t location = (const uint32_t)stream->streamImport; - if ((read_pos + data_end - data) <= stream->streamSize) { - hal_flash_read(data, data_end - data, location + read_pos); - return hpatch_TRUE; - } else { - return hpatch_FALSE; - } -} -void originimg_as_hStreamInput(hpatch_TStreamInput *stream, uint32_t location, uint32_t len) + +void originimg_as_hStreamInput(hpatch_TStreamInput *stream, uint32_t part, uint32_t len) { - stream->streamImport = (void *)location; + stream->streamImport = (void *)part; stream->streamSize = len; - stream->read = _read_builtin_flash_stream; + stream->read = _read_storage_partition_stream; } hpatch_BOOL getDecompressPlugin(const hpatch_compressedDiffInfo* diffInfo, @@ -134,8 +126,6 @@ int ota_detection() ota_flag_t ota_flag; int32_t ret; int32_t patch_ret = UPGRADE_RESULT_SUCC; - uint32_t old_img_size = OTA_IMAGE_BCK_SIZE; - uint32_t new_img_size = OTA_IMAGE_DOWNLOAD_SIZE; ota_storage_flag_read(&ota_flag); hpatch_compressedDiffInfo diff_info; hpatch_TDecompress* decompress_plugin = 0; @@ -145,6 +135,7 @@ int ota_detection() printf("ota.state = %ld\n", ota_flag.cur_state); printf("ota.file size = %ld\n", ota_flag.file_size); printf("ota.ret_upgrade = %ld\n", ota_flag.ret_upgrade); + printf("ota.updater = %lx\n", ota_flag.updater); //if state is not EN_OTA_STATUS_UPGRADING, jump to app if (ota_flag.cur_state == EN_OTA_STATUS_UPGRADING) { @@ -154,39 +145,39 @@ int ota_detection() ota_update_upgrade_result(&ota_flag, UPGRADE_RESULT_MEMEXHAUSTED); return 0; } - //tell upgrade with full patch or diff patch + ota_storage_bin_read(0, cache, CACHE_SIZE); + +/* tell full upgrade or patch upgrade by diff info, no need this code if (get_package_type(cache, ota_flag.file_size) == PACKAGE_TYPE_FULL) { - printf("upgrage for full patch!\n"); - flash_inner2spi(OTA_DEFAULT_IMAGE_ADDR, OTA_IMAGE_BCK_ADDR, old_img_size, cache, CACHE_SIZE); - flash_spi2inner(OTA_IMAGE_DOWNLOAD_ADDR + sizeof(ota_pack_info), OTA_DEFAULT_IMAGE_ADDR, \ - ota_flag.file_size - sizeof(ota_pack_info), cache, CACHE_SIZE); + printf("upgrage full patch!\n"); +// app_image_backup(PART_APP, PART_OTA_IMG_BACKUP, OTA_IMAGE_BCK_SIZE, cache, CACHE_SIZE); + app_image_restore(PART_OTA_IMG_DOWNLOAD, PART_APP, \ + ota_flag.file_size, sizeof(ota_binary_info), cache, CACHE_SIZE); patch_ret = UPGRADE_RESULT_SUCC; goto EXIT; } - +*/ // diff upgrade // read diff head, get compress type and file size - printf("upgrage for diff patch!\n"); - ret = getCompressedDiffInfo_mem(&diff_info, cache + sizeof(ota_pack_info), cache + CACHE_SIZE); + printf("upgrage diff patch!\n"); + ret = getCompressedDiffInfo_mem(&diff_info, cache + OTA_BINARY_OFFSET, cache + CACHE_SIZE); if(ret != hpatch_TRUE) { printf("get diff info failed!\n"); patch_ret = UPGRADE_RESULT_INNERERROR; goto EXIT; } + printf("new img size:%ld, old img size:%ld\n", diff_info.newDataSize, diff_info.oldDataSize); getDecompressPlugin(&diff_info, &decompress_plugin); - old_img_size = diff_info.oldDataSize; - new_img_size = diff_info.newDataSize; - printf("new img size:%ld, old img size:%ld\n", new_img_size, old_img_size); hpatch_TStreamInput download_img_stream; hpatch_TStreamInput origin_img_stream; hpatch_TStreamOutput upgrade_img_stream; - downloadimg_as_hStreamInput(&download_img_stream, OTA_IMAGE_DOWNLOAD_ADDR + sizeof(ota_pack_info), ota_flag.file_size - sizeof(ota_pack_info)); - originimg_as_hStreamInput(&origin_img_stream, OTA_DEFAULT_IMAGE_ADDR, old_img_size); - upgradeimg_as_hStreamOutput(&upgrade_img_stream, OTA_IMAGE_DIFF_UPGRADE_ADDR, new_img_size); + downloadimg_as_hStreamInput(&download_img_stream, PART_OTA_IMG_DOWNLOAD, ota_flag.file_size - OTA_BINARY_OFFSET); + originimg_as_hStreamInput(&origin_img_stream, PART_APP, diff_info.oldDataSize); + upgradeimg_as_hStreamOutput(&upgrade_img_stream, PART_OTA_DIFF_UPGTADE, diff_info.newDataSize); ret = patch_decompress_with_cache(&upgrade_img_stream, &origin_img_stream, &download_img_stream, decompress_plugin, cache, cache + CACHE_SIZE); @@ -198,8 +189,8 @@ int ota_detection() } //write upgraded img to origin image -//TODO flash_inner2spi(OTA_DEFAULT_IMAGE_ADDR, OTA_IMAGE_BCK_ADDR, old_img_size, cache, CACHE_SIZE); //backup old - flash_spi2inner(OTA_IMAGE_DIFF_UPGRADE_ADDR, OTA_DEFAULT_IMAGE_ADDR, new_img_size, cache, CACHE_SIZE); // resore new +// app_image_backup(PART_APP, PART_OTA_IMG_BACKUP, diff_info.oldDataSize, cache, CACHE_SIZE); + app_image_restore(PART_OTA_DIFF_UPGTADE, PART_APP, diff_info.newDataSize, 0, cache, CACHE_SIZE); // resore new EXIT: //save upgrade result ota_update_upgrade_result(&ota_flag, patch_ret); diff --git a/targets/STM32F429IGTx_FIRE/Src/ota_adaptor.c b/targets/STM32F429IGTx_FIRE/Src/ota_adaptor.c index 93e1caee8..8373ea99a 100644 --- a/targets/STM32F429IGTx_FIRE/Src/ota_adaptor.c +++ b/targets/STM32F429IGTx_FIRE/Src/ota_adaptor.c @@ -32,42 +32,44 @@ * applicable export control laws and regulations. *---------------------------------------------------------------------------*/ #include "ota_adaptor.h" -#include "ota_flag.h" +#include "partition.h" +#include "flash_adaptor.h" +#include "common.h" static int ota_flag_read(ota_flag_t *flag) { if (flag != NULL) { printf("SPI FLAG R\n"); - return hal_spi_flash_read((void *)flag, sizeof(ota_flag_t), OTA_FLAG_ADDR1); + return storage_partition_read(PART_OTA_FLAG1, (void *)flag, sizeof(ota_flag_t), 0); } - return -1; + return ERR; } static int ota_flag_write(ota_flag_t *flag) { if (flag != NULL) { printf("SPI FLAG W:state %d\n", flag->cur_state); - return flash_adaptor_write(OTA_FLAG_ADDR1, (void *)flag, sizeof(ota_flag_t)); + return storage_partition_write(PART_OTA_FLAG1, (void *)flag, sizeof(ota_flag_t), 0); } - return -1; + return ERR; } static int ota_bin_read(uint32_t offset, void *buf, int len) { if (buf != NULL) { printf("SPI BIN R: %08d %08d\n", offset, len); - return hal_spi_flash_read(buf, len, offset + OTA_IMAGE_DOWNLOAD_ADDR); + return storage_partition_read(PART_OTA_IMG_DOWNLOAD, buf, len, offset); } - return -1; + return ERR; } static int ota_bin_write(uint32_t offset, void *buf, int len) { if (buf != NULL) { printf("SPI BIN W: %08d %08d\n", offset, len); - return flash_adaptor_write(offset + OTA_IMAGE_DOWNLOAD_ADDR, buf, len); + return storage_partition_write(PART_OTA_IMG_DOWNLOAD, buf, len, offset); } - return -1; + return ERR; } static ota_storage_t prv_ota_flag_s = @@ -84,11 +86,11 @@ static ota_storage_t prv_ota_flag_s = /* 0: full upgrade, 1: diff upgrade */ EN_PACKAGE_TYPE get_package_type(const uint8_t *data, uint32_t len) { - ota_pack_info *info; - if (data == NULL ||len <= sizeof(ota_pack_info)) - return -1; + ota_binary_info *info; + if (data == NULL ||len <= sizeof(ota_binary_info)) + return ERR; - info = (ota_pack_info *)data; + info = (ota_binary_info *)data; return info->pack_type; } diff --git a/targets/STM32F429IGTx_FIRE/Src/ota_port.c b/targets/STM32F429IGTx_FIRE/Src/ota_port.c index 43db691e3..6b166943a 100644 --- a/targets/STM32F429IGTx_FIRE/Src/ota_port.c +++ b/targets/STM32F429IGTx_FIRE/Src/ota_port.c @@ -34,32 +34,14 @@ #include "ota_port.h" #include "common.h" -#include "flag_manager.h" -#include "upgrade_flag.h" #include #include #include +#include "partition.h" #include "flash_adaptor.h" -#include "hal_spi_flash.h" - - -static const uint32_t g_flash_base_addrs[] = {OTA_IMAGE_DOWNLOAD_ADDR, OTA_IMAGE_DOWNLOAD_ADDR, OTA_FLAG_ADDR1}; -static const uint32_t g_flash_max_size[] = {OTA_IMAGE_DOWNLOAD_SIZE, OTA_IMAGE_DOWNLOAD_SIZE, FLASH_BLOCK_SIZE}; static int hal_check_flash_param(ota_flash_type_e type, int32_t len, uint32_t location) { - if (type > OTA_UPDATE_INFO) - { - HAL_OTA_LOG("err type %d", type); - return ERR; - } - - if(len > g_flash_max_size[type]) - { - HAL_OTA_LOG("err offset %lu, len %lu", location, len); - return ERR; - } - return OK; } @@ -70,7 +52,7 @@ static int hal_read_flash(ota_flash_type_e type, void *buf, int32_t len, uint32_ return ERR; } - return hal_spi_flash_read(buf, len, g_flash_base_addrs[type] + location); + return storage_partition_read(type, buf, len, location); } static int hal_write_flash(ota_flash_type_e type, const void *buf, int32_t len, uint32_t location) @@ -80,15 +62,9 @@ static int hal_write_flash(ota_flash_type_e type, const void *buf, int32_t len, return ERR; } - return flash_adaptor_write(g_flash_base_addrs[type] + location, (const uint8_t *)buf, len); + return storage_partition_write(type, buf, len, location); } -void hal_init_ota(void) -{ - flash_adaptor_init(); -} - - void hal_get_ota_opt(ota_opt_s *opt) { if (opt == NULL) diff --git a/targets/STM32L431_BearPi/Demos/hello_world_demo/defaults.sdkconfig b/targets/STM32L431_BearPi/Demos/hello_world_demo/defaults.sdkconfig index 16840899c..d72b4269c 100644 --- a/targets/STM32L431_BearPi/Demos/hello_world_demo/defaults.sdkconfig +++ b/targets/STM32L431_BearPi/Demos/hello_world_demo/defaults.sdkconfig @@ -39,5 +39,7 @@ CONFIG_OC_LWM2M_TYPE = "none" CONFIG_LOADER_ENABLE = n CONFIG_OC_LWM2M_DEMO_TYPE= "none" CONFIG_OC_MQTT_DEMO_TYPE= "none" +CONFIG_DEMO_ENABLE= y +CONFIG_DEMO_TYPE= "none" CONFIG_USER_DEMO = "hello_world_demo" \ No newline at end of file diff --git a/targets/STM32L431_BearPi/Demos/oc_streetlight_infrared_template/defaults.sdkconfig b/targets/STM32L431_BearPi/Demos/oc_streetlight_infrared_template/defaults.sdkconfig new file mode 100644 index 000000000..61c51da9d --- /dev/null +++ b/targets/STM32L431_BearPi/Demos/oc_streetlight_infrared_template/defaults.sdkconfig @@ -0,0 +1,49 @@ +##############################CONFIGURE INTRODUCTION############################ +#configure type configure value +#------------------:------------------ +#CONFIG_OS_TYPE : "linux" "macos" "liteos" +#CONFIG_SHELL_ENABLE : y n +#CONFIG_LIBC_ENABLE : y n +#CONFIG_CJSON_ENABLE : y n +#CONFIG_TCPIP_TYPE : "lwip" "linux_socket" "macos_socket" "none" +#CONFIG_DTLS_TYPE : "mbedtls" "none" +#CONFIG_EMBEDTLS_MODE : "crt" "psk" "none" +#CONFIG_MQTT_TYPE : "paho" "none" +#CONFIG_LWM2M_TYPE : "wakaama" "none" +#CONFIG_OC_MQTT_TYPE : "soft" "none" +#CONFIG_OC_LWM2M_TYPE : "soft" "boudica150" "none" +#CONFIG_LOADER_ENABLE : y n +#CONFIG_OC_LWM2M_DEMO_TYPE:"none" "oc_lwm2m_demo_dtls" and "oc_lwm2m_demo_nodtls" "oc_lwm2m_demo_bs_dtls" "oc_lwm2m_demo_bearpi_template" +#CONFIG_OC_MQTT_DEMO_TYPE:"none" "oc_mqtt_demo_static" "oc_mqtt_demo_bs" + +#this is for IoT Studio automatic generating kconfig compatibility +CONFIG_OS_LiteOS=y +CONFIG_ARMV7_M=y +CONFIG_OC_LWM2M=y +CONFIG_BOUDICA150=y +CONFIG_Demo_Streetlight=y +# + +CONFIG_OS_TYPE = "liteos" +CONFIG_ARCH_CPU_TYPE = "armv7-m" +CONFIG_SHELL_ENABLE = y +CONFIG_STIMER_ENABLE = y +CONFIG_DRIVER_ENABLE = y +CONFIG_AT_ENABLE = y +CONFIG_LIBC_ENABLE = y +CONFIG_CJSON_ENABLE = n +CONFIG_TCPIP_TYPE = "none" +CONFIG_DTLS_TYPE = "none" +CONFIG_EMBEDTLS_MODE = "none" +CONFIG_MQTT_TYPE = "none" +CONFIG_LWM2M_TYPE = "none" +CONFIG_OC_LWM2M_ENABLE = y +CONFIG_OC_LWM2M_TYPE = "boudica150_oc" +CONFIG_LOADER_ENABLE = n +CONFIG_OC_LWM2M_DEMO_TYPE= "none" +CONFIG_OC_MQTT_DEMO_TYPE= "none" +CONFIG_DEMO_ENABLE= y +CONFIG_DEMO_TYPE= "none" + +CONFIG_USER_DEMO = "oc_streetlight_infrared_template" +CONFIG_DEMO_ENABLE = y diff --git a/targets/STM32L431_BearPi/Demos/oc_streetlight_infrared_template/oc_streetlight_infrared_template.c b/targets/STM32L431_BearPi/Demos/oc_streetlight_infrared_template/oc_streetlight_infrared_template.c new file mode 100644 index 000000000..763b7c7f5 --- /dev/null +++ b/targets/STM32L431_BearPi/Demos/oc_streetlight_infrared_template/oc_streetlight_infrared_template.c @@ -0,0 +1,466 @@ +/*---------------------------------------------------------------------------- + * Copyright (c) <2018>, + * All rights reserved. + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *---------------------------------------------------------------------------*/ +/*---------------------------------------------------------------------------- + * Notice of Export Control Law + * =============================================== + * Huawei LiteOS may be subject to applicable export control laws and regulations, which might + * include those applicable to Huawei LiteOS of U.S. and the country in which you are located. + * Import, export and usage of Huawei LiteOS in any manner by you shall be in compliance with such + * applicable export control laws and regulations. + *---------------------------------------------------------------------------*/ +/** + * DATE AUTHOR INSTRUCTION + * 2019-05-14 17:21 zhangqianfu The first version + * + */ +#include +#include +#include + +#include +#include +#include + +#include +#include "E53_SC1_Infrared.h" +#include "lcd.h" + +#include +#include + +#define cn_endpoint_id "SDK_LWM2M_NODTLS" +#define cn_app_server "49.4.85.232" +#define cn_app_port "5683" + +#define cn_app_connectivity 0 +#define cn_app_lightstats 1 +#define cn_app_light 2 +#define cn_app_ledcmd 3 +#define cn_app_cmdreply 4 + +#define Interrupt_enable 1 +#define Interrupt_disenable 0 +#define E53_SC1_Infrared_start_delay_time 60 //人体红外启动延迟时间,单位S +#define E53_SC1_Infrared_light_time 10 //人体红外触发后亮灯时间,单位S +#define Infrared_Lux_set 50 //人体红外触发,判断是否亮灯的环境光线阀值 + +#define set_light 1 +#define reset_light 0 +int8_t light_state_from_IOTcloud = reset_light; +int8_t light_state_from_Infrared = reset_light; + + +static int set_light_entry() +{ + if(light_state_from_IOTcloud == set_light) + { + HAL_GPIO_WritePin(SC1_Light_GPIO_Port,SC1_Light_Pin,GPIO_PIN_SET); + //set light + } + else + { + if(light_state_from_Infrared == set_light) + { + if( (int)E53_SC1_Data.Lux <= Infrared_Lux_set) + { + + HAL_GPIO_WritePin(SC1_Light_GPIO_Port,SC1_Light_Pin,GPIO_PIN_SET); + //set light + } + } + else + { + HAL_GPIO_WritePin(SC1_Light_GPIO_Port,SC1_Light_Pin,GPIO_PIN_RESET); + //reset light + } + } + + return 0; +} + + +#pragma pack(1) +typedef struct +{ + int8_t msgid; + int16_t rsrp; + int16_t ecl; + int16_t snr; + int32_t cellid; +}app_connectivity_t; + +typedef struct +{ + int8_t msgid; + int16_t tog; +}app_toggle_t; + +typedef struct +{ + int8_t msgid; + int16_t intensity; +}app_light_intensity_t; + + +typedef struct +{ + int8_t msgid; + uint16_t mid; + char led[3]; +}app_led_cmd_t; + +typedef struct +{ + int8_t msgid; + uint16_t mid; + int8_t errorcode; + char curstats[3]; +}app_cmdreply_t; + +#pragma pack() + +void *context; +int *ue_stats; +int8_t key1 = 0; +int8_t key2 = 0; +int8_t Infrared_signal = 0; +int16_t toggle = 0; +int16_t lux; +int8_t qr_code = 1; +extern const unsigned char gImage_Huawei_IoT_QR_Code[114720]; +E53_SC1_Data_TypeDef E53_SC1_Data; + +void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) +{ + switch(GPIO_Pin) + { + case KEY1_Pin: + key1 = 1; + printf("proceed to get ue_status!\r\n"); + break; + case KEY2_Pin: + key2 = 1; + printf("toggle LED and report!\r\n"); + toggle = !toggle; + HAL_GPIO_TogglePin(SC1_Light_GPIO_Port,SC1_Light_Pin); + break; + case SC1_Infrared_Pin: + Infrared_signal = 1; + printf("Ifrared message!\r\n"); + HAL_GPIO_TogglePin(SC1_Light_GPIO_Port,SC1_Light_Pin); + break; + + default: + break; + } +} + +//if your command is very fast,please use a queue here--TODO +#define cn_app_rcv_buf_len 128 +static int s_rcv_buffer[cn_app_rcv_buf_len]; +static int s_rcv_datalen; +static osal_semp_t s_rcv_sync; + +static void timer1_callback(void *arg) +{ + qr_code = !qr_code; + LCD_Clear(WHITE); + if (qr_code == 1) + LCD_Show_Image(0,0,240,239,gImage_Huawei_IoT_QR_Code); + else + { + POINT_COLOR = RED; + LCD_ShowString(40, 10, 200, 16, 24, "IoTCluB BearPi"); + LCD_ShowString(15, 50, 210, 16, 24, "LiteOS NB-IoT Demo"); + LCD_ShowString(10, 100, 200, 16, 16, "NCDP_IP:"); + LCD_ShowString(80, 100, 200, 16, 16, cn_app_server); + LCD_ShowString(10, 150, 200, 16, 16, "NCDP_PORT:"); + LCD_ShowString(100, 150, 200, 16, 16, cn_app_port); + } +} + +//use this function to push all the message to the buffer +static int app_msg_deal(void *usr_data, en_oc_lwm2m_msg_t type, void *data, int len) +{ + unsigned char *msg; + msg = data; + int ret = -1; + + if(len <= cn_app_rcv_buf_len) + { + if (msg[0] == 0xaa && msg[1] == 0xaa) + { + printf("OC respond message received! \n\r"); + return ret; + } + memcpy(s_rcv_buffer,msg,len); + s_rcv_datalen = len; + + osal_semp_post(s_rcv_sync); + + ret = 0; + + } + return ret; +} + + +static int app_cmd_task_entry() +{ + int ret = -1; + app_led_cmd_t *led_cmd; + app_cmdreply_t replymsg; + int8_t msgid; + + while(1) + { + if(osal_semp_pend(s_rcv_sync,cn_osal_timeout_forever)) + { + msgid = s_rcv_buffer[0] & 0x000000FF; + switch (msgid) + { + case cn_app_ledcmd: + led_cmd = (app_led_cmd_t *)s_rcv_buffer; + printf("LEDCMD:msgid:%d mid:%d msg:%s \n\r",led_cmd->msgid,ntohs(led_cmd->mid),led_cmd->led); + //add command action--TODO + if (led_cmd->led[0] == 'O' && led_cmd->led[1] == 'N') + { + if (toggle != 1) + { + toggle = 1; + key2 = true; + } + light_state_from_IOTcloud = set_light; + set_light_entry(); + + //if you need response message,do it here--TODO + replymsg.msgid = cn_app_cmdreply; + replymsg.mid = led_cmd->mid; + printf("reply mid is %d. \n\r",ntohs(replymsg.mid)); + replymsg.errorcode = 0; + replymsg.curstats[0] = 'O'; + replymsg.curstats[1] = 'N'; + replymsg.curstats[2] = ' '; + oc_lwm2m_report(context,(char *)&replymsg,sizeof(replymsg),1000); ///< report cmd reply message + } + + else if (led_cmd->led[0] == 'O' && led_cmd->led[1] == 'F' && led_cmd->led[2] == 'F') + { + if (toggle != 0) + { + toggle = 0; + key2 = true; + } + + light_state_from_IOTcloud = reset_light; + set_light_entry(); + + //if you need response message,do it here--TODO + replymsg.msgid = cn_app_cmdreply; + replymsg.mid = led_cmd->mid; + printf("reply mid is %d. \n\r",ntohs(replymsg.mid)); + replymsg.errorcode = 0; + replymsg.curstats[0] = 'O'; + replymsg.curstats[1] = 'F'; + replymsg.curstats[2] = 'F'; + oc_lwm2m_report(context,(char *)&replymsg,sizeof(replymsg),1000); ///< report cmd reply message + } + + else + break; + default: + break; + } + } + } + + return ret; +} + +static void get_netstats() +{ + ue_stats = boudica150_check_nuestats(); + if (ue_stats[0] < -10) ue_stats[0] = ue_stats[0] / 10; + if (ue_stats[2] > 10) ue_stats[2] = ue_stats[2] / 10; + +} + +static int app_report_task_entry() +{ + int ret = -1; + + oc_config_param_t oc_param; + app_light_intensity_t light; + app_connectivity_t connectivity; + app_toggle_t light_status; + + memset(&oc_param,0,sizeof(oc_param)); + + oc_param.app_server.address = cn_app_server; + oc_param.app_server.port = cn_app_port; + oc_param.app_server.ep_id = cn_endpoint_id; + oc_param.boot_mode = en_oc_boot_strap_mode_factory; + oc_param.rcv_func = app_msg_deal; + + context = oc_lwm2m_config(&oc_param); + + if(NULL != context) //success ,so we could receive and send + { + //install a dealer for the led message received + while(1) //--TODO ,you could add your own code here + { + if (key1 == 1) + { + key1 = 0; + connectivity.msgid = cn_app_connectivity; + get_netstats(); + connectivity.rsrp = htons(ue_stats[0] & 0x0000FFFF); + connectivity.ecl = htons(ue_stats[1] & 0x0000FFFF); + connectivity.snr = htons(ue_stats[2] & 0x0000FFFF); + connectivity.cellid = htonl(ue_stats[3]); + oc_lwm2m_report(context,(char *)&connectivity,sizeof(connectivity),1000); ///< report ue status message + } + + if (key2 == 1) + { + key2 = 0; + light_status.msgid = cn_app_lightstats; + light_status.tog = htons(toggle); + oc_lwm2m_report(context,(char *)&light_status,sizeof(light_status),1000); ///< report toggle message + } + + light.msgid = cn_app_light; + light.intensity = htons((int)E53_SC1_Data.Lux); + oc_lwm2m_report(context,(char *)&light,sizeof(light),1000); ///< report the light message + printf("Infrared Light:%u.\r\n",(int)E53_SC1_Data.Lux); + osal_task_sleep(2*1000); + } + } + + return ret; +} + +static int E53_SC1_Infrared_EnableInterrupt() +{ + osal_int_connect(Infrared_EXTI_IRQn, 4,0,Infrared_IRQHandler,NULL); + return 0; +} + +static int app_infrared_task_entry() +{ + int interrupt_delay_time = E53_SC1_Infrared_start_delay_time; + int Light_time = -1; + int E53_SC1_Infrared_Interrupt_state = Interrupt_disenable; + Init_E53_SC1_Infrared(); + + while (1) + { + if(E53_SC1_Infrared_Interrupt_state == Interrupt_disenable) + { + if(interrupt_delay_time <= 0) + { + E53_SC1_Infrared_EnableInterrupt(); + E53_SC1_Infrared_Interrupt_state = Interrupt_enable; + printf("Infrared interrupt start.\r\n"); + } + interrupt_delay_time--; + printf("Infrared delay time: %d S.\r\n",interrupt_delay_time); + + } + + if(Infrared_signal == 1) + { + Light_time = E53_SC1_Infrared_light_time; + light_state_from_Infrared = set_light; + set_light_entry(); + //HAL_GPIO_WritePin(SC1_Light_GPIO_Port,SC1_Light_Pin,GPIO_PIN_SET); + Infrared_signal = 0; + } + + if(Light_time == 0) + { + Light_time = -1; + light_state_from_Infrared = reset_light; + set_light_entry(); + } + + if(Light_time > 0) + { + Light_time--; + printf("Infrared Light time: %d S.\r\n",Light_time); + } + + + osal_task_sleep(1000); + } + + return 0; +} + +static int app_collect_task_entry() +{ + Init_E53_SC1(); + + while (1) + { + E53_SC1_Read_Data(); + printf("\r\n******************************BH1750 Value is %d\r\n",(int)E53_SC1_Data.Lux); + if (qr_code == 0) + { + LCD_ShowString(10, 200, 200, 16, 16, "BH1750 Value is:"); + LCD_ShowNum(140, 200, (int)E53_SC1_Data.Lux, 5, 16); + } + + osal_task_sleep(2*1000); + } + + return 0; +} + +///< add my own demo main function +#include + +int standard_app_demo_main() +{ + osal_semp_create(&s_rcv_sync,1,0); + + osal_task_create("app_collect",app_collect_task_entry,NULL,0x400,NULL,3); + osal_task_create("app_report",app_report_task_entry,NULL,0x1000,NULL,2); + osal_task_create("app_command",app_cmd_task_entry,NULL,0x1000,NULL,3); + osal_task_create("app_infrared_command",app_infrared_task_entry,NULL,0x1000,NULL,3); + + osal_int_connect(KEY1_EXTI_IRQn, 2,0,Key1_IRQHandler,NULL); + osal_int_connect(KEY2_EXTI_IRQn, 3,0,Key2_IRQHandler,NULL); + + stimer_create("lcdtimer",timer1_callback,NULL,8*1000,cn_stimer_flag_start); + + return 0; +} + + + + + diff --git a/targets/STM32L431_BearPi/Demos/oc_streetlight_template/oc_streetlight_template.c b/targets/STM32L431_BearPi/Demos/oc_streetlight_template/oc_streetlight_template.c index 20c962a59..0cc71e2b2 100644 --- a/targets/STM32L431_BearPi/Demos/oc_streetlight_template/oc_streetlight_template.c +++ b/targets/STM32L431_BearPi/Demos/oc_streetlight_template/oc_streetlight_template.c @@ -123,7 +123,7 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) key2 = 1; printf("toggle LED and report!\r\n"); toggle = !toggle; - HAL_GPIO_TogglePin(Light_GPIO_Port,Light_Pin); + HAL_GPIO_TogglePin(SC1_Light_GPIO_Port,SC1_Light_Pin); break; default: break; @@ -205,7 +205,7 @@ static int app_cmd_task_entry() toggle = 1; key2 = true; } - HAL_GPIO_WritePin(Light_GPIO_Port,Light_Pin,GPIO_PIN_SET); + HAL_GPIO_WritePin(SC1_Light_GPIO_Port,SC1_Light_Pin,GPIO_PIN_SET); //if you need response message,do it here--TODO replymsg.msgid = cn_app_cmdreply; @@ -225,7 +225,7 @@ static int app_cmd_task_entry() toggle = 0; key2 = true; } - HAL_GPIO_WritePin(Light_GPIO_Port,Light_Pin,GPIO_PIN_RESET); + HAL_GPIO_WritePin(SC1_Light_GPIO_Port,SC1_Light_Pin,GPIO_PIN_RESET); //if you need response message,do it here--TODO replymsg.msgid = cn_app_cmdreply; diff --git a/targets/STM32L431_BearPi/Demos/user_demo.mk b/targets/STM32L431_BearPi/Demos/user_demo.mk index 63b4ae358..e472260c5 100644 --- a/targets/STM32L431_BearPi/Demos/user_demo.mk +++ b/targets/STM32L431_BearPi/Demos/user_demo.mk @@ -7,15 +7,24 @@ #example for lwm2m ifeq ($(CONFIG_DEMO_TYPE), "none") - CONFIG_USER_DEMO := "oc_track_template" - + #example for oc_streetlight_template ifeq ($(CONFIG_USER_DEMO), "oc_streetlight_template") user_demo_src = ${wildcard $(TOP_DIR)/targets/STM32L431_BearPi/Demos/oc_streetlight_template/*.c} user_demo_inc = -I $(TOP_DIR)/targets/STM32L431_BearPi/Demos/oc_streetlight_template user_hardware_src = ${wildcard $(TOP_DIR)/targets/STM32L431_BearPi/Hardware/E53_SC1/*.c} user_hardware_inc = -I ${wildcard $(TOP_DIR)/targets/STM32L431_BearPi/Hardware/E53_SC1} - user_demo_defs = -D CONFIG_OC_LWM2M_DEMO_ENABLE=1 + user_demo_defs = -D CONFIG_OC_STREELIGHT_DEMO_ENABLE=1 + + endif + + #example for oc_streetlight_infrared_template + ifeq ($(CONFIG_USER_DEMO), "oc_streetlight_infrared_template") + user_demo_src = ${wildcard $(TOP_DIR)/targets/STM32L431_BearPi/Demos/oc_streetlight_infrared_template/*.c} + user_demo_inc = -I $(TOP_DIR)/targets/STM32L431_BearPi/Demos/oc_streetlight_infrared_template + user_hardware_src = ${wildcard $(TOP_DIR)/targets/STM32L431_BearPi/Hardware/E53_SC1_Infrared/*.c} + user_hardware_inc = -I ${wildcard $(TOP_DIR)/targets/STM32L431_BearPi/Hardware/E53_SC1_Infrared} + user_demo_defs = -D oc_streetlight_infrared_template=1 endif @@ -25,7 +34,7 @@ ifeq ($(CONFIG_DEMO_TYPE), "none") user_demo_inc = -I $(TOP_DIR)/targets/STM32L431_BearPi/Demos/oc_agriculture_template user_hardware_src = ${wildcard $(TOP_DIR)/targets/STM32L431_BearPi/Hardware/E53_IA1/*.c} user_hardware_inc = -I ${wildcard $(TOP_DIR)/targets/STM32L431_BearPi/Hardware/E53_IA1} - user_demo_defs = -D CONFIG_OC_LWM2M_DEMO_ENABLE=1 + user_demo_defs = -D CONFIG_OC_ARRICULTURE_DEMO_ENABLE=1 endif @@ -35,7 +44,7 @@ ifeq ($(CONFIG_DEMO_TYPE), "none") user_demo_inc = -I $(TOP_DIR)/targets/STM32L431_BearPi/Demos/oc_track_template user_hardware_src = ${wildcard $(TOP_DIR)/targets/STM32L431_BearPi/Hardware/E53_ST1/*.c} user_hardware_inc = -I ${wildcard $(TOP_DIR)/targets/STM32L431_BearPi/Hardware/E53_ST1} - user_demo_defs = -D CONFIG_OC_LWM2M_DEMO_ENABLE=1 + user_demo_defs = -D CONFIG_OC_TRACK_DEMO_ENABLE=1 endif @@ -45,7 +54,7 @@ ifeq ($(CONFIG_DEMO_TYPE), "none") user_demo_inc = -I $(TOP_DIR)/targets/STM32L431_BearPi/Demos/oc_smoke_template user_hardware_src = ${wildcard $(TOP_DIR)/targets/STM32L431_BearPi/Hardware/E53_SF1/*.c} user_hardware_inc = -I ${wildcard $(TOP_DIR)/targets/STM32L431_BearPi/Hardware/E53_SF1} - user_demo_defs = -D CONFIG_OC_LWM2M_DEMO_ENABLE=1 + user_demo_defs = -D CONFIG_OC_SMOKE_DEMO_ENABLE=1 endif #example for hello world diff --git a/targets/STM32L431_BearPi/GCC/config.mk b/targets/STM32L431_BearPi/GCC/config.mk index 00bd3bc80..540f192dc 100644 --- a/targets/STM32L431_BearPi/GCC/config.mk +++ b/targets/STM32L431_BearPi/GCC/config.mk @@ -166,5 +166,12 @@ CONFIG_DEMO_TYPE := "none" #########################STANDARD DEMO END###################################### +########################BearPi-IoT OC DEMO START##################################### + +#CONFIG_USER_DEMO could be "oc_streetlight_template" "oc_streetlight_infrared_template" "oc_agriculture_template" "oc_track_template" "oc_smoke_template" + +CONFIG_USER_DEMO := "oc_agriculture_template" + +#########################BearPi-IoT OC DEMO END###################################### diff --git a/targets/STM32L431_BearPi/Hardware/E53_SC1_Infrared/E53_SC1_Infrared.c b/targets/STM32L431_BearPi/Hardware/E53_SC1_Infrared/E53_SC1_Infrared.c new file mode 100644 index 000000000..eb20c06ca --- /dev/null +++ b/targets/STM32L431_BearPi/Hardware/E53_SC1_Infrared/E53_SC1_Infrared.c @@ -0,0 +1,115 @@ +/******************************************************************************** + * 文件名称 :E53_SC1_Infrared.c + * 作 者:LGS + * 版 本:V1.0 + * 编写日期 :2019-11-27 + * 功 能:E53_CS1扩展板增加人体红外传感器驱动 +********************************************************************************* + * 说 明 :本例程配套物联网俱乐部开发板使用 + * + * 淘 宝:https://shop128001708.taobao.com/ + * 论 坛:bbs.iot-club.cn +*********************************************************************************/ + +//#include "E53_SC1.h" +#include "stm32l4xx.h" +#include "i2c.h" +#include "E53_SC1_Infrared.h" + + +uint8_t BUF[2]; +int result; + + +/*************************************************************** +* 函数名称: Init_BH1750 +* 说 明: 写命令初始化BH1750 +* 参 数: 无 +* 返 回 值: 无 +***************************************************************/ +void Init_BH1750(void) +{ + uint8_t t_Data = 0x01; + HAL_I2C_Master_Transmit(&hi2c1,BH1750_Addr,&t_Data,1,0xff); +} + +/*************************************************************** +* 函数名称: Start_BH1750 +* 说 明: 启动BH1750 +* 参 数: 无 +* 返 回 值: 无 +***************************************************************/ +void Start_BH1750(void) +{ + uint8_t t_Data = 0x10; + HAL_I2C_Master_Transmit(&hi2c1,BH1750_Addr,&t_Data,1,0xff); +} + +void Init_Light(void) +{ + + GPIO_InitTypeDef GPIO_InitStruct; + + /* GPIO Ports Clock Enable */ + SC1_Light_GPIO_CLK_ENABLE(); + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(SC1_Light_GPIO_Port, SC1_Light_Pin, GPIO_PIN_RESET); + + /*Configure GPIO pin : PtPin */ + GPIO_InitStruct.Pin = SC1_Light_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(SC1_Light_GPIO_Port, &GPIO_InitStruct); + +} + +void Init_E53_SC1(void) +{ + MX_I2C1_Init(); + Init_Light(); + Init_BH1750(); +} +/*************************************************************** +* 函数名称: E53_SC1_Read_Data +* 说 明: 测量光照强度 +* 参 数: 无 +* 返 回 值: 无 +***************************************************************/ +void E53_SC1_Read_Data(void) +{ + + Start_BH1750(); + HAL_Delay(180); + HAL_I2C_Master_Receive(&hi2c1, BH1750_Addr+1,BUF,2,0xff); + result=BUF[0]; + result=(result<<8)+BUF[1]; //合成数据,即光照数据 + E53_SC1_Data.Lux=(float)(result/1.2); + +} + +/*************************************************************** +* 函数名称: Init_E53_SC1_Infrared +* 说 明: 写命令初始化Infrared IO +* 参 数: 无 +* 返 回 值: 无 +***************************************************************/ +void Init_E53_SC1_Infrared(void) +{ + + GPIO_InitTypeDef GPIO_InitStruct = {0}; + + /* GPIO Ports Clock Enable */ + SC1_Infrared_GPIO_CLK_ENABLE(); + + /*Configure GPIO pin : Ifrared_Pin */ + GPIO_InitStruct.Pin = SC1_Infrared_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; + GPIO_InitStruct.Pull = GPIO_PULLDOWN; + HAL_GPIO_Init(SC1_Infrared_GPIO_Port, &GPIO_InitStruct); + + //HAL_NVIC_SetPriority(EXTI9_5_IRQn, 5, 0); + //HAL_NVIC_EnableIRQ(EXTI9_5_IRQn); + + +} diff --git a/targets/STM32L431_BearPi/Hardware/E53_SC1_Infrared/E53_SC1_Infrared.h b/targets/STM32L431_BearPi/Hardware/E53_SC1_Infrared/E53_SC1_Infrared.h new file mode 100644 index 000000000..b8cc6902d --- /dev/null +++ b/targets/STM32L431_BearPi/Hardware/E53_SC1_Infrared/E53_SC1_Infrared.h @@ -0,0 +1,61 @@ +/******************************************************************************** + * 文件名称 :E53_SC1_Infrared.h + * 作 者:LGS + * 版 本:V1.0 + * 编写日期 :2019-11-27 + * 功 能:E53_CS1扩展板增加人体红外传感器驱动 +********************************************************************************* + * 说 明 :本例程配套物联网俱乐部开发板使用 + * + * 淘 宝:https://shop128001708.taobao.com/ + * 论 坛:bbs.iot-club.cn +*********************************************************************************/ +#ifndef __E53_SC1_Infrared_H__ +#define __E53_SC1_Infrared_H__ +/* 包含头文件 ----------------------------------------------------------------*/ +#include "stm32l4xx_hal.h" + +/* 控制设备IO口定义 ------------------------------------------------------------*/ + +#define SC1_Light_Pin GPIO_PIN_9 +#define SC1_Light_GPIO_Port GPIOB +#define SC1_Light_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE() + +#define SC1_Infrared_Pin GPIO_PIN_9 +#define SC1_Infrared_GPIO_Port GPIOC +#define SC1_Infrared_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE() + +/* E53_IA1传感器数据类型定义 ------------------------------------------------------------*/ +typedef struct +{ + float Lux; //光照强度 +} E53_SC1_Data_TypeDef; + +extern E53_SC1_Data_TypeDef E53_SC1_Data; + + +/* 寄存器宏定义 --------------------------------------------------------------------*/ +#define I2C_OWN_ADDRESS 0x0A + +#define BH1750_Addr 0x46 +#define BH1750_ON 0x01 +#define BH1750_CON 0x10 +#define BH1750_ONE 0x20 +#define BH1750_RSET 0x07 + +void Init_E53_SC1(void); +void E53_SC1_Read_Data(void); +void Init_E53_SC1_Infrared(void); + +#endif + + + + + + + + + + + diff --git a/targets/STM32L431_BearPi/Inc/gpio.h b/targets/STM32L431_BearPi/Inc/gpio.h index 35566f91a..e14d82f72 100644 --- a/targets/STM32L431_BearPi/Inc/gpio.h +++ b/targets/STM32L431_BearPi/Inc/gpio.h @@ -54,8 +54,8 @@ #define LED_Pin GPIO_PIN_13 #define LED_GPIO_Port GPIOC -#define Light_Pin GPIO_PIN_9 -#define Light_GPIO_Port GPIOB +//#define Light_Pin GPIO_PIN_9 +//#define Light_GPIO_Port GPIOB /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ diff --git a/targets/STM32L431_BearPi/Inc/stm32l4xx_it.h b/targets/STM32L431_BearPi/Inc/stm32l4xx_it.h index fa5173b44..fa050b6ce 100644 --- a/targets/STM32L431_BearPi/Inc/stm32l4xx_it.h +++ b/targets/STM32L431_BearPi/Inc/stm32l4xx_it.h @@ -57,12 +57,15 @@ void PendSV_Handler(void); void SysTick_Handler(void); void Key1_IRQHandler(void *args); void Key2_IRQHandler(void *args); +void Infrared_IRQHandler(void *args); void USART1_IRQHandler(void); void USART2_IRQHandler(void); void USART3_IRQHandler(void); #define KEY1_EXTI_IRQn EXTI2_IRQn #define KEY2_EXTI_IRQn EXTI3_IRQn +#define Infrared_EXTI_IRQn EXTI9_5_IRQn + #ifdef __cplusplus } diff --git a/targets/STM32L431_BearPi/Src/gpio.c b/targets/STM32L431_BearPi/Src/gpio.c index d9662d39a..2a1a0afce 100644 --- a/targets/STM32L431_BearPi/Src/gpio.c +++ b/targets/STM32L431_BearPi/Src/gpio.c @@ -68,15 +68,15 @@ void MX_GPIO_Init(void) __HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE(); - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(Light_GPIO_Port, Light_Pin, GPIO_PIN_RESET); - - /*Configure GPIO pin : PtPin */ - GPIO_InitStruct.Pin = Light_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(Light_GPIO_Port, &GPIO_InitStruct); +// /*Configure GPIO pin Output Level */ +// HAL_GPIO_WritePin(Light_GPIO_Port, Light_Pin, GPIO_PIN_RESET); +// +// /*Configure GPIO pin : PtPin */ +// GPIO_InitStruct.Pin = Light_Pin; +// GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; +// GPIO_InitStruct.Pull = GPIO_NOPULL; +// GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; +// HAL_GPIO_Init(Light_GPIO_Port, &GPIO_InitStruct); GPIO_InitStruct.Pin = KEY1_Pin|KEY2_Pin; GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING; diff --git a/targets/STM32L431_BearPi/Src/stm32l4xx_it.c b/targets/STM32L431_BearPi/Src/stm32l4xx_it.c index 1a81c27fb..c7f3b0863 100644 --- a/targets/STM32L431_BearPi/Src/stm32l4xx_it.c +++ b/targets/STM32L431_BearPi/Src/stm32l4xx_it.c @@ -222,6 +222,21 @@ void Key2_IRQHandler(void *args) /* USER CODE END EXTI3_IRQn 1 */ } +/** + * @brief This function handles EXTI line[9:5] interrupts. + */ +//void EXTI9_5_IRQHandler(void) +void Infrared_IRQHandler(void *args) +{ + /* USER CODE BEGIN EXTI9_5_IRQn 0 */ + + /* USER CODE END EXTI9_5_IRQn 0 */ + HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_9); + /* USER CODE BEGIN EXTI9_5_IRQn 1 */ + + /* USER CODE END EXTI9_5_IRQn 1 */ +} + /** * @brief This function handles USART1 global interrupt. */ diff --git a/targets/STM32L431_BearPi_OS_Func/Demos/hello_world_demo/defaults.sdkconfig b/targets/STM32L431_BearPi_OS_Func/Demos/hello_world_demo/defaults.sdkconfig index 16840899c..d72b4269c 100644 --- a/targets/STM32L431_BearPi_OS_Func/Demos/hello_world_demo/defaults.sdkconfig +++ b/targets/STM32L431_BearPi_OS_Func/Demos/hello_world_demo/defaults.sdkconfig @@ -39,5 +39,7 @@ CONFIG_OC_LWM2M_TYPE = "none" CONFIG_LOADER_ENABLE = n CONFIG_OC_LWM2M_DEMO_TYPE= "none" CONFIG_OC_MQTT_DEMO_TYPE= "none" +CONFIG_DEMO_ENABLE= y +CONFIG_DEMO_TYPE= "none" CONFIG_USER_DEMO = "hello_world_demo" \ No newline at end of file diff --git a/targets/STM32L431_BearPi_OS_Func/Demos/osal_mem_demo/defaults.sdkconfig b/targets/STM32L431_BearPi_OS_Func/Demos/osal_mem_demo/defaults.sdkconfig index 19070ed79..15a575528 100644 --- a/targets/STM32L431_BearPi_OS_Func/Demos/osal_mem_demo/defaults.sdkconfig +++ b/targets/STM32L431_BearPi_OS_Func/Demos/osal_mem_demo/defaults.sdkconfig @@ -39,5 +39,7 @@ CONFIG_OC_LWM2M_TYPE = "none" CONFIG_LOADER_ENABLE = n CONFIG_OC_LWM2M_DEMO_TYPE= "none" CONFIG_OC_MQTT_DEMO_TYPE= "none" +CONFIG_DEMO_ENABLE= y +CONFIG_DEMO_TYPE= "none" CONFIG_USER_DEMO = "osal_mem_demo" \ No newline at end of file diff --git a/targets/STM32L431_BearPi_OS_Func/Demos/osal_mutex_demo/defaults.sdkconfig b/targets/STM32L431_BearPi_OS_Func/Demos/osal_mutex_demo/defaults.sdkconfig index 5932ddb47..4a02b9d66 100644 --- a/targets/STM32L431_BearPi_OS_Func/Demos/osal_mutex_demo/defaults.sdkconfig +++ b/targets/STM32L431_BearPi_OS_Func/Demos/osal_mutex_demo/defaults.sdkconfig @@ -39,5 +39,7 @@ CONFIG_OC_LWM2M_TYPE = "none" CONFIG_LOADER_ENABLE = n CONFIG_OC_LWM2M_DEMO_TYPE= "none" CONFIG_OC_MQTT_DEMO_TYPE= "none" +CONFIG_DEMO_ENABLE= y +CONFIG_DEMO_TYPE= "none" CONFIG_USER_DEMO = "osal_mutex_demo" \ No newline at end of file diff --git a/targets/STM32L431_BearPi_OS_Func/Demos/osal_semp_demo/defaults.sdkconfig b/targets/STM32L431_BearPi_OS_Func/Demos/osal_semp_demo/defaults.sdkconfig index 28b10e079..9724dc003 100644 --- a/targets/STM32L431_BearPi_OS_Func/Demos/osal_semp_demo/defaults.sdkconfig +++ b/targets/STM32L431_BearPi_OS_Func/Demos/osal_semp_demo/defaults.sdkconfig @@ -39,5 +39,7 @@ CONFIG_OC_LWM2M_TYPE = "none" CONFIG_LOADER_ENABLE = n CONFIG_OC_LWM2M_DEMO_TYPE= "none" CONFIG_OC_MQTT_DEMO_TYPE= "none" +CONFIG_DEMO_ENABLE= y +CONFIG_DEMO_TYPE= "none" CONFIG_USER_DEMO = "osal_semp_demo" \ No newline at end of file diff --git a/targets/STM32L431_BearPi_OS_Func/Demos/osal_task_demo/defaults.sdkconfig b/targets/STM32L431_BearPi_OS_Func/Demos/osal_task_demo/defaults.sdkconfig index 3a80bd249..35e7dbda2 100644 --- a/targets/STM32L431_BearPi_OS_Func/Demos/osal_task_demo/defaults.sdkconfig +++ b/targets/STM32L431_BearPi_OS_Func/Demos/osal_task_demo/defaults.sdkconfig @@ -39,5 +39,7 @@ CONFIG_OC_LWM2M_TYPE = "none" CONFIG_LOADER_ENABLE = n CONFIG_OC_LWM2M_DEMO_TYPE= "none" CONFIG_OC_MQTT_DEMO_TYPE= "none" +CONFIG_DEMO_ENABLE= y +CONFIG_DEMO_TYPE= "none" CONFIG_USER_DEMO = "osal_task_demo" \ No newline at end of file diff --git a/targets/STM32L431_BearPi_OS_Func/Demos/user_demo.mk b/targets/STM32L431_BearPi_OS_Func/Demos/user_demo.mk index 961b6a7af..f614bb884 100644 --- a/targets/STM32L431_BearPi_OS_Func/Demos/user_demo.mk +++ b/targets/STM32L431_BearPi_OS_Func/Demos/user_demo.mk @@ -7,7 +7,6 @@ #example for LiteOS func ifeq ($(CONFIG_DEMO_TYPE), "none") - CONFIG_USER_DEMO := "hello_world_demo" #example for hello world ifeq ($(CONFIG_USER_DEMO), "hello_world_demo") diff --git a/targets/STM32L431_BearPi_OS_Func/GCC/config.mk b/targets/STM32L431_BearPi_OS_Func/GCC/config.mk index 00bd3bc80..34ca5660d 100644 --- a/targets/STM32L431_BearPi_OS_Func/GCC/config.mk +++ b/targets/STM32L431_BearPi_OS_Func/GCC/config.mk @@ -166,5 +166,11 @@ CONFIG_DEMO_TYPE := "none" #########################STANDARD DEMO END###################################### +########################BearPi-IoT OSAL DEMO START##################################### +#CONFIG_USER_DEMO could be "hello_world_demo" "osal_task_demo" "osal_mem_demo" "osal_semp_demo" "osal_mutex_demo" + +CONFIG_USER_DEMO := "hello_world_demo" + +#########################BearPi-IoT OSAL DEMO END###################################### diff --git a/tools/ota_tool/meta/ota_tool/ota_image_001.png b/tools/ota_tool/meta/ota_tool/ota_image_001.png new file mode 100644 index 000000000..295ee9b50 Binary files /dev/null and b/tools/ota_tool/meta/ota_tool/ota_image_001.png differ diff --git a/tools/ota_tool/meta/ota_tool/ota_image_002.png b/tools/ota_tool/meta/ota_tool/ota_image_002.png new file mode 100644 index 000000000..6c148ee21 Binary files /dev/null and b/tools/ota_tool/meta/ota_tool/ota_image_002.png differ diff --git a/tools/ota_tool/meta/ota_tool/ota_image_003.png b/tools/ota_tool/meta/ota_tool/ota_image_003.png new file mode 100644 index 000000000..50720b069 Binary files /dev/null and b/tools/ota_tool/meta/ota_tool/ota_image_003.png differ diff --git a/tools/ota_tool/meta/ota_tool/ota_image_004.png b/tools/ota_tool/meta/ota_tool/ota_image_004.png new file mode 100644 index 000000000..4b091508c Binary files /dev/null and b/tools/ota_tool/meta/ota_tool/ota_image_004.png differ diff --git a/tools/ota_tool/meta/ota_tool/ota_image_005.png b/tools/ota_tool/meta/ota_tool/ota_image_005.png new file mode 100644 index 000000000..a0afc2bc3 Binary files /dev/null and b/tools/ota_tool/meta/ota_tool/ota_image_005.png differ diff --git a/tools/ota_tool/meta/ota_tool/ota_image_006.png b/tools/ota_tool/meta/ota_tool/ota_image_006.png new file mode 100644 index 000000000..46dde0bde Binary files /dev/null and b/tools/ota_tool/meta/ota_tool/ota_image_006.png differ diff --git a/tools/ota_tool/meta/ota_tool/ota_image_007.png b/tools/ota_tool/meta/ota_tool/ota_image_007.png new file mode 100644 index 000000000..21e39654f Binary files /dev/null and b/tools/ota_tool/meta/ota_tool/ota_image_007.png differ diff --git a/tools/ota_tool/meta/ota_tool/ota_image_008.png b/tools/ota_tool/meta/ota_tool/ota_image_008.png new file mode 100644 index 000000000..9327f7d23 Binary files /dev/null and b/tools/ota_tool/meta/ota_tool/ota_image_008.png differ diff --git a/tools/ota_tool/meta/ota_tool/ota_image_009.png b/tools/ota_tool/meta/ota_tool/ota_image_009.png new file mode 100644 index 000000000..ceb823235 Binary files /dev/null and b/tools/ota_tool/meta/ota_tool/ota_image_009.png differ diff --git a/tools/ota_tool/meta/ota_tool/ota_image_010.png b/tools/ota_tool/meta/ota_tool/ota_image_010.png new file mode 100644 index 000000000..8702e62d4 Binary files /dev/null and b/tools/ota_tool/meta/ota_tool/ota_image_010.png differ diff --git a/tools/ota_tool/meta/ota_tool/ota_image_011.png b/tools/ota_tool/meta/ota_tool/ota_image_011.png new file mode 100644 index 000000000..3ab4bff2b Binary files /dev/null and b/tools/ota_tool/meta/ota_tool/ota_image_011.png differ diff --git a/tools/ota_tool/meta/ota_tool/ota_image_012.png b/tools/ota_tool/meta/ota_tool/ota_image_012.png new file mode 100644 index 000000000..eb1eb111d Binary files /dev/null and b/tools/ota_tool/meta/ota_tool/ota_image_012.png differ diff --git a/tools/ota_tool/meta/ota_tool/ota_image_013.png b/tools/ota_tool/meta/ota_tool/ota_image_013.png new file mode 100644 index 000000000..041e68c58 Binary files /dev/null and b/tools/ota_tool/meta/ota_tool/ota_image_013.png differ diff --git a/tools/ota_tool/meta/ota_tool/ota_image_014.png b/tools/ota_tool/meta/ota_tool/ota_image_014.png new file mode 100644 index 000000000..26573b5d2 Binary files /dev/null and b/tools/ota_tool/meta/ota_tool/ota_image_014.png differ diff --git a/tools/ota_tool/meta/ota_tool/ota_image_015.png b/tools/ota_tool/meta/ota_tool/ota_image_015.png new file mode 100644 index 000000000..e1f327dae Binary files /dev/null and b/tools/ota_tool/meta/ota_tool/ota_image_015.png differ diff --git a/tools/ota_tool/meta/ota_tool/ota_image_016.png b/tools/ota_tool/meta/ota_tool/ota_image_016.png new file mode 100644 index 000000000..79cbf7949 Binary files /dev/null and b/tools/ota_tool/meta/ota_tool/ota_image_016.png differ diff --git a/tools/ota_tool/meta/ota_tool/ota_image_017.png b/tools/ota_tool/meta/ota_tool/ota_image_017.png new file mode 100644 index 000000000..137d30284 Binary files /dev/null and b/tools/ota_tool/meta/ota_tool/ota_image_017.png differ diff --git a/tools/ota_tool/meta/ota_tool/ota_image_018.png b/tools/ota_tool/meta/ota_tool/ota_image_018.png new file mode 100644 index 000000000..2ff78d51b Binary files /dev/null and b/tools/ota_tool/meta/ota_tool/ota_image_018.png differ diff --git a/tools/ota_tool/meta/ota_tool/ota_image_019.png b/tools/ota_tool/meta/ota_tool/ota_image_019.png new file mode 100644 index 000000000..1f304786e Binary files /dev/null and b/tools/ota_tool/meta/ota_tool/ota_image_019.png differ diff --git a/tools/ota_tool/meta/ota_tool/ota_image_020.png b/tools/ota_tool/meta/ota_tool/ota_image_020.png new file mode 100644 index 000000000..98bc2b0bc Binary files /dev/null and b/tools/ota_tool/meta/ota_tool/ota_image_020.png differ diff --git a/tools/ota_tool/ota_tool.zip b/tools/ota_tool/ota_tool.zip new file mode 100644 index 000000000..0ae239081 Binary files /dev/null and b/tools/ota_tool/ota_tool.zip differ diff --git a/tools/ota_tool/ota_tool_user_guide.md b/tools/ota_tool/ota_tool_user_guide.md new file mode 100644 index 000000000..be09f6912 --- /dev/null +++ b/tools/ota_tool/ota_tool_user_guide.md @@ -0,0 +1,131 @@ +# ota_tool使用说明 +## 目 录 + + +- [1 前言](#1) +- [2 差分包生成和还原](#2) + - [2.1 差分包生成](#2.1) + - [2.2 差分包还原](#2.2) +- [3 签名和验签](#3) + - [3.1 生成公私钥对](#3.1) + - [3.2 签名](#3.2) + - [3.3 验签](#3.3) + + +

1.前言

+ + ota_tool是一个差分包制作工具。该工具提供差分包的制作以及还原功能。提供差分包签名和签名验证功能。 + 参考[固件升级](https://support.huaweicloud.com/devg-IoT/iot_02_9984.html)和[软件升级](https://support.huaweicloud.com/devg-IoT/iot_02_9983.html),将ota_tool生成的签名后的差分包,制作成升级包进行升级。 + + github下载ota_tool. + + 地址:https://github.com/LiteOS/LiteOS_Lab/tree/iot_link/tool/ota_tool/ota_tool.zip + +注意:ota_tool当前版本只支持英文路径 + +

2.差分包生成和还原

+解压缩ota_tool.zip,打开ota_tool.exe + +![](./meta/ota_tool/ota_image_001.png) + +

2.1 差分包生成

+ +如果要制作差分包,文件类型选择 “差分”,必须提供软件的旧版本和新版本。 + +如果制作全量包,选择“全量”,只需要提供软件新版本。 + +单击[导入旧版本],在弹出的对话框中选择软件旧版本 + +![](./meta/ota_tool/ota_image_002.png) + +单击[导入新版本],在弹出的对话框中选择软件新版本 + +![](./meta/ota_tool/ota_image_003.png) + +单击[生成差分包],在弹出的对话话框中输入要保存的差分包名称 + +![](./meta/ota_tool/ota_image_004.png) + +单击[保存],弹出消息框单击[OK] + +![](./meta/ota_tool/ota_image_005.png) + +![](./meta/ota_tool/ota_image_006.png) + + +

2.2 差分包还原

+ +如果差分包的文件类型为“差分”,必须提供软件的旧版本和差分包。 + +如果差分包的文件类型为“全量”,只需要提供差分包。 + +单击[导入旧版本],在弹出的对话框中选择软件旧版本 + +![](./meta/ota_tool/ota_image_002.png) + +单击[导入差分包],在弹出的对话框中选择差分包 + +![](./meta/ota_tool/ota_image_007.png) + +单击[还原差分包],在弹出的对话话框中输入要保存的还原后文件名称 + +![](./meta/ota_tool/ota_image_008.png) + +单击[保存],弹出消息框单击[OK] + +![](./meta/ota_tool/ota_image_009.png) + +![](./meta/ota_tool/ota_image_010.png) + + +

3.签名和验签

+ +为了保证差分包不被第三方篡改数据,ota_tool提供差分包签名功能,在进行软固件升级时,设备需要对差分包进行验签。 + +ota_tool采用私钥签名,公钥验签模式。公钥私钥必须成对使用。 + +![](./meta/ota_tool/ota_image_011.png) + +

3.1 生成公私钥对

+ +单击[生成公私钥对],在弹出对对话框中选择保存公私钥目录,然后单击[选择文件夹] +公私钥钥对生成需要花费一两秒钟,请耐心等待生成结果。 + +![](./meta/ota_tool/ota_image_012.png) + +![](./meta/ota_tool/ota_image_013.png) + +![](./meta/ota_tool/ota_image_014.png) + +

3.2 签名

+ +单击[导入私钥文件],在弹出的对话框中选择签名用的私钥文件 + +![](./meta/ota_tool/ota_image_015.png) + +单击[导入待签名文件],在弹出的对话框中选择待签名差分文件 + +![](./meta/ota_tool/ota_image_016.png) + +单击[进行数字签名],签名后的文件如下。 + +![](./meta/ota_tool/ota_image_017.png) + + +

3.3 验签

+ +单击[导入公钥文件],在弹出的对话框中选择验签用的公钥文件 + +![](./meta/ota_tool/ota_image_018.png) + +单击[导入待验签文件],在弹出的对话框中选择待验签文件 + +![](./meta/ota_tool/ota_image_019.png) + +单击[进行签名验证],弹出验证结果对话框。 + +![](./meta/ota_tool/ota_image_020.png) + + + +