使用buildroot制作根文件系统(龙芯1B使用)
准备编译工具链(buildroot制作)
使用buildroot制作根文件系统
准备编译工具链(buildroot制作)
- 准备工具如下(获得方法可以到龙芯官方FTP下载目录点下载):
buildroot-2016.02.tar.bz2 //可以去Buildroot官方下载, dl //内涵部分网络第三方库,提前准备的,没有没关系,在make编译的时候在线下载即可。 buildroot-2016.02-glibc-gcc-4.9.x-mips32-nofpu_defconfig //龙芯4.9编译器默认配置选项,具体参数可以参考后面。
- 使用make menuconfig打开buildroot的配置菜单,选择如下配置选项:
Target options ---> Target Architecture (MIPS (little endian)) ---> Target Binary Format (ELF) ---> Target Architecture Variant (mips 32) ---> [*] Use soft-float Build options ---> 该目录下使用默认配置即可 其中 Mirrors and Download locations ---> (http://mirrors4.ustc.edu.cn/gnu) GNU Software mirror
- 这里把GNU Software mirror的地址修改为国内的镜像地址,加快下载速度。
Toolchain ---> Toolchain type (Buildroot toolchain) ---> (buildroot) custom toolchain vendor name *** Kernel Header Options *** Kernel Headers (Linux 3.18.x kernel headers) ---> C library (glibc) ---> glibc version (2.22) ---> *** Binutils Options *** Binutils Version (binutils 2.24) ---> () Additional binutils options *** GCC Options *** GCC compiler Version (gcc 4.9.x) ---> () Additional gcc options [*] Enable C++ support [ ] Enable Fortran support [*] Enable compiler link-time-optimization support [ ] Enable compiler OpenMP support [ ] Enable graphite support [ ] Build cross gdb for the host [ ] Purge unwanted locales () Generate locale data [ ] Copy gconv libraries () Target Optimizations () Target linker options [ ] Register toolchain within Eclipse Buildroot plug-in
- 这里选择了glibc配置如上,如果uglib的话编译对某些应用会有问题,会出现不能使用的情况,建议不要选择。
System configuration ---> (buildroot) System hostname (Welcome to Buildroot) System banner Passwords encoding (md5) ---> Init system (None) ---> /dev management (Dynamic using devtmpfs only) ---> (system/device_table.txt) Path to the permission tables Root FS skeleton (default target skeleton) ---> [ ] Use symlinks to /usr for /bin, /sbin and /lib [ ] Enable root login with password /bin/sh (none) ---> [ ] Run a getty (login prompt) after boot ---- [ ] remount root filesystem read-write during boot *** automatic network configuration via DHCP needs ifupdown or busybox *** [ ] Install timezone info () Path to the users tables () Root filesystem overlay directories () Custom scripts to run before creating filesystem images () Custom scripts to run after creating filesystem images
- 这里不用busybox制作根文件系统,所以Init system (None)选择None
- 以下选项包括子目录选项全部选择空
Kernel ---> Target packages ---> Filesystem images ---> Bootloaders ---> Host utilities ---> Legacy config options --->
- buildroot-2016.02-glibc-gcc-4.9.x-mips32-nofpu_defconfig(32位)配置内容如下:
# # Automatically generated file; DO NOT EDIT. # Buildroot 2016.02 Configuration # BR2_HAVE_DOT_CONFIG=y BR2_HOST_GCC_AT_LEAST_4_7=y BR2_HOST_GCC_AT_LEAST_4_8=y # # Target options # BR2_SOFT_FLOAT=y BR2_ARCH_HAS_MMU_MANDATORY=y BR2_mipsel=y BR2_ARCH="mipsel" BR2_ENDIAN="LITTLE" BR2_GCC_TARGET_ARCH="mips32" BR2_GCC_TARGET_ABI="32" BR2_BINFMT_SUPPORTS_SHARED=y BR2_BINFMT_ELF=y BR2_mips_32=y BR2_MIPS_SOFT_FLOAT=y BR2_MIPS_OABI32=y # # Build options # # # Commands # BR2_WGET="wget --passive-ftp -nd -t 3" BR2_SVN="svn" BR2_BZR="bzr" BR2_GIT="git" BR2_CVS="cvs" BR2_LOCALFILES="cp" BR2_SCP="scp" BR2_SSH="ssh" BR2_HG="hg" BR2_ZCAT="gzip -d -c" BR2_BZCAT="bzcat" BR2_XZCAT="xzcat" BR2_TAR_OPTIONS="" BR2_DEFCONFIG="$(CONFIG_DIR)/defconfig" BR2_DL_DIR="$(TOPDIR)/dl" BR2_HOST_DIR="$(BASE_DIR)/host" # # Mirrors and Download locations # BR2_PRIMARY_SITE="" BR2_BACKUP_SITE="http://sources.buildroot.net" BR2_KERNEL_MIRROR="https://www.kernel.org/pub" BR2_GNU_MIRROR="http://mirrors4.ustc.edu.cn/gnu" BR2_LUAROCKS_MIRROR="http://rocks.moonscript.org" BR2_CPAN_MIRROR="http://cpan.metacpan.org" BR2_JLEVEL=0 BR2_STRIP_strip=y BR2_STRIP_EXCLUDE_FILES="" BR2_STRIP_EXCLUDE_DIRS="" BR2_OPTIMIZE_S=y BR2_SSP_NONE=y BR2_SHARED_LIBS=y BR2_PACKAGE_OVERRIDE_FILE="$(CONFIG_DIR)/local.mk" BR2_GLOBAL_PATCH_DIR="" # # Advanced # # BR2_COMPILER_PARANOID_UNSAFE_PATH is not set # # Toolchain # BR2_TOOLCHAIN=y BR2_TOOLCHAIN_USES_GLIBC=y BR2_TOOLCHAIN_BUILDROOT=y BR2_TOOLCHAIN_BUILDROOT_VENDOR="buildroot" # # Kernel Header Options # BR2_KERNEL_HEADERS_3_18=y BR2_DEFAULT_KERNEL_HEADERS="3.18.27" BR2_TOOLCHAIN_BUILDROOT_GLIBC=y BR2_TOOLCHAIN_BUILDROOT_LIBC="glibc" BR2_PACKAGE_LINUX_HEADERS=y BR2_PACKAGE_GLIBC=y BR2_GLIBC_VERSION_2_22=y BR2_GLIBC_VERSION_STRING="2.22" # # Binutils Options # BR2_BINUTILS_VERSION_2_24_X=y BR2_BINUTILS_VERSION="2.24" BR2_BINUTILS_ENABLE_LTO=y BR2_BINUTILS_EXTRA_CONFIG_OPTIONS="" # # GCC Options # BR2_GCC_NEEDS_MPC=y BR2_GCC_SUPPORTS_GRAPHITE=y BR2_GCC_VERSION_4_9_X=y BR2_GCC_SUPPORTS_FINEGRAINEDMTUNE=y BR2_GCC_VERSION="4.9.3" BR2_EXTRA_GCC_CONFIG_OPTIONS="" BR2_TOOLCHAIN_BUILDROOT_CXX=y BR2_GCC_ENABLE_TLS=y BR2_GCC_ENABLE_LTO=y BR2_TOOLCHAIN_HAS_NATIVE_RPC=y BR2_USE_WCHAR=y BR2_ENABLE_LOCALE=y BR2_INSTALL_LIBSTDCPP=y BR2_TOOLCHAIN_HAS_THREADS=y BR2_TOOLCHAIN_HAS_THREADS_DEBUG=y BR2_TOOLCHAIN_HAS_THREADS_NPTL=y BR2_TOOLCHAIN_HAS_SHADOW_PASSWORDS=y BR2_TOOLCHAIN_HAS_SSP=y BR2_GENERATE_LOCALE="" BR2_USE_MMU=y BR2_TARGET_OPTIMIZATION="" BR2_TARGET_LDFLAGS="" BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_0=y BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_1=y BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_2=y BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_3=y BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_4=y BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_5=y BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_6=y BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_7=y BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_8=y BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_9=y BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_10=y BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_11=y BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_12=y BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_13=y BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_14=y BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_15=y BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_16=y BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_17=y BR2_TOOLCHAIN_HEADERS_AT_LEAST_3_18=y BR2_TOOLCHAIN_HEADERS_AT_LEAST="3.18" BR2_TOOLCHAIN_GCC_AT_LEAST_4_3=y BR2_TOOLCHAIN_GCC_AT_LEAST_4_4=y BR2_TOOLCHAIN_GCC_AT_LEAST_4_5=y BR2_TOOLCHAIN_GCC_AT_LEAST_4_6=y BR2_TOOLCHAIN_GCC_AT_LEAST_4_7=y BR2_TOOLCHAIN_GCC_AT_LEAST_4_8=y BR2_TOOLCHAIN_GCC_AT_LEAST_4_9=y BR2_TOOLCHAIN_GCC_AT_LEAST="4.9" BR2_TOOLCHAIN_HAS_SYNC_1=y BR2_TOOLCHAIN_HAS_SYNC_2=y BR2_TOOLCHAIN_HAS_SYNC_4=y BR2_TOOLCHAIN_HAS_ATOMIC=y # # System configuration # BR2_TARGET_GENERIC_HOSTNAME="buildroot" BR2_TARGET_GENERIC_ISSUE="Welcome to Buildroot" BR2_TARGET_GENERIC_PASSWD_MD5=y BR2_TARGET_GENERIC_PASSWD_METHOD="md5" BR2_INIT_NONE=y BR2_ROOTFS_DEVICE_CREATION_DYNAMIC_DEVTMPFS=y BR2_ROOTFS_DEVICE_TABLE="system/device_table.txt" BR2_ROOTFS_SKELETON_DEFAULT=y BR2_SYSTEM_BIN_SH_NONE=y BR2_ROOTFS_USERS_TABLES="" BR2_ROOTFS_OVERLAY="" BR2_ROOTFS_POST_BUILD_SCRIPT="" BR2_ROOTFS_POST_IMAGE_SCRIPT="" # # Kernel # # BR2_LINUX_KERNEL is not set # # Target packages # # BR2_PACKAGE_BUSYBOX is not set BR2_PACKAGE_BUSYBOX_SHOW_OTHERS=y BR2_PACKAGE_SKELETON=y # # Audio and video applications # BR2_PACKAGE_KODI_ARCH_SUPPORTS=y BR2_PACKAGE_MPLAYER_ARCH_SUPPORTS=y BR2_PACKAGE_GOOGLE_BREAKPAD_ARCH_SUPPORTS=y BR2_PACKAGE_CMAKE_ARCH_SUPPORTS=y # # Other GUIs # BR2_PACKAGE_QT5_JSCORE_AVAILABLE=y # # Interpreter languages and scripting # BR2_PACKAGE_GAUCHE_ARCH_SUPPORTS=y BR2_PACKAGE_MONO_ARCH_SUPPORTS=y BR2_PACKAGE_OPENAL_ARCH_SUPPORTS=y # # Crypto # BR2_PACKAGE_BOTAN_ARCH_SUPPORTS=y BR2_PACKAGE_WEBKITGTK24_ARCH_SUPPORTS=y BR2_PACKAGE_LIBAIO_ARCH_SUPPORTS=y BR2_PACKAGE_LIBOPENH264_ARCH_SUPPORTS=y BR2_PACKAGE_BOOST_ARCH_SUPPORTS=y BR2_PACKAGE_LIBBSD_ARCH_SUPPORTS=y BR2_PACKAGE_LIBNSPR_ARCH_SUPPORT=y BR2_PACKAGE_LIBUNWIND_ARCH_SUPPORTS=y BR2_PACKAGE_PROTOBUF_ARCH_SUPPORTS=y BR2_PACKAGE_QEMU_ARCH_SUPPORTS_TARGET=y BR2_PACKAGE_MONGREL2_LIBC_SUPPORTS=y BR2_PACKAGE_SYSTEMD_ARCH_SUPPORTS=y BR2_PACKAGE_TZDATA_ZONELIST="" BR2_TARGET_UBOOT_CUSTOM_GIT_REPO_URL="" BR2_TARGET_UBOOT_CUSTOM_GIT_VERSION="" BR2_LINUX_KERNEL_CUSTOM_GIT_REPO_URL="" BR2_LINUX_KERNEL_CUSTOM_GIT_VERSION=""
- 执行如下操作:
cd /home/loongson/tools/buildroot/ tar -xvf buildroot-2016.02.tar.bz2 cd buildroot-2016.02 cp -r /mnt/dl ./ cp /mnt/buildroot-2016.02-glibc-gcc-4.9.x-mips32-nofpu_defconfig .config make menuconfig // 保存退出 make
- 经过比较长时间的等待,buildroot编译完毕。
- 编译后buildroot-2016.02目录下会生成一个output目录,工具链就在该目录下。
- 修改环境变量即可使用该交叉工具链来编译程序
export PATH=/home/loongson/tools/buildroot/buildroot-2016.02/output/host/usr/bin:$PATH
- /output/target/lib(/output/staging/)目录下存放了交叉工具链的C库等工具,可以把需要的库复制到开发板的根文件系统的/lib目录下,某些应用可能需要这些库。
- 注意:主机需要安装G++,另外编译过程中可能会出现错误,比如主机缺少某些工具,按照错误提示安装工具就可以了。
使用buildroot制作根文件系统
- 重新使用buildroot制作根文件系统:
- make menuconfig
make make sdk //制作sdk环境包