diff --git a/os/arch/arm/src/amebasmart/amebasmart_smp.c b/os/arch/arm/src/amebasmart/amebasmart_smp.c index 974494da14..2c1f78c05b 100644 --- a/os/arch/arm/src/amebasmart/amebasmart_smp.c +++ b/os/arch/arm/src/amebasmart/amebasmart_smp.c @@ -147,22 +147,25 @@ int vPortSecondaryBoot(int cpu) int state; int count = 10; - err = psci_cpu_on(cpu, (unsigned long)__cpu1_start); - DEBUGASSERT(err >= 0); - - /* await for PSCI to report cpu state */ - do { - state = psci_affinity_info(cpu, 0); - if (state == AFF_STATE_ON) { - break; + /* If psci_cpu_on is called more than once, the CPU may not function properly. */ + if (psci_affinity_info(cpu, 0) == AFF_STATE_OFF) { + err = psci_cpu_on(cpu, (unsigned long)__cpu1_start); + DEBUGASSERT(err >= 0); + + /* await for PSCI to report cpu state */ + do { + state = psci_affinity_info(cpu, 0); + if (state == AFF_STATE_ON) { + break; + } + + DelayUs(50); + } while (count--); + + if (count <= 0) { + smplldbg("Secondary core boot timeout affinfo: %d\n", state); + return -ETIMEDOUT; } - - DelayUs(50); - } while (count--); - - if (count <= 0) { - smplldbg("Secondary core boot timeout affinfo: %d\n", state); - return -ETIMEDOUT; } return OK; diff --git a/os/arch/arm/src/armv7-a/arm_cpuoff.c b/os/arch/arm/src/armv7-a/arm_cpuoff.c index 4920620af7..9762715ba5 100644 --- a/os/arch/arm/src/armv7-a/arm_cpuoff.c +++ b/os/arch/arm/src/armv7-a/arm_cpuoff.c @@ -292,6 +292,10 @@ int up_cpu_off(int cpu) ret = up_cpu_down(cpu); if (ret < 0) { smplldbg("Failed to powerdown secondary core CPU%d\n", cpu); + /* The core has already been powered down. Returning an error here + * could cause a deadlock due to inconsistent CPU state. + * Therefore, turn the CPU back on. */ + (void)up_cpu_on(cpu); return ret; }