void writeboot(FILE* infile, memory_context_t *mem_c, int page) { INTELHEX_t ihex; if (!infile) return; if (page == -1) page += mem_c->flash_pages; // last page is boot page unsigned char (*flash)[PAGE_SIZE] = (uint8_t(*)[PAGE_SIZE]) mem_c->flash; for (;;) { if (!ReadIntelHex(infile, &ihex)) { return; } switch(ihex.Type) { case 0x00: memcpy(flash[page] + (ihex.Address & 0x3FFF), ihex.Data, ihex.DataSize); break; case 0x02: break; default: return; } } }
TIFILE_t* ImportFlashFile(FILE *infile, TIFILE_t *tifile) { int i; for(i = 0; i < 256; i++) { tifile->flash->pagesize[i] = 0; tifile->flash->data[i] = NULL; } INTELHEX_t record; int CurrentPage = -1; int HighestAddress = 0; int TotalSize = 0; int TotalPages = 0; int done = 0; if (tifile->flash->type == FLASH_TYPE_OS) { // Find the first page, usually after the first line do { if (!ReadIntelHex(infile, &record)) { FreeTiFile(tifile); return NULL; } } while (record.Type != 0x02 || record.DataSize != 2); CurrentPage = ((record.Data[0] << 8) | record.Data[1]) & 0x7F; if (tifile->flash->data[CurrentPage] == 0) { tifile->flash->data[CurrentPage] = (unsigned char *) malloc(PAGE_SIZE); if (tifile->flash->data[CurrentPage] == NULL) { FreeTiFile(tifile); return NULL; } memset(tifile->flash->data[CurrentPage], 0, PAGE_SIZE); //THIS IS IMPORTANT FOR LINKING, APPS FOR NOW } HighestAddress = 0; } while (!feof( infile ) && !done) { ReadIntelHex(infile, &record); switch ( record.Type ) { case 00: if (CurrentPage > -1) { for(i = 0; (i < record.DataSize) && (((i + record.Address) & 0x3FFF) < PAGE_SIZE); i++) { tifile->flash->data[CurrentPage][(i + record.Address) & 0x3FFF] = record.Data[i]; } if ( HighestAddress < i + record.Address ) HighestAddress = (int) (i + record.Address); } break; case 01: done = 1; if (CurrentPage == -1) { printf("invalid current page\n"); FreeTiFile(tifile); return NULL; } TotalSize += (HighestAddress - PAGE_SIZE); tifile->flash->pagesize[CurrentPage] = (HighestAddress - PAGE_SIZE); tifile->flash->pages = TotalPages; break; case 02: if (CurrentPage > -1) { TotalSize += PAGE_SIZE; tifile->flash->pagesize[CurrentPage] = (HighestAddress - PAGE_SIZE); } TotalPages++; CurrentPage = ((record.Data[0] << 8) | record.Data[1]) & 0x7F; if (tifile->flash->data[CurrentPage] == 0) { tifile->flash->data[CurrentPage] = (unsigned char *) malloc(PAGE_SIZE); if (tifile->flash->data[CurrentPage] == NULL) { FreeTiFile(tifile); return NULL; } memset(tifile->flash->data[CurrentPage], 0, PAGE_SIZE); //THIS IS IMPORTANT FOR LINKING, APPS FOR NOW } HighestAddress = 0; break; default: printf("unknown record\n"); FreeTiFile(tifile); return NULL; } } if (tifile->flash->device == 0x74) { tifile->model = TI_73; } else if (tifile->flash->device == 0x73) { tifile->model = TI_83P; } else { FreeTiFile(tifile); return NULL; } return tifile; }