Merge branch 'master' of git://git.denx.de/u-boot-sh
[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 };
31
32 struct mmc_part {
33         int dev_num;
34         struct mmc *mmc;
35         struct blk_desc *mmc_blk;
36         disk_partition_t info;
37 };
38
39 enum mmc_io_type {
40         IO_READ,
41         IO_WRITE
42 };
43
44 AvbOps *avb_ops_alloc(int boot_device);
45 void avb_ops_free(AvbOps *ops);
46
47 char *avb_set_state(AvbOps *ops, enum avb_boot_state boot_state);
48 char *avb_set_enforce_verity(const char *cmdline);
49 char *avb_set_ignore_corruption(const char *cmdline);
50
51 char *append_cmd_line(char *cmdline_orig, char *cmdline_new);
52
53 /**
54  * ============================================================================
55  * I/O helper inline functions
56  * ============================================================================
57  */
58 static inline uint64_t calc_offset(struct mmc_part *part, int64_t offset)
59 {
60         u64 part_size = part->info.size * part->info.blksz;
61
62         if (offset < 0)
63                 return part_size + offset;
64
65         return offset;
66 }
67
68 static inline size_t get_sector_buf_size(void)
69 {
70         return (size_t)CONFIG_FASTBOOT_BUF_SIZE;
71 }
72
73 static inline void *get_sector_buf(void)
74 {
75         return (void *)CONFIG_FASTBOOT_BUF_ADDR;
76 }
77
78 static inline bool is_buf_unaligned(void *buffer)
79 {
80         return (bool)((uintptr_t)buffer % ALLOWED_BUF_ALIGN);
81 }
82
83 static inline int get_boot_device(AvbOps *ops)
84 {
85         struct AvbOpsData *data;
86
87         if (ops) {
88                 data = ops->user_data;
89                 if (data)
90                         return data->mmc_dev;
91         }
92
93         return -1;
94 }
95
96 #endif /* _AVB_VERIFY_H */