target/linux/generic/files/drivers/mtd/nand/mtk_bmt_nmbm.c
static bool nmbm_update_info_table_once(struct nmbm_instance *ni, bool force)
{
	uint32_t table_start_ba, table_end_ba;
	uint32_t main_table_limit;
	bool success;

	/* Do nothing if there is no change */
	if (!nmbm_generate_info_table_cache(ni) && !force)
		return true;

	/* Check whether both two tables exist */
	if (!ni->backup_table_ba) {
		main_table_limit = ni->mapping_blocks_top_ba;
		goto write_main_table;
	}

	/*
	 * Write backup info table in its current range.
	 * Note that limit is set to mapping_blocks_top_off to provide as many
	 * spare blocks as possible for the backup table. If at last
	 * unmapped blocks are used by backup table, mapping_blocks_off will
	 * be adjusted.
	 */
	success = nmbm_write_info_table(ni, ni->backup_table_ba,
					ni->mapping_blocks_top_ba,
					&table_start_ba, &table_end_ba);
	if (!success) {
		/*
		 * There is nothing to do if failed to write backup table.
		 * Write the main table now.
		 */
		nlog_err(ni, "No room for backup table\n");
		ni->mapping_blocks_ba = ni->backup_table_ba;
		ni->backup_table_ba = 0;
		main_table_limit = ni->mapping_blocks_top_ba;
		goto write_main_table;
	}

	/* Backup table is successfully written, record its offset */
	ni->backup_table_ba = table_start_ba;

	/* Adjust mapping_blocks_off */
	ni->mapping_blocks_ba = table_end_ba;

	nmbm_mark_tables_clean(ni);

	/* The normal limit of main table */
	main_table_limit = ni->backup_table_ba;

	nlog_table_update(ni, false, table_start_ba, table_end_ba);

write_main_table:
	if (!ni->main_table_ba)
		goto rebuild_tables;

	/* Write main info table in its current range */
	success = nmbm_write_info_table(ni, ni->main_table_ba,
					main_table_limit, &table_start_ba,
					&table_end_ba);
	if (!success) {
		/* If failed to write main table, go rescue procedure */
		if (!ni->backup_table_ba)
			goto rebuild_tables;

		return nmbm_rescue_main_info_table(ni);
	}

	/* Main info table is successfully written, record its offset */
	ni->main_table_ba = table_start_ba;

	/* Adjust mapping_blocks_off */
	if (!ni->backup_table_ba)
		ni->mapping_blocks_ba = table_end_ba;

	nmbm_mark_tables_clean(ni);

	nlog_table_update(ni, true, table_start_ba, table_end_ba);

	return true;

rebuild_tables:
	return nmbm_rebuild_info_table(ni);
}
/*
 * nmbm_update_info_table_once - Update info table once
 * @ni: NMBM instance structure
 * @force: force update
 *
 * Update both main and backup info table. Return true if at least one info
 * table has been successfully written.
 * This function only try to update info table once regard less of the result.
 */
Update info table once
@ni: NMBM instance structure
@force: force update

