uboot定制自己的板子--Apple的学习笔记
  2Nv1H5BMjysw 2023年11月02日 23 0

一,前言

既然下载了最新的uboot版本,那么就玩玩吧,先要定制自己的板子。

二,问题分析及解决

1,出错信息

U-Boot SPL 2023.10 (Oct 19 2023 - 19:58:50 +0800)
Trying to boot from MMC1


U-Boot 2023.10 (Oct 19 2023 - 19:58:50 +0800)Apple Cai's am335 Board

CPU  : AM335X-GP rev 2.1
Model: TI AM335x EVM
DRAM:  512 MiB
Core:  150 devices, 13 uclasses, devicetree: separate
NAND:  0 MiB
MMC:   OMAP SD/MMC: 0
Loading Environment from FAT... OK
initcall sequence 9ffdbcdc failed at call 8080253d (err=-19)
### ERROR ### Please RESET the board ###

2,分析搜索出错关键字后,在doc帮助中提示at call是一个uboot.map中的地址,可以通过它来找initcall sequence中的函数名称。搜索8080253d找不到,然后找到了类似,看起来都有字节填充。

.text.arch_misc_init
                0x000000008080253c       0x16 arch/arm/mach-omap2/am33xx/board.o
                0x000000008080253c                arch_misc_init
 *fill*         0x0000000080802552        0x2

arch_misc_init是usb用的,我记得usb的device我都没有配置

ret = uclass_first_device_err(UCLASS_MISC, &dev);
    if (ret) {
        return ret;
    }

继续看ret值-19是什么错误

int uclass_first_device_err(enum uclass_id id, struct udevice **devp)

{
    int ret;
    ret = uclass_first_device_check(id, devp);
    if (ret)
        return ret;
    else if (!*devp)
        return -ENODEV;
    return 0;
}

果然-ENODEV就是-19,也就是说明在uclass中没有找到device。那么设备树没有设置misc,那么我就不应该配置驱动了。

#ifdef CONFIG_ARCH_MISC_INIT
    arch_misc_init,     /* miscellaneous arch-dependent init */
#endif

在common/Kconfig中可以找到

config ARCH_MISC_INIT
	bool "Call arch-specific init after relocation, when console is ready"

3,那么我自己的am335_ap_defconfig中CONFIG_ARCH_MISC_INIT注释掉,重新编译,上电成功。可以ping通,但是发现板子名称不对,说明我新加的board文件夹中的文件都没有被编译。

U-Boot SPL 2023.10 (Oct 19 2023 - 21:04:31 +0800)
Trying to boot from MMC1

U-Boot 2023.10 (Oct 19 2023 - 21:04:31 +0800)Apple Cai's am335 Board

CPU  : AM335X-GP rev 2.1
Model: TI AM335x EVM
DRAM:  512 MiB
Core:  150 devices, 13 uclasses, devicetree: separate
NAND:  0 MiB
MMC:   OMAP SD/MMC: 0
Loading Environment from FAT... OK
Net:   eth2: ethernet@4a100000
Hit any key to stop autoboot:  0
AP-Boot=> ping 192.168.0.110
link up on port 0, speed 100, full duplex
Using ethernet@4a100000 device
host 192.168.0.110 is alive
AP-Boot=> printenv board_name
board_name=A335BNLT

4, 发现board_name不对。board_name来自自定义的Kconfig中的SYS_BOARD,然后条件是TARGET_AM335_AP而不是TARGET_AM335X_EVM,所以在arch/arm/mach-omap2/am33xx/Kconfig中注释掉原来的,改成新的。

5,编译出现问题

arm-linux-gnueabihf-ld.bfd: cannot find board/ti/am335x/built-in.o

搜索build-in.o,然后思考ld链接的时候出错,不是编译o的时刻出错,那么想到了应该是链接文件有问题,找到位置board/ti/am335_ap/u-boot.lds,果然错误了,am335x需要修改为am335_ap

.text :
	{
		*(.__image_copy_start)
		*(.vectors)
		CPUDIR/start.o (.text*)
		board/ti/am335x/built-in.o (.text*)
	}

6,又报错了

board/ti/am335_ap/board.o: In function `board_late_init':
/work/giteecode/uboot/u-boot-2023.10/am335x_evm/../board/ti/am335_ap/board.c:841: undefined reference to `set_board_info_env'

于是把CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG先设置为n

7,又出问题了

drivers/power/pmic/pmic_tps65910.o: In function `power_tps65910_init':
/work/giteecode/uboot/u-boot-2023.10/am335x_evm/../drivers/power/pmic/pmic_tps65910.c:43: undefined reference to `i2c_get_chip_for_busnum'
drivers/power/pmic/pmic_tps65910.o: In function `tps65910_read_reg':
/work/giteecode/uboot/u-boot-2023.10/am335x_evm/../drivers/power/pmic/pmic_tps65910.c:20: undefined reference to `dm_i2c_reg_read'

