1 /* 2 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 * Description: UPG lzma Interface Header. 15 */ 16 17 #ifndef UPG_LZMADEC_H 18 #define UPG_LZMADEC_H 19 20 #include <stdint.h> 21 #include "LzmaDec.h" 22 #include "upg_definitions.h" 23 #include "upg.h" 24 25 #ifdef __cplusplus 26 #if __cplusplus 27 extern "C" { 28 #endif 29 #endif 30 /* header: 5 bytes of LZMA properties and 8 bytes of uncompressed size */ 31 #define LZMA_HEAD_SIZE ((LZMA_PROPS_SIZE) + 8) /* 8: lzma解压算法固定长度 */ 32 #define LZMA_HEAD_ALIGN_SIZE ((LZMA_HEAD_SIZE) + 3) /* PROPS(5byte) + head(8byte) + fill_align(3byte) */ 33 #ifdef CONFIG_MIDDLEWARE_SUPPORT_UPG_COMPRESS_ENCRY 34 #define OUT_BUF_SIZE 0x4000 35 #else 36 #define OUT_BUF_SIZE 0x1000 37 #endif 38 #define IN_BUF_SIZE 0x1000 39 40 /* 本块数据解压处理结构体 */ 41 typedef struct { 42 uint8_t *inbuf; /* 暂存从压缩分区读取数据 */ 43 uint8_t *outbuf; /* 暂存写入运行分区的数据 */ 44 uint32_t write_pos; /* 写入outbuf缓冲区下标 */ 45 uint32_t in_size; /* 本次读取数据块,解压前数据长度 */ 46 } upg_lzma_buf_t; 47 48 typedef struct upg_lzma_decode2_data { 49 uint32_t image_id; 50 uint32_t in_offset; /* 已解压部分,解压前的总长度,用作当前待解压的下标 */ 51 uint32_t out_offset; /* 已解压部分,解压后的总长度,用作解压后写入flash的偏移 */ 52 uint32_t compress_len; /* 剩余待解压部分,解压前的总长度 */ 53 uint32_t decompress_len; /* 剩余待解压部分,解压后的总长度 */ 54 upg_lzma_buf_t buf; 55 } upg_lzma_decode2_data_t; 56 57 uint32_t upg_lzma_init(CLzmaDec *p, upg_lzma_decode2_data_t *val_data, const Byte *props, uint32_t props_len); 58 void upg_lzma_deinit(CLzmaDec *p, upg_lzma_decode2_data_t *val_data); 59 uint32_t upg_lzma_decode(CLzmaDec *p, upg_lzma_decode2_data_t *data, const upg_image_header_t *image); 60 errcode_t upg_resource_file_decode(CLzmaDec *p, upg_lzma_decode2_data_t *data, upg_resource_node_t *file_info); 61 62 #ifdef __cplusplus 63 #if __cplusplus 64 } 65 #endif 66 #endif 67 68 #endif /* UPG_LZMADEC_H */ 69