From mboxrd@z Thu Jan 1 00:00:00 1970 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 601F3C433F5 for ; Thu, 9 Dec 2021 12:22:15 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0F8C282A6C; Thu, 9 Dec 2021 13:22:12 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Yx/fG1uN"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E4C2882F7B; Thu, 9 Dec 2021 13:22:09 +0100 (CET) Received: from mail-io1-xd29.google.com (mail-io1-xd29.google.com [IPv6:2607:f8b0:4864:20::d29]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E2694811B9 for ; Thu, 9 Dec 2021 13:22:03 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=javad321javad@gmail.com Received: by mail-io1-xd29.google.com with SMTP id m9so6448619iop.0 for ; Thu, 09 Dec 2021 04:22:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=gBen9dOjADI43YLnoG63O5F2YDcsAMk12nfGyZfeL1I=; b=Yx/fG1uNQKujjqFGAMVM6JoBv8XcHK+dmD6x59CVYXNI9M4UqHBOlO2nDlk5OxUW9s 9LgOO0QrpAwFJgWsl+l8vQAfH0+ZQbi8MWZD3MQN5S/+sJQpgXF5Gei/QDSfDlp0AiNl cRnrZrbhc4BnPBcjkue5AT1+zTX6M5CCenhEiopsWFPaTI2dFeOuSKMpm7BT8sI2aZLB 0epMEgZv+xFK+aZ5ZmSrlLXowS4b6M+XTorEkWRE8VGXrPsvge1HIbTWLwqls1wEXKfk rRDcDUiwmrt6sp5Nt26MHkDAHV4tX9qAfHGV9CSidSCm3QOeghyJcLXiCppB65U/aLCV Xh6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=gBen9dOjADI43YLnoG63O5F2YDcsAMk12nfGyZfeL1I=; b=r8oPfJXQkI7+fXEnBco8/kykjwFNyRF4VyvdJc+p6tnnWQy9NUnebdKipVPJh/nVto x9LeT0Ql/VO6MjMn7XiZNVFsd8SQzQ9wE2EWg50tILL/E9t/c8FDabIyL2iMqtE6Xvp/ cVMY6KYzimZo727sPDvfuTlH3elWxjR6N2uBV5eknO+9Br2JPIm+0VfSEb7Yd39GHO5D jL3sVpTwFz7rfoWkPGfZLUTsQbT01AzzeJ53ZxAZULEMhuun6LoyIChAzf7vTGZ0hYkk y0bCDFKgnsE5TudRupmpP7Vavk3ww6U3Ns926Rm2EG/E2Gmfy8BkR8Lu/o47KmCT8d/B FWlA== X-Gm-Message-State: AOAM530WmXYuT3sAq2S7j3jNbL4VxwXF1IE8f1GGS0mi6oRrpNDRiY3Z jaShPt2kLTyjwfL+vEQUEBGOwHkvgMgHUeFJdmU= X-Google-Smtp-Source: ABdhPJz8v3DZfQQzel4oq55UnM7x3lDAnAbd8iTamSnlT+Ls5Yl9sJJWZpeNqQPkGjFmhVKHjWAmGpCEUDvtuhUvQC0= X-Received: by 2002:a05:6602:29d0:: with SMTP id z16mr13417049ioq.122.1639052522431; Thu, 09 Dec 2021 04:22:02 -0800 (PST) MIME-Version: 1.0 References: <20211208142238.127247-1-javad321javad@gmail.com> <20211208143456.53b9e996@donnerap.cambridge.arm.com> <20211208170328.7e7c4e29@donnerap.cambridge.arm.com> <20211208174325.62929fed@donnerap.cambridge.arm.com> <20211209112410.028cea01@donnerap.cambridge.arm.com> In-Reply-To: <20211209112410.028cea01@donnerap.cambridge.arm.com> From: Javad Rahimi Date: Thu, 9 Dec 2021 15:51:50 +0330 Message-ID: Subject: Re: [PATCH v2] Cubieboard2:SUN7I:Add LED BOOT support To: Andre Przywara Cc: u-boot@lists.denx.de, Jagan Teki , hdegoede@redhat.com Content-Type: text/plain; charset="UTF-8" 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, Dec 9, 2021 at 2:54 PM Andre Przywara wrote: Hi Andre, > > On Thu, 9 Dec 2021 14:38:08 +0330 > Javad Rahimi wrote: > > Hi Javad, > > > On Thu, Dec 9, 2021 at 6:24 AM Javad Rahimi wrote: > > > > > > On Wed, Dec 8, 2021 at 9:13 PM Andre Przywara wrote: > > > > > > > > On Wed, 8 Dec 2021 20:48:54 +0330 > > > > Javad Rahimi wrote: > > > > > > > > > On Wed, Dec 8, 2021 at 8:33 PM Andre Przywara wrote: > > > > > > > > > > > > On Wed, 8 Dec 2021 19:14:22 +0330 > > > > > > Javad Rahimi wrote: > > > > > > > > > > > > > On Wed, Dec 8, 2021 at 6:05 PM Andre Przywara wrote: > > > > > > > > > > > > > > > > On Wed, 8 Dec 2021 15:25:54 +0100 > > > > > > > > Frank Wunderlich wrote: > > > > > > > > > > > > > > > > Hi, > > > > > > > > > > > > > > > > > you should add maintainer email for your patch > > > > > > > > > > > > > > > > > > $ scripts/get_maintainer.pl board/sunxi/board.c > > > > > > > > > Jagan Teki (maintainer:ARM SUNXI) > > > > > > > > > Andre Przywara (maintainer:ARM SUNXI) > > > > > > > > > u-boot@lists.denx.de (open list) > > > > > > > > > > > > > > > > Thanks Frank! > > > > > > > > > > > > > > > > > > Gesendet: Mittwoch, 08. Dezember 2021 um 15:22 Uhr > > > > > > > > > > Von: "Javad Rahimi" > > > > > > > > > > An: u-boot@lists.denx.de > > > > > > > > > > Cc: "Javad Rahimi" > > > > > > > > > > Betreff: [PATCH v2] Cubieboard2:SUN7I:Add LED BOOT support > > > > > > > > > > > > > > > > > > > > This feature makes it possible to assign one of > > > > > > > > > > LED1(PH20) and LED2(PH21) to BOOT process LED. > > > > > > > > > > User should activates the "Enable status LED API" in > > > > > > > > > > "Device Drivers -> LED Support" > > > > > > > > > > > > > > > > Please have a look at the current pinephone_defconfig, because that uses > > > > > > > > the boot LED already in a much easier fashion: > > > > > > > > https://source.denx.de/u-boot/u-boot/-/commit/0534153fd1 > > > > > > > > > > > > > > > > Cheers, > > > > > > > > Andre > > > > > > > > > > > > > > > Hi Andre, > > > > > > > Thanks for your comments. I studied the pinephone_defconfig. > > > > > > > By default, when activating the same options on Cubieboard2_defconfig > > > > > > > it shows linker error for `__led_init` and `__led_set`. > > > > > > > In other words, they are not defined. So, in this patch, I added the > > > > > > > implementation for these functions for this board. > > > > > > > > > > > > Did you add the: > > > > > > CONFIG_SPL_DRIVERS_MISC=y > > > > > > line as well? And re-ran make Cubieboard2_defconfig? > > > > > > Because that seemed to work for me. > > > > > > > > > > > > Cheers, > > > > > > Andre > > > > > > > > > > > > > > > > > When I add CONFIG_SPL_DRIVERS_MISC=y > > > > > By flashing SD card and turning on the board, It freezes in this step: > > > > > ``` > > > > > U-Boot SPL 2022.01-rc3-00025-gf570594bc9-dirty (Dec 08 2021 - 20:36:51 +0330) > > > > > ``` > > > > > ----------------------------------------- > > > > > The customized defconfig file for Cubieboard: > > > > > ``` > > > > > CONFIG_ARM=y > > > > > CONFIG_ARCH_SUNXI=y > > > > > CONFIG_DEFAULT_DEVICE_TREE="sun7i-a20-cubieboard2" > > > > > CONFIG_SPL_DRIVERS_MISC=y > > > > > CONFIG_SPL=y > > > > > CONFIG_MACH_SUN7I=y > > > > > CONFIG_DRAM_CLK=480 > > > > > CONFIG_MMC0_CD_PIN="PH1" > > > > > CONFIG_SATAPWR="PB8" > > > > > CONFIG_AHCI=y > > > > > # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set > > > > > CONFIG_SPL_I2C=y > > > > > CONFIG_SCSI_AHCI=y > > > > > CONFIG_SYS_I2C_MVTWSI=y > > > > > CONFIG_SYS_I2C_SLAVE=0x7f > > > > > CONFIG_SYS_I2C_SPEED=400000 > > > > > CONFIG_PHY_REALTEK=y > > > > > CONFIG_ETH_DESIGNWARE=y > > > > > CONFIG_MII=y > > > > > CONFIG_SUN7I_GMAC=y > > > > > CONFIG_SCSI=y > > > > > CONFIG_USB_EHCI_HCD=y > > > > > CONFIG_USB_OHCI_HCD=y > > > > > CONFIG_LED_STATUS=y > > > > > CONFIG_LED_STATUS_GPIO=y > > > > > CONFIG_LED_STATUS0=y > > > > > CONFIG_LED_STATUS_BIT=114 > > > > > > > > This is the GPIO number, you need to adjust this to point to the pin your > > > > LED is connected to. PH20 would be 244, for instance: > > > > ('H' - 'A') * 32 + 20 > > > > > > > > Cheers, > > > > Andre > > > > > > > Thanks, > > > Now the LED is ON, but the loader still freezes in (SPL, I think) > > > ``` > > > U-Boot SPL 2022.01-rc3-00025-gf570594bc9-dirty (Dec 09 2021 - 06:19:40 +0330) > > > ``` > > > Best Regards, > > > Javad > > Hi Andre, > > The freeze problem solved when I placed `status_led_init` function > > after > > gd->ram_size = sunxi_dram_init(); > > When it is called before sunxi_dram_init(), the bootloader freezes. > > That's probably our old friend .bss in SPL again: To save precious SRAM > space, we place the BSS section in DRAM, so it's only available after the > DRAM init happened. So far the code that runs before DRAM init is not using > variables placed in BSS, so everything works. Possible solutions are: > 1) see if we can get rid of BSS variables in the LED code (my bet is on > "static int status_led_init_done = 0;" as the culprit) > 2) move the LED init after the DRAM init. That's probably a bit late, > though, depends a bit on what people expect from the boot LED. > 3) I guess the A20 can afford BSS in SRAM, but that would not help with > other (64-bit) boards. I actually wonder how it works there, though? > > I'd prefer 1), but 2) is surely easier. > > Cheers, > Andre > Your guess was true. The `status_led_init_done` was the culprit. I removed this variable and added a one-bit variable named "initialized" to the `led_dev_t ` . In this case, when `__led_init` is called, we can set it for every single LED. In this case, we can check `ld->initilized` for each led rather than blindly checking the `status_led_init_done` global variable. Best Regards, Javad > > > > Best Regards, > > Javad > > > > > CONFIG_LED_STATUS_STATE=2 > > > > > ``` > > > > > Best Regards, > > > > > Javad > > > > > > > > > > > > > > > > > > > > Signed-off-by: Javad Rahimi > > > > > > > > > > --- > > > > > > > > > > This is my first contributation in open source world. > > > > > > > > > > I'm sorry if I have mistakes in my commits and versioning. > > > > > > > > > > I do my best to learn fast. > > > > > > > > > > > > > > > > > > > > Changes in v2: > > > > > > > > > > - Missed braces added > > > > > > > > > > - Unnecessary debug removed > > > > > > > > > > - Some typo fixed > > > > > > > > > > > > > > > > > > > > board/sunxi/board.c | 49 +++++++++++++++++++++++++++++++++++++++++++++ > > > > > > > > > > 1 file changed, 49 insertions(+) > > > > > > > > > > > > > > > > > > > > diff --git a/board/sunxi/board.c b/board/sunxi/board.c > > > > > > > > > > index 4f5747c34a..5e2f6ae902 100644 > > > > > > > > > > --- a/board/sunxi/board.c > > > > > > > > > > +++ b/board/sunxi/board.c > > > > > > > > > > @@ -1002,3 +1002,52 @@ int board_fit_config_name_match(const char *name) > > > > > > > > > > return ret; > > > > > > > > > > } > > > > > > > > > > #endif > > > > > > > > > > + > > > > > > > > > > +#if defined(CONFIG_LED_STATUS) && defined(CONFIG_LED_STATUS_BOOT) && defined(CONFIG_LED_STATUS_BOARD_SPECIFIC) > > > > > > > > > > + > > > > > > > > > > +#define CUBIE2_LED_BOOT_GPIO "PH20" > > > > > > > > > > +static int gpio_boot_led; > > > > > > > > > > + > > > > > > > > > > +void __led_init(led_id_t mask, int state) > > > > > > > > > > +{ > > > > > > > > > > + int ret; > > > > > > > > > > + > > > > > > > > > > + if (mask != CONFIG_LED_STATUS_BOOT) > > > > > > > > > > + return; > > > > > > > > > > + > > > > > > > > > > + ret = gpio_lookup_name(CUBIE2_LED_BOOT_GPIO, NULL, NULL, &gpio_boot_led); > > > > > > > > > > + > > > > > > > > > > + if (ret) > > > > > > > > > > + return; > > > > > > > > > > + > > > > > > > > > > + ret = gpio_request(gpio_boot_led, "boot_led"); > > > > > > > > > > + if (ret == -1) { > > > > > > > > > > + debug("[gpio_request] Error:%d\n", ret); > > > > > > > > > > + return; > > > > > > > > > > + } > > > > > > > > > > + > > > > > > > > > > + ret = gpio_direction_output(gpio_boot_led, 1); > > > > > > > > > > + if (ret == -1) { > > > > > > > > > > + debug("[gpio_direction_output] Error:%d\n", ret); > > > > > > > > > > + return; > > > > > > > > > > + } > > > > > > > > > > + __led_set(mask, state); > > > > > > > > > > +} > > > > > > > > > > + > > > > > > > > > > +void __led_set(led_id_t mask, int state) > > > > > > > > > > +{ > > > > > > > > > > + if (mask != CONFIG_LED_STATUS_BOOT) > > > > > > > > > > + return; > > > > > > > > > > + > > > > > > > > > > + gpio_set_value(gpio_boot_led, state); > > > > > > > > > > +} > > > > > > > > > > + > > > > > > > > > > +void __led_toggle(led_id_t mask) > > > > > > > > > > +{ > > > > > > > > > > + if (mask != CONFIG_LED_STATUS_BOOT) > > > > > > > > > > + return; > > > > > > > > > > + > > > > > > > > > > + gpio_set_value(gpio_boot_led, !gpio_get_value(gpio_boot_led)); > > > > > > > > > > +} > > > > > > > > > > + > > > > > > > > > > +#endif > > > > > > > > > > -- > > > > > > > > > > 2.25.1 > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >