context

The following are just a bunch of notes on getting the STM32MP1 development environment running on Ubuntu 20.04LTS. The ST wiki is horseshit (i.e. difficult to navigate topics in a coherent manner) so I’m collecting my (terse) notes here.

Anyhow, this should get you from zero to hero. (this was copied from my org-mode notes, so hopefully the formatting is ok).

install dependencies

  # packages required by OpenEmbedded/Yocto (distribution package)
  sudo apt-get update
  sudo apt-get install gawk wget git-core diffstat unzip texinfo \
       gcc-multilib build-essential chrpath socat cpio python3   \
       python3-pip python3-pexpect xz-utils debianutils          \ 
       iputils-ping python3-git python3-jinja2 libegl1-mesa      \
       libsdl1.2-dev pylint3 pylint xterm
  sudo apt-get install make xsltproc docbook-utils fop           \ 
       dblatex xmlto
  sudo apt-get install libmpc-dev libgmp-dev
  # packages required by the developer package
  sudo apt-get install libncurses5 libncurses5-dev               \
       libncursesw5-dev libssl-dev linux-headers-generic         \
       u-boot-tools device-tree-compiler bison flex g++          \
       libyaml-dev libmpc-dev libgmp-dev
  sudo apt-get install libusb-1.0-0
  # suggested tools
  sudo apt-get install coreutils bsdmainutils sed curl bc lrzsz  \
       corkscrew cvs subversion mercurial nfs-common             \
       nfs-kernel-server libarchive-zip-perl dos2unix texi2html  \
       diffstat libxml2-utils
  # personal tools
  sudo apt-get emacs minicom ssh zsh tree fortune
  # start sshd
  sudo systemctl enable ssh.service
  # change default shell to zsh
  chsh
  # increase the default number of partitions on MMC devices
  echo 'options mmc_block perdev_minors=16' > /tmp/mmc_block.conf
  sudo mv /tmp/mmc_block.conf /etc/modprobe.d/mmc_block.conf

create directories, download and install ST packages

  #
  # install the STMProgrammer app
  #
  mkdir -p ~/STM32MPU_workspace/STM32MPU-Tools/STM32CubeProgrammer-2.8.0/
  mkdir ~/STM32MPU_workspace/tmp
  cd !$
  # * download the latest version of STMCubeProgrammer
  unzip en.stm32cubeprg-lin_v2-8-0_v2.8.0.zip
  ./SetupSTM32CubeProgrammer-2.8.0.linux
  # install to ~/STM32MPU_workspace/STM32MPU-Tools/STM32CubeProgrammer-2.8.0/
  # copy the udev rules
  cd $HOME/STM32MPU_workspace/STM32MPU-Tools/STM32CubeProgrammer-2.8.0/Drivers/rules
  sudo cp * /etc/udev/rules.d
  #
  # install the starter package.
  #
  # I think this just has a bunch of prebuilt installation images.
  # anyhow...
  mkdir -p $HOME/STM32MPU_workspace/STM32MP15-Ecosystem-v3.1.0/Starter-Package
  cd !$
  # * download the starter package to the aforementioned directory
  tar xf en.FLASH-stm32mp1-openstlinux-5-10-dunfell-mp1-21-11-17_tar_v3.1.0.xz
  # OK, here we just follow the instructions on the wiki for flashing a
  # new image to the sdcard.
  #
  # install the A7 sdk
  #
  # * download the toolchain (the SDK not the SOURCES, though we'll want
  # * the SOURCES one later.)
  cd ~/STM32MPU_workspace/tmp
  tar xf en.SDK-x86_64-stm32mp1-openstlinux-5.10-dunfell-mp1-21-11-17.tar_v3.1.0.xz
  mkdir -p ~/STM32MPU_workspace/STM32MP15-Ecosystem-v3.1.0/Developer-Package/SDK
  chmod +x stm32mp1-openstlinux-5.10-dunfell-mp1-21-11-17/sdk/st-image-weston-openstlinux-weston-stm32mp1-x86_64-toolchain-3.1.11-openstlinux-5.10-dunfell-mp1-21-11-17.sh
  ./stm32mp1-openstlinux-5.10-dunfell-mp1-21-11-17/sdk/st-image-weston-openstlinux-weston-stm32mp1-x86_64-toolchain-3.1.11-openstlinux-5.10-dunfell-mp1-21-11-17.sh -d ~/STM32MPU_workspace/STM32MP15-Ecosystem-v3.1.0/Developer-Package/SDK
  # now, to setup the environment (MUST BE BASH!)
  . ~/STM32MPU_workspace/STM32MP15-Ecosystem-v3.1.0/Developer-Package/SDK/environment-setup-cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi

