-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_bad_block.c
More file actions
62 lines (51 loc) · 2.18 KB
/
debug_bad_block.c
File metadata and controls
62 lines (51 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*******************************************************************************
* @file debug_bad_block.c
* @brief Bad Block 模块调试程序
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "src/common/types.h"
#include "src/firmware/ftl/bad_block.h"
int main(void) {
printf("=== Bad Block Module Debug ===\n\n");
BadBlockTable bbt;
memset(&bbt, 0, sizeof(bbt));
printf("1. Initializing BBT with 1024 blocks...\n");
int ret = bad_block_table_init(&bbt, 1024);
printf(" Result: %d (ERR_OK=%d)\n", ret, ERR_OK);
printf(" Initialized: %d\n", bbt.initialized);
printf(" Capacity: %u\n", bbt.capacity);
printf(" Bad block count: %u\n", bbt.header.bad_block_count);
printf(" Replacement count: %u\n", bbt.replacement_count);
if (ret != ERR_OK) {
printf(" ERROR: Initialization failed!\n");
return 1;
}
printf("\n2. Marking block 100 as bad...\n");
ret = bad_block_mark_bad(&bbt, 100);
printf(" Result: %d\n", ret);
printf(" Bad block count after mark: %u\n", bbt.header.bad_block_count);
printf("\n3. Checking if block 100 is bad...\n");
bool is_bad = bad_block_is_bad(&bbt, 100);
printf(" Is bad: %s\n", is_bad ? "true" : "false");
if (!is_bad) {
printf(" ERROR: Block should be marked as bad!\n");
printf(" Checking block_status bitmap...\n");
if (bbt.block_status) {
uint8_t byte = bbt.block_status[100 / 8];
uint8_t bit = (1 << (100 % 8));
printf(" Byte %d: 0x%02x (bit mask: 0x%02x)\n", 100/8, byte, bit);
printf(" Bit is %s\n", (byte & bit) ? "set" : "not set");
} else {
printf(" ERROR: block_status is NULL!\n");
}
}
printf("\n4. Getting replacement block...\n");
uint32_t replacement = bad_block_get_replacement(&bbt, 100);
printf(" Replacement for block 100: %u (0x%08x)\n", replacement, replacement);
printf("\n5. Cleaning up...\n");
bad_block_table_destroy(&bbt);
printf(" Done.\n");
return is_bad ? 0 : 1;
}