Zerocat Chipflasher  v0.4.3 (board-edition-1)
Flash free firmware to BIOS chips, kick the Manageability Engine.
kick.h
Go to the documentation of this file.
1 /******************************************************************/
27 #ifndef __CHIPSPEC_H__
28  #error "chipspec.h has not been included, yet."
29 #endif
30 
31 #ifndef __SERIAL_CODES_H__
32  #error "serial-codes.h has not been included, yet."
33 #endif
34 
35 #ifndef __FILESPEC_H__
36  #error "filespec.h has not been included, yet."
37 #endif
38 
39 #ifndef __KICK_H__
40 #define __KICK_H__
41 
42 //define doxygen module groups
59 //start diagnostic compiler switches
60 #define ERROR_MSG__LINE_TOO_LONG
61 //end diagnostic compiler switches
62 
63 
64 //constants
65 #define HEADER_KICK " Zerocat Chipflasher: kick " VERSION " "
66 #define SIZE_STR_MESSAGE (1 << 7)
67 #define SIZE_STRBUF (1 << 8)
68 #define SIZE_LINEBUF (1 << 8)
69 #define BAUDRATE_DEFAULT 115200
70 #define NOT_APPLICABLE -1
71 #define POWERUP_SPI 25
72 #define POWERUP_SPILINES 25
73 #define POWERUP_EXTRA 2
74 #define POWERUP_OFFTIME 100000
75 #define STACK_DEFAULT 0x40
76 #define STACK_BURNBUF 0x20
77 #define STACK_LEDSTAT 0x20
78 #define MAX_POLLING 100000000
79 
80 //modes, used by main()
81 #define MODE_TERMINAL 0x01
82 #define MODE_CONNECT 0x02
83 
84 //modes, used by SPI_off()
85 #define MODE_SPI_OFF 0x00
86 #define MODE_FORCE_SPI_OFF 0x01
87 #define MODE_SPI_POWEROFF 0x02
88 
89 //used by ledstat()
90 #define LOOP_RES ((CLKFREQ / 1000000) * 1000) //1ms
91 #define STATUS_CYCLE 1000 //1000ms
92 #define LED_PHASE 90 //90ms
93 
94 //macros
95 #define PUTCHAR_CR do { \
96  outfifo(CARR_RET); \
97  } while(0)
98 
99 #define PUTCHAR_NL do { \
100  outfifo(NEW_LINE); \
101  } while(0)
102 
103 #define GET_CHAR_GROUP(n) for(unsigned char i = 0; i < n; i++) { \
104  c[i] = outfifo(getChar()); \
105  }
106 
107 #define MSG_DONE "...done.\r\n\n"
108 
109 #define SPI_ON SPI_ini()
110 #define SPI_OFF(mode) SPI_off(mode)
111 
112 
113 
115  cmd_off = 0,
118 };
119 
121  mode_0 = 0,
123 };
124 
127  ADDRLEN_MOT, //minimal lenght is 2, not 1 or zero
129 };
130 
135 };
136 
137 
138 
146 union tag_typeS {
147  unsigned int mem;
148  struct {
149  unsigned int none:1;
150  unsigned int start:1;
151  unsigned int data:1;
152  unsigned int linecount:1;
153  unsigned int startexec:1;
154  unsigned int addrlen:3;
155  unsigned int num:4;
156  unsigned int :0;
157  } bf;
158 };
159 
160 
161 
166  struct tag_linedat {
167  char * buf;
168  unsigned int mask;
169  unsigned int rd;
170  unsigned int wr;
171  unsigned int startaddr;
172  unsigned char payload;
173 };
174 
175 
176 
182 struct tag_xcog1 {
183  volatile unsigned char green;
184  volatile unsigned char yellow;
185  volatile unsigned char orange;
186  volatile unsigned char inlevel;
187 };
188 
189 
190 
203 struct tag_xcog0 {
204  int * pcog;
205  unsigned char cmd;
206  unsigned char abits;
207  unsigned int lineaddr;
208  int psize;
209  unsigned char * pbuf;
210  unsigned char bufsize;
211  volatile unsigned int offrd;
212  volatile unsigned int offwr;
213  volatile unsigned char queue_empty;
214  volatile unsigned char rq_spioff;
215  volatile unsigned char rq_lineaddr;
216 };
217 
218 
219 
227 struct tag_chip {
228  unsigned char index;
229  struct tag_chipspec * pspec;
230  unsigned char addrlen_in_bits;
231  int pages;
232 };
233 
234 
235 
236 int hex2bin (
237  unsigned char a,
238  unsigned char b
239  );
240 
241 void chip_erase(
242  void
243  );
244 
245 void HEXDUMP_mkline (
246  struct tag_linedat * linedat,
247  char * linebuf_orig
248  );
249 
250 char HEXDUMP_rxline (
251  struct tag_xcog0 * px,
252  unsigned int * lines
253  );
254 
255 void MOT_mkline(
256  struct tag_linedat * linedat,
257  union tag_typeS * typeS,
258  char * linebuf
259  );
260 
261 char MOT_rxline (
262  struct tag_xcog0 * px,
263  unsigned int * lines,
264  int hexmode
265  );
266 
267 void MOT_typeS_fillup(
268  union tag_typeS * typeS
269  );
270 
271 void chip_txfile (
272  struct tag_filespec * filespec,
273  unsigned char addrlen_in_bits,
274  unsigned int firstloc,
275  unsigned int memsize,
276  unsigned char screenmode
277  );
278 
279 void menu_line(
280  unsigned int k1,
281  char * k1msg,
282  unsigned int k2,
283  char * k2msg,
284  unsigned int k3,
285  char * k3msg
286  );
287 
288 void cmd_DP (
289  void
290  );
291 
292 signed char linebuf_out (
293  char * linebuf
294  );
295 
296 unsigned char get_addrlen(
297  enum tag_type_of_addrlen type_of_addrlen,
298  unsigned int addr
299  );
300 
301 void outbits (
302  const unsigned int value,
303  unsigned int msbit
304  );
305 
306 int cmd_RDID_JEDEC (
307  void
308  );
309 
310 char queue (
311  struct tag_xcog0 * px,
312  unsigned char vbin,
313  unsigned int * pwr
314  );
315 
316 void chip_rxfile (
317  struct tag_xcog0 * px,
318  char screen_output
319  );
320 
321 signed char chip_read (
322  struct tag_filespec * filespec,
323  unsigned int firstloc,
324  unsigned int memsize,
325  unsigned int * lines,
326  char * linebuf
327  );
328 
329 void ledstat();
330 void burn();
331 
332 void MOT_header(
333  char * header,
334  char * linebuf
335  );
336 
337 void MOT_data (
338  struct tag_linedat * linedat,
339  char * linebuf
340 );
341 
342 void MOT_summary (
343  unsigned int lines,
344  char * linebuf
345  );
346 
347 void chip_ini (
348  unsigned char new_index
349  );
350 
351 unsigned int CPM_polling (
352  void
353  );
354 
355 void PGM_cycle (
356  enum tag_cmdstat * cmdstat,
357  unsigned char odd_tracker
358  );
359 
360 unsigned char verify_0xff(
361  unsigned int firstloc,
362  unsigned int memsize
363  );
364 
365 inline unsigned char inb (
366  void
367  );
368 
369 unsigned int inbits (
370  unsigned int msbit
371  );
372 
373 void key_config(
374  void
375  );
376 
377 void menu_options(
378  void
379  );
380 
381 void greeting (
382  );
383 
384 unsigned char yes_no (
385  char * question,
386  unsigned char level_rst
387  );
388 
389 void exit_sequence (
390  const char status
391  );
392 
393 void SPI_ini (
394  void
395  );
396 
397 void SPI_off (
398  int mode
399  );
400 
401 int WIP_polling (
402  void
403  );
404 
405 int strpos(
406  char * str,
407  char c
408  );
409 
410 void cmd (
411  const unsigned char cmd,
412  const unsigned int value,
413  unsigned char bits
414  );
415 
416 unsigned char cmd_RDSR (
417  unsigned char regno
418  );
419 
420 void cmd_WRSR (
421  const unsigned char regno,
422  const unsigned char byte
423  );
424 
425 unsigned char SR_report (
426  unsigned char regno
427  );
428 
429 void SR_intro(
430  unsigned char regno
431  );
432 
433 void cmd_WREN (
434  void
435  );
436 
437 void cmd_WRDI (
438  void
439  );
440 
442  unsigned char pswitch
443  );
444 
445 void option_readblock (
446  const enum tag_blocksize blocksize
447  );
448 
450  const enum tag_blocksize blocksize,
451  const unsigned char blockcmd
452  );
453 
454 int do__WIP_polling(
455  void
456  );
457 
458 void key_polling(
459  unsigned char * key_is_valid,
460  unsigned char * quit
461  );
462 
463 void range_error(
464  void
465  );
466 
467 void page_write (
468  const unsigned int addr,
469  unsigned char * buffer
470  );
471 
472 int plug_detect(
473  void
474  );
475 
476 void menu(
477  unsigned char mode
478  );
479 
480 char outfifo (
481  char c
482  );
483 
484 int outstr (
485  char * s
486  );
487 
488 void connected (
489  void
490  );
491 
492 void hr(
493  char c,
494  int n,
495  char nl
496  );
497 
498 void mirror (
499  char * keymsg
500  );
501 
502 void putChar(
503  char c
504  );
505 
506 void report_err(
507  char reported_err
508  );
509 
510 void check_dryrun(
511  void
512  );
513 
514 
515 #endif
516 /* __KICK_H__ */
key_config
void key_config(void)
Enable menu keys according to chip specs.
Definition: kick.c:971
MOT_rxline
char MOT_rxline(struct tag_xcog0 *px, unsigned int *lines, int hexmode)
Receive and parse a line in Motorola S-Record format. This func finishes successfully after having pa...
Definition: kick.c:2678
cmd_off
@ cmd_off
Definition: kick.h:115
do__WIP_polling
int do__WIP_polling(void)
Invoking WIP_polling() usually is accompanied by some checks and messages.
Definition: kick.c:251
menu_options
void menu_options(void)
Put menu options on terminal screen.
Definition: kick.c:1071
global_sector_protect
void global_sector_protect(unsigned char pswitch)
Method to globally protect/unprotect all sectors.
Definition: kick.c:387
tag_linedat::startaddr
unsigned int startaddr
Line’s startaddress.
Definition: kick.h:171
putChar
void putChar(char c)
Definition: putChar.c:46
tag_xcog0::queue_empty
volatile unsigned char queue_empty
Flag to indicate that the data queue is empty.
Definition: kick.h:213
connected
void connected(void)
Definition: kick.c:182
outstr
int outstr(char *s)
Definition: kick.c:1629
PGM_cycle
void PGM_cycle(enum tag_cmdstat *cmdstat, unsigned char odd_tracker)
Definition: kick.c:2228
yes_no
unsigned char yes_no(char *question, unsigned char level_rst)
This function allows to put a question which expects true or false.
Definition: kick.c:1303
tag_chip
Struct that characterizes a chip.
Definition: kick.h:227
mode_0
@ mode_0
Definition: kick.h:121
chip_read
signed char chip_read(struct tag_filespec *filespec, unsigned int firstloc, unsigned int memsize, unsigned int *lines, char *linebuf)
Definition: kick.c:1345
tag_xcog0::abits
unsigned char abits
addrbits.
Definition: kick.h:206
tag_xcog1::yellow
volatile unsigned char yellow
Switch for yellow LED usage.
Definition: kick.h:184
option_batchblockerase
void option_batchblockerase(const enum tag_blocksize blocksize, const unsigned char blockcmd)
Versatile block erase function, which allows erasing of multiple blocks of different sizes,...
Definition: kick.c:291
cmd_DP
void cmd_DP(void)
Definition: kick.c:2045
cmd_CP
@ cmd_CP
Definition: kick.h:117
keymsg
char * keymsg[]
Definition: key-enable-bits.h:99
tag_linedat::rd
unsigned int rd
Read pointer.
Definition: kick.h:169
hex2bin
int hex2bin(unsigned char a, unsigned char b)
Converts a pair of hexadecimal chars into binary value.
Definition: kick.c:2209
tag_xcog0::psize
int psize
Page size.
Definition: kick.h:208
tag_xcog1::green
volatile unsigned char green
Switch for green LED usage.
Definition: kick.h:183
SIZE_32K
#define SIZE_32K
Size of 32K-block.
Definition: chipspec.h:90
get_addrlen
unsigned char get_addrlen(enum tag_type_of_addrlen type_of_addrlen, unsigned int addr)
Auxiliary function that returns the length of an address for different situations.
Definition: kick.c:939
tag_blocksize
tag_blocksize
Definition: kick.h:131
outfifo
char outfifo(char c)
Definition: kick.c:1615
tag_type_of_addrlen
tag_type_of_addrlen
Definition: kick.h:125
MOT_summary
void MOT_summary(unsigned int lines, char *linebuf)
Definition: kick.c:1280
tag_linedat
Struct that characterizes a data line.
Definition: kick.h:166
BLOCK_32K
@ BLOCK_32K
Definition: kick.h:133
cmd_WREN
void cmd_WREN(void)
Set Write Enable Latch bit.
Definition: kick.c:1727
tag_xcog0::cmd
unsigned char cmd
Command to be used for writing.
Definition: kick.h:205
tag_typeS::bf
struct tag_typeS::@0 bf
page_write
void page_write(const unsigned int addr, unsigned char *buffer)
Write a page buffer to chip.
Definition: kick.c:1806
exit_sequence
void exit_sequence(const char status)
Tell terminal to exit listening mode.
Definition: kick.c:1862
tag_xcog0::rq_spioff
volatile unsigned char rq_spioff
Flag to request SPI off.
Definition: kick.h:214
tag_typeS::start
unsigned int start
Definition: kick.h:150
ledstat
void ledstat()
This function controls board LEDs. To be used with extra cog, to be stopped externally.
Definition: kick.c:2266
tag_typeS::num
unsigned int num
Definition: kick.h:155
tag_typeS
Motorola S-Record Type Infos.
Definition: kick.h:146
MOT_typeS_fillup
void MOT_typeS_fillup(union tag_typeS *typeS)
Generating and parsing a Motorola S-record line needs to have some specs available about the line in ...
Definition: kick.c:2481
cmd_WRSR
void cmd_WRSR(const unsigned char regno, const unsigned char byte)
Write to Status Registers.
Definition: kick.c:1743
cmd_RDSR
unsigned char cmd_RDSR(unsigned char regno)
Read the status register.
Definition: kick.c:2069
tag_xcog0::lineaddr
unsigned int lineaddr
startaddress of data line.
Definition: kick.h:207
chip_ini
void chip_ini(unsigned char new_index)
Definition: kick.c:1331
strpos
int strpos(char *str, char c)
Report the position of a character in a string.
Definition: kick.c:1214
inbits
unsigned int inbits(unsigned int msbit)
Definition: kick.c:1980
CPM_polling
unsigned int CPM_polling(void)
Poll CPM bit.
Definition: kick.c:1903
check_dryrun
void check_dryrun(void)
Checks wether a write fail should be expected. A function with very basic and poor functionality.
Definition: kick.c:820
chip_erase
void chip_erase(void)
This function calls the global chip erase command.
Definition: kick.c:3000
MOT_header
void MOT_header(char *header, char *linebuf)
This function invokes MOT_mkline(), but initializes parameters first with apropriate header data.
Definition: kick.c:1237
tag_spimode
tag_spimode
Definition: kick.h:120
HEXDUMP_rxline
char HEXDUMP_rxline(struct tag_xcog0 *px, unsigned int *lines)
Parse a Hexdump line.
Definition: kick.c:2543
tag_xcog1::orange
volatile unsigned char orange
Switch for orange LED usage.
Definition: kick.h:185
tag_typeS::int
unsigned int
Definition: kick.h:156
ADDRLEN_MOT
@ ADDRLEN_MOT
Definition: kick.h:127
tag_xcog0::offrd
volatile unsigned int offrd
Buffer read pointer offset.
Definition: kick.h:211
BLOCK_64K
@ BLOCK_64K
Definition: kick.h:134
MOT_mkline
void MOT_mkline(struct tag_linedat *linedat, union tag_typeS *typeS, char *linebuf)
This function wraps a binary payload into a Motorola S-record frame.
Definition: kick.c:1162
tag_xcog0::rq_lineaddr
volatile unsigned char rq_lineaddr
Flag to request the next line address.
Definition: kick.h:215
menu_line
void menu_line(unsigned int k1, char *k1msg, unsigned int k2, char *k2msg, unsigned int k3, char *k3msg)
Put a menu line with selected menu options on terminal screen.
Definition: kick.c:1040
tag_xcog0::pbuf
unsigned char * pbuf
Pointer to ringbuffer.
Definition: kick.h:209
tag_typeS::none
unsigned int none
Definition: kick.h:149
SIZE_64K
#define SIZE_64K
Size of 64K-block.
Definition: chipspec.h:91
key_polling
void key_polling(unsigned char *key_is_valid, unsigned char *quit)
Essential function. Scans stdin for configured keys and issues the apropriate actions....
Definition: kick.c:420
tag_linedat::wr
unsigned int wr
Write pointer.
Definition: kick.h:170
cmd_RDID_JEDEC
int cmd_RDID_JEDEC(void)
Definition: kick.c:2029
SR_intro
void SR_intro(unsigned char regno)
Provide each bit listing of an status register with a short header.
Definition: kick.c:369
chip_txfile
void chip_txfile(struct tag_filespec *filespec, unsigned char addrlen_in_bits, unsigned int firstloc, unsigned int memsize, unsigned char screenmode)
Definition: kick.c:1507
plug_detect
int plug_detect(void)
Check if an SPI-Plug is detected and put a message on screen.
Definition: kick.c:845
tag_typeS::addrlen
unsigned int addrlen
Definition: kick.h:154
report_err
void report_err(char reported_err)
Definition: kick.c:2848
tag_typeS::startexec
unsigned int startexec
Definition: kick.h:153
range_error
void range_error(void)
Reports an Out-of-Range user input error and resets xcog1.inlevel.
Definition: kick.c:275
chip_rxfile
void chip_rxfile(struct tag_xcog0 *px, char screen_output)
Definition: kick.c:2861
burn
void burn()
Wite data to chip.
Definition: kick.c:2349
filespec
struct tag_filespec filespec[2]
Definition: filespec.c:30
SR_report
unsigned char SR_report(unsigned char regno)
Put status register's content on screen.
Definition: kick.c:1929
outbits
void outbits(const unsigned int value, unsigned int msbit)
Definition: kick.c:1997
tag_typeS::linecount
unsigned int linecount
Definition: kick.h:152
inb
unsigned char inb(void)
Definition: kick.c:1971
cmd_WRDI
void cmd_WRDI(void)
Definition: kick.c:2098
tag_xcog1
Cog parameters for ledstat().
Definition: kick.h:182
tag_chip::pages
int pages
Number of pages (on a paged chip).
Definition: kick.h:231
verify_0xff
unsigned char verify_0xff(unsigned int firstloc, unsigned int memsize)
This function scans the specified chip memory for values different than 0xff. If a value different to...
Definition: kick.c:1122
tag_cmdstat
tag_cmdstat
Definition: kick.h:114
tag_chip::pspec
struct tag_chipspec * pspec
Pointer into chipspec database.
Definition: kick.h:229
BLOCK_4K
@ BLOCK_4K
Definition: kick.h:132
mode_3
@ mode_3
Definition: kick.h:122
SIZE_4K
#define SIZE_4K
Size of 4K-sector.
Definition: chipspec.h:88
SPI_ini
void SPI_ini(void)
Initialize SPI bus; activate hardware write protection.
Definition: kick.c:2121
tag_chip::addrlen_in_bits
unsigned char addrlen_in_bits
Number of bits that are used feed an address into the SPI-bus.
Definition: kick.h:230
MOT_data
void MOT_data(struct tag_linedat *linedat, char *linebuf)
Definition: kick.c:1263
tag_xcog1::inlevel
volatile unsigned char inlevel
Current menu input level.
Definition: kick.h:186
tag_typeS::mem
unsigned int mem
Definition: kick.h:147
tag_xcog0::offwr
volatile unsigned int offwr
Buffer write pointer offset.
Definition: kick.h:212
tag_filespec
Definition: filespec.h:57
option_readblock
void option_readblock(const enum tag_blocksize blocksize)
Definition: kick.c:204
SPI_off
void SPI_off(int mode)
Switch SPI bus off.
Definition: kick.c:2166
mirror
void mirror(char *keymsg)
Definition: kick.c:193
WIP_polling
int WIP_polling(void)
Determine end of write cycle by polling the WIP bit.
Definition: kick.c:1878
tag_linedat::mask
unsigned int mask
Mask for read and write pointers.
Definition: kick.h:168
tag_chip::index
unsigned char index
Definition: kick.h:228
menu
void menu(unsigned char mode)
Put the chipflasher menu on screen and invoke key_polling().
Definition: kick.c:866
tag_xcog0::bufsize
unsigned char bufsize
Size of ringbuffer.
Definition: kick.h:210
cmd_on
@ cmd_on
Definition: kick.h:116
linebuf_out
signed char linebuf_out(char *linebuf)
Put a formatted data line onto tty.
Definition: kick.c:1592
tag_xcog0
Cog parameters for burn().
Definition: kick.h:203
tag_xcog0::pcog
int * pcog
Cog info pointer, used by cog_end().
Definition: kick.h:204
tag_linedat::buf
char * buf
Pointer to buffer, that holds the data.
Definition: kick.h:167
ADDRLEN_IN_BYTES
@ ADDRLEN_IN_BYTES
Definition: kick.h:126
cmd
void cmd(const unsigned char cmd, const unsigned int value, unsigned char bits)
Definition: kick.c:2017
tag_chipspec
Chip specifications, provided within the source code.
Definition: chipspec.h:166
tag_linedat::payload
unsigned char payload
Number of payload bytes.
Definition: kick.h:172
queue
char queue(struct tag_xcog0 *px, unsigned char vbin, unsigned int *pwr)
Definition: kick.c:2831
ADDRLEN_IN_BITS
@ ADDRLEN_IN_BITS
Definition: kick.h:128
tag_typeS::data
unsigned int data
Definition: kick.h:151
HEXDUMP_mkline
void HEXDUMP_mkline(struct tag_linedat *linedat, char *linebuf_orig)
This function transforms a binary payload into a row of ascii chars including line ending characters ...
Definition: kick.c:1660
greeting
void greeting()
Put a small headline on terminal screen that helps to identify the program.
Definition: kick.c:1711
hr
void hr(char c, int n, char nl)
Put a horizontal line on screen.
Definition: kick.c:919