# NVM: Bad block manager failed to initialize on chip 0

- **ID:** `embedded/nvm-bad-block-manager-failure`
- **Domain:** embedded
- **Category:** runtime_error
- **Error Code:** `NVM_ERR_BBT_INIT`
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

NAND flash bad block table (BBT) is corrupted or the reserved block area is worn out, preventing the BBT from loading.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| NAND flash driver v2.1.0 | active | — | — |
| FreeRTOS+IO v1.3.0 | active | — | — |
| STM32CubeFW_F4 v1.27.0 | active | — | — |

## Workarounds

1. **Force BBT rebuild by erasing the reserved block area and reinitializing: `nand_erase(dev, reserved_block_start, reserved_block_count); nand_bbt_init(dev);`** (75% success)
   ```
   Force BBT rebuild by erasing the reserved block area and reinitializing: `nand_erase(dev, reserved_block_start, reserved_block_count); nand_bbt_init(dev);`
   ```
2. **Use a fallback BBT stored in a separate NOR flash or EEPROM, then copy it to NAND: `memcpy(nand_bbt, fallback_bbt, bbt_size); nand_bbt_apply(dev);`** (85% success)
   ```
   Use a fallback BBT stored in a separate NOR flash or EEPROM, then copy it to NAND: `memcpy(nand_bbt, fallback_bbt, bbt_size); nand_bbt_apply(dev);`
   ```

## Dead Ends

- **** — Mass erase removes all data including the BBT, but does not recreate the BBT structure; the manager will still fail because the reserved area is not reinitialized. (70% fail)
- **** — The configuration change only affects future BBT creation; the existing corrupted BBT is still loaded and fails. (80% fail)
