Skip to contentSkip to conversation

imx8mn_ddr4_evk: Add USB Mass Storage support

PATCH Superseded Fabio Estevam 5 participants 16 messages Apr 20, 2022 – Apr 21, 2022

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Fabio Estevam

author reviewer
#0 lore raw

PATCH 1/2 imx8mn_ddr4_evk: Add USB Mass Storage support

From: Fabio Estevam <[email protected]>

Add USB Mass Storage support, which is a convenient way to flash the eMMC card, for example.

---
 configs/imx8mn_ddr4_evk_defconfig | 12 ++++++++++++
 1 file changed, 12 insertions(+)
configs/imx8mn_ddr4_evk_defconfig +12 -0
index 917cdb5aa9d9..065f7392b706 100644
@@ -42,6 +42,8 @@ CONFIG_CMD_FUSE=y
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_I2C=y
 CONFIG_CMD_MMC=y
+CONFIG_CMD_USB=y
+CONFIG_CMD_USB_MASS_STORAGE=y
 CONFIG_CMD_CACHE=y
 CONFIG_CMD_REGULATOR=y
 CONFIG_CMD_EXT4_WRITE=y
@@ -82,4 +84,14 @@ CONFIG_SPL_SYSRESET=y
 CONFIG_SYSRESET_PSCI=y
 CONFIG_SYSRESET_WATCHDOG=y
 CONFIG_DM_THERMAL=y
+CONFIG_USB=y
+# CONFIG_SPL_DM_USB is not set
+CONFIG_USB_EHCI_HCD=y
+CONFIG_MXC_USB_OTG_HACTIVE=y
+CONFIG_USB_GADGET=y
+CONFIG_USB_GADGET_MANUFACTURER="FSL"
+CONFIG_USB_GADGET_VENDOR_NUM=0x0525
+CONFIG_USB_GADGET_PRODUCT_NUM=0xa4a5
+CONFIG_CI_UDC=y
+CONFIG_USB_GADGET_DOWNLOAD=y
 CONFIG_IMX_WATCHDOG=y
Signature · 1 line
2.25.1
author reviewer
#1 lore raw

PATCH 2/2 imx8mn/8mp: Select ENV_IS_NOWHERE

From: Fabio Estevam <[email protected]>

Currently, on i.MX8MN/i.MX8MP (Bootrom version 2) it is not possible to load U-Boot via serial download mode, unless CONFIG_ENV_IS_NOWHERE is selected.

This was noticed before by Adam Ford and fixed on the imx8mn beacon board in commit 2c7ebf7778cf ("imx: imx8mn_beacon: Fix USB booting").

Such commit log states:

"The i.MX8M Nano can boot over USB using the boot ROM instead of adding extra code to SPL to support USB drivers, etc. However, when booting from USB, the environment doesnt' know where to load and causes a hang. Fix this hang by supporting CONFIG_ENV_IS_NOWHERE=y. It only falls back to this condition when booting from USB, so it does not impact MMC booting."

Select ENV_IS_NOWHERE globally when i.MX8MN or i.MX8MP are used, so that serial download mode can be used by default on these SoCs.

---
 arch/arm/mach-imx/imx8m/Kconfig | 2 ++
 1 file changed, 2 insertions(+)
arch/arm/mach-imx/imx8m/Kconfig +2 -0
index 55db25062a9b..ba7328aec8a1 100644
@@ -16,10 +16,12 @@ config IMX8MM
 config IMX8MN
 	bool
 	select IMX8M
+	select ENV_IS_NOWHERE
 
 config IMX8MP
 	bool
 	select IMX8M
+	select ENV_IS_NOWHERE
 
 config SYS_SOC
 	default "imx8m"
Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH 2/2] imx8mn/8mp: Select ENV_IS_NOWHERE

Quoted 9 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

Currently, on i.MX8MN/i.MX8MP (Bootrom version 2) it is not possible to load U-Boot via serial download mode, unless CONFIG_ENV_IS_NOWHERE is selected.

This was noticed before by Adam Ford and fixed on the imx8mn beacon board in commit 2c7ebf7778cf ("imx: imx8mn_beacon: Fix USB booting").

Quoted 8 lines

Such commit log states:

"The i.MX8M Nano can boot over USB using the boot ROM instead of adding extra code to SPL to support USB drivers, etc. However, when booting from USB, the environment doesnt' know where to load and causes a hang. Fix this hang by supporting CONFIG_ENV_IS_NOWHERE=y. It only falls back to this condition when booting from USB, so it does not impact MMC booting."

I suspect this happens because

arch/arm/mach-imx/imx8m/soc.c env_get_location()

contains
"
...
default:
return ENVL_NOWHERE;
"

right ?

I wonder what would happen if you were to add:

case USB_BOOT:
return ENVL_UNKNOWN;

Maybe that would even work without CONFIG_ENV_IS_NOWHERE=y ?

author reviewer
#3 lore raw

Re: [PATCH 2/2] imx8mn/8mp: Select ENV_IS_NOWHERE

Hi Marek,

Quoted 11 lines · Marek Vasut

I suspect this happens because

arch/arm/mach-imx/imx8m/soc.c env_get_location()

contains
"
...
default:
return ENVL_NOWHERE;
"

Quoted 8 lines

right ?

I wonder what would happen if you were to add:

case USB_BOOT:

   return ENVL_UNKNOWN;

Maybe that would even work without CONFIG_ENV_IS_NOWHERE=y ?

Unfortunately, with this change the boot via SDP does not complete:

U-Boot SPL 2022.04-00857-g0f0a48bd2df4-dirty (Apr 20 2022 - 18:57:00 -0300)
SEC0: RNG instantiated
Normal Boot
WDT: Started watchdog@30280000 with servicing (60s timeout)
Trying to boot from BOOTROM
Find img info 0x&48020a00, size 872
Need continue download 1024
Download 762080, Total size 763616

NOTICE:  BL31: v2.2(release):rel_imx_5.4.47_2.2.0-0-gc949a888e909
NOTICE:  BL31: Built : 16:07:45, Apr 20 2022

(it hangs here)

#4 lore raw

Re: [PATCH 2/2] imx8mn/8mp: Select ENV_IS_NOWHERE

Quoted 1 line · Fabio Estevam

Hi Marek,

Hi,

Quoted 15 lines · Marek Vasut
Quoted 14 lines

I suspect this happens because

arch/arm/mach-imx/imx8m/soc.c env_get_location()

contains
"
...
default:

   return ENVL_NOWHERE;

"

right ?

Quoted 8 lines
Quoted 6 lines

I wonder what would happen if you were to add:

case USB_BOOT:

    return ENVL_UNKNOWN;

Maybe that would even work without CONFIG_ENV_IS_NOWHERE=y ?

Unfortunately, with this change the boot via SDP does not complete:

Did you actually hit the USB_BOOT case or did you fall into the default: case ?

author reviewer
#5 lore raw

Re: [PATCH 2/2] imx8mn/8mp: Select ENV_IS_NOWHERE

Hi Marek,

Quoted 2 lines · Marek Vasut

Did you actually hit the USB_BOOT case or did you fall into the default:
case ?

It does hit the USB_BOOT case.

I also tested forcing to return ENVL_UNKNOWN:

