support get serial request in the flasher

master
George Hotz 2017-05-03 17:07:06 -07:00
parent 43b64091ef
commit a5df04e444
3 changed files with 19 additions and 9 deletions

View File

@ -56,7 +56,7 @@ endif
obj/cert.h: ../crypto/getcertheader.py
../crypto/getcertheader.py ../certs/debug.pub ../certs/release.pub > $@
obj/bootstub.$(PROJ_NAME).o: bootstub.c early.h obj/cert.h
obj/bootstub.$(PROJ_NAME).o: bootstub.c early.h obj/cert.h spi_flasher.h
$(CC) $(CFLAGS) -o $@ -c $<
obj/main.$(PROJ_NAME).o: main.c *.h obj/gitversion.h

View File

@ -77,3 +77,11 @@ void *memcpy(void *dest, const void *src, unsigned int n) {
return dest;
}
int memcmp(const void * ptr1, const void * ptr2, unsigned int num) {
int i;
for (i = 0; i < num; i++) {
if ( ((uint8_t*)ptr1)[i] != ((uint8_t*)ptr2)[i] ) return -1;
}
return 0;
}

View File

@ -53,6 +53,8 @@ void spi_flasher() {
lastval = val;
if (rcv && (DMA2->LISR & DMA_LISR_TCIF2)) {
DMA2->LIFCR = DMA_LIFCR_CTCIF2;
rcv = 0;
memset(spi_tx_buf, 0, 0x44);
spi_tx_buf[0x40] = 0xde;
@ -60,12 +62,14 @@ void spi_flasher() {
spi_tx_buf[0x42] = 0xd0;
spi_tx_buf[0x43] = 0x0d;
*(uint32_t*)(&spi_tx_buf[4]) = FLASH->CR;
*(uint32_t*)(&spi_tx_buf[8]) = (uint32_t)prog_ptr;
if (spi_rx_buf[0] == (0xff^spi_rx_buf[1]) &&
spi_rx_buf[2] == (0xff^spi_rx_buf[3])) {
if (memcmp("\x00\x00\x00\x00\x40\xD0\x00\x00\x00\x00\x20\x00", spi_rx_buf, 0xC) == 0) {
*(uint32_t*)(&spi_tx_buf[0]) = 0x20;
memcpy(spi_tx_buf+4, (void *)0x1fff79e0, 0x20);
} else if (spi_rx_buf[0] == (0xff^spi_rx_buf[1]) &&
spi_rx_buf[2] == (0xff^spi_rx_buf[3])) {
spi_tx_buf[0] = 0xff;
*(uint32_t*)(&spi_tx_buf[4]) = FLASH->CR;
*(uint32_t*)(&spi_tx_buf[8]) = (uint32_t)prog_ptr;
// valid
switch (spi_rx_buf[0]) {
case 0x10:
@ -114,11 +118,9 @@ void spi_flasher() {
default:
break;
}
memcpy(spi_tx_buf+0x10, spi_rx_buf, 0x14);
}
memcpy(spi_tx_buf+0x10, spi_rx_buf, 0x14);
DMA2->LIFCR = DMA_LIFCR_CTCIF2;
spi_tx_dma(spi_tx_buf, 0x44);
// signal data is ready by driving low