gzip.h 3.3 KB

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