Skip to content

Commit 05c8316

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 c2ff5d8 commit 05c8316

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
@@ -400,6 +400,7 @@ sint8 chip_reset(void)
400400
sint8 wait_for_bootrom(uint8 arg)
401401
{
402402
sint8 ret = M2M_SUCCESS;
403+
uint16 retries = TIMEOUT;
403404
uint32 reg = 0, cnt = 0;
404405
uint32 u32GpReg1 = 0;
405406
uint32 u32DriverVerInfo = M2M_MAKE_VERSION_INFO(M2M_RELEASE_VERSION_MAJOR_NO,\
@@ -409,13 +410,19 @@ sint8 wait_for_bootrom(uint8 arg)
409410

410411

411412
reg = 0;
412-
while(1) {
413+
while(--retries) {
413414
reg = nm_read_reg(0x1014); /* wait for efuse loading done */
414415
if (reg & 0x80000000) {
415416
break;
416417
}
417418
nm_bsp_sleep(1); /* TODO: Why bus error if this delay is not here. */
418419
}
420+
421+
/* communication with device failed */
422+
if(retries == 0) {
423+
return M2M_ERR_INIT;
424+
}
425+
419426
reg = nm_read_reg(M2M_WAIT_FOR_HOST_REG);
420427
reg &= 0x1;
421428

0 commit comments

Comments
 (0)