STM32CubeProgrammer flashlayout

Revision as of 13:43, 30 March 2022 by Registered User (→‎NOR Flash memory and SD card)
Applicable for STM32MP13x lines, STM32MP15x lines

1. Article purpose[edit source]

This article describes the FlashLayout file format.

This file is used as an input by STM32CubeProgrammer tool in order to:

  1. define the Flash memory partitions (see STM32_MPU_Flash_mapping)
  2. select the files used to boot (see Boot chain overview) and then populate each partition.

The embedded programming service processes this file on the device and interacts with STM32CubeProgrammer to update the Flash memory.
This is done by the stm32prog command in U-Boot. This command is automatically executed for a serial boot (bootcmd on USB or UART boot). However you can launch it manually from the U-Boot console: this is useful if you want to perform a non-virgin board update front of STM32CubeProgrammer, without manipulating the boot pins.

See AN5275: USB DFU/USART protocols used in STM32MP1 Series bootloaders for protocol details and refer to STM32CubeProgrammer article to know how to use this tool.

The next chapters:

The FSBL, SSBL definitions can be found in the Boot chain overview.

As explain in TF-A overview, the FIP file includes all the binaries loaded by FSBL=TF-A BL2:
SSBL=U-Boot, the non secure device tree, BL32 = OP-TEE or SP-MIN...

2. FlashLayout file format[edit source]

The FlashLayout is a text file with a tab-separated-value format (tsv). It includes the below elements:

The lines beginning with the '#' character are ignored and treated as comments.

The "Binary" last column is not used by U-Boot. It is used by STM32CubeProgrammer on the host computer to select the files to be sent to the target.

Several tabulations (<tab>) can be used to allow the correct column alignment in the editor. They are ignored by STM32CubeProgrammer and by U-Boot.

Empty fields are not allowed. The FlashLayout file format supports the none reserved word.

2.1. Examples[edit source]

Below some valid FlashLayout files:

#opt	Id	Name		Type		Device	Offset		Binary
-	0x01	fsbl-boot	Binary		none	0x00000000	tf-a-usb.stm32
-	0x03	fip-boot	FIP		none	0x00000000	fip.bin
P	0x04	fsbl1		Binary		mmc0	0x00004400	tf-a-sdcard.stm32
P	0x05	fsbl2		Binary		mmc0	0x00044400	tf-a-sdcard.stm32
P	0x06	metadata1	Binary		mmc0	0x00084400	metadata.bin
P	0x07	metadata2	Binary		mmc0	0x000C4400	metadata.bin
P	0x08	fip-a		FIP		mmc0	0x00104400	fip.bin
PED	0x09	fip-b		FIP		mmc0	0x00504400	none
PED	0x09	u-boot-env	binary		mmc0	0x00904400	none
P	0x10	bootfs		System		mmc0	0x00984400	bootfs.ext4
P	0x11	vendorfs	FileSystem	mmc0	0x04984400	vendorfs.ext4
P	0x12	rootfs		FileSystem	mmc0	0x05984400	rootfs.ext4
P	0x13	userfs		FileSystem	mmc0	0x33984400	userfs.ext4

Above, the first line contains only header information. This is not mandatory, as shown below:

-	0x01	fsbl_boot	Binary		none	0x0	tf-a-usb.stm32
-	0x03	fip_boot	FIP		none	0x0	fip.bin
P	0x10	sdcard		RawImage	mmc0	0x0	sdcard.bin

2.2. Field1: Options[edit source]

