gzip.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * (C) Copyright 2000-2009
  4. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  5. */
  6. #ifndef __GZIP_H
  7. #define __GZIP_H
  8. struct blk_desc;
  9. /**
  10. * gzip_parse_header() - Parse a header from a gzip file
  11. *
  12. * This returns the length of the header.
  13. *
  14. * @src: Pointer to gzip file
  15. * @len: Length of data
  16. * @return length of header in bytes, or -1 if not enough data
  17. */
  18. int gzip_parse_header(const unsigned char *src, unsigned long len);
  19. /**
  20. * gunzip() - Decompress gzipped data
  21. *
  22. * @dst: Destination for uncompressed data
  23. * @dstlen: Size of destination buffer
  24. * @src: Source data to decompress
  25. * @lenp: Returns length of uncompressed data
  26. * @return 0 if OK, -1 on error
  27. */
  28. int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp);
  29. /**
  30. * zunzip() - Uncompress blocks compressed with zlib without headers
  31. *
  32. * @dst: Destination for uncompressed data
  33. * @dstlen: Size of destination buffer
  34. * @src: Source data to decompress
  35. * @lenp: On entry, length data at @src. On exit, number of bytes used from @src
  36. * @stoponerr: 0 to continue when a decode error is found, 1 to stop
  37. * @offset: start offset within the src buffer
  38. * @return 0 if OK, -1 on error
  39. */
  40. int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp,
  41. int stoponerr, int offset);
  42. /**
  43. * gzwrite progress indicators: defined weak to allow board-specific
  44. * overrides:
  45. *
  46. * gzwrite_progress_init called on startup
  47. * gzwrite_progress called during decompress/write loop
  48. * gzwrite_progress_finish called at end of loop to
  49. * indicate success (retcode=0) or failure
  50. */
  51. void gzwrite_progress_init(u64 expected_size);
  52. void gzwrite_progress(int iteration, u64 bytes_written, u64 total_bytes);
  53. void gzwrite_progress_finish(int retcode, u64 totalwritten, u64 totalsize,
  54. u32 expected_crc, u32 calculated_crc);
  55. /**
  56. * gzwrite() - decompress and write gzipped image from memory to block device
  57. *
  58. * @src: compressed image address
  59. * @len: compressed image length in bytes
  60. * @dev: block device descriptor
  61. * @szwritebuf: bytes per write (pad to erase size)
  62. * @startoffs: offset in bytes of first write
  63. * @szexpected: expected uncompressed length, may be zero to use gzip trailer
  64. * for files under 4GiB
  65. * @return 0 if OK, -1 on error
  66. */
  67. int gzwrite(unsigned char *src, int len, struct blk_desc *dev, ulong szwritebuf,
  68. u64 startoffs, u64 szexpected);
  69. /**
  70. * gzip()- Compress data into a buffer using the gzip algorithm
  71. *
  72. * @dst: Destination buffer for compressed data
  73. * @lenp: On entry, space available in destination buffer (in bytes). On exit,
  74. * number of bytes used in the buffer
  75. * @src: Source data to compress
  76. * @srclen: Size of source data
  77. * @return 0 if OK, -1 on error
  78. */
  79. int gzip(void *dst, unsigned long *lenp, unsigned char *src, ulong srclen);
  80. /**
  81. * zzip() - Compress blocks with zlib
  82. *
  83. * @dst: Destination for compressed data
  84. * @lenp: On entry, length data at @dst. On exit, number of bytes written to
  85. * @dst
  86. * @src: Source data to compress
  87. * @srclen: Size of source data
  88. * @stoponerr: 0 to continue when a decode error is found, 1 to stop
  89. * @func: Some sort of function that is called to do something. !ADD DOCS HERE!
  90. */
  91. int zzip(void *dst, ulong *lenp, unsigned char *src, ulong srclen,
  92. int stoponerr, int (*func)(ulong, ulong));
  93. #endif