Difference between revisions of "How to configure U-Boot for your board"

[checked revision] [quality revision]
m (MTD partitions)
m (partitions)
 

This page explains how to configure the U-Boot source for your board.

Many existing ressources [1][2] explain the porting of U-Boot on a new board. This article only provides basic guidelines for STM32MP1 Series.

To summarize, you need to configure U-Boot for your <VENDOR> <BOARD> with the following steps:

  1. Add your board device tree: arch/arm/dts/<board>.dts and <board>-u-boot.dtsi.
  2. Create your own board support directory: board/<vendor>/<board>.
  3. Add TARGET_<VENDOR> _<BOARD> in Kconfig.
  4. Create your board defconfig: defconfig/<board>_defconfig.
  5. Add your configuration file : include/configs/<board>.h.

1 Device tree[edit]

Add the board device tree files <board>.dts and <board>-u-boot.dtsi in arch/arm/dts , following the steps below:

  • Copy the Linux kernel device tree in the directory arch/arm/dts : <board>.dts.
 dtb-$(CONFIG_STM32MP15x) += \
 	<board>.dtb 
  • Add a U-Boot addon device tree for your board in the arch/arm/dts directory: <board>-u-boot.dtsi
    This file is automatically included during <board>.dts processing.
    It includes the <soc>-u-boot.dtsi file provided by STMicroelectronics (for example arch/arm/dts/stm32mp15-u-boot.dtsi ) and add all the properties on nodes needed by U-Boot (added nodes, config nodes and u-boot, dm-pre-reloc or u-boot, dm-pre-proper attibutes).

At this point you can use the generic STM32 MPU defconfig with the STMicroelectronics board directory, but with your board device tree.

The board-specific features are not correctly managed, but should be sufficient for a simple board derived from STMicroelectronics designs.

For example, on STM32MP15x lines More info.png, you can use the STMicroelectronics code with your device tree as follows:

 
PC $> make stm32mp15_trusted_defconfig
 PC $> make DEVICE_TREE=<board> all

The next steps are required if the STMicroelectronics generic board does not comply with all of the expected behavioral aspects for your board (for example MAC address not located in OTP, specific PMIC, specific boot command).

1.1 Config node[edit]

Some properties in the 'config' node are also used to dynamically configure the U-Boot behavior in the board device tree as follows:

  • Generic U-Boot configuration, managed in generic code:
    • u-boot,mmc-env-partition = name of partition used to save U-Boot environment
  • Some STMicroelectronics properties only managed in STMicroelectronics board code (in line with LEDs and buttons on STM32 MPU boards); they can only be used if your board reuses this code
    • u-boot,boot-led = name of boot-progress indicator LED
    • u-boot,error-led = name of error indicator LED
    • st,adc_usb_pd = ADC channels used to check USB power supply
    • st,stm32prog-gpios = GPIO used to force STM32CubeProgrammer mode
    • st,fastboot-gpios = GPIO used to force Android Fastboot mode

For example in arch/arm/dts/stm32mp157a-dk1-u-boot.dtsi

   	config {
   		u-boot,boot-led = "heartbeat";
   		u-boot,error-led = "error";
   		u-boot,mmc-env-partition = "ssbl";
   		st,adc_usb_pd = <&adc1 18>, <&adc1 19>;
   		st,fastboot-gpios = <&gpioa 13 GPIO_ACTIVE_LOW>;
   		st,stm32prog-gpios = <&gpioa 14 GPIO_ACTIVE_LOW>;
   	};

1.2 USB OTG node[edit]

The U-Boot driver for USB OTG, with the compatible st,stm32mp1-hsotg, does not have a full OTG support, so only the gadget is used in STM32 MPU board with drivers/usb/host/dwc2.c .

Two U-Boot specific properties are added to support the possible USB connection of ID pin and VBUS on the board:

  • u-boot,force-b-session-valid: this property forces USB B session (by deactivating the detection with ID pin) and deactivates VBus sensing. It is used when all these features are managed by the board (for example on the STM32MP5X-DK2 board that uses the STUSB1600 USB type-C controller).
  • u-boot,force-vbus-detection: this property forces Vbus sensing when u-boot,force-b-session-valid is used (typically when the ID pin is not correctly managed).

