Compiling Source Code
Installing the Toolchain
This section describes how to install the cross compilation toolchain on the Linux OS of the compilation program when the Atlas 200 AI accelerator module is used as the main processor or coprocessor.
Prerequisites
Software
WinSCP.exe (third-party free software)
Software Package
The cross compilation toolchain matching the OS kernel version is available.
OS Version |
OS Kernel Version |
Cross Compilation Toolchain |
---|---|---|
Ubuntu 16.04.3 LTS |
4.19.36+ |
Procedure
- Log in to the Linux server.
- Run the following command to switch to the root user:
su - root
- Run the following command to create the compiler directory in /opt/:
mkdir /opt/compiler
- Use WinSCP to upload the cross compilation toolchain to the /opt/compiler directory. For details, see Using WinSCP to Transfer Files.
- Switch to the /opt/compiler directory.
cd /opt/compiler
- Decompress the cross compilation tools.
Command: tar -xvf Cross compilation toolchain -C ./ --strip-components 1
Example: tar -xvf gcc-linaro-5.4.1-2017.05-x86_64_aarch64-linux-gnu.tar.xz -C /opt/compiler --strip-components 1
- Run the following command to add the path of the cross compilation toolchain to the configuration file:
echo "export PATH=\$PATH:/opt/compiler/bin" >> /etc/profile
- Run the following command for the environment variables to take effect:
source /etc/profile
- Run the following command to check the version of the cross compilation toolchain:
aarch64-linux-gnu-gcc -v
If the version information is displayed, the toolchain is successfully installed.
Compiling the Driver
Prerequisites
The Linux server has qemu-user-static, binfmtsupport, YAML, unzip, unrar, and cross compiler installed.
Modifying or Adding a Driver
You can modify the source code of an existing module as required. If a driver needs to be added, perform the following operations:
The following describes how to add the mdio driver as an example.
- Log in to the Linux server.
- Run the following command to switch to the root user:
su - root
- Use WinSCP to upload the A200-3000-Soc-SRC-Vxxx.zip software package to any directory on the Linux OS, for example, /opt. For details, see Using WinSCP to Transfer Files.
- Run the following command to go to the directory where the software package is stored, for example, /opt:
cd /opt
- Run the following command to decompress the A200-3000-Soc-SRC-Vxxx.zip package and obtain the mini_developerkit_source.rar package:
unzip A200-3000-Soc-SRC-Vxxx.zip
- Run the following command to decompress the mini_developerkit_source.rar package and obtain the source.tar.gz package:
unzip mini_developerkit_source.rar
- Run the following command to decompress the source.tar.gz software package:
tar -xzvf source.tar.gz
- Run the following command to go to the source/drivers directory:
cd source/drivers
- To add a user driver, run the following command to create the mdio directory:
mkdir mdio
- Add the driver file and makefile to the directory.
The format of the makefile is similar to other makefiles.
Compiling Drivers
- Log in to the Linux server.
- Run the following command to switch to the root user:
su - root
- Use WinSCP to upload the A200-3000-Soc-SRC-Vxxx.zip package to any directory on the Linux OS, for example, /opt. For details, see Using WinSCP to Transfer Files.
- Run the following command to go to the directory where the software package is stored, for example, /opt:
cd /opt
- Run the following command to decompress the A200-3000-Soc-SRC-Vxxx.zip package and obtain the mini_developerkit_source.rar package:
unzip A200-3000-Soc-SRC-Vxxx.zip
- Run the following command to decompress the mini_developerkit_source.rar package and obtain the source.tar.gz package:
unzip mini_developerkit_source.rar
- Run the following command to decompress the source.tar.gz package:
tar -xzvf source.tar.gz
- Go to the source directory.
cd source
- Run the following command to compile the OS kernel:
bash build.sh kernel
If an error is reported, check whether the dependency packages libncurses5-dev, bison, and flex have been installed. If the system displays a message indicating that some packages are not installed, for example, "/bin/sh: 1: bison: not found", run the apt-get command to install the required dependency packages.
- (Optional) In the DRV_MODLE_PATH variable of the build.sh script, add the "${DRV_DIR}/xxx" driver directory.
- Run the following command to open the build.sh script:
vim build.sh
- Add the MDIO driver to the DRV_MODLE_PATH variable.
- Press Esc, run the following command to save the modification, and press Enter to exit:
:wq!
- Perform this step only when a new driver module is added.
- xxx indicates the new driver module.
- Run the following command to open the build.sh script:
- Run the following command to compile the driver:
bash build.sh minirc
After the compilation is successful, the KO driver file is generated in the output directory.
Installing the Driver
- Log in to the Atlas 200 AI accelerator module by using SSH. The default IP address is 192.168.0.2. For details about the default user name and password, see Atlas Hardware Product User List.
- Copy the driver file generated after compilation to the /var/davinci/driver/ directory.
- Uninstall the original driver before compilation.
Command: rmmod Driver name
Example: rmmod drv_watchdog
- (Optional) During the uninstallation of the original driver, an error message shown in Figure 6-2 may be displayed. The error message does not affect the installation, uninstallation, and driver functions. The source code and header file installation package matching the kernel are not installed. To clear the error, download the linux-headers-4.19.36+_4.19.36+-1_arm64.deb, linux-image-4.19.36+_4.19.36+-1_arm64.deb, and linux-libc-dev_4.19.36+-1_arm64.deb installation packages from the Internet and run the following command to install them one by one:
Command: dpkg –i Installation package
Example: dpkg –i linux-headers-4.19.36+_4.19.36+-1_arm64.deb
- Load the driver.
- If the original Huawei driver is modified, the system automatically runs the boot script to load the driver after the device is restarted.
- If a driver is added, run the following command to load the driver:
- Run the following command to switch to the driver directory:
cd /var/davinci/driver/
- Run the following command to load the driver, for example, mdio.ko:
insmod mdio.ko
- Run the following command to switch to the driver directory:
The load_device_modules() function of the startup script minirc_sys_init.sh in the A200-3000-Soc-FW-Vxxx/scripts/ directory where the A200-3000-Soc-FW-Vxxx.zip package is located loads the original Huawei driver.