14 --> 搭建 OpenWrt 开发环境编译开源 uboot 源码

第一步
编译 openWrt 时选择编译 openwrt-toolchain 工具链;
第二步
解压 编译好的 toolchain 工具链;

robot@ubuntu:~/OpenWrt/mtk7621-19.07$ 
   cd bin/targets/ramips/mt7621/
robot@ubuntu:~/OpenWrt/mtk7621-19.07/bin/targets/ramips/mt7621$ 
   sudo tar xjf openwrt-toolchain-ramips-mt7621_gcc-7.5.0_musl.Linux-x86_64.tar.bz2 -C /opt/

第三步
修改 环境变量

sudo vim /etc/bash.bashrc
# 修改内容
export PATH=/opt/openwrt-toolchain-ramips-mt7621_gcc-7.5.0_musl.Linux-x86_64/toolchain-mipsel_24kc_gcc-7.5.0_musl/bin:$PATH
export STAGING_DIR=/home/robot/OpenWrt/mtk7621-19.07/staging_dir

第四步
验证 开发环境

robot@ubuntu:~/OpenWrt/mtk7621-uboot/GnuBee-MT7621-uboot-master$ mipsel-openwrt-linux-gcc -v
Reading specs from /opt/openwrt-toolchain-ramips-mt7621_gcc-7.5.0_musl.Linux-x86_64/toolchain-mipsel_24kc_gcc-7.5.0_musl/bin/../lib/gcc/mipsel-openwrt-linux-musl/7.5.0/specs
COLLECT_GCC=mipsel-openwrt-linux-musl-gcc.bin
COLLECT_LTO_WRAPPER=/opt/openwrt-toolchain-ramips-mt7621_gcc-7.5.0_musl.Linux-x86_64/toolchain-mipsel_24kc_gcc-7.5.0_musl/bin/../libexec/gcc/mipsel-openwrt-linux-musl/7.5.0/lto-wrapper
Target: mipsel-openwrt-linux-musl
Configured with: /home/robot/OpenWrt/mtk762x-19.07/build_dir/toolchain-mipsel_24kc_gcc-7.5.0_musl/gcc-7.5.0/configure --with-bugurl=http://bugs.openwrt.org/ --with-pkgversion='OpenWrt GCC 7.5.0 unknown' --prefix=/home/robot/OpenWrt/mtk762x-19.07/staging_dir/toolchain-mipsel_24kc_gcc-7.5.0_musl --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu --target=mipsel-openwrt-linux-musl --with-gnu-ld --enable-target-optspace --disable-libgomp --disable-libmudflap --disable-multilib --disable-libmpx --disable-nls --without-isl --without-cloog --with-host-libstdcxx=-lstdc++ --with-float=soft --with-gmp=/home/robot/OpenWrt/mtk762x-19.07/staging_dir/host --with-mpfr=/home/robot/OpenWrt/mtk762x-19.07/staging_dir/host --with-mpc=/home/robot/OpenWrt/mtk762x-19.07/staging_dir/host --disable-decimal-float --with-diagnostics-color=auto-if-env --with-mips-plt --disable-libssp --enable-__cxa_atexit --with-headers=/home/robot/OpenWrt/mtk762x-19.07/staging_dir/toolchain-mipsel_24kc_gcc-7.5.0_musl/include --disable-libsanitizer --enable-languages=c,c++ --enable-shared --enable-threads --with-slibdir=/home/robot/OpenWrt/mtk762x-19.07/staging_dir/toolchain-mipsel_24kc_gcc-7.5.0_musl/lib --enable-lto --with-libelf=/home/robot/OpenWrt/mtk762x-19.07/staging_dir/host
Thread model: posix
gcc version 7.5.0 (OpenWrt GCC 7.5.0 unknown) 
COMPILER_PATH=/opt/openwrt-toolchain-ramips-mt7621_gcc-7.5.0_musl.Linux-x86_64/toolchain-mipsel_24kc_gcc-7.5.0_musl/bin/../libexec/gcc/mipsel-openwrt-linux-musl/7.5.0/:/opt/openwrt-toolchain-ramips-mt7621_gcc-7.5.0_musl.Linux-x86_64/toolchain-mipsel_24kc_gcc-7.5.0_musl/bin/../libexec/gcc/:/opt/openwrt-toolchain-ramips-mt7621_gcc-7.5.0_musl.Linux-x86_64/toolchain-mipsel_24kc_gcc-7.5.0_musl/bin/../lib/gcc/mipsel-openwrt-linux-musl/7.5.0/../../../../mipsel-openwrt-linux-musl/bin/
LIBRARY_PATH=/opt/openwrt-toolchain-ramips-mt7621_gcc-7.5.0_musl.Linux-x86_64/toolchain-mipsel_24kc_gcc-7.5.0_musl/bin/../lib/gcc/mipsel-openwrt-linux-musl/7.5.0/:/opt/openwrt-toolchain-ramips-mt7621_gcc-7.5.0_musl.Linux-x86_64/toolchain-mipsel_24kc_gcc-7.5.0_musl/bin/../lib/gcc/:/opt/openwrt-toolchain-ramips-mt7621_gcc-7.5.0_musl.Linux-x86_64/toolchain-mipsel_24kc_gcc-7.5.0_musl/bin/../lib/gcc/mipsel-openwrt-linux-musl/7.5.0/../../../../mipsel-openwrt-linux-musl/lib/
COLLECT_GCC_OPTIONS='-v' '-msoft-float' '-mllsc' '-mplt' '-mno-shared' '-EL' '-mabi=32'
 /opt/openwrt-toolchain-ramips-mt7621_gcc-7.5.0_musl.Linux-x86_64/toolchain-mipsel_24kc_gcc-7.5.0_musl/bin/../libexec/gcc/mipsel-openwrt-linux-musl/7.5.0/collect2 -plugin /opt/openwrt-toolchain-ramips-mt7621_gcc-7.5.0_musl.Linux-x86_64/toolchain-mipsel_24kc_gcc-7.5.0_musl/bin/../libexec/gcc/mipsel-openwrt-linux-musl/7.5.0/liblto_plugin.so -plugin-opt=/opt/openwrt-toolchain-ramips-mt7621_gcc-7.5.0_musl.Linux-x86_64/toolchain-mipsel_24kc_gcc-7.5.0_musl/bin/../libexec/gcc/mipsel-openwrt-linux-musl/7.5.0/lto-wrapper -plugin-opt=-fresolution=/tmp/ccqPcvJN.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc_s --sysroot=/opt/openwrt-toolchain-ramips-mt7621_gcc-7.5.0_musl.Linux-x86_64/toolchain-mipsel_24kc_gcc-7.5.0_musl/bin//../.. --eh-frame-hdr -EL -dynamic-linker /lib/ld-musl-mipsel-sf.so.1 -melf32ltsmip /opt/openwrt-toolchain-ramips-mt7621_gcc-7.5.0_musl.Linux-x86_64/toolchain-mipsel_24kc_gcc-7.5.0_musl/bin/../lib/gcc/mipsel-openwrt-linux-musl/7.5.0/../../../../mipsel-openwrt-linux-musl/lib/crt1.o /opt/openwrt-toolchain-ramips-mt7621_gcc-7.5.0_musl.Linux-x86_64/toolchain-mipsel_24kc_gcc-7.5.0_musl/bin/../lib/gcc/mipsel-openwrt-linux-musl/7.5.0/../../../../mipsel-openwrt-linux-musl/lib/crti.o /opt/openwrt-toolchain-ramips-mt7621_gcc-7.5.0_musl.Linux-x86_64/toolchain-mipsel_24kc_gcc-7.5.0_musl/bin/../lib/gcc/mipsel-openwrt-linux-musl/7.5.0/crtbegin.o -L /home/robot/OpenWrt/mtk7621-19.07/staging_dir/usr/lib -rpath-link /home/robot/OpenWrt/mtk7621-19.07/staging_dir/usr/lib -L/opt/openwrt-toolchain-ramips-mt7621_gcc-7.5.0_musl.Linux-x86_64/toolchain-mipsel_24kc_gcc-7.5.0_musl/bin/../lib/gcc/mipsel-openwrt-linux-musl/7.5.0 -L/opt/openwrt-toolchain-ramips-mt7621_gcc-7.5.0_musl.Linux-x86_64/toolchain-mipsel_24kc_gcc-7.5.0_musl/bin/../lib/gcc -L/opt/openwrt-toolchain-ramips-mt7621_gcc-7.5.0_musl.Linux-x86_64/toolchain-mipsel_24kc_gcc-7.5.0_musl/bin/../lib/gcc/mipsel-openwrt-linux-musl/7.5.0/../../../../mipsel-openwrt-linux-musl/lib -rpath=/opt/openwrt-toolchain-ramips-mt7621_gcc-7.5.0_musl.Linux-x86_64/toolchain-mipsel_24kc_gcc-7.5.0_musl/bin//../../lib:/opt/openwrt-toolchain-ramips-mt7621_gcc-7.5.0_musl.Linux-x86_64/toolchain-mipsel_24kc_gcc-7.5.0_musl/bin//../../usr/lib -lssp_nonshared -lgcc_s -lc -lgcc_s /opt/openwrt-toolchain-ramips-mt7621_gcc-7.5.0_musl.Linux-x86_64/toolchain-mipsel_24kc_gcc-7.5.0_musl/bin/../lib/gcc/mipsel-openwrt-linux-musl/7.5.0/crtend.o /opt/openwrt-toolchain-ramips-mt7621_gcc-7.5.0_musl.Linux-x86_64/toolchain-mipsel_24kc_gcc-7.5.0_musl/bin/../lib/gcc/mipsel-openwrt-linux-musl/7.5.0/../../../../mipsel-openwrt-linux-musl/lib/crtn.o
