blob: a532a2331aea9a6c03d2cb42420546593bbe363d [file] [log] [blame]
Igor Opaniuk3af30e42018-06-03 21:56:38 +03001
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
Igor Opaniuk5d4fd872018-06-03 21:56:40 +030014#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
19enum avb_boot_state {
20 AVB_GREEN,
21 AVB_YELLOW,
22 AVB_ORANGE,
23 AVB_RED,
24};
Igor Opaniuk3af30e42018-06-03 21:56:38 +030025
26struct AvbOpsData {
27 struct AvbOps ops;
28 int mmc_dev;
Igor Opaniuk5d4fd872018-06-03 21:56:40 +030029 enum avb_boot_state boot_state;
Jens Wiklander6663e072018-09-25 16:40:20 +020030#ifdef CONFIG_OPTEE_TA_AVB
31 struct udevice *tee;
32 u32 session;
33#endif
Igor Opaniuk3af30e42018-06-03 21:56:38 +030034};
35
36struct mmc_part {
37 int dev_num;
38 struct mmc *mmc;
39 struct blk_desc *mmc_blk;
40 disk_partition_t info;
41};
42
43enum mmc_io_type {
44 IO_READ,
45 IO_WRITE
46};
47
48AvbOps *avb_ops_alloc(int boot_device);
49void avb_ops_free(AvbOps *ops);
50
Igor Opaniuk5d4fd872018-06-03 21:56:40 +030051char *avb_set_state(AvbOps *ops, enum avb_boot_state boot_state);
52char *avb_set_enforce_verity(const char *cmdline);
53char *avb_set_ignore_corruption(const char *cmdline);
54
55char *append_cmd_line(char *cmdline_orig, char *cmdline_new);
56
Igor Opaniuk3af30e42018-06-03 21:56:38 +030057/**
58 * ============================================================================
59 * I/O helper inline functions
60 * ============================================================================
61 */
62static 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
72static inline size_t get_sector_buf_size(void)
73{
74 return (size_t)CONFIG_FASTBOOT_BUF_SIZE;
75}
76
77static inline void *get_sector_buf(void)
78{
79 return (void *)CONFIG_FASTBOOT_BUF_ADDR;
80}
81
82static inline bool is_buf_unaligned(void *buffer)
83{
84 return (bool)((uintptr_t)buffer % ALLOWED_BUF_ALIGN);
85}
86
87static 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 */