image-sparse.h 954 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 FASTBOOT_MAX_BLK_WRITE 16384
  9. #define ROUNDUP(x, y) (((x) + ((y) - 1)) & ~((y) - 1))
  10. struct sparse_storage {
  11. lbaint_t blksz;
  12. lbaint_t start;
  13. lbaint_t size;
  14. void *priv;
  15. lbaint_t (*write)(struct sparse_storage *info,
  16. lbaint_t blk,
  17. lbaint_t blkcnt,
  18. const void *buffer);
  19. lbaint_t (*reserve)(struct sparse_storage *info,
  20. lbaint_t blk,
  21. lbaint_t blkcnt);
  22. void (*mssg)(const char *str, char *response);
  23. };
  24. static inline int is_sparse_image(void *buf)
  25. {
  26. sparse_header_t *s_header = (sparse_header_t *)buf;
  27. if ((le32_to_cpu(s_header->magic) == SPARSE_HEADER_MAGIC) &&
  28. (le16_to_cpu(s_header->major_version) == 1))
  29. return 1;
  30. return 0;
  31. }
  32. int write_sparse_image(struct sparse_storage *info, const char *part_name,
  33. void *data, char *response);