Zerocat Chipflasher  v0.4.3 (board-edition-1)
Flash free firmware to BIOS chips, kick the Manageability Engine.
line_info.c
Go to the documentation of this file.
1 /******************************************************************/
27 /******************************************************************/
39  char file_format,
40  int *linepos,
41  char c,
42  //HEXDUMP:
43  struct tag_hexdumpline *hexdumpline,
44  //MOT, MOTBIN:
45  struct tag_motline *motline,
46  int hexmode
47  )
48 {
49  int r = 0;
50 
51  /*
52  * NOTE
53  * *linepos == -1: This function has no effect, return value is zero.
54  * *linepos == 0: Is not used.
55  * *linepos == 1: Points to first byte of line.
56  */
57 
58  if(*linepos > -1) { //is line scanner active?
59  if(*linepos == 0) { //initialize
60  //clear structs for line_info()
61  if(motline != NULL) {
62  motline->linelen = 0;
63  motline->addrlen = 0;
64  motline->pos_addrlsb = 0;
65  motline->payload_orig = 0;
66  motline->payload = 0;
67  motline->length = 0;
68  motline->checksum = 0;
69  motline->chksum_rx = 0;
70  }
71  if(hexdumpline != NULL) {
72  hexdumpline->is_charset_print = OFF;
73  hexdumpline->is_comment_line = OFF;
74  hexdumpline->is_first = '-';
75  }
76  }
77  *linepos += 1; //let's start with value 1, which is easier to understand
78  switch(file_format) {
79  case MOTBIN:
80  switch(*linepos) {
81  case 0: //not used
82  break;
83 
84  case 1: //'S' character
85  break;
86 
87  case 2:
88  motline->addrlen = MOT_addrlen(c);
89  motline->pos_addrlsb = 4 + motline->addrlen * 2;
90  break;
91 
92  case 3:
93  motline->linelen = hexdigit2bin(c) << 4;
94  break;
95 
96  case 4:
97  motline->linelen |= hexdigit2bin(c);
98  motline->checksum = motline->linelen; //start summing checksum
99  //payload_orig: don't count address bytes and checksum
100  motline->payload_orig = (motline->linelen - motline->addrlen - 1) << (hexmode ? 1 : 0);
101  motline->length = motline->linelen + motline->addrlen + 8;
102  break;
103 
104  default:
105  if(*linepos <= motline->pos_addrlsb)
106  motline->checksum += (*linepos % 2) ? hexdigit2bin(c) << 4 : hexdigit2bin(c);
107  if(*linepos == motline->pos_addrlsb)
108  motline->payload = motline->payload_orig;
109  else if(motline->payload) {
110  motline->checksum += c;
111  motline->payload--;
112  r = 1;
113  }
114  if(*linepos == motline->pos_addrlsb + motline->payload_orig + 1)
115  motline->chksum_rx = hexdigit2bin(c) << 4;
116  if(*linepos == motline->pos_addrlsb + motline->payload_orig + 2) {
117  motline->chksum_rx |= hexdigit2bin(c);
118  motline->checksum = ~motline->checksum;
119  }
120  break;
121  }
122  break;
123 
124  case HEXDUMP:
125  if(*linepos == 1)
126  hexdumpline->is_first = c;
127  if(c == '#') {
128  hexdumpline->is_charset_print = ON;
129  if(*linepos == 1)
130  hexdumpline->is_comment_line = ON;
131  }
132  break;
133  }
134  }
135  return r;
136 }
tag_hexdumpline::is_comment_line
char is_comment_line
Definition: common.h:62
tag_motline::payload_orig
int payload_orig
Definition: common.h:53
tag_motline::pos_addrlsb
int pos_addrlsb
Definition: common.h:54
MOT_addrlen
signed char MOT_addrlen(char SREC_type)
Return the address length in bytes that corresponds to a known S-record type.
Definition: MOT_addrlen.c:38
HEXDUMP
@ HEXDUMP
Definition: filespec.h:54
tag_motline::chksum_rx
unsigned char chksum_rx
Definition: common.h:58
tag_motline
Definition: common.h:50
tag_hexdumpline::is_first
char is_first
Definition: common.h:64
hexdigit2bin
signed char hexdigit2bin(unsigned char hexdigit)
Convert a hexadecimal digit into a binary value.
Definition: hexdigit2bin.c:39
OFF
#define OFF
Definition: common.h:41
tag_motline::addrlen
int addrlen
Definition: common.h:51
tag_motline::payload
int payload
Definition: common.h:55
tag_motline::checksum
unsigned char checksum
Definition: common.h:57
tag_motline::length
int length
Definition: common.h:56
tag_motline::linelen
int linelen
Definition: common.h:52
tag_hexdumpline::is_charset_print
char is_charset_print
Definition: common.h:63
MOTBIN
@ MOTBIN
Definition: filespec.h:53
tag_hexdumpline
Definition: common.h:61
ON
#define ON
Definition: common.h:40
line_info
int line_info(char file_format, int *linepos, char c, struct tag_hexdumpline *hexdumpline, struct tag_motline *motline, int hexmode)
Helps to detect wether the byte in question is part of the line’s S-record frame or if it is part of ...
Definition: line_info.c:38