Ejemplo n.º 1
0
/* Fixes the certificate page so that the app is no longer marked as a trial
 * cpu: cpu for the core the application is on
 * page: the page the application you want to mark is on
 */
void fix_certificate(TilemCalc* calc, u_int page) {

	u_char (*dest)[PAGE_SIZE_W] = (u_char (*)[PAGE_SIZE_W]) calc->mem;
	upages_t upages;
	state_userpages(calc, &upages);
	//there is probably some logic here that I'm missing...
	//the 83p wtf is up with that offset
	int offset = 0x1E50;
	if (calc->hw.model_id == TILEM_CALC_TI83P)
		offset = 0x1F18;
	//erase the part of the certificate that marks it as a trial app
	dest[FLASH_PAGES(calc) - 2][offset + 2 * (upages.start - page)] = 0x80;
	dest[FLASH_PAGES(calc) - 2][offset + 1 + 2 * (upages.start - page)] = 0x00;
}
Ejemplo n.º 2
0
// Verifies that update-start command is valid.
// Will enter RECEIVING_FIRMWARE state if everything checks out.
static void startFirmwareUpdate()
{
  uint8_t i, checksum = 0;//, reset_vector[3];
              
  // Calculate checksum
  for (i = 0; i < UPDATE_START_LENGTH; i++) {
    checksum += MSG_PAYLOAD(i);
  }
  // Checksum fail
  if (checksum != 0) {
    send_buf[1] = ERROR_CHECKSUM_FAIL;
    send(CMD_NACK,2);
    return;
  }

  // Get firmware size, NOT including reset vector
  bytes_total = MSG_ST_BYTES;
  // Check that firmware is within legal size range.
  if (bytes_total > FLASH_FW_MAX_SIZE) {
    // Send error report to host.
    send_buf[1] = ERROR_ILLEGAL_SIZE;
    send(CMD_NACK,2);
    return;
  }

  // Get firmware's reset vector. 
  temp_data[0] = MSG_ST_RESET_OPCODE;
  temp_data[1] = MSG_ST_RESET_ADDR_H;
  temp_data[2] = MSG_ST_RESET_ADDR_L;
  // Write reset vector to non-volatile flash
  flash_erase_page(FW_NV_DATA_PAGE);
  flash_write_bytes(FW_RESET_VECTOR, temp_data, 3);
  // Get firmware serial number. Will be written to NV when update complete.
  firmware_number = MSG_ST_NUMBER;
  bytes_received = 0;
/*
  // Read out old reset vector.
  movx_access_code();
  flash_read_bytes(0x0000, reset_vector, 3);
  movx_access_data();
  // Erase first page, containing reset vector.
  flash_erase_page(0);
  // Write back the old reset vector.
  movx_access_code();
  flash_write_bytes(0x0000, reset_vector, 3);
  movx_access_data();
  // Erase the reset of pages available to firmware.
*/
  for (i = BOOTLOADER_PAGES; i < BOOTLOADER_PAGES+FLASH_PAGES(bytes_total); ++i) {
    flash_erase_page(i);
  }

  send(CMD_ACK,1);
  if (send_success) state = RECEIVING_FIRMWARE;
  else state = PINGING;

  return;
}
Ejemplo n.º 3
0
LINK_ERR forceload_os(TilemCalc* calc, TIFILE_t *tifile) {
	int flash_pages = FLASH_PAGES(calc);

	u_int i, page;
	u_char (*dest)[PAGE_SIZE_W] = (u_char (*)[PAGE_SIZE_W]) calc->mem;
	if (dest == NULL)
		return LERR_MODEL;

	if (tifile->flash == NULL)
		return LERR_FILE;

	for (i = 0; i < ARRAYSIZE(tifile->flash->data); i++) {
		if (tifile->flash->data[i] == NULL) {
			continue;
		}
		if (i > 0x10) {
			page = i + flash_pages - 0x20;
		} else {
			page = i;
		}
		int sector = (page / 4) * 4;
		int size;
		if (sector >= flash_pages - 4) {
			size = PAGE_SIZE_W * 2;
		} else {
			size = PAGE_SIZE_W * 4;
		}
		memset(dest[sector], 0xFF, size);
	}
	for (i = 0; i < ARRAYSIZE(tifile->flash->data); i++) {
		if (tifile->flash->data[i] == NULL) {
			continue;
		}
		if (i > 0x10) {
			page = i + flash_pages - 0x20;
		} else {
			page = i;
		}

		memcpy(dest[page], tifile->flash->data[i], PAGE_SIZE_W);
	}

	//valid OS
	dest[0][0x56] = 0x5A;
	dest[0][0x57] = 0xA5;

	return LERR_SUCCESS;
}