image-sparse.h 916 B

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