X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=lib%2Fccdbg-flash.c;h=3e6729851502ff8895a6e2088836284035f7702c;hb=17d2432a8b9c15963cd3b821f025ad33972ef477;hp=8b3390c7787719b203983b25943bf7ff57577938;hpb=ea366058aa467a8a7caf17e7014758f3741ea7f7;p=fw%2Faltos diff --git a/lib/ccdbg-flash.c b/lib/ccdbg-flash.c index 8b3390c7..3e672985 100644 --- a/lib/ccdbg-flash.c +++ b/lib/ccdbg-flash.c @@ -37,10 +37,10 @@ static uint8_t flash_page[] = { MOV_Rn_data(7), 0, #define FLASH_WORDS_HIGH 16 - + MOV_Rn_data(6), 0, #define FLASH_WORDS_LOW 18 - + MOV_direct_data, FWT, 0x20, #define FLASH_TIMING 21 @@ -76,7 +76,7 @@ static uint8_t flash_page[] = { static uint8_t flash_erase_page[] = { 3, MOV_direct_data, FADDRH, 0, #define ERASE_PAGE_HIGH 3 - + 3, MOV_direct_data, FADDRL, 0, #define ERASE_PAGE_LOW 7 @@ -107,7 +107,7 @@ ccdbg_flash_erase_page(struct ccdbg *dbg, uint16_t addr) uint8_t status; uint8_t old[0x10], new[0x10]; int i; - + ccdbg_read_memory(dbg, addr, old, 0x10); flash_erase_page[ERASE_PAGE_HIGH] = page_addr >> 8; flash_erase_page[ERASE_PAGE_LOW] = page_addr & 0xff; @@ -130,7 +130,7 @@ ccdbg_flash_erase_page(struct ccdbg *dbg, uint16_t addr) static uint8_t flash_write[] = { MOV_direct_data, P1DIR, 0x02, MOV_direct_data, P1, 0xFD, - + MOV_A_direct, FCTL, JB, ACC(FCTL_BUSY_BIT), 0xf1, @@ -138,10 +138,10 @@ static uint8_t flash_write[] = { MOV_direct_data, FADDRH, 0, #define WRITE_PAGE_HIGH 16 - + MOV_direct_data, FADDRL, 0, #define WRITE_PAGE_LOW 19 - + MOV_direct_data, FCTL, FCTL_WRITE, MOV_direct_data, FWDATA, 0, #define WRITE_BYTE_0 25 @@ -267,7 +267,7 @@ ccdbg_flash_hex_image(struct ccdbg *dbg, struct hex_image *image) } ram_addr = 0xf000; - + flash_prog = 0xf400; fwt = 0x20; @@ -276,7 +276,7 @@ ccdbg_flash_hex_image(struct ccdbg *dbg, struct hex_image *image) ccdbg_debug(CC_DEBUG_FLASH, "Upload %d flash program bytes to 0x%04x\n", sizeof (flash_page), flash_prog); ccdbg_write_memory(dbg, flash_prog, flash_page, sizeof(flash_page)); - + remain = image->length; start = 0; while (remain) { @@ -288,14 +288,15 @@ ccdbg_flash_hex_image(struct ccdbg *dbg, struct hex_image *image) ccdbg_debug(CC_DEBUG_FLASH, "Upload %d bytes at 0x%04x\n", this_time, ram_addr); ccdbg_write_memory(dbg, ram_addr, image->data + start, this_time); - +#if 0 ccdbg_debug(CC_DEBUG_FLASH, "Verify %d bytes in ram\n", this_time); ccdbg_read_memory(dbg, ram_addr, verify, this_time); if (memcmp (image->data + start, verify, this_time) != 0) { fprintf(stderr, "ram verify failed\n"); return 1; } - +#endif + flash_addr = image->address + start; flash_word_addr = flash_addr >> 1; flash_len = this_time + (this_time & 1); @@ -303,11 +304,11 @@ ccdbg_flash_hex_image(struct ccdbg *dbg, struct hex_image *image) flash_words_low = flash_words & 0xff; flash_words_high = flash_words >> 8; - + /* The flash code above is lame */ if (flash_words_low) flash_words_high++; - + ccdbg_write_uint8(dbg, flash_prog + FLASH_ADDR_HIGH, flash_word_addr >> 8); ccdbg_write_uint8(dbg, flash_prog + FLASH_ADDR_LOW, flash_word_addr & 0xff); @@ -324,15 +325,18 @@ ccdbg_flash_hex_image(struct ccdbg *dbg, struct hex_image *image) status = ccdbg_resume(dbg); for (times = 0; times < 10; times++) { status = ccdbg_read_status(dbg); - ccdbg_debug(CC_DEBUG_FLASH, "chip status is 0x%02x\n", status); + ccdbg_debug(CC_DEBUG_FLASH, "."); + ccdbg_flush(CC_DEBUG_FLASH); if ((status & CC_STATUS_CPU_HALTED) != 0) break; + usleep(10000); } + ccdbg_debug(CC_DEBUG_FLASH, "\n"); if (times == 10) { fprintf(stderr, "flash page timed out\n"); return 1; } - + ccdbg_debug(CC_DEBUG_FLASH, "Verify %d bytes in flash\n", this_time); ccdbg_read_memory(dbg, flash_addr, verify, this_time); if (memcmp (image->data + start, verify, this_time) != 0) {