zte's code,first commit
Change-Id: I9a04da59e459a9bc0d67f101f700d9d7dc8d681b
diff --git a/ap/lib/libupi/inc/common.h b/ap/lib/libupi/inc/common.h
new file mode 100644
index 0000000..a0b7864
--- /dev/null
+++ b/ap/lib/libupi/inc/common.h
@@ -0,0 +1,14 @@
+#ifndef COMMON_H
+#define COMMON_H
+
+#include "zxic_generic_interface.h"
+
+
+
+
+#define free_ptr(ptr) if(ptr != NULL) {ZXIC_Free(ptr); \
+ ptr = NULL;}
+
+
+
+#endif /*COMMON_H*/
diff --git a/ap/lib/libupi/inc/io_zxic.h b/ap/lib/libupi/inc/io_zxic.h
new file mode 100644
index 0000000..e2881bc
--- /dev/null
+++ b/ap/lib/libupi/inc/io_zxic.h
@@ -0,0 +1,9 @@
+#ifndef IO_ZXIC_H
+#define IO_ZXIC_H
+
+#include <ioapi.h>
+
+void fill_zxic_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
+
+#endif /*IO_ZXIC_H*/
+
diff --git a/ap/lib/libupi/inc/md5.h b/ap/lib/libupi/inc/md5.h
new file mode 100755
index 0000000..726520a
--- /dev/null
+++ b/ap/lib/libupi/inc/md5.h
@@ -0,0 +1,52 @@
+#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; \
+}
+
+//int get_md5_32(unsigned char *data, int len, unsigned char *digest);
+
+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
diff --git a/ap/lib/libupi/inc/patch.h b/ap/lib/libupi/inc/patch.h
new file mode 100644
index 0000000..b8ba945
--- /dev/null
+++ b/ap/lib/libupi/inc/patch.h
@@ -0,0 +1,38 @@
+#ifndef PATCH_H
+#define PATCH_H
+
+// Image patch chunk types
+#define CHUNK_NORMAL 0
+#define CHUNK_GZIP 1 // version 1 only
+#define CHUNK_DEFLATE 2 // version 2 only
+#define CHUNK_RAW 3 // version 2 only
+
+// The gzip header size is actually variable, but we currently don't
+// support gzipped data with any of the optional fields, so for now it
+// will always be ten bytes. See RFC 1952 for the definition of the
+// gzip format.
+#define GZIP_HEADER_LEN 10
+
+// The gzip footer size really is fixed.
+#define GZIP_FOOTER_LEN 8
+
+int lzma_decompress(unsigned char *data_in, unsigned char *cpage_out,
+ ssize_t srclen, ssize_t dstlen);
+
+int ApplyBSDiffPatch(const unsigned char *old_data, ssize_t old_size,
+ unsigned char *patch, ssize_t patch_size, ssize_t patch_offset,
+ unsigned char **new_data, ssize_t *new_size);
+
+int ApplyImagePatch(unsigned char *old_data, ssize_t old_size,
+ unsigned char *patch, ssize_t patch_size,
+ unsigned char **new_data, ssize_t *new_size,
+ int seg_num);
+
+int ApplyOverridePatch(const unsigned char* old_data, ssize_t old_size,
+ unsigned char* patch, ssize_t patch_size, ssize_t patch_offset,
+ unsigned char** new_data, ssize_t* new_size);
+
+unsigned char *lzma_decode(const char *file_name, size_t *out_sz);
+int lzma_encode(const char *in, ssize_t in_len, char *out_file);
+
+#endif /*PATCH_H*/
diff --git a/ap/lib/libupi/inc/utils.h b/ap/lib/libupi/inc/utils.h
new file mode 100644
index 0000000..9ca07d9
--- /dev/null
+++ b/ap/lib/libupi/inc/utils.h
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _BUILD_TOOLS_APPLYPATCH_UTILS_H
+#define _BUILD_TOOLS_APPLYPATCH_UTILS_H
+
+#include <sys/types.h>
+
+#include <stdio.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <err.h>
+#include <fcntl.h>
+
+#ifndef _WIN32
+#include <unistd.h>
+#endif
+
+#define free_ptr(ptr) if(ptr!=NULL)free(ptr);ptr=NULL;
+#define close_fp(fp) if(fp!=NULL)fclose(fp);fp=NULL;
+#define safe_free(x) do { if(x) {free(x); x=NULL;} } while(0)
+
+#define GOERR_IF_FAIL(x) do{if((x) < 0) goto out_error;}while(0)
+
+#define GOERR_IF_NOK(x) do{if((x) != 0) goto out_error;}while(0)
+
+typedef unsigned int uint32_t;
+typedef int int32_t;
+typedef unsigned char u_char;
+typedef unsigned char uint8_t;
+
+#define MIN(x,y) (((x)<(y)) ? (x) : (y))
+#define MAX(x,y) (((x)>(y)) ? (x) : (y))
+
+#define safe_free(x) do { if(x) {free(x); x=NULL;} } while(0)
+
+#define log(fmt, args...) do {printf("[%s:%d]"fmt"\n", __FUNCTION__, __LINE__, ##args);}while(0)
+#define LOGD(fmt, args...) do {printf("[%s:%d]"fmt"\n", __FUNCTION__, __LINE__, ##args);}while(0)
+#define LOGE(fmt, args...) do {printf("[%s:%d]"fmt"\n", __FUNCTION__, __LINE__, ##args);}while(0)
+
+#define GOERR_IF_FAIL(x) do{if((x) < 0) goto out_error;}while(0)
+
+unsigned char * readfile(const char *dir, const char *name, size_t *len);
+int write_file(FILE* fp, const void *buf, int count);
+
+void dump_data(const u_char* data, int n);
+uint32_t little_endian_offin(u_char *buf);
+void little_endian_offout(uint32_t x, u_char *buf);
+FILE* create_new_file(const char* name);
+char *dir_name(char * path);
+int write_file_by_path(const char*path, const char*value, int size);
+int read_file_by_path(const char*path, char*buf, int sz);
+
+// Read and write little-endian values of various sizes.
+
+void Write4(int value, FILE* f);
+void Write8(long long value, FILE* f);
+int Read2(void* p);
+int Read4(void* p);
+long long Read8(void* p);
+
+#endif // _BUILD_TOOLS_APPLYPATCH_UTILS_H
diff --git a/ap/lib/libupi/inc/zxic_generic_interface.h b/ap/lib/libupi/inc/zxic_generic_interface.h
new file mode 100644
index 0000000..c5dfaa1
--- /dev/null
+++ b/ap/lib/libupi/inc/zxic_generic_interface.h
@@ -0,0 +1,16 @@
+#ifndef ZXIC_GENERIC_INTERFACE_H
+#define ZXIC_GENERIC_INTERFACE_H
+
+void* ZXIC_Malloc(int size);
+
+void ZXIC_Free(void *ptr);
+
+void* ZXIC_Realloc(void *ptr, int size);
+
+void ZXIC_Log(const char *aFormat, ...);
+
+#define zlog(fmt, args...) \
+ do {ZXIC_Log("[%s-%d]: " fmt"\n", __FUNCTION__, __LINE__, ## args);} while (0)
+
+#endif /*ZXIC_GENERIC_INTERFACE_H*/
+
diff --git a/ap/lib/libupi/inc/zxic_img_interface.h b/ap/lib/libupi/inc/zxic_img_interface.h
new file mode 100644
index 0000000..be25285
--- /dev/null
+++ b/ap/lib/libupi/inc/zxic_img_interface.h
@@ -0,0 +1,13 @@
+#ifndef ZXIC_IMG_INTERFACE_H
+#define ZXIC_IMG_INTERFACE_H
+
+#include "zxic_types.h"
+
+int ZXIC_GetDeltaSize(void *user_data, zxic_u_int32_t *size);
+int ZXIC_GetDelta(void *user_data, unsigned char *buffer, zxic_u_int32_t start_address, zxic_u_int32_t size);
+int ZXIC_GetBlockSize(void *user_data, int *block_size);
+int ZXIC_ReadImage(void *user_data, unsigned char *buffer, zxic_u_int32_t start_address, zxic_u_int32_t size);
+int ZXIC_WriteBlock(void *user_data, zxic_u_int32_t start_address, unsigned char *buffer);
+
+#endif /*ZXIC_IMG_INTERFACE_H*/
+
diff --git a/ap/lib/libupi/inc/zxic_types.h b/ap/lib/libupi/inc/zxic_types.h
new file mode 100644
index 0000000..4a5be0f
--- /dev/null
+++ b/ap/lib/libupi/inc/zxic_types.h
@@ -0,0 +1,38 @@
+#ifndef ZXIC_TYPES_H
+#define ZXIC_TYPES_H
+
+typedef unsigned int zxic_u_int;
+
+typedef signed char zxic_int8_t;
+typedef unsigned char zxic_u_int8_t;
+typedef signed short zxic_int16_t;
+typedef unsigned short zxic_u_int16_t;
+typedef signed int zxic_int32_t;
+typedef unsigned int zxic_u_int32_t;
+typedef signed long long zxic_int64_t;
+typedef unsigned long long zxic_u_int64_t;
+/*
+#define ZXIC_FILEFUNC_MODE_READ (1)
+#define ZXIC_FILEFUNC_MODE_WRITE (2)
+#define ZXIC_FILEFUNC_MODE_READWRITE (4)
+
+#define ZXIC_FILEFUNC_MODE_CREATE (8)
+#define ZXIC_FILEFUNC_MODE_EXISTING (16)
+*/
+
+#define ZXIC_FILEFUNC_SEEK_CUR (1)
+#define ZXIC_FILEFUNC_SEEK_END (2)
+#define ZXIC_FILEFUNC_SEEK_SET (0)
+
+typedef enum
+{
+ ZXIC_FILEFUNC_FLAG_READ = 1,
+ ZXIC_FILEFUNC_FLAG_WRITE = 2,
+ ZXIC_FILEFUNC_FLAG_READWRITE = 4,
+
+ ZXIC_FILEFUNC_FLAG_CREATE = 8,
+ ZXIC_FILEFUNC_FLAG_EXISTING = 16
+} ZXIC_FILEFUNC_FLAG;
+
+#endif /*ZXIC_TYPES_H*/
+