前言

linux系统配置安装自行学习

toolchain

下载 & 解压

这里选择 7.2 版本 gcc,可根据自己需求选择

1
2
wget https://releases.linaro.org/components/toolchain/binaries/7.2-2017.11/arm-linux-gnueabihf/gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabihf.tar.xz
tar -xvf gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabihf.tar.xz

配置环境变量

1
2
3
vim ~/.bashrc
export PATH=$PATH:$your_toolchain_path/bin
source ~/.bashrc

检查是否成功配置

1
aarch64-linux-gnu-gcc -v

uboot

下载 uboot 源码

这里选择荔枝派 nano 的 uboot

1
git clone https://github.com/Lichee-Pi/u-boot.git -b nano-lcd800480

uboot 编译

使用 licheepi_nano_defconfig 配置文件

1
make licheepi_nano_defconfig ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-

uboot图形界面配置

1
make menuconfig ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-

Enable boot arguments 选项上点击空格,弹出Boot arguments选项,选中回车输入以下内容后回车保存

1
console=ttyS0,115200 panic=5 rootwait root=/dev/mmcblk0p2 earlyprintk rw

同样的操作输入bootcmd的值

1
load mmc 0:1 0x80008000 zImage;load mmc 0:1 0x80c08000 suniv-f1c100s-licheepi-nano.dtb;bootz 0x80008000 - 0x80c08000;

执行编译命令

1
make -j12 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-

此时会出现一个错误

1
2
3
4
5
6
/usr/bin/ld: scripts/dtc/dtc-parser.tab.o:(.bss+0x10): multiple definition of `yylloc'; scripts/dtc/dtc-lexer.lex.o:(.bss+0x0): first defined here
collect2: error: ld returned 1 exit status
make[2]: *** [scripts/Makefile.host:108: scripts/dtc/dtc] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [scripts/Makefile.build:425: scripts/dtc] Error 2
make: *** [Makefile:491: scripts] Error 2

是因为重复定义了 yylloc 变量,在低版本的 gcc 上不会出现这个问题,此时我们需要修改 scripts/dtc/dtc-parser.tab.c 这个文件,将 yylloc 进行注释

1
// YYLTYPE yylloc

再次编译

1
make -j12 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-

libfdt_env 错误

1
2
3
4
5
6
7
8
9
10
11
/usr/include/libfdt_env.h:27:30: error: conflicting types for ‘fdt64_t’; have ‘uint64_t’ {aka ‘long unsigned int’}
27 | typedef uint64_t FDT_BITWISE fdt64_t;
| ^~~~~~~
In file included from <command-line>:
././include/libfdt_env.h:19:16: note: previous declaration of ‘fdt64_t’ with type ‘fdt64_t’ {aka ‘long long unsigned int’}
19 | typedef __be64 fdt64_t;
| ^~~~~~~
In file included from ././include/libfdt_env.h:12,
from <command-line>:
/usr/include/libfdt_env.h:47:24: error: expected ‘)’ before ‘x’
47 | static inline uint32_t fdt32_to_cpu(fdt32_t x)

这是u-boot在编译本机程序(使用 HOSTCC)时出现的,出现这个问题是因为你的系统版本太新了, 然后系统中的 libfdt 是比较新的,u-boot 版本比较老,而 libfdt 库改动过,u-boot 调用该库时出现兼容问题,实际上 u-boot 内置有libfdt,你把系统新的 libfdt-dev 删除,u-boot 就会调用源代码自带的旧的 libfdt, 所以只需下面命令然后重新编译:

1
sudo apt-get remove libfdt-dev

重新编译

1
make -j12 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-

这时又会出现一个设备树编译错误,这个是 scripts/Makefile.lib 文件没有换行导致的

1
2
3
4
5
6
Error: arch/arm/dts/.suniv-f1c100s-licheepi-nano.dtb.pre.tmp:59.1-10 syntax error
FATAL ERROR: Unable to parse input tree
make[2]: *** [scripts/Makefile.lib:329: arch/arm/dts/suniv-f1c100s-licheepi-nano.dtb] Error 1
make[1]: *** [dts/Makefile:51: arch/arm/dts/suniv-f1c100s-licheepi-nano.dtb] Error 2
make: *** [Makefile:876: dts/dt.dtb] Error 2
make: *** Waiting for unfinished jobs....

修改scripts/Makefile.lib文件 321 行

1
2
3
4
5
6
7
8
cmd_dtc = mkdir -p $(dir ${dtc-tmp}) ; \
(cat $<; $(if $(u_boot_dtsi),echo '\
#include "$(u_boot_dtsi)"')) > $(pre-tmp); \
$(CPP) $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $(pre-tmp) ; \
$(DTC) -O dtb -o $@ -b 0 \
-i $(dir $<) $(DTC_FLAGS) \
-d $(depfile).dtc.tmp $(dtc-tmp) ; \
cat $(depfile).pre.tmp $(depfile).dtc.tmp > $(depfile)

再次编译即可编译成功

1
make -j12 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-

烧录 uboot

1
sudo dd if=u-boot-sunxi-with-spl.bin of=/dev/sdb bs=1024 seek=8