avb_verify.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * (C) Copyright 2018, Linaro Limited
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #ifndef _AVB_VERIFY_H
  7. #define _AVB_VERIFY_H
  8. #include <../lib/libavb/libavb.h>
  9. #include <mapmem.h>
  10. #include <mmc.h>
  11. #define AVB_MAX_ARGS 1024
  12. #define VERITY_TABLE_OPT_RESTART "restart_on_corruption"
  13. #define VERITY_TABLE_OPT_LOGGING "ignore_corruption"
  14. #define ALLOWED_BUF_ALIGN 8
  15. enum avb_boot_state {
  16. AVB_GREEN,
  17. AVB_YELLOW,
  18. AVB_ORANGE,
  19. AVB_RED,
  20. };
  21. struct AvbOpsData {
  22. struct AvbOps ops;
  23. int mmc_dev;
  24. enum avb_boot_state boot_state;
  25. #ifdef CONFIG_OPTEE_TA_AVB
  26. struct udevice *tee;
  27. u32 session;
  28. #endif
  29. };
  30. struct mmc_part {
  31. int dev_num;
  32. struct mmc *mmc;
  33. struct blk_desc *mmc_blk;
  34. disk_partition_t info;
  35. };
  36. enum mmc_io_type {
  37. IO_READ,
  38. IO_WRITE
  39. };
  40. AvbOps *avb_ops_alloc(int boot_device);
  41. void avb_ops_free(AvbOps *ops);
  42. char *avb_set_state(AvbOps *ops, enum avb_boot_state boot_state);
  43. char *avb_set_enforce_verity(const char *cmdline);
  44. char *avb_set_ignore_corruption(const char *cmdline);
  45. char *append_cmd_line(char *cmdline_orig, char *cmdline_new);
  46. /**
  47. * ============================================================================
  48. * I/O helper inline functions
  49. * ============================================================================
  50. */
  51. static inline uint64_t calc_offset(struct mmc_part *part, int64_t offset)
  52. {
  53. u64 part_size = part->info.size * part->info.blksz;
  54. if (offset < 0)
  55. return part_size + offset;
  56. return offset;
  57. }
  58. static inline size_t get_sector_buf_size(void)
  59. {
  60. return (size_t)CONFIG_FASTBOOT_BUF_SIZE;
  61. }
  62. static inline void *get_sector_buf(void)
  63. {
  64. return map_sysmem(CONFIG_FASTBOOT_BUF_ADDR, CONFIG_FASTBOOT_BUF_SIZE);
  65. }
  66. static inline bool is_buf_unaligned(void *buffer)
  67. {
  68. return (bool)((uintptr_t)buffer % ALLOWED_BUF_ALIGN);
  69. }
  70. static inline int get_boot_device(AvbOps *ops)
  71. {
  72. struct AvbOpsData *data;
  73. if (ops) {
  74. data = ops->user_data;
  75. if (data)
  76. return data->mmc_dev;
  77. }
  78. return -1;
  79. }
  80. #endif /* _AVB_VERIFY_H */