解决PetaLinux编译Microblaze的U-Boot的错误 “undefined reference to `eth_get_dev_index'”等

错误

PetaLinux编译Microblaze的U-Boot时,遇到下列错误 ,链接时提示找不到相关函数。

|   microblazeel-xilinx-linux-ld.bfd    -Bstatic  --no-dynamic-linker -Ttext 0x80100000 -o u-boot -T u-boot.lds arch/microblaze/cpu/start.o --start-group  arch/microblaze/cpu/built-in.o  arch/microblaze/lib/built-in.o  board/xilinx/microblaze-generic/built-in.o  cmd/built-in.o  common/built-in.o  disk/built-in.o  drivers/built-in.o  drivers/dma/built-in.o  drivers/gpio/built-in.o  drivers/i2c/built-in.o  drivers/net/built-in.o  drivers/net/phy/built-in.o  drivers/power/built-in.o  drivers/power/battery/built-in.o  drivers/power/domain/built-in.o  drivers/power/fuel_gauge/built-in.o  drivers/power/mfd/built-in.o  drivers/power/pmic/built-in.o  drivers/power/regulator/built-in.o  drivers/serial/built-in.o  drivers/spi/built-in.o  drivers/usb/cdns3/built-in.o  drivers/usb/common/built-in.o  drivers/usb/dwc3/built-in.o  drivers/usb/emul/built-in.o  drivers/usb/eth/built-in.o  drivers/usb/host/built-in.o  drivers/usb/musb-new/built-in.o  drivers/usb/musb/built-in.o  drivers/usb/phy/built-in.o  drivers/usb/ulpi/built-in.o  dts/built-in.o  env/built-in.o  fs/built-in.o  lib/built-in.o  net/built-in.o --end-group -L /proj/hankf/ac701-microblaze-peta-202/build/tmp/work/microblazeel_v11.0_bs_cmp_mh_div_generic-xilinx-linux/u-boot-xlnx/v2020.01-xilinx-v2020.2+gitAUTOINC+bb4660c33a-r0/recipe-sysroot/usr/lib/microblazeel-xilinx-linux/9.2.0 -lgcc -Map u-boot.map;  true
| microblazeel-xilinx-linux-ld.bfd: cmd/built-in.o: in function `format_mac_pxe':
| /proj/hankf/ac701-microblaze-peta-202/build/tmp/work/microblazeel_v11.0_bs_cmp_mh_div_generic-xilinx-linux/u-boot-xlnx/v2020.01-xilinx-v2020.2+gitAUTOINC+bb4660c33a-r0/git/cmd/pxe_utils.c:49: undefined reference to `eth_get_dev_index'
| microblazeel-xilinx-linux-ld.bfd: /proj/hankf/ac701-microblaze-peta-202/build/tmp/work/microblazeel_v11.0_bs_cmp_mh_div_generic-xilinx-linux/u-boot-xlnx/v2020.01-xilinx-v2020.2+gitAUTOINC+bb4660c33a-r0/git/cmd/pxe_utils.c:49: undefined reference to `eth_env_get_enetaddr_by_index'
| make[1]: *** [/proj/hankf/ac701-microblaze-peta-202/build/tmp/work/microblazeel_v11.0_bs_cmp_mh_div_generic-xilinx-linux/u-boot-xlnx/v2020.01-xilinx-v2020.2+gitAUTOINC+bb4660c33a-r0/git/Makefile:1671: u-boot] Error 1
| make[1]: Leaving directory '/proj/hankf/ac701-microblaze-peta-202/build/tmp/work/microblazeel_v11.0_bs_cmp_mh_div_generic-xilinx-linux/u-boot-xlnx/v2020.01-xilinx-v2020.2+gitAUTOINC+bb4660c33a-r0/build'
| make: *** [Makefile:167: sub-make] Error 2
| make: Leaving directory '/proj/hankf/ac701-microblaze-peta-202/build/tmp/work/microblazeel_v11.0_bs_cmp_mh_div_generic-xilinx-linux/u-boot-xlnx/v2020.01-xilinx-v2020.2+gitAUTOINC+bb4660c33a-r0/git'
| WARNING: /proj/hankf/ac701-microblaze-peta-202/build/tmp/work/microblazeel_v11.0_bs_cmp_mh_div_generic-xilinx-linux/u-boot-xlnx/v2020.01-xilinx-v2020.2+gitAUTOINC+bb4660c33a-r0/temp/run.do_compile.44657:1 exit 1 from 'exit 1'

解决办法

方法1

函数“eth_get_dev_index”在网络代码里定义,使能CONFIG_NET后才会被编译。

hankf@XSZGS4:u-boot-xlnx$ grep -rn eth_get_dev_index 
include/net.h:241:int eth_get_dev_index(void);		/* get the device index */
cmd/pxe_utils.c:49:	if (!eth_env_get_enetaddr_by_index("eth", eth_get_dev_index(), ethaddr))
net/eth_legacy.c:94:int eth_get_dev_index(void)
net/net.c:1394:			int num = eth_get_dev_index();
net/eth-uclass.c:175:int eth_get_dev_index(void)
net/cdp.c:154:	sprintf(buf, CONFIG_CDP_PORT_ID, eth_get_dev_index());

hankf@XSZGS4:u-boot-xlnx$ grep -rn  eth-uclass.c 
Binary file .git/index matches
drivers/net/Kconfig:12:	  This is currently implemented in net/eth-uclass.c

hankf@XSZGS4:u-boot-xlnx$ grep -rn  eth-uclass.o
net/Makefile:14:obj-$(CONFIG_NET)      += eth-uclass.o

检查工程,发现U-Boot没有使能“Networking Support” (CONFIG_NET)。

 There is no help available for this option.          
   Symbol: NET [=y]                        
   Type  : bool                                  
   Prompt: Networking support                 
     Defined at net/Kconfig:5                     

执行“petalinux-config -c u-boot”, 选择“Networking Support”, 再编译,能通过。

方法2

嵌入式系统里,一般不使用PXE,应该可以不编译pxe_utils.c。

搜索“pxe_utils.o”,发现它被下列两个配置项引用。

obj-$(CONFIG_CMD_PXE) += pxe.o pxe_utils.o
obj-$(CONFIG_CMD_SYSBOOT) += sysboot.o pxe_utils.o

检查对应的配置项,发现“CONFIG_CMD_SYSBOOT”被“DISTRO_DEFAULTS”使能。

CONFIG_CMD_SYSBOOT:                         
   Boot image via local extlinux.conf file                                       
   Symbol: CMD_SYSBOOT [=y]                     
   Type  : bool                                  
   Prompt: sysboot  Location:                                   
       -> Command line interface                     
         -> Misc commands                              
     Defined at cmd/Kconfig:1689                   
     Selects: MENU [=y]                            
     Selected by [y]:                              
     - DISTRO_DEFAULTS [=y]   

禁止“DISTRO_DEFAULTS”,“CONFIG_CMD_SYSBOOT”, , 再编译,能通过。

posted @ 2023-06-27 09:49  HankFu  阅读(185)  评论(0编辑  收藏  举报