Skip to content

Commit 9e8c5f9

Browse files
committed
Implemented skipped bad block status message
1 parent 833912b commit 9e8c5f9

File tree

6 files changed

+40
-23
lines changed

6 files changed

+40
-23
lines changed

firmware/nand_programmer.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,9 @@ enum
123123
{
124124
NP_STATUS_OK = 0x00,
125125
NP_STATUS_ERROR = 0x01,
126-
NP_STATUS_BAD_BLOCK = 0x02,
126+
NP_STATUS_BB = 0x02,
127127
NP_STATUS_WRITE_ACK = 0x03,
128+
NP_STATUS_BB_SKIP = 0x04,
128129
};
129130

130131
typedef struct __attribute__((__packed__))
@@ -214,9 +215,10 @@ static int np_send_error(uint8_t err_code)
214215
return 0;
215216
}
216217

217-
static int np_send_bad_block_info(uint32_t addr, uint32_t size)
218+
static int np_send_bad_block_info(uint32_t addr, uint32_t size, bool is_skipped)
218219
{
219-
np_resp_t resp_header = { NP_RESP_STATUS, NP_STATUS_BAD_BLOCK };
220+
uint8_t info = is_skipped ? NP_STATUS_BB_SKIP : NP_STATUS_BB;
221+
np_resp_t resp_header = { NP_RESP_STATUS, info };
220222
np_resp_bad_block_t bad_block = { resp_header, addr, size };
221223

222224
if (np_comm_cb->send((uint8_t *)&bad_block, sizeof(bad_block)))
@@ -333,7 +335,7 @@ static int np_nand_erase(np_prog_t *prog, uint32_t page)
333335
case NAND_READY:
334336
break;
335337
case NAND_ERROR:
336-
if (np_send_bad_block_info(addr, prog->chip_info->block_size))
338+
if (np_send_bad_block_info(addr, prog->chip_info->block_size, false))
337339
return -1;
338340
break;
339341
case NAND_TIMEOUT_ERROR:
@@ -404,7 +406,7 @@ static int _np_cmd_nand_erase(np_prog_t *prog)
404406
if (skip_bb && (is_bad = nand_bad_block_table_lookup(addr)))
405407
{
406408
DEBUG_PRINT("Skipped bad block at 0x%lx\r\n", addr);
407-
if (np_send_bad_block_info(addr, prog->chip_info->block_size))
409+
if (np_send_bad_block_info(addr, prog->chip_info->block_size, true))
408410
return -1;
409411
}
410412

@@ -507,8 +509,11 @@ static int np_nand_handle_status(np_prog_t *prog)
507509
switch (nand_read_status())
508510
{
509511
case NAND_ERROR:
510-
if (np_send_bad_block_info(prog->addr, prog->chip_info->block_size))
512+
if (np_send_bad_block_info(prog->addr, prog->chip_info->block_size,
513+
false))
514+
{
511515
return -1;
516+
}
512517
case NAND_READY:
513518
prog->nand_wr_in_progress = 0;
514519
prog->nand_timeout = 0;
@@ -587,8 +592,11 @@ static int np_cmd_nand_write_data(np_prog_t *prog)
587592
while (prog->skip_bb && nand_bad_block_table_lookup(prog->addr))
588593
{
589594
DEBUG_PRINT("Skipped bad block at 0x%lx\r\n", addr);
590-
if (np_send_bad_block_info(prog->addr, prog->chip_info->block_size))
595+
if (np_send_bad_block_info(prog->addr, prog->chip_info->block_size,
596+
true))
597+
{
591598
return -1;
599+
}
592600

593601
prog->addr += prog->chip_info->block_size;
594602
prog->page.page += prog->chip_info->block_size /
@@ -691,7 +699,7 @@ static int np_nand_read(uint32_t addr, np_page_t *page,
691699
case NAND_READY:
692700
break;
693701
case NAND_ERROR:
694-
if (np_send_bad_block_info(addr, chip_info->block_size))
702+
if (np_send_bad_block_info(addr, chip_info->block_size, false))
695703
return -1;
696704
break;
697705
case NAND_TIMEOUT_ERROR:
@@ -767,7 +775,7 @@ static int _np_cmd_nand_read(np_prog_t *prog)
767775
if (skip_bb && nand_bad_block_table_lookup(addr))
768776
{
769777
DEBUG_PRINT("Skipped bad block at 0x%lx\r\n", addr);
770-
if (np_send_bad_block_info(addr, prog->chip_info->block_size))
778+
if (np_send_bad_block_info(addr, prog->chip_info->block_size, true))
771779
return -1;
772780

773781
/* On partial read do not count bad blocks */
@@ -858,7 +866,7 @@ static int np_send_bad_blocks(np_prog_t *prog)
858866
for (bb_iter = nand_bad_block_table_iter_alloc(&addr); bb_iter;
859867
bb_iter = nand_bad_block_table_iter_next(bb_iter, &addr))
860868
{
861-
if (np_send_bad_block_info(addr, prog->chip_info->block_size))
869+
if (np_send_bad_block_info(addr, prog->chip_info->block_size, false))
862870
return -1;
863871
}
864872

qt/cmd.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ typedef enum
7777
{
7878
STATUS_OK = 0x00,
7979
STATUS_ERROR = 0x01,
80-
STATUS_BAD_BLOCK = 0x02,
80+
STATUS_BB = 0x02,
8181
STATUS_WRITE_ACK = 0x03,
82+
STATUS_BB_SKIP = 0x04,
8283
} StatusData;
8384

8485

qt/reader.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,18 @@ int Reader::read(uint8_t *pbuf, uint32_t len)
7474
return ret;
7575
}
7676

77-
int Reader::handleBadBlock(uint8_t *pbuf, uint32_t len)
77+
int Reader::handleBadBlock(uint8_t *pbuf, uint32_t len, bool isSkipped)
7878
{
7979
RespBadBlock *badBlock = (RespBadBlock *)pbuf;
8080
size_t size = sizeof(RespBadBlock);
81+
QString message = isSkipped ? "Skipped bad block at 0x%1 size 0x%2" :
82+
"Bad block at 0x%1 size 0x%2";
8183

8284
if (len < size)
8385
return 0;
8486

85-
logInfo(QString("Bad block at 0x%1 size 0x%2").arg(badBlock->addr, 8, 16,
86-
QLatin1Char('0')).arg(badBlock->size, 8, 16, QLatin1Char('0')));
87+
logInfo(message.arg(badBlock->addr, 8, 16, QLatin1Char('0'))
88+
.arg(badBlock->size, 8, 16, QLatin1Char('0')));
8789

8890
if (rlen && isSkipBB && isReadLess)
8991
{
@@ -117,8 +119,10 @@ int Reader::handleStatus(uint8_t *pbuf, uint32_t len)
117119
{
118120
case STATUS_ERROR:
119121
return handleError(pbuf, len);
120-
case STATUS_BAD_BLOCK:
121-
return handleBadBlock(pbuf, len);
122+
case STATUS_BB:
123+
return handleBadBlock(pbuf, len, false);
124+
case STATUS_BB_SKIP:
125+
return handleBadBlock(pbuf, len, true);
122126
case STATUS_OK:
123127
// Exit read loop
124128
if (!rlen)

qt/reader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Reader : public QThread
3131
int readStart();
3232
int read(uint8_t *pbuf, uint32_t len);
3333
int handleError(uint8_t *pbuf, uint32_t len);
34-
int handleBadBlock(uint8_t *pbuf, uint32_t len);
34+
int handleBadBlock(uint8_t *pbuf, uint32_t len, bool isSkipped);
3535
int handleStatus(uint8_t *pbuf, uint32_t len);
3636
int handleData(uint8_t *pbuf, uint32_t len);
3737
int handlePacket(uint8_t *pbuf, uint32_t len);

qt/writer.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,18 @@ int Writer::handleWriteAck(RespHeader *header, uint32_t len)
8989
return size;
9090
}
9191

92-
int Writer::handleBadBlock(RespHeader *header, uint32_t len)
92+
int Writer::handleBadBlock(RespHeader *header, uint32_t len, bool isSkipped)
9393
{
9494
int size = sizeof(RespBadBlock);
9595
RespBadBlock *badBlock = (RespBadBlock *)header;
96+
QString message = isSkipped ? "Skipped bad block at 0x%1 size 0x%2" :
97+
"Bad block at 0x%1 size 0x%2";
9698

9799
if (len < (uint32_t)size)
98100
return 0;
99101

100-
logInfo(QString("Bad block at 0x%1").arg(badBlock->addr, 8, 16,
101-
QLatin1Char('0')));
102+
logInfo(message.arg(badBlock->addr, 8, 16, QLatin1Char('0'))
103+
.arg(badBlock->size, 8, 16, QLatin1Char('0')));
102104

103105
return size;
104106
}
@@ -127,8 +129,10 @@ int Writer::handleStatus(uint8_t *pbuf, uint32_t len)
127129
return sizeof(RespHeader);
128130
case STATUS_ERROR:
129131
return handleError(header, len);
130-
case STATUS_BAD_BLOCK:
131-
return handleBadBlock(header, len);
132+
case STATUS_BB:
133+
return handleBadBlock(header, len, false);
134+
case STATUS_BB_SKIP:
135+
return handleBadBlock(header, len, true);
132136
case STATUS_WRITE_ACK:
133137
return handleWriteAck(header, len);
134138
}

qt/writer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Writer : public QThread
2727
int write(uint8_t *data, uint32_t dataLen);
2828
int read(uint8_t *data, uint32_t dataLen);
2929
int handleWriteAck(RespHeader *header, uint32_t len);
30-
int handleBadBlock(RespHeader *header, uint32_t len);
30+
int handleBadBlock(RespHeader *header, uint32_t len, bool isSkipped);
3131
int handleError(RespHeader *header, uint32_t len);
3232
int handleStatus(uint8_t *pbuf, uint32_t len);
3333
int handlePacket(uint8_t *pbuf, uint32_t len);

0 commit comments

Comments
 (0)