本文章是根据官网初见 - Sipeed Wiki进行操作,是自己学习中遇到问题和坑的总结。
硬件:
- Mac、Mac安装Ubuntu虚拟机
- 全志f1c100s licheePi Nano
- USB转TTL
- TF卡
- OTG数据线
- TF读卡器
- 40P 800*480 RGB 显示屏
- 杜邦连接线公/母若干根
环境:
- MacOS、Ubuntu
- Python3
以下是需要安装的环境依赖,所有库和环境的安装都是使用apt-get完成。
sudo apt-get install gcc make cmake rsync wget unzip build-essential git bc swig libncurses-dev libpython3-dev libssl-dev python3-distutils android-tools-mkbootimg -y
所有东西准备完成后开始嵌入式Liunx的学习!
介绍
U-Boot是一个广泛使用的开源引导加载程序,主要用于嵌入式系统。它能够在设备启动时初始化硬件并加载操作系统内核。
Nano串口通信
需要使用TTL转USB连接板子的5v,GND,RXD,TXD(推荐使用OTG连接电脑USB供电只连接RXD,TXD)。
板子的RXD连接到TTL的TXD
板子的TXD连接到TTL的RXD
我使用的是Linux的minicom实现串口连接
ls /dev/ttyUSB* //查看连接的USB串口
#有USB串口显示/dev/ttyUSB0 也可能是其他/dev/ttyUSB*
我的可能是TTL转USB有问题,插入后显示/dev/ttyUSB0后会自动断开需要多次插拔。
找到板子的USB串口后使用串口工具连接就能查看输出信息并输入命令。
安装交叉编译链
sudo apt-get update #更新apt
sudo apt-get install gcc-arm-linux-gnueabi #安装交叉编译链arm-linux-gnueabi
sudo vim /etc/bash.bashrc #bash.bashrc文件配置交叉编译环境变量的PATH路径
#文件末尾添加
#PATH="$PATH:/usr/bin"
source /etc/bash.bashrc #使路径生效
arm-linux-gnueabi-gcc -v #查看交叉编译链版本
编译u-boot
在Ubuntu桌面新建licheePi文件夹存放下载数据.
cd ~/Desktop/licheePi #进入licheePi文件夹
sudo apt-get install git #安装git工具
git clone https:#gitee.com/LicheePiNano/u-boot.git //clone u-boot源码
cd u-boot #进入u-boot文件夹
git branch -a #查看git分支
git checkout nano-lcd800480 #检出nano-lcd800480分支
#此处告知make采用arm-linux-gnueabi下的所有交叉编译工具,目标架构为Arm,设定各项默认配置为 nano 的spiflash的支持版
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- f1c100s_nano_uboot_defconfig
可视化配置
make ARCH=arm menuconfig
make clean //清除生成的.o文件
make distclean //清除生成的.c和.o等文件
#这两个命令可以在合适的时候使用
可视化配置界面根据需求进行配置。上下左右进行选择 Y:选中 X:取消选中
- ARM architecture—>
- Enable graphical uboot console on HDMI, LCD or VGA #设置为Y
- LCD panel timing details
屏幕800480设置为:
x:800,y:480,depth:18,pclk_khz:33000,le:87,ri:40,up:31,lo:13,hs:1,vs:1,sync:3,vmode:0
屏幕480272设置为:
x:480,y:272,depth:18,pclk_khz:10000,le:42,ri:8,up:11,lo:4,hs:1,vs:1,sync:3,vmode:0
(1设置为Y出现,未设置则不显示)
!!!官网给出的文本是pclk\khz是有问题的需要更改为pclk_khz - LCD panel backlight pwm pin #设置为PE6
- Save保存—>Exit退出
开始编译
//开始编译
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- -j8
可能遇到的错误信息(本地为Python3环境)
- CONFIG_BOOTCOMMAND(重复定义值不同)
修改~/Desktop/licheePi/u-boot/include/configs/suniv.h文件//CONFIG_BOOTCOMMAND值修改为run distro_bootcmd #define CONFIG_BOOTCOMMAND "run distro_bootcmd"
- multiple definition of `yylloc’(重复定义)
修改~/Desktop/licheePi/u-boot/scripts/dtc/dtc-parser.tab.c文件//文件1205行不带extern的YYLTYPE yylloc注释掉 /*YYLTYPE yylloc*/
- arch/arm/dts/.suniv-f1c100s-licheepi-nano.dtb.pre.tmp:59.1-10 syntax error(语法错误)
修改~/Desktop/licheePi/u-boot/scripts/Makefile.lib文件
//\#include "$(u_boot_dtsi)前多加了一个“\”
echo '\#include "$(u_boot_dtsi)"')
修改为:
echo '#include "$(u_boot_dtsi)"')
当文件夹内有u-boot-sunxi-with-spl.bin文件时就是编译成功了,这个文件就是需要的u-boot启动文件。
u-boot启动参数配置
- 可以在配置.config文件,下图中是可配置的启动参数和启动执行脚本
- boot.scr文件传递启动参数(这种方式比较好修改,不用重新编译)
boot.scr 由 boot.cmd 生成
boot.com文件内容touch boot.cmd //新建一个cmd文件 vim boot.cmd //编辑文件写入下边内容,我使用的是vim可以选择其他编辑方式
第一行setenv命令,设定了变量bootargs(启动参数)为:通过tty0和ttyS0串口输出启动信息;启动失败延迟5秒重启,根文件在TF卡的第二分区,可读写;setenv bootargs console=tty0 console=ttyS0,115200 panic=5 rootwait root=/dev/mmcblk0p2 rw load mmc 0:1 0x80C00000 suniv-f1c100s-licheepi-nano.dtb load mmc 0:1 0x80008000 zImage bootz 0x80008000 - 0x80C00000
第二行指定了从TF中将设备树的dtb文件加载到0x80C00000的位置(地址参考自官方SDK)
第三行指定了将压缩后的内核zImage加载到0x80008000的位置
第四行为从加载地址启动内核的命令- mkimage安装方式1
cd ~/Desktop/licheePi/u-boot/tools //进入u-boot的tools目录 cp ./mkimage /usr/local/bin/mkimage //拷贝mkimage文件到系统bin目录 cd ~/Desktop/licheePi/u-boot //回到boot.com所在目录 mkimage -C none -A arm -T script -d boot.cmd boot.scr //生成boot.scr文件
- mkimage安装方式2
sudo apt-get install u-boot-tools //apt-get安装u-boot-tools mkimage -C none -A arm -T script -d boot.cmd boot.scr //生成boot.scr文件
安装sunxi-tools
sunxi-tools是Nano下载工具,可以把文件再fel模式下载到板子上。(spi flash启动需要使用,TF卡启动可以略过)
- 安装方式1(推荐)
git clone -b f1c100s-spiflash https://github.com/Icenowy/sunxi-tools.git //git下载sunxi-tools源码
cd sunxi-tools //进入文件夹
make && sudo make install //安装
如果出现fel_lib.c:26:20: fatal error: libusb.h: No such file or directory
则需要安装libusb
sudo apt-get install libusb-1.0-0-dev
- 安装方式2(可能会出现
Warning: no 'soc_sram_info' data for your SoC (id=1663)
错误)
sudo apt-get install sunxi-tools
烧录u-boot
- 板子进fel模式
新板子不插卡上电会自动进入fel模式,可以通过
确认是否进入felsudo sunxi-fel ver
未进入fel模式显示
进入fel模式显示,并在Ubuntu虚拟机上显示一个USB连接ERROR: Allwinner USB FEL device not found!
AWUSBFEX soc=00001663(unknown) 00000001 ver=0001 44 08 scratchpad=00007e00 00000000 00000000
如果spi flash内写入的有数据,需要短接spi flash芯片的CS脚和GND地线使用OTG线连接电脑上电。(!!!引脚连接TTL转USB无法识别进入fel模式)
-
spi flash烧录
有两种方式进行程序下载-
方式一
以 uboot file-with-spl形式进行(单次运行,测试时个人推荐)cd ~/Desktop/licheePi/u-boot //进入u-boot目录 sudo sunxi-fel uboot u-boot-sunxi-with-spl.bin //下载u-boot程序到板子
-
方式二
烧进 spi-flash (开机自启)sudo sunxi-fel -p spiflash-write 0 u-boot-sunxi-with-spl.bin
-
-
TF卡烧录
TF卡烧录前需要对卡进行分区操作
TF卡连接电脑使用fdisk命令进行分区sudo fdisk -l //查看已出入设备号 sudo umount /dev/sdXx //若自动挂载了TF设备,请先卸载我的设备是sda 下边分了sda1和sda2 sudo fdisk /dev/sdX //对主设备进行操作 // 若已存分区即按 d 删除各个分区 //通过 n 新建分区,第一分区暂且申请为32M(足够大了...),剩下的空间都给第二分区 //w 保存写入并退出 sudo mkfs.vfat /dev/sdX1 # 将第一分区格式化成FAT sudo mkfs.ext4 /dev/sdX2 # 将第一分区格式化成EXT4
分区完成后写入u-boot程序
cd ~/Desktop/licheePi/u-boot //进入u-boot目录 //把u-boot启动程序写入到TF卡 sudo dd if=u-boot-sunxi-with-spl.bin of=/dev/sdX bs=1024 seek=8
写入成功后可以插卡上电
成功后显示启动信息
U-Boot SPL 2018.01-05688-ga9729b3241-dirty (May 15 2024 - 14:13:00)
DRAM: 32 MiB
Trying to boot from FEL
U-Boot 2018.01-05688-ga9729b3241-dirty (May 15 2024 - 14:13:00 +0800) Allwinner y CPU: Allwinner F Series (SUNIV)
Model: Lichee Pi Nano
DRAM: 32 MiB
MMC: SUNXI SD/MMC: 0
SF: Detected xt25f128b with page size 256 Bytes, erase size 4 KiB, total 16 MiB
*** Warning - bad CRC, using default environment
Setting up a 800x480 lcd console (overscan 0x0)
In: serial@1c25000
Out: serial@1c25000
Err: serial@1c25000
Net: No ethernet found.
starting USB...
No controllers found
Hit any key to stop autoboot: 0
Card did not respond to voltage select!
mmc_init: -95, time 22
starting USB...
No controllers found
USB is stopped. Please issue 'usb start' first.
starting USB...
No controllers found
missing environment variable: pxeuuid
missing environment variable: bootfile
Retrieving file: pxelinux.cfg/00000000
No ethernet found.
missing environment variable: bootfile
Retrieving file: pxelinux.cfg/0000000
No ethernet found.
missing environment variable: bootfile
Retrieving file: pxelinux.cfg/000000
No ethernet found.
missing environment variable: bootfile
Retrieving file: pxelinux.cfg/00000
No ethernet found.
missing environment variable: bootfile
Retrieving file: pxelinux.cfg/0000
No ethernet found.
missing environment variable: bootfile
Retrieving file: pxelinux.cfg/000
No ethernet found.
missing environment variable: bootfile
Retrieving file: pxelinux.cfg/00
No ethernet found.
missing environment variable: bootfile
Retrieving file: pxelinux.cfg/0
No ethernet found.
missing environment variable: bootfile
Retrieving file: pxelinux.cfg/default-arm-sunxi
No ethernet found.
missing environment variable: bootfile
Retrieving file: pxelinux.cfg/default-arm
No ethernet found.
missing environment variable: bootfile
Retrieving file: pxelinux.cfg/default
No ethernet found.
Config file not found
starting USB...
No controllers found
No ethernet found.
No ethernet found.
=>
串口控制台(minicom、putty或其他)输入 bdinfo
显示板子信息
arch_number = 0x00000000
boot_params = 0x80000100
DRAM bank = 0x00000000
-> start = 0x80000000
-> size = 0x02000000
baudrate = 115200 bps
TLB addr = 0x80FF0000
relocaddr = 0x80F14000
reloc off = 0xFF814000
irq_sp = 0x80E09D90
sp start = 0x80E09D80
FB base = 0x81E89000
Early malloc usage: 118 / 400
fdt_blob = 80e09da8
串口控制台输入printenv
显示u-boot配置信息
arch=arm
baudrate=115200
board=sunxi
board_name=sunxi
boot_a_script=load ${devtype} ${devnum}:${distro_bootpart} ${scriptaddr} ${prefi}
boot_efi_binary=if fdt addr ${fdt_addr_r}; then bootefi bootmgr ${fdt_addr_r};eli
boot_extlinux=sysboot ${devtype} ${devnum}:${distro_bootpart} any ${scriptaddr} f
boot_net_usb_start=usb start
boot_prefixes=/ /boot/
boot_script_dhcp=boot.scr.uimg
boot_scripts=boot.scr.uimg boot.scr
boot_targets=fel mmc0 usb0 pxe dhcp
bootargs=console=ttyS0,115200 panic=5 rootwait root=/dev/mtdblock3 rw rootfstype2
bootcmd=run distro_bootcmd
bootcmd_dhcp=run boot_net_usb_start; if dhcp ${scriptaddr} ${boot_script_dhcp}; ;
bootcmd_fel=if test -n ${fel_booted} && test -n ${fel_scriptaddr}; then echo '(Fi
bootcmd_mmc0=setenv devnum 0; run mmc_boot
bootcmd_pxe=run boot_net_usb_start; dhcp; if pxe get; then pxe boot; fi
bootcmd_usb0=setenv devnum 0; run usb_boot
bootdelay=2
bootm_size=0x1700000
console=ttyS0,115200
cpu=arm926ejs
devnum=0
dfu_alt_info_ram=kernel ram 0x80500000 0x1000000;fdt ram 0x80C00000 0x100000;ram0
distro_bootcmd=for target in ${boot_targets}; do run bootcmd_${target}; done
efi_dtb_prefixes=/ /dtb/ /dtb/current/
fdt_addr_r=0x80C00000
fdtcontroladdr=80e09da8
fdtfile=suniv-f1c100s-licheepi-nano.dtb
fel_booted=1
kernel_addr_r=0x80500000
load_efi_dtb=load ${devtype} ${devnum}:${distro_bootpart} ${fdt_addr_r} ${prefix}
mmc_boot=if mmc dev ${devnum}; then setenv devtype mmc; run scan_dev_for_boot_pai
partitions=name=loader1,start=8k,size=32k,uuid=${uuid_gpt_loader1};name=loader2,;
preboot=usb start
pxefile_addr_r=0x80D00000
ramdisk_addr_r=0x80D50000
scan_dev_for_boot=echo Scanning ${devtype} ${devnum}:${distro_bootpart}...; for ;
scan_dev_for_boot_part=part list ${devtype} ${devnum} -bootable devplist; env exe
scan_dev_for_efi=setenv efi_fdtfile ${fdtfile}; if test -z "${fdtfile}" -a -n "$e
scan_dev_for_extlinux=if test -e ${devtype} ${devnum}:${distro_bootpart} ${prefii
scan_dev_for_scripts=for script in ${boot_scripts}; do if test -e ${devtype} ${de
scriptaddr=0x80C50000
soc=sunxi
stderr=serial@1c25000
stdin=serial@1c25000
stdout=serial@1c25000
usb_boot=usb start; if usb dev ${devnum}; then setenv devtype usb; run scan_dev_i
uuid_gpt_esp=c12a7328-f81f-11d2-ba4b-00a0c93ec93b
uuid_gpt_system=69dad710-2ce4-4e3c-b16c-21a1d49abed3
Environment size: 4554/32764 bytes
- spi flash数据擦除
上电后再串口显示Hit any key to stop autoboot:1
倒数计时是按enter
擦除成功重启后如果没有安装TF卡则会进入fel模式sf probe 0 //初始化 SPI Flash 设备(假设 SPI Flash 设备编号为 0) sf erase 0 0x100000 //擦除 SPI Flash 中地址为 0 处开始,长度为 0x100000 字节的数据 reset //重启
至此u-boot安装完毕!!