How to manually update bootloaders

Revision as of 15:19, 17 June 2021 by Patrick Delaunay (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This page explains how to manually update the bootloaders binary (including U-Boot and TF-A) on an SD card or on the e•MMC.

1 To update an SD card with the Linux dd command[edit]

When a Linux console has access to the SD card device partitions:

  • on a Linux PC
    • with a card reader of this PC
    • through a USB connection to the target and the ums command executed on a U-Boot console
  • on target, with Linux console.

The 3 first GPT partitions on the SD card are:

  1. FSBL1
  2. FSBL2
  3. FIP

See Boot_chain_overview for the bootloader definitions.

You can use the Linux dd command to copy the FSBL and SSBL directly to the correct partition:

 PC $>  dd if=<file> of=/dev/<dev> conv=fdatasync

<dev> is:

  • mmcblk<X>p<n>: PC-embedded card reader case or target Linux console
  • sd<X><n>: USB-connected SD card reader case

where <X> is the ID of the device, and <n> the ID of the partition.

Note: the dd option conv=fdatasync is used to force synchronous copying.

1.1 U-Boot environment[edit]

The U-Boot environment is saved at the end of the U-Boot partition, named "fip": ID = 3.

To clear this environment, erase the U-Boot partition before any update; for example, by writing 0 to this partition:

 PC $>  dd if=/dev/zero of=/dev/mmcblk<X>p3 conv=fdatasync
 PC $>  dd if=/dev/zero of=sd<X>3 conv=fdatasync

1.2 SD card update example[edit]

The internal card reader is /dev/mmcblk0 or for a target Linux console, GPT partition <n> is /dev/mmcblk0p<n>:

 PC $> dd if=tf-a-sdcard.stm32 of=/dev/mmcblk0p1 conv=fdatasync
 PC $> dd if=tf-a-sdcard.stm32 of=/dev/mmcblk0p2 conv=fdatasync
 PC $> dd if=/dev/zero of=/dev/mmcblk0p3 conv=fdatasync
 PC $> dd if=fip.bin of=/dev/mmcblk0p3 conv=fdatasync

Alternatively, with U-Boot console, dev = 0 (SD card device on ST Microelectronics board), GPT partition <n> is /dev/sda<n>:

 Board $> mmc dev 0 
 Board $> ums 0 mmc 0
 PC $> dd if=tf-a-sdcard.stm32 of=/dev/sda1 conv=fdatasync
 PC $> dd if=tf-a-sdcard.stm32 of=/dev/sda2 conv=fdatasync
 PC $> dd if=/dev/zero of=/dev/sda3 conv=fdatasync
 PC $> dd if=fip.bin of=/dev/sda3 conv=fdatasync

1.3 SD card update example with SPL as FSBL[edit]

The USB card reader is /dev/sdb, GPT partition <n> is /dev/sdb<n>:

 PC $> dd if=u-boot-spl.stm32 of=/dev/sdb1 conv=fdatasync
 PC $> dd if=u-boot-spl.stm32 of=/dev/sdb2 conv=fdatasync
 PC $> dd if=/dev/zero of=/dev/sdb3 conv=fdatasync
 PC $> dd if=u-boot.img of=/dev/sdb3 conv=fdatasync

2 Update of e•MMC with the Linux dd command[edit]

The same command, dd, can be used to update e•MMC memory mapping:

  • SSBL U-Boot is the first GPT partition in the e•MMC user area
  • FSBL = TF-A (or SPL) is saved at the beginning of the e•MMC boot partition

The user needs to select the e•MMC hardware partition to update: user data, boot1, or boot2.

2.1 On a Linux console[edit]

If dev = mmcblk1 for e•MMC device (default on ST Microelectronics board)

The boot partitions are available in /dev/mmcblk1boot0 and /dev/mmcblk1boot1 [1].

The user perhaps needs to allow access, for example with:

 Board $>  echo 0 > /sys/class/block/mmcblk1boot0/force_ro

The mmc tools allow the boot partition to be selected [2].

The STM32MP15x ROM code requires:

  • <send_ack> =1
  • the eMMC boot configuration is: 1 wire configuration and 25 MHz, it is done with the command:
 Board $>  mmc bootbus set  single_backward x1 x1 dev/mmcblk1

To update TF-A in boot1 and select this boot partition:

 Board $> dd if=tf-a-emmc.stm32 of=/dev/mmcblk1boot0 conv=fdatasync
 Board $> mmc bootpart enable 1 1 /dev/mmcblk1

To update TF-A in boot2 and select this boot partition:

 Board $> dd if=tf-a-emmc.stm32 of=/dev/mmcblk1boot1 conv=fdatasync
 Board $> mmc bootpart enable 2 1 /dev/mmcblk1

To update U-Boot in the first GPT partition:

 Board $> dd if=/dev/zero of=/dev/mmcblk1p1 conv=fdatasync
 Board $> dd if=fip.bin of=/dev/mmcblk1p1 conv=fdatasync

See also [3].

2.2 On a U-Boot console[edit]

Before the first boot, select the e•MMC correct boot configuration (1 wire, 25 MHz) with the command:

 Board $> mmc bootbus 1 0 0 0

2.2.1 mmc partconf[edit]

The targeted e•MMC HW partition is selected in U-Boot by the command mmc partconf:

 Board $>  help mmc 
 mmc bootbus dev boot_bus_width reset_boot_bus_width boot_mode
- Set the BOOT_BUS_WIDTH field of the specified device
 mmc bootpart-resize <dev> <boot part size MB> <RPMB part size MB>
- Change sizes of boot and RPMB partitions of specified device
 mmc partconf dev [boot_ack boot_partition partition_access]
- Show or change the bits of the PARTITION_CONFIG field of the specified device

For example:

* dev = 1 (e•MMC device on ST Microelectronics board)
* boot_ack=1 (Boot Acknowledge is needed by ROM code) 
* boot_partition = 1 (Boot partition 1 enabled for boot)
* partition_access =  0 (user data partition - default)  

The command to select the boot partition used by ROM code on e•MMC at next reboot is:

  • for boot1:
 Board $> mmc partconf 1 1 1 0
  • for boot2:
 Board $> mmc partconf 1 1 2 0

Don't change the last parameter partition_access value if you don't manually access to the boot partition content with mmc read or mmc write:

  • 0: user data partition (default)
  • 1: boot partition 1
  • 2: boot partition 2

2.2.2 ums[edit]

The e•MMC update is done with the ums command, with the U-Boot's partition syntax[4]:

 <command> <interface> [devnum][.hwpartnum][:partnum|#partname]

The exported e•MMC is mounted on the Linux PC as a block device named sd<X> and the GPT partitions are exported by sd<X><n> where <X> is the ID of the device starting at a and <n> the ID of the partition.

In the next example we assume <X> = a, so the block device e•MMC available in /dev/sda but this value need to be verified on your PC.

boot partitions

To update FSBL=TF-A in the boot1 HW partition.

 Board $> ums 0 mmc 1.1
 UMS: LUN 0, dev 1, hwpart 1, sector 0x0, count 0x1000

On boot partitions, without GPT partitions, just copy TF-A binary on the block device /dev/sda exported by U-Boot.

 PC $> dd if=tf-a-emmc.stm32 of=/dev/sda  conv=fdatasync

For boot2, change the mmc device to 1.2.

user data partition

To export all the e•MMC in /dev/sda, including all GPT partitions in /dev/sdaN:

 Board $> ums 0 mmc 1

And copy the FIP binary in the first partition of this block device:

 PC $> dd if=fip.bin of=/dev/sda1 conv=fdatasync

You can also export only the first GPT partition ("fip" partition index is 1) in /dev/sda:

 Board $> ums 0 mmc 1:1 
 PC $> dd if=fip.bin of=/dev/sda conv=fdatasync

3 References[edit]

Please refer to the following links for additional information: