sparse_state_machine.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #ifndef _SPARSE_STATE_MACHINE_H_
  2. #define _SPARSE_STATE_MACHINE_H_
  3. #include "transfer.h"
  4. #if defined(MTK_EMMC_SUPPORT) || defined(MTK_UFS_SUPPORT)
  5. #define STORAGE_BLOCK_SIZE 4096
  6. #else
  7. #define STORAGE_BLOCK_SIZE (nand_get_alignment())
  8. #endif
  9. typedef enum unsparse_wait_phase
  10. {
  11. UNSPARSE_WAIT_SPARSE_HEADER,
  12. UNSPARSE_WAIT_CHUNK_HEADER,
  13. UNSPARSE_WAIT_CHUNK_DATA,
  14. UNSPARSE_WAIT_CHUNK_NOT_CARE,
  15. UNSPARSE_WAIT_CHUNK_FILL,
  16. UNSPARSE_WAIT_CHUNK_CRC,
  17. } unsparse_phase_t;
  18. typedef struct cache_ctx
  19. {
  20. uint8* c_base; //cache buffer base
  21. uint32 c_offset; //cache buffer offset
  22. uint32 c_size; //cache buffer size
  23. } cache_ctx_t;
  24. typedef struct unsparse_status
  25. {
  26. status_t handle_status;
  27. unsparse_phase_t wait_phase;
  28. uint32 byte_to_process; // byte to be processed in one packet.
  29. uint8 *buf; // byte buffer of one packet.
  30. cache_ctx_t ctx; //buffer download context.
  31. partition_info_struct_t* partition;
  32. } unsparse_status_t;
  33. typedef struct unsparse_data
  34. {
  35. sparse_header_t sparse_hdr;
  36. chunk_header_t chunk_hdr;
  37. uint32 chunks_processed;
  38. uint64 chunk_remain_data_size; //data remained in current packet.
  39. uint64 image_address_offset; //offset of current processed data in packet |base---|---|---|-.....|offset.....|
  40. uint32 unhandle_buf_size;
  41. uint8 unhandle_buf[sizeof(chunk_header_t)];
  42. } unsparse_data_t;
  43. bool is_sparse_image(uint8* data, uint32 length);
  44. bool support_sparse_image(void);
  45. uint64 unspared_size(uint8* data);
  46. void init_unsparse_status(unsparse_status_t* status, partition_info_struct_t* partition);
  47. void write_sparse_data(unsparse_status_t* status, uint8* data, uint32 length);
  48. //ex functions
  49. void end_write_sparse_data(unsparse_status_t* status);
  50. #endif