Examples of USB configuration in <board>-u-boot.dtsi:

  • B session forced as device mode, USB pin not used and VBus sensing deactivated:
 &usbotg_hs {
 	u-boot,force-b-session-valid;
 	dr_mode = "peripheral";
 };
  • B session and VBus sensing forced (deactived by default with "force-b-session-valid")
 &usbotg_hs {
 	u-boot,force-b-session-valid;
 	u-boot,force-vbus-detection;
 	dr_mode = "peripheral";
 };

2 Board subdirectory[edit]

Create your own board support subdirectory = board/<vendor>/<board> and add a Makefile file.

You can add any source files needed for your board.

In this Makefile, you can compile the STMicroelectronics files (in board/st/stm32mp1 or in board/st/common) or just copy them as starting point then modify them.

For example board/dhelectronics/dh_stm32mp1/Makefile uses STMicroelectronics board files in ../../st/stm32mp1 directory and local file "board.c"

 ifdef CONFIG_SPL_BUILD
 obj-y += ../../st/stm32mp1/spl.o
 endif

 obj-y += ../../st/stm32mp1/board.o board.o

3 Kconfig[edit]

You need to support your board in Kconfig with a new configuration flag: TARGET_<VENDOR>_<BOARD>

3.1 Arch Kconfig: arch/arm/mach-stm32mp/Kconfig [edit]

  1. Add new CONFIG_TARGET_<VENDOR>_<BOARD>.
  2. Select the required option (soc for example : CONFIG_STM32MP15x).
  3. Include your board Kconfig in arch one (source "board/<vendor>/<board>/Kconfig").
 choice
 	prompt "STM32MP15x board select"
 	optional
   
   [...]
   
   config TARGET_<VENDOR>_<BOARD>
   	bool "<vendor> <board> board"
   	select STM32MP15x
   	help
 		target the <vendor> <board> board with SOC STM32MP15x
 		managed by board/<vendor>/<board>
 

To check the U-Boot behavior and the value of the generated variables via a U-Boot console, execute the "mtdparts" command.

   endchoice
 
  [...]
  source "board/st/stm32mp1/Kconfig"
  source "board/dhelectronics/dh_stm32mp1/Kconfig"
  source "board/<vendor>/<board>/Kconfig"
  
  endif

3.2 Board Kconfig: board/<vendor>/<board>/Kconfig[edit]

The mininimal content of this file is:

 if TARGET_<VENDOR>_<BOARD>
 
 config SYS_BOARD
 	default "<board>"
 
 config SYS_VENDOR
 	default "<vendor>"
 
 config SYS_CONFIG_NAME
 	default "<config>"
 endif

For example see board/dhelectronics/dh_stm32mp1/Kconfig .

SYS_CONFIG_NAME selects the used configuration file: include/configs/SYS_CONFIG_NAME.h.

4 Defconfig[edit]

Add a new defconfig for your board in configs .

  • copy configs/stm32mp15_trusted_defconfig to your "<vendor>_<board>_defconfig"
  • select your new defconfig: make <vendor>_<board>_defconfig"
  • use make menuconfig to change your defconfig
    • remove CONFIG_TARGET_ST_STM32MP15x
    • add CONFIG_TARGET_<VENDOR>_<BOARD>
    • change CONFIG_DEFAULT_DEVICE_TREE from "stm32mp157c-ev1" to the name of the board device tree: "<board>"
  • save the updated defconfig: make savedefconfig
  • verify and copy the file "defconfig" in configs/<vendor>_<board>_defconfig

For example see the file configs/dh_stm32mp1/stm32mp15_dhcom_basic_defconfig .

5 Configuration file[edit]

The configuration file is the include file in include/configs directory selected in Makefile.autoconf by CONFIG_SYS_CONFIG_NAME.

This file defines the CONFIG_ flags of the boards that are not defined with Kconfig.

For example, in this configuration file, you can choose the initial U-Boot environment through CONFIG_EXTRA_ENV_SETTINGS, including the boot command.

