1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 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 */ 15 16 #ifndef STARTUP_LIBFS_HVB_H 17 #define STARTUP_LIBFS_HVB_H 18 19 #include <stdbool.h> 20 #include <stdio.h> 21 #include <stdint.h> 22 #include <hvb.h> 23 #include <hvb_cert.h> 24 #include "fs_dm.h" 25 #include "fs_manager.h" 26 #include "ext4_super_block.h" 27 #include "erofs_super_block.h" 28 29 #ifdef __cplusplus 30 #if __cplusplus 31 extern "C" { 32 #endif 33 #endif 34 35 #define USE_FEC_FROM_DEVICE "use_fec_from_device" 36 #define FEC_ROOTS "fec_roots" 37 #define FEC_BLOCKS "fec_blocks" 38 #define FEC_START "fec_start" 39 #define BLOCK_SIZE_UINT 4096 40 #define EXTHDR_MAGIC 0xFEEDBEEF 41 #define EXTHDR_BLKSIZ 4096 42 #define SZ_1KB (0x1 << 10) 43 #define SZ_1MB (0x1 << 20) 44 #define SZ_1GB (0x1 << 30) 45 46 #define SZ_2KB (2 * SZ_1KB) 47 #define SZ_4KB (4 * SZ_1KB) 48 #define FS_HVB_MAX_PATH_LEN 128 49 50 typedef struct { 51 uint32_t magicNumber; 52 uint16_t exthdrSize; 53 uint16_t bcc16; 54 uint64_t partSize; 55 } ExtheaderV1; 56 57 typedef enum InitHvbType { 58 MAIN_HVB = 0, 59 EXT_HVB 60 } InitHvbType; 61 62 typedef struct { 63 char *partitionName; 64 char *pathName; 65 } ExtHvbVerifiedDev; 66 67 int FsHvbInit(InitHvbType hvbType); 68 int FsHvbSetupHashtree(FstabItem *fsItem); 69 int FsHvbFinal(InitHvbType hvbType); 70 struct hvb_ops *FsHvbGetOps(void); 71 int FsHvbGetValueFromCmdLine(char *val, size_t size, const char *key); 72 int FsHvbConstructVerityTarget(DmVerityTarget *target, const char *devName, struct hvb_cert *cert); 73 void FsHvbDestoryVerityTarget(DmVerityTarget *target); 74 int VerifyExtHvbImage(const char *devPath, const char *partition, char **outPath); 75 76 bool CheckAndGetExt4Size(const char *headerBuf, uint64_t *imageSize, const char* image); 77 bool CheckAndGetErofsSize(const char *headerBuf, uint64_t *imageSize, const char* image); 78 bool CheckAndGetExtheaderSize(const int fd, uint64_t offset, uint64_t *imageSize, const char* image); 79 80 #ifdef __cplusplus 81 #if __cplusplus 82 } 83 #endif 84 #endif 85 86 #endif // STARTUP_LIBFS_HVB_H 87