Difference between revisions of "How to cross-compile with the Developer Package"

[quality revision] [pending revision]
m (Adding an external out-of-tree Linux kernel module)
m (Modifying the TF-A)
 

1 Article purpose[edit]

This article provides simple examples for the Developer Package of the OpenSTLinux distribution, that illustrate cross-compilation with the SDK:

  • modification of software elements delivered as source code (for example the Linux kernel)
  • addition of software (for example the Linux kernel module or user-space applications)

These examples also show how to deploy the results of the cross-compilation on the target, through a network connection to the host machine.

Info.png There are many ways to achieve the same result; this article aims to provide at least one solution per example. You are at liberty to explore other methods that are better adapted your development constraints.

2 Prerequisites[edit]

The prerequisites from the Cross-compile with OpenSTLinux SDK article must be executed, and the cross-compilation and deployment of any piece of software, as explained in that article, is known.

The board and the host machine are connected through an Ethernet link, and a remote terminal program is started on the host machine: see How to get Terminal.

The target is started, and its IP address (<board ip address>) is known.

Info.png If you encounter a problem with any of the commands in this article, remember that the README.HOW_TO.txt helper files, from the Linux kernel, U-Boot and TF-A installation directories, are the build references.
Info.png Regarding the Linux kernel examples, it is considered that the Linux kernel has been setup, configured and built a first time in a dedicated build directory (<Linux kernel build directory> later in this page) different from the source code directory (<Linux kernel source directory> later in this document).

3 Modifying the Linux kernel configuration[edit]

3.1 Preamble[edit]

Warning.png Please read carefully and pay attention to the following point before modifying the Linux kernel configuration

The Linux kernel configuration option that you want to modify might be used by external out-of-tree Linux kernel modules (for example the GPU kernel driver), and these should then be recompiled. These modules are, by definition, outside the kernel tree structure, and are not delivered in the Developer Package source code; it is not possible to recompile them with the Developer Package. Consequently, if the Linux kernel is reconfigured and recompiled with this option then deployed on the board, the external out-of-tree Linux kernel modules might no longer be loaded.

There are two possible situations:

  • This is not a problem for the use cases on which you are currently working. In this case you can use the Developer Package to modify and recompile the Linux kernel.
  • This is a problem for the use cases on which you are currently working. In this case you need to switch on the STM32MP1 Distribution Package, and after having modified the Linux kernel configuration, use it to rebuild the whole image (that is, not only the Linux kernel but also the external out-of-tree Linux kernel modules).

Example:

  • Let's assume that the FUNCTION_TRACER and FUNCTION_GRAPH_TRACER options are activated to install the ftrace Linux kernel feature
  • This feature is used to add tracers in the whole kernel, including the external out-of-tree Linux kernel modules
  1. The Developer Package is used to reconfigure and recompile the Linux kernel, and to deploy it on the board
    1. The external out-of-tree Linux kernel modules are not recompiled. This is the case for the GPU kernel driver
    2. Consequently, the Linux kernel fails to load the GPU kernel driver module. However, even if the display no longer works, the Linux kernel boot succeeds, and the setup is sufficient, for example, to debug use cases involving an Ethernet or USB connection
  2. The Distribution Package is used to reconfigure the Linux kernel, and to rebuild and deploy the whole image on the board
    1. The external out-of-tree Linux kernel modules are recompiled, including the GPU kernel driver
    2. Consequently, the Linux kernel succeeds in loading the GPU kernel driver module. The display is available.

3.2 Simple example[edit]

This simple example modifies the value defined for the contiguous memory area (CMA) size.

  • Get the current value of the CMA size (128 Mbytes here) through the analysis of the target boot log
Board $> dmesg | grep -i cma
STM32MP157C-EV1
[    0.000000] cma: Reserved 128 MiB at 0xe8000000

STM32MP157C-DK2
[    0.000000] cma: Reserved 128 MiB at 0xd2000000


  • Go to the <Linux Linux kernel build directory>directory
PC $> cd <Linux kernel build directory>

  • Navigate to "Device Drivers - Generic Driver Options"
    • select "Size in Megabytes"
    • modify its value to 256
    • exit and save the new configuration
  • Check that the configuration file (.config) has been modified
PC $> grep -i CONFIG_CMA_SIZE_MBYTES .config
CONFIG_CMA_SIZE_MBYTES=256
  • Get the new value of the CMA size (256 Mbytes) through the analysis of the target boot log
Board $> dmesg | grep -i cma
STM32MP157C-EV1
[    0.000000] cma: Reserved 256 MiB at 0xd8000000

STM32MP157C-DK2
[    0.000000] cma: Reserved 256 MiB at 0xc2000000

4 Modifying the Linux kernel device tree[edit]

This simple example modifies the default status of a user LED.

  • With the board started; check that the user green LED (LD3 for STM32MP157C-EV1, LD5 for STM32MP157C-DK2) is disabled
  • Go to the <Linux Linux kernel source directory>directory
PC $> cd <Linux kernel source directory>

  • Edit the device tree source file to add the lines highlighted below
