comparison fluid-mnf/machine.c @ 340:435e041897f2

fluid-mnf/machine.c: passes compilation
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 13 Mar 2020 02:47:52 +0000
parents 9cecc930d78f
children 37b5f94de802
comparison
equal deleted inserted replaced
339:77c86062e253 340:435e041897f2
13 13
14 #include "fluid.h" 14 #include "fluid.h"
15 #include "flash.h" 15 #include "flash.h"
16 #include "target.h" 16 #include "target.h"
17 #include "fileio.h" 17 #include "fileio.h"
18 #include "../target/protocol.h" 18 #include "protocol.h"
19 #include "misc.h" 19 #include "misc.h"
20 #include "lz.h" 20 #include "lz.h"
21 #include "trace.h" 21 #include "trace.h"
22 // Secure Calypso Plus 22 // Secure Calypso Plus
23 #include "../inc/ram_load.h" 23 #include "calplus/ram_load.h"
24 #include "../inc/secure_types.h" 24 #include "calplus/secure_types.h"
25 25
26 #include <stdio.h> 26 #include <stdio.h>
27 #include <malloc.h> 27 #include <malloc.h>
28 #include <stdlib.h> 28 #include <stdlib.h>
29 #include <string.h> 29 #include <string.h>
1505 { 1505 {
1506 unsigned char sendbuf[1+1+4+4*CHECKSUMS], *buf; 1506 unsigned char sendbuf[1+1+4+4*CHECKSUMS], *buf;
1507 uint32 addr, cksum, mycksum; 1507 uint32 addr, cksum, mycksum;
1508 uint16 word; 1508 uint16 word;
1509 uint8 data[4]; 1509 uint8 data[4];
1510 int index = 0, chunks, n, i, j; 1510 int img_index = 0, chunks, n, i, j;
1511 int line = -1; 1511 int line = -1;
1512 struct { 1512 struct {
1513 uint32 index; 1513 uint32 index;
1514 uint32 addr; 1514 uint32 addr;
1515 uint32 mycksum; 1515 uint32 mycksum;
1531 buf += buf_put1(buf, (unsigned char) n); 1531 buf += buf_put1(buf, (unsigned char) n);
1532 buf += buf_put4(buf, image_chunk_size); 1532 buf += buf_put4(buf, image_chunk_size);
1533 1533
1534 for (i = 0; i < n; i++) { 1534 for (i = 0; i < n; i++) {
1535 // Find next used entry in image_map 1535 // Find next used entry in image_map
1536 while (image_map[index] != 'x' && index < image_map_size) 1536 while (image_map[img_index] != 'x' && img_index < image_map_size)
1537 index++; 1537 img_index++;
1538 1538
1539 if (index == image_map_size) 1539 if (img_index == image_map_size)
1540 break; 1540 break;
1541 1541
1542 addr = index * image_chunk_size; 1542 addr = img_index * image_chunk_size;
1543 block[i].index = index; 1543 block[i].index = img_index;
1544 block[i].addr = addr; 1544 block[i].addr = addr;
1545 1545
1546 buf += buf_put4(buf, addr); 1546 buf += buf_put4(buf, addr);
1547 1547
1548 index++; 1548 img_index++;
1549 } 1549 }
1550 target_send(sendbuf, buf - sendbuf); 1550 target_send(sendbuf, buf - sendbuf);
1551 1551
1552 // Compute checksums while we wait for reply 1552 // Compute checksums while we wait for reply
1553 for (i = 0; i < n; i++) { 1553 for (i = 0; i < n; i++) {
1554 index = block[i].index; 1554 img_index = block[i].index;
1555 addr = block[i].addr; 1555 addr = block[i].addr;
1556 for (j = 0, mycksum = 0; j < image_chunk_size; j += 2) { 1556 for (j = 0, mycksum = 0; j < image_chunk_size; j += 2) {
1557 word = (image[addr + j + 1] << 8) | image[addr + j + 0]; 1557 word = (image[addr + j + 1] << 8) | image[addr + j + 0];
1558 mycksum += word * ((addr + j) & 0xFFFF); 1558 mycksum += word * ((addr + j) & 0xFFFF);
1559 } 1559 }
1560 block[i].mycksum = mycksum; 1560 block[i].mycksum = mycksum;
1565 1565
1566 for (i = 0; i < n; i++) { 1566 for (i = 0; i < n; i++) {
1567 target_recv(data, 4); 1567 target_recv(data, 4);
1568 cksum = data[0] + (data[1] << 8) + (data[2] << 16) + (data[3] << 24); 1568 cksum = data[0] + (data[1] << 8) + (data[2] << 16) + (data[3] << 24);
1569 mycksum = block[i].mycksum; 1569 mycksum = block[i].mycksum;
1570 index = block[i].index; 1570 img_index = block[i].index;
1571 1571
1572 if (cksum == mycksum) 1572 if (cksum == mycksum)
1573 image_map[index] = 'c'; 1573 image_map[img_index] = 'c';
1574 1574
1575 if (arg_checksum_show) { 1575 if (arg_checksum_show) {
1576 // This is a far from perfect dump of checksums... We don't know 1576 // This is a far from perfect dump of checksums... We don't know
1577 // the exact block number of each checksum in a line. 1577 // the exact block number of each checksum in a line.
1578 if (line != (int) index / 4) { 1578 if (line != (int) img_index / 4) {
1579 flowf(NORMAL, "\n%4d:", index); 1579 flowf(NORMAL, "\n%4d:", img_index);
1580 line = index / 4; 1580 line = img_index / 4;
1581 } 1581 }
1582 if (cksum == mycksum) 1582 if (cksum == mycksum)
1583 flowf(NORMAL, "%08X ", cksum); 1583 flowf(NORMAL, "%08X ", cksum);
1584 else 1584 else
1585 flowf(NORMAL, "%08X/%08X ", cksum, mycksum); 1585 flowf(NORMAL, "%08X/%08X ", cksum, mycksum);
1586 1586
1587 } 1587 }
1588 else if (arg_verbose >= VERBOSE) { 1588 else if (arg_verbose >= VERBOSE) {
1589 flowf(VERBOSE, "%c", (image_map[index] == 'c' ? 'c' : '.')); 1589 flowf(VERBOSE, "%c", (image_map[img_index] == 'c' ? 'c' : '.'));
1590 } 1590 }
1591 } 1591 }
1592 index++; 1592 img_index++;
1593 chunks -= n; 1593 chunks -= n;
1594 } 1594 }
1595 time_checksum = (stopwatch_stop(time_checksum) + 50) / 100; 1595 time_checksum = (stopwatch_stop(time_checksum) + 50) / 100;
1596 flowf(BLABBER, " (%d.%ds)", time_checksum / 10, time_checksum % 10); 1596 flowf(BLABBER, " (%d.%ds)", time_checksum / 10, time_checksum % 10);
1597 flowf(NORMAL, " ok\n"); 1597 flowf(NORMAL, " ok\n");
1602 * Flash Program 1602 * Flash Program
1603 ******************************************************************************/ 1603 ******************************************************************************/
1604 1604
1605 int time_program; 1605 int time_program;
1606 int programs_recv, programs_send, erasures; 1606 int programs_recv, programs_send, erasures;
1607 int index, src_size; 1607 int img_index, src_size;
1608 uint32 dst; 1608 uint32 dst;
1609 char *src; 1609 char *src;
1610 1610
1611 void flash_erase_machine(void); 1611 void flash_erase_machine(void);
1612 int flash_operation_wait(int delay); 1612 int flash_operation_wait(int delay);
1619 int expected, chunks, total_size, sectors; 1619 int expected, chunks, total_size, sectors;
1620 int image_chunk_size_old = image_chunk_size; 1620 int image_chunk_size_old = image_chunk_size;
1621 char ch; 1621 char ch;
1622 1622
1623 programs_recv = programs_send = erasures = 0; 1623 programs_recv = programs_send = erasures = 0;
1624 index = 0; 1624 img_index = 0;
1625 1625
1626 // Prepare erase 1626 // Prepare erase
1627 erase_list_size = sectors = sector_map_init(); 1627 erase_list_size = sectors = sector_map_init();
1628 i = image_map_count_used_chunks(); 1628 i = image_map_count_used_chunks();
1629 1629
1794 int flash_program_next(void) 1794 int flash_program_next(void)
1795 { 1795 {
1796 int oldindex; 1796 int oldindex;
1797 1797
1798 // Find next used entry in image_map 1798 // Find next used entry in image_map
1799 while (index < image_map_size && image_map[index] != 'x') 1799 while (img_index < image_map_size && image_map[img_index] != 'x')
1800 index++; 1800 img_index++;
1801 1801
1802 oldindex = index; 1802 oldindex = img_index;
1803 1803
1804 if (index < image_map_size) { 1804 if (img_index < image_map_size) {
1805 dst = index * image_chunk_size; 1805 dst = img_index * image_chunk_size;
1806 if (arg_compress) { 1806 if (arg_compress) {
1807 src_size = compress(src, &image[dst], image_chunk_size); 1807 src_size = compress(src, &image[dst], image_chunk_size);
1808 } 1808 }
1809 else { 1809 else {
1810 src = &image[dst]; 1810 src = &image[dst];
1811 src_size = image_chunk_size; 1811 src_size = image_chunk_size;
1812 } 1812 }
1813 index++; 1813 img_index++;
1814 } 1814 }
1815 else { 1815 else {
1816 dst = 0xFFFFFFFF; 1816 dst = 0xFFFFFFFF;
1817 src_size = 0; 1817 src_size = 0;
1818 } 1818 }