/opt/openwrt-toolchain-ramips-mt7621_gcc-7.5.0_musl.Linux-x86_64/toolchain-mipsel_24kc_gcc-7.5.0_musl/bin/../lib/gcc/mipsel-openwrt-linux-musl/7.5.0/../../../../mipsel-openwrt-linux-musl/bin/ld: /opt/openwrt-toolchain-ramips-mt7621_gcc-7.5.0_musl.Linux-x86_64/toolchain-mipsel_24kc_gcc-7.5.0_musl/bin/../lib/gcc/mipsel-openwrt-linux-musl/7.5.0/../../../../mipsel-openwrt-linux-musl/lib/crt1.o: in function `_start_c':
/home/robot/OpenWrt/mtk762x-19.07/build_dir/toolchain-mipsel_24kc_gcc-7.5.0_musl/musl-1.1.24/crt/crt1.c:18: undefined reference to `main'
/opt/openwrt-toolchain-ramips-mt7621_gcc-7.5.0_musl.Linux-x86_64/toolchain-mipsel_24kc_gcc-7.5.0_musl/bin/../lib/gcc/mipsel-openwrt-linux-musl/7.5.0/../../../../mipsel-openwrt-linux-musl/bin/ld: /home/robot/OpenWrt/mtk762x-19.07/build_dir/toolchain-mipsel_24kc_gcc-7.5.0_musl/musl-1.1.24/crt/crt1.c:18: undefined reference to `main'
collect2: error: ld returned 1 exit status

第五步
修改 uboot 的 Makefile 中的交叉工具链

ifeq ($(ARCH),arm)
CROSS_COMPILE = $(CONFIG_CROSS_COMPILER_PATH)/arm-linux-
endif
ifeq ($(ARCH),i386)
ifeq ($(HOSTARCH),i386)
CROSS_COMPILE =
else
CROSS_COMPILE = $(CONFIG_CROSS_COMPILER_PATH)/i386-linux-
endif
endif
ifeq ($(ARCH),mips)   #修改为 mipsel-openwrt-linux- 交叉编译前缀
CROSS_COMPILE = $(CONFIG_CROSS_COMPILER_PATH)/mipsel-openwrt-linux-
endif

第五步
编译 uboot 源码修改错误

robot@ubuntu:~/OpenWrt/mtk7621-uboot/GnuBee-MT7621-uboot-master$ make
find . -type f \
        \( -name 'core' -o -name '*.bak' -o -name '*~' \
        -o -name '*.o'  -o -name '*.a'  \) -print \
        | xargs rm -f
find ./ -name '.depend' -print | xargs rm -f
rm -f examples/hello_world examples/timer \
      examples/eepro100_eeprom examples/sched \
      examples/mem_to_mem_idma2intr examples/82559_eeprom
rm -f tools/img2srec tools/mkimage tools/envcrc tools/gen_eth_addr
rm -f tools/mpc86x_clk tools/ncb
rm -f tools/easylogo/easylogo tools/bmp_logo
rm -f tools/gdb/astest tools/gdb/gdbcont tools/gdb/gdbsend
rm -f tools/env/fw_printenv tools/env/fw_setenv
rm -f board/cray/L1/bootscript.c board/cray/L1/bootscript.image
rm -f board/trab/trab_fkt
rm -f stage1/stage2.bin stage1/stage1n2.elf stage1/stage1n2.map
rm -f ./uboot.bin ./uboot.img ./u-boot ./u-boot.* ./uboot_a.bin ./System.map
rm -f scripts/lxdialog/lxdialog
make[1]: Entering directory '/home/robot/OpenWrt/mtk7621-uboot/GnuBee-MT7621-uboot-master/tools'
make[1]: Nothing to be done for '.depend'.
make[1]: Leaving directory '/home/robot/OpenWrt/mtk7621-uboot/GnuBee-MT7621-uboot-master/tools'
make -C tools all
make[1]: Entering directory '/home/robot/OpenWrt/mtk7621-uboot/GnuBee-MT7621-uboot-master/tools'
gcc -I./ -DUSE_HOSTCC -c mkimage.c
In file included from mkimage.c:61:0:
./image.h:210:1: warning: ‘packed’ attribute ignored [-Wattributes]
 } dram_header_t __attribute__ ((packed));
 ^
./image.h:218:1: warning: ‘packed’ attribute ignored [-Wattributes]
 } nand_badblock_info1_t __attribute__ ((packed));
 ^
./image.h:232:1: warning: ‘packed’ attribute ignored [-Wattributes]
 } nand_info_1_t __attribute__ ((packed));
 ^
./image.h:246:1: warning: ‘packed’ attribute ignored [-Wattributes]
 } nand_header_t __attribute__ ((packed));
 ^
./image.h:266:1: warning: ‘packed’ attribute ignored [-Wattributes]
 } image_header_t __attribute__((packed));
 ^
mkimage.c: In function ‘main’:
mkimage.c:744:5: warning: implicit declaration of function ‘crc’ [-Wimplicit-function-declaration]
     crc((const char *)hdr, &checksum, sizeof(image_header_t));
     ^
gcc -I./ -DUSE_HOSTCC -c crc32.c
gcc -I./ -DUSE_HOSTCC -c crc.c
gcc -o mkimage mkimage.o crc32.o crc.o
make[1]: Leaving directory '/home/robot/OpenWrt/mtk7621-uboot/GnuBee-MT7621-uboot-master/tools'
echo make -C tools all
make -C tools all
"/opt/openwrt-toolchain-ramips-mt7621_gcc-7.5.0_musl.Linux-x86_64/toolchain-mipsel_24kc_gcc-7.5.0_musl/bin"/mipsel-openwrt-linux-gcc -Wa,-gstabs -D__ASSEMBLY__ -gdwarf-2 -DDEBUG -Os   -D__KERNEL__ -DTEXT_BASE=0xBFC00000 -I/home/robot/OpenWrt/mtk7621-uboot/GnuBee-MT7621-uboot-master/include -fno-builtin -ffreestanding -nostdinc -isystem /usr/lib/gcc/x86_64-linux-gnu/5/include -pipe  -DCONFIG_MIPS -D__MIPS__ -mabicalls -DRALINK_MDIO_ACCESS_FUN -DRALINK_DUAL_CORE_FUN -DRALINK_DUAL_VPE_FUN -EL -mmt -mips32r2 -DRALINK_SPI_UPGRADE_CHECK -DRALINK_RW_RF_REG_FUN -DRALINK_UPGRADE_BY_SERIAL -DRALINK_CMDLINE -DRALINK_EPHY_INIT -DCONFIG_LZMA -DASIC_BOARD -DMT7621_ASIC_BOARD -DMT7621_MP -DMAC_TO_MT7530_MODE -DGPIOx_RESET_MODE -DMT7621_USE_GE1 -DGE_RGMII_FORCE_1000 -DRALINK_DEMO_BOARD_PVLAN -DPDMA_NEW -DRX_SCATTER_GATTER_DMA -DUBOOT_ROM -DON_BOARD_DDR3 -DON_BOARD_DDR_WIDTH_16 -DON_BOARD_16BIT_DRAM_BUS -DON_BOARD_512M_DRAM_COMPONENT -DCFG_ENV_IS_IN_SPI -c -o cpu/ralink_soc/start_1004k.o /home/robot/OpenWrt/mtk7621-uboot/GnuBee-MT7621-uboot-master/cpu/ralink_soc/start_1004k.S
/home/robot/OpenWrt/mtk7621-uboot/GnuBee-MT7621-uboot-master/cpu/ralink_soc/start_1004k.S:944:0: warning: "RALINK_CLKCFG0_REG" redefined
....
....
mipsel-openwrt-linux-musl-ld.bin: lib_mips/libmips.a(mips_linux.o): in function `test_bit':
/home/robot/OpenWrt/mtk7621-uboot/GnuBee-MT7621-uboot-master/include/asm/bitops.h:570: multiple definition of `test_bit'; lib_mips/libmips.a(board.o):/home/robot/OpenWrt/mtk7621-uboot/GnuBee-MT7621-uboot-master/include/asm/bitops.h:570: first defined here
mipsel-openwrt-linux-musl-ld.bin: lib_mips/libmips.a(mips_linux.o): in function `find_first_zero_bit':
/home/robot/OpenWrt/mtk7621-uboot/GnuBee-MT7621-uboot-master/include/asm/bitops.h:590: multiple definition of `find_first_zero_bit'; lib_mips/libmips.a(board.o):/home/robot/OpenWrt/mtk7621-uboot/GnuBee-MT7621-uboot-master/include/asm/bitops.h:590: first defined here
mipsel-openwrt-linux-musl-ld.bin: lib_mips/libmips.a(mips_linux.o): in function `find_next_zero_bit':
/home/robot/OpenWrt/mtk7621-uboot/GnuBee-MT7621-uboot-master/include/asm/bitops.h:638: multiple definition of `find_next_zero_bit'; lib_mips/libmips.a(board.o):/home/robot/OpenWrt/mtk7621-uboot/GnuBee-MT7621-uboot-master/include/asm/bitops.h:638: first defined here
mipsel-openwrt-linux-musl-ld.bin: lib_mips/libmips.a(mips_linux.o): in function `ffz':
/home/robot/OpenWrt/mtk7621-uboot/GnuBee-MT7621-uboot-master/include/asm/bitops.h:687: multiple definition of `ffz'; lib_mips/libmips.a(board.o):/home/robot/OpenWrt/mtk7621-uboot/GnuBee-MT7621-uboot-master/include/asm/bitops.h:687: first defined here
mipsel-openwrt-linux-musl-ld.bin: lib_mips/libmips.a(mips_linux.o): in function `strcpy':
/home/robot/OpenWrt/mtk7621-uboot/GnuBee-MT7621-uboot-master/include/asm/string.h:16: multiple definition of `strcpy'; lib_mips/libmips.a(board.o):/home/robot/OpenWrt/mtk7621-uboot/GnuBee-MT7621-uboot-master/include/asm/string.h:16: first defined here
mipsel-openwrt-linux-musl-ld.bin: lib_mips/libmips.a(mips_linux.o): in function `strncpy':
/home/robot/OpenWrt/mtk7621-uboot/GnuBee-MT7621-uboot-master/include/asm/string.h:41: multiple definition of `strncpy'; lib_mips/libmips.a(board.o):/home/robot/OpenWrt/mtk7621-uboot/GnuBee-MT7621-uboot-master/include/asm/string.h:41: first defined here
mipsel-openwrt-linux-musl-ld.bin: lib_mips/libmips.a(mips_linux.o): in function `strcmp':
/home/robot/OpenWrt/mtk7621-uboot/GnuBee-MT7621-uboot-master/include/asm/string.h:69: multiple definition of `strcmp'; lib_mips/libmips.a(board.o):/home/robot/OpenWrt/mtk7621-uboot/GnuBee-MT7621-uboot-master/include/asm/string.h:69: first defined here
mipsel-openwrt-linux-musl-ld.bin: lib_mips/libmips.a(mips_linux.o): in function `strncmp':
/home/robot/OpenWrt/mtk7621-uboot/GnuBee-MT7621-uboot-master/include/asm/string.h:99: multiple definition of `strncmp'; lib_mips/libmips.a(board.o):/home/robot/OpenWrt/mtk7621-uboot/GnuBee-MT7621-uboot-master/include/asm/string.h:99: first defined here
mipsel-openwrt-linux-musl-ld.bin: lib_mips/libmips.a(mips_linux.o): in function `memscan':
/home/robot/OpenWrt/mtk7621-uboot/GnuBee-MT7621-uboot-master/include/asm/string.h:140: multiple definition of `memscan'; lib_mips/libmips.a(board.o):/home/robot/OpenWrt/mtk7621-uboot/GnuBee-MT7621-uboot-master/include/asm/string.h:140: first defined here
mipsel-openwrt-linux-musl-ld.bin: cpu/ralink_soc/start_1004k.o: in function `relocate_code':
/home/robot/OpenWrt/mtk7621-uboot/GnuBee-MT7621-uboot-master/cpu/ralink_soc/start_1004k.S:1918: undefined reference to `_GLOBAL_OFFSET_TABLE_'
Makefile:362: recipe for target 'u-boot' failed
make: *** [u-boot] Error 1

uboot 源码链接:
https://github.com/dtltljb/GnuBee-uboot-MTKxxxx

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值