int main(int argc, char const *argv[]) { std::string FILE="/homes/kgori/scratch/basic_pll/GGPS1.phy"; std::string PART="/homes/kgori/scratch/basic_pll/GGPS1.partitions.txt"; std::string TREE="/homes/kgori/scratch/basic_pll/GGPS1.tree"; auto inst = make_unique<pll>(FILE, PART, TREE, 1, 123); std::cout << inst->get_likelihood() << std::endl; std::cout << inst->get_partition_name(0) << std::endl; std::cout << inst->get_model_name(0) << std::endl; std::cout << inst->get_epsilon() << std::endl; std::cout << inst->get_alpha(0) << std::endl; std::cout << inst->get_number_of_partitions() << std::endl; std::cout << inst->get_tree() << std::endl; std::cout << inst->get_frac_change() << std::endl; inst->set_tree("((Ptro:0.00147084048849247711,Ppan:0.00106294370976534763):0.00444598321816729036,(Cjac:0.05157798212603657839,(Csab:0.00440006365327790666,(Mmul:0.00652936575529242547,Panu:0.00101047194512476272):0.00381049900890796569):0.01359968787254225639):0.01375788728353777995,Hsap:0.00674547067186638278):0.0;"); inst->set_epsilon(0.001); inst->set_alpha(2, 0, true); auto ef = inst->get_empirical_frequencies(); inst->optimise(true, true, true, true); inst->optimise_tree_search(true); std::cout << inst->get_likelihood() << std::endl; std::cout << inst->get_tree() << std::endl; return 0; }
BOOL write_to_nand(u8* data, u32 length, u32 img_total_len) { static u64 partition_size = 0; int next_flip = 0; u32 index; static int img_type = UNKOWN_IMG; s8* p_type; u32 w_length =0; //u32 pre_chksum = 0; //u32 post_chksum = 0; int r; if(sto_info.first_run) { r = get_partition_name(data, length, sto_info.partition_name); if(r < 0) { display_info("\nGet_partition_name() Fail"); return FALSE; } index = partition_get_index(sto_info.partition_name); // if(index == -1) { display_info("\nBrick phone??"); return FALSE; } if(!is_support_flash(index)) { display_info("\nDont support partition."); return FALSE; } partition_size = partition_get_size(index); dprintf(DBG_LV, "[index:%d]-[partitionSize:%lld]-[downSize:%d]\n", index, partition_size, sto_info.to_write_data_len); if (ROUND_TO_PAGE(sto_info.to_write_data_len,511) > partition_size) { display_info("size too large, space small."); dprintf(DBG_LV, "size too large, space small."); return FALSE; } { char i_type[20] = {0}; get_image_type(data,length,(char *)i_type); partition_get_type(index,&p_type); if(strcmp(i_type,p_type)){ display_info("[warning]image type is not match with partition type\n"); dprintf(DBG_LV, "[warning]image type'%s' is not match with partition type'%s'",i_type,p_type); } printf("image type %s\n",i_type); if(!strcmp(i_type,"raw data")){ img_type = RAW_DATA_IMG; }else if(!strcmp(i_type,"yaffs2")){ img_type = YFFS2_IMG; }else if(!strcmp(i_type,"ubifs")){ img_type = UBIFS_IMG; }else{ dprintf(DBG_LV, "image type '%s' unkown\n",i_type); display_info("\nimage type unkown"); return FALSE; } } sto_info.image_base_addr = partition_get_offset(index); //NAND has no sparse image. //sto_info.unsparse_status.image_base_addr = sto_info.image_base_addr; //sto_info.is_sparse_image = is_sparse_image(data, length); sto_info.first_run = 0; } #if defined(MTK_MLC_NAND_SUPPORT) if (0 != nand_write_img_ex((u64)(sto_info.image_base_addr+sto_info.bulk_image_offset), (void*)data, length,img_total_len?(u64)(img_total_len):(u64)(sto_info.to_write_data_len), &w_length, (u64)(sto_info.image_base_addr),(u64)partition_size, img_type)) #else if (0 != nand_write_img_ex((u32)(sto_info.image_base_addr+sto_info.bulk_image_offset), (void*)data, length,img_total_len?(u32)(img_total_len):(u32)(sto_info.to_write_data_len), &w_length, (u32)(sto_info.image_base_addr),(u32)partition_size, img_type)) #endif { dprintf(DBG_LV, "nand_write_img() Failed.\n"); display_info("Error in write bulk in NAND."); return FALSE; } if(sto_info.checksum_enabled) { //NAND do not support read() now. } sto_info.bulk_image_offset += w_length; return TRUE; }
BOOL write_to_emmc(u8* data, u32 length) { u64 paritition_size = 0; u64 size_wrote = 0; int next_flip = 0; u32 index; u32 pre_chksum = 0; u32 post_chksum = 0; int r; while(sto_info.first_run) { r = get_partition_name(data, length, sto_info.partition_name); if(r < 0) { display_info("\nget_partition_name() Fail"); return FALSE; } if((!strncmp((char*)sto_info.partition_name, (char*)"signatureFile", 16)) || (!strncmp((char*)sto_info.partition_name, (char*)"boot", 8))) { //this do not need subsequent codes for normal partition. ctx.boot_like_info.is_boot_like_image = TRUE; ctx.boot_like_info.offset = 0; sto_info.first_run = 0; break; } index = partition_get_index((char*)sto_info.partition_name); if(index == (u32)(-1)) { display_info("\nBrick phone??"); return FALSE; } if(!is_support_flash(index)) { display_info((char*)sto_info.partition_name); display_info("\nDont support partition"); return FALSE; } paritition_size = partition_get_size(index); dprintf(DBG_LV, "[index:%d]-[downSize:%d]\n", index, sto_info.to_write_data_len); if (ROUND_TO_PAGE(sto_info.to_write_data_len,511) > paritition_size) { display_info("\nsize too large, space small."); dprintf(DBG_LV, "size too large, space small."); return FALSE; } #ifdef MTK_NEW_COMBO_EMMC_SUPPORT sto_info.part_id = partition_get_region(index); sto_info.unsparse_status.part_id = sto_info.part_id; #endif sto_info.image_base_addr = partition_get_offset(index); sto_info.unsparse_status.image_base_addr = sto_info.image_base_addr; sto_info.is_sparse_image = is_sparse_image(data, length); sto_info.first_run = 0; } //boot like image do not need write to image at this function. it is in flash function. if(ctx.boot_like_info.is_boot_like_image) { dprintf(DBG_LV, "boot like img: len: %d\n", length); dprintf(DBG_LV, "data: %08X\n", (u32)data); //dprintf(DBG_LV, "ctx.boot_like_info.boot_like_image_address: %08X, ctx.boot_like_info.offset %u, \n", ctx.boot_like_info.boot_like_image_address , ctx.boot_like_info.offset); memcpy(ctx.boot_like_info.boot_like_image_address + ctx.boot_like_info.offset, data, length); ctx.boot_like_info.offset += length; return TRUE; } if(sto_info.is_sparse_image) { next_flip = cache_shift(ctx.flipIdxR); sto_info.unsparse_status.buf = data; sto_info.unsparse_status.size = length; mmc_write_sparse_data(&sto_info.unsparse_status); if(sto_info.unsparse_status.handle_status == S_DA_SDMMC_SPARSE_INCOMPLETE) { ctx.dual_cache[next_flip].padding_length = sto_info.unsparse_status.size; memcpy(ctx.dual_cache[next_flip].padding_buf +(CACHE_PADDING_SIZE-sto_info.unsparse_status.size) , sto_info.unsparse_status.buf , sto_info.unsparse_status.size); } else if (sto_info.unsparse_status.handle_status== S_DONE) { ctx.dual_cache[next_flip].padding_length = 0; } else { //some error dprintf(DBG_LV, "write_to_emmc() Failed. handle_status(%d)\n", sto_info.unsparse_status.handle_status); display_info("\nError in write sparse image in EMMC."); return FALSE; } } else { #ifdef MTK_NEW_COMBO_EMMC_SUPPORT size_wrote = emmc_write(sto_info.part_id, sto_info.image_base_addr+sto_info.bulk_image_offset , (void*)data, length); #else size_wrote = emmc_write(sto_info.image_base_addr+sto_info.bulk_image_offset , (void*)data, length); #endif if (size_wrote != length) { dprintf(DBG_LV, "write_to_emmc() Failed. act(%d) != want(%d)\n", (u32)size_wrote, length); display_info("\nError in write bulk in EMMC."); return FALSE; } if(sto_info.checksum_enabled) { pre_chksum = calc_checksum(data, (u32)length); #ifdef MTK_NEW_COMBO_EMMC_SUPPORT if(length != emmc_read(sto_info.part_id, sto_info.image_base_addr+sto_info.bulk_image_offset, data, length)) #else if(length != emmc_read(sto_info.image_base_addr+sto_info.bulk_image_offset, data, length)) #endif { dprintf(DBG_LV, "emmc_read() Failed.\n"); display_info("\nError in Read bulk EMMC."); return FALSE; } post_chksum = calc_checksum(data, (u32)length); if(post_chksum != pre_chksum) { dprintf(DBG_LV, "write_to_emmc() Failed. checksum error\n"); display_info("\nWrite bulk in EMMC. Checksum Error"); return FALSE; } } sto_info.bulk_image_offset += size_wrote; } return TRUE; }
BOOL write_to_nand(u8* data, u32 length) { u64 paritition_size = 0; int next_flip = 0; u32 index; BOOL partition_type; s8* p_type; //u32 pre_chksum = 0; //u32 post_chksum = 0; int r; if(sto_info.first_run) { r = get_partition_name(data, length, sto_info.partition_name); if(r < 0) { display_info("ASSERT!! get_partition_name() Fail"); return FALSE; } index = partition_get_index(sto_info.partition_name); // if(index == -1) { display_info("ASSERT!! Brick phone??"); return FALSE; } if(!is_support_flash(index)) { display_info("ASSERT!! Dont support system??"); return FALSE; } //verify boot partition. if (!strcmp(sto_info.partition_name, "boot") || !strcmp(sto_info.partition_name, "recovery")) { if (memcmp((void *)data, BOOT_MAGIC, strlen(BOOT_MAGIC))) { display_info("image is not a boot image"); return FALSE; } } paritition_size = partition_get_size(index); dprintf(DBG_LV, "[index:%d]-[partitionSize:%lld]-[downSize:%d]\n", index, paritition_size, sto_info.to_write_data_len); if (ROUND_TO_PAGE(sto_info.to_write_data_len,511) > paritition_size) { display_info("size too large, space small."); dprintf(DBG_LV, "size too large, space small."); return FALSE; } partition_get_type(index,&p_type); partition_type = (!strcmp(p_type,"yaffs2")) ? TRUE : FALSE; sto_info.image_base_addr = partition_get_offset(index); //NAND has no sparse image. //sto_info.unsparse_status.image_base_addr = sto_info.image_base_addr; //sto_info.is_sparse_image = is_sparse_image(data, length); sto_info.first_run = 0; } if (0 != nand_write_img((u32)(sto_info.image_base_addr+sto_info.bulk_image_offset), (void*)data, length,(u32)paritition_size, partition_type)) { dprintf(DBG_LV, "nand_write_img() Failed.\n"); display_info("Error in write bulk in NAND."); return FALSE; } if(sto_info.checksum_enabled) { //NAND do not support read() now. } sto_info.bulk_image_offset += length; return TRUE; }
BOOL write_to_emmc(u8* data, u32 length) { u64 paritition_size = 0; u64 size_wrote = 0; int next_flip = 0; u32 index; u32 pre_chksum = 0; u32 post_chksum = 0; int r; if(sto_info.first_run) { r = get_partition_name(data, length, sto_info.partition_name); if(r < 0) { display_info("\nASSERT!! get_partition_name() Fail"); return FALSE; } if(!strncmp(sto_info.partition_name, "boot", 8)) { ctx.boot_info.is_boot_image = TRUE; ctx.boot_info.offset = 0; } index = partition_get_index(sto_info.partition_name); if(index == -1) { display_info("\nASSERT!! Brick phone??"); return FALSE; } if(!is_support_flash(index)) { display_info(sto_info.partition_name); display_info("\nASSERT!! Dont support system??"); return FALSE; } paritition_size = partition_get_size(index); dprintf(DBG_LV, "[index:%d]-[partitionSize:%lld]-[downSize:%lld]\n", index, paritition_size, sto_info.to_write_data_len); if (ROUND_TO_PAGE(sto_info.to_write_data_len,511) > paritition_size) { display_info("\nsize too large, space small."); dprintf(DBG_LV, "size too large, space small."); return FALSE; } sto_info.image_base_addr = partition_get_offset(index); sto_info.unsparse_status.image_base_addr = sto_info.image_base_addr; sto_info.is_sparse_image = is_sparse_image(data, length); sto_info.first_run = 0; } //boot image do not need write to image at this function. it is in flash function. if(ctx.boot_info.is_boot_image) { dprintf(DBG_LV, "boot img: len: %d\n", length); dprintf(DBG_LV, "data: %08X\n", data); dprintf(DBG_LV, "ctx.boot_info.boot_image_address: %08X, ctx.boot_info.offset %u, \n", ctx.boot_info.boot_image_address , ctx.boot_info.offset); memcpy(ctx.boot_info.boot_image_address + ctx.boot_info.offset, data, length); ctx.boot_info.offset += length; return TRUE; } if(sto_info.is_sparse_image) { next_flip = cache_shift(ctx.flipIdxR); sto_info.unsparse_status.buf = data; sto_info.unsparse_status.size = length; mmc_write_sparse_data(&sto_info.unsparse_status); if(sto_info.unsparse_status.handle_status == S_DA_SDMMC_SPARSE_INCOMPLETE) { ctx.dual_cache[next_flip].padding_length = sto_info.unsparse_status.size; memcpy(ctx.dual_cache[next_flip].padding_buf +(CACHE_PADDING_SIZE-sto_info.unsparse_status.size) , sto_info.unsparse_status.buf , sto_info.unsparse_status.size); } else if (sto_info.unsparse_status.handle_status== S_DONE) { ctx.dual_cache[next_flip].padding_length = 0; } else { //some error dprintf(DBG_LV, "write_to_emmc() Failed. handle_status(%d)\n", sto_info.unsparse_status.handle_status); display_info("\nError in write sparse image in EMMC."); return FALSE; } } else { size_wrote = emmc_write(sto_info.image_base_addr+sto_info.bulk_image_offset , (void*)data, length); if (size_wrote != length) { dprintf(DBG_LV, "write_to_emmc() Failed. act(%lld) != want(%lld)\n", size_wrote, length); display_info("\nError in write bulk in EMMC."); return FALSE; } if(sto_info.checksum_enabled) { pre_chksum = calc_checksum(data, (u32)length); if(length != emmc_read(sto_info.image_base_addr+sto_info.bulk_image_offset, data, length)) { dprintf(DBG_LV, "emmc_read() Failed.\n"); display_info("\nError in Read bulk EMMC."); return FALSE; } post_chksum = calc_checksum(data, (u32)length); if(post_chksum != pre_chksum) { dprintf(DBG_LV, "write_to_emmc() Failed. checksum error\n"); display_info("\nWrite bulk in EMMC. Checksum Error"); return FALSE; } } sto_info.bulk_image_offset += size_wrote; } return TRUE; }