{"id":5106,"date":"2019-07-17T08:49:41","date_gmt":"2019-07-17T15:49:41","guid":{"rendered":"https:\/\/visualgdb.com\/w\/?p=5106"},"modified":"2020-08-17T07:00:13","modified_gmt":"2020-08-17T14:00:13","slug":"building-an-openstlinux-sdk-for-stm32mp1-devices","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/linux\/stm32mp1\/sdk\/","title":{"rendered":"Building an OpenSTLinux SDK for STM32MP1 Devices"},"content":{"rendered":"<p>This tutorial shows how to build an OpenSTLinux SDK for the STM32MP1 devices. The SDK includes the SD card images for common development boards, a cross-toolchain and the headers\/libraries necessary to cross-compile Linux applications that will run on the Cortex-A cores of the STM32MP1 device. We will show how to use the <strong>repo<\/strong> and <strong>bitbake<\/strong> tools to generate the SDK and how to use it the SDK to compile Linux applications for the STM32MP1 device.<\/p>\n<ol>\n<li>The OpenSTLinux build process depends on a large and relatively fragile ecosystem of Linux tools and hence requires using a specific version of Linux to be running on the build machine. The\u00a0<strong>openstlinux-4.19-thud-mp1-19-02-20<\/strong> version shown in this tutorial requires the Ubuntu 18.04.2, so we recommend creating a Linux VM based on <a href=\"http:\/\/releases.ubuntu.com\/18.04\/ubuntu-18.04.2-desktop-amd64.iso\">ubuntu-18.04.2-desktop-amd64.iso<\/a> with at least 80GB of disk space. To speed up the build, ensure the VM has as many CPU cores as your host machine does.<\/li>\n<li>Connect to your build machine via SSH and run the following command to install the packages required by the OpenSTLinux tools:\n<pre class=\"\">sudo apt-get install sed wget curl cvs subversion git-core coreutils unzip texi2html texinfo docbook-utils gawk python-pysqlite2 diffstat help2man make gcc build-essential g++ desktop-file-utils chrpath libxml2-utils xmlto docbook bsdmainutils iputils-ping cpio python-wand python-pycryptopp python-crypto libsdl1.2-dev xterm corkscrew nfs-common nfs-kernel-server device-tree-compiler mercurial u-boot-tools libarchive-zip-perl ncurses-dev bc linux-headers-generic gcc-multilib libncurses5-dev libncursesw5-dev lrzsz dos2unix lib32ncurses5 repo libssl-dev<\/pre>\n<p>Then confirm the package installation:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/01-packages.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5107\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/01-packages.png\" alt=\"\" width=\"1024\" height=\"691\" \/><\/a><\/li>\n<li>Create a directory for the OpenSTLinux distro you are going to build (e.g. <strong>\/opt\/stlinux-weston<\/strong>) and ensure your user account can write to it. Then clone and initialize the OpenSTLinux repository:\n<pre class=\"\">sudo mkdir \/opt\/stlinux-weston\r\nsudo chown &lt;username&gt;:&lt;groupname&gt; \/opt\/stlinux-weston\r\ncd \/opt\/sylinux-weston\r\nrepo init -u https:\/\/github.com\/STMicroelectronics\/oe-manifest.git -b refs\/tags\/openstlinux-4.19-thud-mp1-19-02-20 &amp;&amp; repo sync<\/pre>\n<p>You can safely ignore the 404 errors during the repo initialization as long as the repo sync command completes successfully:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/02-repo.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5108\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/02-repo.png\" alt=\"\" width=\"1024\" height=\"691\" \/><\/a><\/li>\n<li>Once the repository is initialized, the repo tool will show the list of available tags:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/03-built.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5109\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/03-built.png\" alt=\"\" width=\"1024\" height=\"691\" \/><\/a><\/li>\n<li>Now you are almost ready to start building the OpenSTLinux SDK. Run the following command to setup the necessary environment:\n<pre class=\"\">DISTRO=openstlinux-weston MACHINE=stm32mp1 source layers\/meta-st\/scripts\/envsetup.sh<\/pre>\n<p>Note the image name shown by the <strong>envsetup.sh<\/strong> script:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/04-env.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5110\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/04-env.png\" alt=\"\" width=\"1671\" height=\"947\" \/><\/a><\/li>\n<li>Now it&#8217;s time to build the SDK. Run the following command to begin the build:\n<pre class=\"\">bitbake st-image-weston<\/pre>\n<p>Note that if your VM has insufficient RAM, the build will fail with the following error:<\/p>\n<pre class=\"\">ERROR: Worker process (21931) exited unexpectedly (-9), shutting down...<\/pre>\n<p>If this happens, try increasing the RAM size of your VM, or decrease the amount of its CPU cores. Otherwise, the build will successfully complete after several hours and may produce a few warnings that can be ignored:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/05-built.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5113\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/05-built.png\" alt=\"\" width=\"1188\" height=\"512\" \/><\/a><\/li>\n<li>Go to the <strong>\/opt\/stlinux-weston\/build-openstlinuxweston-stm32mp1\/tmp-glibc\/deploy\/images\/stm32mp1<\/strong> directory and obtain a list of all files there:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/layouts.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5114\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/layouts.png\" alt=\"\" width=\"1188\" height=\"473\" \/><\/a><\/li>\n<li>Note that the <strong>stm32mp1<\/strong> directory itself contains multiple binary files, while the <strong>flashlayout_st-image-weston<\/strong> subdirectory contains text files that describe how the binaries should be mapped to different memories (e.g. partitions on the SD card):<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/layout.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5115\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/layout.png\" alt=\"\" width=\"1188\" height=\"473\" \/><\/a><\/li>\n<li>Now we will program the SD card on the board. In this tutorial we are using Windows, so we will copy the entire <strong>\/opt\/stlinux-weston\/build-openstlinuxweston-stm32mp1\/tmp-glibc\/deploy\/images\/stm32mp1<\/strong> directory to the Windows side (use <a href=\"https:\/\/sysprogs.com\/SmarTTY\/\">SmarTTY<\/a> to handle symlinks automatically).\u00a0 Switch your board into the bootloader mode via the jumpers and connect both power and data USB connectors:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/wiring.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5116\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/wiring.jpg\" alt=\"\" width=\"1200\" height=\"471\" \/><\/a><\/li>\n<li>Locate the FLASH layout file that matches your board. It should typically contain the board name and the word &#8220;trusted&#8221; indicating the trusted bootchain in the name (e.g. FlashLayout_sdcard_stm32mp157c-dk2-trusted.tsv). Then program it using our <a href=\"http:\/\/visualgdb.com\/tools\/STM32MP1Programmer\/\">FLASH Programming tool for STM32WB1 devices<\/a>:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/manual.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5117\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/manual.png\" alt=\"\" width=\"686\" height=\"618\" \/><\/a><\/li>\n<li>Once the SD card image has been programmed, switch the board back to &#8220;boot from SD card&#8221; mode and connect the power and the on-board ST-Link:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/normal.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5118\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/normal.jpg\" alt=\"\" width=\"1200\" height=\"621\" \/><\/a><\/li>\n<li>The on-board ST-Link includes a COM port connected to one of the STM32MP1&#8217;s UART ports. Locate it in the Device Manager:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/08-comport.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5119\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/08-comport.png\" alt=\"\" width=\"730\" height=\"367\" \/><\/a><\/li>\n<li>Then connect to the port (use a baud rate of 115200) via a terminal program and reset the board. The board will start up and open a root terminal:\u00a0 <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/09-booted-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5122\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/09-booted-1.png\" alt=\"\" width=\"674\" height=\"440\" \/><\/a><\/li>\n<li>The on-board LCD screen will display a demo application:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/lcd.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5121\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/lcd.jpg\" alt=\"\" width=\"1280\" height=\"641\" \/><\/a><\/li>\n<li>Finally, we will build an SDK that allows compiling C\/C++ Linux applications that will run on the STM32MP1 device. Switch back to the build environment (started by running envsetup.sh on the build machine) and run the following command:\n<pre class=\"\">bitbake -c populate_sdk st-image-weston<\/pre>\n<p><a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/10-populate.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5123\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/10-populate.png\" alt=\"\" width=\"1188\" height=\"512\" \/><\/a><\/li>\n<li>This command will build an SDK installer (a self-extracting <strong>.sh<\/strong> file under the tmp-glibc\/deploy\/sdk directory). Locate the installer script and run it to extract the SDK for the previously built image:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/sdk.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5125\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/sdk.png\" alt=\"\" width=\"1188\" height=\"512\" \/><\/a><\/li>\n<li>In order to build C\/C++ programs for the board, load the environment from the <strong>&lt;sdk location&gt;\/environment-setup-cortexa7t2hf-neon-vfpv4-openstlinux_weston-linux-gnueabi<\/strong> file. This will set the <strong>CC,<\/strong> <strong>LD<\/strong> and other common environment variables to point to the correct SDK tools including all flags. Then you can simply invoke <strong>$CC<\/strong> instead of the regular <strong>gcc<\/strong> executable to produce binaries compatible with the STM32MP1 board:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/hello.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5126\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2019\/07\/hello.png\" alt=\"\" width=\"1423\" height=\"424\" \/><\/a><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to build an OpenSTLinux SDK for the STM32MP1 devices. The SDK includes the SD card images<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[186,61,187,185],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/5106"}],"collection":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/comments?post=5106"}],"version-history":[{"count":4,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/5106\/revisions"}],"predecessor-version":[{"id":5127,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/5106\/revisions\/5127"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=5106"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=5106"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=5106"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}