image-sparse.h 823 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright 2014 Broadcom Corporation.
  4. */
  5. #include <part.h>
  6. #include <sparse_format.h>
  7. #define ROUNDUP(x, y) (((x) + ((y) - 1)) & ~((y) - 1))
  8. struct sparse_storage {
  9. lbaint_t blksz;
  10. lbaint_t start;
  11. lbaint_t size;
  12. void *priv;
  13. lbaint_t (*write)(struct sparse_storage *info,
  14. lbaint_t blk,
  15. lbaint_t blkcnt,
  16. const void *buffer);
  17. lbaint_t (*reserve)(struct sparse_storage *info,
  18. lbaint_t blk,
  19. lbaint_t blkcnt);
  20. };
  21. static inline int is_sparse_image(void *buf)
  22. {
  23. sparse_header_t *s_header = (sparse_header_t *)buf;
  24. if ((le32_to_cpu(s_header->magic) == SPARSE_HEADER_MAGIC) &&
  25. (le16_to_cpu(s_header->major_version) == 1))
  26. return 1;
  27. return 0;
  28. }
  29. void write_sparse_image(struct sparse_storage *info, const char *part_name,
  30. void *data);