STM32P157C-EV1
Edit the
arch/arm/boot/dts/stm32mp15xx-edx.dtsi
device tree source file
  • Add the lines highlighted below
  • 	led {
    		compatible = "gpio-leds";
    		blue {
    			label = "heartbeat";
    			gpios = <&gpiod 9 GPIO_ACTIVE_HIGH>;
    			linux,default-trigger = "heartbeat";
    			default-state = "off";
    		};
     		green {
     			label = "stm32mp:green:user";
     			gpios = <&gpioa 14 GPIO_ACTIVE_LOW>;
     			default-state = "on";
      		};
    	};
    
    
    STM32MP157C-DK2
    Edit the
    arch/arm/boot/dts/stm32mp15xx-dkx.dtsi
    device tree source file
  • Add the lines highlighted below
  • 	led {
    		compatible = "gpio-leds";
    		blue {
    			label = "heartbeat";
    			gpios = <&gpiod 11 GPIO_ACTIVE_HIGH>;
    			linux,default-trigger = "heartbeat";
    			default-state = "off";
    		};
     		green {
     			label = "stm32mp:green:user";
     			gpios = <&gpioa 14 GPIO_ACTIVE_LOW>;
     			default-state = "on";
      		};
    	};
    
    


    • Go to the <Linux Linux kernel build directory>directory
    PC $> cd <Linux kernel build directory>
    
    
    • Generate the device tree blobs (*.dtb)
    PC $> make dtbs
    PC $> cp arch/arm/boot/dts/stm32mp157*.dtb install_artifact/boot/
    
    • Update the device tree blobs on the board
    PC $> scp install_artifact/boot/stm32mp157*.dtb root@<boardroot@<board ip address>:/boot/
    
    Info.png If the /boot mounting point doesn't exist yet, please see how to create a mounting point
    • Reboot the board
    Board $> reboot
    
    • Check that the user green LED (LD3 for STM32MP157C-EV1, LD5 for STM32MP157C-DK2) is enabled (green)

    5 Modifying a built-in Linux kernel device driver[edit]

    This simple example adds unconditional log information when the display driver is probed.

    • Check that there's no log information when the display driver is probed
    Board $> dmesg | grep -i stm_drm_platform_probe
    Board $>
    
    
    • Go to the <Linux Linux kernel source directory>directory
    PC $> cd <Linux kernel source directory>
    
    
    • Edit the ./drivers/gpu/drm/stm/drv.c source file
    • Add a log information in the stm_drm_platform_probe function
    static int stm_drm_platform_probe(struct platform_device *pdev)
    {
    	struct device *dev = &pdev->dev;
    	struct drm_device *ddev;
    	int ret;
    	[...]
    
    	DRM_INFO("Simple example - %s\n", __func__);
    
    	return 0;
    	[...]
    }
    
    • Go to the <Linux Linux kernel build directory>directory
    PC $> cd <Linux kernel build directory>
    
    
    • Cross-compile the Linux kernel (please check the load address in the README.HOW_TO.txt helper file)
    PC $> make uImage LOADADDR=0xC2000040
    PC $> cp arch/arm/boot/uImage install_artifact/boot/
    
    • Update the Linux kernel image on board
    PC $> scp install_artifact/boot/uImage root@<boardroot@<board ip address>:/boot/
    
    Info.png If the /boot mounting point doesn't exist yet, please see how to create a mounting point
    • Reboot the board
    Board $> reboot
    
    • Check that there is now log information when the display driver is probed
    Board $> dmesg | grep -i stm_drm_platform_probe
    [    2.995125] [drm] Simple example - stm_drm_platform_probe
    

    6 Modifying/adding an external Linux kernel module[edit]

    Most device drivers (modules) in the Linux kernel can be compiled either into the kernel itself (built-in/internal module) or as Loadable Kernel Modules (LKM/external module) that need to be placed in the root file system under the /lib/modules directory. An external module can be in-tree (in the kernel tree structure), or out-of-tree (outside the kernel tree structure).

    6.1 Modifying an external in-tree Linux kernel module[edit]

    This simple example adds an unconditional log information when the virtual video test driver (vivid) kernel module is probed or removed.

    • Go to the <Linux Linux kernel source directory>directory
    PC $> cd <Linux kernel source directory>
    
    
    • Edit the ./drivers/media/test-drivers/vivid/vivid-core.c source file
    • Add log information in the vivid_probe and vivid_remove functions
    static int vivid_probe(struct platform_device *pdev)
    {
    	const struct font_desc *font = find_font("VGA8x16");
    	int ret = 0, i;
    	[...]
    
    	/* n_devs will reflect the actual number of allocated devices */
    	n_devs = i;
    
    	pr_info("Simple example - %s\n", __func__);
    
    	return ret;
    }
    
    static int vivid_remove(struct platform_device *pdev)
    {
    	struct vivid_dev *dev;
    	unsigned int i, j;
    	[...]
    
    	pr_info("Simple example - %s\n", __func__);
    
    	return 0;
    }
    
    • Go to the <Linux Linux kernel build directory>directory
    PC $> cd <Linux kernel build directory>
    
    
    
    • Cross-compile the Linux kernel modules
    PC $> make modules
    PC $> make INSTALL_MOD_PATH="./install_artifact" modules_install
    
    • Remove the link on "install_artifact/lib/modules/<kernel version>/"
    PC $> rm install_artifact/lib/modules/<kernel version>/build
    PC $> rm install_artifact/lib/modules/<kernel version>/source
    
    • Optionally, strip kernel modules (to reduce the size of each kernel modules)
    PC $> find . -name "*.ko" | xargs $STRIP --strip-debug --remove-section=.comment --remove-section=.note --preserve-dates
    
    • Update the vivid kernel module on the board (please check the kernel version <kernel version>)
    PC $> scp install_artifact/lib/modules/<kernel version>/kernel/drivers/media/test-drivers/vivid/vivid.ko root@<boardroot@<board ip address>:/lib/modules/<kernel version>/kernel/drivers/media/test-drivers/vivid/
    

    OR

    PC $> scp -r install_artifact/lib/modules/* root@<boardroot@<board ip address>:/lib/modules/
    
    • Update dependency descriptions for loadable kernel modules, and synchronize the data on disk with memory
    Board $> /sbin/depmod -a
    Board $> sync
    
    • Insert the vivid kernel module into the Linux kernel
    Board $> modprobe vivid                   
    [...]
    [ 3412.784638] Simple example - vivid_probe
    
    • Remove the vivid kernel module from the Linux kernel
    Board $> rmmod vivid
    [...]
    [ 3423.708517] Simple example - vivid_remove
    

    6.2 Adding an external out-of-tree Linux kernel module[edit]

    This simple example adds a "Hello World" external out-of-tree Linux kernel module to the Linux kernel.

    • Prerequisite: the Linux source code is installed, and the Linux kernel has been cross-compiled
    • Go to the working directory that contains all the source code (that is, the directory that contains the Linux kernel, U-Boot and TF-A source code directories)
    PC $> cd <tag>/sources/arm-<distro>-linux-gnueabi
    
    • Export to KERNEL_SRC_PATH the path to the Linux kernel build directory that contains both the Linux kernel source code and the configuration file (.config)
    PC $> export KERNEL_SRC_PATH=$PWD/<Linux kernel build directory>/
    
    • Create a directory for this kernel module example
    PC $> mkdir kernel_module_example
    PC $> cd kernel_module_example
    
    • Create the source code file for this kernel module example: kernel_module_example.c
    // SPDX-identifier: GPL-2.0
    /*
     * Copyright (C) STMicroelectronics SA 2018
     *
     * Authors: Jean-Christophe Trotin <jean-christophe.trotin@st.com>
     *
     */
    
    #include <linux/module.h>    /* for all kernel modules */
    #include <linux/kernel.h>    /* for KERN_INFO */
    #include <linux/init.h>      /* for __init and __exit macros */
    
    static int __init kernel_module_example_init(void)
    {
    	printk(KERN_INFO "Kernel module example: hello world from STMicroelectronics\n");
    	return 0;
    }
    
    static void __exit kernel_module_example_exit(void)
    {
    	printk(KERN_INFO "Kernel module example: goodbye from STMicroelectronics\n");
    }
    
    module_init(kernel_module_example_init);
    module_exit(kernel_module_example_exit);
    
    MODULE_DESCRIPTION("STMicroelectronics simple external out-of-tree Linux kernel module example");
    MODULE_AUTHOR("Jean-Christophe Trotin <jean-christophe.trotin@st.com>");
    MODULE_LICENSE("GPL v2");
    
    • Create the makefile for this kernel module example: Makefile
    Info.png All the indentations in a makefile are tabulations
    # Makefile for simple external out-of-tree Linux kernel module example
    
    # Object file(s) to be built
    obj-m := kernel_module_example.o
    
    # Path to the directory that contains the Linux kernel source code
    # and the configuration file (.config)
    KERNEL_DIR ?=  $(KERNEL_SRC_PATH)
    
    # Path to the directory that contains the generated objects
    DESTDIR ?= $(KERNEL_DIR)/install_artifact
    
    # Path to the directory that contains the source file(s) to compile
    PWD := $(shell pwd) 
      
    default:
    	$(MAKE) -C $(KERNEL_DIR) M=$(PWD) modules
    
    install:
    	$(MAKE) -C $(KERNEL_DIR) M=$(PWD) INSTALL_MOD_PATH=$(DESTDIR) modules_install
    
    clean:
    	$(MAKE) -C $(KERNEL_DIR) M=$(PWD) clean
    
    • Cross-compile the kernel module example
    PC $> make clean
    PC $> make
    PC $> make install
    
    • Go to the <Linux Linux kernel build directory>directory
    PC $> cd <Linux kernel build directory>
    
    
    • The generated kernel module example is in: install_artifact/lib/modules/<kernel version>/extra/kernel_module_example.ko
    • Remove the link on "install_artifact/lib/modules/<kernel version>/"
    PC $> rm install_artifact/lib/modules/<kernel version>/build
    PC $> rm install_artifact/lib/modules/<kernel version>/source
    
    • Optionally, strip kernel modules (to reduce the size of each kernel modules)
    PC $> find . -name "*.ko" | xargs $STRIP --strip-debug --remove-section=.comment --remove-section=.note --preserve-dates
    
    • Push this kernel module example on board (please check the kernel version <kernel version>)
    PC $> ssh root@<boardroot@<board ip address> mkdir -p /lib/modules/<kernel version>/extra
    PC $> scp install_artifact/lib/modules/<kernel version>/extra/kernel_module_example.ko root@<boardroot@<board ip address>:/lib/modules/<kernel version>/extra
    

    OR

    PC $> scp -r install_artifact/lib/modules/* root@<boardroot@<board ip address>:/lib/modules/
    
    • Update dependency descriptions for loadable kernel modules, and synchronize the data on disk with memory
    Board $> /sbin/depmod -a
    Board $> sync
    
    • Insert the kernel module example into the Linux kernel
    Board $> modprobe kernel_module_example
    [18167.821725] Kernel module example: hello world from STMicroelectronics
    
    • Remove the kernel module example from the Linux kernel
    Board $> rmmod kernel_module_example
    [18180.086722] Kernel module example: goodbye from STMicroelectronics
    

    7 Modifying the U-Boot[edit]

    This simple example adds unconditional log information when U-Boot starts. Within the scope of the trusted boot chain, U-Boot is used as second stage boot loader (SSBL).

    • Have a look at the U-Boot log information when the board reboots
    Board $> reboot
    


    STM32MP157C-EV1
    [...]
    U-Boot <U-Boot version> (<U-Boot build time flag>)
    CPU: STM32MP157CAA Rev.B
    Model: STMicroelectronics STM32MP157C eval daughter on eval mother
    Board: stm32mp1 in trusted mode (st,stm32mp157c-ev1)
    [...]
    
    
    STM32MP157C-DK2
    [...]
    U-Boot <U-Boot version> (<U-Boot build time flag>)""
    CPU: STM32MP157CAC Rev.B
    Model: STMicroelectronics STM32MP157C-DK2 Discovery Board
    Board: stm32mp1 in trusted mode (st,stm32mp157c-dk2)
    [...]
    
    


    • Go to the <UU-Boot source directory>directory
    PC $> cd <U-Boot source directory>
    
    

    Example:

    PC $> cd <U-Boot source directory>

    • Edit the ./board/st/stm32mp1/stm32mp1.c source file Add to add a log information in the checkboard function
    int checkboard(void)
    {
    	int ret;
          char *mode;
    
    	[...]
    	puts("\n");
    	printf("U-Boot simple example\n");
    	[...]
    
    	return 0;
    }
    
    • Get the list of supported configurations with the following command
    PC $> make -f $PWD/../Makefile.sdk help
    


    stm32 legacy images case building (no FIP)

    • Enable CONFIG_STM32MP15x_STM32IMAGE in your defconfig (i.e. configs/stm32mp15_trusted_defconfig)
    • Cross-compile the U-Boot: here trusted boot for STM32MP157C-EV1 and STM32MP157C-DK2
    PC $> make -f $PWD/../Makefile.sdk all UBOOT_CONFIGS=stm32mp15_trusted_defconfig,trusted,u-boot.stm32 ENABLE_FIP=0
    
    
    • Go to the directory where the compilation results are stored
    PC $> cd ../deploy/
    
    
    • Reboot the board, and hit any key to stop in the U-boot shell
    Board $> reboot
    [...]
    Hit any key to stop autoboot:  0 
    STM32MP> 
    
    
    • Connect a USB cable between the host machine and the board via the USB OTG ports
    • In the U-Boot shell, call the USB mass storage function
    STM32MP> ums 0 mmc 0
    
    
    Info.png For more information about the usage of U-Boot UMS functionality, see How to use USB mass storage in U-Boot


    • On the host machine, check the partition associated with the secondary stage boot loader (ssbl): sdb3 here
    PC $> ls -l /dev/disk/by-partlabel/
    total 0
    lrwxrwxrwx 1 root root 10 Feb  8 08:57 bootfs -> ../../sdb4
    lrwxrwxrwx 1 root root 10 Feb  8 08:57 fsbl1 -> ../../sdb1
    lrwxrwxrwx 1 root root 10 Feb  8 08:57 fsbl2 -> ../../sdb2
    lrwxrwxrwx 1 root root 10 Feb  8 08:57 rootfs -> ../../sdb6
    lrwxrwxrwx 1 root root 10 Feb  8 08:57 ssbl -> ../../sdb3
    lrwxrwxrwx 1 root root 10 Feb  8 08:57 userfs -> ../../sdb7
    lrwxrwxrwx 1 root root 10 Feb  8 08:57 vendorfs -> ../../sdb5
    
    
    • Copy the U-Boot binary to the dedicated partition
    STM32MP157C-EV1
    PC $> dd if=u-boot-stm32mp157c-ev1-trusted.stm32 of=/dev/sdb3 bs=1M conv=fdatasync
    
    
    STM32MP157C-DK2
    PC $> dd if=u-boot-stm32mp157c-dk2-trusted.stm32 of=/dev/sdb3 bs=1M conv=fdatasync
    
    

    or

    FIP images case building (Default)

    • As mentionned in help, OpenSTLinux has activated FIP by default, so the "FIP_artifacts" folder should be specified to allow to update the FIP binary with the new U-Boot binary. When using the "SOURCES-xxxx.tar.gz" from Developer package the "FIP_DEPLOYDIR_ROOT" var should be set as below:
    PC $> export FIP_DEPLOYDIR_ROOT=$PWD/../../FIP_artifacts
    
    
    • Note that to keep the original FIP binary, the "FIP_DEPLOYDIR_FIP" var should be set as below:
    PC $> export FIP_DEPLOYDIR_FIP=$PWD/../deploy/fip
    
    
    • Cross-compile the U-Boot: here trusted boot for STM32MP157C-EV1 and STM32MP157C-DK2
    PC $> make -f $PWD/../Makefile.sdk all UBOOT_CONFIGS=stm32mp15_trusted_defconfig,trusted,u-boot.dtb DEVICE_TREE="stm32mp157c-ev1-trusted stm32mp157c-dk2"
    
    
    • Go to the directory where the compilation results are stored
    PC $> cd $FIP_DEPLOYDIR_FIP
    
    
    • Reboot the board, and hit any key to stop in the U-boot shell
    Board $> reboot
    [...]
    Hit any key to stop autoboot:  0 
    STM32MP> 
    
    
    • Connect a USB cable between the host machine and the board via the USB OTG ports
    • In the U-Boot shell, call the USB mass storage function
    STM32MP> ums 0 mmc 0
    
    
    Info.png For more information about the usage of U-Boot UMS functionality, see How to use USB mass storage in U-Boot


    • On the host machine, check the partition associated with the secondary stage boot loader that contains the FIP binary (fip): sdb3 here
    PC $> ls -l /dev/disk/by-partlabel/
    total 0
    lrwxrwxrwx 1 root root 10 Feb  8 08:57 bootfs -> ../../sdb4
    lrwxrwxrwx 1 root root 10 Feb  8 08:57 fsbl1 -> ../../sdb1
    lrwxrwxrwx 1 root root 10 Feb  8 08:57 fsbl2 -> ../../sdb2
    lrwxrwxrwx 1 root root 10 Feb  8 08:57 rootfs -> ../../sdb6
    lrwxrwxrwx 1 root root 10 Feb  8 08:57 fip -> ../../sdb3
    lrwxrwxrwx 1 root root 10 Feb  8 08:57 userfs -> ../../sdb7
    lrwxrwxrwx 1 root root 10 Feb  8 08:57 vendorfs -> ../../sdb5
    
    
    • Copy the FIP binary to the dedicated partition
    STM32MP157C-EV1
    PC $> dd if=fip-stm32mp157c-ev1-trusted.bin of=/dev/sdb3 bs=1M conv=fdatasync
    
    
    STM32MP157C-DK2
    PC $> dd if=fip-stm32mp157c-dk2-trusted.bin of=/dev/sdb3 bs=1M conv=fdatasync
    
    
    • Reset the U-Boot shell
    STM32MP> reset
    
    • Have a look at the new U-Boot log information when the board reboots
    STM32MP157C-EV1
    [...]
    U-Boot <U-Boot version> (<U-Boot build time flag>)
    CPU: STM32MP157CAA Rev.B
    Model: STMicroelectronics STM32MP157C eval daughter on eval mother
    Board: stm32mp1 in trusted mode (st,stm32mp157c-ev1)
    U-Boot simple example
    [...]
    
    
    STM32MP157C-DK2
    [...]
    U-Boot <U-Boot version> (<U-Boot build time flag>)
    CPU: STM32MP157CAC Rev.B
    Model: STMicroelectronics STM32MP157C-DK2 Discovery Board
    Board: stm32mp1 in trusted mode (st,stm32mp157c-dk2)
    U-Boot simple example
    [...]
    
    

    8 Modifying the TF-A[edit]

    This simple example adds unconditional log information when the TF-A starts. Within the scope of the trusted boot chain, TF-A is used as first stage boot loader (FSBL).

    • Have a look at the TF-A log information when the board reboots
    Board $> reboot
    [...]
    INFO:      System reset generated by MPU (MPSYSRST)
    INFO:    PMIC version = 0x10
    INFO:    Using SDMMC
    [...]
    
    • Go to the <TFTF-A source directory>directory
    PC $> cd <TF-A source directory>
    
    

    Example:

    • Edit the ./plat/st/stm32mp1/bl2_plat_setup.c source file Add to add a log information in the print_reset_reason function
    static void print_reset_reason(void)
    {
    	[...]
    	INFO("Reset reason (0x%x):\n", rstsr);
    
    	INFO("TF-A simple example\n");
    	[...]
    }
    
    • Get the list of supported configurations with the following command
    PC $> make -f $PWD/../Makefile.sdk help
    


    stm32 legacy images case building (no FIP)

    Under construction.png This section to be reviewed
    • Cross-compile the TF-A: here trusted boot for STM32MP157C-EV1 and STM32MP157C-DK2
    for microSD card
    PC $> make -f $PWD/../Makefile.sdk 
    
    stm32
    TF_A_CONFIG=
    
    "sdcard"
    trusted ENABLE_FIP=0 all
    
    
    • Go to the directory in which the compilation results are stored
    PC $> cd ../deploy
    
    
    • Reboot the board, and hit any key to stop in the U-boot shell
    Board $> reboot
    [...]
    Hit any key to stop autoboot:  0 
    STM32MP> 
    
    
    • Connect a USB cable between the host machine and the board via the USB OTG ports
    • In the U-Boot shell, call the USB mass storage function
    STM32MP> ums 0 mmc 0
    
    
    Info.png For more information about the usage of U-Boot UMS functionality, see How to use USB mass storage in U-Boot
    • On the host machine, check the partition associated with the first stage boot loader (fsbl1 and fsbl2 as backup): sdb1 and sdb2 (as backup) here
    PC $> ls -l /dev/disk/by-partlabel/
    total 0
    lrwxrwxrwx 1 root root 10 Feb  8 10:01 bootfs -> ../../sdb4
    lrwxrwxrwx 1 root root 10 Feb  8 10:01 fsbl1 -> ../../sdb1
    lrwxrwxrwx 1 root root 10 Feb  8 10:01 fsbl2 -> ../../sdb2
    lrwxrwxrwx 1 root root 10 Feb  8 10:01 rootfs -> ../../sdb6
    lrwxrwxrwx 1 root root 10 Feb  8 10:01 
    
    fip
    ssbl -> ../../sdb3
    lrwxrwxrwx 1 root root 10 Feb  8 10:01 userfs -> ../../sdb7
    lrwxrwxrwx 1 root root 10 Feb  8 10:01 vendorfs -> ../../sdb5
    
    
    • Copy the TF-A binary to the dedicated partition; to test the new TF-A binary, it might be useful to keep the old TF-A binary in the backup FSBL (fsbl2)
    STM32MP157C-EV1
    PC $> dd if=tf-a-stm32mp157c-ev1-
    
    sdcard
    trusted.stm32 of=/dev/sdb1 bs=1M conv=fdatasync
    
    
    STM32MP157C-DK2
    PC $> dd if=tf-a-stm32mp157c-dk2-trusted.stm32 of=/dev/sdb1 bs=1M conv=fdatasync
    
    
    Info.png In case you get a permission denied you can set more permission on /dev/sdb1 : sudo chmod 777 /dev/sdb1


    • Reset the U-Boot shell

    In the U-Boot shell, press Ctrl+C prior to get hand back.

    STM32MP> reset
    
    
    • Have a look at the new TF-A log information when the board reboots
    [...]
    INFO:      System reset generated by MPU (MPSYSRST)
    INFO:    TF-A simple example
    INFO:    PMIC version = 0x10
    INFO:    Using SDMMC
    [...]
    
    

    or

    FIP images case building (Default)

    • Cross-compile the TF-A: here trusted boot for STM32MP157C-EV1 and STM32MP157C-DK2 for microSD card
    PC $> make -f $PWD/../Makefile.sdk stm32 TF_A_CONFIG="sdcard"
    
    
    • Go to the directory in which the compilation results are stored
    PC $> cd ../deploy
    
    
    • Reboot the board, and hit any key to stop in the U-boot shell
    Board $> reboot
    [...]
    Hit any key to stop autoboot:  0 
    STM32MP> 
    
    
    • Connect a USB cable between the host machine and the board via the USB OTG ports
    • In the U-Boot shell, call the USB mass storage function
    STM32MP> ums 0 mmc 0
    
    
    Info.png For more information about the usage of U-Boot UMS functionality, see How to use USB mass storage in U-Boot
    • On the host machine, check the partition associated with the first stage boot loader (fsbl1 and fsbl2 as backup): sdb1 and sdb2 (as backup) here
    PC $> ls -l /dev/disk/by-partlabel/
    total 0
    lrwxrwxrwx 1 root root 10 Feb  8 10:01 bootfs -> ../../sdb4
    lrwxrwxrwx 1 root root 10 Feb  8 10:01 fsbl1 -> ../../sdb1
    lrwxrwxrwx 1 root root 10 Feb  8 10:01 fsbl2 -> ../../sdb2
    lrwxrwxrwx 1 root root 10 Feb  8 10:01 rootfs -> ../../sdb6
    lrwxrwxrwx 1 root root 10 Feb  8 10:01 fip -> ../../sdb3
    lrwxrwxrwx 1 root root 10 Feb  8 10:01 userfs -> ../../sdb7
    lrwxrwxrwx 1 root root 10 Feb  8 10:01 vendorfs -> ../../sdb5
    
    
    • Copy the TF-A binary to the dedicated partition; to test the new TF-A binary, it might be useful to keep the old TF-A binary in the backup FSBL (fsbl2)
    STM32MP157C-EV1
    PC $> dd if=tf-a-stm32mp157c-ev1-sdcard.stm32 of=/dev/sdb1 bs=1M conv=fdatasync
    
    
    STM32MP157C-DK2
    PC $> dd if=tf-a-stm32mp157c-dk2-sdcard.stm32 of=/dev/sdb1 bs=1M conv=fdatasync
    
    
    Info.png In case you get a permission denied you can set more permission on /dev/sdb1 : sudo chmod 777 /dev/sdb1


    • Reset the U-Boot shell

    In the U-Boot shell, press Ctrl+C prior to get hand back.

    STM32MP> reset
    
    
    • Have a look at the new TF-A log information when the board reboots
    [...]
    INFO:      System reset generated by MPU (MPSYSRST)
    INFO:    TF-A simple example
    INFO:    PMIC version = 0x10
    INFO:    Using SDMMC
    [...]
    
    
    • Note that according to the modification done on TF-A source code, the FIP binary may need also to be updated. In such case, to cross-compile the TF-A trusted boot for STM32MP157C-EV1 and STM32MP157C-DK2 for microSD card with FIP binary update, follow the steps:
    • The "FIP_artifacts" folder should be specified to allow to update the FIP binary with the new U-Boot binary. When using the "SOURCES-xxxx.tar.gz" from Developer package the "FIP_DEPLOYDIR_ROOT" var should be set as below:
    PC $> export FIP_DEPLOYDIR_ROOT=$PWD/../../FIP_artifacts
    
    
    • To keep the original FIP binary, the "FIP_DEPLOYDIR_FIP" var should be set as below:
    PC $> export FIP_DEPLOYDIR_FIP=$PWD/../deploy/fip
    
    
    • Launch cross-compilation (trusted boot for STM32MP157C-EV1 and STM32MP157C-DK2 for microSD):
    PC $> make -f $PWD/../Makefile.sdk all TF_A_CONFIG="sdcard trusted" FIP_CONFIG=trusted
    
    
    • Go to the directory in which the compilation results are stored
    PC $> cd $FIP_DEPLOYDIR_FIP
    
    
    • Reboot the board, and hit any key to stop in the U-boot shell
    Board $> reboot
    [...]
    Hit any key to stop autoboot:  0 
    STM32MP> 
    
    
    • Connect a USB cable between the host machine and the board via the USB OTG ports
    • In the U-Boot shell, call the USB mass storage function
    STM32MP> ums 0 mmc 0
    
    
    Info.png For more information about the usage of U-Boot UMS functionality, see How to use USB mass storage in U-Boot
    • On the host machine, check the partition associated with the second stage boot loader that contains the FIP binary (fip): sdb3"
    PC $> ls -l /dev/disk/by-partlabel/
    total 0
    lrwxrwxrwx 1 root root 10 Feb  8 10:01 bootfs -> ../../sdb4
    lrwxrwxrwx 1 root root 10 Feb  8 10:01 Highlight|fsbl1 -> ../../sdb1
    lrwxrwxrwx 1 root root 10 Feb  8 10:01 Highlight|fsbl2 -> ../../sdb2
    lrwxrwxrwx 1 root root 10 Feb  8 10:01 rootfs -> ../../sdb6
    lrwxrwxrwx 1 root root 10 Feb  8 10:01 fip -> ../../sdb3
    lrwxrwxrwx 1 root root 10 Feb  8 10:01 userfs -> ../../sdb7
    lrwxrwxrwx 1 root root 10 Feb  8 10:01 vendorfs -> ../../sdb5
    
    
    • Copy the FIP binary to the dedicated partition
    STM32MP157C-EV1
    PC $> dd if=fip-stm32mp157c-ev1-trusted.bin of=/dev/sdb3 bs=1M conv=fdatasync
    
    
    Info.png In case you get a permission denied you can set more permission on /dev/sdb1 : sudo chmod 777 /dev/sdb3
    STM32MP157C-DK2
    PC $> dd if=fip-stm32mp157c-dk2-trusted.bin of=/dev/sdb3 bs=1M conv=fdatasync
    
    
    Info.png In case you get a permission denied you can set more permission on /dev/sdb3 : sudo chmod 777 /dev/sdb3
    • Reset the U-Boot shell

    In the U-Boot shell, press Ctrl+C prior to get hand back.

    STM32MP> reset
    

    9 Adding a "hello world" user space example[edit]

    Thanks to the OpenSTLinux SDK, it is easy to develop a project outside of the OpenEmbedded build system. This chapter shows how to compile and execute a simple "hello world" example.

    9.1 Source code file[edit]

    • Go to the working directory that contains all the source codes (i.e. directory that contains the Linux kernel, U-Boot and TF-A source code directories)
    PC $> cd <tag>/sources/arm-<distro>-linux-gnueabi
    
    • Create a directory for this user space example
    PC $> mkdir hello_world_example
    PC $> cd hello_world_example
    
    • Create the source code file for this user space example: hello_world_example.c
    // SPDX-identifier: GPL-2.0
    /*
     * Copyright (C) STMicroelectronics SA 2018
     *
     * Authors: Jean-Christophe Trotin <jean-christophe.trotin@st.com>
     *
     */
    
    #include <stdio.h>
    #include <unistd.h>
    
    int main(int argc, char **argv)
    {
    	int i =11;
    
    	printf("\nUser space example: hello world from STMicroelectronics\n");
    	setbuf(stdout,NULL);
    	while (i--) {
    		printf("%i ", i);
    		sleep(1);
    	}
    	printf("\nUser space example: goodbye from STMicroelectronics\n");
    
    	return(0);
    }
    

    9.2 Cross-compilation[edit]

    Three ways to use the OpenSTLinux SDK to cross-compile this user space example are proposed below: (1) command line (2) makefile-based project (3) autotools-based project.

    9.2.1 Command line[edit]

    This method allows quick cross-compilation of a single-source code file. It applies if the project has only one file.
    The cross-development toolchain is associated with the sysroot that contains the header files and libraries needed for generating binaries that run on the target architecture (see SDK for OpenSTLinux distribution#Native and target sysroots).
    The sysroot location is specified with the --sysroot option.

    The sysroot location must be specified using the --sysroot option. The CC environment variable created by the SDK already includes the --sysroot option that points to the SDK sysroot location.

    PC $> echo $CC
    arm-ostl-linux-gnueabi-gcc -march=armv7ve -mthumb -mfpu=neon-vfpv4 -mfloat-abi=hard -mcpu=cortex-a7 --sysroot=<SDK installation directory>/SDK/sysroots/cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi
    
    • Create the directory in which the generated binary is to be stored
    PC $> mkdir -p install_artifact install_artifact/usr install_artifact/usr/local install_artifact/usr/local/bin
    
    • Cross-compile the single source code file for the user space example
    PC $> $CC hello_world_example.c -o ./install_artifact/usr/local/bin/hello_world_example
    

    9.2.2 Makefile-based project[edit]

    For this method, the cross-toolchain environment variables established by running the cross-toolchain environment setup script are subject to general make rules.
    For example, see the following environment variables:

    PC $> echo $CC
    arm-ostl-linux-gnueabi-gcc -march=armv7ve -mthumb -mfpu=neon-vfpv4 -mfloat-abi=hard -mcpu=cortex-a7 --sysroot=<SDK installation directory>/SDK/sysroots/cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi
    PC $> echo $CFLAGS
    -O2 -pipe -g -feliminate-unused-debug-types
    PC $> echo $LDFLAGS
    -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed
    PC $> echo $LD
    arm-ostl-linux-gnueabi-ld --sysroot=<SDK installation directory>/SDK/sysroots/cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi
    
    • Create the makefile for this user space example: Makefile
    Info.png All the indentations in a makefile are tabulations
    PROG = hello_world_example
    SRCS = hello_world_example.c
    OBJS = $(SRCS:.c=.o)
    
    CLEANFILES = $(PROG)
    INSTALL_DIR = ./install_artifact/usr/local/bin
    
    # Add / change option in CFLAGS if needed
    # CFLAGS += <new option>
    
    $(PROG):  $(OBJS)
    	$(CC) $(CFLAGS) -o $(PROG) $(OBJS)
    
    .c.o:
    	$(CC) $(CFLAGS) -c $< -o $@
    
    all: $(PROG)
     
     
    clean:
    	rm -f $(CLEANFILES) $(patsubst %.c,%.o, $(SRCS)) *~
    
    install: $(PROG)
    	mkdir -p $(INSTALL_DIR)
    	install $(PROG) $(INSTALL_DIR)
    
    • Cross-compile the project
    PC $> make
    PC $> make install
    

    9.2.3 Autotools-based project[edit]

    This method creates a project based on GNU autotools.

    • Create the makefile for this user space example: Makefile.am
    bin_PROGRAMS = hello_world_example
    hello_world_example_SOURCES = hello_world_example.c
    
    • Create the configuration file for this user space example: configure.ac
    AC_INIT(hello_world_example,0.1)
    AM_INIT_AUTOMAKE([foreign])
    AC_PROG_CC
    AC_PROG_INSTALL
    AC_OUTPUT(Makefile)
    
    • Generate the local aclocal.m4 files and create the configure script
    PC $> aclocal
    PC $> autoconf
    
    • Generate the files needed by GNU coding standards (for compliance)
    PC $> touch NEWS README AUTHORS ChangeLog
    
    • Generate the links towards SDK scripts
    PC $> automake -a
                           
    
    • Cross-compile the project
    PC $> ./configure ${CONFIGURE_FLAGS}
    PC $> make
    PC $> make install DESTDIR=./install_artifact
    

    9.3 Deploy and execute on board[edit]

    • Check that the generated binary for this user space example is in: ./install_artifact/usr/local/bin/hello_world_example
    • Push this binary onto the board
    PC $> scp -r install_artifact/* root@<board ip address>:/
    
    • Execute this user space example
    Board $> cd /usr/local/bin
    Board $> ./hello_world_example 
    
    User space example: hello world from STMicroelectronics
    10 9 8 7 6 5 4 3 2 1 0 
    User space example: goodbye from STMicroelectronics
    

    10 Tips[edit]

    10.1 Creating a mounting point[edit]

    The objective is to create a mounting point for the boot file system (bootfs partition)

    • Find the partition label associated with the boot file system
    Board $> ls -l /dev/disk/by-partlabel/
    total 0
    lrwxrwxrwx 1 root root 15 Jan 23 17:00 bootfs -> ../../mmcblk0p4
    lrwxrwxrwx 1 root root 15 Jan 23 17:00 fsbl1 -> ../../mmcblk0p1
    lrwxrwxrwx 1 root root 15 Jan 23 17:00 fsbl2 -> ../../mmcblk0p2
    lrwxrwxrwx 1 root root 15 Jan 23 17:00 rootfs -> ../../mmcblk0p6
    lrwxrwxrwx 1 root root 15 Jan 23 17:00 fip -> ../../mmcblk0p3
    lrwxrwxrwx 1 root root 15 Jan 23 17:00 userfs -> ../../mmcblk0p7
    lrwxrwxrwx 1 root root 15 Jan 23 17:00 vendorfs -> ../../mmcblk0p5
    
    • Attach the boot file system found under /dev/mmcblk0p4 in the directory /boot
    Board $> mount /dev/mmcblk0p4 /boot
    


    ==Article purpose==
    This article provides simple examples for the Developer Package of the OpenSTLinux distribution, that illustrate cross-compilation with the [[SDK for OpenSTLinux distribution|SDK]]:
    * modification of software elements delivered as source code (for example the Linux kernel)
    * addition of software (for example the Linux kernel module or user-space applications)
    These examples also show how to deploy the results of the cross-compilation on the target, through a network connection to the host machine.
    
    {{info|There are many ways to achieve the same result; this article aims to provide at least one solution per example. You are at liberty to explore other methods that are better adapted your development constraints.}}
    
    ==Prerequisites==
    The prerequisites from the [[Cross-compile with OpenSTLinux SDK]] article must be executed, and the cross-compilation and deployment of any piece of software, as explained in that article, is known.
    
    The board and the host machine are connected through an Ethernet link, and a remote terminal program is started on the host machine: see [[How to get Terminal]].
    
    The target is started, and its IP address (<board ip address>) is known.
    
    {{info|If you encounter a problem with any of the commands in this article, remember that the README.HOW_TO.txt helper files, from the Linux kernel, U-Boot and TF-A installation directories, are '''the''' build references.}}
    
    {{info|Regarding the Linux kernel examples, it is considered that the Linux kernel has been setup, configured and built a first time in a dedicated build directory (''<Linux kernel build directory>'' later in this page) different from the source code directory (''<Linux kernel source directory>'' later in this document).}}
    
    ==Modifying the Linux kernel configuration==
    ===Preamble===
    {{Warning|Please read carefully and pay attention to the following point before modifying the Linux kernel configuration}}
    The Linux kernel configuration option that you want to modify might be used by external out-of-tree Linux kernel modules (for example the GPU kernel driver), and these should then be recompiled. These modules are, by definition, outside the kernel tree structure, and are not delivered in the Developer Package source code; it is not possible to recompile them with the Developer Package. Consequently, if the Linux kernel is reconfigured and recompiled with this option then deployed on the board, the external out-of-tree Linux kernel modules might no longer be loaded.
    
    There are two possible situations:
    * This is not a problem for the use cases on which you are currently working. In this case you can use the Developer Package to modify and recompile the Linux kernel.
    * This is a problem for the use cases on which you are currently working. In this case you need to switch on the [[STM32MP1 Distribution Package]], and after having modified the Linux kernel configuration, use it to rebuild the whole image (that is, not only the Linux kernel but also the external out-of-tree Linux kernel modules).
    
    Example:
    * Let's assume that the FUNCTION_TRACER and FUNCTION_GRAPH_TRACER options are activated to install the [[Ftrace|ftrace]] Linux kernel feature
    * This feature is used to add tracers in the whole kernel, including the external out-of-tree Linux kernel modules
    # The Developer Package is used to reconfigure and recompile the Linux kernel, and to deploy it on the board
    ## The external out-of-tree Linux kernel modules are not recompiled. This is the case for the GPU kernel driver
    ## Consequently, the Linux kernel fails to load the GPU kernel driver module. However, even if the display no longer works, the Linux kernel boot succeeds, and the setup is sufficient, for example, to debug use cases involving an Ethernet or USB connection
    # The Distribution Package is used to reconfigure the Linux kernel, and to rebuild and deploy the whole image on the board
    ## The external out-of-tree Linux kernel modules are recompiled, including the GPU kernel driver
    ## Consequently, the Linux kernel succeeds in loading the GPU kernel driver module. The display is available.
    
    ===Simple example===
    This simple example modifies the value defined for the contiguous memory area (CMA) size.
    * Get the current value of the CMA size (128 Mbytes here) through the analysis of the target boot log
     {{Board$}} dmesg | grep -i cma''STM32MP157C-EV1''{|
    ||'''STM32MP157C-EV1'''
    ||[    0.000000] cma: Reserved 128 MiB at 0xe8000000''STM32MP157C-DK2''|-
    || '''STM32MP157C-DK2'''
    ||[    0.000000] cma: Reserved 128 MiB at 0xd2000000
    |}
    * Go to the <Linux kernel build directory>Linux  {{PC$}} cd <Linux kernel build directory>kernel build directory
     {{PC$}} cd {{HighlightParam|''<Linux kernel build directory>''}}
    
    
    * Start the Linux kernel configuration menu: see [[Menuconfig or how to configure kernel#Menuconfig and Developer Package|Menuconfig or how to configure kernel]]
    
    * Navigate to "Device Drivers - Generic Driver Options"
    ** select "Size in Megabytes"
    ** modify its value to 256
    ** exit and save the new configuration
    
    * Check that the configuration file (''.config'') has been modified
     {{PC$}} grep -i CONFIG_CMA_SIZE_MBYTES .config
     CONFIG_CMA_SIZE_MBYTES=256
    
    * Cross-compile the Linux kernel: see [[Menuconfig or how to configure kernel#Menuconfig and Developer Package|Menuconfig or how to configure kernel]]
    
    * Update the Linux kernel image on board: see [[Menuconfig or how to configure kernel#Menuconfig and Developer Package|Menuconfig or how to configure kernel]]
    
    * Reboot the board: see [[Menuconfig or how to configure kernel#Menuconfig and Developer Package|Menuconfig or how to configure kernel]]
    
    * Get the new value of the CMA size (256 Mbytes) through the analysis of the target boot log
     {{Board$}} dmesg | grep -i cma''STM32MP157C-EV1''{|
    || '''STM32MP157C-EV1'''
    ||[    0.000000] cma: Reserved {{Highlight|256}} MiB at 0xd8000000''STM32MP157C-DK2''|-
    || '''STM32MP157C-DK2'''
    ||[    0.000000] cma: Reserved {{Highlight|256}} MiB at 0xc2000000
    |}
    ==Modifying the Linux kernel device tree==
    This simple example modifies the default status of a user LED.
    
    * With the board started; check that the user green LED (LD3 for STM32MP157C-EV1, LD5 for STM32MP157C-DK2) is disabled
    
    * Go to the <Linux kernel source directory>Linux  {{PC$}} cd <Linux kernel source directory>
    
    
    ''STM32P157C-EV1''
    * Edit the ''arch/arm/boot/dts/stm32mp15xx-edx.dtsi'' kernel source directory
     {{PC$}} cd {{HighlightParam|''<Linux kernel source directory>''}}
    * Edit the device tree source file * Addto add the lines highlighted below {|
    || '''STM32P157C-EV1'''
    || arch/arm/boot/dts/{{HighlightParam|stm32mp15xx-edx}}.dtsi
    ||	led {
     		compatible = "gpio-leds";
     		blue {
     			label = "heartbeat";
     			gpios = <&gpiod 9 GPIO_ACTIVE_HIGH>;
     			linux,default-trigger = "heartbeat";
     			default-state = "off";
     		};
      		{{Highlight|green &#123;}}
      			{{Highlight|label &#61; "stm32mp:green:user";}}
      			{{Highlight|gpios &#61; <&gpioa 14 GPIO_ACTIVE_LOW>;}}
      			{{Highlight|default-state &#61; "on";}}
       		{{Highlight|&#125;;}}
     	};
    
    ''STM32MP157C-DK2''
    * Edit the ''|-
    || '''STM32MP157C-DK2'''
    || arch/arm/boot/dts/{{HighlightParam|stm32mp15xx-dkx}}.dtsi'' device tree source file
    * Add the lines highlighted below
    
    ||	led {
     		compatible = "gpio-leds";
     		blue {
     			label = "heartbeat";
     			gpios = <&gpiod 11 GPIO_ACTIVE_HIGH>;
     			linux,default-trigger = "heartbeat";
     			default-state = "off";
     		};
      		{{Highlight|green &#123;}}
      			{{Highlight|label &#61; "stm32mp:green:user";}}
      			{{Highlight|gpios &#61; <&gpioa 14 GPIO_ACTIVE_LOW>;}}
      			{{Highlight|default-state &#61; "on";}}
       		{{Highlight|&#125;;}}
     	};
    |}
    * Go to the <Linux kernel build directory>Linux  {{PC$}} cd <Linux kernel build directory>kernel build directory
     {{PC$}} cd {{HighlightParam|''<Linux kernel build directory>''}}
    
    
    * Generate the device tree blobs (''*.dtb'')
     {{PC$}} make dtbs
     {{PC$}} cp arch/arm/boot/dts/stm32mp157*.dtb install_artifact/boot/
    
    * Update the device tree blobs on the board
     {{PC$}} scp install_artifact/boot/stm32mp157*.dtb root@<board ip address>{{HighlightParam|''<board ip address>''}}:/boot/
    {{Info|If the ''/boot'' mounting point doesn't exist yet, please see [[#Creating a mounting point|how to create a mounting point]]}}
    
    * Reboot the board
     {{Board$}} reboot
    
    * Check that the user green LED (LD3 for STM32MP157C-EV1, LD5 for STM32MP157C-DK2) is {{Highlight|enabled}} (green)
    
    ==Modifying a built-in Linux kernel device driver==
    This simple example adds unconditional log information when the display driver is probed.<br><br>
    
    
    * Check that there's no log information when the display driver is probed
     {{Board$}} dmesg | grep -i stm_drm_platform_probe
     {{Board$}}
    
    * Go to the <Linux kernel source directory>Linux  {{PC$}} cd <Linux kernel source directory>kernel source directory
     {{PC$}} cd {{HighlightParam|''<Linux kernel source directory>''}}
    
    
    * Edit the ''./drivers/gpu/drm/stm/drv.c'' source file
    * Add a log information in the ''stm_drm_platform_probe'' function
     static int stm_drm_platform_probe(struct platform_device *pdev)
     {
     	struct device *dev = &pdev->dev;
     	struct drm_device *ddev;
     	int ret;
     	[...]
    
     	{{Highlight|DRM_INFO("Simple example - %s\n", __func__);}}
    
     	return 0;
     	[...]
     }
    
    * Go to the <Linux kernel build directory>Linux  {{PC$}} cd <Linux kernel build directory>kernel build directory
     {{PC$}} cd {{HighlightParam|''<Linux kernel build directory>''}}
    
    
    * Cross-compile the Linux kernel ({{Highlight|please check the load address in the ''README.HOW_TO.txt'' helper file}})
     {{PC$}} make uImage LOADADDR={{Highlight|0xC2000040}}
    
     {{PC$}} cp arch/arm/boot/uImage install_artifact/boot/
    
    * Update the Linux kernel image on board
     {{PC$}} scp install_artifact/boot/uImage root@<board ip address>{{HighlightParam|''<board ip address>''}}:/boot/
    {{Info|If the ''/boot'' mounting point doesn't exist yet, please see [[#Creating a mounting point|how to create a mounting point]]}}
    
    * Reboot the board
     {{Board$}} reboot
    
    * Check that there is now log information when the display driver is probed
     {{Board$}} dmesg | grep -i stm_drm_platform_probe
     [    2.995125] [drm] {{Highlight|Simple example}} - stm_drm_platform_probe
    
    ==Modifying/adding an external Linux kernel module==
    Most device drivers (modules) in the Linux kernel can be compiled either into the kernel itself (built-in/internal module) or as Loadable Kernel Modules (LKM/external module) that need to be placed in the root file system under the /lib/modules directory. An external module can be in-tree (in the kernel tree structure), or out-of-tree (outside the kernel tree structure).
    
    ===Modifying an external in-tree Linux kernel module===
    This simple example adds an unconditional log information when the virtual video test driver (vivid) kernel module is probed or removed.<br><br>
    
    
    * Go to the <Linux kernel source directory>Linux  {{PC$}} cd <Linux kernel source directory>kernel source directory
     {{PC$}} cd {{HighlightParam|''<Linux kernel source directory>''}}
    
    
    * Edit the ''./drivers/media/test-drivers/vivid/vivid-core.c'' source file
    * Add log information in the ''vivid_probe'' and ''vivid_remove'' functions
     static int vivid_probe(struct platform_device *pdev)
     {
     	const struct font_desc *font = find_font("VGA8x16");
     	int ret = 0, i;
     	[...]
    
     	/* n_devs will reflect the actual number of allocated devices */
     	n_devs = i;
    
     	{{Highlight|pr_info("Simple example - %s\n", __func__)}};
    
     	return ret;
     }
    
     static int vivid_remove(struct platform_device *pdev)
     {
     	struct vivid_dev *dev;
     	unsigned int i, j;
     	[...]
    
     	{{Highlight|pr_info("Simple example - %s\n", __func__)}};
    
     	return 0;
     }
    
    * Go to the <Linux kernel build directory>Linux  {{PC$}} cd <Linux kernel build directory>kernel build directory
     {{PC$}} cd {{HighlightParam|''<Linux kernel build directory>''}}
    
    
    * Cross-compile the Linux kernel modules
     {{PC$}} make modules
     {{PC$}} make INSTALL_MOD_PATH="./install_artifact" modules_install
    
    * Remove the link on "''install_artifact/lib/modules/{{HighlightParam|<kernel version>/"}}/''
    
     {{PC$}} rm install_artifact/lib/modules/<kernel version>{{HighlightParam|''<kernel version>''}}/build
     {{PC$}} rm install_artifact/lib/modules/<kernel version>{{HighlightParam|''<kernel version>''}}/source
    
    * Optionally, strip kernel modules (to reduce the size of each kernel modules)
     {{PC$}} find . -name "*.ko" | xargs $STRIP --strip-debug --remove-section=.comment --remove-section=.note --preserve-dates
    
    * Update the vivid kernel module on the board (please check the kernel version <kernel version>)
     {{PC$}} scp install_artifact/lib/modules/<kernel version>/kernel/drivers/media/test-drivers/vivid/vivid.ko root@<board ip address>:/lib/modules/<kernel version>{{HighlightParam|''<board ip address>''}}:/lib/modules/{{HighlightParam|''<kernel version>''}}/kernel/drivers/media/test-drivers/vivid/
    OR
     {{PC$}} scp -r install_artifact/lib/modules/* root@<board ip address>{{HighlightParam|''<board ip address>''}}:/lib/modules/
    
    * Update dependency descriptions for loadable kernel modules, and synchronize the data on disk with memory
     {{Board$}} /sbin/depmod -a
     {{Board$}} sync
    
    * Insert the vivid kernel module into the Linux kernel
     {{Board$}} modprobe vivid                   
     [...]
     [ 3412.784638] {{Highlight|Simple example}} - vivid_probe
    
    * Remove the vivid kernel module from the Linux kernel
     {{Board$}} rmmod vivid
     [...]
     [ 3423.708517] {{Highlight|Simple example}} - vivid_remove
    
    ===Adding an external out-of-tree Linux kernel module===
    This simple example adds a "Hello World" external out-of-tree Linux kernel module to the Linux kernel.<br><br>
    
    
    * Prerequisite: the Linux source code is installed, and the Linux kernel has been cross-compiled
    
    * Go to the working directory that contains all the source code (that is, the directory that contains the Linux kernel, U-Boot and TF-A source code directories)
     {{PC$}} cd <tag>/sources/arm-<distro>{{HighlightParam|''<tag>''}}/sources/arm-{{HighlightParam|''<distro>''}}-linux-gnueabi
    
    * Export to KERNEL_SRC_PATH the path to the Linux kernel build directory that contains both the Linux kernel source code and the configuration file (''.config'')
     {{PC$}} export KERNEL_SRC_PATH=$PWD/<Linux kernel build directory>{{HighlightParam|''<Linux kernel build directory>''}}/
    
    * Create a directory for this kernel module example
     {{PC$}} mkdir kernel_module_example
     {{PC$}} cd kernel_module_example
    
    * Create the source code file for this kernel module example: ''kernel_module_example.c''<pre>
    
    // SPDX-identifier: GPL-2.0
    /*
     * Copyright (C) STMicroelectronics SA 2018
     *
     * Authors: Jean-Christophe Trotin <jean-christophe.trotin@st.com>
    
     *
     */
    
    #include <linux/module.h>    /* for all kernel modules */
    #include <linux/kernel.h>    /* for KERN_INFO */
    #include <linux/init.h>      /* for __init and __exit macros */
    
    static int __init kernel_module_example_init(void)
    {
    	printk(KERN_INFO "Kernel module example: hello world from STMicroelectronics\n");
    	return 0;
    }
    
    static void __exit kernel_module_example_exit(void)
    {
    	printk(KERN_INFO "Kernel module example: goodbye from STMicroelectronics\n");
    }
    
    module_init(kernel_module_example_init);
    module_exit(kernel_module_example_exit);
    
    MODULE_DESCRIPTION("STMicroelectronics simple external out-of-tree Linux kernel module example");
    MODULE_AUTHOR("Jean-Christophe Trotin <jean-christophe.trotin@st.com>");
    MODULE_LICENSE("GPL v2");</pre>
    
    
    * Create the makefile for this kernel module example: ''Makefile''
    {{info|All the indentations in a makefile are tabulations}}<pre>
    
    # Makefile for simple external out-of-tree Linux kernel module example
    
    # Object file(s) to be built
    obj-m := kernel_module_example.o
    
    # Path to the directory that contains the Linux kernel source code
    # and the configuration file (.config)
    KERNEL_DIR ?=  $(KERNEL_SRC_PATH)
    
    # Path to the directory that contains the generated objects
    DESTDIR ?= $(KERNEL_DIR)/install_artifact
    
    # Path to the directory that contains the source file(s) to compile
    PWD := $(shell pwd) 
    
    default:
    	$(MAKE) -C $(KERNEL_DIR) M=$(PWD) modules
    
    install:
    	$(MAKE) -C $(KERNEL_DIR) M=$(PWD) INSTALL_MOD_PATH=$(DESTDIR) modules_install
    
    clean:
    	$(MAKE) -C $(KERNEL_DIR) M=$(PWD) clean</pre>
    
    
    * Cross-compile the kernel module example
     {{PC$}} make clean
     {{PC$}} make
     {{PC$}} make install
    
    * Go to the <Linux kernel build directory>Linux  {{PC$}} cd <Linux kernel build directory>kernel build directory
     {{PC$}} cd {{HighlightParam|''<Linux kernel build directory>''}}
    
    
    * The generated kernel module example is in: ''install_artifact/lib/modules/<kernel version>/extra/kernel_module_example.ko''
    
    * Remove the link on "install_artifact/lib/modules/<kernel version>{{HighlightParam|''<kernel version>''}}/"
     {{PC$}} rm install_artifact/lib/modules/<kernel version>{{HighlightParam|''<kernel version>''}}/build
     {{PC$}} rm install_artifact/lib/modules/<kernel version>{{HighlightParam|''<kernel version>''}}/source
    
    * Optionally, strip kernel modules (to reduce the size of each kernel modules)
     {{PC$}} find . -name "*.ko" | xargs $STRIP --strip-debug --remove-section=.comment --remove-section=.note --preserve-dates
    
    * Push this kernel module example on board (please check the kernel version <kernel version>)
     {{PC$}} ssh root@<board ip address>{{HighlightParam|''<board ip address>''}} mkdir -p /lib/modules/<kernel version>/extra
     {{PC$}} scp install_artifact/lib/modules/<kernel version>{{HighlightParam|''<kernel version>''}}/extra/kernel_module_example.ko root@<board ip address>:/lib/modules/<kernel version>{{HighlightParam|''<board ip address>''}}:/lib/modules/{{HighlightParam|''<kernel version>''}}/extra
    OR
     {{PC$}} scp -r install_artifact/lib/modules/* root@<board ip address>{{HighlightParam|''<board ip address>''}}:/lib/modules/
    
    * Update dependency descriptions for loadable kernel modules, and synchronize the data on disk with memory
     {{Board$}} /sbin/depmod -a
     {{Board$}} sync
    
    * Insert the kernel module example into the Linux kernel
     {{Board$}} modprobe kernel_module_example
     [18167.821725] {{Highlight|Kernel module example}}: hello world from STMicroelectronics
    
    * Remove the kernel module example from the Linux kernel
     {{Board$}} rmmod kernel_module_example
     [18180.086722] {{Highlight|Kernel module example}}: goodbye from STMicroelectronics
    
    ==Modifying the U-Boot==
    This simple example adds unconditional log information when U-Boot starts. Within the scope of the [[Boot chain overview|trusted boot chain]], U-Boot is used as second stage boot loader (SSBL).
    
    * Have a look at the U-Boot log information when the board reboots
     {{Board$}} reboot''STM32MP157C-EV1''
     [...]
     U-Boot <U-Boot version> (<U-Boot build time flag>)
     CPU: STM32MP157CAA Rev.B
    
    {{ReviewsComments|-- [[User:Jean-philippe Romain|Jean-philippe Romain]] ([[User talk:Jean-philippe Romain|talk]]) 14:59, 12 August 2021 (CEST)<br />MP13 disco board to be added for v4}}
    {|
    || '''STM32MP157C-EV1'''
    ||
     [...]
     U-Boot {{HighlightParam|''<U-Boot version> (<U-Boot build time flag>)''}}
     CPU: {{highlight|STM32MP157CAA Rev.B}}
    
     Model: STMicroelectronics STM32MP157C eval daughter on eval mother
     Board: stm32mp1 in trusted mode (st,{{highlight|stm32mp157c-ev1)
     [...]
    
    ''STM32MP157C-DK2''
     [...]
     U-Boot <U-Boot version> (<U-Boot build time flag>)
     CPU: STM32MP157CAC Rev.B}})
     [...]
    |-
    || '''STM32MP157C-DK2'''
    ||
     [...]
     U-Boot {{HighlightParam|''<U-Boot version> (<U-Boot build time flag>)""}}
     CPU: {{highlight|STM32MP157CAC Rev.B}}
    
     Model: STMicroelectronics STM32MP157C-DK2 Discovery Board
     Board: stm32mp1 in trusted mode (st,{{highlight|stm32mp157c-dk2)
     [...]
    
    * Go to the <U-Boot source directory>
    
     {{PC$}} cd <U-Boot source directory>
    
    
     Example:
     {{PC$}} cd <U-Boot source directory>}})
     [...]
    |}
    
    * Go to the U-Boot source directory
     {{PC$}} cd {{HighlightParam|''<U-Boot source directory>''}}
    
    '''Example:'''
    
    * Edit the ''./board/st/stm32mp1/stm32mp1.c'' source file * Addto add a log information in the ''checkboard'' function
     int checkboard(void)
     {
     	int ret;
           char *mode;
    
     	[...]
     	puts("\n");
     	{{Highlight|printf("U-Boot simple example\n");}}
     	[...]
     	return 0;
     }
    
    * Get the list of supported configurations with the following command
     {{PC$}} make -f $PWD/../Makefile.sdk help
    * {{ReviewsComments|-- [[User:Jean-philippe Romain|Jean-philippe Romain]] ([[User talk:Jean-philippe Romain|talk]]) 16:58, 12 August 2021 (CEST)<br />Below section to be removed on v4}}<div class="mw-collapsible mw-collapsed">
    
    '''stm32 legacy images case building (no FIP)'''<div class="mw-collapsible-content">
    
    * Enable {{Highlight|CONFIG_STM32MP15x_STM32IMAGE}} in your defconfig (i.e. ''configs/stm32mp15_trusted_defconfig'')
    * Cross-compile the U-Boot: here trusted boot for '''STM32MP157C-EV1''' and '''STM32MP157C-DK2'''
    {{ReviewsComments|-- [[User:Jean-philippe Romain|Jean-philippe Romain]] ([[User talk:Jean-philippe Romain|talk]]) 10:39, 13 August 2021 (CEST)<br />Command line to be review for v3.1}}
     {{PC$}} make -f $PWD/../Makefile.sdk all UBOOT_CONFIGS=stm32mp15_trusted_defconfig,trusted,u-boot.stm32 ENABLE_FIP=0
    
    * Go to the directory where the compilation results are stored
     {{PC$}} cd ../deploy/
    
    * Reboot the board, and hit any key to stop in the U-boot shell
     {{Board$}} reboot
     [...]
     Hit any key to stop autoboot:  0 
     STM32MP> 
    
    * Connect a USB cable between the host machine and the board via the USB OTG ports
    
    * In the U-Boot shell, call the USB mass storage function
     STM32MP> ums 0 mmc 0
    {{Info|For more information about the usage of U-Boot UMS functionality, see [[How to use USB mass storage in U-Boot]]}}
    
    * On the host machine, check the partition associated with the secondary stage boot loader (''ssbl''): ''sdb3'' here
     {{PC$}} ls -l /dev/disk/by-partlabel/
     total 0
     lrwxrwxrwx 1 root root 10 Feb  8 08:57 bootfs -> ../../sdb4
     lrwxrwxrwx 1 root root 10 Feb  8 08:57 fsbl1 -> ../../sdb1
     lrwxrwxrwx 1 root root 10 Feb  8 08:57 fsbl2 -> ../../sdb2
     lrwxrwxrwx 1 root root 10 Feb  8 08:57 rootfs -> ../../sdb6
     lrwxrwxrwx 1 root root 10 Feb  8 08:57 {{Highlight|ssbl -> ../../sdb3}}
     lrwxrwxrwx 1 root root 10 Feb  8 08:57 userfs -> ../../sdb7
     lrwxrwxrwx 1 root root 10 Feb  8 08:57 vendorfs -> ../../sdb5
    
    * Copy the U-Boot binary to the dedicated partition
    {|
    || '''STM32MP157C-EV1'''
    ||
     {{PC$}} dd if={{Highlight|u-boot-stm32mp157c-ev1-trusted.stm32}} of=/dev/sdb3 bs=1M conv=fdatasync
    |-
    || '''STM32MP157C-DK2'''
    ||
     {{PC$}} dd if={{Highlight|u-boot-stm32mp157c-dk2-trusted.stm32}} of=/dev/sdb3 bs=1M conv=fdatasync
    |}</div>
    </div>
    
    
    or
    <div class="mw-collapsible">
    
    '''FIP images case building ({{Highlight|Default}})'''<div class="mw-collapsible-content">
    
    
    * As mentionned in help, OpenSTLinux has activated FIP by default, so the "FIP_artifacts" folder should be specified to allow to update the FIP binary with the new U-Boot binary. When using the "SOURCES-xxxx.tar.gz" from Developer package the "FIP_DEPLOYDIR_ROOT" var should be set as below:
     {{PC$}} export FIP_DEPLOYDIR_ROOT=$PWD/../../FIP_artifacts
    
    * Note that to keep the original FIP binary, the "FIP_DEPLOYDIR_FIP" var should be set as below:
     {{PC$}} export FIP_DEPLOYDIR_FIP=$PWD/../deploy/fip
    
    * Cross-compile the U-Boot: here trusted boot for '''STM32MP157C-EV1''' and '''STM32MP157C-DK2
    '''
    {{ReviewsComments|-- [[User:Jean-philippe Romain|Jean-philippe Romain]] ([[User talk:Jean-philippe Romain|talk]]) 10:39, 13 August 2021 (CEST)<br />Command line to be review for v3.1}}{{PC$}} make -f $PWD/../Makefile.sdk all UBOOT_CONFIGS=stm32mp15_trusted_defconfig,trusted,u-boot.dtb DEVICE_TREE="stm32mp157c-ev1-trusted stm32mp157c-dk2"
    
    * Go to the directory where the compilation results are stored
     {{PC$}} cd $FIP_DEPLOYDIR_FIP
    
    * Reboot the board, and hit any key to stop in the U-boot shell
     {{Board$}} reboot
     [...]
     Hit any key to stop autoboot:  0 
     STM32MP> 
    
    * Connect a USB cable between the host machine and the board via the USB OTG ports
    
    * In the U-Boot shell, call the USB mass storage function
     STM32MP> ums 0 mmc 0
    {{Info|For more information about the usage of U-Boot UMS functionality, see [[How to use USB mass storage in U-Boot]]}}
    
    * On the host machine, check the partition associated with the secondary stage boot loader that contains the FIP binary (''fip''): ''sdb3'' here
     {{PC$}} ls -l /dev/disk/by-partlabel/
     total 0
     lrwxrwxrwx 1 root root 10 Feb  8 08:57 bootfs -> ../../sdb4
     lrwxrwxrwx 1 root root 10 Feb  8 08:57 fsbl1 -> ../../sdb1
     lrwxrwxrwx 1 root root 10 Feb  8 08:57 fsbl2 -> ../../sdb2
     lrwxrwxrwx 1 root root 10 Feb  8 08:57 rootfs -> ../../sdb6
     lrwxrwxrwx 1 root root 10 Feb  8 08:57 {{Highlight|fip -> ../../sdb3}}
     lrwxrwxrwx 1 root root 10 Feb  8 08:57 userfs -> ../../sdb7
     lrwxrwxrwx 1 root root 10 Feb  8 08:57 vendorfs -> ../../sdb5
    
    * Copy the FIP binary to the dedicated partition''STM32MP157C-EV1''
     {{PC$}} dd if={{ReviewsComments|-- [[User:Jean-philippe Romain|Jean-philippe Romain]] ([[User talk:Jean-philippe Romain|talk]]) 14:59, 12 August 2021 (CEST)<br />MP13 disco board to be added for v4}}
    {|
    || '''STM32MP157C-EV1'''
    ||
     {{PC$}} dd if={{Highlight|fip-stm32mp157c-ev1-trusted.bin}} of=/dev/sdb3 bs=1M conv=fdatasync''STM32MP157C-DK2''
     {{PC$}} dd if=|-
    || '''STM32MP157C-DK2'''
    ||
     {{PC$}} dd if={{Highlight|fip-stm32mp157c-dk2-trusted.bin}} of=/dev/sdb3 bs=1M conv=fdatasync
    |}</div>
    </div>
    
    * Reset the U-Boot shell
     STM32MP> reset
    
    * Have a look at the new U-Boot log information when the board reboots''STM32MP157C-EV1''{{ReviewsComments|-- [[User:Jean-philippe Romain|Jean-philippe Romain]] ([[User talk:Jean-philippe Romain|talk]]) 14:59, 12 August 2021 (CEST)<br />MP13 disco board to be added for v4}}
    {|
    || '''STM32MP157C-EV1'''
    ||[...]
     U-Boot <U-Boot version> (<U-Boot build time flag>)
     CPU: STM32MP157CAA Rev.B
     Model: STMicroelectronics STM32MP157C eval daughter on eval mother
     Board: stm32mp1 in trusted mode (st,stm32mp157c-ev1)
     {{Highlight|U-Boot simple example}}
     [...]
    
    ''STM32MP157C-DK2''|-
    || '''STM32MP157C-DK2'''
    ||[...]
     U-Boot <U-Boot version> (<U-Boot build time flag>)
     CPU: STM32MP157CAC Rev.B
     Model: STMicroelectronics STM32MP157C-DK2 Discovery Board
     Board: stm32mp1 in trusted mode (st,stm32mp157c-dk2)
     {{Highlight|U-Boot simple example}}
     [...]
    |}
    ==Modifying the TF-A==
    This simple example adds unconditional log information when the TF-A starts. Within the scope of the [[Boot chain overview|trusted boot chain]], TF-A is used as first stage boot loader (FSBL).
    
    * Have a look at the TF-A log information when the board reboots
     {{Board$}} reboot
     [...]
     INFO:      System reset generated by MPU (MPSYSRST)
     INFO:    PMIC version = 0x10
     INFO:    Using SDMMC
     [...]
    
    * Go to the <TF-A source directory>
    
     {{PC$}} cd <TF-A source directory>
    
    TF-A source directory
     {{PC$}} cd {{HighlightParam|''<TF-A source directory>''}}
    
    '''Example:'''* Edit the ''./plat/st/stm32mp1/bl2_plat_setup.c'' source file * Addto add a log information in the ''print_reset_reason'' function
     static void print_reset_reason(void)
     {
     	[...]
     	INFO("Reset reason (0x%x):\n", rstsr);
    
     	{{Highlight|INFO("TF-A simple example\n");}}
     	[...]
     }
    
    * Get the list of supported configurations with the following command
     {{PC$}} make -f $PWD/../Makefile.sdk help
    {{ReviewsComments|-- [[User:Jean-philippe Romain|Jean-philippe Romain]] ([[User talk:Jean-philippe Romain|talk]]) 16:58, 12 August 2021 (CEST)<br />Below section to be removed on v4}}<div class="mw-collapsible mw-collapsed">
    
    '''stm32 legacy images case building (no FIP)'''<div class="mw-collapsible-content">
    
    {{UnderConstruction| This section to be reviewed}}* Cross-compile the TF-A: here trusted boot for '''STM32MP157C-EV1''' and '''STM32MP157C-DK2 for microSD card'''{{PC$}} make -f $PWD/../Makefile.sdk stm32 TF_A_CONFIG="sdcard"
    trusted ENABLE_FIP=0 all
    * Go to the directory in which the compilation results are stored
     {{PC$}} cd ../deploy
    
    * Reboot the board, and hit any key to stop in the U-boot shell
     {{Board$}} reboot
     [...]
     Hit any key to stop autoboot:  0 
     STM32MP> 
    
    * Connect a USB cable between the host machine and the board via the USB OTG ports
    
    * In the U-Boot shell, call the USB mass storage function
     STM32MP> ums 0 mmc 0
    {{Info|For more information about the usage of U-Boot UMS functionality, see [[How to use USB mass storage in U-Boot]]}}
    
    * On the host machine, check the partition associated with the first stage boot loader (''fsbl1'' and ''fsbl2'' as backup): ''sdb1'' and ''sdb2'' (as backup) here
     {{PC$}} ls -l /dev/disk/by-partlabel/
     total 0
     lrwxrwxrwx 1 root root 10 Feb  8 10:01 bootfs -> ../../sdb4
     lrwxrwxrwx 1 root root 10 Feb  8 10:01 {{Highlight|fsbl1 -> ../../sdb1}}
     lrwxrwxrwx 1 root root 10 Feb  8 10:01 {{Highlight|fsbl2 -> ../../sdb2}}
     lrwxrwxrwx 1 root root 10 Feb  8 10:01 rootfs -> ../../sdb6
     lrwxrwxrwx 1 root root 10 Feb  8 10:01 fipssbl -> ../../sdb3
     lrwxrwxrwx 1 root root 10 Feb  8 10:01 userfs -> ../../sdb7
     lrwxrwxrwx 1 root root 10 Feb  8 10:01 vendorfs -> ../../sdb5
    
    * Copy the TF-A  binary to the dedicated partition; to test the new TF-A binary, it might be useful to keep the old TF-A binary in the backup FSBL (''fsbl2'') 
    
    ''STM32MP157C-EV1''
     {{PC$}} dd if={{ReviewsComments|-- [[User:Jean-philippe Romain|Jean-philippe Romain]] ([[User talk:Jean-philippe Romain|talk]]) 15:08, 12 August 2021 (CEST)<br />MP13 disco board to be added for v4}}
    {|
    || '''STM32MP157C-EV1'''
    ||
     {{PC$}} dd if={{Highlight|tf-a-stm32mp157c-ev1-sdcardtrusted.stm32}} of=/dev/sdb1 bs=1M conv=fdatasync{{|-
    || '''STM32MP157C-DK2'''
    ||
     {{PC$}} dd if={{Highlight|tf-a-stm32mp157c-dk2-trusted.stm32}} of=/dev/sdb1 bs=1M conv=fdatasync
    |}
    {{Info|In case you get a ''permission denied'' you can set more permission on ''/dev/sdb1'' : ''sudo chmod 777 /dev/sdb1''}}
    ''STM32MP157C-DK2''
     {{PC$}} dd if=tf-a-stm32mp157c-dk2-sdcard.stm32
    
    * Reset the U-Boot shell
    In the U-Boot shell, press Ctrl+C prior to get hand back.
     STM32MP> reset
    
    * Have a look at the new TF-A log information when the board reboots
     [...]
     INFO:      System reset generated by MPU (MPSYSRST)
     INFO:    {{Highlight|TF-A simple example}}
     INFO:    PMIC version = 0x10
     INFO:    Using SDMMC
     [...]
    </div>
    </div>
    
    
    or
    <div class="mw-collapsible">
    
    '''FIP images case building ({{Highlight|Default}})'''<div class="mw-collapsible-content">
    
    * Cross-compile the TF-A: here trusted boot for '''STM32MP157C-EV1''' and '''STM32MP157C-DK2''' for microSD card
     {{PC$}} make -f $PWD/../Makefile.sdk stm32 TF_A_CONFIG="sdcard"
    
    * Go to the directory in which the compilation results are stored
     {{PC$}} cd ../deploy
    
    * Reboot the board, and hit any key to stop in the U-boot shell
     {{Board$}} reboot
     [...]
     Hit any key to stop autoboot:  0 
     STM32MP> 
    
    * Connect a USB cable between the host machine and the board via the USB OTG ports
    
    * In the U-Boot shell, call the USB mass storage function
     STM32MP> ums 0 mmc 0
    {{Info|For more information about the usage of U-Boot UMS functionality, see [[How to use USB mass storage in U-Boot]]}}
    
    * On the host machine, check the partition associated with the first stage boot loader (''fsbl1'' and ''fsbl2'' as backup): ''sdb1'' and ''sdb2'' (as backup) here
     {{PC$}} ls -l /dev/disk/by-partlabel/
     total 0
     lrwxrwxrwx 1 root root 10 Feb  8 10:01 bootfs -> ../../sdb4
     lrwxrwxrwx 1 root root 10 Feb  8 10:01 {{Highlight|fsbl1 -> ../../sdb1}}
     lrwxrwxrwx 1 root root 10 Feb  8 10:01 {{Highlight|fsbl2 -> ../../sdb2}}
     lrwxrwxrwx 1 root root 10 Feb  8 10:01 rootfs -> ../../sdb6
     lrwxrwxrwx 1 root root 10 Feb  8 10:01 fip -> ../../sdb3
     lrwxrwxrwx 1 root root 10 Feb  8 10:01 userfs -> ../../sdb7
     lrwxrwxrwx 1 root root 10 Feb  8 10:01 vendorfs -> ../../sdb5
    
    * Copy the TF-A  binary to the dedicated partition; to test the new TF-A binary, it might be useful to keep the old TF-A binary in the backup FSBL (''fsbl2'') 
    {{ReviewsComments|-- [[User:Jean-philippe Romain|Jean-philippe Romain]] ([[User talk:Jean-philippe Romain|talk]]) 15:08, 12 August 2021 (CEST)<br />MP13 disco board to be added for v4}}
    {|
    || '''STM32MP157C-EV1'''
    ||
     {{PC$}} dd if={{Highlight|tf-a-stm32mp157c-ev1-sdcard.stm32}} of=/dev/sdb1 bs=1M conv=fdatasync
    |-
    || '''STM32MP157C-DK2'''
    ||
     {{PC$}} dd if={{Highlight|tf-a-stm32mp157c-dk2-sdcard.stm32}} of=/dev/sdb1 bs=1M conv=fdatasync
    |}
    {{Info|In case you get a ''permission denied'' you can set more permission on ''/dev/sdb1'' : ''sudo chmod 777 /dev/sdb1''}}
    * Reset the U-Boot shell
    In the U-Boot shell, press Ctrl+C prior to get hand back.
     STM32MP> reset
    
    * Have a look at the new TF-A log information when the board reboots
     [...]
     INFO:      System reset generated by MPU (MPSYSRST)
     INFO:    {{Highlight|TF-A simple example}}
     INFO:    PMIC version = 0x10
     INFO:    Using SDMMC
     [...]
    
    * Note that according to the modification done on TF-A source code, the FIP binary may need also to be updated. In such case, to cross-compile the TF-A trusted boot for STM32MP157C-EV1 and STM32MP157C-DK2 for microSD card with FIP binary update, follow the steps:
    
    :* The "FIP_artifacts" folder should be specified to allow to update the FIP binary with the new U-Boot binary. When using the "SOURCES-xxxx.tar.gz" from Developer package the "FIP_DEPLOYDIR_ROOT" var should be set as below:
     {{PC$}} export FIP_DEPLOYDIR_ROOT=$PWD/../../FIP_artifacts
    
    :* To keep the original FIP binary, the "FIP_DEPLOYDIR_FIP" var should be set as below:
     {{PC$}} export FIP_DEPLOYDIR_FIP=$PWD/../deploy/fip
    
    :* Launch cross-compilation (trusted boot for STM32MP157C-EV1 and STM32MP157C-DK2 for microSD):
     {{PC$}} make -f $PWD/../Makefile.sdk all TF_A_CONFIG="sdcard trusted" FIP_CONFIG=trusted
    
    :* Go to the directory in which the compilation results are stored
     {{PC$}} cd $FIP_DEPLOYDIR_FIP
    
    :* Reboot the board, and hit any key to stop in the U-boot shell
     {{Board$}} reboot
     [...]
     Hit any key to stop autoboot:  0 
     STM32MP> 
    
    :* Connect a USB cable between the host machine and the board via the USB OTG ports
    
    :* In the U-Boot shell, call the USB mass storage function
     STM32MP> ums 0 mmc 0
    {{Info|For more information about the usage of U-Boot UMS functionality, see [[How to use USB mass storage in U-Boot]]}}
    
    :* On the host machine, check the partition associated with the second stage boot loader that contains the FIP binary (''fip''): ''sdb3"
     {{PC$}} ls -l /dev/disk/by-partlabel/
     total 0
     lrwxrwxrwx 1 root root 10 Feb  8 10:01 bootfs -> ../../sdb4
     lrwxrwxrwx 1 root root 10 Feb  8 10:01 {{Highlight|fsbl1 -> ../../sdb1}}
    
     lrwxrwxrwx 1 root root 10 Feb  8 10:01 {{Highlight|fsbl2 -> ../../sdb2}}
    
     lrwxrwxrwx 1 root root 10 Feb  8 10:01 rootfs -> ../../sdb6
     lrwxrwxrwx 1 root root 10 Feb  8 10:01 {{Highlight|fip -> ../../sdb3}}
    
     lrwxrwxrwx 1 root root 10 Feb  8 10:01 userfs -> ../../sdb7
     lrwxrwxrwx 1 root root 10 Feb  8 10:01 vendorfs -> ../../sdb5
    
    :* Copy the FIP  binary to the dedicated partition
    ''STM32MP157C-EV1''
     {{PC$}} dd if={|
    || '''STM32MP157C-EV1'''
    ||
     {{PC$}} dd if={{Highlight|fip-stm32mp157c-ev1-trusted.bin}} of=/dev/sdb3 bs=1M conv=fdatasync{{|-
    || '''STM32MP157C-DK2'''
    ||
     {{PC$}} dd if={{Highlight|fip-stm32mp157c-dk2-trusted.bin}} of=/dev/sdb3 bs=1M conv=fdatasync
    |}
    {{Info|In case you get a ''permission denied'' you can set more permission on ''/dev/sdb1sdb3'' : ''sudo chmod 777 /dev/sdb3''}}
    
    ''STM32MP157C-DK2''
     {{PC$}} dd if=fip-stm32mp157c-dk2-trusted.bin of=/dev/sdb3 bs=1M conv=fdatasync
    </div>
    </div>
    
    * Reset the U-Boot shell
    In the U-Boot shell, press Ctrl+C prior to get hand back.
     STM32MP> reset
    
    ==Adding a "hello world" user space example==
    Thanks to the OpenSTLinux SDK, it is easy to develop a project outside of the OpenEmbedded build system. This chapter shows how to compile and execute a simple "hello world" example.
    
    ===Source code file===
    * Go to the working directory that contains all the source codes (i.e. directory that contains the Linux kernel, U-Boot and TF-A source code directories)
     {{PC$}} cd <tag>{{HighlightParam|''<tag>''}}/sources/arm-<distro>-linux-gnueabi
    
    * Create a directory for this user space example
     {{PC$}} mkdir hello_world_example
     {{PC$}} cd hello_world_example
    
    * Create the source code file for this user space example: ''hello_world_example.c''<pre>
    
    // SPDX-identifier: GPL-2.0
    /*
     * Copyright (C) STMicroelectronics SA 2018
     *
     * Authors: Jean-Christophe Trotin <jean-christophe.trotin@st.com>
    
     *
     */
    
    #include <stdio.h>
    
    #include <unistd.h>
    
    
    int main(int argc, char **argv)
    {
    	int i =11;
    
    	printf("\nUser space example: hello world from STMicroelectronics\n");
    	setbuf(stdout,NULL);
    	while (i--) {
    		printf("%i ", i);
    		sleep(1);
    	}
    	printf("\nUser space example: goodbye from STMicroelectronics\n");
    
    	return(0);
    }</pre>
    
    
    ===Cross-compilation===
    Three ways to use the OpenSTLinux SDK to cross-compile this user space example are proposed below: (1) command line (2) makefile-based project (3) autotools-based project.
    
    ====Command line====
    This method allows quick cross-compilation of a single-source code file. It applies if the project has only one file. <br>
    
    The cross-development toolchain is associated with the sysroot that contains the header files and libraries needed for generating binaries that run on the target architecture (see [[SDK for OpenSTLinux distribution#Native and target sysroots]]). <br>
    
    The sysroot location is specified with the ''--sysroot'' option.
    
    The sysroot location must be specified using the --sysroot option. The ''CC'' environment variable created by the SDK already includes the ''--sysroot'' option that points to the SDK sysroot location.
     {{PC$}} echo $CC
     arm-ostl-linux-gnueabi-gcc -march=armv7ve -mthumb -mfpu=neon-vfpv4 -mfloat-abi=hard -mcpu=cortex-a7 --sysroot=<SDK installation directory>{{HighlightParam|''<SDK installation directory>''}}/SDK/sysroots/cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi
    
    * Create the directory in which the generated binary is to be stored
     {{PC$}} mkdir -p install_artifact install_artifact/usr install_artifact/usr/local install_artifact/usr/local/bin
    
    * Cross-compile the single source code file for the user space example
     {{PC$}} $CC hello_world_example.c -o ./install_artifact/usr/local/bin/hello_world_example
    
    ====Makefile-based project====
    For this method, the cross-toolchain environment variables established by running the cross-toolchain environment setup script are subject to general ''make'' rules. <br>
    
    For example, see the following environment variables:
     {{PC$}} echo $CC
     arm-ostl-linux-gnueabi-gcc -march=armv7ve -mthumb -mfpu=neon-vfpv4 -mfloat-abi=hard -mcpu=cortex-a7 --sysroot=<SDK installation directory>{{HighlightParam|''<SDK installation directory>''}}/SDK/sysroots/cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi
     {{PC$}} echo $CFLAGS
     -O2 -pipe -g -feliminate-unused-debug-types
     {{PC$}} echo $LDFLAGS
     -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed
     {{PC$}} echo $LD
     arm-ostl-linux-gnueabi-ld --sysroot=<SDK installation directory>/SDK/sysroots/cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi
    
    * Create the makefile for this user space example: ''Makefile''
    {{info|All the indentations in a makefile are tabulations}}<pre>
    
    PROG = hello_world_example
    SRCS = hello_world_example.c
    OBJS = $(SRCS:.c=.o)
    
    CLEANFILES = $(PROG)
    INSTALL_DIR = ./install_artifact/usr/local/bin
    
    # Add / change option in CFLAGS if needed
    # CFLAGS += <new option>
    
    
    $(PROG):  $(OBJS)
    	$(CC) $(CFLAGS) -o $(PROG) $(OBJS)
    
    .c.o:
    	$(CC) $(CFLAGS) -c $< -o $@
    
    all: $(PROG)
    
    clean:
    	rm -f $(CLEANFILES) $(patsubst %.c,%.o, $(SRCS)) *~
    
    install: $(PROG)
    	mkdir -p $(INSTALL_DIR)
    	install $(PROG) $(INSTALL_DIR)</pre>
    
    * Cross-compile the project
     {{PC$}} make
     {{PC$}} make install
    
    ====Autotools-based project====
    This method creates a project based on GNU autotools.
    
    * Create the makefile for this user space example: ''Makefile.am''<pre>
    
    bin_PROGRAMS = hello_world_example
    hello_world_example_SOURCES = hello_world_example.c</pre>
    
    
    * Create the configuration file for this user space example: ''configure.ac''<pre>
    
    AC_INIT(hello_world_example,0.1)
    AM_INIT_AUTOMAKE([foreign])
    AC_PROG_CC
    AC_PROG_INSTALL
    AC_OUTPUT(Makefile)</pre>
    
    
    * Generate the local aclocal.m4 files and create the configure script
     {{PC$}} aclocal
     {{PC$}} autoconf
    
    * Generate the files needed by GNU coding standards (for compliance)
     {{PC$}} touch NEWS README AUTHORS ChangeLog
    
    * Generate the links towards SDK scripts
     {{PC$}} automake -a
    
    * Cross-compile the project
     {{PC$}} ./configure ${CONFIGURE_FLAGS}
     {{PC$}} make
     {{PC$}} make install DESTDIR=./install_artifact
    
    ===Deploy and execute on board===
    
    * Check that the generated binary for this user space example is in: ''./install_artifact/usr/local/bin/hello_world_example''
    
    * Push this binary onto the board
     {{PC$}} scp -r install_artifact/* root@<board ip address>:/
    
    * Execute this user space example
     {{Board$}} cd /usr/local/bin
     {{Board$}} ./hello_world_example 
    
     {{Highlight|User space example}}: hello world from STMicroelectronics
     10 9 8 7 6 5 4 3 2 1 0 
     {{Highlight|User space example}}: goodbye from STMicroelectronics
    
    ==Tips==
    ===Creating a mounting point===
    The objective is to create a mounting point for the boot file system (bootfs partition)
    * Find the partition label associated with the boot file system
     {{Board$}} ls -l /dev/disk/by-partlabel/
     total 0
     lrwxrwxrwx 1 root root 15 Jan 23 17:00 {{Highlight|bootfs -> ../../mmcblk0p4}}
     lrwxrwxrwx 1 root root 15 Jan 23 17:00 fsbl1 -> ../../mmcblk0p1
     lrwxrwxrwx 1 root root 15 Jan 23 17:00 fsbl2 -> ../../mmcblk0p2
     lrwxrwxrwx 1 root root 15 Jan 23 17:00 rootfs -> ../../mmcblk0p6
     lrwxrwxrwx 1 root root 15 Jan 23 17:00 fip -> ../../mmcblk0p3
     lrwxrwxrwx 1 root root 15 Jan 23 17:00 userfs -> ../../mmcblk0p7
     lrwxrwxrwx 1 root root 15 Jan 23 17:00 vendorfs -> ../../mmcblk0p5
    
    * Attach the boot file system found under ''/dev/mmcblk0p4'' in the directory ''/boot''
     {{Board$}} mount /dev/mmcblk0p4 /boot
    <noinclude>
    
    [[Category:How to build software]]
    [[Category:Developer Package]]
    {{PublicationRequestId | 7648 | 2018-06-14 | PhilipS}}
    {{UpdateNeededForNewRelease|Please check regularly that the commands work fine}}</noinclude>
    (17 intermediate revisions by the same user not shown)
    Line 41: Line 41:
     
    * Get the current value of the CMA size (128 Mbytes here) through the analysis of the target boot log
     
    * Get the current value of the CMA size (128 Mbytes here) through the analysis of the target boot log
     
      {{Board$}} dmesg | grep -i cma
     
      {{Board$}} dmesg | grep -i cma
    ''STM32MP157C-EV1''
    +
    {|
      +
    ||'''STM32MP157C-EV1'''
      +
    ||
     
      [    0.000000] cma: Reserved 128 MiB at 0xe8000000
     
      [    0.000000] cma: Reserved 128 MiB at 0xe8000000
    ''STM32MP157C-DK2''
    +
    |-
      +
    || '''STM32MP157C-DK2'''
      +
    ||
     
      [    0.000000] cma: Reserved 128 MiB at 0xd2000000
     
      [    0.000000] cma: Reserved 128 MiB at 0xd2000000
      +
    |}
       
    * Go to the <Linux kernel build directory>
    +
     
      {{PC$}} cd <Linux kernel build directory>
    +
    * Go to the Linux kernel build directory
      +
      {{PC$}} cd {{HighlightParam|''<Linux kernel build directory>''}}
       
     
    * Start the Linux kernel configuration menu: see [[Menuconfig or how to configure kernel#Menuconfig and Developer Package|Menuconfig or how to configure kernel]]
     
    * Start the Linux kernel configuration menu: see [[Menuconfig or how to configure kernel#Menuconfig and Developer Package|Menuconfig or how to configure kernel]]
    Line 68: Line 74:
     
    * Get the new value of the CMA size (256 Mbytes) through the analysis of the target boot log
     
    * Get the new value of the CMA size (256 Mbytes) through the analysis of the target boot log
     
      {{Board$}} dmesg | grep -i cma
     
      {{Board$}} dmesg | grep -i cma
    ''STM32MP157C-EV1''
    +
    {|
      +
    || '''STM32MP157C-EV1'''
      +
    ||
     
      [    0.000000] cma: Reserved {{Highlight|256}} MiB at 0xd8000000
     
      [    0.000000] cma: Reserved {{Highlight|256}} MiB at 0xd8000000
    ''STM32MP157C-DK2''
    +
    |-
      +
    || '''STM32MP157C-DK2'''
      +
    ||
     
      [    0.000000] cma: Reserved {{Highlight|256}} MiB at 0xc2000000
     
      [    0.000000] cma: Reserved {{Highlight|256}} MiB at 0xc2000000
      +
    |}
       
     
    ==Modifying the Linux kernel device tree==
     
    ==Modifying the Linux kernel device tree==
    Line 78: Line 89:
     
    * With the board started; check that the user green LED (LD3 for STM32MP157C-EV1, LD5 for STM32MP157C-DK2) is disabled
     
    * With the board started; check that the user green LED (LD3 for STM32MP157C-EV1, LD5 for STM32MP157C-DK2) is disabled
       
    * Go to the <Linux kernel source directory>
    +
    * Go to the Linux kernel source directory
      {{PC$}} cd <Linux kernel source directory>
    +
      {{PC$}} cd {{HighlightParam|''<Linux kernel source directory>''}}
     
    +
    * Edit the device tree source file to add the lines highlighted below
    ''STM32P157C-EV1''
    +
    {|
    * Edit the ''arch/arm/boot/dts/stm32mp15xx-edx.dtsi'' device tree source file
    +
    || '''STM32P157C-EV1'''
    * Add the lines highlighted below
    +
    || arch/arm/boot/dts/{{HighlightParam|stm32mp15xx-edx}}.dtsi
      +
    ||
     
      led {
     
      led {
     
      compatible = "gpio-leds";
     
      compatible = "gpio-leds";
    Line 98: Line 110:
     
       {{Highlight|&#125;;}}
     
       {{Highlight|&#125;;}}
     
      };
     
      };
     
    +
    |-
    ''STM32MP157C-DK2''
    +
    || '''STM32MP157C-DK2'''
    * Edit the ''arch/arm/boot/dts/stm32mp15xx-dkx.dtsi'' device tree source file
    +
    || arch/arm/boot/dts/{{HighlightParam|stm32mp15xx-dkx}}.dtsi
    * Add the lines highlighted below
    +
    ||
     
      led {
     
      led {
     
      compatible = "gpio-leds";
     
      compatible = "gpio-leds";
    Line 116: Line 128:
     
       {{Highlight|&#125;;}}
     
       {{Highlight|&#125;;}}
     
      };
     
      };
      +
    |}
      +
       
    * Go to the <Linux kernel build directory>
    +
    * Go to the Linux kernel build directory
      {{PC$}} cd <Linux kernel build directory>
    +
      {{PC$}} cd {{HighlightParam|''<Linux kernel build directory>''}}
       
     
    * Generate the device tree blobs (''*.dtb'')
     
    * Generate the device tree blobs (''*.dtb'')
    Line 125: Line 139:
       
     
    * Update the device tree blobs on the board
     
    * Update the device tree blobs on the board
      {{PC$}} scp install_artifact/boot/stm32mp157*.dtb root@<board ip address>:/boot/
    +
      {{PC$}} scp install_artifact/boot/stm32mp157*.dtb root@{{HighlightParam|''<board ip address>''}}:/boot/
     
    {{Info|If the ''/boot'' mounting point doesn't exist yet, please see [[#Creating a mounting point|how to create a mounting point]]}}
     
    {{Info|If the ''/boot'' mounting point doesn't exist yet, please see [[#Creating a mounting point|how to create a mounting point]]}}
       
    Line 141: Line 155:
     
      {{Board$}}
     
      {{Board$}}
       
    * Go to the <Linux kernel source directory>
    +
    * Go to the Linux kernel source directory
      {{PC$}} cd <Linux kernel source directory>
    +
      {{PC$}} cd {{HighlightParam|''<Linux kernel source directory>''}}
       
     
    * Edit the ''./drivers/gpu/drm/stm/drv.c'' source file
     
    * Edit the ''./drivers/gpu/drm/stm/drv.c'' source file
    Line 159: Line 173:
     
      }
     
      }
       
    * Go to the <Linux kernel build directory>
    +
    * Go to the Linux kernel build directory
      {{PC$}} cd <Linux kernel build directory>
    +
      {{PC$}} cd {{HighlightParam|''<Linux kernel build directory>''}}
       
    * Cross-compile the Linux kernel (please check the load address in the ''README.HOW_TO.txt'' helper file)
    +
    * Cross-compile the Linux kernel ({{Highlight|please check the load address in the ''README.HOW_TO.txt'' helper file}})
      {{PC$}} make uImage LOADADDR=0xC2000040
    +
      {{PC$}} make uImage LOADADDR={{Highlight|0xC2000040}}
     
      {{PC$}} cp arch/arm/boot/uImage install_artifact/boot/
     
      {{PC$}} cp arch/arm/boot/uImage install_artifact/boot/
       
     
    * Update the Linux kernel image on board
     
    * Update the Linux kernel image on board
      {{PC$}} scp install_artifact/boot/uImage root@<board ip address>:/boot/
    +
      {{PC$}} scp install_artifact/boot/uImage root@{{HighlightParam|''<board ip address>''}}:/boot/
     
    {{Info|If the ''/boot'' mounting point doesn't exist yet, please see [[#Creating a mounting point|how to create a mounting point]]}}
     
    {{Info|If the ''/boot'' mounting point doesn't exist yet, please see [[#Creating a mounting point|how to create a mounting point]]}}
       
    Line 184: Line 198:
     
    <br><br>
     
    <br><br>
       
    * Go to the <Linux kernel source directory>
    +
    * Go to the Linux kernel source directory
      {{PC$}} cd <Linux kernel source directory>
    +
      {{PC$}} cd {{HighlightParam|''<Linux kernel source directory>''}}
       
     
    * Edit the ''./drivers/media/test-drivers/vivid/vivid-core.c'' source file
     
    * Edit the ''./drivers/media/test-drivers/vivid/vivid-core.c'' source file
    Line 214: Line 228:
     
      }
     
      }
       
    * Go to the <Linux kernel build directory>
    +
    * Go to the Linux kernel build directory
      {{PC$}} cd <Linux kernel build directory>
    +
      {{PC$}} cd {{HighlightParam|''<Linux kernel build directory>''}}
     
       
     
       
     
    * Cross-compile the Linux kernel modules
     
    * Cross-compile the Linux kernel modules
    Line 221: Line 235:
     
      {{PC$}} make INSTALL_MOD_PATH="./install_artifact" modules_install
     
      {{PC$}} make INSTALL_MOD_PATH="./install_artifact" modules_install
       
    * Remove the link on "install_artifact/lib/modules/<kernel version>/"
    +
    * Remove the link on ''install_artifact/lib/modules/{{HighlightParam|<kernel version>}}/''
      {{PC$}} rm install_artifact/lib/modules/<kernel version>/build
    +
      {{PC$}} rm install_artifact/lib/modules/{{HighlightParam|''<kernel version>''}}/build
      {{PC$}} rm install_artifact/lib/modules/<kernel version>/source
    +
      {{PC$}} rm install_artifact/lib/modules/{{HighlightParam|''<kernel version>''}}/source
       
     
    * Optionally, strip kernel modules (to reduce the size of each kernel modules)
     
    * Optionally, strip kernel modules (to reduce the size of each kernel modules)
    Line 229: Line 243:
       
     
    * Update the vivid kernel module on the board (please check the kernel version <kernel version>)
     
    * Update the vivid kernel module on the board (please check the kernel version <kernel version>)
      {{PC$}} scp install_artifact/lib/modules/<kernel version>/kernel/drivers/media/test-drivers/vivid/vivid.ko root@<board ip address>:/lib/modules/<kernel version>/kernel/drivers/media/test-drivers/vivid/
    +
      {{PC$}} scp install_artifact/lib/modules/<kernel version>/kernel/drivers/media/test-drivers/vivid/vivid.ko root@{{HighlightParam|''<board ip address>''}}:/lib/modules/{{HighlightParam|''<kernel version>''}}/kernel/drivers/media/test-drivers/vivid/
     
    OR
     
    OR
      {{PC$}} scp -r install_artifact/lib/modules/* root@<board ip address>:/lib/modules/
    +
      {{PC$}} scp -r install_artifact/lib/modules/* root@{{HighlightParam|''<board ip address>''}}:/lib/modules/
       
     
    * Update dependency descriptions for loadable kernel modules, and synchronize the data on disk with memory
     
    * Update dependency descriptions for loadable kernel modules, and synchronize the data on disk with memory
    Line 254: Line 268:
       
     
    * Go to the working directory that contains all the source code (that is, the directory that contains the Linux kernel, U-Boot and TF-A source code directories)
     
    * Go to the working directory that contains all the source code (that is, the directory that contains the Linux kernel, U-Boot and TF-A source code directories)
      {{PC$}} cd <tag>/sources/arm-<distro>-linux-gnueabi
    +
      {{PC$}} cd {{HighlightParam|''<tag>''}}/sources/arm-{{HighlightParam|''<distro>''}}-linux-gnueabi
       
     
    * Export to KERNEL_SRC_PATH the path to the Linux kernel build directory that contains both the Linux kernel source code and the configuration file (''.config'')
     
    * Export to KERNEL_SRC_PATH the path to the Linux kernel build directory that contains both the Linux kernel source code and the configuration file (''.config'')
      {{PC$}} export KERNEL_SRC_PATH=$PWD/<Linux kernel build directory>/
    +
      {{PC$}} export KERNEL_SRC_PATH=$PWD/{{HighlightParam|''<Linux kernel build directory>''}}/
       
     
    * Create a directory for this kernel module example
     
    * Create a directory for this kernel module example
    Line 329: Line 343:
     
      {{PC$}} make install
     
      {{PC$}} make install
       
    * Go to the <Linux kernel build directory>
    +
    * Go to the Linux kernel build directory
      {{PC$}} cd <Linux kernel build directory>
    +
      {{PC$}} cd {{HighlightParam|''<Linux kernel build directory>''}}
       
     
    * The generated kernel module example is in: ''install_artifact/lib/modules/<kernel version>/extra/kernel_module_example.ko''
     
    * The generated kernel module example is in: ''install_artifact/lib/modules/<kernel version>/extra/kernel_module_example.ko''
       
    * Remove the link on "install_artifact/lib/modules/<kernel version>/"
    +
    * Remove the link on "install_artifact/lib/modules/{{HighlightParam|''<kernel version>''}}/"
      {{PC$}} rm install_artifact/lib/modules/<kernel version>/build
    +
      {{PC$}} rm install_artifact/lib/modules/{{HighlightParam|''<kernel version>''}}/build
      {{PC$}} rm install_artifact/lib/modules/<kernel version>/source
    +
      {{PC$}} rm install_artifact/lib/modules/{{HighlightParam|''<kernel version>''}}/source
       
     
    * Optionally, strip kernel modules (to reduce the size of each kernel modules)
     
    * Optionally, strip kernel modules (to reduce the size of each kernel modules)
    Line 342: Line 356:
       
     
    * Push this kernel module example on board (please check the kernel version <kernel version>)
     
    * Push this kernel module example on board (please check the kernel version <kernel version>)
      {{PC$}} ssh root@<board ip address> mkdir -p /lib/modules/<kernel version>/extra
    +
      {{PC$}} ssh root@{{HighlightParam|''<board ip address>''}} mkdir -p /lib/modules/<kernel version>/extra
      {{PC$}} scp install_artifact/lib/modules/<kernel version>/extra/kernel_module_example.ko root@<board ip address>:/lib/modules/<kernel version>/extra
    +
      {{PC$}} scp install_artifact/lib/modules/{{HighlightParam|''<kernel version>''}}/extra/kernel_module_example.ko root@{{HighlightParam|''<board ip address>''}}:/lib/modules/{{HighlightParam|''<kernel version>''}}/extra
     
    OR
     
    OR
      {{PC$}} scp -r install_artifact/lib/modules/* root@<board ip address>:/lib/modules/
    +
      {{PC$}} scp -r install_artifact/lib/modules/* root@{{HighlightParam|''<board ip address>''}}:/lib/modules/
       
     
    * Update dependency descriptions for loadable kernel modules, and synchronize the data on disk with memory
     
    * Update dependency descriptions for loadable kernel modules, and synchronize the data on disk with memory
    Line 364: Line 378:
     
    * Have a look at the U-Boot log information when the board reboots
     
    * Have a look at the U-Boot log information when the board reboots
     
      {{Board$}} reboot
     
      {{Board$}} reboot
    ''STM32MP157C-EV1''
    +
     
      +
    {{ReviewsComments|-- [[User:Jean-philippe Romain|Jean-philippe Romain]] ([[User talk:Jean-philippe Romain|talk]]) 14:59, 12 August 2021 (CEST)<br />MP13 disco board to be added for v4}}
      +
    {|
      +
    || '''STM32MP157C-EV1'''
      +
    ||
     
      [...]
     
      [...]
      U-Boot <U-Boot version> (<U-Boot build time flag>)
    +
      U-Boot {{HighlightParam|''<U-Boot version> (<U-Boot build time flag>)''}}
      CPU: STM32MP157CAA Rev.B
    +
      CPU: {{highlight|STM32MP157CAA Rev.B}}
     
      Model: STMicroelectronics STM32MP157C eval daughter on eval mother
     
      Model: STMicroelectronics STM32MP157C eval daughter on eval mother
      Board: stm32mp1 in trusted mode (st,stm32mp157c-ev1)
    +
      Board: stm32mp1 in trusted mode (st,{{highlight|stm32mp157c-ev1}})
     
      [...]
     
      [...]
     
    +
    |-
    ''STM32MP157C-DK2''
    +
    || '''STM32MP157C-DK2'''
      +
    ||
     
      [...]
     
      [...]
      U-Boot <U-Boot version> (<U-Boot build time flag>)
    +
      U-Boot {{HighlightParam|''<U-Boot version> (<U-Boot build time flag>)""}}
      CPU: STM32MP157CAC Rev.B
    +
      CPU: {{highlight|STM32MP157CAC Rev.B}}
     
      Model: STMicroelectronics STM32MP157C-DK2 Discovery Board
     
      Model: STMicroelectronics STM32MP157C-DK2 Discovery Board
      Board: stm32mp1 in trusted mode (st,stm32mp157c-dk2)
    +
      Board: stm32mp1 in trusted mode (st,{{highlight|stm32mp157c-dk2}})
     
      [...]
     
      [...]
      +
    |}
      +
       
    * Go to the <U-Boot source directory>
    +
    * Go to the U-Boot source directory
      {{PC$}} cd <U-Boot source directory>
    +
      {{PC$}} cd {{HighlightParam|''<U-Boot source directory>''}}
       
    Example:
    +
    '''Example:'''
    {{PC$}} cd <U-Boot source directory>
    +
    * Edit the ''./board/st/stm32mp1/stm32mp1.c'' source file to add a log information in the ''checkboard'' function
    * Edit the ''./board/st/stm32mp1/stm32mp1.c'' source file
     
    * Add a log information in the ''checkboard'' function
     
     
      int checkboard(void)
     
      int checkboard(void)
     
      {
     
      {
    Line 396: Line 415:
     
      {{Highlight|printf("U-Boot simple example\n");}}
     
      {{Highlight|printf("U-Boot simple example\n");}}
     
      [...]
     
      [...]
     
    +
     
      return 0;
     
      return 0;
     
      }
     
      }
    Line 402: Line 421:
     
    * Get the list of supported configurations with the following command
     
    * Get the list of supported configurations with the following command
     
      {{PC$}} make -f $PWD/../Makefile.sdk help
     
      {{PC$}} make -f $PWD/../Makefile.sdk help
      +
      +
    {{ReviewsComments|-- [[User:Jean-philippe Romain|Jean-philippe Romain]] ([[User talk:Jean-philippe Romain|talk]]) 16:58, 12 August 2021 (CEST)<br />Below section to be removed on v4}}
      +
    <div class="mw-collapsible mw-collapsed">
      +
    '''stm32 legacy images case building (no FIP)'''
      +
    <div class="mw-collapsible-content">
      +
    * Enable {{Highlight|CONFIG_STM32MP15x_STM32IMAGE}} in your defconfig (i.e. ''configs/stm32mp15_trusted_defconfig'')
      +
    * Cross-compile the U-Boot: here trusted boot for '''STM32MP157C-EV1''' and '''STM32MP157C-DK2'''
      +
    {{ReviewsComments|-- [[User:Jean-philippe Romain|Jean-philippe Romain]] ([[User talk:Jean-philippe Romain|talk]]) 10:39, 13 August 2021 (CEST)<br />Command line to be review for v3.1}}
      +
    {{PC$}} make -f $PWD/../Makefile.sdk all UBOOT_CONFIGS=stm32mp15_trusted_defconfig,trusted,u-boot.stm32 ENABLE_FIP=0
      +
      +
    * Go to the directory where the compilation results are stored
      +
    {{PC$}} cd ../deploy/
      +
      +
    * Reboot the board, and hit any key to stop in the U-boot shell
      +
    {{Board$}} reboot
      +
    [...]
      +
    Hit any key to stop autoboot:  0
      +
    STM32MP>
      +
      +
    * Connect a USB cable between the host machine and the board via the USB OTG ports
      +
      +
    * In the U-Boot shell, call the USB mass storage function
      +
    STM32MP> ums 0 mmc 0
      +
    {{Info|For more information about the usage of U-Boot UMS functionality, see [[How to use USB mass storage in U-Boot]]}}
      +
      +
      +
    * On the host machine, check the partition associated with the secondary stage boot loader (''ssbl''): ''sdb3'' here
      +
    {{PC$}} ls -l /dev/disk/by-partlabel/
      +
    total 0
      +
    lrwxrwxrwx 1 root root 10 Feb  8 08:57 bootfs -> ../../sdb4
      +
    lrwxrwxrwx 1 root root 10 Feb  8 08:57 fsbl1 -> ../../sdb1
      +
    lrwxrwxrwx 1 root root 10 Feb  8 08:57 fsbl2 -> ../../sdb2
      +
    lrwxrwxrwx 1 root root 10 Feb  8 08:57 rootfs -> ../../sdb6
      +
    lrwxrwxrwx 1 root root 10 Feb  8 08:57 {{Highlight|ssbl -> ../../sdb3}}
      +
    lrwxrwxrwx 1 root root 10 Feb  8 08:57 userfs -> ../../sdb7
      +
    lrwxrwxrwx 1 root root 10 Feb  8 08:57 vendorfs -> ../../sdb5
      +
      +
    * Copy the U-Boot binary to the dedicated partition
      +
    {|
      +
    || '''STM32MP157C-EV1'''
      +
    ||
      +
    {{PC$}} dd if={{Highlight|u-boot-stm32mp157c-ev1-trusted.stm32}} of=/dev/sdb3 bs=1M conv=fdatasync
      +
    |-
      +
    || '''STM32MP157C-DK2'''
      +
    ||
      +
    {{PC$}} dd if={{Highlight|u-boot-stm32mp157c-dk2-trusted.stm32}} of=/dev/sdb3 bs=1M conv=fdatasync
      +
    |}
      +
    </div>
      +
    </div>
      +
      +
    or
      +
      +
    <div class="mw-collapsible">
      +
    '''FIP images case building ({{Highlight|Default}})'''
      +
    <div class="mw-collapsible-content">
       
     
    * As mentionned in help, OpenSTLinux has activated FIP by default, so the "FIP_artifacts" folder should be specified to allow to update the FIP binary with the new U-Boot binary. When using the "SOURCES-xxxx.tar.gz" from Developer package the "FIP_DEPLOYDIR_ROOT" var should be set as below:
     
    * As mentionned in help, OpenSTLinux has activated FIP by default, so the "FIP_artifacts" folder should be specified to allow to update the FIP binary with the new U-Boot binary. When using the "SOURCES-xxxx.tar.gz" from Developer package the "FIP_DEPLOYDIR_ROOT" var should be set as below:
    Line 409: Line 483:
     
      {{PC$}} export FIP_DEPLOYDIR_FIP=$PWD/../deploy/fip
     
      {{PC$}} export FIP_DEPLOYDIR_FIP=$PWD/../deploy/fip
       
    * Cross-compile the U-Boot: trusted boot for STM32MP157C-EV1 and STM32MP157C-DK2
    +
    * Cross-compile the U-Boot: here trusted boot for '''STM32MP157C-EV1''' and '''STM32MP157C-DK2'''
      +
    {{ReviewsComments|-- [[User:Jean-philippe Romain|Jean-philippe Romain]] ([[User talk:Jean-philippe Romain|talk]]) 10:39, 13 August 2021 (CEST)<br />Command line to be review for v3.1}}
     
      {{PC$}} make -f $PWD/../Makefile.sdk all UBOOT_CONFIGS=stm32mp15_trusted_defconfig,trusted,u-boot.dtb DEVICE_TREE="stm32mp157c-ev1-trusted stm32mp157c-dk2"
     
      {{PC$}} make -f $PWD/../Makefile.sdk all UBOOT_CONFIGS=stm32mp15_trusted_defconfig,trusted,u-boot.dtb DEVICE_TREE="stm32mp157c-ev1-trusted stm32mp157c-dk2"
       
    Line 426: Line 501:
     
      STM32MP> ums 0 mmc 0
     
      STM32MP> ums 0 mmc 0
     
    {{Info|For more information about the usage of U-Boot UMS functionality, see [[How to use USB mass storage in U-Boot]]}}
     
    {{Info|For more information about the usage of U-Boot UMS functionality, see [[How to use USB mass storage in U-Boot]]}}
      +
       
     
    * On the host machine, check the partition associated with the secondary stage boot loader that contains the FIP binary (''fip''): ''sdb3'' here
     
    * On the host machine, check the partition associated with the secondary stage boot loader that contains the FIP binary (''fip''): ''sdb3'' here
    Line 439: Line 515:
       
     
    * Copy the FIP binary to the dedicated partition
     
    * Copy the FIP binary to the dedicated partition
    ''STM32MP157C-EV1''
    +
    {{ReviewsComments|-- [[User:Jean-philippe Romain|Jean-philippe Romain]] ([[User talk:Jean-philippe Romain|talk]]) 14:59, 12 August 2021 (CEST)<br />MP13 disco board to be added for v4}}
      {{PC$}} dd if=fip-stm32mp157c-ev1-trusted.bin of=/dev/sdb3 bs=1M conv=fdatasync
    +
    {|
    ''STM32MP157C-DK2''
    +
    || '''STM32MP157C-EV1'''
      {{PC$}} dd if=fip-stm32mp157c-dk2-trusted.bin of=/dev/sdb3 bs=1M conv=fdatasync
    +
    ||
      +
      {{PC$}} dd if={{Highlight|fip-stm32mp157c-ev1-trusted.bin}} of=/dev/sdb3 bs=1M conv=fdatasync
      +
    |-
      +
    || '''STM32MP157C-DK2'''
      +
    ||
      +
      {{PC$}} dd if={{Highlight|fip-stm32mp157c-dk2-trusted.bin}} of=/dev/sdb3 bs=1M conv=fdatasync
      +
    |}
      +
    </div>
      +
    </div>
       
     
    * Reset the U-Boot shell
     
    * Reset the U-Boot shell
    Line 448: Line 532:
       
     
    * Have a look at the new U-Boot log information when the board reboots
     
    * Have a look at the new U-Boot log information when the board reboots
    ''STM32MP157C-EV1''
    +
    {{ReviewsComments|-- [[User:Jean-philippe Romain|Jean-philippe Romain]] ([[User talk:Jean-philippe Romain|talk]]) 14:59, 12 August 2021 (CEST)<br />MP13 disco board to be added for v4}}
      +
    {|
      +
    || '''STM32MP157C-EV1'''
      +
    ||
     
      [...]
     
      [...]
     
      U-Boot <U-Boot version> (<U-Boot build time flag>)
     
      U-Boot <U-Boot version> (<U-Boot build time flag>)
    Line 456: Line 543:
     
      {{Highlight|U-Boot simple example}}
     
      {{Highlight|U-Boot simple example}}
     
      [...]
     
      [...]
     
    +
    |-
    ''STM32MP157C-DK2''
    +
    || '''STM32MP157C-DK2'''
      +
    ||
     
      [...]
     
      [...]
     
      U-Boot <U-Boot version> (<U-Boot build time flag>)
     
      U-Boot <U-Boot version> (<U-Boot build time flag>)
    Line 465: Line 553:
     
      {{Highlight|U-Boot simple example}}
     
      {{Highlight|U-Boot simple example}}
     
      [...]
     
      [...]
      +
    |}
       
     
    ==Modifying the TF-A==
     
    ==Modifying the TF-A==
    Line 477: Line 566:
     
      [...]
     
      [...]
       
    * Go to the <TF-A source directory>
    +
    * Go to the TF-A source directory
      {{PC$}} cd <TF-A source directory>
    +
      {{PC$}} cd {{HighlightParam|''<TF-A source directory>''}}
       
    * Edit the ''./plat/st/stm32mp1/bl2_plat_setup.c'' source file
    +
    '''Example:'''
    * Add a log information in the ''print_reset_reason'' function
    +
    * Edit the ''./plat/st/stm32mp1/bl2_plat_setup.c'' source file to add a log information in the ''print_reset_reason'' function
     
      static void print_reset_reason(void)
     
      static void print_reset_reason(void)
     
      {
     
      {
    Line 494: Line 583:
     
      {{PC$}} make -f $PWD/../Makefile.sdk help
     
      {{PC$}} make -f $PWD/../Makefile.sdk help
       
    * Cross-compile the TF-A: trusted boot for STM32MP157C-EV1 and STM32MP157C-DK2 for microSD card
    +
    {{ReviewsComments|-- [[User:Jean-philippe Romain|Jean-philippe Romain]] ([[User talk:Jean-philippe Romain|talk]]) 16:58, 12 August 2021 (CEST)<br />Below section to be removed on v4}}
      +
    <div class="mw-collapsible mw-collapsed">
      +
    '''stm32 legacy images case building (no FIP)'''
      +
    <div class="mw-collapsible-content">
      +
    {{UnderConstruction| This section to be reviewed}}
      +
    * Cross-compile the TF-A: here trusted boot for '''STM32MP157C-EV1''' and '''STM32MP157C-DK2'''
      +
    {{PC$}} make -f $PWD/../Makefile.sdk TF_A_CONFIG=trusted ENABLE_FIP=0 all
      +
     
      +
    * Go to the directory in which the compilation results are stored
      +
    {{PC$}} cd ../deploy
      +
     
      +
    * Reboot the board, and hit any key to stop in the U-boot shell
      +
    {{Board$}} reboot
      +
    [...]
      +
    Hit any key to stop autoboot:  0
      +
    STM32MP>
      +
     
      +
    * Connect a USB cable between the host machine and the board via the USB OTG ports
      +
     
      +
    * In the U-Boot shell, call the USB mass storage function
      +
    STM32MP> ums 0 mmc 0
      +
    {{Info|For more information about the usage of U-Boot UMS functionality, see [[How to use USB mass storage in U-Boot]]}}
      +
     
      +
    * On the host machine, check the partition associated with the first stage boot loader (''fsbl1'' and ''fsbl2'' as backup): ''sdb1'' and ''sdb2'' (as backup) here
      +
    {{PC$}} ls -l /dev/disk/by-partlabel/
      +
    total 0
      +
    lrwxrwxrwx 1 root root 10 Feb  8 10:01 bootfs -> ../../sdb4
      +
    lrwxrwxrwx 1 root root 10 Feb  8 10:01 {{Highlight|fsbl1 -> ../../sdb1}}
      +
    lrwxrwxrwx 1 root root 10 Feb  8 10:01 {{Highlight|fsbl2 -> ../../sdb2}}
      +
    lrwxrwxrwx 1 root root 10 Feb  8 10:01 rootfs -> ../../sdb6
      +
    lrwxrwxrwx 1 root root 10 Feb  8 10:01 ssbl -> ../../sdb3
      +
    lrwxrwxrwx 1 root root 10 Feb  8 10:01 userfs -> ../../sdb7
      +
    lrwxrwxrwx 1 root root 10 Feb  8 10:01 vendorfs -> ../../sdb5
      +
     
      +
    * Copy the TF-A  binary to the dedicated partition; to test the new TF-A binary, it might be useful to keep the old TF-A binary in the backup FSBL (''fsbl2'')
      +
    {{ReviewsComments|-- [[User:Jean-philippe Romain|Jean-philippe Romain]] ([[User talk:Jean-philippe Romain|talk]]) 15:08, 12 August 2021 (CEST)<br />MP13 disco board to be added for v4}}
      +
    {|
      +
    || '''STM32MP157C-EV1'''
      +
    ||
      +
    {{PC$}} dd if={{Highlight|tf-a-stm32mp157c-ev1-trusted.stm32}} of=/dev/sdb1 bs=1M conv=fdatasync
      +
    |-
      +
    || '''STM32MP157C-DK2'''
      +
    ||
      +
    {{PC$}} dd if={{Highlight|tf-a-stm32mp157c-dk2-trusted.stm32}} of=/dev/sdb1 bs=1M conv=fdatasync
      +
    |}
      +
    {{Info|In case you get a ''permission denied'' you can set more permission on ''/dev/sdb1'' : ''sudo chmod 777 /dev/sdb1''}}
      +
     
      +
     
      +
    * Reset the U-Boot shell
      +
    In the U-Boot shell, press Ctrl+C prior to get hand back.
      +
    STM32MP> reset
      +
     
      +
    * Have a look at the new TF-A log information when the board reboots
      +
    [...]
      +
    INFO:      System reset generated by MPU (MPSYSRST)
      +
    INFO:    {{Highlight|TF-A simple example}}
      +
    INFO:    PMIC version = 0x10
      +
    INFO:    Using SDMMC
      +
    [...]
      +
     
      +
    </div>
      +
    </div>
      +
     
      +
    or
      +
     
      +
    <div class="mw-collapsible">
      +
    '''FIP images case building ({{Highlight|Default}})'''
      +
    <div class="mw-collapsible-content">
      +
    * Cross-compile the TF-A: here trusted boot for '''STM32MP157C-EV1''' and '''STM32MP157C-DK2''' for microSD card
     
      {{PC$}} make -f $PWD/../Makefile.sdk stm32 TF_A_CONFIG="sdcard"
     
      {{PC$}} make -f $PWD/../Makefile.sdk stm32 TF_A_CONFIG="sdcard"
       
    Line 524: Line 681:
       
     
    * Copy the TF-A  binary to the dedicated partition; to test the new TF-A binary, it might be useful to keep the old TF-A binary in the backup FSBL (''fsbl2'')  
     
    * Copy the TF-A  binary to the dedicated partition; to test the new TF-A binary, it might be useful to keep the old TF-A binary in the backup FSBL (''fsbl2'')  
     
    +
    {{ReviewsComments|-- [[User:Jean-philippe Romain|Jean-philippe Romain]] ([[User talk:Jean-philippe Romain|talk]]) 15:08, 12 August 2021 (CEST)<br />MP13 disco board to be added for v4}}
    ''STM32MP157C-EV1''
    +
    {|
      {{PC$}} dd if=tf-a-stm32mp157c-ev1-sdcard.stm32 of=/dev/sdb1 bs=1M conv=fdatasync
    +
    || '''STM32MP157C-EV1'''
      +
    ||
      +
      {{PC$}} dd if={{Highlight|tf-a-stm32mp157c-ev1-sdcard.stm32}} of=/dev/sdb1 bs=1M conv=fdatasync
      +
    |-
      +
    || '''STM32MP157C-DK2'''
      +
    ||
      +
    {{PC$}} dd if={{Highlight|tf-a-stm32mp157c-dk2-sdcard.stm32}} of=/dev/sdb1 bs=1M conv=fdatasync
      +
    |}
     
    {{Info|In case you get a ''permission denied'' you can set more permission on ''/dev/sdb1'' : ''sudo chmod 777 /dev/sdb1''}}
     
    {{Info|In case you get a ''permission denied'' you can set more permission on ''/dev/sdb1'' : ''sudo chmod 777 /dev/sdb1''}}
       
    ''STM32MP157C-DK2''
     
    {{PC$}} dd if=tf-a-stm32mp157c-dk2-sdcard.stm32 of=/dev/sdb1 bs=1M conv=fdatasync
     
       
     
    * Reset the U-Boot shell
     
    * Reset the U-Boot shell
    Line 574: Line 736:
     
      total 0
     
      total 0
     
      lrwxrwxrwx 1 root root 10 Feb  8 10:01 bootfs -> ../../sdb4
     
      lrwxrwxrwx 1 root root 10 Feb  8 10:01 bootfs -> ../../sdb4
      lrwxrwxrwx 1 root root 10 Feb  8 10:01 {{Highlight|fsbl1 -> ../../sdb1}}
    +
      lrwxrwxrwx 1 root root 10 Feb  8 10:01 Highlight|fsbl1 -> ../../sdb1
      lrwxrwxrwx 1 root root 10 Feb  8 10:01 {{Highlight|fsbl2 -> ../../sdb2}}
    +
      lrwxrwxrwx 1 root root 10 Feb  8 10:01 Highlight|fsbl2 -> ../../sdb2
     
      lrwxrwxrwx 1 root root 10 Feb  8 10:01 rootfs -> ../../sdb6
     
      lrwxrwxrwx 1 root root 10 Feb  8 10:01 rootfs -> ../../sdb6
      lrwxrwxrwx 1 root root 10 Feb  8 10:01 fip -> ../../sdb3
    +
      lrwxrwxrwx 1 root root 10 Feb  8 10:01 {{Highlight|fip -> ../../sdb3}}
     
      lrwxrwxrwx 1 root root 10 Feb  8 10:01 userfs -> ../../sdb7
     
      lrwxrwxrwx 1 root root 10 Feb  8 10:01 userfs -> ../../sdb7
     
      lrwxrwxrwx 1 root root 10 Feb  8 10:01 vendorfs -> ../../sdb5
     
      lrwxrwxrwx 1 root root 10 Feb  8 10:01 vendorfs -> ../../sdb5
    Line 583: Line 745:
     
    :* Copy the FIP  binary to the dedicated partition
     
    :* Copy the FIP  binary to the dedicated partition
       
    ''STM32MP157C-EV1''
    +
    {|
      {{PC$}} dd if=fip-stm32mp157c-ev1-trusted.bin of=/dev/sdb3 bs=1M conv=fdatasync
    +
    || '''STM32MP157C-EV1'''
    {{Info|In case you get a ''permission denied'' you can set more permission on ''/dev/sdb1'' : ''sudo chmod 777 /dev/sdb3''}}
    +
    ||
     
    +
      {{PC$}} dd if={{Highlight|fip-stm32mp157c-ev1-trusted.bin}} of=/dev/sdb3 bs=1M conv=fdatasync
    ''STM32MP157C-DK2''
    +
    |-
    {{PC$}} dd if=fip-stm32mp157c-dk2-trusted.bin of=/dev/sdb3 bs=1M conv=fdatasync
    +
    || '''STM32MP157C-DK2'''
      +
    ||
      +
    {{PC$}} dd if={{Highlight|fip-stm32mp157c-dk2-trusted.bin}} of=/dev/sdb3 bs=1M conv=fdatasync
      +
    |}
      +
    {{Info|In case you get a ''permission denied'' you can set more permission on ''/dev/sdb3'' : ''sudo chmod 777 /dev/sdb3''}}
      +
    </div>
      +
    </div>
       
     
    * Reset the U-Boot shell
     
    * Reset the U-Boot shell
    Line 599: Line 767:
     
    ===Source code file===
     
    ===Source code file===
     
    * Go to the working directory that contains all the source codes (i.e. directory that contains the Linux kernel, U-Boot and TF-A source code directories)
     
    * Go to the working directory that contains all the source codes (i.e. directory that contains the Linux kernel, U-Boot and TF-A source code directories)
      {{PC$}} cd <tag>/sources/arm-<distro>-linux-gnueabi
    +
      {{PC$}} cd {{HighlightParam|''<tag>''}}/sources/arm-<distro>-linux-gnueabi
       
     
    * Create a directory for this user space example
     
    * Create a directory for this user space example
    Line 644: Line 812:
     
    The sysroot location must be specified using the --sysroot option. The ''CC'' environment variable created by the SDK already includes the ''--sysroot'' option that points to the SDK sysroot location.
     
    The sysroot location must be specified using the --sysroot option. The ''CC'' environment variable created by the SDK already includes the ''--sysroot'' option that points to the SDK sysroot location.
     
      {{PC$}} echo $CC
     
      {{PC$}} echo $CC
      arm-ostl-linux-gnueabi-gcc -march=armv7ve -mthumb -mfpu=neon-vfpv4 -mfloat-abi=hard -mcpu=cortex-a7 --sysroot=<SDK installation directory>/SDK/sysroots/cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi
    +
      arm-ostl-linux-gnueabi-gcc -march=armv7ve -mthumb -mfpu=neon-vfpv4 -mfloat-abi=hard -mcpu=cortex-a7 --sysroot={{HighlightParam|''<SDK installation directory>''}}/SDK/sysroots/cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi
       
     
    * Create the directory in which the generated binary is to be stored
     
    * Create the directory in which the generated binary is to be stored
    Line 656: Line 824:
     
    For example, see the following environment variables:
     
    For example, see the following environment variables:
     
      {{PC$}} echo $CC
     
      {{PC$}} echo $CC
      arm-ostl-linux-gnueabi-gcc -march=armv7ve -mthumb -mfpu=neon-vfpv4 -mfloat-abi=hard -mcpu=cortex-a7 --sysroot=<SDK installation directory>/SDK/sysroots/cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi
    +
      arm-ostl-linux-gnueabi-gcc -march=armv7ve -mthumb -mfpu=neon-vfpv4 -mfloat-abi=hard -mcpu=cortex-a7 --sysroot={{HighlightParam|''<SDK installation directory>''}}/SDK/sysroots/cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi
     
      {{PC$}} echo $CFLAGS
     
      {{PC$}} echo $CFLAGS
     
      -O2 -pipe -g -feliminate-unused-debug-types
     
      -O2 -pipe -g -feliminate-unused-debug-types