1 /*
2  * Copyright (C) 2015-2017 Alibaba Group Holding Limited
3  */
4 
5 #ifndef OTA_LIBC_H
6 #define OTA_LIBC_H
7 
8 #define ALIGN(x,a)                 (((x) + (a) - 1) & ~((a) - 1))
9 #define XZ_HEAP_ALIGNMENT          4
10 #define XZ_HEAP_BLK_HEAD_SIZE      ALIGN(sizeof(blk_head_t), XZ_HEAP_ALIGNMENT)
11 #define XZ_HEAP_BLK_MIN            ((XZ_HEAP_BLK_HEAD_SIZE) << 1)
12 #define XZ_HEAP_MAGIC              (0xF0000000)
13 
14 #define OTA_LOG_I(fmt, ...) printf("%d: "fmt"\r\n", __LINE__, ##__VA_ARGS__)
15 
16 #if defined __LINUX_HOST__
17 #include <stdint.h>
18 #include <stdlib.h>
19 #include <stdio.h>
20 #include <string.h>
21 #else
22 
23 #ifndef AOS_2ND_BOOT_NO_LDS
24 extern void *_rec_heap_start;
25 extern void *_rec_heap_len;
26 #define XZ_HEAP_BASE ((int)&_rec_heap_start)
27 #define XZ_HEAP_SIZE ((int)&_rec_heap_len)
28 #else
29 extern void *_rec_heap_start;
30 extern unsigned int _rec_heap_len;
31 #define XZ_HEAP_BASE ((unsigned int)_rec_heap_start)
32 #define XZ_HEAP_SIZE (_rec_heap_len)
33 #endif
34 
35 #define memset  ota_memset
36 #define memcpy  ota_memcpy
37 #define memcmp  ota_memcmp
38 #define memmove ota_memmove
39 #define strlen  ota_strlen
40 #define strcat  ota_strcat
41 
42 #define printf  ota_printf
43 #define malloc  ota_heap_malloc
44 #define free    ota_heap_free
45 
46 #define puts ota_puts
47 
48 #endif
49 
50 void *ota_memset(void *s, int c, unsigned int n);
51 void *ota_memcpy(void *dest, const void *src, unsigned int n);
52 int ota_memcmp(const void * buf1, const void * buf2, unsigned int count);
53 void *ota_memmove(void *dest, const void *src, unsigned int count);
54 unsigned int ota_strlen(char * str);
55 char *ota_strcat (char * dst, const char * src);
56 int ota_puts(const char *str);
57 int ota_printf(const char *format, ...);
58 void *ota_heap_malloc(unsigned int alloc_size);
59 void ota_heap_free(void *pfree);
60 
61 typedef struct {
62     unsigned short crc;
63 } CRC16_CTX;
64 
65 void crc16_init(CRC16_CTX *inContext);
66 void crc16_update(CRC16_CTX *inContext, const void *inSrc, long inLen);
67 void crc16_final(CRC16_CTX *inContext, unsigned short *outResult);
68 unsigned short crc16_computer(void *buf, long len);
69 #endif /* _OTA_LIBC_H_ */
70