一. 資源下載
1.1. Lichee官方資料:https://cn.dl.sipeed.com/LICHEE
1.2. uboot github源碼:https://github.com/Lichee-Pi/u-boot.git
1.3. kernel github源碼:https://github.com/Lichee-Pi/linux.git
1.4. buildroot 源碼路徑:https://buildroot.org/downloads/buildroot-2017.08.tar.gz
1.5. 交叉編譯鏈工具(6.3-2017.02版本):https://releases.linaro.org/components/toolchain/binaries/
二. 硬件介紹
2.1. 硬件是Lichee Zero,下圖是官方介紹圖片

三. 配置與編譯
3.1. 交叉編譯鏈工具
3.1.1. 下載(如果已下載跳過)
wget https://releases.linaro.org/components/toolchain/binaries/latest/arm-linux-gnueabihf/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf.tar.xz
3.1.2. 配置
tar xvf gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf.tar.xz mv gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf /opt/ vim /etc/bash.bashrc # add: PATH="$PATH:/opt/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf/bin" source /etc/bash.bashrc
3.1.3. 查看版本
arm-linux-gnueabihf-gcc -v

3.2. 安裝設備樹編譯器
sudo apt-get install device-tree-compiler
3.3. uboot
3.3.1. 下載(已下載跳過)
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
3.3.2. 修改u-boot/include/configs/sun8i.h文件 加入:
#define CONFIG_BOOTCOMMAND "setenv bootm_boot_mode sec; " \
"load mmc 0:1 0x41000000 zImage; " \
"load mmc 0:1 0x41800000 sun8i-v3s-licheepi-zero.dtb; " \
"bootz 0x41000000 - 0x41800000;"
#define CONFIG_BOOTARGS "console=ttyS0,115200 panic=5 rootwait root=/dev/mmcblk0p2 earlyprintk rw vt.global_cursor_default=0"
3.3.3. 配置
cd u-boot
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- LicheePi_Zero_defconfig
#or make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- LicheePi_Zero_800x480LCD_defconfig
#or make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- LicheePi_Zero_480x272LCD_defconfig
make ARCH=arm menuconfig
3.3.4. 編譯
time make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- 2>&1 | tee build.log
a. 編譯完成后,在當前目錄下生成了u-boot-sunxi-with-spl.bin,可以燒錄到TF卡8K偏移處啟動
3.4. kernal
3.4.1. 下載(已下載跳過)
git clone https://github.com/Lichee-Pi/linux.git
3.4.2. 配置
cd linux make ARCH=arm licheepi_zero_defconfig make ARCH=arm menuconfig #add bluethooth, etc.
3.4.3. 編譯
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j16
a. 編譯完成后,zImage在arch/arm/boot/下,dtb在arch/arm/boot/dts/下
3.5. buildroot
3.5.1. 下載
wget https://buildroot.org/downloads/buildroot-2017.08.tar.gz
3.5.2. 配置
3.5.2.1. 首先安裝一些依賴,比如linux頭文件
apt-get install linux-headers-$(uname -r)
3.5.2.1. buildroot配置
tar xvf buildroot-2017.08.tar.gz cd buildroot-2017.08/ make menuconfig
a. target options配置

b. Toolchain配置

c. System configuretion配置

3.5.3. 編譯
make #有時候構建會出現莫名其妙的錯誤,make clean下會ok?
編譯完成后,會生成 output/images/rootfs.tar,此即所需的根文件系統
四. 燒錄(TF卡燒錄)
4.1. 使用SDFormatter格式化SD卡(window環境下)
下載路徑:https://www.sdcard.org/downloads/formatter/

4.2. ubuntu下分區(TF卡插入ubuntu)
4.2.1. 安裝gparted工具
sudo apt-get install gparted
4.2.2. 打開分區工具

4.2.2.1. 選擇TF卡

4.2.2.2. 新建分區
a. 軟件TF卡上有分區應先刪掉分區,方法一:可以使用 4.1. 使用SDFormatter格式化SD卡(window環境下)或者方法二:參考:http://zero.lichee.pro/%E8%B4%A1%E7%8C%AE/article%201.html


b. 繼續新建分區(將屬於的全部作為rootfs分區)

c. apply

4.3. 燒錄固件
4.3.1. 燒錄uboot
a. sudo fdisk -l查看設備

b. 使用dd命令燒錄uboot
cd ./u-boot #先進入你uboot 的存放路徑 sudo dd if=u-boot-sunxi-with-spl.bin of=/dev/sdb bs=1024 seek=8 #如果盤符是sdb,則可直接實用這條指令,不是的話將/dev/sdb 改為實際的即可。
4.3.2 燒錄zImage和dtb
a. 把zImage, sun8i-v3s-licheepi-zero.dtb拷貝到第一個分區
sudo mount /dev/sdb1 mnt/ //掛載sdb1 到mnt sudo cp arch/arm/boot/zImage mnt/ sudo cp arch/arm/boot/dts/sun8i-v3s-licheepi-zero.dtb mnt/ && sync sudo umount /dev/sdb1
4.3.3. 燒錄rootfs
a. 把buildroot產生的rootfs.tar解壓到第二分區
sudo mount /dev/sdb2 mnt
sudo rm -rf mnt/
sudo tar xvf output/images/rootfs.tar -C mnt/ && sync #解壓到分區中
sudo umount /dev/sdb2
五. 測試驗證
5.1. 插上串口上電啟動
參考資料:http://zero.lichee.pro/%E8%B4%A1%E7%8C%AE/article%201.html
http://zero.lichee.pro/%E7%B3%BB%E7%BB%9F%E5%BC%80%E5%8F%91/buildroot.html
http://zero.lichee.pro/%E7%B3%BB%E7%BB%9F%E5%BC%80%E5%8F%91/uboot_build.html
http://zero.lichee.pro/%E7%B3%BB%E7%BB%9F%E5%BC%80%E5%8F%91/kernel_build.html
