回复: [PATCH v1] mailbox: add i.MX MU driver

2024-09-29 Thread Alice Guo (OSS)
Sorry, please ignore this patch. I used the wrong mail.

> -邮件原件-
> 发件人: U-Boot  代表 Alice Guo
> 发送时间: 2024年9月29日 9:55
> 收件人: u-boot@lists.denx.de
> 抄送: tr...@konsulko.com; Peng Fan ; Viorel Suman
> ; michal.si...@amd.com; Ye Li ;
> Alice Guo 
> 主题: [PATCH v1] mailbox: add i.MX MU driver
> 
> From: Peng Fan 
> 
> Add i.MX MU based mailbox driver.
> 
> Signed-off-by: Viorel Suman 
> Signed-off-by: Peng Fan 
> Signed-off-by: Alice Guo 
> Reviewed-by: Ye Li 
> ---
>  drivers/mailbox/Kconfig   |   7 +
>  drivers/mailbox/Makefile  |   1 +
>  drivers/mailbox/imx-mailbox.c | 417
> ++
>  3 files changed, 425 insertions(+)
>  create mode 100644 drivers/mailbox/imx-mailbox.c
> 
> diff --git a/drivers/mailbox/Kconfig b/drivers/mailbox/Kconfig index
> 67d5ac1a74..4d9f004eba 100644
> --- a/drivers/mailbox/Kconfig
> +++ b/drivers/mailbox/Kconfig
> @@ -21,6 +21,13 @@ config APPLE_MBOX
> such as the System Management Controller (SMC) and NVMe and this
> driver is required to get that functionality up and running.
> 
> +config IMX_MU_MBOX
> + bool "Enable i.MX MU MBOX support"
> + depends on DM_MAILBOX
> + help
> +   Enable support for i.MX Messaging Unit for communication with other
> +   processors on the SoC using mailbox interface
> +
>  config SANDBOX_MBOX
>   bool "Enable the sandbox mailbox test driver"
>   depends on DM_MAILBOX && SANDBOX
> diff --git a/drivers/mailbox/Makefile b/drivers/mailbox/Makefile index
> 59e8d0de93..96a6adb709 100644
> --- a/drivers/mailbox/Makefile
> +++ b/drivers/mailbox/Makefile
> @@ -5,6 +5,7 @@
> 
>  obj-$(CONFIG_$(SPL_)DM_MAILBOX) += mailbox-uclass.o
>  obj-$(CONFIG_APPLE_MBOX) += apple-mbox.o
> +obj-$(CONFIG_IMX_MU_MBOX) += imx-mailbox.o
>  obj-$(CONFIG_SANDBOX_MBOX) += sandbox-mbox.o
>  obj-$(CONFIG_SANDBOX_MBOX) += sandbox-mbox-test.o
>  obj-$(CONFIG_STM32_IPCC) += stm32-ipcc.o diff --git
> a/drivers/mailbox/imx-mailbox.c b/drivers/mailbox/imx-mailbox.c new file
> mode 100644 index 00..584950b20d
> --- /dev/null
> +++ b/drivers/mailbox/imx-mailbox.c
> @@ -0,0 +1,417 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Copyright 2017-2023 NXP
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +/* This driver only exposes the status bits to keep with the
> + * polling methodology of u-boot.
> + */
> +DECLARE_GLOBAL_DATA_PTR;
> +
> +#define IMX_MU_CHANS 24
> +
> +#define IMX_MU_V2_PAR_OFF0x4
> +#define IMX_MU_V2_TR_MASKGENMASK(7, 0)
> +#define IMX_MU_V2_RR_MASKGENMASK(15, 8)
> +
> +enum imx_mu_chan_type {
> + IMX_MU_TYPE_TX  = 0, /* Tx */
> + IMX_MU_TYPE_RX  = 1, /* Rx */
> + IMX_MU_TYPE_TXDB= 2, /* Tx doorbell */
> + IMX_MU_TYPE_RXDB= 3, /* Rx doorbell */
> + IMX_MU_TYPE_RST = 4, /* Reset */
> + IMX_MU_TYPE_TXDB_V2 = 5, /* Tx doorbell with S/W ACK */
> +};
> +
> +enum imx_mu_xcr {
> + IMX_MU_CR,
> + IMX_MU_GIER,
> + IMX_MU_GCR,
> + IMX_MU_TCR,
> + IMX_MU_RCR,
> + IMX_MU_xCR_MAX,
> +};
> +
> +enum imx_mu_xsr {
> + IMX_MU_SR,
> + IMX_MU_GSR,
> + IMX_MU_TSR,
> + IMX_MU_RSR,
> + IMX_MU_xSR_MAX,
> +};
> +
> +struct imx_mu_con_priv {
> + unsigned intidx;
> + enum imx_mu_chan_type   type;
> + struct mbox_chan*chan;
> +};
> +
> +enum imx_mu_type {
> + IMX_MU_V1,
> + IMX_MU_V2 = BIT(1),
> + IMX_MU_V2_S4 = BIT(15),
> + IMX_MU_V2_IRQ = BIT(16),
> +};
> +
> +struct imx_mu {
> + void __iomem *base;
> + const struct imx_mu_dcfg *dcfg;
> + u32 num_tr;
> + u32 num_rr;
> + /* use pointers to channel as a way to reserve channels */
> + struct mbox_chan *channels[IMX_MU_CHANS];
> + struct imx_mu_con_priv  con_priv[IMX_MU_CHANS]; };
> +
> +struct imx_mu_dcfg {
> + int (*tx)(struct imx_mu *plat, struct imx_mu_con_priv *cp, const void
> *data);
> + int (*rx)(struct imx_mu *plat, struct imx_mu_con_priv *cp);
> + int (*rxdb)(struct imx_mu *plat, struct imx_mu_con_priv *cp);
> + int (*init)(struct imx_mu *plat);
> + int (*of_xlate)(struct mbox_chan *chan, struct ofnode_phandle_args
> *args);
> + enum imx_mu_type type;
> + u32 xTR;/* Transmit Register0 */
> + u32 xRR;/* Receive Register0 */
> + u32 xSR[IMX_MU_xSR_MAX];/* Status Registers */
> + u32 xCR[IMX_MU_xCR_MAX];/* Control Registers */
> +};
> +
> +#define IMX_MU_xSR_GIPn(type, x) (type & IMX_MU_V2 ? BIT(x) : BIT(28 +
> +(3 - (x #define IMX_MU_xSR_RFn(type, x) (type & IMX_MU_V2 ? BIT(x)
> +: BIT(24 + (3 - (x #define IMX_MU_xSR_TEn(type, x) (type &
> +IMX_MU_V2 ? BIT(x) : BIT(20 + (3 - (x
> +
> +/* General Purpose Interrupt Enable */
> +#define IMX_MU_xCR_GIEn(type, x) (type & IMX_MU_V2 ? BIT(x) : BIT(28 +
> +(3 - (x
> +/* Receive Interrupt Enable */
> +#define IMX

[PATCH v2 4/4] watchdog: ulp_wdog: add driver model for ulp watchdog driver

2022-10-21 Thread Alice Guo (OSS)
From: Alice Guo 

Enable driver model for ulp watchdog timer. When CONFIG_WDT=y and the
status of device node is "okay", initr_watchdog will be called and
finally calls ulp_wdt_probe() and ulp_wdt_start().

Signed-off-by: Alice Guo 
Reviewed-by: Ye Li 
---

Changes for v2:
 none

 drivers/watchdog/ulp_wdog.c | 94 ++---
 1 file changed, 87 insertions(+), 7 deletions(-)

diff --git a/drivers/watchdog/ulp_wdog.c b/drivers/watchdog/ulp_wdog.c
index 1b286816b5..e081054304 100644
--- a/drivers/watchdog/ulp_wdog.c
+++ b/drivers/watchdog/ulp_wdog.c
@@ -7,6 +7,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 /*
  * MX7ULP WDOG Register Map
@@ -18,6 +20,11 @@ struct wdog_regs {
u32 win;
 };
 
+struct ulp_wdt_priv {
+   struct wdog_regs *wdog;
+   u32 clk_rate;
+};
+
 #ifndef CONFIG_WATCHDOG_TIMEOUT_MSECS
 #define CONFIG_WATCHDOG_TIMEOUT_MSECS 0x1500
 #endif
@@ -46,6 +53,9 @@ struct wdog_regs {
 #define WDG_32KHZ_CLK(0x2)
 #define WDG_EXT_CLK  (0x3)
 
+#define CLK_RATE_1KHZ  1000
+#define CLK_RATE_32KHZ 125
+
 void hw_watchdog_set_timeout(u16 val)
 {
/* setting timeout value */
@@ -54,10 +64,8 @@ void hw_watchdog_set_timeout(u16 val)
writel(val, &wdog->toval);
 }
 
-void hw_watchdog_reset(void)
+void ulp_watchdog_reset(struct wdog_regs *wdog)
 {
-   struct wdog_regs *wdog = (struct wdog_regs *)WDOG_BASE_ADDR;
-
if (readl(&wdog->cs) & WDGCS_CMD32EN) {
writel(REFRESH_WORD, &wdog->cnt);
} else {
@@ -68,9 +76,8 @@ void hw_watchdog_reset(void)
}
 }
 
-void hw_watchdog_init(void)
+void ulp_watchdog_init(struct wdog_regs *wdog, u16 timeout)
 {
-   struct wdog_regs *wdog = (struct wdog_regs *)WDOG_BASE_ADDR;
u32 cmd32 = 0;
 
if (readl(&wdog->cs) & WDGCS_CMD32EN) {
@@ -87,7 +94,7 @@ void hw_watchdog_init(void)
while (!(readl(&wdog->cs) & WDGCS_ULK))
;
 
-   hw_watchdog_set_timeout(CONFIG_WATCHDOG_TIMEOUT_MSECS);
+   hw_watchdog_set_timeout(timeout);
writel(0, &wdog->win);
 
/* setting 1-kHz clock source, enable counter running, and clear 
interrupt */
@@ -102,7 +109,21 @@ void hw_watchdog_init(void)
while (!(readl(&wdog->cs) & WDGCS_RCS))
;
 
-   hw_watchdog_reset();
+   ulp_watchdog_reset(wdog);
+}
+
+void hw_watchdog_reset(void)
+{
+   struct wdog_regs *wdog = (struct wdog_regs *)WDOG_BASE_ADDR;
+
+   ulp_watchdog_reset(wdog);
+}
+
+void hw_watchdog_init(void)
+{
+   struct wdog_regs *wdog = (struct wdog_regs *)WDOG_BASE_ADDR;
+
+   ulp_watchdog_init(wdog, CONFIG_WATCHDOG_TIMEOUT_MSECS);
 }
 
 void reset_cpu(void)
@@ -142,3 +163,62 @@ void reset_cpu(void)
 
while (1);
 }
+
+static int ulp_wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags)
+{
+   struct ulp_wdt_priv *priv = dev_get_priv(dev);
+   u64 timeout = 0;
+
+   timeout = (timeout_ms * priv->clk_rate) / 1000;
+   if (timeout > U16_MAX)
+   return -EINVAL;
+
+   ulp_watchdog_init(priv->wdog, (u16)timeout);
+
+   return 0;
+}
+
+static int ulp_wdt_reset(struct udevice *dev)
+{
+   struct ulp_wdt_priv *priv = dev_get_priv(dev);
+
+   ulp_watchdog_reset(priv->wdog);
+
+   return 0;
+}
+
+static int ulp_wdt_probe(struct udevice *dev)
+{
+   struct ulp_wdt_priv *priv = dev_get_priv(dev);
+
+   priv->wdog = dev_read_addr_ptr(dev);
+   if (!priv->wdog)
+   return -EINVAL;
+
+   priv->clk_rate = (u32)dev_get_driver_data(dev);
+   if (!priv->clk_rate)
+   return -EINVAL;
+
+   return 0;
+}
+
+static const struct wdt_ops ulp_wdt_ops = {
+   .start = ulp_wdt_start,
+   .reset = ulp_wdt_reset,
+};
+
+static const struct udevice_id ulp_wdt_ids[] = {
+   { .compatible = "fsl,imx7ulp-wdt", .data = CLK_RATE_1KHZ },
+   { .compatible = "fsl,imx8ulp-wdt", .data = CLK_RATE_1KHZ },
+   { .compatible = "fsl,imx93-wdt", .data = CLK_RATE_32KHZ },
+   {}
+};
+
+U_BOOT_DRIVER(ulp_wdt) = {
+   .name   = "ulp_wdt",
+   .id = UCLASS_WDT,
+   .of_match   = ulp_wdt_ids,
+   .priv_auto  = sizeof(struct ulp_wdt_priv),
+   .probe  = ulp_wdt_probe,
+   .ops= &ulp_wdt_ops,
+};
-- 
2.17.1



[PATCH v2 3/4] watchdog: ulp_wdog: enable watchdog interrupt on imx93

2022-10-21 Thread Alice Guo (OSS)
From: Alice Guo 

The reset source of the external PMIC on i.MX93 is WDOG_ANY PAD and the
source of WDOG_ANY PAD is interrupt. Therefore, using PMIC to reset
needs to enable the watchdog interrupt.

Signed-off-by: Alice Guo 
---

Changes for v2:
 none

 drivers/watchdog/ulp_wdog.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/watchdog/ulp_wdog.c b/drivers/watchdog/ulp_wdog.c
index 17778587ee..1b286816b5 100644
--- a/drivers/watchdog/ulp_wdog.c
+++ b/drivers/watchdog/ulp_wdog.c
@@ -39,6 +39,7 @@ struct wdog_regs {
 #define WDOG_CS_PRESBIT(12)
 #define WDGCS_CMD32EN   BIT(13)
 #define WDGCS_FLG   BIT(14)
+#define WDGCS_INT  BIT(6)
 
 #define WDG_BUS_CLK  (0x0)
 #define WDG_LPO_CLK  (0x1)
@@ -92,7 +93,7 @@ void hw_watchdog_init(void)
/* setting 1-kHz clock source, enable counter running, and clear 
interrupt */
if (IS_ENABLED(CONFIG_ARCH_IMX9))
writel((cmd32 | WDGCS_WDGE | WDGCS_WDGUPDATE | (WDG_LPO_CLK << 
8) |
-  WDGCS_FLG | WDOG_CS_PRES), &wdog->cs);
+  WDGCS_FLG | WDOG_CS_PRES | WDGCS_INT), &wdog->cs);
else
writel((cmd32 | WDGCS_WDGE | WDGCS_WDGUPDATE | (WDG_LPO_CLK << 
8) |
   WDGCS_FLG), &wdog->cs);
@@ -128,7 +129,8 @@ void reset_cpu(void)
 
/* enable counter running */
if (IS_ENABLED(CONFIG_ARCH_IMX9))
-   writel((cmd32 | WDGCS_WDGE | (WDG_LPO_CLK << 8) | 
WDOG_CS_PRES), &wdog->cs);
+   writel((cmd32 | WDGCS_WDGE | (WDG_LPO_CLK << 8) | WDOG_CS_PRES |
+  WDGCS_INT), &wdog->cs);
else
writel((cmd32 | WDGCS_WDGE | (WDG_LPO_CLK << 8)), &wdog->cs);
 
-- 
2.17.1



[PATCH v2 2/4] watchdog: ulp_wdog: Update watchdog driver for imx93

2022-10-21 Thread Alice Guo (OSS)
From: Alice Guo 

The WDOG clocks are sourced from the fixed 32KHz (lpo_clk).When the
timeout period exceeds 2 seconds, the value written to the TOVAL
register is larger than 16-bit can represent. Enabling watchdog
prescaler to solve this problem.

Signed-off-by: Alice Guo 
---

Changes for v2:
 use 'if (IS_ENABLED(CONFIG...))' instead of '#if or #ifdef'

 drivers/watchdog/ulp_wdog.c | 15 ---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/watchdog/ulp_wdog.c b/drivers/watchdog/ulp_wdog.c
index 820da0f9dd..17778587ee 100644
--- a/drivers/watchdog/ulp_wdog.c
+++ b/drivers/watchdog/ulp_wdog.c
@@ -36,6 +36,7 @@ struct wdog_regs {
 
 #define WDGCS_RCS   BIT(10)
 #define WDGCS_ULK   BIT(11)
+#define WDOG_CS_PRESBIT(12)
 #define WDGCS_CMD32EN   BIT(13)
 #define WDGCS_FLG   BIT(14)
 
@@ -89,7 +90,12 @@ void hw_watchdog_init(void)
writel(0, &wdog->win);
 
/* setting 1-kHz clock source, enable counter running, and clear 
interrupt */
-   writel((cmd32 | WDGCS_WDGE | WDGCS_WDGUPDATE | (WDG_LPO_CLK << 8) | 
WDGCS_FLG), &wdog->cs);
+   if (IS_ENABLED(CONFIG_ARCH_IMX9))
+   writel((cmd32 | WDGCS_WDGE | WDGCS_WDGUPDATE | (WDG_LPO_CLK << 
8) |
+  WDGCS_FLG | WDOG_CS_PRES), &wdog->cs);
+   else
+   writel((cmd32 | WDGCS_WDGE | WDGCS_WDGUPDATE | (WDG_LPO_CLK << 
8) |
+  WDGCS_FLG), &wdog->cs);
 
/* Wait WDOG reconfiguration */
while (!(readl(&wdog->cs) & WDGCS_RCS))
@@ -117,11 +123,14 @@ void reset_cpu(void)
while (!(readl(&wdog->cs) & WDGCS_ULK))
;
 
-   hw_watchdog_set_timeout(5); /* 5ms timeout */
+   hw_watchdog_set_timeout(5); /* 5ms timeout for general; 40ms timeout 
for imx93 */
writel(0, &wdog->win);
 
/* enable counter running */
-   writel((cmd32 | WDGCS_WDGE | (WDG_LPO_CLK << 8)), &wdog->cs);
+   if (IS_ENABLED(CONFIG_ARCH_IMX9))
+   writel((cmd32 | WDGCS_WDGE | (WDG_LPO_CLK << 8) | 
WDOG_CS_PRES), &wdog->cs);
+   else
+   writel((cmd32 | WDGCS_WDGE | (WDG_LPO_CLK << 8)), &wdog->cs);
 
/* Wait WDOG reconfiguration */
while (!(readl(&wdog->cs) & WDGCS_RCS))
-- 
2.17.1



[PATCH v2 1/4] ulp_wdog: Update ulp wdog driver for 32bits command

2022-10-21 Thread Alice Guo (OSS)
From: Ye Li 

To use 32bits refresh and unlock command as default, check the CMD32EN
bit to select the corresponding commands.

Signed-off-by: Ye Li 
Signed-off-by: Alice Guo 
Reviewed-by: Peng Fan 
---

Changes for v2:
 resolve a coding style issue

 drivers/watchdog/ulp_wdog.c | 52 +
 1 file changed, 36 insertions(+), 16 deletions(-)

diff --git a/drivers/watchdog/ulp_wdog.c b/drivers/watchdog/ulp_wdog.c
index ecd35ef22a..820da0f9dd 100644
--- a/drivers/watchdog/ulp_wdog.c
+++ b/drivers/watchdog/ulp_wdog.c
@@ -28,11 +28,15 @@ struct wdog_regs {
 #define UNLOCK_WORD0 0xC520 /* 1st unlock word */
 #define UNLOCK_WORD1 0xD928 /* 2nd unlock word */
 
+#define UNLOCK_WORD 0xD928C520 /* unlock word */
+#define REFRESH_WORD 0xB480A602 /* refresh word */
+
 #define WDGCS_WDGE  BIT(7)
 #define WDGCS_WDGUPDATE BIT(5)
 
 #define WDGCS_RCS   BIT(10)
 #define WDGCS_ULK   BIT(11)
+#define WDGCS_CMD32EN   BIT(13)
 #define WDGCS_FLG   BIT(14)
 
 #define WDG_BUS_CLK  (0x0)
@@ -52,20 +56,30 @@ void hw_watchdog_reset(void)
 {
struct wdog_regs *wdog = (struct wdog_regs *)WDOG_BASE_ADDR;
 
-   dmb();
-   __raw_writel(REFRESH_WORD0, &wdog->cnt);
-   __raw_writel(REFRESH_WORD1, &wdog->cnt);
-   dmb();
+   if (readl(&wdog->cs) & WDGCS_CMD32EN) {
+   writel(REFRESH_WORD, &wdog->cnt);
+   } else {
+   dmb();
+   __raw_writel(REFRESH_WORD0, &wdog->cnt);
+   __raw_writel(REFRESH_WORD1, &wdog->cnt);
+   dmb();
+   }
 }
 
 void hw_watchdog_init(void)
 {
struct wdog_regs *wdog = (struct wdog_regs *)WDOG_BASE_ADDR;
-
-   dmb();
-   __raw_writel(UNLOCK_WORD0, &wdog->cnt);
-   __raw_writel(UNLOCK_WORD1, &wdog->cnt);
-   dmb();
+   u32 cmd32 = 0;
+
+   if (readl(&wdog->cs) & WDGCS_CMD32EN) {
+   writel(UNLOCK_WORD, &wdog->cnt);
+   cmd32 = WDGCS_CMD32EN;
+   } else {
+   dmb();
+   __raw_writel(UNLOCK_WORD0, &wdog->cnt);
+   __raw_writel(UNLOCK_WORD1, &wdog->cnt);
+   dmb();
+   }
 
/* Wait WDOG Unlock */
while (!(readl(&wdog->cs) & WDGCS_ULK))
@@ -75,7 +89,7 @@ void hw_watchdog_init(void)
writel(0, &wdog->win);
 
/* setting 1-kHz clock source, enable counter running, and clear 
interrupt */
-   writel((WDGCS_WDGE | WDGCS_WDGUPDATE |(WDG_LPO_CLK << 8) | WDGCS_FLG), 
&wdog->cs);
+   writel((cmd32 | WDGCS_WDGE | WDGCS_WDGUPDATE | (WDG_LPO_CLK << 8) | 
WDGCS_FLG), &wdog->cs);
 
/* Wait WDOG reconfiguration */
while (!(readl(&wdog->cs) & WDGCS_RCS))
@@ -87,11 +101,17 @@ void hw_watchdog_init(void)
 void reset_cpu(void)
 {
struct wdog_regs *wdog = (struct wdog_regs *)WDOG_BASE_ADDR;
-
-   dmb();
-   __raw_writel(UNLOCK_WORD0, &wdog->cnt);
-   __raw_writel(UNLOCK_WORD1, &wdog->cnt);
-   dmb();
+   u32 cmd32 = 0;
+
+   if (readl(&wdog->cs) & WDGCS_CMD32EN) {
+   writel(UNLOCK_WORD, &wdog->cnt);
+   cmd32 = WDGCS_CMD32EN;
+   } else {
+   dmb();
+   __raw_writel(UNLOCK_WORD0, &wdog->cnt);
+   __raw_writel(UNLOCK_WORD1, &wdog->cnt);
+   dmb();
+   }
 
/* Wait WDOG Unlock */
while (!(readl(&wdog->cs) & WDGCS_ULK))
@@ -101,7 +121,7 @@ void reset_cpu(void)
writel(0, &wdog->win);
 
/* enable counter running */
-   writel((WDGCS_WDGE | (WDG_LPO_CLK << 8)), &wdog->cs);
+   writel((cmd32 | WDGCS_WDGE | (WDG_LPO_CLK << 8)), &wdog->cs);
 
/* Wait WDOG reconfiguration */
while (!(readl(&wdog->cs) & WDGCS_RCS))
-- 
2.17.1



[PATCH v2 0/4] ulp wdog

2022-10-21 Thread Alice Guo (OSS)
From: Alice Guo 

Alice Guo (3):
  watchdog: ulp_wdog: Update watchdog driver for imx93
  watchdog: ulp_wdog: enable watchdog interrupt on imx93
  watchdog: ulp_wdog: add driver model for ulp watchdog driver

Ye Li (1):
  ulp_wdog: Update ulp wdog driver for 32bits command

 drivers/watchdog/ulp_wdog.c | 159 ++--
 1 file changed, 135 insertions(+), 24 deletions(-)

-- 
2.17.1



[PATCH v1 4/4] watchdog: ulp_wdog: add driver model for ulp watchdog driver

2022-10-09 Thread Alice Guo (OSS)
From: Alice Guo 

Enable driver model for ulp watchdog timer. When CONFIG_WDT=y and the
status of device node is "okay", initr_watchdog will be called and
finally calls ulp_wdt_probe() and ulp_wdt_start().

Signed-off-by: Alice Guo 
Reviewed-by: Ye Li 
---
 drivers/watchdog/ulp_wdog.c | 94 ++---
 1 file changed, 87 insertions(+), 7 deletions(-)

diff --git a/drivers/watchdog/ulp_wdog.c b/drivers/watchdog/ulp_wdog.c
index 49f8900cd3..93cf6e253d 100644
--- a/drivers/watchdog/ulp_wdog.c
+++ b/drivers/watchdog/ulp_wdog.c
@@ -7,6 +7,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 /*
  * MX7ULP WDOG Register Map
@@ -18,6 +20,11 @@ struct wdog_regs {
u32 win;
 };
 
+struct ulp_wdt_priv {
+   struct wdog_regs *wdog;
+   u32 clk_rate;
+};
+
 #ifndef CONFIG_WATCHDOG_TIMEOUT_MSECS
 #define CONFIG_WATCHDOG_TIMEOUT_MSECS 0x1500
 #endif
@@ -46,6 +53,9 @@ struct wdog_regs {
 #define WDG_32KHZ_CLK(0x2)
 #define WDG_EXT_CLK  (0x3)
 
+#define CLK_RATE_1KHZ  1000
+#define CLK_RATE_32KHZ 125
+
 void hw_watchdog_set_timeout(u16 val)
 {
/* setting timeout value */
@@ -54,10 +64,8 @@ void hw_watchdog_set_timeout(u16 val)
writel(val, &wdog->toval);
 }
 
-void hw_watchdog_reset(void)
+void ulp_watchdog_reset(struct wdog_regs *wdog)
 {
-   struct wdog_regs *wdog = (struct wdog_regs *)WDOG_BASE_ADDR;
-
if (readl(&wdog->cs) & WDGCS_CMD32EN) {
writel(REFRESH_WORD, &wdog->cnt);
} else {
@@ -68,9 +76,8 @@ void hw_watchdog_reset(void)
}
 }
 
-void hw_watchdog_init(void)
+void ulp_watchdog_init(struct wdog_regs *wdog, u16 timeout)
 {
-   struct wdog_regs *wdog = (struct wdog_regs *)WDOG_BASE_ADDR;
u32 cmd32 = 0;
 
if (readl(&wdog->cs) & WDGCS_CMD32EN) {
@@ -87,7 +94,7 @@ void hw_watchdog_init(void)
while (!(readl(&wdog->cs) & WDGCS_ULK))
;
 
-   hw_watchdog_set_timeout(CONFIG_WATCHDOG_TIMEOUT_MSECS);
+   hw_watchdog_set_timeout(timeout);
writel(0, &wdog->win);
 
/* setting 1-kHz clock source, enable counter running, and clear 
interrupt */
@@ -102,7 +109,21 @@ void hw_watchdog_init(void)
while (!(readl(&wdog->cs) & WDGCS_RCS))
;
 
-   hw_watchdog_reset();
+   ulp_watchdog_reset(wdog);
+}
+
+void hw_watchdog_reset(void)
+{
+   struct wdog_regs *wdog = (struct wdog_regs *)WDOG_BASE_ADDR;
+
+   ulp_watchdog_reset(wdog);
+}
+
+void hw_watchdog_init(void)
+{
+   struct wdog_regs *wdog = (struct wdog_regs *)WDOG_BASE_ADDR;
+
+   ulp_watchdog_init(wdog, CONFIG_WATCHDOG_TIMEOUT_MSECS);
 }
 
 void reset_cpu(void)
@@ -142,3 +163,62 @@ void reset_cpu(void)
 
while (1);
 }
+
+static int ulp_wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags)
+{
+   struct ulp_wdt_priv *priv = dev_get_priv(dev);
+   u64 timeout = 0;
+
+   timeout = (timeout_ms * priv->clk_rate) / 1000;
+   if (timeout > U16_MAX)
+   return -EINVAL;
+
+   ulp_watchdog_init(priv->wdog, (u16)timeout);
+
+   return 0;
+}
+
+static int ulp_wdt_reset(struct udevice *dev)
+{
+   struct ulp_wdt_priv *priv = dev_get_priv(dev);
+
+   ulp_watchdog_reset(priv->wdog);
+
+   return 0;
+}
+
+static int ulp_wdt_probe(struct udevice *dev)
+{
+   struct ulp_wdt_priv *priv = dev_get_priv(dev);
+
+   priv->wdog = dev_read_addr_ptr(dev);
+   if (!priv->wdog)
+   return -EINVAL;
+
+   priv->clk_rate = (u32)dev_get_driver_data(dev);
+   if (!priv->clk_rate)
+   return -EINVAL;
+
+   return 0;
+}
+
+static const struct wdt_ops ulp_wdt_ops = {
+   .start = ulp_wdt_start,
+   .reset = ulp_wdt_reset,
+};
+
+static const struct udevice_id ulp_wdt_ids[] = {
+   { .compatible = "fsl,imx7ulp-wdt", .data = CLK_RATE_1KHZ },
+   { .compatible = "fsl,imx8ulp-wdt", .data = CLK_RATE_1KHZ },
+   { .compatible = "fsl,imx93-wdt", .data = CLK_RATE_32KHZ },
+   {}
+};
+
+U_BOOT_DRIVER(ulp_wdt) = {
+   .name   = "ulp_wdt",
+   .id = UCLASS_WDT,
+   .of_match   = ulp_wdt_ids,
+   .priv_auto  = sizeof(struct ulp_wdt_priv),
+   .probe  = ulp_wdt_probe,
+   .ops= &ulp_wdt_ops,
+};
-- 
2.17.1



[PATCH v1 3/4] watchdog: ulp_wdog: enable watchdog interrupt on imx93

2022-10-09 Thread Alice Guo (OSS)
From: Alice Guo 

The reset source of the external PMIC on i.MX93 is WDOG_ANY PAD and the
source of WDOG_ANY PAD is interrupt. Therefore, using PMIC to reset
needs to enable the watchdog interrupt.

Signed-off-by: Alice Guo 
---
 drivers/watchdog/ulp_wdog.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/watchdog/ulp_wdog.c b/drivers/watchdog/ulp_wdog.c
index 843f95aa4f..49f8900cd3 100644
--- a/drivers/watchdog/ulp_wdog.c
+++ b/drivers/watchdog/ulp_wdog.c
@@ -39,6 +39,7 @@ struct wdog_regs {
 #define WDOG_CS_PRESBIT(12)
 #define WDGCS_CMD32EN   BIT(13)
 #define WDGCS_FLG   BIT(14)
+#define WDGCS_INT  BIT(6)
 
 #define WDG_BUS_CLK  (0x0)
 #define WDG_LPO_CLK  (0x1)
@@ -92,7 +93,7 @@ void hw_watchdog_init(void)
/* setting 1-kHz clock source, enable counter running, and clear 
interrupt */
 #if defined(CONFIG_ARCH_IMX9)
writel((cmd32 | WDGCS_WDGE | WDGCS_WDGUPDATE | (WDG_LPO_CLK << 8) |
-  WDGCS_FLG | WDOG_CS_PRES), &wdog->cs);
+  WDGCS_FLG | WDOG_CS_PRES | WDGCS_INT), &wdog->cs);
 #else
writel((cmd32 | WDGCS_WDGE | WDGCS_WDGUPDATE |(WDG_LPO_CLK << 8) | 
WDGCS_FLG), &wdog->cs);
 #endif
@@ -128,7 +129,7 @@ void reset_cpu(void)
 
/* enable counter running */
 #if defined(CONFIG_ARCH_IMX9)
-   writel((cmd32 | WDGCS_WDGE | (WDG_LPO_CLK << 8) | WDOG_CS_PRES), 
&wdog->cs);
+   writel((cmd32 | WDGCS_WDGE | (WDG_LPO_CLK << 8) | WDOG_CS_PRES | 
WDGCS_INT), &wdog->cs);
 #else
writel((cmd32 | WDGCS_WDGE | (WDG_LPO_CLK << 8)), &wdog->cs);
 #endif
-- 
2.17.1



[PATCH v1 2/4] watchdog: ulp_wdog: Update watchdog driver for imx93

2022-10-09 Thread Alice Guo (OSS)
From: Alice Guo 

The WDOG clocks are sourced from the fixed 32KHz (lpo_clk).When the
timeout period exceeds 2 seconds, the value written to the TOVAL
register is larger than 16-bit can represent. Enabling watchdog
prescaler to solve this problem.

Signed-off-by: Alice Guo 
---
 drivers/watchdog/ulp_wdog.c | 12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/watchdog/ulp_wdog.c b/drivers/watchdog/ulp_wdog.c
index c40e785d0a..843f95aa4f 100644
--- a/drivers/watchdog/ulp_wdog.c
+++ b/drivers/watchdog/ulp_wdog.c
@@ -36,6 +36,7 @@ struct wdog_regs {
 
 #define WDGCS_RCS   BIT(10)
 #define WDGCS_ULK   BIT(11)
+#define WDOG_CS_PRESBIT(12)
 #define WDGCS_CMD32EN   BIT(13)
 #define WDGCS_FLG   BIT(14)
 
@@ -89,7 +90,12 @@ void hw_watchdog_init(void)
writel(0, &wdog->win);
 
/* setting 1-kHz clock source, enable counter running, and clear 
interrupt */
+#if defined(CONFIG_ARCH_IMX9)
+   writel((cmd32 | WDGCS_WDGE | WDGCS_WDGUPDATE | (WDG_LPO_CLK << 8) |
+  WDGCS_FLG | WDOG_CS_PRES), &wdog->cs);
+#else
writel((cmd32 | WDGCS_WDGE | WDGCS_WDGUPDATE |(WDG_LPO_CLK << 8) | 
WDGCS_FLG), &wdog->cs);
+#endif
 
/* Wait WDOG reconfiguration */
while (!(readl(&wdog->cs) & WDGCS_RCS))
@@ -117,11 +123,15 @@ void reset_cpu(void)
while (!(readl(&wdog->cs) & WDGCS_ULK))
;
 
-   hw_watchdog_set_timeout(5); /* 5ms timeout */
+   hw_watchdog_set_timeout(5); /* 5ms timeout for general; 40ms timeout 
for imx93 */
writel(0, &wdog->win);
 
/* enable counter running */
+#if defined(CONFIG_ARCH_IMX9)
+   writel((cmd32 | WDGCS_WDGE | (WDG_LPO_CLK << 8) | WDOG_CS_PRES), 
&wdog->cs);
+#else
writel((cmd32 | WDGCS_WDGE | (WDG_LPO_CLK << 8)), &wdog->cs);
+#endif
 
/* Wait WDOG reconfiguration */
while (!(readl(&wdog->cs) & WDGCS_RCS))
-- 
2.17.1



[PATCH v1 1/4] ulp_wdog: Update ulp wdog driver for 32bits command

2022-10-09 Thread Alice Guo (OSS)
From: Ye Li 

To use 32bits refresh and unlock command as default, check the CMD32EN
bit to select the corresponding commands.

Signed-off-by: Ye Li 
Signed-off-by: Alice Guo 
Reviewed-by: Peng Fan 
---
 drivers/watchdog/ulp_wdog.c | 52 +
 1 file changed, 36 insertions(+), 16 deletions(-)

diff --git a/drivers/watchdog/ulp_wdog.c b/drivers/watchdog/ulp_wdog.c
index ecd35ef22a..c40e785d0a 100644
--- a/drivers/watchdog/ulp_wdog.c
+++ b/drivers/watchdog/ulp_wdog.c
@@ -28,11 +28,15 @@ struct wdog_regs {
 #define UNLOCK_WORD0 0xC520 /* 1st unlock word */
 #define UNLOCK_WORD1 0xD928 /* 2nd unlock word */
 
+#define UNLOCK_WORD 0xD928C520 /* unlock word */
+#define REFRESH_WORD 0xB480A602 /* refresh word */
+
 #define WDGCS_WDGE  BIT(7)
 #define WDGCS_WDGUPDATE BIT(5)
 
 #define WDGCS_RCS   BIT(10)
 #define WDGCS_ULK   BIT(11)
+#define WDGCS_CMD32EN   BIT(13)
 #define WDGCS_FLG   BIT(14)
 
 #define WDG_BUS_CLK  (0x0)
@@ -52,20 +56,30 @@ void hw_watchdog_reset(void)
 {
struct wdog_regs *wdog = (struct wdog_regs *)WDOG_BASE_ADDR;
 
-   dmb();
-   __raw_writel(REFRESH_WORD0, &wdog->cnt);
-   __raw_writel(REFRESH_WORD1, &wdog->cnt);
-   dmb();
+   if (readl(&wdog->cs) & WDGCS_CMD32EN) {
+   writel(REFRESH_WORD, &wdog->cnt);
+   } else {
+   dmb();
+   __raw_writel(REFRESH_WORD0, &wdog->cnt);
+   __raw_writel(REFRESH_WORD1, &wdog->cnt);
+   dmb();
+   }
 }
 
 void hw_watchdog_init(void)
 {
struct wdog_regs *wdog = (struct wdog_regs *)WDOG_BASE_ADDR;
-
-   dmb();
-   __raw_writel(UNLOCK_WORD0, &wdog->cnt);
-   __raw_writel(UNLOCK_WORD1, &wdog->cnt);
-   dmb();
+   u32 cmd32 = 0;
+
+   if (readl(&wdog->cs) & WDGCS_CMD32EN) {
+   writel(UNLOCK_WORD, &wdog->cnt);
+   cmd32 = WDGCS_CMD32EN;
+   } else {
+   dmb();
+   __raw_writel(UNLOCK_WORD0, &wdog->cnt);
+   __raw_writel(UNLOCK_WORD1, &wdog->cnt);
+   dmb();
+   }
 
/* Wait WDOG Unlock */
while (!(readl(&wdog->cs) & WDGCS_ULK))
@@ -75,7 +89,7 @@ void hw_watchdog_init(void)
writel(0, &wdog->win);
 
/* setting 1-kHz clock source, enable counter running, and clear 
interrupt */
-   writel((WDGCS_WDGE | WDGCS_WDGUPDATE |(WDG_LPO_CLK << 8) | WDGCS_FLG), 
&wdog->cs);
+   writel((cmd32 | WDGCS_WDGE | WDGCS_WDGUPDATE |(WDG_LPO_CLK << 8) | 
WDGCS_FLG), &wdog->cs);
 
/* Wait WDOG reconfiguration */
while (!(readl(&wdog->cs) & WDGCS_RCS))
@@ -87,11 +101,17 @@ void hw_watchdog_init(void)
 void reset_cpu(void)
 {
struct wdog_regs *wdog = (struct wdog_regs *)WDOG_BASE_ADDR;
-
-   dmb();
-   __raw_writel(UNLOCK_WORD0, &wdog->cnt);
-   __raw_writel(UNLOCK_WORD1, &wdog->cnt);
-   dmb();
+   u32 cmd32 = 0;
+
+   if (readl(&wdog->cs) & WDGCS_CMD32EN) {
+   writel(UNLOCK_WORD, &wdog->cnt);
+   cmd32 = WDGCS_CMD32EN;
+   } else {
+   dmb();
+   __raw_writel(UNLOCK_WORD0, &wdog->cnt);
+   __raw_writel(UNLOCK_WORD1, &wdog->cnt);
+   dmb();
+   }
 
/* Wait WDOG Unlock */
while (!(readl(&wdog->cs) & WDGCS_ULK))
@@ -101,7 +121,7 @@ void reset_cpu(void)
writel(0, &wdog->win);
 
/* enable counter running */
-   writel((WDGCS_WDGE | (WDG_LPO_CLK << 8)), &wdog->cs);
+   writel((cmd32 | WDGCS_WDGE | (WDG_LPO_CLK << 8)), &wdog->cs);
 
/* Wait WDOG reconfiguration */
while (!(readl(&wdog->cs) & WDGCS_RCS))
-- 
2.17.1



[PATCH v1 0/4] ulp wdog

2022-10-09 Thread Alice Guo (OSS)
From: Alice Guo 

Alice Guo (3):
  watchdog: ulp_wdog: Update watchdog driver for imx93
  watchdog: ulp_wdog: enable watchdog interrupt on imx93
  watchdog: ulp_wdog: add driver model for ulp watchdog driver

Ye Li (1):
  ulp_wdog: Update ulp wdog driver for 32bits command

 drivers/watchdog/ulp_wdog.c | 159 ++--
 1 file changed, 135 insertions(+), 24 deletions(-)

-- 
2.17.1



[PATCH v2] gpio: adp5585: add gpio driver for ADP5585 I/O Expander Controller

2022-10-08 Thread Alice Guo (OSS)
From: Alice Guo 

Add gpio driver for ADP5585 I/O Expander Controller. The ADP5585 is a 10
input/output port expander and can be used to increase the number of
I/Os available to a processor.

Signed-off-by: Alice Guo 
---

Changes for v2:
 - add a commit log
 - remove unrelated change
 - remove "on i.MX platform" in Kconfig file

 drivers/gpio/Kconfig|   6 +
 drivers/gpio/Makefile   |   1 +
 drivers/gpio/adp5585_gpio.c | 238 
 3 files changed, 245 insertions(+)
 create mode 100644 drivers/gpio/adp5585_gpio.c

diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index c949f9d2f7..c38022d01c 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -605,4 +605,10 @@ config TURRIS_OMNIA_MCU
help
   Support for GPIOs on MCU connected to Turris Omnia via i2c.
 
+config ADP5585_GPIO
+   bool "ADP5585 GPIO driver"
+   depends on DM_GPIO && DM_I2C
+   help
+ Support ADP5585 GPIO expander.
+
 endif
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index 9d718a554e..2f60b98384 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -75,3 +75,4 @@ obj-$(CONFIG_SL28CPLD_GPIO)   += sl28cpld-gpio.o
 obj-$(CONFIG_ZYNQMP_GPIO_MODEPIN)  += zynqmp_gpio_modepin.o
 obj-$(CONFIG_SLG7XL45106_I2C_GPO)  += gpio_slg7xl45106.o
 obj-$(CONFIG_$(SPL_TPL_)TURRIS_OMNIA_MCU)  += turris_omnia_mcu.o
+obj-$(CONFIG_ADP5585_GPIO) += adp5585_gpio.o
diff --git a/drivers/gpio/adp5585_gpio.c b/drivers/gpio/adp5585_gpio.c
new file mode 100644
index 00..ea0cb75459
--- /dev/null
+++ b/drivers/gpio/adp5585_gpio.c
@@ -0,0 +1,238 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2022 NXP
+ *
+ * ADP5585 I/O Expander Controller
+ *
+ * Author: Alice Guo 
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#define ADP5585_ID 0x00
+#define ADP5585_INT_STATUS 0x01
+#define ADP5585_STATUS 0x02
+#define ADP5585_FIFO_1 0x03
+#define ADP5585_FIFO_2 0x04
+#define ADP5585_FIFO_3 0x05
+#define ADP5585_FIFO_4 0x06
+#define ADP5585_FIFO_5 0x07
+#define ADP5585_FIFO_6 0x08
+#define ADP5585_FIFO_7 0x09
+#define ADP5585_FIFO_8 0x0A
+#define ADP5585_FIFO_9 0x0B
+#define ADP5585_FIFO_100x0C
+#define ADP5585_FIFO_110x0D
+#define ADP5585_FIFO_120x0E
+#define ADP5585_FIFO_130x0F
+#define ADP5585_FIFO_140x10
+#define ADP5585_FIFO_150x11
+#define ADP5585_FIFO_160x12
+#define ADP5585_GPI_INT_STAT_A 0x13
+#define ADP5585_GPI_INT_STAT_B 0x14
+#define ADP5585_GPI_STATUS_A   0x15
+#define ADP5585_GPI_STATUS_B   0x16
+#define ADP5585_RPULL_CONFIG_A 0x17
+#define ADP5585_RPULL_CONFIG_B 0x18
+#define ADP5585_RPULL_CONFIG_C 0x19
+#define ADP5585_RPULL_CONFIG_D 0x1A
+#define ADP5585_GPI_INT_LEVEL_A0x1B
+#define ADP5585_GPI_INT_LEVEL_B0x1C
+#define ADP5585_GPI_EVENT_EN_A 0x1D
+#define ADP5585_GPI_EVENT_EN_B 0x1E
+#define ADP5585_GPI_INTERRUPT_EN_A 0x1F
+#define ADP5585_GPI_INTERRUPT_EN_B 0x20
+#define ADP5585_DEBOUNCE_DIS_A 0x21
+#define ADP5585_DEBOUNCE_DIS_B 0x22
+#define ADP5585_GPO_DATA_OUT_A 0x23
+#define ADP5585_GPO_DATA_OUT_B 0x24
+#define ADP5585_GPO_OUT_MODE_A 0x25
+#define ADP5585_GPO_OUT_MODE_B 0x26
+#define ADP5585_GPIO_DIRECTION_A   0x27
+#define ADP5585_GPIO_DIRECTION_B   0x28
+#define ADP5585_RESET1_EVENT_A 0x29
+#define ADP5585_RESET1_EVENT_B 0x2A
+#define ADP5585_RESET1_EVENT_C 0x2B
+#define ADP5585_RESET2_EVENT_A 0x2C
+#define ADP5585_RESET2_EVENT_B 0x2D
+#define ADP5585_RESET_CFG  0x2E
+#define ADP5585_PWM_OFFT_LOW   0x2F
+#define ADP5585_PWM_OFFT_HIGH  0x30
+#define ADP5585_PWM_ONT_LOW0x31
+#define ADP5585_PWM_ONT_HIGH   0x32
+#define ADP5585_PWM_CFG0x33
+#define ADP5585_LOGIC_CFG  0x34
+#define ADP5585_LOGIC_FF_CFG   0x35
+#define ADP5585_LOGIC_INT_EVENT_EN 0x36
+#define ADP5585_POLL_PTIME_CFG 0x37
+#define ADP5585_PIN_CONFIG_A   0x38
+#define ADP5585_PIN_CONFIG_B   0x39
+#define ADP5585_PIN_CONFIG_D   0x3A
+#define ADP5585_GENERAL_CFG0x3B
+#define ADP5585_INT_EN 0x3C
+
+#define ADP5585_MAXGPIO10
+#define ADP5585_BANK(offs) ((offs) > 4)
+#define ADP5585_BIT(offs)  ((offs) > 4 ? \
+   1u << ((offs) - 5) : 1u << (offs))
+
+struct adp5585_plat {
+   fdt_addr_t addr;
+   u8 id;
+   u8 dat_out[2];
+   u8 dir[

RE: [PATCH v1] gpio: adp5585: add gpio driver for ADP5585 I/O Expander Controller

2022-09-28 Thread Alice Guo (OSS)


> -Original Message-
> From: Fabio Estevam 
> Sent: Tuesday, September 27, 2022 8:16 PM
> To: Alice Guo (OSS) 
> Cc: sba...@denx.de; s...@chromium.org; dl-uboot-imx ;
> u-boot@lists.denx.de
> Subject: Re: [PATCH v1] gpio: adp5585: add gpio driver for ADP5585 I/O
> Expander Controller
> 
> Hi Alice,
> 
> On Tue, Sep 6, 2022 at 6:37 AM Alice Guo (OSS) 
> wrote:
> >
> > From: Alice Guo 
> 
> Please add a commit log.
> 
> > Signed-off-by: Alice Guo 
> 
> > --- a/arch/arm/include/asm/arch-imx9/gpio.h
> > +++ b/arch/arm/include/asm/arch-imx9/gpio.h
> > @@ -6,6 +6,8 @@
> >  #ifndef __ASM_ARCH_IMX9_GPIO_H
> >  #define __ASM_ARCH_IMX9_GPIO_H
> >
> > +#include 
> 
> This looks like an unrelated change.

Hi Fabio,

Thanks for your reply. When compiling without "#include ", the 
following error will appear:
In file included from ./arch/arm/include/asm/gpio.h:2,
 from drivers/gpio/adp5585_gpio.c:10:
./arch/arm/include/asm/arch/gpio.h:12:9: error: unknown type name ‘u32’
   12 | u32 gpio_pdor;
  | ^~~
./arch/arm/include/asm/arch/gpio.h:13:9: error: unknown type name ‘u32’
   13 | u32 gpio_psor;
  | ^~~
./arch/arm/include/asm/arch/gpio.h:14:9: error: unknown type name ‘u32’
   14 | u32 gpio_pcor;
  | ^~~
./arch/arm/include/asm/arch/gpio.h:15:9: error: unknown type name ‘u32’
   15 | u32 gpio_ptor;
  | ^~~
./arch/arm/include/asm/arch/gpio.h:16:9: error: unknown type name ‘u32’
   16 | u32 gpio_pdir;
  | ^~~
./arch/arm/include/asm/arch/gpio.h:17:9: error: unknown type name ‘u32’
   17 | u32 gpio_pddr;
  | ^~~
./arch/arm/include/asm/arch/gpio.h:18:9: error: unknown type name ‘u32’
   18 | u32 gpio_pidr;
  | ^~~
./arch/arm/include/asm/arch/gpio.h:19:9: error: unknown type name ‘u8’
   19 | u8 gpio_pxdr[32];


Best Regards,
Alice Guo

> > +config ADP5585_GPIO
> > +   bool "ADP5585 GPIO driver"
> > +   depends on DM_GPIO && DM_I2C
> > +   help
> > + Support ADP5585 GPIO expander on i.MX platform.
> 
> Please remove "on i.MX platform" as the GPIO expander can be used on any
> platform.


RE: [PATCH v1] gpio: adp5585: add gpio driver for ADP5585 I/O Expander Controller

2022-09-26 Thread Alice Guo (OSS)
A friendly ping...

Best Regards,
Alice Guo

> -Original Message-
> From: U-Boot  On Behalf Of Alice Guo (OSS)
> Sent: Tuesday, September 6, 2022 5:38 PM
> To: sba...@denx.de; feste...@gmail.com; s...@chromium.org
> Cc: dl-uboot-imx ; u-boot@lists.denx.de
> Subject: [PATCH v1] gpio: adp5585: add gpio driver for ADP5585 I/O Expander
> Controller
> 
> From: Alice Guo 
> 
> Signed-off-by: Alice Guo 
> ---
>  arch/arm/include/asm/arch-imx9/gpio.h |   2 +
>  drivers/gpio/Kconfig  |   6 +
>  drivers/gpio/Makefile |   1 +
>  drivers/gpio/adp5585_gpio.c   | 238
> ++
>  4 files changed, 247 insertions(+)
>  create mode 100644 drivers/gpio/adp5585_gpio.c
> 
> diff --git a/arch/arm/include/asm/arch-imx9/gpio.h
> b/arch/arm/include/asm/arch-imx9/gpio.h
> index 40732022e7..599f7511c3 100644
> --- a/arch/arm/include/asm/arch-imx9/gpio.h
> +++ b/arch/arm/include/asm/arch-imx9/gpio.h
> @@ -6,6 +6,8 @@
>  #ifndef __ASM_ARCH_IMX9_GPIO_H
>  #define __ASM_ARCH_IMX9_GPIO_H
> 
> +#include 
> +
>  struct gpio_regs {
>   u32 gpio_pdor;
>   u32 gpio_psor;
> diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index
> c949f9d2f7..550ff9c586 100644
> --- a/drivers/gpio/Kconfig
> +++ b/drivers/gpio/Kconfig
> @@ -605,4 +605,10 @@ config TURRIS_OMNIA_MCU
>   help
>  Support for GPIOs on MCU connected to Turris Omnia via i2c.
> 
> +config ADP5585_GPIO
> + bool "ADP5585 GPIO driver"
> + depends on DM_GPIO && DM_I2C
> + help
> +   Support ADP5585 GPIO expander on i.MX platform.
> +
>  endif
> diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index
> 9d718a554e..2f60b98384 100644
> --- a/drivers/gpio/Makefile
> +++ b/drivers/gpio/Makefile
> @@ -75,3 +75,4 @@ obj-$(CONFIG_SL28CPLD_GPIO) += sl28cpld-gpio.o
>  obj-$(CONFIG_ZYNQMP_GPIO_MODEPIN)+= zynqmp_gpio_modepin.o
>  obj-$(CONFIG_SLG7XL45106_I2C_GPO)+= gpio_slg7xl45106.o
>  obj-$(CONFIG_$(SPL_TPL_)TURRIS_OMNIA_MCU)+= turris_omnia_mcu.o
> +obj-$(CONFIG_ADP5585_GPIO)   += adp5585_gpio.o
> diff --git a/drivers/gpio/adp5585_gpio.c b/drivers/gpio/adp5585_gpio.c new
> file mode 100644 index 00..ea0cb75459
> --- /dev/null
> +++ b/drivers/gpio/adp5585_gpio.c
> @@ -0,0 +1,238 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Copyright 2022 NXP
> + *
> + * ADP5585 I/O Expander Controller
> + *
> + * Author: Alice Guo   */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define ADP5585_ID   0x00
> +#define ADP5585_INT_STATUS   0x01
> +#define ADP5585_STATUS   0x02
> +#define ADP5585_FIFO_1   0x03
> +#define ADP5585_FIFO_2   0x04
> +#define ADP5585_FIFO_3   0x05
> +#define ADP5585_FIFO_4   0x06
> +#define ADP5585_FIFO_5   0x07
> +#define ADP5585_FIFO_6   0x08
> +#define ADP5585_FIFO_7   0x09
> +#define ADP5585_FIFO_8   0x0A
> +#define ADP5585_FIFO_9   0x0B
> +#define ADP5585_FIFO_10  0x0C
> +#define ADP5585_FIFO_11  0x0D
> +#define ADP5585_FIFO_12  0x0E
> +#define ADP5585_FIFO_13  0x0F
> +#define ADP5585_FIFO_14  0x10
> +#define ADP5585_FIFO_15  0x11
> +#define ADP5585_FIFO_16  0x12
> +#define ADP5585_GPI_INT_STAT_A   0x13
> +#define ADP5585_GPI_INT_STAT_B   0x14
> +#define ADP5585_GPI_STATUS_A 0x15
> +#define ADP5585_GPI_STATUS_B 0x16
> +#define ADP5585_RPULL_CONFIG_A   0x17
> +#define ADP5585_RPULL_CONFIG_B   0x18
> +#define ADP5585_RPULL_CONFIG_C   0x19
> +#define ADP5585_RPULL_CONFIG_D   0x1A
> +#define ADP5585_GPI_INT_LEVEL_A  0x1B
> +#define ADP5585_GPI_INT_LEVEL_B  0x1C
> +#define ADP5585_GPI_EVENT_EN_A   0x1D
> +#define ADP5585_GPI_EVENT_EN_B   0x1E
> +#define ADP5585_GPI_INTERRUPT_EN_A   0x1F
> +#define ADP5585_GPI_INTERRUPT_EN_B   0x20
> +#define ADP5585_DEBOUNCE_DIS_A   0x21
> +#define ADP5585_DEBOUNCE_DIS_B   0x22
> +#define ADP5585_GPO_DATA_OUT_A   0x23
> +#define ADP5585_GPO_DATA_OUT_B   0x24
> +#define ADP5585_GPO_OUT_MODE_A   0x25
> +#define ADP5585_GPO_OUT_MODE_B   0x26
> +#define ADP5585_GPIO_DIRECTION_A 0x27
> +#define ADP5585_GPIO_DIRECTION_B 0x28
> +#define ADP5585_RESET1_EVENT_A  

[PATCH v1] gpio: adp5585: add gpio driver for ADP5585 I/O Expander Controller

2022-09-06 Thread Alice Guo (OSS)
From: Alice Guo 

Signed-off-by: Alice Guo 
---
 arch/arm/include/asm/arch-imx9/gpio.h |   2 +
 drivers/gpio/Kconfig  |   6 +
 drivers/gpio/Makefile |   1 +
 drivers/gpio/adp5585_gpio.c   | 238 ++
 4 files changed, 247 insertions(+)
 create mode 100644 drivers/gpio/adp5585_gpio.c

diff --git a/arch/arm/include/asm/arch-imx9/gpio.h 
b/arch/arm/include/asm/arch-imx9/gpio.h
index 40732022e7..599f7511c3 100644
--- a/arch/arm/include/asm/arch-imx9/gpio.h
+++ b/arch/arm/include/asm/arch-imx9/gpio.h
@@ -6,6 +6,8 @@
 #ifndef __ASM_ARCH_IMX9_GPIO_H
 #define __ASM_ARCH_IMX9_GPIO_H
 
+#include 
+
 struct gpio_regs {
u32 gpio_pdor;
u32 gpio_psor;
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index c949f9d2f7..550ff9c586 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -605,4 +605,10 @@ config TURRIS_OMNIA_MCU
help
   Support for GPIOs on MCU connected to Turris Omnia via i2c.
 
+config ADP5585_GPIO
+   bool "ADP5585 GPIO driver"
+   depends on DM_GPIO && DM_I2C
+   help
+ Support ADP5585 GPIO expander on i.MX platform.
+
 endif
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index 9d718a554e..2f60b98384 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -75,3 +75,4 @@ obj-$(CONFIG_SL28CPLD_GPIO)   += sl28cpld-gpio.o
 obj-$(CONFIG_ZYNQMP_GPIO_MODEPIN)  += zynqmp_gpio_modepin.o
 obj-$(CONFIG_SLG7XL45106_I2C_GPO)  += gpio_slg7xl45106.o
 obj-$(CONFIG_$(SPL_TPL_)TURRIS_OMNIA_MCU)  += turris_omnia_mcu.o
+obj-$(CONFIG_ADP5585_GPIO) += adp5585_gpio.o
diff --git a/drivers/gpio/adp5585_gpio.c b/drivers/gpio/adp5585_gpio.c
new file mode 100644
index 00..ea0cb75459
--- /dev/null
+++ b/drivers/gpio/adp5585_gpio.c
@@ -0,0 +1,238 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2022 NXP
+ *
+ * ADP5585 I/O Expander Controller
+ *
+ * Author: Alice Guo 
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#define ADP5585_ID 0x00
+#define ADP5585_INT_STATUS 0x01
+#define ADP5585_STATUS 0x02
+#define ADP5585_FIFO_1 0x03
+#define ADP5585_FIFO_2 0x04
+#define ADP5585_FIFO_3 0x05
+#define ADP5585_FIFO_4 0x06
+#define ADP5585_FIFO_5 0x07
+#define ADP5585_FIFO_6 0x08
+#define ADP5585_FIFO_7 0x09
+#define ADP5585_FIFO_8 0x0A
+#define ADP5585_FIFO_9 0x0B
+#define ADP5585_FIFO_100x0C
+#define ADP5585_FIFO_110x0D
+#define ADP5585_FIFO_120x0E
+#define ADP5585_FIFO_130x0F
+#define ADP5585_FIFO_140x10
+#define ADP5585_FIFO_150x11
+#define ADP5585_FIFO_160x12
+#define ADP5585_GPI_INT_STAT_A 0x13
+#define ADP5585_GPI_INT_STAT_B 0x14
+#define ADP5585_GPI_STATUS_A   0x15
+#define ADP5585_GPI_STATUS_B   0x16
+#define ADP5585_RPULL_CONFIG_A 0x17
+#define ADP5585_RPULL_CONFIG_B 0x18
+#define ADP5585_RPULL_CONFIG_C 0x19
+#define ADP5585_RPULL_CONFIG_D 0x1A
+#define ADP5585_GPI_INT_LEVEL_A0x1B
+#define ADP5585_GPI_INT_LEVEL_B0x1C
+#define ADP5585_GPI_EVENT_EN_A 0x1D
+#define ADP5585_GPI_EVENT_EN_B 0x1E
+#define ADP5585_GPI_INTERRUPT_EN_A 0x1F
+#define ADP5585_GPI_INTERRUPT_EN_B 0x20
+#define ADP5585_DEBOUNCE_DIS_A 0x21
+#define ADP5585_DEBOUNCE_DIS_B 0x22
+#define ADP5585_GPO_DATA_OUT_A 0x23
+#define ADP5585_GPO_DATA_OUT_B 0x24
+#define ADP5585_GPO_OUT_MODE_A 0x25
+#define ADP5585_GPO_OUT_MODE_B 0x26
+#define ADP5585_GPIO_DIRECTION_A   0x27
+#define ADP5585_GPIO_DIRECTION_B   0x28
+#define ADP5585_RESET1_EVENT_A 0x29
+#define ADP5585_RESET1_EVENT_B 0x2A
+#define ADP5585_RESET1_EVENT_C 0x2B
+#define ADP5585_RESET2_EVENT_A 0x2C
+#define ADP5585_RESET2_EVENT_B 0x2D
+#define ADP5585_RESET_CFG  0x2E
+#define ADP5585_PWM_OFFT_LOW   0x2F
+#define ADP5585_PWM_OFFT_HIGH  0x30
+#define ADP5585_PWM_ONT_LOW0x31
+#define ADP5585_PWM_ONT_HIGH   0x32
+#define ADP5585_PWM_CFG0x33
+#define ADP5585_LOGIC_CFG  0x34
+#define ADP5585_LOGIC_FF_CFG   0x35
+#define ADP5585_LOGIC_INT_EVENT_EN 0x36
+#define ADP5585_POLL_PTIME_CFG 0x37
+#define ADP5585_PIN_CONFIG_A   0x38
+#define ADP5585_PIN_CONFIG_B   0x39
+#define ADP5585_PIN_CONFIG_D   0x3A
+#define ADP5585_GENERAL_CFG0x3B
+#define ADP5585_INT_EN 0x3C
+
+#define ADP5585_MAXGPIO10
+#define ADP5585_BANK(offs) ((offs) > 4)
+#define ADP5585_BIT(offs)  ((offs) > 4 ? \
+

[PATCH v3] imx8mq: configs: add support for distro boot commands

2021-01-14 Thread Alice Guo (OSS)
From: Alice Guo 

Supported boot device types in iMX8MQ: MMC, DHCP.

CONFIG_DISTRO_DEFAULTS is added for enabling the DISTRO_DEFAULTS option.

CONFIG_BOOTCOMMAND which is defined in include/configs/imx8mq_evk.h is
deleted because "run distro_bootcmd" is required to be the default boot
mode.

scriptaddr is the location in RAM where boot.scr.uimg/boot.scr will be
loaded to prior to execution.

kernel_addr_r is the location in RAM where the kernel will be loaded to.

Delete unnecessary environment variables because "run distro_bootcmd" is
set to be the default boot mode.

Signed-off-by: Alice Guo 
---

Changes for v3:
 - enable the DISTRO_DEFAULTS option by adding CONFIG_DISTRO_DEFAULTS=y
 - modify commit log
Changes for v2:
 - re-add boot_fdt, initrd_addr and bootm_size which may need to be used

 configs/imx8mq_evk_defconfig |  1 +
 include/configs/imx8mq_evk.h | 75 ++--
 2 files changed, 13 insertions(+), 63 deletions(-)

diff --git a/configs/imx8mq_evk_defconfig b/configs/imx8mq_evk_defconfig
index de91a76d41..424301bf4d 100644
--- a/configs/imx8mq_evk_defconfig
+++ b/configs/imx8mq_evk_defconfig
@@ -36,6 +36,7 @@ CONFIG_CMD_EXT2=y
 CONFIG_CMD_EXT4=y
 CONFIG_CMD_EXT4_WRITE=y
 CONFIG_CMD_FAT=y
+CONFIG_DISTRO_DEFAULTS=y
 CONFIG_OF_CONTROL=y
 CONFIG_ENV_OVERWRITE=y
 CONFIG_ENV_IS_IN_MMC=y
diff --git a/include/configs/imx8mq_evk.h b/include/configs/imx8mq_evk.h
index 96bfff749c..1861ebad18 100644
--- a/include/configs/imx8mq_evk.h
+++ b/include/configs/imx8mq_evk.h
@@ -74,20 +74,20 @@
 #define IMX_FEC_BASE   0x30BE
 #endif

-#define CONFIG_MFG_ENV_SETTINGS \
-   "mfgtool_args=setenv bootargs console=${console},${baudrate} " \
-   "rdinit=/linuxrc " \
-   "g_mass_storage.stall=0 g_mass_storage.removable=1 " \
-   "g_mass_storage.idVendor=0x066F g_mass_storage.idProduct=0x37FF 
"\
-   "g_mass_storage.iSerialNumber=\"\" "\
-   "clk_ignore_unused "\
-   "\0" \
-   "initrd_addr=0x4380\0" \
-   "bootcmd_mfg=run mfgtool_args;booti ${loadaddr} ${initrd_addr} 
${fdt_addr};\0" \
+#ifndef CONFIG_SPL_BUILD
+#define BOOT_TARGET_DEVICES(func) \
+   func(MMC, mmc, 0) \
+   func(MMC, mmc, 1) \
+   func(DHCP, dhcp, na)
+
+#include 
+#endif
+
 /* Initial environment variables */
 #define CONFIG_EXTRA_ENV_SETTINGS  \
-   CONFIG_MFG_ENV_SETTINGS \
-   "script=boot.scr\0" \
+   BOOTENV \
+   "scriptaddr=0x4350\0" \
+   "kernel_addr_r=0x4088\0" \
"image=Image\0" \
"console=ttymxc0,115200\0" \
"fdt_addr=0x4300\0" \
@@ -95,59 +95,8 @@
"fdt_file=imx8mq-evk.dtb\0" \
"initrd_addr=0x4380\0"  \
"bootm_size=0x1000\0" \
-   "mmcdev="__stringify(CONFIG_SYS_MMC_ENV_DEV)"\0" \
"mmcpart=" __stringify(CONFIG_SYS_MMC_IMG_LOAD_PART) "\0" \
"mmcroot=" CONFIG_MMCROOT " rootwait rw\0" \
-   "mmcautodetect=yes\0" \
-   "mmcargs=setenv bootargs console=${console} root=${mmcroot}\0 " \
-   "loadbootscript=fatload mmc ${mmcdev}:${mmcpart} ${loadaddr} 
${script};\0" \
-   "bootscript=echo Running bootscript from mmc ...; " \
-   "source\0" \
-   "loadimage=fatload mmc ${mmcdev}:${mmcpart} ${loadaddr} ${image}\0" \
-   "loadfdt=fatload mmc ${mmcdev}:${mmcpart} ${fdt_addr} ${fdt_file}\0" \
-   "mmcboot=echo Booting from mmc ...; " \
-   "run mmcargs; " \
-   "if test ${boot_fdt} = yes || test ${boot_fdt} = try; then " \
-   "if run loadfdt; then " \
-   "booti ${loadaddr} - ${fdt_addr}; " \
-   "else " \
-   "echo WARN: Cannot load the DT; " \
-   "fi; " \
-   "else " \
-   "echo wait for boot; " \
-   "fi;\0" \
-   "netargs=setenv bootargs console=${console} " \
-   "root=/dev/nfs " \
-   "ip=dhcp nfsroot=${serverip}:${nfsroot},v3,tcp\0" \
-   "netboot=echo Booting from net ...; " \
-   "run netargs;  " \
-   "if test ${ip_dyn} = yes; then " \
-   "setenv get_cmd dhcp; " \
-   "else " \
-   "setenv get_cmd tftp; " \
-   "fi; " \
-   "${get_cmd} ${loadaddr} ${image}; " \
-   "if test ${boot_fdt} = yes || test ${boot_fdt} = try; then " \
-   "if ${get_cmd} ${fdt_addr} ${fdt_file}; then " \
-   "booti ${loadaddr} - ${fdt_addr}; " \
-   "else " \
-   "echo WARN: Cannot load the DT; " \
-   "fi; " \
-   "else " \
-   "booti; " \
-   "fi;\0"
-
-#define CONFIG_BOOTCOMMAND \
-  "mmc dev ${mmcdev}; if mmc rescan; then " \
-  "if

RE: [EXT] Re: [PATCH v1 1/2] imx8mp: configs: add support for distro boot commands

2020-12-18 Thread Alice Guo (OSS)


> -Original Message-
> From: Fabio Estevam 
> Sent: 2020年12月18日 18:59
> To: Alice Guo (OSS) 
> Cc: Stefano Babic ; Peng Fan ;
> dl-uboot-imx ; Ye Li ; U-Boot-Denx
> ; Alice Guo 
> Subject: [EXT] Re: [PATCH v1 1/2] imx8mp: configs: add support for distro boot
> commands
> 
> Caution: EXT Email
> 
> Hi Alice,
> 
> On Thu, Dec 17, 2020 at 7:28 AM Alice Guo (OSS) 
> wrote:
> 
> > diff --git a/configs/imx8mp_evk_defconfig
> > b/configs/imx8mp_evk_defconfig index cd5724e811..7831a940a3 100644
> > --- a/configs/imx8mp_evk_defconfig
> > +++ b/configs/imx8mp_evk_defconfig
> > @@ -51,6 +51,8 @@ CONFIG_CMD_EXT2=y
> >  CONFIG_CMD_EXT4=y
> >  CONFIG_CMD_EXT4_WRITE=y
> >  CONFIG_CMD_FAT=y
> > +CONFIG_CMD_PART=y
> > +CONFIG_CMD_FS_GENERIC=y
> 
> Please read doc/README.distro, which states:
> 
> "In your board's defconfig, enable the DISTRO_DEFAULTS option by adding a line
> with "CONFIG_DISTRO_DEFAULTS=y"."

Hi,
I know "CONFIG_DISTRO_DEFAULTS=y" exists. It can work when I write like this so 
that I did not change it. I will modify as your advice.
Thank you.

Best Regards,
Alice



RE: [EXT] Re: [PATCH v2 2/2] board: imx8mp: add boot.cmd for distro boot on iMX8MP

2020-12-18 Thread Alice Guo (OSS)


> -Original Message-
> From: Fabio Estevam 
> Sent: 2020年12月18日 19:03
> To: Alice Guo (OSS) 
> Cc: Stefano Babic ; Peng Fan ;
> dl-uboot-imx ; Ye Li ; U-Boot-Denx
> ; Alice Guo ; Otavio Salvador
> ; andrey.zhizhi...@leica-geosystems.com
> Subject: [EXT] Re: [PATCH v2 2/2] board: imx8mp: add boot.cmd for distro boot
> on iMX8MP
> 
> Caution: EXT Email
> 
> Hi Alice,
> 
> On Fri, Dec 18, 2020 at 4:20 AM Alice Guo (OSS) 
> wrote:
> 
> > +++ b/board/freescale/imx8mp_evk/boot.cmd
> > @@ -0,0 +1,25 @@
> > +setenv bootargs console=${console} root=${mmcroot};
> > +
> > +for boot_target in ${boot_targets};
> 
> This is not how distro boot support works.
> 
> boot.scr or extlinux.conf scripts should be provided by the distro itself 
> (Yocto,
> Buildroot, Debian, etc), and not from U-Boot.
> 
> Each distro has its own partitioning mechanism and may store the kernel, dtb 
> in
> different locations.

Hi,
Can you tell me where I can see more details about boot.scr? I didn't see that 
" boot.scr or extlinux.conf scripts should be provided by the distro itself".
Thank you.

Alice


[PATCH v2 2/2] board: imx8mp: add boot.cmd for distro boot on iMX8MP

2020-12-17 Thread Alice Guo (OSS)
From: Alice Guo 

Distro Boot requires a U-Boot-specific script named boot.scr or
boot.scr.uimg which contains boot commands to boot the system. The
boot.cmd is such a file. Use mkimage to generate boot.scr or
boot.scr.uimg from boot.cmd, and the command is:
mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n "Distro Boot Script" -d 
boot.cmd boot.scr.uimg

The boot.cmd file is an example script and can be modified based on
needs. bootargs is set in this script and root uses the default value
"/dev/mmcblk1p2 rootwait rw" which can be changed by overriding mmcroot.

Signed-off-by: Alice Guo 
---

Changes for v2:
 - none

 board/freescale/imx8mp_evk/boot.cmd | 25 +
 1 file changed, 25 insertions(+)
 create mode 100644 board/freescale/imx8mp_evk/boot.cmd

diff --git a/board/freescale/imx8mp_evk/boot.cmd 
b/board/freescale/imx8mp_evk/boot.cmd
new file mode 100644
index 00..10bcced774
--- /dev/null
+++ b/board/freescale/imx8mp_evk/boot.cmd
@@ -0,0 +1,25 @@
+setenv bootargs console=${console} root=${mmcroot};
+
+for boot_target in ${boot_targets};
+do
+if test "${boot_target}" = "mmc1" ; then
+if fatload mmc 1:${mmcpart} ${kernel_addr_r} ${image}; then
+if fatload mmc 1:${mmcpart} ${fdt_addr} ${fdt_file}; 
then
+echo Load image and .dtb from SD card(mmc1);
+booti ${kernel_addr_r} - ${fdt_addr};
+exit;
+fi
+fi
+fi
+
+if test "${boot_target}" = "mmc2" ; then
+if fatload mmc 2:${mmcpart} ${kernel_addr_r} ${image}; then
+if fatload mmc 2:${mmcpart} ${fdt_addr} ${fdt_file}; 
then
+echo Load image and .dtb from eMMC(mmc2);
+booti ${kernel_addr_r} - ${fdt_addr};
+exit;
+fi
+fi
+fi
+
+done
--
2.17.1



[PATCH v2 1/2] imx8mp: configs: add support for distro boot commands

2020-12-17 Thread Alice Guo (OSS)
From: Alice Guo 

Supported boot device types in iMX8MP: MMC.

CONFIG_CMD_PART is added for command part and CONFIG_CMD_FS_GENERIC is
for command fstype.

scriptaddr is the location in RAM where boot.scr.uimg/boot.scr will be
loaded to prior to execution. kernel_addr_r is the location in RAM where
the kernel will be loaded to. Delete unnecessary environment variables
because "run distro_bootcmd" is set to be the default boot mode.

On the iMX8MP platform I used, "mmc1" represents SD card and "mmc2"
represents eMMC.

Signed-off-by: Alice Guo 
---

Changes for v2:
 - re-add boot_fit, initrd_addr and bootm_size which may need to be used

 configs/imx8mp_evk_defconfig |  2 ++
 include/configs/imx8mp_evk.h | 63 +++-
 2 files changed, 13 insertions(+), 52 deletions(-)

diff --git a/configs/imx8mp_evk_defconfig b/configs/imx8mp_evk_defconfig
index cd5724e811..7831a940a3 100644
--- a/configs/imx8mp_evk_defconfig
+++ b/configs/imx8mp_evk_defconfig
@@ -51,6 +51,8 @@ CONFIG_CMD_EXT2=y
 CONFIG_CMD_EXT4=y
 CONFIG_CMD_EXT4_WRITE=y
 CONFIG_CMD_FAT=y
+CONFIG_CMD_PART=y
+CONFIG_CMD_FS_GENERIC=y
 CONFIG_OF_CONTROL=y
 CONFIG_SPL_OF_CONTROL=y
 CONFIG_ENV_OVERWRITE=y
diff --git a/include/configs/imx8mp_evk.h b/include/configs/imx8mp_evk.h
index 8253c6aa2f..fd7ec45b16 100644
--- a/include/configs/imx8mp_evk.h
+++ b/include/configs/imx8mp_evk.h
@@ -44,9 +44,19 @@

 #endif

+#ifndef CONFIG_SPL_BUILD
+#define BOOT_TARGET_DEVICES(func) \
+   func(MMC, mmc, 1) \
+   func(MMC, mmc, 2)
+
+#include 
+#endif
+
 /* Initial environment variables */
 #define CONFIG_EXTRA_ENV_SETTINGS  \
-   "script=boot.scr\0" \
+   BOOTENV \
+   "scriptaddr=0x4350\0" \
+   "kernel_addr_r=0x4088\0" \
"image=Image\0" \
"console=ttymxc1,115200 earlycon=ec_imx6q,0x3089,115200\0" \
"fdt_addr=0x4300\0" \
@@ -54,59 +64,8 @@
"fdt_file=" CONFIG_DEFAULT_FDT_FILE "\0" \
"initrd_addr=0x4380\0"  \
"bootm_size=0x1000\0" \
-   "mmcdev="__stringify(CONFIG_SYS_MMC_ENV_DEV)"\0" \
"mmcpart=" __stringify(CONFIG_SYS_MMC_IMG_LOAD_PART) "\0" \
"mmcroot=" CONFIG_MMCROOT " rootwait rw\0" \
-   "mmcautodetect=yes\0" \
-   "mmcargs=setenv bootargs ${jh_clk} console=${console} root=${mmcroot}\0 
" \
-   "loadbootscript=fatload mmc ${mmcdev}:${mmcpart} ${loadaddr} 
${script};\0" \
-   "bootscript=echo Running bootscript from mmc ...; " \
-   "source\0" \
-   "loadimage=fatload mmc ${mmcdev}:${mmcpart} ${loadaddr} ${image}\0" \
-   "loadfdt=fatload mmc ${mmcdev}:${mmcpart} ${fdt_addr} ${fdt_file}\0" \
-   "mmcboot=echo Booting from mmc ...; " \
-   "run mmcargs; " \
-   "if test ${boot_fdt} = yes || test ${boot_fdt} = try; then " \
-   "if run loadfdt; then " \
-   "booti ${loadaddr} - ${fdt_addr}; " \
-   "else " \
-   "echo WARN: Cannot load the DT; " \
-   "fi; " \
-   "else " \
-   "echo wait for boot; " \
-   "fi;\0" \
-   "netargs=setenv bootargs ${jh_clk} console=${console} " \
-   "root=/dev/nfs " \
-   "ip=dhcp nfsroot=${serverip}:${nfsroot},v3,tcp\0" \
-   "netboot=echo Booting from net ...; " \
-   "run netargs;  " \
-   "if test ${ip_dyn} = yes; then " \
-   "setenv get_cmd dhcp; " \
-   "else " \
-   "setenv get_cmd tftp; " \
-   "fi; " \
-   "${get_cmd} ${loadaddr} ${image}; " \
-   "if test ${boot_fdt} = yes || test ${boot_fdt} = try; then " \
-   "if ${get_cmd} ${fdt_addr} ${fdt_file}; then " \
-   "booti ${loadaddr} - ${fdt_addr}; " \
-   "else " \
-   "echo WARN: Cannot load the DT; " \
-   "fi; " \
-   "else " \
-   "booti; " \
-   "fi;\0"
-
-#define CONFIG_BOOTCOMMAND \
-  "mmc dev ${mmcdev}; if mmc rescan; then " \
-  "if run loadbootscript; then " \
-  "run bootscript; " \
-  "else " \
-  "if run loadimage; then " \
-  "run mmcboot; " \
-  "else run netboot; " \
-  "fi; " \
-  "fi; " \
-  "else booti ${loadaddr} - ${fdt_addr}; fi"

 /* Link Definitions */
 #define CONFIG_LOADADDR0x4048
--
2.17.1



[PATCH v2 1/2] imx8mq: configs: add support for distro boot commands

2020-12-17 Thread Alice Guo (OSS)
From: Alice Guo 

Supported boot device types in iMX8MQ: MMC, DHCP.

CONFIG_CMD_PART is added for command part and CONFIG_CMD_FS_GENERIC is
for command fstype.

scriptaddr is the location in RAM where boot.scr.uimg/boot.scr will be
loaded to prior to execution.

kernel_addr_r is the location in RAM where the kernel will be loaded to.

Delete unnecessary environment variables because "run distro_bootcmd" is
set to be the default boot mode.

Signed-off-by: Alice Guo 
---

Changes for v2:
 - re-add boot_fit, initrd_addr and bootm_size which may need to be used

 configs/imx8mq_evk_defconfig |  2 +
 include/configs/imx8mq_evk.h | 76 ++--
 2 files changed, 14 insertions(+), 64 deletions(-)

diff --git a/configs/imx8mq_evk_defconfig b/configs/imx8mq_evk_defconfig
index de91a76d41..901841ea36 100644
--- a/configs/imx8mq_evk_defconfig
+++ b/configs/imx8mq_evk_defconfig
@@ -36,6 +36,8 @@ CONFIG_CMD_EXT2=y
 CONFIG_CMD_EXT4=y
 CONFIG_CMD_EXT4_WRITE=y
 CONFIG_CMD_FAT=y
+CONFIG_CMD_PART=y
+CONFIG_CMD_FS_GENERIC=y
 CONFIG_OF_CONTROL=y
 CONFIG_ENV_OVERWRITE=y
 CONFIG_ENV_IS_IN_MMC=y
diff --git a/include/configs/imx8mq_evk.h b/include/configs/imx8mq_evk.h
index 3f9a3bc100..eb5bc03403 100644
--- a/include/configs/imx8mq_evk.h
+++ b/include/configs/imx8mq_evk.h
@@ -74,80 +74,28 @@
 #define IMX_FEC_BASE   0x30BE
 #endif

-#define CONFIG_MFG_ENV_SETTINGS \
-   "mfgtool_args=setenv bootargs console=${console},${baudrate} " \
-   "rdinit=/linuxrc " \
-   "g_mass_storage.stall=0 g_mass_storage.removable=1 " \
-   "g_mass_storage.idVendor=0x066F g_mass_storage.idProduct=0x37FF 
"\
-   "g_mass_storage.iSerialNumber=\"\" "\
-   "clk_ignore_unused "\
-   "\0" \
-   "initrd_addr=0x4380\0" \
-   "bootcmd_mfg=run mfgtool_args;booti ${loadaddr} ${initrd_addr} 
${fdt_addr};\0" \
+#ifndef CONFIG_SPL_BUILD
+#define BOOT_TARGET_DEVICES(func) \
+   func(MMC, mmc, 0) \
+   func(MMC, mmc, 1) \
+   func(DHCP, dhcp, na)
+
+#include 
+#endif
+
 /* Initial environment variables */
 #define CONFIG_EXTRA_ENV_SETTINGS  \
-   CONFIG_MFG_ENV_SETTINGS \
-   "script=boot.scr\0" \
+   BOOTENV \
+   "scriptaddr=0x4350\0" \
+   "kernel_addr_r=0x4088\0" \
"image=Image\0" \
"console=ttymxc0,115200\0" \
"fdt_addr=0x4300\0" \
-   "boot_fdt=try\0" \
"fdt_file=imx8mq-evk.dtb\0" \
"initrd_addr=0x4380\0"  \
"bootm_size=0x1000\0" \
-   "mmcdev="__stringify(CONFIG_SYS_MMC_ENV_DEV)"\0" \
"mmcpart=" __stringify(CONFIG_SYS_MMC_IMG_LOAD_PART) "\0" \
"mmcroot=" CONFIG_MMCROOT " rootwait rw\0" \
-   "mmcautodetect=yes\0" \
-   "mmcargs=setenv bootargs console=${console} root=${mmcroot}\0 " \
-   "loadbootscript=fatload mmc ${mmcdev}:${mmcpart} ${loadaddr} 
${script};\0" \
-   "bootscript=echo Running bootscript from mmc ...; " \
-   "source\0" \
-   "loadimage=fatload mmc ${mmcdev}:${mmcpart} ${loadaddr} ${image}\0" \
-   "loadfdt=fatload mmc ${mmcdev}:${mmcpart} ${fdt_addr} ${fdt_file}\0" \
-   "mmcboot=echo Booting from mmc ...; " \
-   "run mmcargs; " \
-   "if test ${boot_fdt} = yes || test ${boot_fdt} = try; then " \
-   "if run loadfdt; then " \
-   "booti ${loadaddr} - ${fdt_addr}; " \
-   "else " \
-   "echo WARN: Cannot load the DT; " \
-   "fi; " \
-   "else " \
-   "echo wait for boot; " \
-   "fi;\0" \
-   "netargs=setenv bootargs console=${console} " \
-   "root=/dev/nfs " \
-   "ip=dhcp nfsroot=${serverip}:${nfsroot},v3,tcp\0" \
-   "netboot=echo Booting from net ...; " \
-   "run netargs;  " \
-   "if test ${ip_dyn} = yes; then " \
-   "setenv get_cmd dhcp; " \
-   "else " \
-   "setenv get_cmd tftp; " \
-   "fi; " \
-   "${get_cmd} ${loadaddr} ${image}; " \
-   "if test ${boot_fdt} = yes || test ${boot_fdt} = try; then " \
-   "if ${get_cmd} ${fdt_addr} ${fdt_file}; then " \
-   "booti ${loadaddr} - ${fdt_addr}; " \
-   "else " \
-   "echo WARN: Cannot load the DT; " \
-   "fi; " \
-   "else " \
-   "booti; " \
-   "fi;\0"
-
-#define CONFIG_BOOTCOMMAND \
-  "mmc dev ${mmcdev}; if mmc rescan; then " \
-  "if run loadbootscript; then " \
-  "run bootscript; " \
-  "else " \
-  "if run loadimage; then " \
-  "run mmcboot; " \

[PATCH v2 2/2] board: imx8mq: add boot.cmd for distro boot on iMX8MQ

2020-12-17 Thread Alice Guo (OSS)
From: Alice Guo 

Distro Boot requires a U-Boot-specific script named boot.scr or
boot.scr.uimg which contains boot commands to boot the system. The
boot.cmd is such a file. Use mkimage to generate boot.scr or
boot.scr.uimg from boot.cmd, and the command is:
mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n "Distro Boot Script" -d 
boot.cmd boot.scr.uimg

The boot.cmd file is an example script and can be modified based on
needs. bootargs is set in this script and root uses the default value
"/dev/mmcblk1p2 rootwait rw" which can be changed by overriding mmcroot.

On the iMX8MQ platform I used, "mmc0" represents eMMC and "mmc1"
represents SD card.

Signed-off-by: Alice Guo 
---

Changes for v2:
 - none

 board/freescale/imx8mq_evk/boot.cmd | 35 +
 1 file changed, 35 insertions(+)
 create mode 100644 board/freescale/imx8mq_evk/boot.cmd

diff --git a/board/freescale/imx8mq_evk/boot.cmd 
b/board/freescale/imx8mq_evk/boot.cmd
new file mode 100644
index 00..964993e144
--- /dev/null
+++ b/board/freescale/imx8mq_evk/boot.cmd
@@ -0,0 +1,35 @@
+setenv bootargs console=${console} root=${mmcroot};
+
+for boot_target in ${boot_targets};
+do
+if test "${boot_target}" = "mmc0" ; then
+if fatload mmc 0:${mmcpart} ${kernel_addr_r} ${image}; then
+if fatload mmc 0:${mmcpart} ${fdt_addr} ${fdt_file}; 
then
+echo Load image and .dtb from eMMC(mmc0);
+booti ${kernel_addr_r} - ${fdt_addr};
+exit;
+fi
+fi
+fi
+
+if test "${boot_target}" = "mmc1" ; then
+if fatload mmc 1:${mmcpart} ${kernel_addr_r} ${image}; then
+if fatload mmc 1:${mmcpart} ${fdt_addr} ${fdt_file}; 
then
+echo Load image and .dtb from SD card(mmc1);
+booti ${kernel_addr_r} - ${fdt_addr};
+exit;
+fi
+fi
+fi
+
+if test "${boot_target}" = "dhcp" ; then
+if dhcp ${kernel_addr_r} ${serverip}:${image}; then
+if dhcp ${fdt_addr} ${serverip}:${fdt_file}; then
+echo Load image and .dtb from net(dhcp);
+booti ${kernel_addr_r} - ${fdt_addr};
+exit;
+fi
+fi
+fi
+
+done
--
2.17.1



[PATCH v3 2/2] board: imx8mm: add boot.cmd for distro boot on iMX8MM

2020-12-17 Thread Alice Guo (OSS)
From: Alice Guo 

Distro Boot requires a U-Boot-specific script named boot.scr or
boot.scr.uimg which contains boot commands to boot the system. The
boot.cmd is such a file. Use mkimage to generate boot.scr or
boot.scr.uimg from boot.cmd, and the command is:
mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n "Distro Boot Script" -d 
boot.cmd boot.scr.uimg

The boot.cmd file is an example script and can be modified based on
needs. bootargs is set in this script and root uses the default value "
/dev/mmcblk1p2 rootwait rw" which can be changed by overriding mmcroot.

Reviewed-by: Peng Fan 
Signed-off-by: Alice Guo 
---

Changes for v3:
 - add Reviewed-by
Changes for v2:
 - add the additional explanation of boot.cmd in commit message

 board/freescale/imx8mm_evk/boot.cmd | 35 +
 1 file changed, 35 insertions(+)
 create mode 100644 board/freescale/imx8mm_evk/boot.cmd

diff --git a/board/freescale/imx8mm_evk/boot.cmd 
b/board/freescale/imx8mm_evk/boot.cmd
new file mode 100644
index 00..fdfceec263
--- /dev/null
+++ b/board/freescale/imx8mm_evk/boot.cmd
@@ -0,0 +1,35 @@
+setenv bootargs console=${console} root=${mmcroot};
+
+for boot_target in ${boot_targets};
+do
+if test "${boot_target}" = "mmc1" ; then
+if fatload mmc 1:${mmcpart} ${kernel_addr_r} ${image}; then
+if fatload mmc 1:${mmcpart} ${fdt_addr} ${fdt_file}; 
then
+echo Load image and .dtb from SD card(mmc1);
+booti ${kernel_addr_r} - ${fdt_addr};
+exit;
+fi
+fi
+fi
+
+if test "${boot_target}" = "mmc2" ; then
+if fatload mmc 2:${mmcpart} ${kernel_addr_r} ${image}; then
+if fatload mmc 2:${mmcpart} ${fdt_addr} ${fdt_file}; 
then
+echo Load image and .dtb from eMMC(mmc2);
+booti ${kernel_addr_r} - ${fdt_addr};
+exit;
+fi
+fi
+fi
+
+if test "${boot_target}" = "dhcp" ; then
+if dhcp ${kernel_addr_r} ${serverip}:${image}; then
+if dhcp ${fdt_addr} ${serverip}:${fdt_file}; then
+echo Load image and .dtb from net(dhcp);
+booti ${kernel_addr_r} - ${fdt_addr};
+exit;
+fi
+fi
+fi
+
+done
--
2.17.1



[PATCH v3 1/2] imx8mm: configs: add support for distro boot commands

2020-12-17 Thread Alice Guo (OSS)
From: Alice Guo 

Supported boot device types in iMX8MM: MMC, DHCP.

CONFIG_CMD_PART is added for command part and CONFIG_CMD_FS_GENERIC is
for command fstype.

CONFIG_BOOTCOMMAND which is defined in include/configs/imx8mm_evk.h is
deleted because "run distro_bootcmd" is required to be the default boot
mode.

scriptaddr is the location in RAM where boot.scr.uimg/boot.scr will be
loaded to prior to execution.

kernel_addr_r is the location in RAM where the kernel will be loaded to.

Delete unnecessary environment variables.

Reviewed-by: Peng Fan 
Signed-off-by: Alice Guo 
---

Changes for v3:
 - add Reviewed-by
 - re-add boot_fit, initrd_addr and bootm_size which may need to be used
Changes for v2:
 - remove supported boot device type QSPI
 - delete unnecessary environment variables
 - set "run distro_bootcmd" to be the default boot mode

 configs/imx8mm_evk_defconfig |  2 ++
 include/configs/imx8mm_evk.h | 64 +++-
 2 files changed, 14 insertions(+), 52 deletions(-)

diff --git a/configs/imx8mm_evk_defconfig b/configs/imx8mm_evk_defconfig
index 91d3bc3ac9..4c0dd27e71 100644
--- a/configs/imx8mm_evk_defconfig
+++ b/configs/imx8mm_evk_defconfig
@@ -49,6 +49,8 @@ CONFIG_CMD_EXT2=y
 CONFIG_CMD_EXT4=y
 CONFIG_CMD_EXT4_WRITE=y
 CONFIG_CMD_FAT=y
+CONFIG_CMD_PART=y
+CONFIG_CMD_FS_GENERIC=y
 CONFIG_OF_CONTROL=y
 CONFIG_SPL_OF_CONTROL=y
 CONFIG_ENV_OVERWRITE=y
diff --git a/include/configs/imx8mm_evk.h b/include/configs/imx8mm_evk.h
index 83521ad401..6d4ae71f24 100644
--- a/include/configs/imx8mm_evk.h
+++ b/include/configs/imx8mm_evk.h
@@ -32,9 +32,20 @@

 #endif

+#ifndef CONFIG_SPL_BUILD
+#define BOOT_TARGET_DEVICES(func) \
+   func(MMC, mmc, 1) \
+   func(MMC, mmc, 2) \
+   func(DHCP, dhcp, na)
+
+#include 
+#endif
+
 /* Initial environment variables */
 #define CONFIG_EXTRA_ENV_SETTINGS  \
-   "script=boot.scr\0" \
+   BOOTENV \
+   "scriptaddr=0x4350\0" \
+   "kernel_addr_r=0x4088\0" \
"image=Image\0" \
"console=ttymxc1,115200\0" \
"fdt_addr=0x4300\0" \
@@ -42,59 +53,8 @@
"fdt_file=imx8mm-evk.dtb\0" \
"initrd_addr=0x4380\0"  \
"bootm_size=0x1000\0" \
-   "mmcdev="__stringify(CONFIG_SYS_MMC_ENV_DEV)"\0" \
"mmcpart=" __stringify(CONFIG_SYS_MMC_IMG_LOAD_PART) "\0" \
"mmcroot=" CONFIG_MMCROOT " rootwait rw\0" \
-   "mmcautodetect=yes\0" \
-   "mmcargs=setenv bootargs console=${console} root=${mmcroot}\0 " \
-   "loadbootscript=fatload mmc ${mmcdev}:${mmcpart} ${loadaddr} 
${script};\0" \
-   "bootscript=echo Running bootscript from mmc ...; " \
-   "source\0" \
-   "loadimage=fatload mmc ${mmcdev}:${mmcpart} ${loadaddr} ${image}\0" \
-   "loadfdt=fatload mmc ${mmcdev}:${mmcpart} ${fdt_addr} ${fdt_file}\0" \
-   "mmcboot=echo Booting from mmc ...; " \
-   "run mmcargs; " \
-   "if test ${boot_fit} = yes || test ${boot_fit} = try; then " \
-   "bootm ${loadaddr}; " \
-   "else " \
-   "if run loadfdt; then " \
-   "booti ${loadaddr} - ${fdt_addr}; " \
-   "else " \
-   "echo WARN: Cannot load the DT; " \
-   "fi; " \
-   "fi;\0" \
-   "netargs=setenv bootargs console=${console} " \
-   "root=/dev/nfs " \
-   "ip=dhcp nfsroot=${serverip}:${nfsroot},v3,tcp\0" \
-   "netboot=echo Booting from net ...; " \
-   "run netargs;  " \
-   "if test ${ip_dyn} = yes; then " \
-   "setenv get_cmd dhcp; " \
-   "else " \
-   "setenv get_cmd tftp; " \
-   "fi; " \
-   "${get_cmd} ${loadaddr} ${image}; " \
-   "if test ${boot_fit} = yes || test ${boot_fit} = try; then " \
-   "bootm ${loadaddr}; " \
-   "else " \
-   "if ${get_cmd} ${fdt_addr} ${fdt_file}; then " \
-   "booti ${loadaddr} - ${fdt_addr}; " \
-   "else " \
-   "echo WARN: Cannot load the DT; " \
-   "fi; " \
-   "fi;\0"
-
-#define CONFIG_BOOTCOMMAND \
-  "mmc dev ${mmcdev}; if mmc rescan; then " \
-  "if run loadbootscript; then " \
-  "run bootscript; " \
-  "else " \
-  "if run loadimage; then " \
-  "run mmcboot; " \
-  "else run netboot; " \
-  "fi; " \
-  "fi; " \
-  "fi;"

 /* Link Definitions */
 #define CONFIG_LOADADDR0x4048
--
2.17.1



RE: [EXT] RE: [PATCH v1 1/2] imx8mp: configs: add support for distro boot commands

2020-12-17 Thread Alice Guo (OSS)


> -Original Message-
> From: ZHIZHIKIN Andrey 
> Sent: 2020年12月17日 19:21
> To: Alice Guo (OSS) ; sba...@denx.de;
> feste...@gmail.com; Peng Fan 
> Cc: dl-uboot-imx ; Ye Li ;
> u-boot@lists.denx.de; Alice Guo 
> Subject: [EXT] RE: [PATCH v1 1/2] imx8mp: configs: add support for distro boot
> commands
> 
> Caution: EXT Email
> 
> Hello Alice,
> 
> > -Original Message-
> > From: U-Boot  On Behalf Of Alice Guo
> > (OSS)
> > Sent: Thursday, December 17, 2020 11:29 AM
> > To: sba...@denx.de; feste...@gmail.com; peng@nxp.com
> > Cc: uboot-...@nxp.com; ye...@nxp.com; u-boot@lists.denx.de; Alice Guo
> > 
> > Subject: [PATCH v1 1/2] imx8mp: configs: add support for distro boot
> > commands
> >
> > From: Alice Guo 
> >
> > Supported boot device types in iMX8MP: MMC.
> >
> > CONFIG_CMD_PART is added for command part and
> CONFIG_CMD_FS_GENERIC is
> > for command fstype.
> >
> > scriptaddr is the location in RAM where boot.scr.uimg/boot.scr will be
> > loaded to prior to execution. kernel_addr_r is the location in RAM
> > where the kernel will be loaded to. Delete unnecessary environment
> > variables because "run distro_bootcmd" is set to be the default boot mode.
> >
> > On the iMX8MP platform I used, "mmc1" represents SD card and "mmc2"
> > represents eMMC.
> >
> > Signed-off-by: Alice Guo 
> > ---
> >  configs/imx8mp_evk_defconfig |  2 ++
> >  include/configs/imx8mp_evk.h | 66
> > ++--
> >  2 files changed, 13 insertions(+), 55 deletions(-)
> >
> > diff --git a/configs/imx8mp_evk_defconfig
> > b/configs/imx8mp_evk_defconfig index cd5724e811..7831a940a3 100644
> > --- a/configs/imx8mp_evk_defconfig
> > +++ b/configs/imx8mp_evk_defconfig
> > @@ -51,6 +51,8 @@ CONFIG_CMD_EXT2=y
> >  CONFIG_CMD_EXT4=y
> >  CONFIG_CMD_EXT4_WRITE=y
> >  CONFIG_CMD_FAT=y
> > +CONFIG_CMD_PART=y
> > +CONFIG_CMD_FS_GENERIC=y
> >  CONFIG_OF_CONTROL=y
> >  CONFIG_SPL_OF_CONTROL=y
> >  CONFIG_ENV_OVERWRITE=y
> > diff --git a/include/configs/imx8mp_evk.h
> > b/include/configs/imx8mp_evk.h index 8253c6aa2f..70f5fb2928 100644
> > --- a/include/configs/imx8mp_evk.h
> > +++ b/include/configs/imx8mp_evk.h
> > @@ -44,69 +44,25 @@
> >
> >  #endif
> >
> > +#ifndef CONFIG_SPL_BUILD
> > +#define BOOT_TARGET_DEVICES(func) \
> > +   func(MMC, mmc, 1) \
> > +   func(MMC, mmc, 2)
> > +
> > +#include 
> > +#endif
> > +
> >  /* Initial environment variables */
> >  #define CONFIG_EXTRA_ENV_SETTINGS  \
> > -   "script=boot.scr\0" \
> > +   BOOTENV \
> > +   "scriptaddr=0x4350\0" \
> > +   "kernel_addr_r=0x4088\0" \
> > "image=Image\0" \
> > "console=ttymxc1,115200
> earlycon=ec_imx6q,0x3089,115200\0" \
> > "fdt_addr=0x4300\0" \
> > -   "boot_fdt=try\0" \
> > "fdt_file=" CONFIG_DEFAULT_FDT_FILE "\0" \
> > -   "initrd_addr=0x4380\0"  \
> > -   "bootm_size=0x1000\0" \
> 
> I believe that without proper bootm_size set, FIT image cannot be loaded
> correctly.
> 
> Commit acbc1d86f1 ("imx8m: config: convert to bootm_size") had this
> addressed, and removing the "bootm_size" would break FIT load again.
> 
> Have you tested your implementation with "bootm" in boot script? So far, I see
> that only "booti" has been used.

Hi,
Thank you for your advice. I have no need to support FIT image so that I did 
not notice this problem.
I will check and modify it.

Best Regards,
Alice

> > -   "mmcdev="__stringify(CONFIG_SYS_MMC_ENV_DEV)"\0" \
> > "mmcpart=" __stringify(CONFIG_SYS_MMC_IMG_LOAD_PART)
> "\0" \
> > "mmcroot=" CONFIG_MMCROOT " rootwait rw\0" \
> > -   "mmcautodetect=yes\0" \
> > -   "mmcargs=setenv bootargs ${jh_clk} console=${console}
> root=${mmcroot}\0
> > " \
> > -   "loadbootscript=fatload mmc ${mmcdev}:${mmcpart} ${loadaddr}
> > ${script};\0" \
> > -   "bootscript=echo Running bootscript from mmc ...; " \
> > -   "source\0" \
> > -   "loadimage=fatload mmc ${mmcdev}:${mmcpart} ${loadaddr}
> ${image}\0" \
> > -   &quo

[PATCH v1 2/2] board: imx8mp: add boot.cmd for distro boot on iMX8MP

2020-12-17 Thread Alice Guo (OSS)
From: Alice Guo 

Distro Boot requires a U-Boot-specific script named boot.scr or
boot.scr.uimg which contains boot commands to boot the system. The
boot.cmd is such a file. Use mkimage to generate boot.scr or
boot.scr.uimg from boot.cmd, and the command is:
mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n "Distro Boot Script" -d 
boot.cmd boot.scr.uimg

The boot.cmd file is an example script and can be modified based on
needs. bootargs is set in this script and root uses the default value
"/dev/mmcblk1p2 rootwait rw" which can be changed by overriding mmcroot.

Signed-off-by: Alice Guo 
---
 board/freescale/imx8mp_evk/boot.cmd | 25 +
 1 file changed, 25 insertions(+)
 create mode 100644 board/freescale/imx8mp_evk/boot.cmd

diff --git a/board/freescale/imx8mp_evk/boot.cmd 
b/board/freescale/imx8mp_evk/boot.cmd
new file mode 100644
index 00..10bcced774
--- /dev/null
+++ b/board/freescale/imx8mp_evk/boot.cmd
@@ -0,0 +1,25 @@
+setenv bootargs console=${console} root=${mmcroot};
+
+for boot_target in ${boot_targets};
+do
+if test "${boot_target}" = "mmc1" ; then
+if fatload mmc 1:${mmcpart} ${kernel_addr_r} ${image}; then
+if fatload mmc 1:${mmcpart} ${fdt_addr} ${fdt_file}; 
then
+echo Load image and .dtb from SD card(mmc1);
+booti ${kernel_addr_r} - ${fdt_addr};
+exit;
+fi
+fi
+fi
+
+if test "${boot_target}" = "mmc2" ; then
+if fatload mmc 2:${mmcpart} ${kernel_addr_r} ${image}; then
+if fatload mmc 2:${mmcpart} ${fdt_addr} ${fdt_file}; 
then
+echo Load image and .dtb from eMMC(mmc2);
+booti ${kernel_addr_r} - ${fdt_addr};
+exit;
+fi
+fi
+fi
+
+done
--
2.17.1



[PATCH v1 1/2] imx8mp: configs: add support for distro boot commands

2020-12-17 Thread Alice Guo (OSS)
From: Alice Guo 

Supported boot device types in iMX8MP: MMC.

CONFIG_CMD_PART is added for command part and CONFIG_CMD_FS_GENERIC is
for command fstype.

scriptaddr is the location in RAM where boot.scr.uimg/boot.scr will be
loaded to prior to execution. kernel_addr_r is the location in RAM where
the kernel will be loaded to. Delete unnecessary environment variables
because "run distro_bootcmd" is set to be the default boot mode.

On the iMX8MP platform I used, "mmc1" represents SD card and "mmc2"
represents eMMC.

Signed-off-by: Alice Guo 
---
 configs/imx8mp_evk_defconfig |  2 ++
 include/configs/imx8mp_evk.h | 66 ++--
 2 files changed, 13 insertions(+), 55 deletions(-)

diff --git a/configs/imx8mp_evk_defconfig b/configs/imx8mp_evk_defconfig
index cd5724e811..7831a940a3 100644
--- a/configs/imx8mp_evk_defconfig
+++ b/configs/imx8mp_evk_defconfig
@@ -51,6 +51,8 @@ CONFIG_CMD_EXT2=y
 CONFIG_CMD_EXT4=y
 CONFIG_CMD_EXT4_WRITE=y
 CONFIG_CMD_FAT=y
+CONFIG_CMD_PART=y
+CONFIG_CMD_FS_GENERIC=y
 CONFIG_OF_CONTROL=y
 CONFIG_SPL_OF_CONTROL=y
 CONFIG_ENV_OVERWRITE=y
diff --git a/include/configs/imx8mp_evk.h b/include/configs/imx8mp_evk.h
index 8253c6aa2f..70f5fb2928 100644
--- a/include/configs/imx8mp_evk.h
+++ b/include/configs/imx8mp_evk.h
@@ -44,69 +44,25 @@

 #endif

+#ifndef CONFIG_SPL_BUILD
+#define BOOT_TARGET_DEVICES(func) \
+   func(MMC, mmc, 1) \
+   func(MMC, mmc, 2)
+
+#include 
+#endif
+
 /* Initial environment variables */
 #define CONFIG_EXTRA_ENV_SETTINGS  \
-   "script=boot.scr\0" \
+   BOOTENV \
+   "scriptaddr=0x4350\0" \
+   "kernel_addr_r=0x4088\0" \
"image=Image\0" \
"console=ttymxc1,115200 earlycon=ec_imx6q,0x3089,115200\0" \
"fdt_addr=0x4300\0" \
-   "boot_fdt=try\0" \
"fdt_file=" CONFIG_DEFAULT_FDT_FILE "\0" \
-   "initrd_addr=0x4380\0"  \
-   "bootm_size=0x1000\0" \
-   "mmcdev="__stringify(CONFIG_SYS_MMC_ENV_DEV)"\0" \
"mmcpart=" __stringify(CONFIG_SYS_MMC_IMG_LOAD_PART) "\0" \
"mmcroot=" CONFIG_MMCROOT " rootwait rw\0" \
-   "mmcautodetect=yes\0" \
-   "mmcargs=setenv bootargs ${jh_clk} console=${console} root=${mmcroot}\0 
" \
-   "loadbootscript=fatload mmc ${mmcdev}:${mmcpart} ${loadaddr} 
${script};\0" \
-   "bootscript=echo Running bootscript from mmc ...; " \
-   "source\0" \
-   "loadimage=fatload mmc ${mmcdev}:${mmcpart} ${loadaddr} ${image}\0" \
-   "loadfdt=fatload mmc ${mmcdev}:${mmcpart} ${fdt_addr} ${fdt_file}\0" \
-   "mmcboot=echo Booting from mmc ...; " \
-   "run mmcargs; " \
-   "if test ${boot_fdt} = yes || test ${boot_fdt} = try; then " \
-   "if run loadfdt; then " \
-   "booti ${loadaddr} - ${fdt_addr}; " \
-   "else " \
-   "echo WARN: Cannot load the DT; " \
-   "fi; " \
-   "else " \
-   "echo wait for boot; " \
-   "fi;\0" \
-   "netargs=setenv bootargs ${jh_clk} console=${console} " \
-   "root=/dev/nfs " \
-   "ip=dhcp nfsroot=${serverip}:${nfsroot},v3,tcp\0" \
-   "netboot=echo Booting from net ...; " \
-   "run netargs;  " \
-   "if test ${ip_dyn} = yes; then " \
-   "setenv get_cmd dhcp; " \
-   "else " \
-   "setenv get_cmd tftp; " \
-   "fi; " \
-   "${get_cmd} ${loadaddr} ${image}; " \
-   "if test ${boot_fdt} = yes || test ${boot_fdt} = try; then " \
-   "if ${get_cmd} ${fdt_addr} ${fdt_file}; then " \
-   "booti ${loadaddr} - ${fdt_addr}; " \
-   "else " \
-   "echo WARN: Cannot load the DT; " \
-   "fi; " \
-   "else " \
-   "booti; " \
-   "fi;\0"
-
-#define CONFIG_BOOTCOMMAND \
-  "mmc dev ${mmcdev}; if mmc rescan; then " \
-  "if run loadbootscript; then " \
-  "run bootscript; " \
-  "else " \
-  "if run loadimage; then " \
-  "run mmcboot; " \
-  "else run netboot; " \
-  "fi; " \
-  "fi; " \
-  "else booti ${loadaddr} - ${fdt_addr}; fi"

 /* Link Definitions */
 #define CONFIG_LOADADDR0x4048
--
2.17.1



[PATCH v1 2/2] board: imx8mq: add boot.cmd for distro boot on iMX8MQ

2020-12-16 Thread Alice Guo (OSS)
From: Alice Guo 

Distro Boot requires a U-Boot-specific script named boot.scr or
boot.scr.uimg which contains boot commands to boot the system. The
boot.cmd is such a file. Use mkimage to generate boot.scr or
boot.scr.uimg from boot.cmd, and the command is:
mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n "Distro Boot Script" -d 
boot.cmd boot.scr.uimg

The boot.cmd file is an example script and can be modified based on
needs. bootargs is set in this script and root uses the default value
"/dev/mmcblk1p2 rootwait rw" which can be changed by overriding mmcroot.

On the iMX8MQ platform I used, "mmc0" represents eMMC and "mmc1"
represents SD card.

Signed-off-by: Alice Guo 
---
 board/freescale/imx8mq_evk/boot.cmd | 35 +
 1 file changed, 35 insertions(+)
 create mode 100644 board/freescale/imx8mq_evk/boot.cmd

diff --git a/board/freescale/imx8mq_evk/boot.cmd 
b/board/freescale/imx8mq_evk/boot.cmd
new file mode 100644
index 00..964993e144
--- /dev/null
+++ b/board/freescale/imx8mq_evk/boot.cmd
@@ -0,0 +1,35 @@
+setenv bootargs console=${console} root=${mmcroot};
+
+for boot_target in ${boot_targets};
+do
+if test "${boot_target}" = "mmc0" ; then
+if fatload mmc 0:${mmcpart} ${kernel_addr_r} ${image}; then
+if fatload mmc 0:${mmcpart} ${fdt_addr} ${fdt_file}; 
then
+echo Load image and .dtb from eMMC(mmc0);
+booti ${kernel_addr_r} - ${fdt_addr};
+exit;
+fi
+fi
+fi
+
+if test "${boot_target}" = "mmc1" ; then
+if fatload mmc 1:${mmcpart} ${kernel_addr_r} ${image}; then
+if fatload mmc 1:${mmcpart} ${fdt_addr} ${fdt_file}; 
then
+echo Load image and .dtb from SD card(mmc1);
+booti ${kernel_addr_r} - ${fdt_addr};
+exit;
+fi
+fi
+fi
+
+if test "${boot_target}" = "dhcp" ; then
+if dhcp ${kernel_addr_r} ${serverip}:${image}; then
+if dhcp ${fdt_addr} ${serverip}:${fdt_file}; then
+echo Load image and .dtb from net(dhcp);
+booti ${kernel_addr_r} - ${fdt_addr};
+exit;
+fi
+fi
+fi
+
+done
--
2.17.1



[PATCH v1 1/2] imx8mq: configs: add support for distro boot commands

2020-12-16 Thread Alice Guo (OSS)
From: Alice Guo 

Supported boot device types in iMX8MQ: MMC, DHCP.

CONFIG_CMD_PART is added for command part and CONFIG_CMD_FS_GENERIC is
for command fstype.

scriptaddr is the location in RAM where boot.scr.uimg/boot.scr will be
loaded to prior to execution.

kernel_addr_r is the location in RAM where the kernel will be loaded to.

Delete unnecessary environment variables because "run distro_bootcmd" is
set to be the default boot mode.

Signed-off-by: Alice Guo 
---
 configs/imx8mq_evk_defconfig |  2 +
 include/configs/imx8mq_evk.h | 78 ++--
 2 files changed, 14 insertions(+), 66 deletions(-)

diff --git a/configs/imx8mq_evk_defconfig b/configs/imx8mq_evk_defconfig
index de91a76d41..901841ea36 100644
--- a/configs/imx8mq_evk_defconfig
+++ b/configs/imx8mq_evk_defconfig
@@ -36,6 +36,8 @@ CONFIG_CMD_EXT2=y
 CONFIG_CMD_EXT4=y
 CONFIG_CMD_EXT4_WRITE=y
 CONFIG_CMD_FAT=y
+CONFIG_CMD_PART=y
+CONFIG_CMD_FS_GENERIC=y
 CONFIG_OF_CONTROL=y
 CONFIG_ENV_OVERWRITE=y
 CONFIG_ENV_IS_IN_MMC=y
diff --git a/include/configs/imx8mq_evk.h b/include/configs/imx8mq_evk.h
index 3f9a3bc100..1f740f0745 100644
--- a/include/configs/imx8mq_evk.h
+++ b/include/configs/imx8mq_evk.h
@@ -74,80 +74,26 @@
 #define IMX_FEC_BASE   0x30BE
 #endif

-#define CONFIG_MFG_ENV_SETTINGS \
-   "mfgtool_args=setenv bootargs console=${console},${baudrate} " \
-   "rdinit=/linuxrc " \
-   "g_mass_storage.stall=0 g_mass_storage.removable=1 " \
-   "g_mass_storage.idVendor=0x066F g_mass_storage.idProduct=0x37FF 
"\
-   "g_mass_storage.iSerialNumber=\"\" "\
-   "clk_ignore_unused "\
-   "\0" \
-   "initrd_addr=0x4380\0" \
-   "bootcmd_mfg=run mfgtool_args;booti ${loadaddr} ${initrd_addr} 
${fdt_addr};\0" \
+#ifndef CONFIG_SPL_BUILD
+#define BOOT_TARGET_DEVICES(func) \
+   func(MMC, mmc, 0) \
+   func(MMC, mmc, 1) \
+   func(DHCP, dhcp, na)
+
+#include 
+#endif
+
 /* Initial environment variables */
 #define CONFIG_EXTRA_ENV_SETTINGS  \
-   CONFIG_MFG_ENV_SETTINGS \
-   "script=boot.scr\0" \
+   BOOTENV \
+   "scriptaddr=0x4350\0" \
+   "kernel_addr_r=0x4088\0" \
"image=Image\0" \
"console=ttymxc0,115200\0" \
"fdt_addr=0x4300\0" \
-   "boot_fdt=try\0" \
"fdt_file=imx8mq-evk.dtb\0" \
-   "initrd_addr=0x4380\0"  \
-   "bootm_size=0x1000\0" \
-   "mmcdev="__stringify(CONFIG_SYS_MMC_ENV_DEV)"\0" \
"mmcpart=" __stringify(CONFIG_SYS_MMC_IMG_LOAD_PART) "\0" \
"mmcroot=" CONFIG_MMCROOT " rootwait rw\0" \
-   "mmcautodetect=yes\0" \
-   "mmcargs=setenv bootargs console=${console} root=${mmcroot}\0 " \
-   "loadbootscript=fatload mmc ${mmcdev}:${mmcpart} ${loadaddr} 
${script};\0" \
-   "bootscript=echo Running bootscript from mmc ...; " \
-   "source\0" \
-   "loadimage=fatload mmc ${mmcdev}:${mmcpart} ${loadaddr} ${image}\0" \
-   "loadfdt=fatload mmc ${mmcdev}:${mmcpart} ${fdt_addr} ${fdt_file}\0" \
-   "mmcboot=echo Booting from mmc ...; " \
-   "run mmcargs; " \
-   "if test ${boot_fdt} = yes || test ${boot_fdt} = try; then " \
-   "if run loadfdt; then " \
-   "booti ${loadaddr} - ${fdt_addr}; " \
-   "else " \
-   "echo WARN: Cannot load the DT; " \
-   "fi; " \
-   "else " \
-   "echo wait for boot; " \
-   "fi;\0" \
-   "netargs=setenv bootargs console=${console} " \
-   "root=/dev/nfs " \
-   "ip=dhcp nfsroot=${serverip}:${nfsroot},v3,tcp\0" \
-   "netboot=echo Booting from net ...; " \
-   "run netargs;  " \
-   "if test ${ip_dyn} = yes; then " \
-   "setenv get_cmd dhcp; " \
-   "else " \
-   "setenv get_cmd tftp; " \
-   "fi; " \
-   "${get_cmd} ${loadaddr} ${image}; " \
-   "if test ${boot_fdt} = yes || test ${boot_fdt} = try; then " \
-   "if ${get_cmd} ${fdt_addr} ${fdt_file}; then " \
-   "booti ${loadaddr} - ${fdt_addr}; " \
-   "else " \
-   "echo WARN: Cannot load the DT; " \
-   "fi; " \
-   "else " \
-   "booti; " \
-   "fi;\0"
-
-#define CONFIG_BOOTCOMMAND \
-  "mmc dev ${mmcdev}; if mmc rescan; then " \
-  "if run loadbootscript; then " \
-  "run bootscript; " \
-  "else " \
-  "if run loadimage; then " \
-  "run mmcboot; " \
-  "else run netboot; " \
-  "fi; " \
-

[PATCH v2 2/2] board: imx8mm: add boot.cmd for distro boot on iMX8MM

2020-12-15 Thread Alice Guo (OSS)
From: Alice Guo 

Distro Boot requires a U-Boot-specific script named boot.scr or
boot.scr.uimg which contains boot commands to boot the system. The
boot.cmd is such a file. Use mkimage to generate boot.scr or
boot.scr.uimg from boot.cmd, and the command is:
mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n "Distro Boot Script" -d 
boot.cmd boot.scr.uimg

The boot.cmd file is an example script and can be modified based on
needs. bootargs is set in this script and root uses the default value "
/dev/mmcblk1p2 rootwait rw" which can be changed by overriding mmcroot.

Signed-off-by: Alice Guo 
---

Changes for v2:
 - add the additional explanation of boot.cmd in commit message

 board/freescale/imx8mm_evk/boot.cmd | 35 +
 1 file changed, 35 insertions(+)
 create mode 100644 board/freescale/imx8mm_evk/boot.cmd

diff --git a/board/freescale/imx8mm_evk/boot.cmd 
b/board/freescale/imx8mm_evk/boot.cmd
new file mode 100644
index 00..fdfceec263
--- /dev/null
+++ b/board/freescale/imx8mm_evk/boot.cmd
@@ -0,0 +1,35 @@
+setenv bootargs console=${console} root=${mmcroot};
+
+for boot_target in ${boot_targets};
+do
+if test "${boot_target}" = "mmc1" ; then
+if fatload mmc 1:${mmcpart} ${kernel_addr_r} ${image}; then
+if fatload mmc 1:${mmcpart} ${fdt_addr} ${fdt_file}; 
then
+echo Load image and .dtb from SD card(mmc1);
+booti ${kernel_addr_r} - ${fdt_addr};
+exit;
+fi
+fi
+fi
+
+if test "${boot_target}" = "mmc2" ; then
+if fatload mmc 2:${mmcpart} ${kernel_addr_r} ${image}; then
+if fatload mmc 2:${mmcpart} ${fdt_addr} ${fdt_file}; 
then
+echo Load image and .dtb from eMMC(mmc2);
+booti ${kernel_addr_r} - ${fdt_addr};
+exit;
+fi
+fi
+fi
+
+if test "${boot_target}" = "dhcp" ; then
+if dhcp ${kernel_addr_r} ${serverip}:${image}; then
+if dhcp ${fdt_addr} ${serverip}:${fdt_file}; then
+echo Load image and .dtb from net(dhcp);
+booti ${kernel_addr_r} - ${fdt_addr};
+exit;
+fi
+fi
+fi
+
+done
--
2.17.1



[PATCH v2 1/2] imx8mm: configs: add support for distro boot commands

2020-12-15 Thread Alice Guo (OSS)
From: Alice Guo 

Supported boot device types in iMX8MM: MMC, DHCP.

CONFIG_CMD_PART is added for command part and CONFIG_CMD_FS_GENERIC is
for command fstype.

CONFIG_BOOTCOMMAND which is defined in include/configs/imx8mm_evk.h is
deleted because "run distro_bootcmd" is required to be the default boot
mode.

scriptaddr is the location in RAM where boot.scr.uimg/boot.scr will be
loaded to prior to execution.

kernel_addr_r is the location in RAM where the kernel will be loaded to.

Delete unnecessary environment variables.

Signed-off-by: Alice Guo 
---

Changes for v2:
 - remove supported boot device type QSPI
 - delete unnecessary environment variables
 - set "run distro_bootcmd" to be the default boot mode

 configs/imx8mm_evk_defconfig |  2 ++
 include/configs/imx8mm_evk.h | 67 +++-
 2 files changed, 14 insertions(+), 55 deletions(-)

diff --git a/configs/imx8mm_evk_defconfig b/configs/imx8mm_evk_defconfig
index 91d3bc3ac9..4c0dd27e71 100644
--- a/configs/imx8mm_evk_defconfig
+++ b/configs/imx8mm_evk_defconfig
@@ -49,6 +49,8 @@ CONFIG_CMD_EXT2=y
 CONFIG_CMD_EXT4=y
 CONFIG_CMD_EXT4_WRITE=y
 CONFIG_CMD_FAT=y
+CONFIG_CMD_PART=y
+CONFIG_CMD_FS_GENERIC=y
 CONFIG_OF_CONTROL=y
 CONFIG_SPL_OF_CONTROL=y
 CONFIG_ENV_OVERWRITE=y
diff --git a/include/configs/imx8mm_evk.h b/include/configs/imx8mm_evk.h
index 83521ad401..3bb2bcc287 100644
--- a/include/configs/imx8mm_evk.h
+++ b/include/configs/imx8mm_evk.h
@@ -32,69 +32,26 @@

 #endif

+#ifndef CONFIG_SPL_BUILD
+#define BOOT_TARGET_DEVICES(func) \
+   func(MMC, mmc, 1) \
+   func(MMC, mmc, 2) \
+   func(DHCP, dhcp, na)
+
+#include 
+#endif
+
 /* Initial environment variables */
 #define CONFIG_EXTRA_ENV_SETTINGS  \
-   "script=boot.scr\0" \
+   BOOTENV \
+   "scriptaddr=0x4350\0" \
+   "kernel_addr_r=0x4088\0" \
"image=Image\0" \
"console=ttymxc1,115200\0" \
"fdt_addr=0x4300\0" \
-   "boot_fit=no\0" \
"fdt_file=imx8mm-evk.dtb\0" \
-   "initrd_addr=0x4380\0"  \
-   "bootm_size=0x1000\0" \
-   "mmcdev="__stringify(CONFIG_SYS_MMC_ENV_DEV)"\0" \
"mmcpart=" __stringify(CONFIG_SYS_MMC_IMG_LOAD_PART) "\0" \
"mmcroot=" CONFIG_MMCROOT " rootwait rw\0" \
-   "mmcautodetect=yes\0" \
-   "mmcargs=setenv bootargs console=${console} root=${mmcroot}\0 " \
-   "loadbootscript=fatload mmc ${mmcdev}:${mmcpart} ${loadaddr} 
${script};\0" \
-   "bootscript=echo Running bootscript from mmc ...; " \
-   "source\0" \
-   "loadimage=fatload mmc ${mmcdev}:${mmcpart} ${loadaddr} ${image}\0" \
-   "loadfdt=fatload mmc ${mmcdev}:${mmcpart} ${fdt_addr} ${fdt_file}\0" \
-   "mmcboot=echo Booting from mmc ...; " \
-   "run mmcargs; " \
-   "if test ${boot_fit} = yes || test ${boot_fit} = try; then " \
-   "bootm ${loadaddr}; " \
-   "else " \
-   "if run loadfdt; then " \
-   "booti ${loadaddr} - ${fdt_addr}; " \
-   "else " \
-   "echo WARN: Cannot load the DT; " \
-   "fi; " \
-   "fi;\0" \
-   "netargs=setenv bootargs console=${console} " \
-   "root=/dev/nfs " \
-   "ip=dhcp nfsroot=${serverip}:${nfsroot},v3,tcp\0" \
-   "netboot=echo Booting from net ...; " \
-   "run netargs;  " \
-   "if test ${ip_dyn} = yes; then " \
-   "setenv get_cmd dhcp; " \
-   "else " \
-   "setenv get_cmd tftp; " \
-   "fi; " \
-   "${get_cmd} ${loadaddr} ${image}; " \
-   "if test ${boot_fit} = yes || test ${boot_fit} = try; then " \
-   "bootm ${loadaddr}; " \
-   "else " \
-   "if ${get_cmd} ${fdt_addr} ${fdt_file}; then " \
-   "booti ${loadaddr} - ${fdt_addr}; " \
-   "else " \
-   "echo WARN: Cannot load the DT; " \
-   "fi; " \
-   "fi;\0"
-
-#define CONFIG_BOOTCOMMAND \
-  "mmc dev ${mmcdev}; if mmc rescan; then " \
-  "if run loadbootscript; then " \
-  "run bootscript; " \
-  "else " \
-  "if run loadimage; then " \
-  "run mmcboot; " \
-  "else run netboot; " \
-  "fi; " \
-  "fi; " \
-  "fi;"

 /* Link Definitions */
 #define CONFIG_LOADADDR0x4048
--
2.17.1



[PATCH v1 2/2] board: imx8mm: add boot.cmd for distro boot on iMX8MM

2020-12-12 Thread Alice Guo (OSS)
From: Alice Guo 

Distro Boot requires a U-Boot-specific script named boot.scr or
boot.scr.uimg which contains boot commands to boot the system. The
boot.cmd is such a file. Use mkimage to generate boot.scr or
boot.scr.uimg from boot.cmd, and the command is:
mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n "Distro Boot Script" -d 
boot.cmd boot.scr.uimg

QSPI in iMX8MM platform is only used to store bootloader and script so
that we do not load image or .dtb file from QSPI as is shown in
boot.cmd file.

The boot.cmd file is an example script and can be modified based on
needs.

Signed-off-by: Alice Guo 
---
 board/freescale/imx8mm_evk/boot.cmd | 35 +
 1 file changed, 35 insertions(+)
 create mode 100644 board/freescale/imx8mm_evk/boot.cmd

diff --git a/board/freescale/imx8mm_evk/boot.cmd 
b/board/freescale/imx8mm_evk/boot.cmd
new file mode 100644
index 00..fdfceec263
--- /dev/null
+++ b/board/freescale/imx8mm_evk/boot.cmd
@@ -0,0 +1,35 @@
+setenv bootargs console=${console} root=${mmcroot};
+
+for boot_target in ${boot_targets};
+do
+if test "${boot_target}" = "mmc1" ; then
+if fatload mmc 1:${mmcpart} ${kernel_addr_r} ${image}; then
+if fatload mmc 1:${mmcpart} ${fdt_addr} ${fdt_file}; 
then
+echo Load image and .dtb from SD card(mmc1);
+booti ${kernel_addr_r} - ${fdt_addr};
+exit;
+fi
+fi
+fi
+
+if test "${boot_target}" = "mmc2" ; then
+if fatload mmc 2:${mmcpart} ${kernel_addr_r} ${image}; then
+if fatload mmc 2:${mmcpart} ${fdt_addr} ${fdt_file}; 
then
+echo Load image and .dtb from eMMC(mmc2);
+booti ${kernel_addr_r} - ${fdt_addr};
+exit;
+fi
+fi
+fi
+
+if test "${boot_target}" = "dhcp" ; then
+if dhcp ${kernel_addr_r} ${serverip}:${image}; then
+if dhcp ${fdt_addr} ${serverip}:${fdt_file}; then
+echo Load image and .dtb from net(dhcp);
+booti ${kernel_addr_r} - ${fdt_addr};
+exit;
+fi
+fi
+fi
+
+done
--
2.17.1



[PATCH v1 1/2] imx8mm: configs: add support for distro boot commands

2020-12-12 Thread Alice Guo (OSS)
From: Alice Guo 

Supported boot device types in iMX8MM: MMC, QSPI, DHCP.

BOOTENV introduces other environment variables, so the size of ENV
should be increased. CONFIG_CMD_PART is added for command part and
CONFIG_CMD_FS_GENERIC is for command fstype.

CONFIG_BOOTCOMMAND which is defined in include/configs/imx8mm_evk.h is
moved to the place before BOOTENV because "run distro_bootcmd" is not
required to be the default boot mode. scriptaddr is the location in RAM
where boot.scr.uimg/boot.scr will be loaded to prior to execution.
script_offset_f is the location of boot.scr.uimg/boot.scr in QSPI and
script_size_f is the size of boot.scr.uimg/boot.scr. kernel_addr_r is
the location in RAM where the kernel will be loaded to.

Signed-off-by: Alice Guo 
---
 configs/imx8mm_evk_defconfig |  4 ++-
 include/configs/imx8mm_evk.h | 47 +++-
 2 files changed, 38 insertions(+), 13 deletions(-)

diff --git a/configs/imx8mm_evk_defconfig b/configs/imx8mm_evk_defconfig
index 91d3bc3ac9..993b7b8835 100644
--- a/configs/imx8mm_evk_defconfig
+++ b/configs/imx8mm_evk_defconfig
@@ -5,7 +5,7 @@ CONFIG_SPL_GPIO_SUPPORT=y
 CONFIG_SPL_LIBCOMMON_SUPPORT=y
 CONFIG_SPL_LIBGENERIC_SUPPORT=y
 CONFIG_SYS_MALLOC_F_LEN=0x1
-CONFIG_ENV_SIZE=0x1000
+CONFIG_ENV_SIZE=0x2000
 CONFIG_ENV_OFFSET=0x40
 CONFIG_SYS_I2C_MXC_I2C1=y
 CONFIG_SYS_I2C_MXC_I2C2=y
@@ -49,6 +49,8 @@ CONFIG_CMD_EXT2=y
 CONFIG_CMD_EXT4=y
 CONFIG_CMD_EXT4_WRITE=y
 CONFIG_CMD_FAT=y
+CONFIG_CMD_PART=y
+CONFIG_CMD_FS_GENERIC=y
 CONFIG_OF_CONTROL=y
 CONFIG_SPL_OF_CONTROL=y
 CONFIG_ENV_OVERWRITE=y
diff --git a/include/configs/imx8mm_evk.h b/include/configs/imx8mm_evk.h
index 83521ad401..e6a1a0557a 100644
--- a/include/configs/imx8mm_evk.h
+++ b/include/configs/imx8mm_evk.h
@@ -32,8 +32,43 @@

 #endif

+#define CONFIG_BOOTCOMMAND \
+  "mmc dev ${mmcdev}; if mmc rescan; then " \
+  "if run loadbootscript; then " \
+  "run bootscript; " \
+  "else " \
+  "if run loadimage; then " \
+  "run mmcboot; " \
+  "else run netboot; " \
+  "fi; " \
+  "fi; " \
+  "fi;"
+
+#define BOOTENV_DEV_QSPI(devtypeu, devtypel, instance) \
+   "bootcmd_" #devtypel #instance "=sf probe " #instance " 0 0 && " \
+  "sf read $scriptaddr $script_offset_f $script_size_f && 
" \
+  "source ${scriptaddr}; echo SCRIPT FAILED: 
continuing...;\0"
+
+#define BOOTENV_DEV_NAME_QSPI(devtypeu, devtypel, instance) \
+   #devtypel #instance " "
+
+#ifndef CONFIG_SPL_BUILD
+#define BOOT_TARGET_DEVICES(func) \
+   func(MMC, mmc, 1) \
+   func(MMC, mmc, 2) \
+   func(QSPI, qspi, 0) \
+   func(DHCP, dhcp, na)
+
+#include 
+#endif
+
 /* Initial environment variables */
 #define CONFIG_EXTRA_ENV_SETTINGS  \
+   BOOTENV \
+   "scriptaddr=0x4350\0" \
+   "script_offset_f=0x50\0" \
+   "script_size_f=0x10\0" \
+   "kernel_addr_r=0x4088\0" \
"script=boot.scr\0" \
"image=Image\0" \
"console=ttymxc1,115200\0" \
@@ -84,18 +119,6 @@
"fi; " \
"fi;\0"

-#define CONFIG_BOOTCOMMAND \
-  "mmc dev ${mmcdev}; if mmc rescan; then " \
-  "if run loadbootscript; then " \
-  "run bootscript; " \
-  "else " \
-  "if run loadimage; then " \
-  "run mmcboot; " \
-  "else run netboot; " \
-  "fi; " \
-  "fi; " \
-  "fi;"
-
 /* Link Definitions */
 #define CONFIG_LOADADDR0x4048

--
2.17.1