arch/arm/mach-imx/imx8m/soc.c +1 -0
@@ -1531,6 +1531,7 @@ void do_error(struct pt_regs *pt_regs)
 enum env_location env_get_location(enum env_operation op, int prio)
 {
        enum boot_device dev = get_boot_device();
+       return ENVL_UNKNOWN;
 
        if (prio)
                return ENVL_UNKNOWN;

but still, the boot does not complete.

#6 lore raw

Re: [PATCH 2/2] imx8mn/8mp: Select ENV_IS_NOWHERE

Hi Fabio

Quoted 23 lines · Fabio Estevam

Hi Marek,

Quoted 2 lines · Marek Vasut

Did you actually hit the USB_BOOT case or did you fall into the default:
case ?

It does hit the USB_BOOT case.

I also tested forcing to return ENVL_UNKNOWN:

arch/arm/mach-imx/imx8m/soc.c +1 -0
@@ -1531,6 +1531,7 @@ void do_error(struct pt_regs *pt_regs)
 enum env_location env_get_location(enum env_operation op, int prio)
 {
        enum boot_device dev = get_boot_device();
+       return ENVL_UNKNOWN;
 
        if (prio)
                return ENVL_UNKNOWN;
Quoted 1 line

but still, the boot does not complete.

You need only add USB_ case in MMC and NAND

#ifdef CONFIG_ENV_IS_IN_NAND
        /* add */
        case USB_BOOT:
        case NAND_BOOT:
                env_loc = ENVL_NAND;
                break;
#endif
#ifdef CONFIG_ENV_IS_IN_MMC
        /* add */
        case USB_BOOT:
        case SD1_BOOT:
        case SD2_BOOT:
        case SD3_BOOT:
        case MMC1_BOOT:
        case MMC2_BOOT:
        case MMC3_BOOT:
                env_loc =  ENVL_MMC;
                break;

#endif

Michael

Signature · 11 lines
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
[email protected]
__________________________________

Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
[email protected]
www.amarulasolutions.com
#7 lore raw

Re: [PATCH 2/2] imx8mn/8mp: Select ENV_IS_NOWHERE

Hi Michael,

Quoted 19 lines · Michael Nazzareno Trimarchi

You need only add USB_ case in MMC and NAND

#ifdef CONFIG_ENV_IS_IN_NAND
        /* add */
        case USB_BOOT:
        case NAND_BOOT:
                env_loc = ENVL_NAND;
                break;
#endif
#ifdef CONFIG_ENV_IS_IN_MMC
        /* add */
        case USB_BOOT:
        case SD1_BOOT:
        case SD2_BOOT:
        case SD3_BOOT:
        case MMC1_BOOT:
        case MMC2_BOOT:
        case MMC3_BOOT:
                env_loc =  ENVL_MMC;
                break;
Quoted 1 line

#endif

Your suggestion works, thanks.

I will prepare v2.

Thanks,

Fabio Estevam

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-60 Fax: (+49)-8142-66989-80 Email: [email protected]
#8 lore raw

Re: [PATCH 2/2] imx8mn/8mp: Select ENV_IS_NOWHERE

Hi Fabio

Quoted 26 lines · Fabio Estevam

Hi Michael,

Quoted 19 lines · Michael Nazzareno Trimarchi

You need only add USB_ case in MMC and NAND

#ifdef CONFIG_ENV_IS_IN_NAND
        /* add */
        case USB_BOOT:
        case NAND_BOOT:
                env_loc = ENVL_NAND;
                break;
#endif
#ifdef CONFIG_ENV_IS_IN_MMC
        /* add */
        case USB_BOOT:
        case SD1_BOOT:
        case SD2_BOOT:
        case SD3_BOOT:
        case MMC1_BOOT:
        case MMC2_BOOT:
        case MMC3_BOOT:
                env_loc =  ENVL_MMC;
                break;
Quoted 1 line

#endif

Quoted 3 lines

Your suggestion works, thanks.

I will prepare v2.

That function should drop. There is not other architecture that does it. What about:

register_enviroment_hook()
deregister_enviroment_hook()

This can replace the one default with board/arch etc

Michael

Quoted 9 lines

Thanks,

Fabio Estevam
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-60 Fax: (+49)-8142-66989-80 Email:
[email protected]

Signature · 11 lines
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
[email protected]
__________________________________

Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
[email protected]
www.amarulasolutions.com
#9 lore raw

Re: [PATCH 2/2] imx8mn/8mp: Select ENV_IS_NOWHERE

Hi Michael,

Quoted 2 lines · Michael Nazzareno Trimarchi

That function should drop. There is not other architecture that does it. What about:

I implemented your suggestion like this:

arch/arm/mach-imx/imx8m/soc.c +8 -0
@@ -1536,6 +1536,14 @@ enum env_location arch_env_get_location(enum env_operation op, int prio)
                return ENVL_UNKNOWN;
 
        switch (dev) {
+       case USB_BOOT:
+               if (IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH))
+                       return ENVL_SPI_FLASH;
+               if (IS_ENABLED(CONFIG_ENV_IS_IN_NAND))
+                       return ENVL_NAND;
+               if (IS_ENABLED(CONFIG_ENV_IS_IN_MMC))
+                       return ENVL_MMC;
+               return ENVL_NOWHERE;
        case QSPI_BOOT:
        case SPI_NOR_BOOT:
                if (IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH))

This still allows me to save the env into the eMMC when U-Boot is loaded from USB.

Quoted 4 lines

register_enviroment_hook()
deregister_enviroment_hook()

This can replace the one default with board/arch etc

Marek submitted these patches:

https://source.denx.de/u-boot/u-boot/-/commit/de70e8879bb253f4d2a9ba9149cd41cb38b94ed8

https://source.denx.de/u-boot/u-boot/-/commit/e4dc2d0620851d6e0e784d4ef0a50f26e1e73857

Is this the mechanism that you are looking for?

#10 lore raw

Re: [PATCH 2/2] imx8mn/8mp: Select ENV_IS_NOWHERE

Quoted 35 lines · Fabio Estevam

Hi Michael,

Quoted 2 lines · Michael Nazzareno Trimarchi

That function should drop. There is not other architecture that does it. What about:

I implemented your suggestion like this:

arch/arm/mach-imx/imx8m/soc.c +8 -0
@@ -1536,6 +1536,14 @@ enum env_location arch_env_get_location(enum
 env_operation op, int prio)
                 return ENVL_UNKNOWN;
 
         switch (dev) {
+       case USB_BOOT:
+               if (IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH))
+                       return ENVL_SPI_FLASH;
+               if (IS_ENABLED(CONFIG_ENV_IS_IN_NAND))
+                       return ENVL_NAND;
+               if (IS_ENABLED(CONFIG_ENV_IS_IN_MMC))
+                       return ENVL_MMC;
+               return ENVL_NOWHERE;
         case QSPI_BOOT:
         case SPI_NOR_BOOT:

if (IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH))

This still allows me to save the env into the eMMC when U-Boot is loaded from USB.

Quoted 3 lines

