avb_verify: support using OP-TEE TA AVB
[oweals/u-boot.git] / include / avb_verify.h
1
2 /*
3  * (C) Copyright 2018, Linaro Limited
4  *
5  * SPDX-License-Identifier:     GPL-2.0+
6  */
7
8 #ifndef _AVB_VERIFY_H
9 #define _AVB_VERIFY_H
10
11 #include <../lib/libavb/libavb.h>
12 #include <mmc.h>
13
14 #define AVB_MAX_ARGS                    1024
15 #define VERITY_TABLE_OPT_RESTART        "restart_on_corruption"
16 #define VERITY_TABLE_OPT_LOGGING        "ignore_corruption"
17 #define ALLOWED_BUF_ALIGN               8
18
19 enum avb_boot_state {
20         AVB_GREEN,
21         AVB_YELLOW,
22         AVB_ORANGE,
23         AVB_RED,
24 };
25
26 struct AvbOpsData {
27         struct AvbOps ops;
28         int mmc_dev;
29         enum avb_boot_state boot_state;
30 #ifdef CONFIG_OPTEE_TA_AVB
31         struct udevice *tee;
32         u32 session;
33 #endif
34 };
35
36 struct mmc_part {
37         int dev_num;
38         struct mmc *mmc;
39         struct blk_desc *mmc_blk;
40         disk_partition_t info;
41 };
42
43 enum mmc_io_type {
44         IO_READ,
45         IO_WRITE
46 };
47
48 AvbOps *avb_ops_alloc(int boot_device);
49 void avb_ops_free(AvbOps *ops);
50
51 char *avb_set_state(AvbOps *ops, enum avb_boot_state boot_state);
52 char *avb_set_enforce_verity(const char *cmdline);
53 char *avb_set_ignore_corruption(const char *cmdline);
54
55 char *append_cmd_line(char *cmdline_orig, char *cmdline_new);
56
57 /**
58  * ============================================================================
59  * I/O helper inline functions
60  * ============================================================================
61  */
62 static inline uint64_t calc_offset(struct mmc_part *part, int64_t offset)
63 {
64         u64 part_size = part->info.size * part->info.blksz;
65
66         if (offset < 0)
67                 return part_size + offset;
68
69         return offset;
70 }
71
72 static inline size_t get_sector_buf_size(void)
73 {
74         return (size_t)CONFIG_FASTBOOT_BUF_SIZE;
75 }
76
77 static inline void *get_sector_buf(void)
78 {
79         return (void *)CONFIG_FASTBOOT_BUF_ADDR;
80 }
81
82 static inline bool is_buf_unaligned(void *buffer)
83 {
84         return (bool)((uintptr_t)buffer % ALLOWED_BUF_ALIGN);
85 }
86
87 static inline int get_boot_device(AvbOps *ops)
88 {
89         struct AvbOpsData *data;
90
91         if (ops) {
92                 data = ops->user_data;
93                 if (data)
94                         return data->mmc_dev;
95         }
96
97         return -1;
98 }
99
100 #endif /* _AVB_VERIFY_H */