How do I deploy an ARM software executable from a Simulink model to my Zynq board to run in standalone mode? And how can this exectuable be auto-run on startup?

21 views (last 30 days)
I would like to deploy the ARM software executable generated from a Simulink model to my Zynq board (e.g. Zedboard, ZC702, ZC706, ZCU102...), so that it can be run without any connection to Simulink on my host machine.
However, each time I restart my Zynq board, the software application no longer runs. How do I permanently deploy the executable to my Zynq board so that it can always be run?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 24 Jan 2024
Edited: MathWorks Support Team on 24 Jan 2024
An ARM application deployed using Simulink is lost after reboot because Simulink places the executable in the  "/tmp" folder of the Zynq board's file system. This folder is cleared after power-cycling the board.
The following steps demonstrate how to generate and deploy a software executable in standalone mode, so that it can be run without any connection to Simulink on your host machine.
NOTE: This guide refers to the generated standalone executable as the “.elf file”. In R2018a and prior, the executable will not have a file extension. The steps below will be the same, but the executable file will be called “modelName” instead of “modelName.elf” 
1. In the Model Configuration Parameters, set the “Build action” to “Build”. This will generate the executable (.elf file) without automatically downloading it to the board and running it. 
2. Build the .elf file using the shortcut CTRL+B in Simulink, or in MATLAB using the "slbuild" command:
>> modelName = 'zynqRadioADSB_interface';
>> slbuild(modelName)
 When the build process completes, the "modelname.elf" file will be placed in your current directory.
3. Copy the .elf file to the board using the "zynq" object interface shipped with the "Embedded Coder Support Package for Xilinx Zynq Platform". Make sure to use the actual IP address of your board if it is different than 192.168.3.2. 
>> z = zynq('linux','192.168.3.2','root','root','/tmp')
z =
LinuxShell with properties:
IPAddress: '192.168.3.2'
  Username: 'root'
  Port: 22
>> z.putFile('zynqRadioADSB_interface.elf','/mnt')
 The second argument to putFile is the destination directory on the target. Here, "/mnt" is the mounted SD card directory in Linux. It is the only persistent directory in this Embedded Linux file system, so placing the .elf file somewhere other than /mnt will cause that file to disappear when the board is rebooted. 
4. Run the .elf file from an SSH terminal session on the target. 
>> z.openShell('ssh')
5. When you are done running the application, exit with Ctrl+C. 
6. If you would like the standalone software to run automatically when the board is powered on, add a line to the "init.sh" file on the SD card. This file is a shell script that is called by Linux on startup. 
Editing this file is shown below using the "vi" editor on the board, but you can also do this using your preferred text editor on your host machine, and copy this file to the SD card.
Please note that the /mnt directory is mapped to the FAT32 file system which is not a native Linux ext4 or tmpfs file system. To avoid any potential issues between these file systems, you should copy the ELF file to the /tmp
 directory, and then run the ELF file in the /tmp directory. You can copy and execute the ELF file on startup using this code in the "init.sh" file:\n
cp -f /mnt/<appname>.elf /tmp/<appname>.elf
cd /tmp && /tmp/<appname>.elf &
In this code, "<appname>" is the name of the executable.
  1 Comment
Abhijeet Gadkari
Abhijeet Gadkari on 20 Dec 2023
Typically, this will work for simpler cases, but the /mnt partition on Xilnx SoC Linux images is mapped to FAT32 file partition. FAT32 partition is not a Linux native ext4 or tmpfs partition. There may be issues with large data read/write, fragmentation etc, possibly other journaling issues. It is recommended to copy the app to /tmp or /root folder and run it from there.
So, you can update the init.sh code as follows:
cp -f /mnt/<appname>.elf /tmp/<appname>.elf
cd /tmp && /tmp/<appname>.elf &

Sign in to comment.

More Answers (0)

Products


Release

R2017a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!