register_enviroment_hook()
deregister_enviroment_hook()

Quoted 8 lines
Quoted 1 line

This can replace the one default with board/arch etc

Marek submitted these patches:

https://source.denx.de/u-boot/u-boot/-/commit/de70e8879bb253f4d2a9ba9149cd41cb38b94ed8

https://source.denx.de/u-boot/u-boot/-/commit/e4dc2d0620851d6e0e784d4ef0a50f26e1e73857

I believe those were applied today. I haven't verified it yet, but I think I saw the e-mail go by.

Quoted 1 line

Is this the mechanism that you are looking for?

#11 lore raw

Re: [PATCH 2/2] imx8mn/8mp: Select ENV_IS_NOWHERE

Hi

Quoted 41 lines · Adam Ford
Quoted 39 lines · Fabio Estevam

Hi Michael,

Quoted 2 lines · Michael Nazzareno Trimarchi

That function should drop. There is not other architecture that does it. What about:

I implemented your suggestion like this:

arch/arm/mach-imx/imx8m/soc.c +8 -0
@@ -1536,6 +1536,14 @@ enum env_location arch_env_get_location(enum
 env_operation op, int prio)
                 return ENVL_UNKNOWN;
 
         switch (dev) {
+       case USB_BOOT:
+               if (IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH))
+                       return ENVL_SPI_FLASH;
+               if (IS_ENABLED(CONFIG_ENV_IS_IN_NAND))
+                       return ENVL_NAND;
+               if (IS_ENABLED(CONFIG_ENV_IS_IN_MMC))
+                       return ENVL_MMC;
+               return ENVL_NOWHERE;
         case QSPI_BOOT:
         case SPI_NOR_BOOT:

if (IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH))

This still allows me to save the env into the eMMC when U-Boot is loaded from USB.

Quoted 4 lines

register_enviroment_hook()
deregister_enviroment_hook()

This can replace the one default with board/arch etc

Marek submitted these patches:

Quoted 9 lines
Quoted 4 lines

https://source.denx.de/u-boot/u-boot/-/commit/de70e8879bb253f4d2a9ba9149cd41cb38b94ed8

https://source.denx.de/u-boot/u-boot/-/commit/e4dc2d0620851d6e0e784d4ef0a50f26e1e73857

I believe those were applied today. I haven't verified it yet, but I think I saw the e-mail go by.

Quoted 1 line

Is this the mechanism that you are looking for?

I have seen those patches already but the cost of a function pointer and a call is more readable. If they get applied, I will be fine with them ;)

Michael

Signature · 11 lines
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
[email protected]
__________________________________

Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
[email protected]
www.amarulasolutions.com
#12 lore raw

Re: [PATCH 2/2] imx8mn/8mp: Select ENV_IS_NOWHERE

Quoted 3 lines · Michael Nazzareno Trimarchi

I have seen those patches already but the cost of a function pointer and a call is more readable. If they get applied, I will be fine with them ;)

They are already in master.

How do we proceed to fix the U-Boot load via USB?

#13 lore raw

Re: [PATCH 2/2] imx8mn/8mp: Select ENV_IS_NOWHERE

Hi

Quoted 10 lines · Fabio Estevam
Quoted 3 lines · Michael Nazzareno Trimarchi

I have seen those patches already but the cost of a function pointer and a call is more readable. If they get applied, I will be fine with them ;)

They are already in master.

How do we proceed to fix the U-Boot load via USB?

The uboot has no problem, the problem is that the function is wrong ;). When you boot from USB you should inform where to pick the environment. You can force ENV_EVERYWHERE for those architectures, you can decide to change the switch as I said, or you can add in your board and override at board level the function ;)

Michael

Signature · 11 lines
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
[email protected]
__________________________________

Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
[email protected]
www.amarulasolutions.com
#14 lore raw

Re: [PATCH 2/2] imx8mn/8mp: Select ENV_IS_NOWHERE

Quoted 4 lines · Michael Nazzareno Trimarchi

The uboot has no problem, the problem is that the function is wrong ;). When you boot from USB you should inform where to pick the environment. You can force ENV_EVERYWHERE for those architectures, you can decide to change the switch as I said, or you can add in your board and override

I will send a patch based on your suggestion, thanks.

#15 lore raw

Re: [PATCH 2/2] imx8mn/8mp: Select ENV_IS_NOWHERE

In reply to Fabio Estevam
Quoted 10 lines · Fabio Estevam

Hi Marek,

Quoted 2 lines · Marek Vasut

Did you actually hit the USB_BOOT case or did you fall into the default:
case ?

It does hit the USB_BOOT case.

I also tested forcing to return ENVL_UNKNOWN:

Hum, sigh.

Can you check where exactly this hangs ? I speculate env_select() in env/env.c returns -ENODEV and then whatever calls env_select() ends up in hang(), no ?