The Options field defines the operations to perform with a combination of characters: - P D E provided in any order;
First select the line of the FlashLayout with '-' or 'P':

  • '-' : none option, the partition or the device is not modified (mandatory if #Field5: Device = none)
  • 'P' : Program the partition or the device
U-Boot requests the binary to STM32CubeProgrammer and programs the partition or the Flash device.
On the block devices (SD card or eMMC), the GPT partitioning is performed if all partitions of the device are selected with P.
For the 'P' option, two optional modifiers can be added:
  • 'E' : Empty partition or device, update is not requested (associated "Id" is skipped)
  • 'D' : Delete partition or device

The only supported combinations are the following (with character in any order):

  • - : no action
  • P : update = program the partition or the flash device
  • PE : do not update (also EP) : allow the GPT partitioning with empty partition for the block device but equivalent to '-' for RAW flash device
  • PD : delete and update (also DP)
  • PDE : delete and keep empty (also PED / DPE / DEP / EPD / EDP)

All other combinations are invalid.

2.3. Field2: Id[edit source]

Id identifies in a unique way the "download phase" requested by the device to STM32CubeProgrammer.
It is used by the embedded programming service to identify the next binary that is downloaded to the device.

Their destination depends on the executed code:

  • ROM code and TF-A (FSBL): binary loaded in RAM, to start the embedded programming service
  • U-Boot(SSBL): the embedded programming service is running, the binary is populated in Flash memory by stm32prog command.

The FlashLayout supported ranges are :

Range Partition
0x01 to 0x0F Boot partitions
with FIP header: file containing SSBL
or with STM32 header: FSBL or other
or without header: metadata
0x10 to 0xF0 User partitions programmed without header (uimage, dtb, rootfs, vendorfs, userfs)

All the other values are forbidden in FlashLayout file.

The Id 0x01 and 0x03 are reserved for binaries containing FSBL and SSBL respectively; the presence of these two Id in the FlashLayout file is mandatory to load the embedded service.

2.3.1. Reserved Id[edit source]

The reserved and allowed values in FlashLayout file are the following:

Code Content Description
0x01 image containing FSBL loaded by ROM code in embedded RAM
0x03 image containing SSBL loaded by FSBL in external RAM for serial boot = FIP for OpenSTLinux

For information some other Id are reserved and used for the communication between the embedded programming service and STM32CubeProgrammer, but they are forbidden in FlashLayout file.

Code Virtual Partition or State
0x00 FlashLayout
0xF1 Command GetPhase
0xF2 OTP
0xF3 SSP
0xF4 PMIC NVM
0xFE State = End of operation
0xFF State = Reset

2.3.2. Using Id for boot partition[edit source]

Even if in the FlashLayout file, any other Id lower than 0x10 (boot partition with FIP header or STM32 header) can identify the binaries containing the FSBL and SSBL to be programmed in Flash memory, the recommended mapping is:

Code Comment Content Description
0x01 reserved FSBL to boot file containing FSBL with serial load support: loaded by ROM code
0x03 reserved SSBL to boot file containing SSBL with programming support : loaded by FSBL
0x04 FSBL to program 1 file containing FSBL to program in Flash memory (first copy)
0x05 FSBL to program 2 file containing FSBL to program in Flash memory (second copy)
0x06 metadata 1 FBSL metadata to program in Flash memory (first copy)
0x07 metadata 2 FBSL metadata to program in Flash memory (second copy)
0x08 SSBL to program A file containing SSBL slot A to program in Flash memory
0x09 SSBL to program B file containing SSBL slot B to program in Flash memory

It enables having different binaries loaded in RAM (with Reserved ID 0x1 and 0x3) and programmed in Flash memory, for example when an updated feature is deactivated in the binaries to be programmed in Flash memory (see example in #Load and program different binaries).

We also skip the Id 0x2 (not reserved) to have a more coherent order, as U-Boot requests and programs the partitions in Id order.

With OpenSTLinux binaries (FSBL=TF-A and the FIP contains SSBL=U-Boot) , this recommended mapping uses two ID (0x03 and 0x08) for the same FIP file used to boot and to program slot A:

Code Comment File Description
0x01 reserved tf-a-usb.stm32 TF-A to boot with serial load support on usb
0x03 reserved fip.bin FIP image file to boot, including U-Boot
0x04 tf-a-<dev>.stm32 TF-A for <dev> boot device to program: first copy
0x05 tf-a-<dev>.stm32 TF-A for <dev> boot device to program: second copy
... ... ... ...
0x08 fip.bin FIP file to program, including U-Boot (same FIP binary slot A than FIP to boot)

However the minimal mapping is, when the same FSBL and SSBL binaries can be loaded in RAM and programmed in Flash memory:

Code Comment Content Description
0x01 reserved FSBL file containing FSBL (first copy) to program in Flash memory, also used for serial boot, loaded by ROM code
0x02 default FSBL file containing FSBL second copy to program in Flash memory
0x03 reserved SSBL file containing SSBL programmed in Flash memory, also used for serial boot, loaded by FSBL

2.4. Field3: Name[edit source]

Name of the alternate setting of the USB DFU[1] for U-Boot enumeration. This is a string descriptor that indicates the target memory segment (see Interface Descriptor in DFU spec [2])

This is also the name of the Block device GPT partition: SD card / e•MMC.

The requirements for the GPT partitions, only for device = mmc + instance, are:

  • FSBL for SD card boot: the name must start with "fsbl"= fsbl, fsbl1, fsbl2... (ROM code requirement)
  • FIP containing SSBL for eMMC/SD card boot with #Field4: Type = FIP, the name must be:
  • a partition named "rootfs", see specific behavior described in #GPT partuuid of rootfs partition.

These requirements are not verified by U-Boot during the Flash programming. If they are not fulfilled, the ROM code or TF-A does not find the boot stage binary and the boot from Flash memory fails.

2.5. Field4: Type[edit source]

Type is only used in U-Boot to select the part of Flash memory to be updated:

The supported values are:

GPT MTD
Type SD card eMMC NAND Flash memory NOR Flash memory RAM
Binary x x x x x
Binary(N) fsbl
FIP x x x x x
FileSystem x x x x dtb
System x x UBI UBI kernel
RawImage x user data x x

2.5.1. Block device GPT partition: SD card / eMMC[edit source]

Refer to GPT standard for details [3].

The supported values, with associated partition type GUID (globally unique identifiers[4]), are:

  • Binary : raw data / linux reserved
    GUID = 8DA63339-0007-60C0-C436-083AC8230908
  • FIP : FIP partition
    GUID = 19D5DF83-11B0-457b-BE2C-7559C13142A5
    see also #GPT partuuid of FIP partition
  • FileSystem : Linux filesystem data (for example ext2/ext4/fat file system)
    GUID = 0FC63DAF-8483-4772-8E79-3D69D8477DE4
  • System : FileSystem partition marked as bootable and used by U-Boot to find extlinux.conf configuration file (normally only one in the device, generic DISTRO feature)

For a Block device, the GPT header is updated only if all the partitions of this device are selected with the P option (full update).

2.5.2. Raw Flash device (NAND/NOR Flash memories) MTD partition[edit source]

The supported values are:

  • Binary: raw data, skip bad block.
  • Binary(N): raw data, skip bad block. The loaded binary is repeated N times.
    It is only supported for NAND Flash memories when the partition name starts with "fsbl". It is used to avoid disturbances during the first boot (uncorrectable ECC errors).
    The first good block is read from NAND and duplicated N times in the same partition (write skip bad block).
    This feature is no more used in OpenSTLinux flashlayout which use one MTD partition by copy.
  • FIP: raw data, skip bad block.
  • FileSystem: unspecified File system, raw data
  • System : normally UBI volume, U-Boot erases all the blocks following the last data in the MTD partition to avoid mount errors.

2.5.3. Hardware device[edit source]

Export the associated device as one alternate setting by using Type=RawImage.

  • For SD card, NOR and NAND Flash memories: all the devices
  • For eMMC: the user data area of eMMC (see #Field6: Offset for access to the boot area partitions)

For RawImage, Offset=0x0 and PartId >= 0x10

2.5.4. RAM device (DDR)[edit source]

The supported values are:

  • Binary: raw data, used for initrd in the bootm command
  • FileSystem: device tree used in the bootm command
  • System : kernel image used in the bootm command (uImage.bin for example)

When a RAM device is present in the FlashLayout, the programming service will not reboot but start the loaded kernel image with the associated device tree or when it is absent with the U-Boot device tree.

2.6. Field5: Device[edit source]

Select the targeted device and the instance (starting at 0) as defined by U-Boot device tree:

  • mmc + instance : mmc0, mmc1, mmc2
    It is used for eMMC or SD card on SDMMC. In the below examples and for STMicroelectronics boards:
    • SD card = mmc0 (SDMMC1)
    • eMMC = mmc1 (SDMMC2)
  • nor + instance : nor0
    It is used for NOR on QUADSPI.
  • nand + instance : nand0
    It is used for parallel NAND Flash memories on FMC.
  • spi-nand + instance : spi-nand0
    It is used for serial NAND Flash memories on QSPI.
  • none only used to load the programming service in RAM
    It is allowed only for the reserved bootloaders partition (FSBL=0x1 and SSBL=0x3).
    In this case, the only allowed fields are: Type=Binary, Offset=0x0 and option=-
  • ram + instance : ram0
    It is used for files loaded in RAM by the programming service, for example to load and execute kernel.

Several devices can be mixed in the same FlashLayout file.

2.7. Field6: Offset[edit source]

The supported values are:

  • boot1: first boot area partition of eMMC (offset is 0x0)
  • boot2: second boot area partition of eMMC (offset is 0x0)
  • Offset in Bytes: offset in Flash memory area (in the user data area for eMMC)

Refer to #Partition sizes for offset constraints.

2.8. Field7: Binary[edit source]

This file is used by STM32CubeProgrammer to find the file associated to each Id when it is requested by embedded programming service .

The file can be absent (Binary=none in the tsv file) only for skipped partitions tagged with the E option. In all other cases, this file is sent to U-Boot to update the Flash memory only for the partitions selected with the P option.

2.9. GPT partuuid[edit source]

For GPT on block device (SD card / eMMC), U-Boot can also set a unique partition guid [4](PARTUUID) on one partition.

This partition PARTUUID is distinct from the filesystem UUID and it is persistent.

Refer to GPT standard for details. [3]

2.9.1. GPT partuuid of FIP partition[edit source]

If #Field4: Type = FIP and the GPT partition UUID is defined according the #Field3: Name value:

  • fip-a : PARTUUID = "4FD84C93-54EF-463F-A7EF-AE25FF887087"
  • fip-b : PARTUUID = "09C54952-D5BF-45AF-ACEE-335303766FB3"

These value are aligned with the metadata generated by TF-A tools and allow to support the firmware update in TF-A BL2.

2.9.2. GPT partuuid of rootfs partition[edit source]

If #Field3: Name = rootfs and for each targeted MMC instance with #Field5: Device:

  • rmmc0: PARTUUID = "e91c4e10-16e6-4c0e-bd0e-77becf4a3582"
  • rmmc1: PARTUUID = "491f6117-415d-4f53-88c9-6e0de54deac6"
  • rmmc2: PARTUUID = "fd58f1c7-be0d-4338-8ee9-ad8f050aeb18"

This value can be used with the "root" argument in the kernel bootargs to identify the partition used for the "Root filesystem". For instance, "root=PARTUUID=e91c4e10-16e6-4c0e-bd0e-77becf4a3582" [5] starts with the partition named rootfs on mmc0.

2.10. Partition operations[edit source]

To update only one partition, use the same FlashLayout file, keep the #Field1: Options=P for the partition to update and change the others to -.
And to delete only one partition, add the DE option on the corresponding line.

To update fip-a partition (based on #Examples):

 #opt	Id	Name		Type		Device	Offset		Binary
 -	0x01	fsbl-boot	Binary		none	0x00000000	tf-a-usb.stm32
 -	0x03	fip-boot	FIP		none	0x00000000	fip.bin
 -	0x04	fsbl1		Binary		mmc0	0x00004400	tf-a-sdcard.stm32
 -	0x05	fsbl2		Binary		mmc0	0x00044400	tf-a-sdcard.stm32
 -	0x06	metadata1	Binary		mmc0	0x00084400	metadata.bin
 -	0x07	metadata2	Binary		mmc0	0x000C4400	metadata.bin
 P	0x08	fip-a		FIP		mmc0	0x00104400	fip.bin
 -	0x09	fip-b		FIP		mmc0	0x00504400	none
 -	0x09	u-boot-env	binary		mmc0	0x00904400	none
 -	0x10	bootfs		System		mmc0	0x00984400	bootfs.ext4
 -	0x11	vendorfs	FileSystem	mmc0	0x04984400	vendorfs.ext4
 -	0x12	rootfs		FileSystem	mmc0	0x05984400	rootfs.ext4
 -	0x13	userfs		FileSystem	mmc0	0x33984400	userfs.ext4

To delete fip-a partition, with PDE:

 #opt	Id	Name		Type		Device	Offset		Binary
 -	0x01	fsbl-boot	Binary		none	0x00000000	tf-a-usb.stm32
 -	0x03	fip-boot	FIP		none	0x00000000	fip.bin
 -	0x04	fsbl1		Binary		mmc0	0x00004400	tf-a-sdcard.stm32
 -	0x05	fsbl2		Binary		mmc0	0x00044400	tf-a-sdcard.stm32
 -	0x06	metadata1	Binary		mmc0	0x00084400	metadata.bin
 -	0x07	metadata2	Binary		mmc0	0x000C4400	metadata.bin
 PDE	0x08	fip-a		FIP		mmc0	0x00104400	fip.bin
 -	0x09	fip-b		FIP		mmc0	0x00504400	none
 -	0x09	u-boot-env	binary		mmc0	0x00904400	none
 -	0x10	bootfs		System		mmc0	0x00984400	bootfs.ext4
 -	0x11	vendorfs	FileSystem	mmc0	0x04984400	vendorfs.ext4
 -	0x12	rootfs		FileSystem	mmc0	0x05984400	rootfs.ext4
 -	0x13	userfs		FileSystem	mmc0	0x33984400	userfs.ext4

2.11. Partition sizes[edit source]

The partitions are contiguous (no holes in Flash memory).
The last partition continues until the end of the selected Flash memory.

To reduce the size of the last partition, use an 'Empty' partition and leave it unused.

All the partitions need to be present in the FlashLayout file, even if they are not selected or empty.
Then the offset and size of each partition are compared with:

  • pre-existing GPT partitioning, for updates on block devices (eMMC or SD card)
  • predefined partitioning for MTD devices (NOR and NAND): see mtdparts environment variable in U-Boot for more information.

In case of partition size error, compare the existing partition size in U-Boot with the offset in the FlashLayout file.

2.11.1. GPT partition sizes[edit source]

Each GPT partition must be aligned to:

  • 512 bytes (LBA)
  • eMMC erase group size

The first partition starts after 17 Kbytes, the default size of GPT header for 128 entries in U-Boot.

Prior to updating partitions in a block device, check the partition size by executing the U-Boot command part list on the mmc device:

  part list mmc 0
 Partition Map for MMC device 0  --   Partition Type: EFI
 
 Part	Start LBA	End LBA		Name
 	Attributes
 	Type GUID
 	Partition GUID
   1	0x00000022	0x00000221	"fsbl1"
   	attrs:	0x0000000000000000
 	type:	8da63339-0007-60c0-c436-083ac8230908
 	guid:	3bc90966-2c53-4eba-8187-e6630626d1d2
   2	0x00000222	0x00000421	"fsbl2"
 	attrs:	0x0000000000000000
 	type:	8da63339-0007-60c0-c436-083ac8230908
 	guid:	1dfe7c94-8223-447c-90ed-a7fc5a4ea823
   3	0x00000422	0x00000621	"metadata1"
 	attrs:	0x0000000000000000
 	type:	8da63339-0007-60c0-c436-083ac8230908
 	guid:	eb8119bb-592b-40ef-b4b8-b4b14557e7f2
   4	0x00000622	0x00000821	"metadata2"
 	attrs:	0x0000000000000000
 	type:	8da63339-0007-60c0-c436-083ac8230908
 	guid:	125e7af2-0e1b-408e-a621-e23765c01d0b
   5	0x00000822	0x00002821	"fip-a"
 	attrs:	0x0000000000000000
 	type:	19d5df83-11b0-457b-be2c-7559c13142a5
 	guid:	4fd84c93-54ef-463f-a7ef-ae25ff887087
   6	0x00002822	0x00004821	"fip-b"
 	attrs:	0x0000000000000000
 	type:	19d5df83-11b0-457b-be2c-7559c13142a5
 	guid:	09c54952-d5bf-45af-acee-335303766fb3
   7	0x00004822	0x00004c21	"u-boot-env"
 	attrs:	0x0000000000000000
 	type:	8da63339-0007-60c0-c436-083ac8230908
 	guid:	def45efd-bc82-415b-87d3-f00d63388fe6
   8	0x00004c22	0x00024c21	"boot"
 	attrs:	0x0000000000000004
 	type:	0fc63daf-8483-4772-8e79-3d69d8477de4
 	type:	linux
 	guid:	d072dc90-f3cf-49ce-a851-4d011c9768c6
   9	0x00024c22	0x0002cc21	"vendorfs"
 	attrs:	0x0000000000000000
 	type:	0fc63daf-8483-4772-8e79-3d69d8477de4
 	type:	linux
 	guid:	1d6c73ce-4521-43dd-a069-b08022c3013d
  10	0x0002cc22	0x0019cc21	"rootfs"
 	attrs:	0x0000000000000000
 	type:	0fc63daf-8483-4772-8e79-3d69d8477de4
 	type:	linux
 	guid:	e91c4e10-16e6-4c0e-bd0e-77becf4a3582
  11	0x0019cc22	0x01dacbdc	"userfs"
 	attrs:	0x0000000000000000
 	type:	0fc63daf-8483-4772-8e79-3d69d8477de4
 	type:	linux
 	guid:	81ad4323-f879-4788-a40e-b190d614df9d

Warning: in mmccommand, start and end are indicated in multiple of LBA (512 bytes by default).

To check the eMMC erase group size in U-Boot, select the mmc device with mmc dev command (1 on STMicroelectronics board and in next example) and use the command mmc info.

   mmc dev 1
 switch to partitions #0, OK
 mmc1(part 0) is current device
   mmc info
 Device: STM32 SD/MMC
 Manufacturer ID: 11
 OEM: 100
 Name: 004GA 
 Bus Speed: 52000000
 Mode: MMC High Speed (52MHz)
 Rd Block Len: 512
 MMC version 5.0
 High Capacity: Yes
 Capacity: 3.7 GiB
 Bus Width: 8-bit
 Erase Group Size: 512 KiB
 HC WP Group Size: 4 MiB
 User Capacity: 3.7 GiB WRREL
 Boot Capacity: 2 MiB ENH
 RPMB Capacity: 512 KiB ENH
 Boot area 0 is not write protected
 Boot area 1 is not write protected

2.11.2. MTD partition sizes[edit source]

Each MTD partition must be aligned to the device erase block size (NOR/NAND Flash memory).

In U-Boot shell, this size is verified with the command:

  nand info
 Device 0: nand0, sector size 256 KiB
   Page size       4096 b
   OOB size         224 b
   Erase size    262144 b
   subpagesize     4096 b
   options     0x00084200
   bbt options 0x00060000
  sf probe
 SF: Detected mx25l51235f with page size 256 Bytes, erase size  64 KiB, total 64 MiB

For MTD, the U-Boot uses the mtdparts variable. Execute the U-Boot command mtdparts or mtd to know the current value:

  mtdparts
  mtd list

By default on ST board, the mtdpart variable is built dynamically in board_mtdparts_default() under CONFIG_SYS_MTDPARTS_RUNTIME with the STMicroelectronics configs:

  • CONFIG_MTDPARTS_NAND0_BOOT = "512k(fsbl1),512k(fsbl2),512k(metadata1),512k(metadata2),4m(fip-a1),4m(fip-a2),4m(fip-b1),4m(fip-b2)"
  • CONFIG_MTDPARTS_NOR0_BOOT = "256k(fsbl1),256k(fsbl2),256k(metadata1),256k(metadata2),4m(fip-a1),4m(fip-a2),4m(fip-b1),4m(fip-b2),512k(u-boot-env)"
  • CONFIG_MTDPARTS_SPINAND0_BOOT = "512k(fsbl1),512k(fsbl2),512k(metadata1),512k(metadata2),4m(fip-a1),4m(fip-a2),4m(fip-b1),4m(fip-b2)"

On NAND Flash, the last partition 'UBI' uses the remaining space with several UBI volumes for OpenSTLinux:
uboot_config, uboot_config_r, boot, rootfs, vendorfs, and userfs ("boot" is the volume name expected by U-Boot).

On NOR Flash, the last partition named 'nor_user', is a free MTD partition which uses the remaining space.

We align each partition size on max supported erase block size (512 Kbytes on NAND and 256 Kbytes on NOR).

To change the MTP partitioning on NOR and NAND Flash memories, update these configurations in your U-Boot defconfig as explained in U-Boot and in 'MTD partitions in U-Boot' or override this behavior in your board.

2.11.3. NOR MTD partition on STMicroelectronics boards[edit source]

The default MTD partitions used on the STMicroelectronics boards with OpenSTLinux for NOR boot is:

   mtd list
 SF: Detected mx66l51235l with page size 256 Bytes, erase size 64 KiB, total 64 MiB
 List of MTD devices:
 * nor0
   - device: mx66l51235l@0
   - parent: spi@58003000
   - driver: jedec_spi_nor
   - path: /soc/spi@58003000/mx66l51235l@0
   - type: NOR flash
   - block size: 0x10000 bytes
   - min I/O: 0x1 bytes
   - 0x000000000000-0x000004000000 : "nor0"
         - 0x000000000000-0x000000040000 : "fsbl1"
         - 0x000000040000-0x000000080000 : "fsbl2"
         - 0x000000080000-0x0000000c0000 : "metadata1"
         - 0x0000000c0000-0x000000100000 : "metadata2"
         - 0x000000100000-0x000000500000 : "fip-a"
         - 0x000000500000-0x000000900000 : "fip-b"
         - 0x000000900000-0x000000980000 : "u-boot-env"
         - 0x000000980000-0x000004000000 : "nor_user"
 * nor1
   - device: mx66l51235l@1
   - parent: spi@58003000
   - driver: jedec_spi_nor
   - path: /soc/spi@58003000/mx66l51235l@1
   - type: NOR flash
   - block size: 0x10000 bytes
   - min I/O: 0x1 bytes
   - 0x000000000000-0x000004000000 : "nor1"
  mtdparts 
 SF: Detected mx66l51235l with page size 256 Bytes, erase size 64 KiB, total 64 MiB
 
 device nor0 <nor0>, # parts = 8
 #: name          size        offset            mask_flags
 0: fsbl1               0x00040000 0x00000000  0
 1: fsbl2               0x00040000 0x00040000  0
 2: metadata1           0x00040000 0x00080000  0
 3: metadata2           0x00040000 0x000c0000  0
 4: fip-a               0x00400000 0x00100000  0
 5: fip-b               0x00400000 0x00500000  0
 6: u-boot-env          0x00080000 0x00900000  0
 7: nor_user            0x03680000 0x00980000  0
 
 active partition: nor0,0 - (fsbl1) 0x00040000 @ 0x00000000
 
 defaults:
 mtdids  : nor0=nor0
 mtdparts: mtdparts=nor0:256k(fsbl1),256k(fsbl2),256k(metadata1),256k(metadata2),4m(fip-a),4m(fip-b),512k(u-boot-env),-(nor_user)

This default partitioning is compatible for any NOR device, as we align each partition size on max supported erase block size on = 256 Kbytes.

2.11.4. NAND MTD partition on STMicroelectronics boards[edit source]

The default MTD partitions used on the ST boards with OpenSTLinux for NAND boot is:

   mtd list
 List of MTD devices:
 * nand0
   - type: NAND flash
   - block size: 0x40000 bytes
   - min I/O: 0x1000 bytes
   - OOB size: 224 bytes
   - OOB available: 118 bytes
   - ECC strength: 8 bits
   - ECC step size: 512 bytes
   - bitflip threshold: 6 bits
   - 0x000000000000-0x000040000000 : "nand0"
         - 0x000000000000-0x000000080000 : "fsbl1"
         - 0x000000080000-0x000000100000 : "fsbl2"
         - 0x000000100000-0x000000180000 : "metadata1"
         - 0x000000180000-0x000000200000 : "metadata2"
         - 0x000000200000-0x000000600000 : "fip-a1"
         - 0x000000600000-0x000000a00000 : "fip-a2"
         - 0x000000a00000-0x000000e00000 : "fip-b1"
         - 0x000000e00000-0x000001200000 : "fip-b2"
         - 0x000001200000-0x000040000000 : "UBI"
   mtdparts 
 device nand0 <nand0>, # parts = 9
 #: name          size        offset            mask_flags
 0: fsbl1               0x00080000 0x00000000  0
 1: fsbl2               0x00080000 0x00080000  0
 2: metadata1           0x00080000 0x00100000  0
 3: metadata2           0x00080000 0x00180000  0
 4: fip-a1              0x00400000 0x00200000  0
 5: fip-a2              0x00400000 0x00600000  0
 6: fip-b1              0x00400000 0x00a00000  0
 7: fip-b2              0x00400000 0x00e00000  0
 8: UBI                 0x3ee00000 0x01200000  0
 
 active partition: nand0,0 - (fsbl1) 0x00080000 @ 0x00000000
 
 defaults:
 mtdids  : nand0=nand0,nor0=nor0
 mtdparts: mtdparts=nand0:512k(fsbl1),512k(fsbl2),512k(metadata1),512k(metadata2),4m(fip-a1),4m(fip-a2),4m(fip-b1),4m(fip-b2),- 
(UBI);nor0:256k(fsbl1),256k(fsbl2),256k(metadata1),256k(metadata2),4m(fip-a),4m(fip-b),512k(u-boot-env),-(nor_user)

This default partitioning is compatible for any NAND device, as we align each partition size on max supported erase block size on NAND = 512 Kbytes.

3. Typical FlashLayout file[edit source]

This chapter describes the Layout file for the typical OpenSTLinux boot use cases based on STM32_MPU_Flash_mapping.

Data are presented in tables for better readability despite the Layout file is plain text.

In the next examples, the boot chain of OpenSTLinux is used together with the following files:

  • FSBL = TF-A with 2 different binary
    • FSBL to boot with serial boot over USB = tf-a-usb.stm32
      TF-A BL2 with STM32CubeProgrammer USB support,
      this file is replaced by tf-a-uart.stm32 when UART is used
    • FSBL to program = tf-a-<dev>.stm32 (TF-A with boot from <dev> support, <dev> = emmc, sdcard, nand, spinand, nor)
  • TF-A metadata binary for FIP update support = metadata.bin
  • FIP file containing SSBL = fip.bin, it includes secure monitor, from TF-A = SPMIN or from OP-TEE, SSBL=U-Boot binary and device tree.

3.1. NOR Flash memory and SD card[edit source]

NOR Flash memory in RAW, containing the bootloaders, use the MTD partitions for OpenSTLinux:

  • 2 for TF-A : 2 copy for failsafe update
  • 2 for TF-A metadata for FIP update support: 2 copy for failsafe update
  • 2 for FIP : file fip.bin in the first slot (fip-a), the second slot is empty (fip-b), reserved for FIP update support
  • 1 for U-Boot environment

SD card using GPT: several EXT4 partitions.

In this next NOR flashlayout for the STMicroelectronics boards, we align each partition on max supported erase block size of NOR 256 Kbytes, based on default MTD partition on NOR but the size of these MTD partitions can be optimized for NOR with lower erase block size.

Opt Part Name Type Device Offset Binary
- 0x01 fsbl-boot Binary none 0x0 tf-a-usb.stm32
- 0x03 fip-boot Binary none 0x0 fip.bin
P 0x04 fsbl1 Binary nor0 0x00000000 tf-a-nor.stm32
P 0x05 fsbl2 Binary nor0 0x00040000 tf-a-nor.stm32
P 0x06 metadata1 Binary nor0 0x00080000 metadata.bin
P 0x07 metadata2 Binary nor0 0x000C0000 metadata.bin
P 0x08 fip-a Binary nor0 0x00100000 fip.bin
PED 0x09 fip-b Binary nor0 0x00500000 none
PED 0x0A u-boot-env Binary nor0 0x00900000 none
PE 0x0B unused Binary nor0 0x00980000 none
P 0x10 bootfs System mmc0 0x00004400 bootfs.ext4
P 0x11 vendorfs FileSystem mmc0 0x04004400 vendorfs.ext4
P 0x12 rootfs FileSystem mmc0 0x05004400 rootfs.ext4
P 0x13 userfs FileSystem mmc0 0x33004400 userfs.ext4
Warning white.png Warning
It is only a example of tsv file with two metadata partitions and two FIP slots A/B for the update feature, activated by default in OpenSTLinux; the erase block size of selected NOR is also a part a MTD partitions dimensioning !


see STM32_MPU_Flash_mapping#NOR_memory_mapping for details

The PartId 0x09 is empty/deleted in nor0 ('PED' flag), the second FIP slot is empty and cleared.

The FIP partition {{HighlightParam|0x8} named "fip-a" and - ! Opt !! Part !! Name !! Type !! Device !! Offset !! Binary || FIP || mmc0 || 0x00104400 || none |- | PED || 0x0A || u-boot-env || Binary || mmc0 || 0x00504400 || none |- | P || 0x09 || bootfs || System || mmc0 || 0x00904400 || bootfs.ext4 |- | P || 0x10 || vendorfs || FileSytem || mmc0 || TBD || vendorfs.ext4 |- | P || 0x12 || rootfs || FileSytem || mmc0 || TBD || rootfs.ext4 |- | P || 0x13 || userfs || FileSytem || mmc0 || TBD || userfs.ext4 |- | PED || 0x60 || emmc_boot1 || Binary || mmc1 || boot1 || none |- | DPE || 0x61 || emmc_boot2 || Binary || mmc1 || boot2 || none |- | EPD || 0x62 || emmc || RawImage || mmc1 || 0x0 || none |- | EPD || 0x10 || nand || RawImage || nand0 || 0x0 || none |}

4. Reference list[edit source]