/******************************************************************* * [BMT Interface] * * Description: * Init bmt from nand. Reconstruct if not found or data error * * Parameter: * size: size of bmt and replace pool * * Return: * NULL for failure, and a bmt struct for success *******************************************************************/ bmt_struct *init_bmt(struct nand_chip * chip, int size) { if (size > 0 && size < MAX_BMT_SIZE) { MSG(INIT, "Init bmt table, size: %d\n", size); bmt_block_count = size; } else { MSG(INIT, "Invalid bmt table size: %d\n", size); return NULL; } nand_chip_bmt = chip; system_block_count = chip->chipsize / chip->erasesize; total_block_count = bmt_block_count + system_block_count; page_per_block = chip->erasesize / chip->page_size; MSG(INIT, "bmt count: %d, system count: %d\n", bmt_block_count, system_block_count); pool_erased = 0; memset(bmt.table, 0, size * sizeof(bmt_entry)); if ((bmt_block_index = load_bmt_data(system_block_count, size))) { MSG(INFO, "Load bmt data success @ block 0x%x\n", bmt_block_index); //dump_bmt_info(&bmt); return &bmt; } else { MSG(INFO, "Load bmt data fail, need re-construct!\n"); if (reconstruct_bmt(&bmt)) return &bmt; else return NULL; } }
/******************************************************************* * [BMT Interface] * * Description: * Init bmt from nand. Reconstruct if not found or data error * * Parameter: * size: size of bmt and replace pool * * Return: * NULL for failure, and a bmt struct for success *******************************************************************/ bmt_struct *init_bmt(struct nand_chip * chip, int size) { struct mtk_nand_host *host; if (size > 0 && size < MAX_BMT_SIZE) { MSG(INIT, "Init bmt table, size: %d\n", size); bmt_block_count = size; } else { MSG(INIT, "Invalid bmt table size: %d\n", size); return NULL; } nand_chip_bmt = chip; system_block_count = (u32)(chip->chipsize >> chip->phys_erase_shift); total_block_count = bmt_block_count + system_block_count; page_per_block = BLOCK_SIZE_BMT / PAGE_SIZE_BMT; host = (struct mtk_nand_host *)chip->priv; mtd_bmt = &host->mtd; MSG(INIT, "mtd_bmt: %p, nand_chip_bmt: %p\n", mtd_bmt, nand_chip_bmt); MSG(INIT, "bmt count: %d, system count: %d\n", bmt_block_count, system_block_count); // set this flag, and unmapped block in pool will be erased. pool_erased = 0; memset(bmt.table, 0, size * sizeof(bmt_entry)); if ((bmt_block_index = load_bmt_data(system_block_count, size))) { MSG(INIT, "Load bmt data success @ block 0x%x\n", bmt_block_index); dump_bmt_info(&bmt); return &bmt; } else { MSG(INIT, "Load bmt data fail, need re-construct!\n"); if (reconstruct_bmt(&bmt)) return &bmt; else return NULL; } }
/******************************************************************* * [BMT Interface] * * Description: * Init bmt from nand. Reconstruct if not found or data error * * Parameter: * size: size of bmt and replace pool * * Return: * NULL for failure, and a bmt struct for success *******************************************************************/ bmt_struct *init_bmt(struct nand_chip *chip, int size) { #if defined(__KERNEL_NAND__) struct mtk_nand_host *host; #endif dat_buf = bmt_buf; //(0x80000); oob_buf = bmt_buf + 16384; //(0x80000 + 4096); //return NULL; if (size > 0 && size < MAX_BMT_SIZE) { MSG(INIT, "Init bmt table, size: %d\n", size); bmt_block_count = size; } else { MSG(INIT, "Invalid bmt table size: %d\n", size); return NULL; } #if defined(__PRELOADER_NAND__) nand_chip_bmt = chip; system_block_count = (u32)(chip->chipsize / (nand_chip_bmt->sector_size == 512?nand_chip_bmt->erasesize : nand_chip_bmt->erasesize*2)); total_block_count = bmt_block_count + system_block_count; page_per_block = (nand_chip_bmt->sector_size == 512?nand_chip_bmt->erasesize : nand_chip_bmt->erasesize*2) / chip->page_size; #elif defined(__KERNEL_NAND__) nand_chip_bmt = chip; system_block_count = chip->chipsize >> chip->phys_erase_shift; total_block_count = bmt_block_count + system_block_count; page_per_block = BLOCK_SIZE_BMT / PAGE_SIZE_BMT; host = (struct mtk_nand_host *)chip->priv; mtd_bmt = &host->mtd; #endif #ifdef DBG_PRELOADER MSG(INIT, "bmt count: %d, system count: %d\n", bmt_block_count, system_block_count); #endif // set this flag, and unmapped block in pool will be erased. pool_erased = 0; // alloc size for bmt. memset(bmt.table, 0, size * sizeof(bmt_entry)); // load bmt if exist if ((bmt_block_index = load_bmt_data(system_block_count, size))) { #ifdef DBG_PRELOADER MSG(INIT, "Load bmt data success @ block 0x%x\n", bmt_block_index); dump_bmt_info(&bmt); #endif return &bmt; } else { MSG(INIT, "Load bmt data fail, need re-construct!\n"); #ifndef __UBOOT_NAND__ // BMT is not re-constructed in UBOOT. if (reconstruct_bmt(&bmt)) return &bmt; else #endif return NULL; } }
bmt_struct *init_bmt(struct ra_nand_chip *ra, int size) #endif { #if defined(TCSUPPORT_CPU_MT7510)||defined(TCSUPPORT_CPU_MT7520) struct mt6573_nand_host *host; #endif if (size > 0 && size < MAX_BMT_SIZE) { MSG("Init bmt table, size: %d\n", size); bmt_block_count = size; } else { MSG("Invalid bmt table size: %d\n", size); return NULL; } #if defined(TCSUPPORT_CPU_MT7510)||defined(TCSUPPORT_CPU_MT7520) nand_chip_bmt = chip; system_block_count = chip->chipsize >> chip->phys_erase_shift; total_block_count = bmt_block_count + system_block_count; host = (struct mt6573_nand_host *)chip->priv; mtd_bmt = &host->mtd; #else nand_chip_bmt = ra; total_block_count = (1 << ra->flash->chip_shift) / (1 << ra->flash->erase_shift); system_block_count = total_block_count - bmt_block_count; #endif page_per_block = BLOCK_SIZE_BMT / PAGE_SIZE_BMT; MSG("bmt count: %d, system count: %d\n", bmt_block_count, system_block_count); // set this flag, and unmapped block in pool will be erased. pool_erased = 0; // alloc size for bmt. memset(bmt.table, 0, size * sizeof(bmt_entry)); bmt_block_index = load_bmt_data(system_block_count, size); // load bmt if exist if (bmt_block_index) { MSG("Load bmt data success @ block %d \n", bmt_block_index); dump_bmt_info(&bmt); return &bmt; } else { MSG("Load bmt data fail! \n"); if (reconstruct_bmt(&bmt)) { need_write_bmt_to_nand = 1; return &bmt; } else return NULL; } }