void cmd_multitouch_fw_install(int argc, char** argv) { if(argc < 5) { bufferPrintf("%s <a-speed fw> <a-speed fw len> <main fw> <main fw len>\r\n", argv[0]); return; } uint8_t* aspeedFW = (uint8_t*) parseNumber(argv[1]); uint32_t aspeedFWLen = parseNumber(argv[2]); uint8_t* mainFW = (uint8_t*) parseNumber(argv[3]); uint32_t mainFWLen = parseNumber(argv[4]); //get latest apple image Image* image = images_get_last_apple_image(); uint32_t offset = image->offset+image->padded; //write aspeed first if(offset >= 0xfc000 || (offset + aspeedFWLen + mainFWLen) >= 0xfc000) { bufferPrintf("**ABORTED** Image of size %d at 0x%x would overflow NOR!\r\n", aspeedFWLen+mainFWLen, offset); return; } bufferPrintf("Writing aspeed 0x%x - 0x%x to 0x%x...\r\n", aspeedFW, aspeedFW + aspeedFWLen, offset); nor_write((void*)aspeedFW, offset, aspeedFWLen); offset += aspeedFWLen; bufferPrintf("Writing main 0x%x - 0x%x to 0x%x...\r\n", mainFW, mainFW + mainFWLen, offset); nor_write((void*)mainFW, offset, mainFWLen); bufferPrintf("Zephyr firmware installed.\r\n"); }
void images_append(void* data, int len) { if(MaxOffset >= 0xfc000 || (MaxOffset + len) >= 0xfc000) { bufferPrintf("writing image of size %d at %x would overflow NOR!\r\n", len, MaxOffset); } else { nor_write(data, MaxOffset, len); // Destroy any following image if((MaxOffset + len) < 0xfc000) { uint8_t zero = 0; nor_write(&zero, MaxOffset + len, 1); } images_release(); images_setup(); } }
void images_duplicate_at(Image* image, uint32_t type, int index, int offset) { if(image == NULL) return; uint32_t totalLen = sizeof(Img2Header) + image->padded; uint8_t* buffer = (uint8_t*) malloc(totalLen); nor_read(buffer, image->offset, totalLen); Img2Header* header = (Img2Header*) buffer; header->imageType = type; if(index >= 0) header->index = index; calculateDataHash(buffer + sizeof(Img2Header), image->padded, header->dataHash); uint32_t checksum = 0; crc32(&checksum, buffer, 0x64); header->header_checksum = checksum; calculateHash(header, header->hash); nor_write(buffer, offset, totalLen); free(buffer); images_release(); images_setup(); }
void cmd_multitouch_fw_install(int argc, char** argv) { if(argc < 3) { bufferPrintf("%s <constructed fw> <constructed fw len>\r\n", argv[0]); return; } uint8_t* fwData = (uint8_t*) parseNumber(argv[1]); uint32_t fwLen = parseNumber(argv[2]); //get latest apple image Image* image = images_get_last_apple_image(); if (image == NULL) { bufferPrintf("**ABORTED** Last image position cannot be read\r\n"); return; } uint32_t offset = image->offset+image->padded; if(offset >= 0xfc000 || (offset + fwLen) >= 0xfc000) { bufferPrintf("**ABORTED** Image of size %d at %x would overflow NOR!\r\n", fwLen, offset); return; } bufferPrintf("Writing 0x%x - 0x%x to 0x%x...\r\n", fwData, fwData + fwLen, offset); nor_write((void*)fwData, offset, fwLen); bufferPrintf("Zephyr2 firmware installed.\r\n"); }
/** EEPROM emulation controller side periodic task. * */ void EEP_hw_process (void) { /* check for dirty buffer and set write */ if (eep_buf_dirty) { int32_t idle_time = ((int32_t) ESCvar.Time) - ((int32_t) eep_last_write); if (idle_time > EEP_IDLE_TIMEOUT) { eep_buf_dirty = 0; eep_write_req = 1; } } /* check for write process */ if (eep_next_block != NULL) { /* write flash page */ nor_write(drv, EEP_FLASH_SECTOR_OFFSET((uint32_t)eep_write_dst), EEP_BYTES_PER_PAGE, (const uint8_t *)eep_write_src); eep_write_src += (EEP_BYTES_PER_PAGE / sizeof(*eep_write_src)); eep_write_dst += (EEP_BYTES_PER_PAGE / sizeof(*eep_write_dst)); /* update counter */ eep_write_page++; /* check for finished job */ if (eep_write_page >= EEP_PAGES_PER_BLOCK) { /* update block pointer and reset write state */ eep_curr_block = eep_next_block; eep_next_block = NULL; } return; } /* start write of new block */ if (eep_write_req) { EEP_BUSY_LED_ON(); /* get next block */ eep_next_block = get_next_block(eep_curr_block); /* copy data */ memcpy(eep_write_buf.data, eep_buf, EEP_EMU_BYTES); /* setup header */ eep_write_buf.header.seq = eep_curr_block->header.seq + 1; eep_write_buf.header.crc = fce_crc32 (&fce_config, (const uint32_t *)eep_write_buf.data, EEP_DATA_BYTES); /* initialize write position */ eep_write_src = (uint32_t *) &eep_write_buf; eep_write_dst = (uint32_t *) eep_next_block; eep_write_page = 0; /* reset write request */ eep_write_req = 0; } }
void cmd_nor_write(int argc, char** argv) { if(argc < 4) { bufferPrintf("Usage: %s <address> <offset> <len>\r\n", argv[0]); return; } uint32_t address = parseNumber(argv[1]); uint32_t offset = parseNumber(argv[2]); uint32_t len = parseNumber(argv[3]); bufferPrintf("Writing 0x%x - 0x%x to 0x%x...\r\n", address, address + len, offset); nor_write((void*)address, offset, len); bufferPrintf("Done.\r\n"); }
void images_write(Image* image, void* data, unsigned int length, int encrypt) { bufferPrintf("images_write(%x, %x, %x)\r\n", image, data, length); if(image == NULL) return; uint32_t padded = length; if((length & 0xF) != 0) { padded = (padded & ~0xF) + 0x10; } if(image->next != NULL && (image->offset + sizeof(Img2Header) + padded) >= image->next->offset) { bufferPrintf("requested length greater than space available in the hole\r\n"); return; } uint32_t totalLen = sizeof(Img2Header) + padded; uint8_t* writeBuffer = (uint8_t*) malloc(totalLen); nor_read(writeBuffer, image->offset, sizeof(Img2Header)); memcpy(writeBuffer + sizeof(Img2Header), data, length); if(encrypt) aes_838_encrypt(writeBuffer + sizeof(Img2Header), padded, NULL); Img2Header* header = (Img2Header*) writeBuffer; header->dataLen = length; header->dataLenPadded = padded; calculateDataHash(writeBuffer + sizeof(Img2Header), padded, header->dataHash); uint32_t checksum = 0; crc32(&checksum, writeBuffer, 0x64); header->header_checksum = checksum; calculateHash(header, header->hash); bufferPrintf("nor_write(%x, %x, %x)\r\n", writeBuffer, image->offset, totalLen); nor_write(writeBuffer, image->offset, totalLen); bufferPrintf("nor_write(%x, %x, %x) done\r\n", writeBuffer, image->offset, totalLen); free(writeBuffer); images_release(); images_setup(); }
void images_from_template(Image* image, uint32_t type, int index, void* dataBuffer, unsigned int len, int encrypt) { if(image == NULL) return; uint32_t offset = MaxOffset + (SegmentSize - (MaxOffset % SegmentSize)); uint32_t padded = len; if((len & 0xF) != 0) { padded = (padded & ~0xF) + 0x10; } uint32_t totalLen = sizeof(Img2Header) + padded; uint8_t* buffer = (uint8_t*) malloc(totalLen); nor_read(buffer, image->offset, sizeof(Img2Header)); Img2Header* header = (Img2Header*) buffer; header->imageType = type; if(index >= 0) header->index = index; header->dataLen = len; header->dataLenPadded = padded; memcpy(buffer + sizeof(Img2Header), dataBuffer, len); if(encrypt) aes_838_encrypt(buffer + sizeof(Img2Header), padded, NULL); calculateDataHash(buffer + sizeof(Img2Header), image->padded, header->dataHash); uint32_t checksum = 0; crc32(&checksum, buffer, 0x64); header->header_checksum = checksum; calculateHash(header, header->hash); nor_write(buffer, offset, totalLen); free(buffer); images_release(); images_setup(); }
static void init_flash_data(void) { uint32_t i; const uint32_t *src; uint32_t dst; /* erase both sectors */ nor_erase(drv, EEP_FLASH_SECTOR_OFFSET(EEP_SECTOR_A), EEP_BYTES_PER_SECTOR); nor_erase(drv, EEP_FLASH_SECTOR_OFFSET(EEP_SECTOR_B), EEP_BYTES_PER_SECTOR); /* copy default data to write buffer */ memcpy(eep_write_buf.data, SII_EE_DEFLT, (SII_EE_DEFLT_SIZE < EEP_EMU_BYTES) ? SII_EE_DEFLT_SIZE : EEP_EMU_BYTES); /* * memcpy(eep_write_buf.data, SII_EE_DEFLT, (SII_EE_DEFLT_SIZE < EEP_EMU_BYTES) ? SII_EE_DEFLT_SIZE : EEP_EMU_BYTES); */ /* setup header data */ eep_write_buf.header.seq = 0; eep_write_buf.header.crc = fce_crc32 (&fce_config, (const uint32_t *)eep_write_buf.data, EEP_DATA_BYTES); /* write pages */ src = (const uint32_t *) &eep_write_buf; dst = EEP_SECTOR_A; for (i = 0; i < EEP_PAGES_PER_BLOCK; i++) { nor_write(drv, EEP_FLASH_SECTOR_OFFSET(dst), EEP_BYTES_PER_PAGE, (const uint8_t *)src); src += (EEP_BYTES_PER_PAGE / sizeof(*src)); dst += EEP_BYTES_PER_PAGE; } /* set current block */ eep_curr_block = (eep_block_t *) EEP_SECTOR_A; }