Skip to content

Commit 1d3796f

Browse files
committed
nmasic: limit retries in wait_for_bootrom()
If no device is connected or init failed, wait_for_bootrom() will be stuck in an infinite loop trying to get a result from nm_read_reg(). Place an upper limit on the number of retries so we can recover from this instead of being stuck here.
1 parent fa6526a commit 1d3796f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/driver/source/nmasic.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ sint8 chip_reset(void)
404404
sint8 wait_for_bootrom(uint8 arg)
405405
{
406406
sint8 ret = M2M_SUCCESS;
407+
uint16 retries = 1000;
407408
uint32 reg = 0, cnt = 0;
408409
uint32 u32GpReg1 = 0;
409410
uint32 u32DriverVerInfo = M2M_MAKE_VERSION_INFO(M2M_RELEASE_VERSION_MAJOR_NO,\
@@ -413,13 +414,19 @@ sint8 wait_for_bootrom(uint8 arg)
413414

414415

415416
reg = 0;
416-
while(1) {
417+
while(--retries) {
417418
reg = nm_read_reg(0x1014); /* wait for efuse loading done */
418419
if (reg & 0x80000000) {
419420
break;
420421
}
421422
nm_bsp_sleep(1); /* TODO: Why bus error if this delay is not here. */
422423
}
424+
425+
/* communication with device failed */
426+
if(retries == 0) {
427+
return M2M_ERR_INIT;
428+
}
429+
423430
reg = nm_read_reg(M2M_WAIT_FOR_HOST_REG);
424431
reg &= 0x1;
425432

0 commit comments

Comments
 (0)