bcmalgo.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #ifndef bcmutils_H
  2. #define bcmutils_H
  3. typedef struct
  4. {
  5. uint16_t magic;
  6. uint16_t control;
  7. uint16_t rev_maj;
  8. uint16_t rev_min;
  9. uint32_t build_date;
  10. uint32_t filelen;
  11. uint32_t ldaddress;
  12. char filename[64];
  13. uint16_t hcs;
  14. uint16_t her_znaet_chto; //v dushe ne ebu
  15. uint32_t crc;
  16. } ldr_header_t;
  17. /**
  18. * Reverses endianess of a 32bit int, if the ENDIAN_REVERSE_NEEDED defined at compile-time
  19. * @param data
  20. * @return
  21. */
  22. uint32_t reverse_endian32 ( uint32_t data );
  23. /**
  24. * Reverses endianess of a 16bit int, if the ENDIAN_REVERSE_NEEDED defined at compile-time
  25. * @param data
  26. * @return
  27. */
  28. uint16_t reverse_endian16 ( uint16_t data );
  29. /**
  30. * Calculates the strange crc (used by bcm modems) of the file. Thnx fly out to Vector for the algorithm.
  31. * @param filename
  32. * @return
  33. */
  34. uint32_t get_file_crc ( char* filename );
  35. /**
  36. * Calculates HCS of the header.
  37. * @param hd
  38. * @return
  39. */
  40. uint16_t get_hcs ( ldr_header_t* hd );
  41. /**
  42. * Constructs the header of the image with the information given It also automagically calculates HCS and writes it there.
  43. * @param magic - magic device bytes
  44. * @param rev_maj - major revision
  45. * @param rev_min - minor revision
  46. * @param build_date - build date (seconds from EPOCH UTC)
  47. * @param filelen - file length in bytes
  48. * @param ldaddress - Load adress
  49. * @param filename - filename
  50. * @param crc_data - the crc of the data
  51. * @return
  52. */
  53. ldr_header_t* construct_header ( uint32_t magic, uint16_t rev_maj,uint16_t rev_min, uint32_t build_date, uint32_t filelen, uint32_t ldaddress, const char* filename, uint32_t crc_data );
  54. /**
  55. * Dumps header information to stdout.
  56. * @param hd
  57. */
  58. int dump_header ( ldr_header_t* hd );
  59. /**
  60. * Returns a null terminated string describing what the control number meens
  61. * DO NOT FREE IT!!!
  62. * @param control
  63. * @return
  64. */
  65. char* get_control_info ( uint16_t control );
  66. #endif
  67. /**
  68. * Calculates bcmCRC of a data buffer.
  69. * @param filebuffer - pointer to buffer
  70. * @param size - buffer size
  71. * @return
  72. */
  73. uint32_t get_buffer_crc ( char* filebuffer, size_t size );