For STMicroelectronics boards, CONFIG_SYS_CONFIG_NAME = stm32mp1 and the configuration file is include/configs/stm32mp1.h .

This STMicroelectronics configuration file can be:

  • either used in your project (through CONFIG_SYS_CONFIG_NAME="stm32mp1"), or
  • included in your board configuration file (#include "stm32mp1"), or
  • used a starting point for your configuration file (copy and update it).

6 Configuration example[edit]

6.1 MTD partitions[edit]

In U-Boot, all the mtd partitions are managed in mtdparts and mtdids U-Boot variables.

U-Boot then dynamically updates the Linux® kernel device tree with these information under CONFIG_OF_BOARD_SETUP in board/st/stm32mp1/stm32mp1.c ::ft_board_setup().

This device tree update enables the alignment of MTD configuration between U-Boot and Linux, and avoids STM32CubeProgrammer support issues as the MTD partition sizes has to be aligned with Flashlayout.

To define the MTD partitions parttions in Linux device tree, deactivate CONFIG_OF_BOARD_SETUP in the customer defconfig. However this might result in misalignments with U-Boot.

To simplify the STMicroelectronics board deployment (same software for boot with and without TEE and for all devices), the mtdparts and mtdids variables are dynamically built under CONFIG_SYS_MTDPARTS_RUNTIME with :

To check this U-Boot behavior and the generated value of theses variables, execute the mtdparts command via a U-Boot console.

The default values of CONFIG_MTDPARTS_XXX are used for STMicroelectronics boards (see values provided in board/st/common/Kconfig ).

However the customer can modify them in her/his defconfig if the stm32mp_mtdparts.c file is also used in board configuration file.

For example CONFIG_MTDPARTS_NAND0_BOOT = "1m(u-boot),512k(params)" and the 'UBI' partition is automatically added at the end of the device.

The MTD default configuration can also be directly hardcoded in the customer defconfig (stm32mp_mtdparts.c is not used). To do this:

  • Deactivate CONFIG_SYS_MTDPARTS_RUNTIME
  • Select your MTDPARTS default configuration with
    • CONFIG_MTDPARTS_DEFAULT
    • CONFIG_MTDIDS_DEFAULT

For example:

  
CONFIG_MTDPARTS_DEFAULT="mtdparts=nand0:1m(u-boot),512k(params),-(ubifs)"
  CONFIG_MTDIDS_DEFAULT="nand0=nand0"

For information, only mtdids_default and mtdparts_default are generated in mtdparts_init() / board_mtdparts_default() and these defaults values are used only if mtdpart/mtdids variables are empty.

As a result you can also define the MTD configuration directly through these U-Boot variables by setting CONFIG_EXTRA_ENV_SETTINGS in your board configuration file:

  • mtdparts="mtdparts=nand0:2m(fsbl),2m(ssbl1),2m(ssbl2),-(UBI)"
  • mtdids="nand0=nand0"

This corresponds to a generic U-Boot configuration (see U-Boot documentation for additional details).

7 References[edit]



This page explains how to configure the [[U-Boot_overview|U-Boot]] source for your board.

__TOC__

Many existing ressources<ref>https://archive.fosdem.org/2018/schedule/event/state_of_the_art_uboot/attachments/slides/2051/export/events/attachments/state_of_the_art_uboot/slides/2051/fosdem_2018_u_boot.pdf</ref>
<ref>https://elinux.org/images/2/2a/Schulz-how-to-support-new-board-u-boot-linux.pdf</ref>

explain the porting of U-Boot on a new board. This article only provides basic guidelines for STM32MP1 Series.

To summarize, you need to [[U-Boot_overview#U-Boot_configuration|configure U-Boot]] for your {{HighlightParam|<VENDOR>}} {{HighlightParam|<BOARD>}} with the following steps:
# Add your board [[#Device tree|device tree]]: arch/arm/dts/{{HighlightParam|<board>}}.dts and {{HighlightParam|<board>}}-u-boot.dtsi.
# Create your own board support [[#Board subdirectory|directory]]: board/{{HighlightParam|<vendor>}}/{{HighlightParam|<board>}}.
# Add TARGET_{{HighlightParam|<VENDOR>}} _{{HighlightParam|<BOARD>}} in [[#Kconfig|Kconfig]].
# Create your board [[#Defconfig|defconfig]]: defconfig/{{HighlightParam|<board>}}_defconfig.
# Add your [[#Configuration file|configuration file]] : include/configs/{{HighlightParam|<board>}}.h.

== Device tree ==

Add the board [[U-Boot_overview#Device_tree|device tree]] files {{HighlightParam|<board>}}.dts and {{HighlightParam|<board>}}-u-boot.dtsi in {{CodeSource | U-Boot |arch/arm/dts}}, following the steps below:

* Copy the Linux kernel device tree in the directory {{CodeSource | U-Boot |arch/arm/dts}}: {{HighlightParam|<board>}}.dts.

* Update {{CodeSource | U-Boot |arch/arm/dts/Makefile}} to compile your device tree, for example:
  dtb-$(CONFIG_STM32MP15x) += \
  	{{HighlightParam|<board>}}.dtb 

* Add a U-Boot addon device tree for your board in the {{CodeSource | U-Boot |arch/arm/dts}} directory: '''{{HighlightParam|<board>}}-u-boot.dtsi'''<br/>This file is automatically included during {{HighlightParam|<board>}}.dts processing.<br/>It includes the <soc>-u-boot.dtsi file provided by STMicroelectronics (for example {{CodeSource | U-Boot |arch/arm/dts/stm32mp15-u-boot.dtsi}}) and add all the properties on nodes needed by U-Boot (added nodes, config nodes and u-boot, dm-pre-reloc or u-boot, dm-pre-proper attibutes).

At this point you can use the generic STM32 MPU defconfig with the STMicroelectronics board directory, but with your board device tree.

The board-specific features are not correctly managed, but should be sufficient for a simple board derived from STMicroelectronics designs.

For example, on {{MicroprocessorDevice | device=15}}, you can use the STMicroelectronics code with your device tree as follows:
  {{PC$}} make {{HighlightParam|stm32mp15_trusted_defconfig}}
  {{PC$}} make DEVICE_TREE={{HighlightParam|<board>}} all

The next steps are required if the STMicroelectronics generic board does not comply with all of the expected behavioral aspects for your board (for example MAC address not located in OTP, specific PMIC, specific boot command). 

=== Config node ===

Some properties in the  'config' node are also used to dynamically configure the U-Boot behavior in the board device tree as follows:
* Generic U-Boot configuration, managed in generic code:
** {{HighlightParam|u-boot,mmc-env-partition}} = name of partition used to save U-Boot environment
* Some STMicroelectronics properties only managed in STMicroelectronics board code (in line with [[LEDs and buttons on STM32 MPU boards]]); they can only be used if your board reuses this code
** {{Highlight|u-boot,boot-led}} = name of boot-progress indicator LED
** {{Highlight|u-boot,error-led}} = name of error indicator LED
** {{Highlight|st,adc_usb_pd}} = ADC channels used to check USB power supply
** {{Highlight|st,stm32prog-gpios}} = GPIO used to force STM32CubeProgrammer mode
** {{Highlight|st,fastboot-gpios}} = GPIO used to force Android Fastboot mode

For example in {{CodeSource | U-Boot |arch/arm/dts/stm32mp157a-dk1-u-boot.dtsi}}

    	config {
    		{{Highlight|u-boot,boot-led}} = "heartbeat";
    		{{Highlight|u-boot,error-led}} = "error";
    		{{HighlightParam|u-boot,mmc-env-partition}} = "ssbl";
    		{{Highlight|st,adc_usb_pd}} = <&adc1 18>, <&adc1 19>;
    		{{Highlight|st,fastboot-gpios}} = <&gpioa 13 GPIO_ACTIVE_LOW>;
    		{{Highlight|st,stm32prog-gpios}} = <&gpioa 14 GPIO_ACTIVE_LOW>;
    	};

=== USB OTG node ===

The U-Boot driver for USB OTG, with the compatible {{HighlightParam|st,stm32mp1-hsotg}}, does not have a full OTG support, so only the gadget is used in STM32 MPU board with {{CodeSource | U-Boot |drivers/usb/host/dwc2.c }}.

Two U-Boot specific properties are added to support the possible USB connection of ID pin and VBUS on the board:
* {{Highlight|u-boot,force-b-session-valid}}: this property forces USB B session (by deactivating the detection with ID pin) and deactivates VBus sensing. It is used when all these features are managed by the board (for example on the STM32MP5X-DK2 board that uses the STUSB1600 USB type-C controller).
* {{Highlight|u-boot,force-vbus-detection}}: this property forces Vbus sensing when '''u-boot,force-b-session-valid''' is used (typically when the ID pin is not correctly managed).

Examples of USB configuration in '''{{HighlightParam|<board>}}-u-boot.dtsi''':
* B session forced as device mode, USB pin not used and VBus sensing deactivated:

  &usbotg_hs {
  	{{Highlight|u-boot,force-b-session-valid}};
  	dr_mode = "peripheral";
  };

* B session and VBus sensing forced (deactived by default with "force-b-session-valid")

  &usbotg_hs {
  	{{Highlight|u-boot,force-b-session-valid}};
  	{{Highlight|u-boot,force-vbus-detection}};
  	dr_mode = "peripheral";
  };

== Board subdirectory ==

Create your own board support subdirectory = board/{{HighlightParam|<vendor>}}/{{HighlightParam|<board>}} and add a Makefile file.

You can add any source files needed for your board.

In this Makefile, you can compile the STMicroelectronics files (in board/st/stm32mp1 or in board/st/common) or just copy them as starting point then modify them. 

For example {{CodeSource | U-Boot |board/dhelectronics/dh_stm32mp1/Makefile}} uses STMicroelectronics board files in {{HighlightParam|../../st/stm32mp1}} directory and local file "{{Highlight|board}}.c" 

  ifdef CONFIG_SPL_BUILD
  obj-y += {{HighlightParam|../../st/stm32mp1}}/spl.o
  endif

  obj-y += {{HighlightParam|../../st/stm32mp1}}/board.o {{Highlight|board}}.o

== Kconfig ==

You need to support your board in Kconfig with a new configuration flag: TARGET_{{HighlightParam|<VENDOR>}}_{{HighlightParam|<BOARD>}}

=== Arch Kconfig: {{CodeSource | U-Boot |arch/arm/mach-stm32mp/Kconfig}} ===
# Add new CONFIG_TARGET_{{HighlightParam|<VENDOR>}}_{{HighlightParam|<BOARD>}}.
# Select the required option (soc for example : {{Highlight|CONFIG_STM32MP15x}}).
# Include your board Kconfig in arch one (source "board/{{HighlightParam|<vendor>}}/{{HighlightParam|<board>}}/Kconfig").

  choice
  	prompt "STM32MP15x board select"
  	optional

    [...]

    config TARGET_{{HighlightParam|<VENDOR>}}_{{HighlightParam|<BOARD>}}
    	bool "{{HighlightParam|<vendor>}} {{HighlightParam|<board>}} board"
    	select {{Highlight|STM32MP15x}}
    	help
  		target the {{HighlightParam|<vendor>}} {{HighlightParam|<board>}} board with SOC {{Highlight|STM32MP15x}}
  		managed by board/{{HighlightParam|<vendor>}}/{{HighlightParam|<board>}}

To check the U-Boot behavior and the value of the generated variables via a U-Boot console, execute the "mtdparts" command. 
    endchoice

   [...]
   source "board/st/stm32mp1/Kconfig"
   source "board/dhelectronics/dh_stm32mp1/Kconfig"
   source "board/{{HighlightParam|<vendor>}}/{{HighlightParam|<board>}}/Kconfig"

   endif

=== Board Kconfig: board/{{HighlightParam|<vendor>}}/{{HighlightParam|<board>}}/Kconfig ===

The mininimal content of this file is:

  if TARGET_{{HighlightParam|<VENDOR>}}_{{HighlightParam|<BOARD>}}

  config SYS_BOARD
  	default "{{HighlightParam|<board>}}"

  config SYS_VENDOR
  	default "{{HighlightParam|<vendor>}}"

  config {{Highlight|SYS_CONFIG_NAME}}
  	default "{{Highlight|<config>}}"
  endif

For example see {{CodeSource | U-Boot |board/dhelectronics/dh_stm32mp1/Kconfig}}.

{{Highlight|SYS_CONFIG_NAME}} selects the used [[#Configuration file|configuration file]]: include/configs/{{Highlight|SYS_CONFIG_NAME}}.h.

== Defconfig ==

Add a new defconfig for your board in {{CodeSource | U-Boot |configs}}.
* copy  {{CodeSource | U-Boot |configs/stm32mp15_trusted_defconfig}} to your  "{{HighlightParam|<vendor>}}_{{HighlightParam|<board>}}_defconfig"
* select your new defconfig: <code>make {{HighlightParam|<vendor>}}_{{HighlightParam|<board>}}_defconfig"</code>

* use <code>make menuconfig</code> to change your defconfig
** remove CONFIG_TARGET_ST_STM32MP15x
** add CONFIG_TARGET_{{HighlightParam|<VENDOR>}}_{{HighlightParam|<BOARD>}}
** change CONFIG_DEFAULT_DEVICE_TREE from "stm32mp157c-ev1" to the name of the board device tree: "{{HighlightParam|<board>}}" 
* save the updated defconfig: <code>make savedefconfig</code>

* verify and copy the file "defconfig" in configs/{{HighlightParam|<vendor>}}_{{HighlightParam|<board>}}_defconfig

For example see the file {{CodeSource | U-Boot |configs/dh_stm32mp1/stm32mp15_dhcom_basic_defconfig}}.

== Configuration file ==

The configuration file is the include file in {{CodeSource | U-Boot | include/configs}} directory selected in Makefile.autoconf by {{Highlight|CONFIG_SYS_CONFIG_NAME}}.

This file defines the CONFIG_ flags of the boards that are not defined with Kconfig.  

For example, in this configuration file, you can choose the initial U-Boot environment through CONFIG_EXTRA_ENV_SETTINGS, including the boot command.

For STMicroelectronics boards, {{Highlight|CONFIG_SYS_CONFIG_NAME}} = {{HighlightParam|stm32mp1}} and the configuration file is  {{CodeSource | U-Boot | include/configs/stm32mp1.h}}.

This STMicroelectronics configuration file can be:
* either used in your project (through {{Highlight|CONFIG_SYS_CONFIG_NAME}}="{{HighlightParam|stm32mp1}}"), or 
* included in your board configuration file (#include "{{HighlightParam|stm32mp1}}"), or
* used a starting point for your configuration file (copy and update it).

== Configuration example ==

=== MTD partitions ===

In U-Boot, all the mtd partitions are managed in <code>mtdparts</code> and <code>mtdids</code> [[U-Boot_overview#U-Boot_environment_variables|U-Boot variables]].

U-Boot then dynamically updates the Linux<sup>&reg;</sup> kernel device tree with these information under  {{Highlight|CONFIG_OF_BOARD_SETUP}} in {{CodeSource |U-Boot|board/st/stm32mp1/stm32mp1.c}}::ft_board_setup().

This device tree update enables the alignment of MTD configuration between U-Boot and Linux, and avoids STM32CubeProgrammer support issues as the [[STM32CubeProgrammer_flashlayout#MTD_partition_sizes|MTD partition sizes]] has to be aligned with Flashlayout.

To define the MTD partitionsparttions in Linux device tree, deactivate {{Highlight|CONFIG_OF_BOARD_SETUP}} in the customer defconfig. However  this might result in misalignments with U-Boot.

To simplify the STMicroelectronics board deployment (same software for boot with and without TEE and for all devices), the  <code>mtdparts</code> and <code>mtdids</code> variables are dynamically built under {{Highlight|CONFIG_SYS_MTDPARTS_RUNTIME}} with :
* several {{Highlight|CONFIG_MTDPARTS_XXX}} config defined in  {{CodeSource |U-Boot|board/st/common/Kconfig}}
* some hardcoded treatment in {{CodeSource |U-Boot|board/st/common/stm32mp_mtdparts.c}}::board_mtdparts_default() function.

To check this U-Boot behavior and the generated value of theses variables, execute the <code>mtdparts</code> command via a U-Boot console. 

The default values of  {{Highlight|CONFIG_MTDPARTS_XXX}} are used for STMicroelectronics boards (see values provided in {{CodeSource |U-Boot|board/st/common/Kconfig}}).

However the customer can modify them in [[#Defconfig|her/his defconfig]] if the {{CodeSource |U-Boot|board/st/common/stm32mp_mtdparts.c|stm32mp_mtdparts.c}} file is also used in [[#Board subdirectory|board configuration file]].

For example {{Highlight|CONFIG_MTDPARTS_NAND0_BOOT}} = "{{HighlightParam|1m(u-boot),512k(params)}}" and the 'UBI' partition is automatically added at the end of the device.

The MTD default configuration can also be directly  hardcoded in the [[#Defconfig|customer defconfig]] ({{CodeSource |U-Boot|board/st/common/stm32mp_mtdparts.c|stm32mp_mtdparts.c}} is not used). To do this:
* Deactivate  {{Highlight|CONFIG_SYS_MTDPARTS_RUNTIME}}
* Select your MTDPARTS default configuration with 
**  {{Highlight|CONFIG_MTDPARTS_DEFAULT}}
**  {{Highlight|CONFIG_MTDIDS_DEFAULT}}

For example:

   {{Highlight|CONFIG_MTDPARTS_DEFAULT}}="{{HighlightParam|mtdparts{{=}}nand0:1m(u-boot),512k(params),-(ubifs)}}"
   {{Highlight|CONFIG_MTDIDS_DEFAULT}}="{{HighlightParam|nand0{{=}}nand0}}"

For information, only <code>mtdids_default</code> and <code>mtdparts_default</code> are  generated in mtdparts_init() / board_mtdparts_default() and these defaults values are used only if <code>mtdpart</code>/<code>mtdids</code> variables are empty.

As a result you can also define the MTD configuration directly through these U-Boot variables by setting {{Highlight|CONFIG_EXTRA_ENV_SETTINGS}} in your [[#Configuration file|board configuration file]]:
* {{Highlight|mtdparts}}="{{HighlightParam|mtdparts{{=}}nand0:2m(fsbl),2m(ssbl1),2m(ssbl2),-(UBI)}}"
* {{Highlight|mtdids}}="{{HighlightParam|nand0{{=}}nand0}}"

This corresponds to a generic U-Boot configuration (see [[U-Boot overview|U-Boot documentation]] for additional details).

== References ==<references/>

<noinclude>

{{PublicationRequestId |17913| 2020-10-27 | }}

[[Category:How to customize software]] 
[[Category:U-Boot]]</noinclude>
Line 191: Line 191:
 
This device tree update enables the alignment of MTD configuration between U-Boot and Linux, and avoids STM32CubeProgrammer support issues as the [[STM32CubeProgrammer_flashlayout#MTD_partition_sizes|MTD partition sizes]] has to be aligned with Flashlayout.
 
This device tree update enables the alignment of MTD configuration between U-Boot and Linux, and avoids STM32CubeProgrammer support issues as the [[STM32CubeProgrammer_flashlayout#MTD_partition_sizes|MTD partition sizes]] has to be aligned with Flashlayout.
   
To define the MTD parttions in Linux device tree, deactivate {{Highlight|CONFIG_OF_BOARD_SETUP}} in the customer defconfig. However  this might result in misalignments with U-Boot.
+
To define the MTD partitions in Linux device tree, deactivate {{Highlight|CONFIG_OF_BOARD_SETUP}} in the customer defconfig. However  this might result in misalignments with U-Boot.
   
 
To simplify the STMicroelectronics board deployment (same software for boot with and without TEE and for all devices), the  <code>mtdparts</code> and <code>mtdids</code> variables are dynamically built under {{Highlight|CONFIG_SYS_MTDPARTS_RUNTIME}} with :
 
To simplify the STMicroelectronics board deployment (same software for boot with and without TEE and for all devices), the  <code>mtdparts</code> and <code>mtdids</code> variables are dynamically built under {{Highlight|CONFIG_SYS_MTDPARTS_RUNTIME}} with :