Last edited 2 months ago

How to populate the SD card with dd command

Applicable for STM32MP13x lines, STM32MP15x lines, STM32MP21x lines, STM32MP23x lines, STM32MP25x lines


1. Introduction[edit | edit source]

STMicroelectronics delivers also a script runing on Linux host PC to populate ONLY the microSD card device.

This script is located here : build-<DISTRO>-<MACHINE>/tmp-glibc/deploy/images/<MACHINE>/scripts/
(Refer to OpenSTLinux_distribution article for MACHINE / DISTRO available values)

This script is also located in the Starter Package/<VERSION>/ images/<MACHINE>/scripts.

This script, as STM32CubeProgrammer tool, is using Flashlayout.tsv file in input parameter
This script creates a raw file <FlashLayoutName>.raw and a txt file <FlashLayoutName>.how_to_update.txt
Then you can use this raw file to populate your microSD card inserted on your HOST PC

2. Usage[edit | edit source]

cd build-<DISTRO>-<MACHINE>/tmp-glibc/deploy/images/<MACHINE>/scripts
./create_sdcard_from_flashlayout.sh ../flashlayout_<built-image>/<FlashLayout file>

Example :

PC $> cd build-openstlinuxweston-stm32mp2/tmp-glibc/deploy/images/stm32mp2
PC $> ./scripts/create_sdcard_from_flashlayout.sh flashlayout_st-image-weston/optee/FlashLayout_sdcard_stm32mp257f-ev1-optee.tsv 
Create Raw empty image: flashlayout_st-image-weston/optee/../../FlashLayout_sdcard_stm32mp257f-ev1-optee.raw of 5120MB
Create partition table:
[CREATED] part 01:     fsbla1 [partition size 256.0 KiB]
[CREATED] part 02:     fsbla2 [partition size 256.0 KiB]
[CREATED] part 03:  metadata1 [partition size 256.0 KiB]
[CREATED] part 04:  metadata2 [partition size 256.0 KiB]
[CREATED] part 05:      fip-a [partition size 4.0 MiB]
[CREATED] part 06:      fip-b [partition size 4.0 MiB]
[CREATED] part 07: u-boot-env [partition size 512.0 KiB]
[CREATED] part 08:     bootfs [partition size 64.0 MiB]
[CREATED] part 09:   vendorfs [partition size 250.0 MiB]
[CREATED] part 10:     rootfs [partition size 4.0 GiB]
[CREATED] part 11:     userfs [partition size 700.5 MiB]

Partition table from flashlayout_st-image-weston/optee/../../FlashLayout_sdcard_stm32mp257f-ev1-optee.raw
Disk flashlayout_st-image-weston/optee/../../FlashLayout_sdcard_stm32mp257f-ev1-optee.raw: 10485760 sectors, 5.0 GiB
Sector size (logical): 512 bytes
Disk identifier (GUID): DF8ECD0B-FD58-432F-8BEB-10325DFBAFF8
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 10485726
Partitions will be aligned on 2-sector boundaries
Total free space is 0 sectors (0 bytes)

Number  Start (sector)    End (sector)  Size       Code  Name
   1              34             545   256.0 KiB   8301  fsbla1
   2             546            1057   256.0 KiB   8301  fsbla2
   3            1058            1569   256.0 KiB   FFFF  metadata1
   4            1570            2081   256.0 KiB   FFFF  metadata2
   5            2082           10273   4.0 MiB     FFFF  fip-a
   6           10274           18465   4.0 MiB     FFFF  fip-b
   7           18466           19489   512.0 KiB   B000  u-boot-env
   8           19490          150561   64.0 MiB    8300  bootfs
   9          150562          662561   250.0 MiB   8300  vendorfs
  10          662562         9051169   4.0 GiB     8300  rootfs
  11         9051170        10485726   700.5 MiB   8300  userfs

Partition GUID code: 19D5DF83-11B0-457B-BE2C-7559C13142A5 (Unknown)
Partition unique GUID: 4FD84C93-54EF-463F-A7EF-AE25FF887087
First sector: 2082 (at 1.0 MiB)
Last sector: 10273 (at 5.0 MiB)
Partition size: 8192 sectors (4.0 MiB)
Attribute flags: 0000000000000000
Partition name: 'fip-a'

