[PATCH v1] Cubieboard2:Fix Cubieboard2 freeze, when LED boot enabled

Javad Rahimi javad321javad at gmail.com
Thu Dec 9 16:20:06 CET 2021


When enabling the LED support for Cubieboard2 (SUN7I)
the uboot freezes in status_led_init() function.
It uses a static global variable, while the .BSS is defined in DRAM area
while that function is called before DRAM

Signed-off-by: Javad Rahimi <javad321javad at gmail.com>
---

 drivers/misc/status_led.c | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/drivers/misc/status_led.c b/drivers/misc/status_led.c
index a6e9c03a02..7d30355423 100644
--- a/drivers/misc/status_led.c
+++ b/drivers/misc/status_led.c
@@ -23,6 +23,7 @@ typedef struct {
 	int state;
 	int period;
 	int cnt;
+	int initialized:1;
 } led_dev_t;
 
 led_dev_t led_dev[] = {
@@ -30,12 +31,14 @@ led_dev_t led_dev[] = {
 		CONFIG_LED_STATUS_STATE,
 		LED_STATUS_PERIOD,
 		0,
+		0,
 	},
 #if defined(CONFIG_LED_STATUS1)
 	{	CONFIG_LED_STATUS_BIT1,
 		CONFIG_LED_STATUS_STATE1,
 		LED_STATUS_PERIOD1,
 		0,
+		0,
 	},
 #endif
 #if defined(CONFIG_LED_STATUS2)
@@ -43,6 +46,7 @@ led_dev_t led_dev[] = {
 		CONFIG_LED_STATUS_STATE2,
 		LED_STATUS_PERIOD2,
 		0,
+		0,
 	},
 #endif
 #if defined(CONFIG_LED_STATUS3)
@@ -50,6 +54,7 @@ led_dev_t led_dev[] = {
 		CONFIG_LED_STATUS_STATE3,
 		LED_STATUS_PERIOD3,
 		0,
+		0,
 	},
 #endif
 #if defined(CONFIG_LED_STATUS4)
@@ -57,6 +62,7 @@ led_dev_t led_dev[] = {
 		CONFIG_LED_STATUS_STATE4,
 		LED_STATUS_PERIOD4,
 		0,
+		0,
 	},
 #endif
 #if defined(CONFIG_LED_STATUS5)
@@ -64,22 +70,26 @@ led_dev_t led_dev[] = {
 		CONFIG_LED_STATUS_STATE5,
 		LED_STATUS_PERIOD5,
 		0,
+		0,
 	},
 #endif
 };
 
 #define MAX_LED_DEV	(sizeof(led_dev)/sizeof(led_dev_t))
 
-static int status_led_init_done = 0;
 
 void status_led_init(void)
 {
 	led_dev_t *ld;
 	int i;
 
-	for (i = 0, ld = led_dev; i < MAX_LED_DEV; i++, ld++)
+	for (i = 0, ld = led_dev; i < MAX_LED_DEV; i++, ld++) {
 		__led_init (ld->mask, ld->state);
-	status_led_init_done = 1;
+		ld->initialized = 1;
+	}
+
+	return 0;
+
 }
 
 void status_led_tick(ulong timestamp)
@@ -87,11 +97,11 @@ void status_led_tick(ulong timestamp)
 	led_dev_t *ld;
 	int i;
 
-	if (!status_led_init_done)
-		status_led_init();
-
 	for (i = 0, ld = led_dev; i < MAX_LED_DEV; i++, ld++) {
 
+		if (!ld->initialized)
+			continue;
+
 		if (ld->state != CONFIG_LED_STATUS_BLINKING)
 			continue;
 
@@ -110,11 +120,11 @@ void status_led_set(int led, int state)
 	if (led < 0 || led >= MAX_LED_DEV)
 		return;
 
-	if (!status_led_init_done)
-		status_led_init();
-
 	ld = &led_dev[led];
 
+	if (!ld->initialized)
+		return;
+
 	ld->state = state;
 	if (state == CONFIG_LED_STATUS_BLINKING) {
 		ld->cnt = 0;		/* always start with full period    */
-- 
2.25.1



More information about the U-Boot mailing list