1、uboot移植、修改LED灯;2、学习uboot代码;3、阅读代码的取巧方法
认知:使用uboot指令控制LED灯,在uboot/cmd文件中找到led指令文件,在uboot/cmd/makefile文件中查看是否链接led指令文件,如果未链接则需要添加。原有添加方式中需要判断UBOOT_CMD_LED的值,需要在uboot/.config中设置UBOOT_CMD_LED=y,将led指令文件编译连接到指令中。
编译后,下载到demo板,打开串口调试工具,输入help指令,可以看到有led指令,在输入了的指令,可以看到介绍,对比介绍与led指令文件中一致,表示指令过程正确。
但现在的指令不能执行硬件动作,猜测需要修改驱动和设备树,以支持led设备。
2、uboot代码学习,利用正确的Uboot代码,输出信息到串口调试助手:
[20:57:46.566]收←◆
U-Boot SPL 2018.01-05679-g013ca457fd-dirty (Feb 16 2022 - 14:45:21)
DRAM: 64 MiB
Trying to boot from MMC1
U-Boot SPL 2018.01-05679-g013ca457fd-dirty (Feb 16 2022 - 14:45:21)
DRAM: 64 MiB
Trying to boot from MMC1
[20:57:46.926]收←◆
U-Boot SPL 2018.01-05679-g013ca457fd-dirty (Feb 16 2022 - 14:45:21)preloader_console_init\spl.c
DRAM: 64 MiBsunxi_board_init\board.c
Trying to boot from MMC1boot_from_devices\spl.c
[20:57:47.096]收←◆
U-Boot 2018.01-05679-g013ca457fd-dirty (Feb 16 2022 - 14:45:21 +0800) Allwinner TechnologyU_BOOT_VERSION_STRING\version.h display_options_get_banner_priv\display_options.c
CPU: Allwinner F Series (SUNIV)print_cpuinfo\cpu_info.c
Model: Lichee Pi Nanoshow_board_info\board_info.c
DRAM: 64 MiBannounce_dram_init+show_dram_config\board_f.c+display_options.c
[20:57:47.628]收←◆MMC: SUNXI SD/MMC: 0initr_mmc+mmc_initialize+print_mmc_devices\board_r.c+mmc.c+mmc_legasy.c
[20:57:47.706]收←◆*** Warning - bad CRC, using default environment
In: serial@1c25000
Out: serial@1c25000
Err: serial@1c25000
__led_init: failed requesting GPIO0!
Net: No ethernet found.
starting USB...
No controllers found
Hit any key to stop autoboot: 2
[20:57:48.734]收←◆ 1
[20:57:49.735]收←◆ 0
[20:57:49.798]收←◆switch to partitions #0, OK
mmc0 is current device
[20:57:50.345]收←◆Scanning mmc 0:1...
[20:57:50.489]收←◆reading /suniv-f1c100s-licheepi-nano.dtb
4393 bytes read in 25 ms (170.9 KiB/s)
[20:57:50.561]收←◆starting USB...
No controllers found
USB is stopped. Please issue 'usb start' first.
starting USB...
No controllers found
No ethernet 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.
=>
然后按照这个输出信息,一条一条找到执行位置,上面标红为函数接口,蓝色为接口所在源文件。
屏蔽以上代码后,下面的输出信息依旧存在,表示下面的输出信息位于执行borad_init_f()之前。
在指定位置添加调试信息,发现以下部分信息属于borad_init_f()内
U-Boot 2018.01-05679-g013ca457fd-dirty (Feb 16 2022 - 14:45:21 +0800) Allwinner Technology
++++++++
DRAM: 64 MiB
这之后的信息属于board_init_r()内。
前几天不是纠结uboot中函数在何处调用问题吗,今天找到一个笨办法了,就是把函数本身名修改成另一个,然后再编译,就会提示哪个位置有错误或警告,那就是被调用位置呐。阅读代码的取巧方法。
使用上述方法后终于找到了所有输出信息对应的位置。
同时发现了这个BUG,就是代码是灰色的,但是却是会执行的。下一步是想办法控制LED亮灭。