Partition GUID code: 19D5DF83-11B0-457B-BE2C-7559C13142A5 (Unknown)
Partition unique GUID: 09C54952-D5BF-45AF-ACEE-335303766FB3
First sector: 10274 (at 5.0 MiB)
Last sector: 18465 (at 9.0 MiB)
Partition size: 8192 sectors (4.0 MiB)
Attribute flags: 0000000000000000
Partition name: 'fip-b'

Partition GUID code: 0FC63DAF-8483-4772-8E79-3D69D8477DE4 (Linux filesystem)
Partition unique GUID: E91C4E10-16E6-4C0E-BD0E-77BECF4A3582
First sector: 662562 (at 323.5 MiB)
Last sector: 9051169 (at 4.3 GiB)
Partition size: 8388608 sectors (4.0 GiB)
Attribute flags: 0000000000000000
Partition name: 'rootfs'

Populate raw image with image content:
[ FILLED ] part 01:     fsbla1, image: arm-trusted-firmware/tf-a-stm32mp257f-ev1-optee-sdcard.stm32 
[ FILLED ] part 02:     fsbla2, image: arm-trusted-firmware/tf-a-stm32mp257f-ev1-optee-sdcard.stm32 
[ FILLED ] part 03:  metadata1, image: arm-trusted-firmware/metadata.bin 
[ FILLED ] part 04:  metadata2, image: arm-trusted-firmware/metadata.bin 
[ FILLED ] part 05:      fip-a, image: fip/fip-stm32mp257f-ev1-optee-sdcard.bin 
[ FILLED ] part 08:     bootfs, image: st-image-bootfs-openstlinux-weston-stm32mp2.bootfs.ext4 
[ FILLED ] part 09:   vendorfs, image: st-image-vendorfs-openstlinux-weston-stm32mp2.vendorfs.ext4 
[ FILLED ] part 10:     rootfs, image: st-image-weston-openstlinux-weston-stm32mp2.rootfs.ext4 
[ FILLED ] part 11:     userfs, image: st-image-userfs-openstlinux-weston-stm32mp2.userfs.ext4 

###########################################################################
###########################################################################

RAW IMAGE generated: flashlayout_st-image-weston/optee/../../FlashLayout_sdcard_stm32mp257f-ev1-optee.raw

WARNING: before to use the command dd, please umount all the partitions
	associated to SDCARD.
    sudo umount `lsblk --list | grep mmcblk0 | grep part | gawk '{ print $7 }' | tr '\n' ' '`

To put this raw image on sdcard:
    sudo dd if=flashlayout_st-image-weston/optee/../../FlashLayout_sdcard_stm32mp257f-ev1-optee.raw of=/dev/mmcblk0 bs=8M conv=fdatasync status=progress

