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