e4ebdc40d7a5bf42925200bdd18e53128b22dac7
4 static void toggle_led(void);
6 static void read_load_info(void);
7 static void decode_load_info(void);
9 static void read_file(byte
* addr
, udword size
);
12 static void print_descr(dma_descr_T
*d
);
15 static int memory_test(udword addr
, udword size
, udword
*failed_address
);
16 static void memory_dump(udword
*from
, udword
*to
);
21 #ifdef USE_BAUDRATE_CHANGING
30 REG_SET(R_PORT_PA_DATA
, data_out
, 0xaa);
34 io_buf_next
= (byte
*)IO_BUF_START
;
35 io_buf_cur
= (byte
*)IO_BUF_START
;
39 send_string("\r\n\r\nDevice ID = ");
40 send_hex(ntohl(tx_header
.id
), NL
);
41 send_string(e100boot_version
);
49 for (b
= (byte
*)_Stext
; b
!= (byte
*)_Edata
; b
++) {
52 send_string("Checksum of bootloader is ");
59 __asm__
volatile ("jump _start");
66 REG_SET(R_PORT_PA_DATA
, data_out
, 0x55);
69 REG_SET(R_PORT_PA_DATA
, data_out
, ~REG_GET(R_PORT_PA_READ
, data_in
));
73 for (i
= 0; i
!= 2000000; i
++)
86 #ifdef USE_BAUDRATE_CHANGING
90 send_string("Waiting for load info.\r\n");
94 read_file((byte
*)IO_BUF_START
, IO_BUF_END
- IO_BUF_START
- CRC_LEN
);
95 send_string("Got load info.\r\n");
98 #ifdef USE_BAUDRATE_CHANGING
99 if (change_baudrate
) {
100 REG_WR(R_SERIAL0_BAUD
, new_baudrate
);
104 while (i
++ < 1000000)
115 decode_load_info(void)
117 udword
*type_p
= (udword
*)IO_BUF_START
;
118 udword failed_address
;
122 while (type_p
!= (udword
*)(IO_BUF_END
- CRC_LEN
)) { /* !!! */
123 // send_hex(type_p, NL);
124 *type_p
= ntohl(*type_p
);
125 // send_hex(*type_p, NL);
129 // memory_dump(IO_BUF_START, IO_BUF_END);
131 cmd
= (command_T
*)IO_BUF_START
;
135 send_string("PACKET_INFO\r\n");
136 send_hex(cmd
->args
.packet_info
.addr
, NL
);
137 send_hex(cmd
->args
.packet_info
.size
, NL
);
143 read_file((byte
*)cmd
->args
.packet_info
.addr
, cmd
->args
.packet_info
.size
);
145 (byte
*)cmd
+= sizeof cmd
->type
+ sizeof cmd
->args
.packet_info
;
149 send_string("SET_REGISTER\r\n");
150 send_hex(cmd
->args
.set_register
.addr
, NL
);
151 send_hex(cmd
->args
.set_register
.val
, NL
);
153 *(udword
*)cmd
->args
.set_register
.addr
= cmd
->args
.set_register
.val
;
155 (byte
*)cmd
+= sizeof cmd
->type
+ sizeof cmd
->args
.set_register
;
159 send_string("GET_REGISTER\r\n");
160 send_hex(cmd
->args
.get_register
.addr
, NL
);
161 send_hex(*(udword
*)cmd
->args
.get_register
.addr
, NL
);
163 (byte
*)cmd
+= sizeof cmd
->type
+ sizeof cmd
->args
.get_register
;
167 send_string("PAUSE_LOOP\r\n");
168 send_hex(cmd
->args
.pause_loop
.pause
, NL
);
170 for (i
= cmd
->args
.pause_loop
.pause
; i
; i
--)
173 (byte
*)cmd
+= sizeof cmd
->type
+ sizeof cmd
->args
.pause_loop
;
177 send_string("MEM_VERIFY\r\n");
178 send_hex(cmd
->args
.mem_verify
.addr
, NL
);
179 send_hex(cmd
->args
.mem_verify
.val
, NL
);
181 if (*(udword
*)cmd
->args
.mem_verify
.addr
!= cmd
->args
.mem_verify
.val
) {
182 send_string("verify failed\r\n");
186 (byte
*)cmd
+= sizeof cmd
->type
+ sizeof cmd
->args
.mem_verify
;
190 send_string("MEM_TEST\r\n");
191 send_hex(cmd
->args
.mem_test
.from
, NL
);
192 send_hex(cmd
->args
.mem_test
.to
, NL
);
194 if (!memory_test(cmd
->args
.mem_test
.from
,
195 cmd
->args
.mem_test
.to
,
197 send_string("### Memory test failed at ");
198 send_hex(failed_address
, NL
);
199 memory_dump((udword
*)DWORD_ALIGN(failed_address
- 64),
200 (udword
*)DWORD_ALIGN(failed_address
+ 64));
203 send_string("Passed memory test.\r\n");
205 (byte
*)cmd
+= sizeof cmd
->type
+ sizeof cmd
->args
.mem_test
;
209 send_string("MEM_DUMP\r\n");
210 send_hex(cmd
->args
.mem_dump
.from_addr
, NL
);
211 send_hex(cmd
->args
.mem_dump
.to_addr
, NL
);
213 memory_dump((udword
*)cmd
->args
.mem_dump
.from_addr
,
214 (udword
*)cmd
->args
.mem_dump
.to_addr
);
216 (byte
*)cmd
+= sizeof cmd
->type
+ sizeof cmd
->args
.mem_dump
;
220 send_string("MEM_CLEAR\r\n");
221 send_hex(cmd
->args
.mem_clear
.from_addr
, NL
);
222 send_hex(cmd
->args
.mem_clear
.to_addr
, NL
);
224 for (i
= cmd
->args
.mem_clear
.from_addr
;
225 i
<= cmd
->args
.mem_clear
.to_addr
;
230 (byte
*)cmd
+= sizeof cmd
->type
+ sizeof cmd
->args
.mem_clear
;
234 send_string("FLASH\r\n");
235 send_hex((udword
)cmd
->args
.flash
.source
, NL
);
236 send_hex(cmd
->args
.flash
.offset
, NL
);
237 send_hex(cmd
->args
.flash
.size
, NL
);
239 if ((i
= flash_write(cmd
->args
.flash
.source
,
240 cmd
->args
.flash
.offset
,
241 cmd
->args
.flash
.size
)) != ERR_FLASH_OK
) {
242 if (i
== ERR_FLASH_VERIFY
) {
244 (cmd
->args
.flash
.size
< 65536 ? cmd
->args
.flash
.size
: 65536);
246 /* Try to erase the first block(s) we tried to flash to prevent a
247 unit which failed to flash correctly from booting */
248 flash_write(NULL
, cmd
->args
.flash
.offset
, size
);
254 (byte
*)cmd
+= sizeof cmd
->type
+ sizeof cmd
->args
.flash
;
259 /* for the printf function in our libc */
260 REG_WR(R_DMA_CH8_FIRST
, *(udword
*)&tx_header
.dest
[0]);
261 REG_WR(R_DMA_CH9_FIRST
, *(uword
*)&tx_header
.dest
[4]);
262 // REG_WR(R_NETWORK_SA_1, &tx_header.dest[4]);
263 // REG_WR(R_NETWORK_SA_2, tx_header.id);
265 send_string("JUMP\r\n");
266 send_hex(cmd
->args
.jump
.addr
, NL
);
267 send_string("END\r\n");
269 __asm__
volatile ("jump %0" :: "r" (cmd
->args
.jump
.addr
));
271 (byte
*)cmd
+= sizeof cmd
->type
+ sizeof cmd
->args
.jump
;
275 send_string("LOOP\r\n");
276 send_hex(cmd
->args
.bne
.addr
, NL
);
277 send_hex(cmd
->args
.bne
.target
, NL
);
279 if (*(udword
*)cmd
->args
.bne
.addr
) {
280 (*(udword
*)cmd
->args
.bne
.addr
)--;
281 (byte
*)cmd
= cmd
->args
.bne
.target
;
284 (byte
*)cmd
+= sizeof cmd
->type
+ sizeof cmd
->args
.bne
;
288 #ifdef USE_BAUDRATE_CHANGING
290 send_string("BAUDRATE\r\n");
291 send_hex(cmd
->args
.br
.baudrate
, NL
);
293 new_baudrate
= cmd
->args
.br
.baudrate
;
295 (byte
*)cmd
+= sizeof cmd
->type
+ sizeof cmd
->args
.br
;
300 send_string("### Unknown type: ");
301 send_hex(cmd
->type
, NL
);
309 send_string("END\r\n");
313 read_file(byte
* addr
, udword size
)
315 udword nbr_read_last
;
320 /* send_string(">read_file\r\n"); */
324 target_address
= (udword
)addr
;
326 if (interface
== NETWORK
) {
327 rx_descr2
.buf
= (udword
)addr
;
328 bytes_to_read
= size
;
329 rx_descr2
.sw_len
= size
+ CRC_LEN
> 1500 ? 1500 : size
+ CRC_LEN
;
330 /* rx_descr2.sw_len = 1500; */
332 REG_SET(R_DMA_CH1_FIRST
, first
, (udword
)&rx_descr
);
334 /* Restart receiver so descriptor is re-read. */
335 REG_SET(R_DMA_CH1_CMD
, cmd
, reset
);
336 while (REG_EQL(R_DMA_CH1_CMD
, cmd
, reset
)) {
339 REG_SET(R_DMA_CH1_CMD
, cmd
, start
);
342 /* send_hex(rx_descr2.hw_len, NL); */
343 from
= (byte
*)rx_descr2
.buf
;
345 if (nbr_read
< size
) {
346 REG_SET(R_DMA_CH1_CMD
, cmd
, start
);
350 print_descr(&rx_descr
);
351 print_descr(&rx_descr2
);
355 send_string("Read ");
356 send_hex(rx_descr2
.hw_len
- CRC_LEN
, NO_NL
);
357 send_string(" bytes. ");
358 send_hex((udword
)from
, NO_NL
);
360 send_hex(rx_descr2
.buf
-1, NO_NL
);
362 send_hex(nbr_read
, NO_NL
);
364 send_hex(size
, NO_NL
);
365 send_string(")\r\n");
368 nbr_read_last
= nbr_read
;
369 /* from = (byte*)rx_descr2.buf; */
371 if (nbr_read
>= size
) {
377 else { /* interface != NETWORK */
378 while (nbr_read
< size
) {
384 for (b
= addr
; b
!= (byte
*)(addr
+size
); b
++) {
387 send_string("Checksum of file is ");
390 /* memory_dump((udword*)addr, (udword*)addr+size); */
391 /* send_string("<read_file\r\n"); */
396 print_descr(dma_descr_T
*d
)
398 send_string("Descriptor at ");
399 send_hex((udword
)d
, NL
);
401 send_string("ctrl : ");
402 send_hex(d
->ctrl
, NL
);
404 send_string("sw_len : ");
405 send_hex(d
->sw_len
, NL
);
407 send_string("next : ");
408 send_hex(d
->next
, NL
);
410 send_string("buf : ");
411 send_hex(d
->buf
, NL
);
413 send_string("status : ");
414 send_hex(d
->status
, NL
);
416 send_string("hw_len : ");
417 send_hex(d
->hw_len
, NL
);
422 memory_test(udword from
, udword to
, udword
*failed_address
)
428 /* At each dword (but bytewise) write the inverse of the adress,
429 check that it worked, then write the inverse of the last byte
430 written. Exit on fail. The memory after a successfull test will
433 0xC0000000 : 0xC0000000 0xC0000004 0xC0000008 0xC000000C
434 0xC0000010 : 0xC0000010 0xC0000014 0xC0000018 0xC000001C
437 for (i
= from
; i
< to
; i
+= 4) {
438 for (j
= 0; (j
!= sizeof(udword
)) && (i
+j
< to
); j
++) {
439 b
= ((~i
) >> (j
*8)) & 0xff;
440 *(volatile byte
*)(i
+j
) = b
;
441 if (*(volatile byte
*)(i
+j
) == b
) {
442 *(volatile byte
*)(i
+j
) = ~b
;
445 *failed_address
= i
+j
;
446 send_string("### Memory test 1 failed at ");
447 send_hex(*failed_address
, NL
);
453 /* Run through entire region, check bytewise that the dwords contain
454 the address to the dword. Exit on fail. */
456 for (i
= from
; i
< to
; i
+= 4) {
457 for (j
= 0; (j
!= sizeof(udword
)) && (i
+j
< to
); j
++) {
458 b
= (i
>> (j
*8)) & 0xff;
459 if (*(volatile byte
*)(i
+j
) != b
) {
460 *failed_address
= i
+j
;
461 send_string("### Memory test 2 failed at ");
462 send_hex(*failed_address
, NL
);
472 memory_dump(udword
*from
, udword
*to
)
477 for (; i
<= to
; i
+= 4) {
478 send_hex((udword
)i
, NO_NL
);
480 for(j
= 0; j
!= 4 && (i
+j
<= to
); j
++) {
482 send_hex(*(udword
*)(i
+j
), NO_NL
);
This page took 0.081973 seconds and 3 git commands to generate.