• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #define FS_HVB_AB_SUFFIX_LEN 2
50 
51 typedef struct {
52     uint32_t magicNumber;
53     uint16_t exthdrSize;
54     uint16_t bcc16;
55     uint64_t partSize;
56 } ExtheaderV1;
57 
58 typedef enum InitHvbType {
59     MAIN_HVB = 0,
60     EXT_HVB
61 } InitHvbType;
62 
63 typedef struct {
64     char *partitionName;
65     char *pathName;
66 } ExtHvbVerifiedDev;
67 
68 int FsHvbInit(InitHvbType hvbType);
69 int FsHvbSetupHashtree(FstabItem *fsItem);
70 int FsHvbFinal(InitHvbType hvbType);
71 struct hvb_ops *FsHvbGetOps(void);
72 int FsHvbGetValueFromCmdLine(char *val, size_t size, const char *key);
73 int FsHvbConstructVerityTarget(DmVerityTarget *target, const char *devName, struct hvb_cert *cert);
74 void FsHvbDestoryVerityTarget(DmVerityTarget *target);
75 int VerifyExtHvbImage(const char *devPath, const char *partition, char **outPath);
76 
77 bool CheckAndGetExt4Size(const char *headerBuf, uint64_t *imageSize, const char* image);
78 bool CheckAndGetErofsSize(const char *headerBuf, uint64_t *imageSize, const char* image);
79 bool CheckAndGetExtheaderSize(const int fd, uint64_t offset, uint64_t *imageSize, const char* image);
80 
81 #ifdef __cplusplus
82 #if __cplusplus
83 }
84 #endif
85 #endif
86 
87 #endif // STARTUP_LIBFS_HVB_H
88