From 656192fc149241be366299c14ab6d543620e03ef Mon Sep 17 00:00:00 2001 From: David Voswinkel Date: Tue, 30 Jun 2009 23:04:24 +0200 Subject: [PATCH] crc checks working, simple uploads working --- avr/usbload/commandline/snesuploader | Bin 18552 -> 18596 bytes avr/usbload/commandline/snesuploader.c | 74 +++++++++++++------------ avr/usbload/config.h | 1 + avr/usbload/crc.c | 12 ++-- avr/usbload/main.c | 8 +-- avr/usbload/usbconfig.h | 4 +- 6 files changed, 53 insertions(+), 46 deletions(-) diff --git a/avr/usbload/commandline/snesuploader b/avr/usbload/commandline/snesuploader index efc207e23e9080a5593b304cd7218894b25dab16..3eeec65e710fc1348390fce3a3b51e0fd9f517d2 100755 GIT binary patch delta 2685 zcmZ`*4NMbf82;`kqeZk-{whCh#ZuiIN_2|^bOGeRIh{YOif-UkAn}(3!Qqs(vm;tA zRmqo_xMe1DYBVv7hyt5r;vf>ujJn0d__LVJpCX$f69pCRp7(lnN1{!8_uTXTJ@5N{ z*Sn!T!ofyi&#}ni6vpNo856?iCQzu*Q z^&eQmkA-E5!znyhi2r^#ERvgz*%QK385{5;6DtlhUo_|}}505mynZk2o zE5+oX@ovZ%OzTbNw_-P#Qb()BBpc-$mCQ@yvP_FZtkXskI+OU(IE#2AiJyzxE$%V! z3tcdr?71xy;3(eNV;68M=3Pe7jn_)Tn4{TruTxFxuMyq#5cpl zqH$TET%JG|db-A$?i8idcZCGLC^6R+N6}IT(PyPD((J86`+ggRD)pIO9k8bUe#}Ca zZj?!7^_^R?{2qYUs}mF%in?ilA$8Z|C{eROTJ&yY zMFy8nmfER}docRii1ln}cMqNo;NPakN%d)RvhxJp2B)3{0>(B{811dLNBMTR`vU>e zVQiJUaK=6`(X^27JEa(n0=ZnsWq2WVQ5t8vx4&Yt)KTHt(B!UgeOcGU+|?1@!QN}w z9qzg=p*r1L(;-XU$TwmRw7{4e>6nP*SgGBdHWbQ3^~=SjNYppLmQ& zVn;dng=9T9B*(a9m`NnvO<1%^{%xcHI#6Pw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andline/snesuploader.c index 6aa8f3f..8f038ad 100644 --- a/avr/usbload/commandline/snesuploader.c +++ b/avr/usbload/commandline/snesuploader.c @@ -17,7 +17,6 @@ #define READ_BUFFER_SIZE (1024 * 32) #define SEND_BUFFER_SIZE 128 -#define BUFFER_CRC (1024 * 32) #define BANK_SIZE (1<<15) #define BANK_SIZE_SHIFT 15 @@ -119,20 +118,19 @@ int main(int argc, char **argv) USB_CFG_DEVICE_ID}; char vendor[] = { USB_CFG_VENDOR_NAME, 0 }, product[] = { USB_CFG_DEVICE_NAME, 0}; - int cnt, - vid, - pid; - int cnt_crc = 0; + int cnt, vid, pid; uint8_t *read_buffer; uint8_t *crc_buffer; + uint8_t *ptr; + uint32_t addr = 0; uint16_t addr_lo = 0; uint16_t addr_hi = 0; uint16_t step = 0; uint16_t crc = 0; uint8_t bank = 0; + FILE *fp; - usb_init(); if (argc < 2) { /* we need at least one argument */ usage(argv[0]); @@ -167,58 +165,64 @@ int main(int argc, char **argv) exit(1); } read_buffer = (unsigned char *) malloc(READ_BUFFER_SIZE); - crc_buffer = (unsigned char *) malloc(BUFFER_CRC); - memset(crc_buffer, 0, BUFFER_CRC); + crc_buffer = (unsigned char *) malloc(0x1000); + memset(crc_buffer, 0, 0x1000); addr = 0x000000; - usb_control_msg(handle, + cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, USB_UPLOAD_INIT, BANK_SIZE_SHIFT , 0, NULL, 0, 5000); - + if (cnt < 0) { + fprintf(stderr, "USB error: %s\n", usb_strerror()); + usb_close(handle); + exit(-1); + } + ptr = crc_buffer; while ((cnt = fread(read_buffer, READ_BUFFER_SIZE, 1, fp)) > 0) { - for (step = 0; step <= READ_BUFFER_SIZE; step += SEND_BUFFER_SIZE) { + ptr = crc_buffer; + for (step = 0; step < READ_BUFFER_SIZE; step += SEND_BUFFER_SIZE) { + + addr_lo = addr & 0xffff; - addr_hi = (addr >> 16) & 0xff; + addr_hi = (addr >> 16) & 0x00ff; cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, USB_UPLOAD_ADDR, addr_hi, addr_lo, (char *) read_buffer + step, SEND_BUFFER_SIZE, 5000); - if (addr%0x1000==0){ - printf ("bank=0x%02x addr=0x%08x\n", bank, addr); - } if (cnt < 0) { fprintf(stderr, "USB error: %s\n", usb_strerror()); usb_close(handle); exit(-1); } + + memcpy(ptr, read_buffer + step, SEND_BUFFER_SIZE); addr += SEND_BUFFER_SIZE; - //break; + ptr += SEND_BUFFER_SIZE; + if ( addr % 0x1000 == 0){ + crc = do_crc(crc_buffer, 0x1000); + printf ("bank=0x%02x addr=0x%08x addr=0x%08x crc=0x%04x\n", bank, addr - 0x1000, addr, crc); + ptr = crc_buffer; + if ( addr % 0x8000 == 0) { + bank++; + + } + } } - //dump_packet(0x00000,SEND_BUFFER_SIZE, read_buffer); - memcpy(crc_buffer + cnt_crc, read_buffer, READ_BUFFER_SIZE); - cnt_crc += READ_BUFFER_SIZE; - if (cnt_crc >= READ_BUFFER_SIZE) { - crc = do_crc(crc_buffer, READ_BUFFER_SIZE); - printf ("bank=0x%02x crc=0x%04x\n", bank, crc); - memset(crc_buffer, 0, BUFFER_CRC); - bank++; - cnt_crc = 0; + if (bank == 1) break; - } - - //break; } + bank = 0; + + fseek(fp, 0, SEEK_SET); + while ((cnt = fread(read_buffer, READ_BUFFER_SIZE, 1, fp)) > 0) { + printf ("bank=0x%02x crc=0x%04x\n", bank++, + do_crc(read_buffer, READ_BUFFER_SIZE)); + } + fclose(fp); - /* - - cnt = usb_control_msg(handle, - USB_TYPE_VENDOR | USB_RECIP_DEVICE | - USB_ENDPOINT_OUT, USB_CRC, addr_hi, addr_lo, NULL, - 0, 5000); - */ cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, USB_SNES_BOOT, 0, 0, NULL, diff --git a/avr/usbload/config.h b/avr/usbload/config.h index 1377182..44e1e86 100644 --- a/avr/usbload/config.h +++ b/avr/usbload/config.h @@ -8,6 +8,7 @@ #define DEBUG_SRAM 8 #define DEBUG_SRAM_RAW 16 #define DEBUG_SREG 32 +#define DEBUG_CRC 64 #define REQ_STATUS_IDLE 0x01 #define REQ_STATUS_UPLOAD 0x02 diff --git a/avr/usbload/crc.c b/avr/usbload/crc.c index ef3ea5b..a5900ed 100644 --- a/avr/usbload/crc.c +++ b/avr/usbload/crc.c @@ -5,6 +5,7 @@ #include "uart.h" #include "config.h" #include "sram.h" +#include "debug.h" extern FILE uart_stdout; @@ -48,12 +49,13 @@ uint16_t crc_check_bulk_memory(uint32_t bottom_addr,uint32_t top_addr) uint32_t addr = 0; uint8_t req_bank = 0; sram_bulk_read_start(bottom_addr); - printf("crc_check_bulk_memory: bottom_addr=0x%08lx top_addr=0x%08lx\n", - bottom_addr, top_addr); + + //debug(DEBUG_CRC,"crc_check_bulk_memory: bottom_addr=0x%08lx top_addr=0x%08lx\n", + // bottom_addr, top_addr); for (addr = bottom_addr; addr < top_addr; addr++) { if (addr && addr % 0x8000 == 0) { - printf("crc_check_bulk_memory: bank=0x%02x addr=0x%08lx crc=0x%04x\n", + debug(DEBUG_CRC,"crc_check_bulk_memory: bank=0x%02x addr=0x%08lx crc=0x%04x\n", req_bank,addr,crc); req_bank++; crc = 0; @@ -62,7 +64,7 @@ uint16_t crc_check_bulk_memory(uint32_t bottom_addr,uint32_t top_addr) sram_bulk_read_next(); } if (addr % 0x8000 == 0) - printf("crc_check_bulk_memory: bank=0x%02x addr=0x%08lx crc=0x%04x\n", + debug(DEBUG_CRC,"crc_check_bulk_memory: bank=0x%02x addr=0x%08lx crc=0x%04x\n", req_bank,addr,crc); sram_bulk_read_end(); return crc; @@ -77,7 +79,7 @@ void crc_check_memory(uint32_t bottom_addr,uint32_t top_addr,uint8_t *buffer) uint8_t req_bank = 0; for (addr = bottom_addr; addr < top_addr; addr += TRANSFER_BUFFER_SIZE) { if (addr && addr % 0x8000 == 0) { - printf("crc_check_memory: bank=0x%02x addr=0x%08lx crc=0x%04x\n", + debug(DEBUG_CRC,"crc_check_memory: bank=0x%02x addr=0x%08lx crc=0x%04x\n", req_bank,addr,crc); req_bank++; crc = 0; diff --git a/avr/usbload/main.c b/avr/usbload/main.c index d4436c4..945ce3c 100644 --- a/avr/usbload/main.c +++ b/avr/usbload/main.c @@ -18,7 +18,7 @@ extern FILE uart_stdout; -uint8_t debug_level = ( DEBUG | DEBUG_USB); +uint8_t debug_level = ( DEBUG | DEBUG_USB | DEBUG_CRC ); uint8_t read_buffer[TRANSFER_BUFFER_SIZE]; uint32_t req_addr = 0; @@ -75,10 +75,10 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) rx_remaining = rq->wLength.word; ret_len = USB_MAX_TRANS; + if (req_addr && (req_addr % 0x1000) == 0) { - debug(DEBUG_USB,"USB_UPLOAD_ADDR: bank=0x%02x addr=0x%08lx\n", - req_bank, req_addr); - crc_check_bulk_memory(req_addr - 0x1000,req_addr); + debug(DEBUG_USB,"USB_UPLOAD_ADDR: bank=0x%02x addr=0x%08lx crc=%04x\n", + req_bank, req_addr,crc_check_bulk_memory(req_addr - 0x1000,req_addr)); } if (req_addr && req_addr % req_bank_size == 0) { diff --git a/avr/usbload/usbconfig.h b/avr/usbload/usbconfig.h index 1afdae5..37ad803 100644 --- a/avr/usbload/usbconfig.h +++ b/avr/usbload/usbconfig.h @@ -105,7 +105,7 @@ section at the end of this file). * (e.g. HID), but never want to send any data. This option saves a couple * of bytes in flash memory and the transmit buffers in RAM. */ -#define USB_CFG_INTR_POLL_INTERVAL 10 +#define USB_CFG_INTR_POLL_INTERVAL 200 /* If you compile a version with endpoint 1 (interrupt-in), this is the poll * interval. The value is in milliseconds and must not be less than 10 ms for * low speed devices. @@ -114,7 +114,7 @@ section at the end of this file). /* Define this to 1 if the device has its own power supply. Set it to 0 if the * device is powered from the USB bus. */ -#define USB_CFG_MAX_BUS_POWER 200 +#define USB_CFG_MAX_BUS_POWER 300 /* Set this variable to the maximum USB bus power consumption of your device. * The value is in milliamperes. [It will be divided by two since USB * communicates power requirements in units of 2 mA.]