You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.8 KiB

  1. /*
  2. * This file is part of the coreboot project.
  3. *
  4. * Copyright 2015 Google Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; version 2 of the License.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #ifndef _COMMONLIB_CBFS_H_
  16. #define _COMMONLIB_CBFS_H_
  17. #include <commonlib/cbfs_serialized.h>
  18. #include <commonlib/region.h>
  19. #include <vb2_api.h>
  20. /* Object representing cbfs files. */
  21. struct cbfsf {
  22. struct region_device metadata;
  23. struct region_device data;
  24. };
  25. /* Locate file by name and optional type. Returns 0 on succcess else < 0 on
  26. * error.*/
  27. int cbfs_locate(struct cbfsf *fh, const struct region_device *cbfs,
  28. const char *name, uint32_t *type);
  29. static inline void cbfs_file_data(struct region_device *data,
  30. const struct cbfsf *file)
  31. {
  32. rdev_chain(data, &file->data, 0, region_device_sz(&file->data));
  33. }
  34. static inline void cbfs_file_metadata(struct region_device *metadata,
  35. const struct cbfsf *file)
  36. {
  37. rdev_chain(metadata, &file->metadata, 0,
  38. region_device_sz(&file->metadata));
  39. }
  40. /*
  41. * Provide a handle to each cbfs file within a cbfs. The prev pointer represents
  42. * the previous file (NULL on first invocation). The next object gets filled
  43. * out with the next file. This returns < 0 on error, 0 on finding the next
  44. * file, and > 0 at end of cbfs.
  45. */
  46. int cbfs_for_each_file(const struct region_device *cbfs,
  47. const struct cbfsf *prev, struct cbfsf *fh);
  48. /*
  49. * Return the offset for each CBFS attribute in a CBFS file metadata region.
  50. * The metadata must already be fully mapped by the caller. Will return the
  51. * offset (relative to the start of the metadata) or 0 when there are no
  52. * further attributes. Should be called with 0 to begin, then always with
  53. * the previously returned value until it returns 0.
  54. */
  55. size_t cbfs_for_each_attr(void *metadata, size_t metadata_size,
  56. size_t last_offset);
  57. /*
  58. * Find out the decompression algorithm and decompressed size of a non-stage
  59. * CBFS file (by parsing its metadata attributes), and return them with
  60. * out-parameters. Returns 0 on success and < 0 on error.
  61. */
  62. int cbfsf_decompression_info(struct cbfsf *fh, uint32_t *algo, size_t *size);
  63. /*
  64. * Perform the vb2 hash over the CBFS region skipping empty file contents.
  65. * Caller is responsible for providing the hash algorithm as well as storage
  66. * for the final digest. Return 0 on success or non-zero on error.
  67. */
  68. int cbfs_vb2_hash_contents(const struct region_device *cbfs,
  69. enum vb2_hash_algorithm hash_alg, void *digest,
  70. size_t digest_sz);
  71. #endif