(mmcblk0 can be replaced by:
     sdX if it's a device dedicated to receive the raw image 
          (where X can be a, b, c, d, e)

To mount bootfs partition:
     udisksctl mount -b /dev/disk/by-partlabel/bootfs

After the dd command you can verify if copy are correctly done and partitions take into account
     sgdisk /dev/mmcblk0 -p
     sgdisk /dev/mmcblk0 -v
if '-v' command indicate a problem, please execute the following command:
     sgdisk /dev/mmcblk0 -e

###########################################################################
###########################################################################

3. Populate the microSD card inserted on your linux host PC with the created raw file[edit | edit source]

You need first to retrieve the volume name of your drive (USB Key or MMC card)


To connect a USB device to the virtual machine manually, select VM > Removable Devices > Device Name > Connect (Disconnect from host)

More explanations for this specific case here


Insert your drive then use the following command :

  • In this example, the volume name is sdd (microSD card is inserted with USB key)
PC $> cat /proc/partitions 
major minor  #blocks  name

   8        0  488386584 sda
   8        1     999424 sda1
   8        2          1 sda2
   8        5  487384064 sda5
  11        0    1048575 sr0
252        0  487382016 dm-0
252        1   19996672 dm-1
252        2    8335360 dm-2
252        3  459046912 dm-3
   8       48    1921024 sdd
  • In this example, the volume name is mmcblk0 (microSD card is inserted directly with microSD card adapter)
PC $> cat /proc/partitions 
major minor  #blocks  name

   8        0  488386584 sda
   8        1     999424 sda1
   8        2          1 sda2
   8        5  487384064 sda5
  11        0    1048575 sr0
252        0  487382016 dm-0
252        1   19996672 dm-1
252        2    8335360 dm-2
252        3  459046912 dm-3
   8       48    1921024 mmcblk0


Info white.png Information
mmcblk0 can be replaced by: sdX if it's a device dedicated to receive the raw image (where X can be a, b, c, d, e)
  • Before using the command dd, please umount all the partitions associated to microSD card
Example:
sudo umount `lsblk --list | grep mmcblk0 | grep part | gawk '{ print $7 }' | tr '\n' ' '`
  • Populate microSD card with dd command
Example:
cd build-openstlinuxweston-stm32mp2/tmp-glibc/deploy/images/stm32mp2

sudo dd if=FlashLayout_sdcard_stm32mp257f-ev1-optee.raw of=/dev/mmcblk0 bs=8M conv=fdatasync status=progress

The dd command takes few minutes (depending mainly of your rootfs size)

4. Update manually some partitions with dd command[edit | edit source]

Once you have populated your microSD card with the raw file, it is possible to update manually some partitions as explained in txt file.

Example :

PC $> cat FlashLayout_sdcard_stm32mp257f-ev1-optee.how_to_update.txt
This file describe How to update manually the partition of SDCARD:
1. SDCARD schema of partition
2. How to populate each partition
3. How to update the kernel/devicetree

1. SDCARD schema of partition:
------------------------------

===========================================================================================================================================================
=             =             =             =             =             =             =             =             =             =             =             =
=     fsbla1  =     fsbla2  =  metadata1  =  metadata2  =      fip-a  =      fip-b  =  u-boot-env  =     bootfs  =   vendorfs  =     rootfs  =     userfs  =
=             =             =             =             =             =             =             =             =             =             =             =
=  mmcblk0p1  =  mmcblk0p2  =  mmcblk0p3  =  mmcblk0p4  =  mmcblk0p5  =  mmcblk0p6  =  mmcblk0p7  =  mmcblk0p8  =  mmcblk0p9  =  mmcblk0p10 =  mmcblk0p11 =
=      (1 )   =      (2 )   =      (3 )   =      (4 )   =      (5 )   =      (6 )   =      (7 )   =      (8 )   =      (9 )   =      (10)   =      (11)   =
=             =             =             =             =             =             =             =             =             =             =             =
===========================================================================================================================================================
(1):
    Device: /dev/mmcblk0p1
    Label:  fsbla1
    Image:  arm-trusted-firmware/tf-a-stm32mp257f-ev1-optee-sdcard.stm32
(2):
    Device: /dev/mmcblk0p2
    Label:  fsbla2
    Image:  arm-trusted-firmware/tf-a-stm32mp257f-ev1-optee-sdcard.stm32
(3):
    Device: /dev/mmcblk0p3
    Label:  metadata1
    Image:  arm-trusted-firmware/metadata.bin
(4):
    Device: /dev/mmcblk0p4
    Label:  metadata2
    Image:  arm-trusted-firmware/metadata.bin
(5):
    Device: /dev/mmcblk0p5
    Label:  fip-a
    Image:  fip/fip-stm32mp257f-ev1-optee-sdcard.bin
(6):
    Device: /dev/mmcblk0p6
    Label:  fip-b
    Image:  none
(7):
    Device: /dev/mmcblk0p7
    Label:  u-boot-env
    Image:  none
(8):
    Device: /dev/mmcblk0p8
    Label:  bootfs
    Image:  st-image-bootfs-openstlinux-weston-stm32mp2.bootfs.ext4
(9):
    Device: /dev/mmcblk0p9
    Label:  vendorfs
    Image:  st-image-vendorfs-openstlinux-weston-stm32mp2.vendorfs.ext4
(10):
    Device: /dev/mmcblk0p10
    Label:  rootfs
    Image:  st-image-weston-openstlinux-weston-stm32mp2.rootfs.ext4
(11):
    Device: /dev/mmcblk0p11
    Label:  userfs
    Image:  st-image-userfs-openstlinux-weston-stm32mp2.userfs.ext4

2. How to populate each partition
---------------------------------
- Populate partition fsbla1 (/dev/mmcblk0p1)
    dd if=arm-trusted-firmware/tf-a-stm32mp257f-ev1-optee-sdcard.stm32 of=/dev/mmcblk0p1 bs=1M conv=fdatasync status=progress

- Populate partition fsbla2 (/dev/mmcblk0p2)
    dd if=arm-trusted-firmware/tf-a-stm32mp257f-ev1-optee-sdcard.stm32 of=/dev/mmcblk0p2 bs=1M conv=fdatasync status=progress

- Populate partition metadata1 (/dev/mmcblk0p3)
    dd if=arm-trusted-firmware/metadata.bin of=/dev/mmcblk0p3 bs=1M conv=fdatasync status=progress

- Populate partition metadata2 (/dev/mmcblk0p4)
    dd if=arm-trusted-firmware/metadata.bin of=/dev/mmcblk0p4 bs=1M conv=fdatasync status=progress

- Populate partition fip-a (/dev/mmcblk0p5)
    dd if=fip/fip-stm32mp257f-ev1-optee-sdcard.bin of=/dev/mmcblk0p5 bs=1M conv=fdatasync status=progress

- Populate partition fip-b (/dev/mmcblk0p6)
    dd if=none of=/dev/mmcblk0p6 bs=1M conv=fdatasync status=progress

- Populate partition u-boot-env (/dev/mmcblk0p7)
    dd if=none of=/dev/mmcblk0p7 bs=1M conv=fdatasync status=progress

- Populate partition bootfs (/dev/mmcblk0p8)
    dd if=st-image-bootfs-openstlinux-weston-stm32mp2.bootfs.ext4 of=/dev/mmcblk0p8 bs=1M conv=fdatasync status=progress

- Populate partition vendorfs (/dev/mmcblk0p9)
    dd if=st-image-vendorfs-openstlinux-weston-stm32mp2.vendorfs.ext4 of=/dev/mmcblk0p9 bs=1M conv=fdatasync status=progress

- Populate partition rootfs (/dev/mmcblk0p10)
    dd if=st-image-weston-openstlinux-weston-stm32mp2.rootfs.ext4 of=/dev/mmcblk0p10 bs=1M conv=fdatasync status=progress

- Populate partition userfs (/dev/mmcblk0p11)
    dd if=st-image-userfs-openstlinux-weston-stm32mp2.userfs.ext4 of=/dev/mmcblk0p11 bs=1M conv=fdatasync status=progress


3. How to mount manually each partition
---------------------------------
- Mount manually partition bootfs (/dev/mmcblk0p8)
    udiskctl mount -b /dev/disk/by-partlabel/bootfs

- Mount manually partition vendorfs (/dev/mmcblk0p9)
    udiskctl mount -b /dev/disk/by-partlabel/vendorfs

- Mount manually partition rootfs (/dev/mmcblk0p10)
    udiskctl mount -b /dev/disk/by-partlabel/rootfs

- Mount manually partition userfs (/dev/mmcblk0p11)
    udiskctl mount -b /dev/disk/by-partlabel/userfs


4. How to update the kernel/devicetree
--------------------------------------
The kernel and devicetree are present on "boot" partition.
To change kernel and devicetree, you can copy the file on this partitions:
- plug SDCARD on your PC
- copy kernel uImage on SDCARD
   sudo cp uImage /media/$USER/bootfs/
- copy devicetree uImage on SDCARD
   sudo cp stm32mp1*.dtb /media/$USER/bootfs/
- umount partitions of SDCARD
   sudo umount /media/$USER/bootfs/
   (dont't forget to umount the other partitions of SDCARD:
   sudo umount `lsblk --list | grep mmcblk0 | grep part | gawk '{ print $7 }' | tr '\n' ' '`
   )