compile a kernel

  #
  # install the sources
  #
  cd ~/STM32MPU_workspace/STM32MP15-Ecosystem-v3.1.0/Developer-Package
  tar xf en.SOURCES-stm32mp1-openstlinux-5.10-dunfell-mp1-21-03-31.tar_v3.0.0.xz
  # extract the kernel sources
  cd stm32mp1-openstlinux-5.10-dunfell-mp1-21-03-31/sources/arm-ostl-linux-gnueabi/linux-stm32mp-5.10.10-r0
  tar xf linux-5.10.10.tar.xz
  # apply the ST patches
  cd linux-5.10.10
  for p in `ls -1 ../*.patch`; do patch -p1 < $p; done
  # apply the fragments (this is the ST augmented kernel configuration)
  # (XXX it's be nice to understand exactly what is going on here)
  make ARCH=arm multi_v7_defconfig "fragment*.config"
  for f in `ls -1 ../fragment*.config`; do 
      scripts/kconfig/merge_config.sh -m -r .config $f
  done
  yes '' | make ARCH=arm oldconfig
  # finally, build the kernel (XXX what are the 3 make targets?)
  make -j4 ARCH=arm uImage vmlinux dtbs LOADADDR=0xC2000040
  # build the kernel modules
  make -j4 ARCH=arm modules
  # install kernel modules to a local directory
  mkdir -p $PWD/install_artifact/
  make ARCH=arm INSTALL_MOD_PATH="$PWD/install_artifact" modules_install
  # push the kernel, device tree and modules to the board via scp
  scp arch/arm/boot/uImage root@192.168.0.100:/boot
  scp arch/arm/boot/dts/stm32mp157*.dtb root@192.168.0.100:/boot
  # remove the links in the artifact directory so we don't recursively copy
  rm install_artifact/lib/modules/5.10.10/build install_artifact/lib/modules/5.10.10/source
  # optionally strip the modules
  find install_artifact/ -name "*.ko" | xargs $STRIP --strip-debug --remove-section=.comment --remove-section=.note --preserve-dates
  # copy modules to the board
  scp -r install_artifact/lib/modules/* root@192.168.0.100:/lib/modules
  # aaaaaand on the board's console
  /sbin/depmod -a
  sync
  reboot

install the IDE for the sidecar M4

  #
  # install stm32cube ide
  #
  # * download and extract the installer
  unzip -q en.st-stm32cubeide_1.7.0_10852_20210715_0634_amd64.deb_bundle.sh_v1.7.0.zip
  cd en.st-stm32cubeide_1.7.0_10852_20210715_0634_amd64.deb_bundle.sh_v1.7.0
  chmod +x st-stm32cubeide_1.7.0_10852_20210715_0634_amd64.deb_bundle.sh
  sudo ./st-stm32cubeide_1.7.0_10852_20210715_0634_amd64.deb_bundle.sh
  # fin.

finally, enjoy beer


boddingtons

phew!

That is a lot of stuff to install!

Anyhow, here’s an obligatory pic of the board. As you can see, “embedded” is a misnomer in this case. Just check the specs of the STM32MP1 line.


STM32MP157D-EV1
plenty of accoutrements.