aboutsummaryrefslogtreecommitdiffstats
path: root/tools/firmware-utils/src/bcmalgo.h
blob: 46647cf6d3dbb32adfd1f651e85aa320f30868b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#ifndef bcmutils_H
#define bcmutils_H

typedef struct
{
	uint16_t magic;
	uint16_t control;
	uint16_t rev_maj;
	uint16_t rev_min;
	uint32_t build_date;
	uint32_t filelen;
	uint32_t ldaddress;
	char filename[64];
	uint16_t hcs;
	uint16_t her_znaet_chto; //v dushe ne ebu
	uint32_t crc;
} ldr_header_t;


/**
 * Reverses endianess of a 32bit int, if the ENDIAN_REVERSE_NEEDED defined at compile-time
 * @param data
 * @return
 */
uint32_t reverse_endian32 ( uint32_t data );

/**
 * Reverses endianess of a 16bit int, if the ENDIAN_REVERSE_NEEDED defined at compile-time
 * @param data
 * @return
 */
uint16_t reverse_endian16 ( uint16_t data );
/**
 * Calculates the strange crc (used by bcm modems) of the file. Thnx fly out to Vector for the algorithm.
 * @param filename
 * @return
 */
uint32_t get_file_crc ( char* filename );

/**
 * Calculates HCS of the header.
 * @param hd
 * @return
 */
uint16_t get_hcs ( ldr_header_t* hd );

/**
 * Constructs the header of the image with the information given It also automagically calculates HCS and writes it there.
 * @param magic - magic device bytes
 * @param rev_maj - major revision
 * @param rev_min - minor revision
 * @param build_date - build date (seconds from EPOCH UTC)
 * @param filelen - file length in bytes
 * @param ldaddress - Load adress
 * @param filename - filename
 * @param crc_data - the crc of the data
 * @return
 */
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 );

/**
 * Dumps header information to stdout.
 * @param hd
 */
int dump_header ( ldr_header_t* hd );


/**
 * Returns a null terminated string describing what the control number meens
 * DO NOT FREE IT!!!
 * @param control
 * @return
 */
char* get_control_info ( uint16_t control );
#endif

/**
 * Calculates bcmCRC of a data buffer.
 * @param filebuffer - pointer to buffer
 * @param size - buffer size
 * @return
 */
uint32_t get_buffer_crc ( char* filebuffer, size_t size );