How to enable USB power with u-boot?

I’d like to use uboot’s USB subsystem to boot off a USB flash drive.
However, the USB power is disabled at boot/reset. When I provide external power everything works as expected,

So, how to enable USB power at CPU power-up/reset or with u-boot itself?
Thanks for advises!

Once you boot into "U-Boot" from the microSD/eMMC, load the files from
the USB flash drive and jump into that rootfs..

Regards,

That’s exactly what I do, it works fine, the problem is that the USB has no power at that time, I have to use an external power supply.

From this thread https://e2e.ti.com/support/arm/sitara_arm/f/791/t/270060:
Modifying bit 0 of 8 bit register address 0x47401C60 it switch on/off USB1_DRVVBUS pin

Is it possible to do from u-boot environment or I’ll need to modify u-boot source code?

But I don't think you have to do all that. Read my post from nearly 4 years
ago here: http://www.embeddedhobbyist.com/2013/07/beaglebone-black-usb-boot/

Scroll down where I talk about uEnv.txt. "usb start" should initiate power,
and the driver. Note that I'm calling it first before loading files over
USB. If you require in depth details, you'll have to read through the
source code. But I might be able to answer *some* questions. I'm by no
means a uboot expert.

Oh, thanks, William, I was inspired doing this by your post!

The problem is that “usb start” starts u-boot’s USB subsystem, it (probably) has nothing to do with the CPU.
You explicitly mentioned that used a USB HDD with external power supply, but I’m trying to boot off a USB flash drive. The CPU doesn’t provide USB power at early stage. If I provide power from an external source, everything works fine.

The latest u-boot supports loading overlays, I’m not sure whether it’s possible to load an overlays with the correct configuration of that pin and then load kernel and stuff from USB flash drive.

Oh, thanks, William, I was inspired doing this by your post!

Oh, cool ! Glad someone reads my stuff now and then :wink:

The problem is that "usb start" starts *u-boot*'s USB subsystem, it
(probably) has nothing to do with the CPU.
You explicitly mentioned that used a USB HDD with external power supply,
but I'm trying to boot off a USB flash drive. The CPU doesn't provide USB
power at early stage. If I provide power from an external source,
everything works fine.

Right so in that case, I explicitly mentioned using external power for a
hard drive. As many hard drives need at least 1-3A when spinning up, then
typically for a 3.5" HDD 1A after that. I just assumed that flash stick
would / should work, because most of them are pulling less than 500mA, or
is what I'd guess at any rate. However, you tested it seems, where I did
not.

The latest u-boot supports loading overlays, I'm not sure whether it's
possible to load an overlays with the correct configuration of that pin and
*then* load kernel and stuff from USB flash drive.

So I do not know all the specifics, and quite honestly Robert would
probably know better than I. But *maybe* there is a way you can create a
new overlay, based on the board file, to get the USB power up. A lot of
overlays are already set in the board file by default, or more specifically
references to hardware are in the board file, and in some cases all you
need to do is write an overlay that targets the hardware in question, and
provide status="okay". With that said. . . I'm not 100% sure how soon the
overlays get loaded. As in if they're actually loaded in uboot, or if
they're somehow loaded just prior, or simotaneously when the kernel is
loaded via cmdline options.

It's a really interesting problem to solve, one that I'd like to figure out
myself - even. If only I were not already busy with a ton of things at
work :confused: Which, yeah, I'll probably be spending part of my weekend doing too
. . .

Why not?

zImage:

"loadimage=load ${devtype} ${bootpart} ${loadaddr} ${bootdir}/${bootfile}\0" \

https://github.com/eewiki/u-boot-patches/blob/master/v2017.07-rc2/0001-am335x_evm-uEnv.txt-bootz-n-fixes.patch#L507

overlay:

"load ${devtype} ${bootpart} ${rdaddr} ${uboot_overlay}; " \

https://github.com/eewiki/u-boot-patches/blob/master/v2017.07-rc2/0002-U-Boot-BeagleBone-Cape-Manager.patch#L800

both use the devtype & bootpart references.. Thus if the kernel/dtb
are on the same partition of the usb flash drive as the overlays,
everything just works..

But, you'll need to add the usb options here:

https://github.com/eewiki/u-boot-patches/blob/master/v2017.07-rc2/0001-am335x_evm-uEnv.txt-bootz-n-fixes.patch#L277

Regards,

Thanks, Robert!

However, those “loads” just copy kernel/dtb into RAM for subsequent use, they are not going to change the CPU configuration at u-boot level. They cannot turn on the USB power until the control is passed to the kernel. That way works: I load kernel and dtbs from eMMC, but tell them “root=/dev/sda1 rootwait” (i.e. USB drive), so the kernel enables the USB power, then mount the USB stick. With this approach you cannot load a kernel from USB drive.

Then that’s a u-boot bug, usb should be on after USB start.

Most likely you’re right assuming that u-boot must be aware of what particular CPU it’s dealing with (otherwise it’s not possible since there is no standard API for such things as USB power).

Robert is right, it must be a u-boot bug, these treads below are evidences of a proper (more or less) work in the past, in particular, the register mentioned above, is defined.

http://u-boot.10912.n7.nabble.com/PATCH-v3-0-3-AM335x-Add-USB-support-in-u-boot-td127575.html
http://u-boot.10912.n7.nabble.com/USB-Host-not-enumerating-properly-on-AM335x-based-board-td196920.html

Since I’ll be traveling the next 10 days, will not be able to try different versions or look into u-boot’s code…
Will report the results later.

Exactly, ‘it’ knows… USB should be enabled and powered up by default for us… like I said… u-boot bug…

I’ve found the problem: the USB flash drive I used was USB-3!
Everything works as expected with USB-2 devices.