lib/thread: Verify threads are initialized before yielding
In hardwaremain.c we call console_init before threads_initialize. Part of setting up the uart requires calling udelay which then calls thread_yield_microseconds. Since threads have not been set up, trying to yield will result in bad things happening. This change guards the thread methods by making current_thread return NULL if the structures have not been initialized. BUG=b:179699789 TEST=Ramstage no longer hangs with serial enabled Signed-off-by: Raul E Rangel <rrangel@chromium.org> Change-Id: If9e1eedfaebe584901d2937c8aa24e158706fa43 Reviewed-on: https://review.coreboot.org/c/coreboot/+/56318 Reviewed-by: Krystian Hebel <krystian.hebel@3mdeb.com> Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-by: Karthik Ramasubramanian <kramasub@google.com> Reviewed-by: Furquan Shaikh <furquan@google.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
parent
577e146895
commit
000138e6c1
|
@ -9,6 +9,8 @@
|
||||||
#include <thread.h>
|
#include <thread.h>
|
||||||
#include <timer.h>
|
#include <timer.h>
|
||||||
|
|
||||||
|
static bool initialized;
|
||||||
|
|
||||||
static void idle_thread_init(void);
|
static void idle_thread_init(void);
|
||||||
|
|
||||||
/* There needs to be at least one thread to run the ramstate state machine. */
|
/* There needs to be at least one thread to run the ramstate state machine. */
|
||||||
|
@ -40,6 +42,9 @@ static inline struct thread *cpu_info_to_thread(const struct cpu_info *ci)
|
||||||
|
|
||||||
static inline struct thread *current_thread(void)
|
static inline struct thread *current_thread(void)
|
||||||
{
|
{
|
||||||
|
if (!initialized)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
return cpu_info_to_thread(cpu_info());
|
return cpu_info_to_thread(cpu_info());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,6 +270,8 @@ void threads_initialize(void)
|
||||||
free_thread(t);
|
free_thread(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
initialized = 1;
|
||||||
|
|
||||||
idle_thread_init();
|
idle_thread_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue