Igor Opaniuk | bb4aac4 | 2018-06-03 21:56:38 +0300 | [diff] [blame] | 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> |
Jens Wiklander | 179c1d8 | 2018-09-25 16:40:22 +0200 | [diff] [blame] | 12 | #include <mapmem.h> |
Igor Opaniuk | bb4aac4 | 2018-06-03 21:56:38 +0300 | [diff] [blame] | 13 | #include <mmc.h> |
| 14 | |
Igor Opaniuk | f0f3bfe | 2018-06-03 21:56:40 +0300 | [diff] [blame] | 15 | #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 | |
| 20 | enum avb_boot_state { |
| 21 | AVB_GREEN, |
| 22 | AVB_YELLOW, |
| 23 | AVB_ORANGE, |
| 24 | AVB_RED, |
| 25 | }; |
Igor Opaniuk | bb4aac4 | 2018-06-03 21:56:38 +0300 | [diff] [blame] | 26 | |
| 27 | struct AvbOpsData { |
| 28 | struct AvbOps ops; |
| 29 | int mmc_dev; |
Igor Opaniuk | f0f3bfe | 2018-06-03 21:56:40 +0300 | [diff] [blame] | 30 | enum avb_boot_state boot_state; |
Jens Wiklander | 838c70c | 2018-09-25 16:40:20 +0200 | [diff] [blame] | 31 | #ifdef CONFIG_OPTEE_TA_AVB |
| 32 | struct udevice *tee; |
| 33 | u32 session; |
| 34 | #endif |
Igor Opaniuk | bb4aac4 | 2018-06-03 21:56:38 +0300 | [diff] [blame] | 35 | }; |
| 36 | |
| 37 | struct mmc_part { |
| 38 | int dev_num; |
| 39 | struct mmc *mmc; |
| 40 | struct blk_desc *mmc_blk; |
Simon Glass | c1c4a8f | 2020-05-10 11:39:57 -0600 | [diff] [blame] | 41 | struct disk_partition info; |
Igor Opaniuk | bb4aac4 | 2018-06-03 21:56:38 +0300 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | enum mmc_io_type { |
| 45 | IO_READ, |
| 46 | IO_WRITE |
| 47 | }; |
| 48 | |
| 49 | AvbOps *avb_ops_alloc(int boot_device); |
| 50 | void avb_ops_free(AvbOps *ops); |
| 51 | |
Igor Opaniuk | f0f3bfe | 2018-06-03 21:56:40 +0300 | [diff] [blame] | 52 | char *avb_set_state(AvbOps *ops, enum avb_boot_state boot_state); |
| 53 | char *avb_set_enforce_verity(const char *cmdline); |
| 54 | char *avb_set_ignore_corruption(const char *cmdline); |
| 55 | |
| 56 | char *append_cmd_line(char *cmdline_orig, char *cmdline_new); |
| 57 | |
Igor Opaniuk | bb4aac4 | 2018-06-03 21:56:38 +0300 | [diff] [blame] | 58 | /** |
| 59 | * ============================================================================ |
| 60 | * I/O helper inline functions |
| 61 | * ============================================================================ |
| 62 | */ |
| 63 | static inline uint64_t calc_offset(struct mmc_part *part, int64_t offset) |
| 64 | { |
| 65 | u64 part_size = part->info.size * part->info.blksz; |
| 66 | |
| 67 | if (offset < 0) |
| 68 | return part_size + offset; |
| 69 | |
| 70 | return offset; |
| 71 | } |
| 72 | |
| 73 | static inline size_t get_sector_buf_size(void) |
| 74 | { |
| 75 | return (size_t)CONFIG_FASTBOOT_BUF_SIZE; |
| 76 | } |
| 77 | |
| 78 | static inline void *get_sector_buf(void) |
| 79 | { |
Jens Wiklander | 179c1d8 | 2018-09-25 16:40:22 +0200 | [diff] [blame] | 80 | return map_sysmem(CONFIG_FASTBOOT_BUF_ADDR, CONFIG_FASTBOOT_BUF_SIZE); |
Igor Opaniuk | bb4aac4 | 2018-06-03 21:56:38 +0300 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | static inline bool is_buf_unaligned(void *buffer) |
| 84 | { |
| 85 | return (bool)((uintptr_t)buffer % ALLOWED_BUF_ALIGN); |
| 86 | } |
| 87 | |
| 88 | static inline int get_boot_device(AvbOps *ops) |
| 89 | { |
| 90 | struct AvbOpsData *data; |
| 91 | |
| 92 | if (ops) { |
| 93 | data = ops->user_data; |
| 94 | if (data) |
| 95 | return data->mmc_dev; |
| 96 | } |
| 97 | |
| 98 | return -1; |
| 99 | } |
| 100 | |
| 101 | #endif /* _AVB_VERIFY_H */ |