summaryrefslogtreecommitdiff
path: root/downloader/proto.txt
blob: 71b07745d4c1a46081b5e2eb4ad1288a90565d6a (plain) (blame)
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
Command List:
=============

'i'  ... identify
'b'  ... boot
'r'  ... reset
'f'  ... read flash
'F'  ... write flash
'e'  ... read eeprom
'E'  ... write eeprom
'c'  ... read config
'C'  ... write config


Description:
------------

Every command consits of one byte command code, a fixed number of bytes as
arguments and ends with a XOR checksum over all bytes sent. All data is
transferred LSB first (aka little endian). All addresses and words are 2bytes long.
Every answer to a command starts with the command code. One byte return value,
optionally some data and a checksum (XOR over all bytes received)
The return codes have the following meaning:

  code | Error
 ------+-------------
    0  | OK
    1  | invalid command
    2  | bad checksum
    3  | not implemented
    4  | flash write error
    5  | address invalid
    6  | address prohibited
    5  | value out of bounds

identify:
~~~~~~~~~
  command:
    'i' | <csum> (in this case <csum> will always be 'i')

  answer:
    'i' | <ret> | version | name | devid | fss | mess | supported | <csum>

      version:
         2bytes, protocol version
         It is an error if the major version (MSB) is different (hence any
         protocol update must change the major version of the bootloader).

      name:
         10bytes, a descriptive name of the device.
         The downloader has to compare this name with the device name supplied
         via commandline and stop in case they don't match

      devid:
         2bytes, device id of the PIC
	 The downlaoder may use this id to check if it talks to the right bootloader

      fss:
         1byte, flash segment size
         The number of words of one flash segment which has to be written at once.
         The downloader can fill up holes by supplying the illegal code word 0xFFFF
         for some addresses. The bootloader will skip those areas.

      mess:
         2bytes, maximum eeprom segment size
         This represents the maximum number of eeprom bytes which may be written or
         read at once. Unlike <fss> value it is ok to write or read less than <mess>
         bytes.

      supported:
         2bytes, a bitmap showing supported commands
         The commands 'identify' and 'boot' are always supported by the bootloader,
         others may not (i.e.: not all PICs allow to update the configurtion words)

           bit | command
          -----+----------
            0  | reset
            1  | read flash
            2  | write flash
            3  | read eeprom
            4  | write eeprom
            5  | read config
            6  | write config


boot:
~~~~~

  command:
    'b' | <csum> (in this case <csum> will always be 'b')

  answer:
    'b' | <ret> | <csum>

  This instucts the bootloader to boot to the user application directly (no reset)


reset:
~~~~~~

  command:
    'r' | <csum> (in this case <csum> will always be 'r')

  answer:
    'r' | <ret> | <csum>

  The device performs a reboot. If the boot condition (i.e.: port pin) is not met
  this instructs the device to boot to the user application.


read flash:
~~~~~~~~~~~

  command:
    'f' | addr | <csum>

  answer:
    'f' | <ret> | data | <csum>

  The bootloader reads <fss> words from flash address <addr> and returns it as
  <data>.


write flash:
~~~~~~~~~~~~

  command:
    'F' | addr | data | <csum>

  answer:
    'F' | <ret> | <csum>

  The bootloader writes <data> (which has to contain exactly <fss> words) to address
  <addr> inside the flash.


read eeprom:
~~~~~~~~~~~~

  command:
    'e' | addr | len | <csum>

  answer:
    'e' | <ret> | data | <csum>

  The bootloader reads <len> bytes from eeprom at address <addr> and returns it as
  <data>. len is 2bytes long.


write eeprom:
~~~~~~~~~~~~~

  command:
    'E' | addr | len | data | <csum>

  answer:
    'E' | <ret> | <csum>

  The bootloader writes <data> (which has to contain exactly <len> bytes) to address
  <addr> inside the eeprom. len is 2bytes long and the value must not exceed <mess> bytes.


read config:
~~~~~~~~~~~~

   command:
     'c' | nr | <csum>

   answer:
     'c' | <ret> | word | <csum>

   The bootloader reads and returns the configuration word number <nr>. <nr> is one
   byte long.


write config:
~~~~~~~~~~~~~

   command:
     'C' | nr | word | <csum>

   answer:
     'C' | <ret> | <csum>

   The bootloader writes <word> onto configuration word number <nr>. <nr> is one
   byte long