[Feature]add MT2731_MP2_MR2_SVN388 baseline version
Change-Id: Ief04314834b31e27effab435d3ca8ba33b499059
diff --git a/src/lynq/lib/liblynq-fota/include/iot_rock.h b/src/lynq/lib/liblynq-fota/include/iot_rock.h
new file mode 100644
index 0000000..b87bf51
--- /dev/null
+++ b/src/lynq/lib/liblynq-fota/include/iot_rock.h
@@ -0,0 +1,121 @@
+#ifndef _IOT_ROCK_H_
+#define _IOT_ROCK_H_
+
+/* public */
+
+#define E_ROCK_SUCCESS (0)
+#define E_ROCK_INVALID_DELTA (-1)
+#define E_ROCK_DELTA_MISMATCH (-2)
+#define E_ROCK_DELTA_CHUNK_MISMATCH (-3)
+#define E_ROCK_READ_DELTA_ERROR (-4)
+#define E_ROCK_READ_BLOCK_ERROR (-11)
+#define E_ROCK_WRITE_BLOCK_ERROR (-12)
+#define E_ROCK_RAM_NOT_ENOUGH (-20)
+#define E_ROCK_INVALID_CTX (-30)
+
+
+#define PATCH_SYSTEM (1)
+#define PATCH_BOOT (2)
+#define PATCH_TEE (3)
+#define PATCH_MD1IMG (4)
+#define PATCH_VBMETA (5)
+#define PATCH_BL33 (6)
+#define FULL_SYSTEM (7)
+#define FULL_BOOT (8)
+#define FULL_TEE (9)
+#define FULL_MD1IMG (10)
+#define FULL_VBMETA (11)
+#define FULL_BL33 (12)
+
+#define MAX_OTA_ROLE (12)
+
+
+
+#define MODE_NORMAL 0
+#define MODE_A2B 1
+#define MODE_B2A 2
+
+#define WAIT 0xff
+#define PASS 0
+#define ERROR -1
+
+typedef struct {
+ void* user_context;
+ unsigned int rom_base; // old rom start
+ unsigned char* ram_base; // ram working buffer start
+ unsigned int ram_len; // ram working buffer len
+
+ unsigned int backup_base; // ram backup storage start
+ unsigned int backup_len; // ram backup storage len
+
+ unsigned int update_nvram; // nvram update flag
+
+ int read_rom_directly;
+ int first_run;
+} IOT_UPDATA_CONTEXT;
+
+
+typedef struct {
+ unsigned int sys; //system 差分包大小
+ unsigned int boot; //boot 差分包大小
+ unsigned int tee; //tee 差分包大小
+ unsigned int md1img; //md1img 差分包大小
+ unsigned int vbmeta; //vbmeta 差分包大小
+ unsigned int bl33; //bl33 差分包大小
+ unsigned int full_sys; //system 整包大小
+ unsigned int full_boot; //boot
+ unsigned int full_tee; //tee 整包大小
+ unsigned int full_md1img; // 整包大小
+ unsigned int full_vbmeta; //vbmeta 整包大小
+ unsigned int full_bl33; //bl33 整包大小
+} DELTA_HEAD;
+
+typedef struct {
+
+ char fota_flag[32]; //fota 标志保留
+ int update_result; //升级结果
+ int ota_run; //
+ char cid[32];
+ char did[32];
+} UPDATE_INFO;
+
+
+typedef struct {
+ int need_update;
+ int check_delta;
+ int check_rom;
+ int update_result;
+
+} UPDATE_STATUS;
+
+
+typedef struct {
+ int ota_run;
+ UPDATE_STATUS update_status[MAX_OTA_ROLE];
+ int update_result;
+ int switch_slot;
+
+} OTA_STATUS;
+
+
+
+
+
+//#define DELTA_HEARD_SIZE (4*5)
+
+#define DELTA_HEARD_SIZE (4*6 + 4*6)
+#define DELTA_FULL_HEARD_SIZE 8
+
+
+
+int iot_patch(IOT_UPDATA_CONTEXT* update_ctx);
+
+unsigned int iot_hash(unsigned char *buf,unsigned int len, unsigned int* value);
+int lynq_md5_file_verfy(char* filePath, char* file_md5);
+//int md5_file_verfy_new(char* filePath, char* file_md5,int packe_len);
+int lynq_rock_main(int first_run);
+int lynq_fota_func(void);
+#endif
+
+
+
diff --git a/src/lynq/lib/liblynq-fota/include/iot_rock_ipl.h b/src/lynq/lib/liblynq-fota/include/iot_rock_ipl.h
new file mode 100644
index 0000000..77c7c2a
--- /dev/null
+++ b/src/lynq/lib/liblynq-fota/include/iot_rock_ipl.h
@@ -0,0 +1,22 @@
+#ifndef _IOT_ROCK_IPL_H_
+#define _IOT_ROCK_IPL_H_
+
+void rock_trace(void* ctx, const char* fmt, ...);
+void rock_progress(void* ctx, int percent);
+int rock_read_block(void* ctx, unsigned char* dest, unsigned int start, unsigned int size);
+int rock_read_delta(void* ctx, unsigned char* dest, unsigned int offset, unsigned int size);
+int rock_write_block(void* ctx, unsigned char* src, unsigned int start, unsigned int size);
+int rock_process_block(void* ctx, unsigned char* data, unsigned int start, unsigned int size);
+int rock_get_blocksize(void* ctx);
+
+int rock_read_file(void* ctx, void* name, unsigned char* dest, unsigned int offset, unsigned int size);
+int rock_write_file(void* ctx, void* name, unsigned char* src, unsigned int offset, unsigned int size);
+
+int rock_delete_file(void* ctx, void* name);
+
+int rock_fatal(void* ctx, int error_code);
+
+int rock_mismatch(void* ctx, unsigned char* buf, unsigned int start, unsigned int size,
+ unsigned int source_hash,unsigned int target_hash);
+#endif
+
diff --git a/src/lynq/lib/liblynq-fota/include/md5.h b/src/lynq/lib/liblynq-fota/include/md5.h
new file mode 100644
index 0000000..f0e3a1b
--- /dev/null
+++ b/src/lynq/lib/liblynq-fota/include/md5.h
@@ -0,0 +1,48 @@
+#ifndef MD5_H
+#define MD5_H
+
+typedef struct
+{
+ unsigned int count[2];
+ unsigned int state[4];
+ unsigned char buffer[64];
+}MD5_CTX;
+
+
+#define F(x,y,z) ((x & y) | (~x & z))
+#define G(x,y,z) ((x & z) | (y & ~z))
+#define H(x,y,z) (x^y^z)
+#define I(x,y,z) (y ^ (x | ~z))
+#define ROTATE_LEFT(x,n) ((x << n) | (x >> (32-n)))
+#define FF(a,b,c,d,x,s,ac) \
+{ \
+ a += F(b,c,d) + x + ac; \
+ a = ROTATE_LEFT(a,s); \
+ a += b; \
+}
+#define GG(a,b,c,d,x,s,ac) \
+{ \
+ a += G(b,c,d) + x + ac; \
+ a = ROTATE_LEFT(a,s); \
+ a += b; \
+}
+#define HH(a,b,c,d,x,s,ac) \
+{ \
+ a += H(b,c,d) + x + ac; \
+ a = ROTATE_LEFT(a,s); \
+ a += b; \
+}
+#define II(a,b,c,d,x,s,ac) \
+{ \
+ a += I(b,c,d) + x + ac; \
+ a = ROTATE_LEFT(a,s); \
+ a += b; \
+}
+void MD5Init(MD5_CTX *context);
+void MD5Update(MD5_CTX *context,unsigned char *input,unsigned int inputlen);
+void MD5Final(MD5_CTX *context,unsigned char digest[16]);
+void MD5Transform(unsigned int state[4],unsigned char block[64]);
+void MD5Encode(unsigned char *output,unsigned int *input,unsigned int len);
+void MD5Decode(unsigned int *output,unsigned char *input,unsigned int len);
+
+#endif
\ No newline at end of file
diff --git a/src/lynq/lib/liblynq-fota/include/md5_encode.h b/src/lynq/lib/liblynq-fota/include/md5_encode.h
new file mode 100644
index 0000000..d106eac
--- /dev/null
+++ b/src/lynq/lib/liblynq-fota/include/md5_encode.h
@@ -0,0 +1,33 @@
+#ifndef MD5_ENCODE_H_
+#define MD5_ENCODE_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+//打开文件
+int ota_file_open(char* path, char* flag);
+//文件偏移位置
+int ota_file_seek(int handle, int offset, int flag);
+//读文件内容
+int ota_file_read(char* buffer, size_t count, int file);
+//关闭文件
+void ota_file_close(int handle);
+
+
+/***
+ * @description: 校验文件的MD5
+ * @param filePath 文件路径
+ * @param file_md5 待校验MD5值
+ * @return 0:校验成功; 其他:校验失败
+ */
+int lynq_md5_file_verfy(char* filePath, char* file_md5);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif
diff --git a/src/lynq/lib/liblynq-fota/include/sha.h b/src/lynq/lib/liblynq-fota/include/sha.h
new file mode 100644
index 0000000..05f9941
--- /dev/null
+++ b/src/lynq/lib/liblynq-fota/include/sha.h
@@ -0,0 +1,75 @@
+/* sha.h
+**
+** Copyright 2008, The Android Open Source Project
+**
+** Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * 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.
+** * Neither the name of Google Inc. 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 Google Inc. ``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 Google Inc. 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.
+*/
+
+#ifndef _EMBEDDED_SHA_H_
+#define _EMBEDDED_SHA_H_
+
+#include <inttypes.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct SHA_CTX {
+ uint64_t count;
+ uint32_t state[5];
+#if defined(HAVE_ENDIAN_H) && defined(HAVE_LITTLE_ENDIAN)
+ union {
+ uint8_t b[64];
+ uint32_t w[16];
+ } buf;
+#else
+ uint8_t buf[64];
+#endif
+} SHA_CTX;
+
+void SHA_init(SHA_CTX* ctx);
+void SHA_update(SHA_CTX* ctx, const void* data, int len);
+const uint8_t* SHA_final(SHA_CTX* ctx);
+
+/* Convenience method. Returns digest parameter value. */
+const uint8_t* SHA(const void* data, int len, uint8_t* digest);
+
+#define SHA_DIGEST_SIZE 20
+
+typedef enum check_status_t{
+ ERROR_SHA = -3, // sha1输入参数错误
+ PATCH_ERR = -2, // 检测hash既不等于source_hash也不等于target_hash, 一般错误情况
+ NOT_EXIST_FILE = -1, // 检测文件不存在
+ SOURCE_SUCC = 0, // 检测hash等于目标source_hash, 一般正常情况
+ PATCH_SUCC = 1, // 检测hash等于目标target_hash, up to data
+}Check_status;
+
+int ParseSha1(const char* str, uint8_t* digest);
+
+const uint8_t* ROCK_SHA(const char *file_name, uint8_t *digest);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif