blob: 428c69a2bc361fa1d6e616d49950025961aa5279 [file] [log] [blame]
Igor Opaniukbb4aac42018-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
14#define ALLOWED_BUF_ALIGN 8
15
16struct AvbOpsData {
17 struct AvbOps ops;
18 int mmc_dev;
19};
20
21struct mmc_part {
22 int dev_num;
23 struct mmc *mmc;
24 struct blk_desc *mmc_blk;
25 disk_partition_t info;
26};
27
28enum mmc_io_type {
29 IO_READ,
30 IO_WRITE
31};
32
33AvbOps *avb_ops_alloc(int boot_device);
34void avb_ops_free(AvbOps *ops);
35
36/**
37 * ============================================================================
38 * I/O helper inline functions
39 * ============================================================================
40 */
41static inline uint64_t calc_offset(struct mmc_part *part, int64_t offset)
42{
43 u64 part_size = part->info.size * part->info.blksz;
44
45 if (offset < 0)
46 return part_size + offset;
47
48 return offset;
49}
50
51static inline size_t get_sector_buf_size(void)
52{
53 return (size_t)CONFIG_FASTBOOT_BUF_SIZE;
54}
55
56static inline void *get_sector_buf(void)
57{
58 return (void *)CONFIG_FASTBOOT_BUF_ADDR;
59}
60
61static inline bool is_buf_unaligned(void *buffer)
62{
63 return (bool)((uintptr_t)buffer % ALLOWED_BUF_ALIGN);
64}
65
66static inline int get_boot_device(AvbOps *ops)
67{
68 struct AvbOpsData *data;
69
70 if (ops) {
71 data = ops->user_data;
72 if (data)
73 return data->mmc_dev;
74 }
75
76 return -1;
77}
78
79#endif /* _AVB_VERIFY_H */