Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 53282C433F5 for ; Thu, 9 Dec 2021 15:48:55 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 36540830A2; Thu, 9 Dec 2021 16:48:52 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 4890B80F6E; Thu, 9 Dec 2021 16:48:50 +0100 (CET) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id C195980F6E for ; Thu, 9 Dec 2021 16:48:46 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=andre.przywara@arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B6807ED1; Thu, 9 Dec 2021 07:48:45 -0800 (PST) Received: from donnerap.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 06F0D3F5A1; Thu, 9 Dec 2021 07:48:44 -0800 (PST) Date: Thu, 9 Dec 2021 15:48:42 +0000 From: Andre Przywara To: Javad Rahimi Cc: u-boot@lists.denx.de, jagan@amarulasolutions.com, hdegoede@redhat.com Subject: Re: [PATCH v1] Cubieboard2:Fix Cubieboard2 freeze, when LED boot enabled Message-ID: <20211209154842.2cea8333@donnerap.cambridge.arm.com> In-Reply-To: <20211209152006.7624-1-javad321javad@gmail.com> References: <20211209152006.7624-1-javad321javad@gmail.com> Organization: ARM X-Mailer: Claws Mail 3.17.5 (GTK+ 2.24.32; aarch64-unknown-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.38 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean On Thu, 9 Dec 2021 18:50:06 +0330 Javad Rahimi wrote: Hi Javad, thanks for the patch! > 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 So I'd say that the commit message and the subject is misleading, it's not a real fix, because nothing was really broken before. That fact that sunxi puts the BSS into DRAM, even when this is not available at the very beginning, is more a nasty workaround than a feature. So can you please reword the commit message, to focus on what this patch actually does, and mention that this allow to get rid of a global variable. And then just briefly mention that it helps sunxi to enable LEDs early, as a motivation. Some things below .... > Signed-off-by: Javad Rahimi > --- > > 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; This bitfield doesn't really help here, since the compiler will pad it with 31 more bits. So just make it a "bool", and let the compiler figure out what's best here. Or can you check whether you can fold this bit into the "state" variable? By introducing something like an "uninitialised" state? Or is there is another way to detect initialisation (period != 0)? > } 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; But this is not what the current code does, is it? At the moment a call to status_led_tick() would initialise all LEDs, now you just skip over (all of) them? > + > 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; Same here, I think? Cheers, Andre > ld->state = state; > if (state == CONFIG_LED_STATUS_BLINKING) { > ld->cnt = 0; /* always start with full period */