target/linux/generic/files/drivers/mtd/nand/mtk_bmt_nmbm.c
static bool nmbm_write_mgmt_range(struct nmbm_instance *ni, uint32_t ba,
				  uint32_t limit, const void *data,
				  uint32_t size, uint32_t *actual_start_ba,
				  uint32_t *actual_end_ba)
{
	const uint8_t *ptr = data;
	uint32_t sizeremain = size, chunksize;
	bool success;

	while (sizeremain && ba < limit) {
		chunksize = sizeremain;
		if (chunksize > bmtd.blk_size)
			chunksize = bmtd.blk_size;

		if (nmbm_get_block_state(ni, ba) != BLOCK_ST_GOOD)
			goto next_block;

		/* Insurance to detect unexpected bad block marked by user */
		if (nmbm_check_bad_phys_block(ni, ba)) {
			nmbm_set_block_state(ni, ba, BLOCK_ST_BAD);
			goto next_block;
		}

		success = nmbm_erase_block_and_check(ni, ba);
		if (!success)
			goto skip_bad_block;

		success = nmbn_write_verify_data(ni, ba2addr(ni, ba), ptr,
						 chunksize);
		if (!success)
			goto skip_bad_block;

		if (sizeremain == size)
			*actual_start_ba = ba;

		ptr += chunksize;
		sizeremain -= chunksize;

		goto next_block;

	skip_bad_block:
		nmbm_mark_phys_bad_block(ni, ba);
		nmbm_set_block_state(ni, ba, BLOCK_ST_BAD);

	next_block:
		ba++;
	}

	if (sizeremain)
		return false;

	*actual_end_ba = ba;

	return true;
}
/*
 * nmbm_write_mgmt_range - Write management data into NAND within a range
 * @ni: NMBM instance structure
 * @addr: preferred start block address for writing
 * @limit: highest block address allowed for writing
 * @data: the data to be written
 * @size: the size of data
 * @actual_start_ba: actual start block address of data
 * @actual_end_ba: block address after the end of data
 *
 * @limit is not counted into the allowed write address.
 */


@limit is not counted into the allowed write address.
@limit is not counted into the allowed write address .
static bool nmbm_write_mgmt_range(struct nmbm_instance *ni, uint32_t ba,
				  uint32_t limit, const void *data,
				  uint32_t size, uint32_t *actual_start_ba,
				  uint32_t *actual_end_ba)
{
	const uint8_t *ptr = data;
	uint32_t sizeremain = size, chunksize;
	bool success;
	while (sizeremain && ba < limit) {
		chunksize = sizeremain;
		if (chunksize > bmtd.blk_size)
			chunksize = bmtd.blk_size;
		if (nmbm_get_block_state(ni, ba) != BLOCK_ST_GOOD)
			goto next_block;
		if (nmbm_check_bad_phys_block(ni, ba)) {
			nmbm_set_block_state(ni, ba, BLOCK_ST_BAD);
			goto next_block;
		}
		success = nmbm_erase_block_and_check(ni, ba);
		if (!success)
			goto skip_bad_block;
		success = nmbn_write_verify_data(ni, ba2addr(ni, ba), ptr,
						 chunksize);
		if (!success)
			goto skip_bad_block;
		if (sizeremain == size)
			*actual_start_ba = ba;
		ptr += chunksize;
		sizeremain -= chunksize;
		goto next_block;
	skip_bad_block:
		nmbm_mark_phys_bad_block(ni, ba);
		nmbm_set_block_state(ni, ba, BLOCK_ST_BAD);
	next_block:
		ba++;
	}
	if (sizeremain)
		return false;
	*actual_end_ba = ba;
	return true;
}
static bool nmbm_write_mgmt_range ( struct nmbm_instance * ni , uint32_t ba , uint32_t limit , const void * data , uint32_t size , uint32_t * actual_start_ba , uint32_t * actual_end_ba ) { const uint8_t * ptr = data ; uint32_t sizeremain = size , chunksize ; bool success ; while ( sizeremain && ba < limit ) { chunksize = sizeremain ; if ( chunksize > bmtd . blk_size ) chunksize = bmtd . blk_size ; if ( nmbm_get_block_state ( ni , ba ) != BLOCK_ST_GOOD ) goto next_block ; if ( nmbm_check_bad_phys_block ( ni , ba ) ) { nmbm_set_block_state ( ni , ba , BLOCK_ST_BAD ) ; goto next_block ; } success = nmbm_erase_block_and_check ( ni , ba ) ; if ( ! success ) goto skip_bad_block ; success = nmbn_write_verify_data ( ni , ba2addr ( ni , ba ) , ptr , chunksize ) ; if ( ! success ) goto skip_bad_block ; if ( sizeremain == size ) * actual_start_ba = ba ; ptr += chunksize ; sizeremain -= chunksize ; goto next_block ; skip_bad_block : nmbm_mark_phys_bad_block ( ni , ba ) ; nmbm_set_block_state ( ni , ba , BLOCK_ST_BAD ) ; next_block : ba ++ ; } if ( sizeremain ) return false ; * actual_end_ba = ba ; return true ; }
nmbm_write_mgmt_range - Write management data into NAND within a range
 @ni: NMBM instance structure
 @addr: preferred start block address for writing
 @limit: highest block address allowed for writing
 @data: the data to be written
 @size: the size of data
 @actual_start_ba: actual start block address of data
 @actual_end_ba: block address after the end of data
nmbm_write_mgmt_range - Write management data into NAND within a range @ni : NMBM instance structure @addr : preferred start block address for writing @limit : highest block address allowed for writing @data : the data to be written @size : the size of data @actual_start_ba : actual start block address of data @actual_end_ba : block address after the end of data
/* Insurance to detect unexpected bad block marked by user */