Update both main and backup info table. Return true if at least one info
table has been successfully written.
This function only try to update info table once regard less of the result.
Update info table once @ni : NMBM instance structure @force : force update Update both main and backup info table . Return true if at least one info table has been successfully written . This function only try to update info table once regard less of the result .
static bool nmbm_update_info_table_once(struct nmbm_instance *ni, bool force)
{
	uint32_t table_start_ba, table_end_ba;
	uint32_t main_table_limit;
	bool success;
	if (!nmbm_generate_info_table_cache(ni) && !force)
		return true;
	if (!ni->backup_table_ba) {
		main_table_limit = ni->mapping_blocks_top_ba;
		goto write_main_table;
	}
	success = nmbm_write_info_table(ni, ni->backup_table_ba,
					ni->mapping_blocks_top_ba,
					&table_start_ba, &table_end_ba);
	if (!success) {
		nlog_err(ni, "No room for backup table\n");
		ni->mapping_blocks_ba = ni->backup_table_ba;
		ni->backup_table_ba = 0;
		main_table_limit = ni->mapping_blocks_top_ba;
		goto write_main_table;
	}
	ni->backup_table_ba = table_start_ba;
	ni->mapping_blocks_ba = table_end_ba;
	nmbm_mark_tables_clean(ni);
	main_table_limit = ni->backup_table_ba;
	nlog_table_update(ni, false, table_start_ba, table_end_ba);
write_main_table:
	if (!ni->main_table_ba)
		goto rebuild_tables;
	success = nmbm_write_info_table(ni, ni->main_table_ba,
					main_table_limit, &table_start_ba,
					&table_end_ba);
	if (!success) {
		if (!ni->backup_table_ba)
			goto rebuild_tables;
		return nmbm_rescue_main_info_table(ni);
	}
	ni->main_table_ba = table_start_ba;
	if (!ni->backup_table_ba)
		ni->mapping_blocks_ba = table_end_ba;
	nmbm_mark_tables_clean(ni);
	nlog_table_update(ni, true, table_start_ba, table_end_ba);
	return true;
rebuild_tables:
	return nmbm_rebuild_info_table(ni);
}
static bool nmbm_update_info_table_once ( struct nmbm_instance * ni , bool force ) { uint32_t table_start_ba , table_end_ba ; uint32_t main_table_limit ; bool success ; if ( ! nmbm_generate_info_table_cache ( ni ) && ! force ) return true ; if ( ! ni -> backup_table_ba ) { main_table_limit = ni -> mapping_blocks_top_ba ; goto write_main_table ; } success = nmbm_write_info_table ( ni , ni -> backup_table_ba , ni -> mapping_blocks_top_ba , & table_start_ba , & table_end_ba ) ; if ( ! success ) { nlog_err ( ni , " \n " ) ; ni -> mapping_blocks_ba = ni -> backup_table_ba ; ni -> backup_table_ba = 0 ; main_table_limit = ni -> mapping_blocks_top_ba ; goto write_main_table ; } ni -> backup_table_ba = table_start_ba ; ni -> mapping_blocks_ba = table_end_ba ; nmbm_mark_tables_clean ( ni ) ; main_table_limit = ni -> backup_table_ba ; nlog_table_update ( ni , false , table_start_ba , table_end_ba ) ; write_main_table : if ( ! ni -> main_table_ba ) goto rebuild_tables ; success = nmbm_write_info_table ( ni , ni -> main_table_ba , main_table_limit , & table_start_ba , & table_end_ba ) ; if ( ! success ) { if ( ! ni -> backup_table_ba ) goto rebuild_tables ; return nmbm_rescue_main_info_table ( ni ) ; } ni -> main_table_ba = table_start_ba ; if ( ! ni -> backup_table_ba ) ni -> mapping_blocks_ba = table_end_ba ; nmbm_mark_tables_clean ( ni ) ; nlog_table_update ( ni , true , table_start_ba , table_end_ba ) ; return true ; rebuild_tables : return nmbm_rebuild_info_table ( ni ) ; }
nmbm_update_info_table_once - Update info table once
 @ni: NMBM instance structure
 @force: force update
nmbm_update_info_table_once - Update info table once @ni : NMBM instance structure @force : force update
/* Do nothing if there is no change */ /* Check whether both two tables exist */ /*
	 * Write backup info table in its current range.
	 * Note that limit is set to mapping_blocks_top_off to provide as many
	 * spare blocks as possible for the backup table. If at last
	 * unmapped blocks are used by backup table, mapping_blocks_off will
	 * be adjusted.
	 */ /*
		 * There is nothing to do if failed to write backup table.
		 * Write the main table now.
		 */ /* Backup table is successfully written, record its offset */ /* Adjust mapping_blocks_off */ /* The normal limit of main table */ /* Write main info table in its current range */ /* If failed to write main table, go rescue procedure */ /* Main info table is successfully written, record its offset */ /* Adjust mapping_blocks_off */