blob: 2fb850044d952195a50f07295035dd51b6d5e4a3 [file] [log] [blame]
Igor Opaniuka14aa592024-02-09 20:20:40 +01001/* SPDX-License-Identifier: GPL-2.0+ */
Igor Opaniuk3af30e42018-06-03 21:56:38 +03002/*
3 * (C) Copyright 2018, Linaro Limited
Igor Opaniuk3af30e42018-06-03 21:56:38 +03004 */
5
6#ifndef _AVB_VERIFY_H
7#define _AVB_VERIFY_H
8
9#include <../lib/libavb/libavb.h>
Jens Wiklanderbbddbef2018-09-25 16:40:22 +020010#include <mapmem.h>
Igor Opaniuk3af30e42018-06-03 21:56:38 +030011#include <mmc.h>
12
Igor Opaniuk5d4fd872018-06-03 21:56:40 +030013#define AVB_MAX_ARGS 1024
14#define VERITY_TABLE_OPT_RESTART "restart_on_corruption"
15#define VERITY_TABLE_OPT_LOGGING "ignore_corruption"
16#define ALLOWED_BUF_ALIGN 8
17
18enum avb_boot_state {
19 AVB_GREEN,
20 AVB_YELLOW,
21 AVB_ORANGE,
22 AVB_RED,
23};
Igor Opaniuk3af30e42018-06-03 21:56:38 +030024
25struct AvbOpsData {
26 struct AvbOps ops;
27 int mmc_dev;
Igor Opaniuk5d4fd872018-06-03 21:56:40 +030028 enum avb_boot_state boot_state;
Jens Wiklander6663e072018-09-25 16:40:20 +020029#ifdef CONFIG_OPTEE_TA_AVB
30 struct udevice *tee;
31 u32 session;
32#endif
Igor Opaniuk3af30e42018-06-03 21:56:38 +030033};
34
35struct mmc_part {
36 int dev_num;
37 struct mmc *mmc;
38 struct blk_desc *mmc_blk;
Simon Glass05289792020-05-10 11:39:57 -060039 struct disk_partition info;
Igor Opaniuk3af30e42018-06-03 21:56:38 +030040};
41
42enum mmc_io_type {
43 IO_READ,
44 IO_WRITE
45};
46
47AvbOps *avb_ops_alloc(int boot_device);
48void avb_ops_free(AvbOps *ops);
49
Igor Opaniuk5d4fd872018-06-03 21:56:40 +030050char *avb_set_state(AvbOps *ops, enum avb_boot_state boot_state);
51char *avb_set_enforce_verity(const char *cmdline);
52char *avb_set_ignore_corruption(const char *cmdline);
53
54char *append_cmd_line(char *cmdline_orig, char *cmdline_new);
55
Igor Opaniuk3af30e42018-06-03 21:56:38 +030056/**
57 * ============================================================================
58 * I/O helper inline functions
59 * ============================================================================
60 */
61static inline uint64_t calc_offset(struct mmc_part *part, int64_t offset)
62{
63 u64 part_size = part->info.size * part->info.blksz;
64
65 if (offset < 0)
66 return part_size + offset;
67
68 return offset;
69}
70
71static inline size_t get_sector_buf_size(void)
72{
Usama Arife61b4152020-08-11 15:46:03 +010073 return (size_t)CONFIG_AVB_BUF_SIZE;
Igor Opaniuk3af30e42018-06-03 21:56:38 +030074}
75
76static inline void *get_sector_buf(void)
77{
Usama Arife61b4152020-08-11 15:46:03 +010078 return map_sysmem(CONFIG_AVB_BUF_ADDR, CONFIG_AVB_BUF_SIZE);
Igor Opaniuk3af30e42018-06-03 21:56:38 +030079}
80
81static inline bool is_buf_unaligned(void *buffer)
82{
83 return (bool)((uintptr_t)buffer % ALLOWED_BUF_ALIGN);
84}
85
86static inline int get_boot_device(AvbOps *ops)
87{
88 struct AvbOpsData *data;
89
90 if (ops) {
91 data = ops->user_data;
92 if (data)
93 return data->mmc_dev;
94 }
95
96 return -1;
97}
98
99#endif /* _AVB_VERIFY_H */