通过信息看出tps设备是power设备,而且用到了i2c,于是把这2块的设备树内容添加上即可解决。 i2c我用了0,是之前看dm信息看到的。

i2c           0  [   ]   i2c_omap              |   |-- i2c@44e0b000
 pmic          0  [   ]   tps65217 pmic         |   |   `-- tps@24

三,主要修改

1,先copy一份board文件夹,头文件及defconfig,和自己的dts文件。

2,加Kconfig内容,在arch/arm/mach-omap2/Kconfig下添加

source "board/ti/am335_ap/Kconfig"

在arch/arm/mach-omap2/am33xx/Kconfig路径下找到TARGET_AM335X_EVM然后下方添加

config TARGET_AM335_AP
	bool "Support am335_ap"
	select BOARD_LATE_INIT
	select DM
	select DM_GPIO
	select DM_SERIAL
	select TI_I2C_BOARD_DETECT
	imply CMD_DM
	imply SPL_DM
	imply SPL_DM_SEQ_ALIAS
	imply SPL_ENV_SUPPORT
	imply SPL_FS_EXT4
	imply SPL_FS_FAT
	imply SPL_GPIO
	imply SPL_I2C
	imply SPL_LIBCOMMON_SUPPORT
	imply SPL_LIBDISK_SUPPORT
	imply SPL_LIBGENERIC_SUPPORT
	imply SPL_MMC
	imply SPL_NAND_SUPPORT
	imply SPL_OF_LIBFDT
	imply SPL_POWER
	imply SPL_SERIAL
	help
	  This option specifies support for the AM335 apple
	  board.

3,自己目录的kconfig内容为

if TARGET_AM335_AP

config SYS_BOARD
	default "am335_ap"

config SYS_VENDOR
	default "ti"

config SYS_SOC
	default "am33xx"

config SYS_CONFIG_NAME
	default "am335_ap"

config NOR
	bool "Support for NOR flash"
	help
	  The AM335x SoC supports having a NOR flash connected to the GPMC.
	  In practice this is seen as a NOR flash module connected to the
	  "memory cape" for the BeagleBone family.

source "board/ti/common/Kconfig"

endif

4,自定义的defconfig中CONFIG_OF_LIST修改为"am335_ap",这一个即可 由于这是搜索list,需要在arch/arm/dts/Makefile文件中的dtb-$(CONFIG_AM33XX) +=下面的列表中进行添加am335_ap.dts。

5,修改控制命令符号 在ap355_ap_defconfig设置CONFIG_SYS_PROMPT="AP-Boot=> "

6,设备特别的板子名称 在ap355_ap_defconfig设置CONFIG_IDENT_STRING="Apple Cai's am335 Board"

7,添加自定义cmd命令apled 只要自己新建一个c文件,然后参考其它cmd文件夹下的模板,添加Kconfig和Makefile中的配置项即可。内容仅仅是printf,没有进行调用api直接控制led。

四,成功的输出效果

board_name是新加的自定义板子ap335_ap,apled的新加命令及参数也可以正常运行。 自定义的板子信息"Apple Cai's am335 Board"及自定义的命令符"AP-Boot=>"显示正常。

U-Boot SPL 2023.10 (Oct 20 2023 - 19:37:40 +0800)
Trying to boot from MMC1

U-Boot 2023.10 (Oct 20 2023 - 19:37:40 +0800)Apple Cai's am335 Board

CPU  : AM335X-GP rev 2.1
Model: TI AM335x EVM
DRAM:  512 MiB
Core:  154 devices, 16 uclasses, devicetree: separate
NAND:  0 MiB
MMC:   OMAP SD/MMC: 0
Loading Environment from FAT... 
Unable to read "uboot.env" from mmc0:1...
<ethaddr> not set. Validating first E-fuse MAC
Net:  eth2: ethernet@4a100000
Hit any key to stop autoboot:  0
AP-Boot=> printenv board_name
board_name=am335_ap
AP-Boot=> apled led on
led name = led,set to on

五,小结

关于驱动开发就是要多动动手,有时候看起来很容易,感觉半小时就完成了,但是没想到过程中还有那么多小坑。

然后我还有一个小问题没有解决,关于arch_misc_init,device没有设置而driver配置了居然会报错,感觉设计的没有解耦,我记得应该设备和驱动分离的,然后再进行绑定,不应该会报错的。明天把uboot的dm驱动的绑定再深入看看代码流。


【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
2Nv1H5BMjysw