Currently, most industrial control systems are embedded systems (a few simple systems use bare metal development directly). An “embedded system” refers to a computer system with specific functions embedded within specific hardware. Embedded systems generally consist of a real-time operating system (RTOS) + application software (a PLC itself is also an embedded system). Common real-time operating systems include: FreeRTOS, RT-Linux, VxWorks, RT-Thread, SylixOS, etc. Among them, RT-Thread and SylixOS are purely domestic real-time operating systems; the former relies on community development and has very rich resources. I personally like it very much and will share related knowledge with you later. Linux itself is not a real-time operating system; for embedded development, it is best to use its real-time branch—RT-Linux. The embedded Linux system consists of four major components: cross-compilation toolchain, BootLoader, kernel, and root filesystem. In today’s article, I will introduce how to obtain and set up the cross-compilation toolchain.
Since embedded systems run on specific boards, while the development environment is an ordinary personal computer, the hardware of the board is significantly different from that of a personal computer. To ensure that the compiled program can run on the board, cross-compilation must be used (you can refer to previous articles: Embedded Development | What is Cross Compilation (CROSS_COMPILE)). Cross-compilation is accomplished by the cross-compilation toolchain.
1. Downloading and Extracting the Toolchain
The cross-compilation toolchain is a collection of tools. If you purchase a development board, the manufacturer usually provides the cross-compilation toolchain, but the version may be quite old. We can download Linaro’s toolchain from the following website:
https://releases.linaro.org/components/toolchain/binaries/
https://releases.linaro.org
For example, if we choose the latest version latest-7, click on “arm-linux-gnueabihf” to enter the download page and click on “gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf.tar.xz” to download the toolchain, as shown in the image below:
After the download is complete, enter the command window and type the following command to extract:
tar -xvf gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf.tar.tar
2. Setting Environment Variables
Add the /bin directory of the extracted toolchain to the environment variable PATH. Assuming the extraction path is: /home/jack/eLinux/toolChain/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf
Then add the following code in the command window:
export PATH=$PATH:/home/jack/eLinux/toolChain/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/binexport ARCH=armexport CROSS_COMPILE=arm-linux-gnueabihf-
The environment variables set in this way are temporary and will be lost after a restart.
To permanently set environment variables (you can choose one of the two methods):
1. Create a script in /etc/profile.d/, for example, linaro_toolchain.sh, and add the code we just wrote:
export PATH=$PATH:/home/jack/eLinux/toolChain/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/binexport ARCH=armexport CROSS_COMPILE=arm-linux-gnueabihf-
Save the script file and add executable attributes:
sudo chmod +x linaro_toolchain.sh
2. Open the profile file in the current user’s home directory (~/.profile) and add the code we just wrote:
export PATH=$PATH:/home/jack/eLinux/toolChain/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/binexport ARCH=armexport CROSS_COMPILE=arm-linux-gnueabihf-
Save the file and compile or restart.
source ~/.profile
Alright, this concludes the introduction to downloading and setting up the cross-compilation toolchain.
I share small knowledge about industrial control on my WeChat video account, welcome to watch: