只是做一下记录。由于uboot的兼容性问题,仍然选用gcc5。以下主要记录命令,基本可以直接复制使用。因目标平台为Cortex-A7,选择gnueabihf工具链。全文基本复读https://ntzyz.io/post/arm-v7-a-cross-compile-notes,zyz真是太强啦!

环境:Ubuntu 16.04 LTS + bash 执行用户需要具有root权限

#建立保存下载文件的临时文件夹
mkdir temp && cd temp

#下载linaro工具链
wget http://releases.linaro.org/components/toolchain/binaries/5.5-2017.10/arm-linux-gnueabihf/gcc-linaro-5.5.0-2017.10-x86_64_arm-linux-gnueabihf.tar.xz

#解压至/opt
xz -d gcc-linaro-5.5.0-2017.10-x86_64_arm-linux-gnueabihf.tar.xz
sudo tar xvf gcc-linaro-5.5.0-2017.10-x86_64_arm-linux-gnueabihf.tar -C /opt/

#准备目标文件系统,放置于/opt/basefiles中
sudo mkdir /opt/basefiles

#为当前session设置环境变量
export PATH=/opt/gcc-linaro-5.5.0-2017.10-x86_64_arm-linux-gnueabihf/bin:$PATH
export ARCH=arm
export CROSS_COMPILE=arm-linux-gnueabihf-

#下载并编译BusyBox
wget https://busybox.net/downloads/busybox-1.28.3.tar.bz2
tar xjvf busybox-1.28.3.tar.bz2
cd busybox-1.28.3
make defconfig
sudo ARCH=arm CROSS_COMPILE=/opt/gcc-linaro-5.5.0-2017.10-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf- make -j4 install CONFIG_PREFIX=/opt/basefiles
cd ..

#下载并编译SDL
wget https://www.libsdl.org/release/SDL-1.2.15.tar.gz
tar xvzf SDL-1.2.15.tar.gz
cd SDL-1.2.15
./configure --host=arm-linux-gnueabihf \
  --prefix=/opt/basefiles/usr \
  --disable-audio \
  --disable-threads \
  --disable-x11 \
  --disable-dga \
  --disable-video-photon \
  --disable-video-cocoa \
  --disable-video-directfb \
  --disable-video-ps2gs \
  --disable-video-ps3 \
  --disable-video-svga \
  --disable-video-vgl \
  --disable-video-wscons \
  --disable-video-xbios \
  --disable-video-gem \
  --disable-video-opengl
make -j4
sudo make install
cd ..

#下载并编译zlib, libpng和freetype的依赖
wget https://www.zlib.net/zlib-1.2.11.tar.gz
tar xvzf zlib-1.2.11.tar.gz
cd zlib-1.2.11
CC=arm-linux-gnueabihf-gcc LD=arm-linux-gnueabihf-ld AS=arm-linux-gnueabihf-as ./configure --prefix=/opt/basefiles/usr
make -j4
sudo make install
cd ..

#下载并编译libpng
wget https://download.sourceforge.net/libpng/libpng-1.6.36.tar.gz
tar xvzf libpng-1.6.36.tar.gz
cd libpng-1.6.36
./configure --host=arm-linux-gnueabihf \
            --prefix=/opt/basefiles/usr \
            CPPFLAGS="-I/opt/basefiles/usr/include" \
            LDFLAGS="-L/opt/basefiles/usr/lib"
make -j4
sudo make install
cd ..

#下载并编译SDL_image
wget https://www.libsdl.org/projects/SDL_image/release/SDL_image-1.2.12.tar.gz
tar xvzf SDL_image-1.2.12.tar.gz
cd SDL_image-1.2.12
./configure --host=arm-linux-gnueabihf \
            --prefix=/opt/basefiles/usr/ \
            --with-sdl-prefix=/opt/basefiles/usr/ \
            --disable-jpg \
            --disable-tif \
            --disable-webp \
            CFLAGS="-I/opt/basefiles/usr/include" \
            LDFLAGS="-L/opt/basefiles/usr/lib"
make -j4
sudo make install
cd ..

#下载并编译freetype
wget https://download.savannah.gnu.org/releases/freetype/freetype-2.9.1.tar.gz
tar xvzf freetype-2.9.1.tar.gz
cd freetype-2.9.1
./configure --host=arm-linux-gnueabihf \
            --prefix=/opt/basefiles/usr/ \
            --with-png=yes \
            CFLAGS="-I/opt/basefiles/usr/include" \
            LDFLAGS="-L/opt/basefiles/usr/lib" \
            PKG_CONFIG_PATH=/opt/basefiles/usr/lib/pkgconfig/
make -j4
sudo make install
cd ..

#下载并编译SDL_ttf
wget https://www.libsdl.org/projects/SDL_ttf/release/SDL_ttf-2.0.11.tar.gz
tar xvzf SDL_ttf-2.0.11.tar.gz
cd SDL_ttf-2.0.11
[ -e /opt/basefiles/usr/include/SDL/SDL_opengl.h ] && sudo mv /opt/basefiles/usr/include/SDL/SDL_opengl.h /opt/basefiles/usr/include/SDL/SDL_opengl.fucked.h
./configure --host=arm-linux-gnueabihf \
            --prefix=/opt/basefiles/usr/ \
            --with-freetype-prefix=/opt/basefiles/usr/ \
            CFLAGS="-I/opt/basefiles/usr/include -I/opt/basefiles/usr/include/freetype2" \
            LDFLAGS="-L/opt/basefiles/usr/lib -lfreetype -lpng -lz" \
            PKG_CONFIG_PATH=/opt/basefiles/usr/lib/pkgconfig/
make -j4
sudo make install
cd ..

#OpenCV3 未测试
#cmake -DCMAKE_TOOLCHAIN_FILE=../arm-gnueabi.toolchain.cmake ../../.. -DCMAKE_INSTALL_PREFIX=/opt/basefiles/usr -DENABLE_NEON=ON

#向目标文件系统补充必要的动态链接库
wget http://releases.linaro.org/components/toolchain/binaries/5.5-2017.10/arm-linux-gnueabihf/sysroot-glibc-linaro-2.21-2017.10-arm-linux-gnueabihf.tar.xz
xz -d sysroot-glibc-linaro-2.21-2017.10-arm-linux-gnueabihf.tar.xz
sudo tar xvf sysroot-glibc-linaro-2.21-2017.10-arm-linux-gnueabihf.tar -C /opt
sudo cp -R /opt/sysroot-glibc-linaro-2.21-2017.10-arm-linux-gnueabihf/* /opt/basefiles/
sudo rm -rf /opt/sysroot-glibc-linaro-2.21-2017.10-arm-linux-gnueabihf/

#向目标文件系统建立必要的文件夹
sudo mkdir /opt/basefiles/proc
sudo mkdir /opt/basefiles/dev
sudo mkdir /opt/basefiles/sys
sudo mkdir /opt/basefiles/tmp

#建立启动脚本
echo '#!/bin/sh' > rcS
echo 'mount -t proc none /proc' >> rcS
echo 'mount -t sysfs none /sys' >> rcS
echo 'mount -t tmpfs none /tmp' >> rcS
echo 'mount -o remount,rw /' >> rcS
echo 'export HOME=/root' >> rcS
echo 'exit 0' >> rcS
sudo mkdir /opt/basefiles/etc/init.d/
sudo mv rcS /opt/basefiles/etc/init.d/
sudo chmod +x /opt/basefiles/etc/init.d/rcS