1 2 #ifndef DFU_FILE_H 3 #define DFU_FILE_H 4 5 #include <stdint.h> 6 7 struct dfu_file { 8 /* File name */ 9 const char *name; 10 /* Pointer to file loaded into memory */ 11 uint8_t *firmware; 12 /* Different sizes */ 13 struct { 14 off_t total; 15 int prefix; 16 int suffix; 17 } size; 18 /* From prefix fields */ 19 uint32_t lmdfu_address; 20 /* From prefix fields */ 21 uint32_t prefix_type; 22 23 /* From DFU suffix fields */ 24 uint32_t dwCRC; 25 uint16_t bcdDFU; 26 uint16_t idVendor; 27 uint16_t idProduct; 28 uint16_t bcdDevice; 29 }; 30 31 enum suffix_req { 32 NO_SUFFIX, 33 NEEDS_SUFFIX, 34 MAYBE_SUFFIX 35 }; 36 37 enum prefix_req { 38 NO_PREFIX, 39 NEEDS_PREFIX, 40 MAYBE_PREFIX 41 }; 42 43 enum prefix_type { 44 ZERO_PREFIX, 45 LMDFU_PREFIX, 46 LPCDFU_UNENCRYPTED_PREFIX 47 }; 48 49 extern int verbose; 50 51 void dfu_load_file(struct dfu_file *file, enum suffix_req check_suffix, enum prefix_req check_prefix); 52 void dfu_store_file(struct dfu_file *file, int write_suffix, int write_prefix); 53 54 void dfu_progress_bar(const char *desc, unsigned long long curr, 55 unsigned long long max); 56 void *dfu_malloc(size_t size); 57 uint32_t dfu_file_write_crc(int f, uint32_t crc, const void *buf, int size); 58 void show_suffix_and_prefix(struct dfu_file *file); 59 60 #endif /* DFU_FILE_H */ 61