blob: f04ecdb1a1f4f1e14c4c747aaee4f6ef3ba20390 [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>
Jens Wiklanderbbddbef2018-09-25 16:40:22 +020012#include <mapmem.h>
Igor Opaniuk3af30e42018-06-03 21:56:38 +030013#include <mmc.h>
14
Igor Opaniuk5d4fd872018-06-03 21:56:40 +030015#define AVB_MAX_ARGS 1024
16#define VERITY_TABLE_OPT_RESTART "restart_on_corruption"
17#define VERITY_TABLE_OPT_LOGGING "ignore_corruption"
18#define ALLOWED_BUF_ALIGN 8
19
Mingyen Hung6e468002023-01-04 23:43:04 -080020#ifdef CONFIG_AMLOGIC_MODIFY
21#ifndef CONFIG_AVB_BUF_SIZE
22#define CONFIG_AVB_BUF_SIZE CONFIG_FASTBOOT_BUF_SIZE
23#endif
24
25#ifndef CONFIG_AVB_BUF_ADDR
26#define CONFIG_AVB_BUF_ADDR CONFIG_FASTBOOT_BUF_ADDR
27#endif
28#endif
29
Igor Opaniuk5d4fd872018-06-03 21:56:40 +030030enum avb_boot_state {
31 AVB_GREEN,
32 AVB_YELLOW,
33 AVB_ORANGE,
34 AVB_RED,
35};
Igor Opaniuk3af30e42018-06-03 21:56:38 +030036
37struct AvbOpsData {
38 struct AvbOps ops;
39 int mmc_dev;
Igor Opaniuk5d4fd872018-06-03 21:56:40 +030040 enum avb_boot_state boot_state;
Jens Wiklander6663e072018-09-25 16:40:20 +020041#ifdef CONFIG_OPTEE_TA_AVB
42 struct udevice *tee;
43 u32 session;
44#endif
Igor Opaniuk3af30e42018-06-03 21:56:38 +030045};
46
47struct mmc_part {
48 int dev_num;
49 struct mmc *mmc;
50 struct blk_desc *mmc_blk;
Simon Glass05289792020-05-10 11:39:57 -060051 struct disk_partition info;
Igor Opaniuk3af30e42018-06-03 21:56:38 +030052};
53
54enum mmc_io_type {
55 IO_READ,
56 IO_WRITE
57};
58
59AvbOps *avb_ops_alloc(int boot_device);
60void avb_ops_free(AvbOps *ops);
61
Igor Opaniuk5d4fd872018-06-03 21:56:40 +030062char *avb_set_state(AvbOps *ops, enum avb_boot_state boot_state);
63char *avb_set_enforce_verity(const char *cmdline);
64char *avb_set_ignore_corruption(const char *cmdline);
65
66char *append_cmd_line(char *cmdline_orig, char *cmdline_new);
67
Igor Opaniuk3af30e42018-06-03 21:56:38 +030068/**
69 * ============================================================================
70 * I/O helper inline functions
71 * ============================================================================
72 */
73static inline uint64_t calc_offset(struct mmc_part *part, int64_t offset)
74{
75 u64 part_size = part->info.size * part->info.blksz;
76
77 if (offset < 0)
78 return part_size + offset;
79
80 return offset;
81}
82
83static inline size_t get_sector_buf_size(void)
84{
Usama Arife61b4152020-08-11 15:46:03 +010085 return (size_t)CONFIG_AVB_BUF_SIZE;
Igor Opaniuk3af30e42018-06-03 21:56:38 +030086}
87
88static inline void *get_sector_buf(void)
89{
Usama Arife61b4152020-08-11 15:46:03 +010090 return map_sysmem(CONFIG_AVB_BUF_ADDR, CONFIG_AVB_BUF_SIZE);
Igor Opaniuk3af30e42018-06-03 21:56:38 +030091}
92
93static inline bool is_buf_unaligned(void *buffer)
94{
95 return (bool)((uintptr_t)buffer % ALLOWED_BUF_ALIGN);
96}
97
98static inline int get_boot_device(AvbOps *ops)
99{
100 struct AvbOpsData *data;
101
102 if (ops) {
103 data = ops->user_data;
104 if (data)
105 return data->mmc_dev;
106 }
107
108 return -1;
109}
110
111#endif /* _AVB_VERIFY_H */