int __attribute__((noreturn)) main(void) { unsigned int blink_cnt = 0; /* initialize hardware */ bootLoaderInit(); /* * Calling the function below for it to get included in the bootloader. * Also, making sure that it actually doesn't do anything. And hence, * passing an unaligned address 0x0001, for the function to fail. */ #if (FLASHEND) > 0xFFFF flash_write_block(0x00000001, NULL); #else flash_write_block(0x0001, NULL); #endif odDebugInit(); DBG1(0x00, 0, 0); /* jump to application if jumper is set */ if(bootLoaderCondition()){ #ifndef TEST_MODE uint8_t gicr; gicr = GICR; GICR = gicr | (1 << IVCE); /* enable change of interrupt vectors */ GICR = gicr | (1 << IVSEL); /* move interrupts to boot flash section */ #endif DBG1(0x02, 0, 0); initForUsbConnectivity(); do{ /* main event loop */ //DBG2(0x03, 0, 0); wdt_reset(); usbPoll(); /* The following piece of code indicates being in bootloader */ if (++blink_cnt == 60000) { blink_cnt = 0; toggleLED(); //DBG2(0x04, 0, 0); } //DBG2(0x05, 0, 0); #if BOOTLOADER_CAN_EXIT if(exitMainloop){ break; } #endif }while(1); } leaveBootloader(); }
static bool flash_write(struct wacom_i2c *wac_i2c, unsigned char *flash_data, size_t data_size, unsigned long start_address, unsigned long *max_address, int mpuType) { unsigned long ulAddress; bool rv; int i; unsigned long pageNo = 0; u8 command_id = 0; printk(KERN_DEBUG "epen:flash_write start\n"); for (ulAddress = start_address; ulAddress < *max_address; ulAddress += FLASH_BLOCK_SIZE) { unsigned int j; bool bWrite = false; if (epen_debug) printk(KERN_DEBUG"epen:write addr %#x\n", (unsigned int)ulAddress); /* Wacom 2012/10/04: skip if all each data locating on from ulAddr to ulAddr+Block_SIZE_W are 0xff */ for (i = 0; i < FLASH_BLOCK_SIZE; i++) { if (flash_data[ulAddress + i] != 0xFF) break; } if (i == (FLASH_BLOCK_SIZE)) { /*if (epen_debug) printk(KERN_DEBUG"epen:BLOCK %#x PASSED\n", (unsigned int)ulAddress);*/ continue; } /* Wacom 2012/10/04 */ for (j = 0; j < FLASH_BLOCK_SIZE; j++) { if (flash_data[ulAddress + j] == 0xFF) continue; else { bWrite = true; break; } } if (!bWrite) { pageNo++; continue; } rv = flash_write_block(wac_i2c, flash_data, ulAddress, &command_id); if (rv == false) return false; pageNo++; } return true; }
void flash_write( uint32_t addr, uint8_t* buf, uint16_t len ) { uint16_t i = 0; // // HACK: assume the block is already erased and write is aligned with the block address // if( ((addr & 0x3F) != 0) || ((len % 64) != 0)) { return; } while( len != 0 ) { flash_write_block( addr + i * 64, buf + i * 64, 64 ); len -= 64; i++; } }
bool flash_write(struct wacom_i2c *wac_i2c, unsigned char *flash_data, size_t data_size, unsigned long start_address, unsigned long *max_address, int mpuType) { unsigned long ulAddress; int rv; unsigned long pageNo=0; u8 command_id = 0; printk(KERN_DEBUG "[PEN] %s flash_write start\n", __func__); for (ulAddress = start_address; ulAddress < *max_address; ulAddress += FLASH_BLOCK_SIZE) { unsigned int j; bool bWrite = false; for (j = 0; j < FLASH_BLOCK_SIZE; j++) { if (flash_data[ulAddress+j] == 0xFF) continue; else { bWrite = true; break; } } if (!bWrite) { pageNo++; continue; } rv = flash_write_block(wac_i2c, flash_data, ulAddress, &command_id); if(rv < 0) return false; pageNo++; } return true; }
static bool flash_write(struct wacom_i2c *wac_i2c, unsigned char *flash_data, unsigned long start_address, unsigned long *max_address) { bool bRet = false; u8 command_id = 0; u8 command[BOOT_RSP_SIZE]; u8 response[BOOT_RSP_SIZE]; int ret, i, j, len, ECH = 0, ECH_len = 0; int ECH_ARRAY[3]; unsigned long ulAddress; j = 0; for (ulAddress = start_address; ulAddress < *max_address; ulAddress += FLASH_BLOCK_SIZE) { for (i = 0; i < FLASH_BLOCK_SIZE; i++) { if (flash_data[ulAddress + i] != 0xFF) break; } if (i == (FLASH_BLOCK_SIZE)) continue; /* for debug */ //printk(KERN_DEBUG"epen:write data %#x\n", (unsigned int)ulAddress); bRet = flash_write_block(wac_i2c, flash_data, ulAddress, &command_id, &ECH); if (!bRet) return false; if (ECH_len == 3) ECH_len = 0; ECH_ARRAY[ECH_len++] = ECH; if (ECH_len == 3) { for (j = 0; j < 3; j++) { do { len = 0; command[len++] = 4; command[len++] = 0; command[len++] = 0x38; command[len++] = CMD_GET_FEATURE; command[len++] = 5; command[len++] = 0; ret = wacom_i2c_send(wac_i2c, command, len, WACOM_I2C_MODE_BOOT); if (ret < 0) { printk(KERN_DEBUG"epen:%s failing 2:%d \n", __func__, i); return false; } ret = wacom_i2c_recv(wac_i2c, response, BOOT_RSP_SIZE, WACOM_I2C_MODE_BOOT); if (ret < 0) { printk(KERN_DEBUG"epen:%s failing 3:%d \n", __func__, i); return false; } if ((response[3] != 0x01 || response[4] != ECH_ARRAY[j]) || (response[5] != 0xff && response[5] != 0x00)) return false; //printk(KERN_DEBUG"epen:addr: %x res:%x \n", ulAddress, response[5]); } while (response[3] == 0x01 && response[4] == ECH_ARRAY[j] && response[5] == 0xff); } } } return true; }