3.1.1.5. SD, eMMC and USB
The following guide shows how to flash and boot from storage media like the embedded multimedia card (eMMC), secure digital (SD) card, and USB storage devices. While this is a step-by-step guide, it is in no way extensive and does not cover all the per-platform corner-cases. For any issues/questions on this guide, please reach out to: Help e2e.
3.1.1.5.1. MMC
3.1.1.5.1.1. Listing MMC devices
Usually in all the platforms there will be two MMC instances of which one would be SD and the other would be eMMC. The device index of them can vary from one class of platforms to the other. For a given platform, the device index can be found in the following way:
=> mmc list
sdhci@fa10000: 0 (eMMC)
sdhci@fa00000: 1 (SD)
The device index “0” for eMMC will be used when flashing to the eMMC device here using mmc dev command.
In u-boot environment, usually mmcdev=n is used to selct which MMC device to boot Linux from, where n is the device index.
3.1.1.5.1.2. MMC HW partitions
This sections includes a summary of MMC hardware partitions.
eMMC
Normally eMMC is divided into 4 areas (aka HW partitions):
UDA (User Data Area): Used to store user data such as a file system. This partition can divided into disk partitions
Boot0/1: Used to store firmware and data needed during boot
RPMB (Replay-protected memory-block area): Used to store secure data
SD
SD card memory is not divided into sections like eMMC, but acts like UDA in eMMC where user can create disk partitions in software allowing to divide the storage space into multiple sections.
3.1.1.5.1.3. Selecting MMC device and partitions
To selct an MMC device in u-boot, the command: mmc dev could be used. The general syntax is:
=> mmc dev [dev] [partition]
Where [dev] is the MMC device index.
The following lists examples and their explanation for each MMC device and partitions according to the example here.
=> mmc dev 0 0 # select eMMC UDA
=> mmc dev 0 1 # select eMMC Boot0
=> mmc dev 0 2 # select eMMC Boot1
=> mmc dev 1 # select SD
3.1.1.5.1.4. View MMC partition contents
This section assumes an SD card or eMMC was prepared previously to boot the device.
Note
For eMMC, typically, the device ships without a partition table If there is a need to create a partition in UDA, please go here and to format the partition go here before proceeding.
To list disk partitions for any MMC device from u-boot prompt, use the command: mmc part.
=> mmc dev 0
switch to partitions #0, OK
mmc0(part 0) is current device
=> mmc part
Partition Map for MMC device 0 -- Partition Type: DOS
Part Start Sector Num Sectors UUID Type
1 2048 31078400 8ece5cfe-01 83
If the partitions are formatted with a file system type that is supported by u-boot, you can view the contents of the MMC partition as show below:
=> ls mmc 0:1
<DIR> 4096 .
<DIR> 4096 ..
<SYM> 7 bin
<DIR> 4096 boot
<DIR> 4096 dev
<DIR> 4096 etc
<DIR> 4096 home
<SYM> 7 lib
<DIR> 4096 media
<DIR> 4096 mnt
<DIR> 4096 opt
<DIR> 4096 proc
<DIR> 4096 root
<DIR> 4096 run
<SYM> 8 sbin
<DIR> 4096 srv
<DIR> 4096 sys
<DIR> 4096 tmp
<DIR> 4096 usr
<DIR> 4096 var
=> ls mmc 0:1 boot/dtb/ti
<DIR> 4096 .
<DIR> 4096 ..
60319 k3-am625-sk.dtb
Where the general syntax is:
$ ls <interface> [<dev[:partition]> [directory]]
3.1.1.5.1.5. MMC supported bootmodes
The K3 based processors support and recommends using eMMC boot from Boot0/1. For complete
information on the MMC bootmodes supported by ROM, please refer to the device specific TRM,
under: Initialization/Boot Mode Pins
. ROM supports the following two MMC bootmodes:
eMMC boot
This bootmode is a special bootmode specific to eMMC device. In this bootmode, ROM cannot boot from SD and can only boot from Boot0 or Boot1 in eMMC. Please go here for a step-by-step guide to boot with this bootmode.
MMCSD boot
This bootmode allows to boot from either eMMC or SD device. With this bootmode, ROM can only boot from SD card or UDA in eMMC. ROM allows to boot in RAW or FS mode, FS mode being the recommended option and hence will have a subsequent guide to boot using this mode. Configuration for selecting MMC device and RAW/FS mode, is done with bootmode pins, please refer to TRM for this setup. To boot from eMMC UDA in FS mode, please go here.
3.1.1.5.1.6. Flashing an MMC device using USB-DFU
To flash the eMMC device (Boot0) using USB-DFU, the device should be booted to u-boot prompt and a USB cable connected from the host machine to the device USB port configured to USB peripheral mode.
From u-boot prompt execute the following:
=> setenv dfu_alt_info ${dfu_alt_info_emmc}
=> dfu 0 mmc 0
This comands assumes eMMC device exists and is mmc device 0.
On the host machine have the bootloader binaries ready to flash to eMMC Boot0. Execute the dfu-util to transfer files to the device. The general syntax for dfu-util command is:
$ sudo dfu-util -R -a <dfu-target> -D <binary>
To see what are the dfu-targets, on the host machine run: sudo dfu-util -l
$ sudo dfu-util -l
dfu-util 0.9
Found DFU: [0451:6165] ver=0223, devnum=32, cfg=1, intf=0, path="1-10", alt=6, name="sysfw.itb.raw", serial="0000000000000591"
Found DFU: [0451:6165] ver=0223, devnum=32, cfg=1, intf=0, path="1-10", alt=5, name="u-env.raw", serial="0000000000000591"
Found DFU: [0451:6165] ver=0223, devnum=32, cfg=1, intf=0, path="1-10", alt=4, name="u-boot.img.raw", serial="0000000000000591"
Found DFU: [0451:6165] ver=0223, devnum=32, cfg=1, intf=0, path="1-10", alt=3, name="tispl.bin.raw", serial="0000000000000591"
Found DFU: [0451:6165] ver=0223, devnum=32, cfg=1, intf=0, path="1-10", alt=2, name="tiboot3.bin.raw", serial="0000000000000591"
Found DFU: [0451:6165] ver=0223, devnum=32, cfg=1, intf=0, path="1-10", alt=1, name="rootfs", serial="0000000000000591"
Found DFU: [0451:6165] ver=0223, devnum=32, cfg=1, intf=0, path="1-10", alt=0, name="rawemmc", serial="0000000000000591"
Then transfer each desired binary from the host to the device:
Host:
$ sudo dfu-util -R -a tiboot3.bin.raw -D tiboot3.bin $ sudo dfu-util -R -a tispl.bin.raw -D tispl.bin $ sudo dfu-util -R -a u-boot.img.raw -D u-boot.img
Device:
##DOWNLOAD ... OK Ctrl+C to exit ... ##DOWNLOAD ... OK Ctrl+C to exit ... ##DOWNLOAD ... OK Ctrl+C to exit ...
3.1.1.5.1.7. Flashing an SD card from a host PC
This section assumes that you have flashed an SD card using the script “create-sdcard.sh” packaged in the installer or have made a compatible layout manually. In this case, you will need to copy the boot images:
tiboot3.bin
tispl.bin
u-boot.img
to the SD card boot partition. At this point, the device can boot to u-boot prompt.
3.1.1.5.2. USB
3.1.1.5.2.1. Configuring USB in Host Mode
Configuring USB in host mode documentation is pending for AM67 please reach out to: Help e2e for additional information.
3.1.1.5.2.2. Flash and boot SPL from USB storage
Booting to U-Boot prompt from USB storage is supported. The following are the steps to be followed:
In U-Boot the USB controller can be used in either host or peripheral mode. For booting to linux kernel from USB storage device, the USB port should be in host mode.
By default, USB0 is set to peripheral mode. Change this from peripheral to host mode.
Build the bootloader images using the default “j722s_evm_r5_defconfig” and the config fragment “j722s_evm_r5_usbmsc.config” and “j722s_evm_a53_defconfig” configs files. The configs required for USB MSC boot are already enabled. For instructions to build the bootloader images please refer to Build U-Boot.
Create a FAT32 partition with boot flag enabled on the USB storage device.
Copy the bootloader images(tiboot3.bin, tispl.bin, u-boot.img) into the above created partition.
Set the boot mode switches to USB host boot mode (Refer to the Initialization chapter of TRM for boot switch details)
Make sure USB0 port in DRP mode: SW2[2:3] = 00
Connect the USB Mass storage device with the bootloader images and boot up the board.
Note
While using usb reset
or usb start
commands in U-Boot, or
booting from a USB Mass storage device, some of the USB devices fail to get
detected. This issue is seen because these USB devices are failing to follow the
spec for power good delay. It can be resolved by overriding the power good delay
using the environment variable usb_pgood_delay, setting it to 2000 should be
good enough for all cases.
3.1.1.5.2.3. Boot Linux from USB storage
To load the Linux kernel, Device Tree and the root file system from USB mass storage device, the following changes are required to be done:
U-Boot
In U-Boot, the USB controller can be used in either host or peripheral mode. For booting to linux prompt. For USB storage device, the USB port has to be set as host. By default, USB0 is set to peripheral mode. Change this from peripheral to host mode in u-boot DT.
Linux
In Linux, by default the USB subsystem is built as modules. For booting from USB mass storage device, the USB subsytem is required to be built into the image. This can be done by making the following changes in the configuration used for building kernel:
CONFIG_USB_COMMON=y CONFIG_USB=y CONFIG_USB_XHCI_HCD=y CONFIG_USB_XHCI_PCI=y CONFIG_USB_XHCI_PLATFORM=y CONFIG_USB_STORAGE=y CONFIG_USB_DWC3=y CONFIG_USB_DWC3_AM62=y CONFIG_USB_GADGET=y CONFIG_TYPEC=y CONFIG_TYPEC_TPS6598X=y CONFIG_USB_ROLE_SWITCH=y
Copying the images to USB storage device
After making the required changes mentioned above, build the kernel, device tree file and modules. The USB Mass storage device should have the rootfs in the second partition with ext4 file system. The following images should be in /boot/ directory:
Linux kernel Image
Device tree (dtb) file
Run usb_boot
During the boot, cancel the autoboot at U-Boot and run the following command at u-boot prompt:
=> run usb_boot
3.1.1.5.2.4. Steps for working around SD card issues in u-boot
In some cases, issues can be seen while using some SD cards, like:
Error while trying to initialize:
U-Boot SPL 2021.01-g74fc69c889 (May 19 2022 - 02:44:29 +0000) SYSFW ABI: 3.1 (firmware rev 0x0008 '8.3.2--v08.03.02 (Jolly Jellyfi') Trying to boot from MMC2 spl: mmc init failed with error: -110 SPL: failed to boot from all boot devices ### ERROR ### Please RESET the board ###
Given below are the list of various workarounds that can be done in the device tree MMC node to get SD card working. The workarounds are ordered in increasing order of reducing performance.
Note
All the mentioned below, are to be done in the MMC device tree node corresponding to the SD instance. This is usually the first (index starting from zero) instance.
Restricting to a given speed mode
By default the U-Boot driver tries to enumerate a SD card in the highest supported speed mode. Given below is the order in which the driver tries to enumerate a SD card:
SDR104
SDR50
DDR50
SD HS
SD legacy
The sdhci-caps-mask can be added to the DT node to cap at a specific mode:
Limit to DDR50:
sdhci-caps-mask = <0x00000003 0x00000000>
Limit to SD HS:
sdhci-caps-mask = <0x00000007 0x00000000>
Limit to SD legacy:
sdhci-caps-mask = <0x00000007 0x00200000>
&sdhci1 { /* SD/MMC */ vmmc-supply = <&vdd_mmc1>; vqmmc-supply = <&vdd_sd_dv>; pinctrl-names = "default"; pinctrl-0 = <&main_mmc1_pins_default>; ti,driver-strength-ohm = <50>; disable-wp; sdhci-caps-mask = <0x00000003 0x00000000>; /* Limiting to DDR50 speed mode */ };
Increase power cycle period
Increasing the delay while power cycling the SD card. This can be done by increasing the delay value in the diff indicated below,
diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index f486e2a2c364..38cc956b3d53 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c @@ -2761,7 +2761,7 @@ static int mmc_power_cycle(struct mmc *mmc) * SD spec recommends at least 1ms of delay. Let's wait for 2ms * to be on the safer side. */ - udelay(2000); + udelay(4000); return mmc_power_on(mmc); }
Reduce the bus width
The SD interface supports a bus width of 4. It can be reduced to 1 by changing the bus-width device tree property from 4 to 1.
diff --git a/arch/arm/dts/k3-am62-main.dtsi b/arch/arm/dts/k3-am62-main.dtsi index c06ec7355035..4ab29b6aa4b7 100644 --- a/arch/arm/dts/k3-am62-main.dtsi +++ b/arch/arm/dts/k3-am62-main.dtsi @@ -373,7 +373,7 @@ ti,itap-del-sel-sdr12 = <0x0>; ti,itap-del-sel-sdr25 = <0x0>; ti,clkbuf-sel = <0x7>; - bus-width = <4>; + bus-width = <1>; }; sdhci2: mmc@fa20000 {
3.1.1.5.2.5. eMMC HS400 support in u-boot
eMMC HS400 is not suppported, refer to this table for the list of modes supported in u-boot for J722S SoC.