static bool is_ut_rom(void) { int len = 0; int c = 0; int i = 0; char *main_version, *sku_version; if(!rom_version) { if(!get_rom_version()) { pr_err("[smem]%s: no ROM version.\n", __func__); return false; } } main_version = strstr(rom_version, "."); if(!main_version || strlen(main_version+1) == 0) { pr_err("[smem]%s: no main version.\n", __func__); return false; } sku_version = strstr(main_version+1, ".") + 1; if(!sku_version || strlen(sku_version+1) == 0) { pr_err("[smem]%s: no sku version.\n", __func__); return false; } len = strlen(sku_version); for(i = 0; i < len; i++){ if(isdigit(sku_version[i])) c++; else break; } if(sku_version[0] == UT_LONG_SKU_FIRST_NUM && c == UT_LONG_SKU_LEN) return true; if( strstr(sku_version, UT_SHORT_SKU_NUM) && c == strlen(UT_SHORT_SKU_NUM)) return true; return false; }
/* Get some information on the FLASH upgrade: - size - ROM base address - os version - calc type */ int ti68k_get_tib_infos(const char *filename, IMG_INFO *tib, int preload) { FlashContent *content; FlashContent *ptr; int nheaders = 0; int i; // No filename, exits if(!strcmp(g_basename(filename), "")) return ERR_CANT_OPEN; // Check valid file if(!tifiles_file_is_ti(filename)) return ERR_NOT_TI_FILE; if(!tifiles_file_is_os(filename)) return ERR_INVALID_UPGRADE; // Load file content = tifiles_content_create_flash(CALC_TI89); if(tifiles_file_read_flash(filename, content) != 0) return ERR_INVALID_UPGRADE; // count headers for (ptr = content; ptr != NULL; ptr = ptr->next) nheaders++; // keep the last one (data) for (i = 0, ptr = content; i < nheaders - 1; i++) ptr = ptr->next; // Load TIB into memory and relocate at SPP if(tib->data == NULL) tib->data = malloc(SPP + ptr->data_length + 4); if(tib->data == NULL) return ERR_MALLOC; memset(tib->data + SPP, 0xff, ptr->data_length); memcpy(tib->data + SPP, ptr->data_part, ptr->data_length); // Update current rom infos tib->rom_base = tib->data[BO+5 + SPP] & 0xf0; // libtifiles can't distinguish TI89/TI89t and 92+/V200. We need to look. switch(ptr->device_type & 0xff) { case DEVICE_TYPE_89: // can be a Titanium, too switch(tib->rom_base & 0xff) { case 0x20: tib->calc_type = TI89; break; case 0x80: tib->calc_type = TI89t; break; default: return ERR_INVALID_UPGRADE; } break; case DEVICE_TYPE_92P: switch(tib->rom_base & 0xff) { case 0x20: tib->calc_type = V200; break; case 0x40: tib->calc_type = TI92p; break; default: return ERR_INVALID_UPGRADE; } break; default: tiemu_info("TIB problem: %02x!\n", 0xff & ptr->device_type); return ERR_INVALID_UPGRADE; break; } tib->flash = FLASH_ROM; tib->has_boot = 0; tib->size = ptr->data_length + SPP; get_rom_version(tib->data, tib->size, tib->version); tifiles_content_delete_flash(content); if(!preload) free(tib->data); return 0; }
/* Get some information on the ROM dump: - size - ROM base address - FLASH/EPROM - os version - calc type Note: if the data field is NULL, memory is allocated. Otherwise, data is overwritten. Thanks to Kevin for HW2 detection code. */ int ti68k_get_rom_infos(const char *filename, IMG_INFO *rom, int preload) { FILE *file; HW_PARM_BLOCK hwblock; // No filename, exits if(!strcmp(g_basename(filename), "")) return ERR_CANT_OPEN; // Open file file = fopen(filename, "rb"); if(file == NULL) { tiemu_info(_("Unable to open this file: <%s>"), filename); return ERR_CANT_OPEN; } // Retrieve ROM size fseek(file, 0, SEEK_END); rom->size = ftell(file); fseek(file, 0, SEEK_SET); if(rom->size < 256) return ERR_INVALID_ROM_SIZE; if (rom->size == 8*MB) { // TiLP used to dump 8 MB images for HW4, try to load them anyway. tiemu_info(_("Warning: truncating 8 MB image to 4 MB: <%s>"), filename); rom->size = 4*MB; } if (rom->size > 4*MB) return ERR_INVALID_ROM_SIZE; if(rom->data == NULL) rom->data = malloc(rom->size + 4); if(rom->data == NULL) return ERR_MALLOC; memset(rom->data, 0xff, rom->size); if (fread(rom->data, 1, rom->size, file) < (size_t)rom->size) { tiemu_info(_("Failed to read from file: <%s>"), filename); fclose(file); return ERR_CANT_OPEN; } if (fclose(file)) { tiemu_info(_("Failed to close file: <%s>"), filename); return ERR_CANT_OPEN; } rom->has_boot = 1; rom->rom_base = rom->data[0x05] & 0xf0; rom->flash = (rom->data[0x65] & 0x0f) ? 0 : FLASH_ROM; get_rom_version(rom->data, rom->size, rom->version); if(!rom->flash) { rom->calc_type = TI92; rom->hw_type = HW1; } else { // Get hw param block to determine calc type & hw type if(ti68k_get_hw_param_block((uint8_t*)rom->data, rom->rom_base, &hwblock) == -1) return ERR_INVALID_ROM; ti68k_display_hw_param_block(&hwblock); switch(hwblock.hardwareID) { case HWID_TI92P: rom->calc_type = TI92p; break; case HWID_TI89: rom->calc_type = TI89; break; case HWID_V200: rom->calc_type = V200; break; case HWID_TI89T: rom->calc_type = TI89t; break; default: break; } if(rom->flash) { if(hwblock.len < 24) rom->hw_type = HW1; else rom->hw_type = (char)hwblock.gateArray; } } if(!preload) free(rom->data); return 0; }