1、安装编译链
安装C版本gcc-arm-linux-gnueabihf
1 2 3 4 |
|
2、编译uboot
git clone https://github.com/Lichee-Pi/u-boot.git -b v3s-current
#or git clone https://github.com/Lichee-Pi/u-boot.git -b v3s-spi-experimental
cd u-boot
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- LicheePi_Zero_800x480LCD_defconfig
#or make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- LicheePi_Zero480x272LCD_defconfig
#or make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- LicheePi_Zero_defconfig
make ARCH=arm menuconfig
time make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- 2>&1 | tee build.log
Tee是Linux命令,用于显示程序的输出并将其复制到一个文件中。
tee指令会从标准输入设备读取数据,将其内容输出到标准输出设备,同时保存成文件。
关于uboot的结构,这里不在赘述,放一个官网的说明:
├── api 存放uboot提供的API接口函数
├── arch 平台相关的部分我们只需要关心这个目录下的ARM文件夹
│ ├──arm
│ │ └──cpu
│ │ │ └──armv7
│ │ └──dts
│ │ │ └──*.dts 存放设备的dts,也就是设备配置相关的引脚信息
├── board 对于不同的平台的开发板对应的代码
├── cmd 顾名思义,大部分的命令的实现都在这个文件夹下面。
├── common 公共的代码
├── configs 各个板子的对应的配置文件都在里面,我们的Lichee配置也在里面
├── disk 对磁盘的一些操作都在这个文件夹里面,例如分区等。
├── doc 参考文档,这里面有很多跟平台等相关的使用文档。
├── drivers 各式各样的驱动文件都在这里面
├── dts 一种树形结构(device tree)这个应该是uboot新的语法
├── examples 官方给出的一些样例程序
├── fs 文件系统,uboot会用到的一些文件系统
├── include 头文件,所有的头文件都在这个文件夹下面
├── lib 一些常用的库文件在这个文件夹下面
├── Licenses 这个其实跟编译无关了,就是一些license的声明
├── net 网络相关的,需要用的小型网络协议栈
├── post 上电自检程序
├── scripts 编译脚本和Makefile文件
├── spl second program loader,即相当于二级uboot启动。
├── test 小型的单元测试程序。
└── tools 里面有很多uboot常用的工具。
2、编译内核
下载
git clone -b zero-5.2.y --depth 1 https://github.com/Lichee-Pi/linux.git
下载成功后修改makefile文件
cd linux
vim Makefile
[364]ARCH = arm
[365]CROSS_COMPILE = arm-linux-gnueabihf-
[366]INSTALL_MOD_PATH = out
然后开始编译
cd linux
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- licheepi_zero_defconfig
make menuconfig #一般不用修改,需要时单独改
make -j16
make -j16 modules #编译模块
make -j16 modules_install #安装模块
make dtbs #编译设备树
或者
make ARCH=arm licheepi_zero_defconfig
make ARCH=arm menuconfig #add bluethooth, etc.
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j16
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j16 INSTALL_MOD_PATH=out modules
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j16 INSTALL_MOD_PATH=out modules_install
分别是指定架构,交叉编译器,MOD安装位置。
如果涉及到多个编译链版本,可以不用写入环境变量,在这里直接绝对路径指定。
编译完成后,zImage在arch/arm/boot/下,驱动模块在out/lib下,设备树在arch/arm/boot/dts下。
然后把zImage,sun8i-v3s-licheepi-zero-dock.dtb放到第一分区
modules文件夹放入文件系统的lib下
使用modprobe xxx
加载模块。
编译过程中可能遇到以下问题:
/usr/bin/ld: scripts/dtc/dtc-parser.tab.o:(.bss+0x20): multiple definition of `yylloc'; scripts/dtc/dtc-lexer.lex.o:(.bss+0x0): first defined here
collect2: error: ld returned 1 exit status
make[1]: *** [scripts/Makefile.host:99: scripts/dtc/dtc] Error 1
解决办法:
vim scripts/dtc/dtc-parser.tab.h
修改extern XXX yylloc 为yyloc
vim scripts/dtc/dtc-lexer.l
修改XXX yylloc 为 extern XXX yylloc
或者用 buildroot 生成sdimage镜像
sudo apt-get update
sudo apt-get install gcc
sudo apt install git wget make gcc flex bison libssl-dev bc kmod -y
apt-get install libncurses5-dev
sudo apt install g++
sudo apt install unzip
sudo make
sudo apt install bzip2
git clone https://github.com/buildroot/buildroot.git
cd buildroot
ls configs/licheepi_zero_defconfig
make licheepi_zero_defconfig
这里换源,换成国内的镜像,下载速度会快点
可以在make menuconfig
的界面里的Build options
–>Mirrors and Download locations
中的几个地址依次填入下面几个国内的加速url地址,速度可以快非常多!!
BACKUP_SITE="http://sources.buildroot.net"
KERNEL_MIRROR="https://mirror.bjtu.edu.cn/kernel/"
GNU_MIRROR="http://mirrors.nju.edu.cn/gnu/"
LUAROCKS_MIRROR="https://luarocks.cn"
CPAN_MIRROR="http://mirrors.nju.edu.cn/CPAN/"
注意:BR2_KERNEL_MIRROR的网址,每家镜像源可能稍有区别,
阿里云的网址:https://mirrors.aliyun.com/linux-kernel (暂时没验证)
清华的网址:https://mirrors.tuna.tsinghua.edu.cn/kernel
中国科学技术大学的网址:https://mirrors.aliyun.com/kernel.org
sudo make