1. Get the source code
https://github.com/mtk-openwrt/u-boot
2. Compilation steps
The compilation environment is ubuntu 18.04. For the cross-compilation toolchain, I use the toolchain generated by openwrt compilation and set it to the environment variable, as follows:
export PATH=$PATH:/root/mt8976/BPI-R3-OPENWRT-V21.02.3-main/staging_dir/toolchain-aarch64_cortex-a53_gcc-8.4.0_musl/bin export STAGING_DIR=/root/mt8976/BPI-R3-OPENWRT-V21.02.3-main/staging_dir
1. Configuration
make mt7986a_bpir3_sd_defconfig.
It can be seen from the command that the uboot is configured for programming in the SD card, and you can also choose to compile and program in SPI-NOR, SPI-NAND and eMMC, as follows:
[root@u-boot-mtksoc]#ls configs/ | grep 7986 mt7986a_bpir3_emmc_defconfig mt7986a_bpir3_sd_defconfig mt7986a_emmc_rfb_defconfig mt7986a_emmc_sb_rfb_defconfig mt7986a_sd_rfb_defconfig mt7986b_emmc_rfb_defconfig mt7986b_sd_rfb_defconfig mt7986_nmbm_snfi_nand_sb_rfb_defconfig mt7986_rfb_defconfig mt7986_snfi_nand_rfb_defconfig mt7986_spim_nand_rfb_defconfig mt7986_spim_nand_sb_rfb_defconfig mt7986_spim_nor_rfb_defconfig
2. Compile the code
make CROSS_COMPILE=aarch64-openwrt-linux-V=1
V=1: You can see what the specific compilation command is, and it is convenient to check the specific cause of the compilation problem.
PS: The following errors may be reported during compilation:
tools/sunxi_toc0.o: In function `toc0_verify_header': sunxi_toc0.c:(.text + 0x4f5): undefined reference to `RSA_set0_key' sunxi_toc0.c:(.text + 0x50c): undefined reference to `RSA_get0_n' sunxi_toc0.c:(.text + 0x52a): undefined reference to `RSA_get0_e' sunxi_toc0.c:(.text + 0x5f0): undefined reference to `RSA_set0_key' sunxi_toc0.c:(.text + 0x702): undefined reference to `RSA_set0_key' sunxi_toc0.c:(.text + 0x719): undefined reference to `RSA_get0_n' sunxi_toc0.c:(.text + 0x726): undefined reference to `RSA_get0_n' sunxi_toc0.c:(.text + 0x743): undefined reference to `RSA_get0_e' sunxi_toc0.c:(.text + 0x750): undefined reference to `RSA_get0_e' tools/sunxi_toc0.o: In function `toc0_set_header': sunxi_toc0.c:(.text + 0xaa5): undefined reference to `RSA_get0_d' sunxi_toc0.c:(.text + 0xafe): undefined reference to `RSA_get0_d' sunxi_toc0.c:(.text + 0xd81): undefined reference to `RSA_get0_n' sunxi_toc0.c:(.text + 0xda9): undefined reference to `RSA_get0_e' sunxi_toc0.c:(.text + 0xde9): undefined reference to `RSA_get0_n' sunxi_toc0.c:(.text + 0xe11): undefined reference to `RSA_get0_e' sunxi_toc0.c:(.text + 0xf14): undefined reference to `RSA_get0_n' sunxi_toc0.c:(.text + 0xf29): undefined reference to `BN_bn2binpad' sunxi_toc0.c:(.text + 0xf3b): undefined reference to `RSA_get0_e' sunxi_toc0.c:(.text + 0xf50): undefined reference to `BN_bn2binpad' tools/lib/ecdsa/ecdsa-libcrypto.o: In function `prepare_ctx': ecdsa-libcrypto.c:(.text + 0xcd): undefined reference to `OPENSSL_init_ssl' ecdsa-libcrypto.c:(.text + 0x185): undefined reference to `EC_GROUP_order_bits' tools/lib/ecdsa/ecdsa-libcrypto.o: In function `ecdsa_check_signature.isra.3': ecdsa-libcrypto.c:(.text + 0x3ad): undefined reference to `ECDSA_SIG_set0' tools/lib/ecdsa/ecdsa-libcrypto.o: In function `ecdsa_sign': ecdsa-libcrypto.c:(.text + 0x497): undefined reference to `ECDSA_SIG_get0' ecdsa-libcrypto.c:(.text + 0x4ae): undefined reference to `BN_bn2binpad' ecdsa-libcrypto.c:(.text + 0x4c0): undefined reference to `BN_bn2binpad' tools/lib/ecdsa/ecdsa-libcrypto.o: In function `ecdsa_add_verify_data': ecdsa-libcrypto.c:(.text + 0x68d): undefined reference to `EC_GROUP_order_bits' ecdsa-libcrypto.c:(.text + 0x6d3): undefined reference to `EC_POINT_get_affine_coordinates' tools/lib/rsa/rsa-sign.o: In function `rsa_sign': rsa-sign.c:(.text + 0x524): undefined reference to `OPENSSL_init_ssl' tools/lib/rsa/rsa-sign.o: In function `rsa_get_params': rsa-sign.c:(.text + 0x973): undefined reference to `RSA_get0_key' rsa-sign.c:(.text + 0x9c0): undefined reference to `RSA_get0_key' tools/lib/rsa/rsa-sign.o: In function `rsa_add_verify_data': rsa-sign.c:(.text + 0xe21): undefined reference to `EVP_PKEY_get0_RSA' collect2: error: ld returned 1 exit status scripts/Makefile.host:104: recipe for target 'tools/dumpimage' failed make[1]: *** [tools/dumpimage] Error 1 Makefile:1916: recipe for target 'tools' failed make: *** [tools] Error 2
Compiling sunxi_toc0.c lacks the openssl library, which may also be caused by the low version of openssl. Here I manually compiled and installed the openssl-1.1.1n version of the library, the specific steps are as follows:
cd openssl-1.1.1n ./configure make & amp; & amp; make install ldconfig
3. Take out uboot
The results of uboot compilation success are as follows:
[root@u-boot-mtksoc]#make CROSS_COMPILE=aarch64-openwrt-linux- UPD include/generated/timestamp_autogenerated.h ENVC include/generated/env.txt ENVP include/generated/env.in ENVT include/generated/environment.h CC cmd/version.o AR cmd/built-in.o CC env/common.o AR env/built-in.o LD u-boot OBJCOPY u-boot.srec OBJCOPY u-boot-nodtb.bin RELOC u-boot-nodtb.bin CAT u-boot-dtb.bin COPY u-boot.bin SYM u-boot.sym MKIMAGE u-boot-mtk.bin CFGCHK u-boot.cfg OFCHK.config
u-boot: The most original uboot for code compilation, including symbol information, debug information, etc.
u-boot-nodtb.bin: u-boot leaves the necessary segments through objcopy, so the size is much smaller than u-boot.
u-boot-dtb.bin: Based on u-boot-nodtb.bin, the dts/dt.dtb file is added.
u-boot.bin: is a copy of u-boot-dtb.bin.
u-boot.sym: u-boot symbol table information.
u-boot-mtk.bin: The u-boot.bin file processed by the mkimage command. Files for final flashing.
Three. Summary
The cross-compilation toolchain used to compile BPI-R3 development board uboot is generated by compiling openwrt. During the compilation process, an openssl-related error may be reported. You can install openssl-1.1.1n to solve it. Remember to run ldconfig after installing openssl, and uboot is compiled. Burn the u-boot-mtk.bin file.
The knowledge points of the article match the official knowledge files, and you can further learn relevant knowledge. CS introductory skill tree Introduction to LinuxFirst acquaintance with Linux28836 People are learning systematically