Files

53 lines
1.1 KiB
C
Raw Permalink Normal View History

2023-08-30 16:21:18 +08:00
/*
2025-04-23 17:54:31 +08:00
* Copyright (c) 2023-2025, ArtInChip Technology Co., Ltd
2023-08-30 16:21:18 +08:00
*
* SPDX-License-Identifier: Apache-2.0
*
* Authors: xuan.wen <xuan.wen@artinchip.com>
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <malloc.h>
#include <spinand.h>
#include <bbt.h>
int nand_bbt_init(struct aic_spinand *flash)
{
2024-09-03 11:16:08 +08:00
u32 nblocks;
2023-08-30 16:21:18 +08:00
2024-09-03 11:16:08 +08:00
nblocks = flash->info->block_per_lun;
flash->bbt.cache = calloc(1, nblocks);
2023-08-30 16:21:18 +08:00
if (!flash->bbt.cache)
return -SPINAND_ERR;
return SPINAND_SUCCESS;
}
bool nand_bbt_is_initialized(struct aic_spinand *flash)
{
return !!flash->bbt.cache;
}
void nand_bbt_cleanup(struct aic_spinand *flash)
{
free(flash->bbt.cache);
}
2024-09-03 11:16:08 +08:00
int nand_bbt_get_block_status(struct aic_spinand *flash, u32 block)
2023-08-30 16:21:18 +08:00
{
2025-04-23 17:54:31 +08:00
u8 *cache = flash->bbt.cache + block;
2023-08-30 16:21:18 +08:00
2025-04-23 17:54:31 +08:00
return (cache[0] & BBT_BLOCK_STATUS_MSK);
2023-08-30 16:21:18 +08:00
}
2025-04-23 17:54:31 +08:00
void nand_bbt_set_block_status(struct aic_spinand *flash, u32 block, u32 status)
2023-08-30 16:21:18 +08:00
{
2025-04-23 17:54:31 +08:00
u8 *cache = flash->bbt.cache + block;
2023-08-30 16:21:18 +08:00
2025-04-23 17:54:31 +08:00
cache[0] &= ~BBT_BLOCK_STATUS_MSK;
cache[0] |= (status & BBT_BLOCK_STATUS_MSK);
2023-08-30 16:21:18 +08:00
}