int update_normal(int curr_cell_type) { int ret; struct update_op *p_op_start = NULL, *p_op_end = NULL, *p_op_buf = NULL; int i,j; BAT_DBG(" fw flashing... please wait for about 10s at least.\n"); ret = UPDATE_ERR_MATCH_OP_BUF; for (i=0; i<num_of_op_buf; i++) { if (curr_cell_type != bq27xx_fw[i].cell_type) continue; //Skip normal i2c mode op until OP_I2C_START + 1 p_op_buf = bq27xx_fw[i].op; p_op_start = p_op_buf; p_op_end = &p_op_buf[bq27xx_fw[i].num_op-1]; for (j=0; j<RETRY_COUNT; j++) { ret = update_fw(p_op_start, p_op_end); if (ret == UPDATE_OK) break; } break; } return ret; }
int update_from_rom_mode(void) { int cell_type=TYPE_LG; int i,j,k; int ret; struct update_op *p_op_start = NULL, *p_op_end = NULL, *p_op_buf = NULL; BAT_DBG(" (%s) enter\n", __func__); #if 0 cell_type = bq27520_batt_current_sel_type(); #endif BAT_DBG(" fw flashing... please wait for about 30s at least.\n"); ret = UPDATE_ERR_MATCH_OP_BUF; for (i=0; i<num_of_op_buf; i++) { if (cell_type != bq27xx_fw[i].cell_type) continue; //Skip normal i2c mode op until OP_I2C_START + 1 p_op_buf = bq27xx_fw[i].op; p_op_end = &p_op_buf[bq27xx_fw[i].num_op-1]; for (j=0; j<bq27xx_fw[i].num_op; j++) { #if 0 BAT_DBG("OP: %d, 0x%02X, 0x%02X\n", p_op_buf[j].bq_op, p_op_buf[j].off, p_op_buf[j].arg ); #endif if (p_op_buf[j].bq_op >= OP_I2C_START) { k=j; while(p_op_buf[k].bq_op >= OP_I2C_START) k++; p_op_start = &p_op_buf[k]; break; } } for (j=0; j<RETRY_COUNT; j++) { ret = update_fw(p_op_start, p_op_end); if (ret == UPDATE_OK) { ret = UPDATE_FROM_ROM_MODE; break; } } break; } return ret; }
/* * main - Bootloader main entry function * * INPUT * - argc: (not used) * - argv: (not used) * OUTPUT * 0 when complete */ int main(int argc, char *argv[]) { (void)argc; (void)argv; clock_init(); bootloader_init(); #if !defined(DEBUG_ON) && (MEMORY_PROTECT == 0) #error "To compile release version, please set MEMORY_PROTECT flag" #elif !defined(DEBUG_ON) /* Checks and sets memory protection */ memory_protect(); #elif (MEMORY_PROTECT == 1) #error "Can only compile release versions with MEMORY_PROTECT flag" #endif /* Initialize stack guard with random value (-fstack_protector_all) */ __stack_chk_guard = random32(); led_func(SET_GREEN_LED); led_func(SET_RED_LED); dbg_print("\n\rKeepKey LLC, Copyright (C) 2015\n\r"); dbg_print("BootLoader Version %d.%d.%d\n\r", BOOTLOADER_MAJOR_VERSION, BOOTLOADER_MINOR_VERSION, BOOTLOADER_PATCH_VERSION); if(is_fw_update_mode()) { update_fw(); } else { boot(); } #if DEBUG_LINK board_reset(); #else system_halt(); /* Loops forever */ #endif return(0); /* Should never get here */ }
int update_normal(int curr_cell_type) { int ret; struct update_op *p_op_start = NULL, *p_op_end = NULL, *p_op_buf = NULL; int i,j; BAT_DBG(" fw flashing... please wait for about 10s at least.\n"); ret = UPDATE_ERR_MATCH_OP_BUF; if (batt_info.gauge_version == IC_VERSION_G3) { BAT_DBG("bq27520 gauge is G3, no dffs file ignore it.\n"); ret = UPDATE_NONE; } else if (batt_info.gauge_version == IC_VERSION_G4) { BAT_DBG("bq27520 gauge is G4\n"); for (i=0; i<g4_num_of_op_buf; i++) { if (curr_cell_type != g4_bq27xx_fw[i].cell_type) continue; //Skip normal i2c mode op until OP_I2C_START + 1 p_op_buf = g4_bq27xx_fw[i].op; p_op_start = p_op_buf; p_op_end = &p_op_buf[g4_bq27xx_fw[i].num_op-1]; for (j=0; j<RETRY_COUNT; j++) { ret = update_fw(p_op_start, p_op_end); if (ret == UPDATE_OK) break; } break; } } return ret; }