ITADN

Linker error when using MDIO without a PHY

#113763ClosedAlbrechtL 创建于 2026-07-16
priority: lowarea: Ethernet
A
AlbrechtLcommented
### Describe the bug For debugging purposes I tried to use the `mdio-gpio` driver to access a RTL8305 Ethernet switch chip via the MDIO shell and some test c-code. It seems that this is not tested or supported because I'm getting a linker error `undefined reference to __device_dts_ord_39`. See below how to reproduce it. I'm using a STM32G030 (32 kb flash, 8 kb memory). Possible workaround: adding a dummy PHY node `ethernet-phy-fixed-link` to the device tree and enabled networking as well as the networking stack but then the 8 kb of RAM of the µC exceeds :-(. ### Regression - [ ] This is a regression. ### Steps to reproduce I'm using the `hello world` example and the board `weact_stm32g030_core`. 1. Enhance the board device tree `weact_stm32g030_core.dts` with this node. ``` mdio0: mdio { compatible = "zephyr,mdio-gpio"; mdc-gpios = <&gpioa 11 GPIO_ACTIVE_HIGH>; mdio-gpios = <&gpioa 12 GPIO_ACTIVE_HIGH>; status = "okay"; #address-cells = <1>; #size-cells = <0>; }; ``` 2. Add this code to the hello world example ``` #include <stdio.h> #include <zephyr/kernel.h> #include <zephyr/drivers/mdio.h> #define MDIO_NODE DT_NODELABEL(mdio0) int main(void) { const struct device *dev = DEVICE_DT_GET(MDIO_NODE); int cnt = 0; uint16_t data = 0; uint16_t reg_addr = 0; printf("Hello World! %s\n", CONFIG_BOARD_TARGET); if (!device_is_ready(dev)) { printf("MDIO-device is not ready\n"); } for (int i = 0; i < 32; i++) { data = 0; if (mdio_read(dev, i, reg_addr, &data) >= 0 && data != UINT16_MAX) { cnt++; printf("Found MDIO device @ 0x%x", i); } } printf("%u devices found on %s", cnt, dev->name); return 0; } ``` 3. Enable these kconfig options ``` CONFIG_GPIO=y CONFIG_MDIO=y CONFIG_MDIO_GPIO=y ``` 4. Build it ### Relevant log output ```shell (.venv) $ west build [3/8] Linking C executable zephyr/zephyr_pre0.elf; Logical command for additional byproducts on target: zephyr_pre0 FAILED: [code=1] zephyr/zephyr_pre0.elf zephyr/zephyr_pre0.map /xxxx/src/zephyrproject/zephyr/build/zephyr/zephyr_pre0.map : && /usr/bin/ccache /xxxx/zephyr-sdk-1.0.1/gnu/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc -gdwarf-4 -Os zephyr/CMakeFiles/zephyr_pre0.dir/misc/empty_file.c.obj -o zephyr/zephyr_pre0.elf zephyr/CMakeFiles/offsets.dir/./arch/arm/core/offsets/offsets.c.obj -T zephyr/linker_zephyr_pre0.cmd -Wl,-Map,/xxxx/src/zephyrproject/zephyr/build/zephyr/zephyr_pre0.map -Wl,--whole-archive app/libapp.a zephyr/libzephyr.a zephyr/arch/common/libarch__common.a zephyr/arch/arch/arm/core/libarch__arm__core.a zephyr/arch/arch/arm/core/cortex_m/libarch__arm__core__cortex_m.a zephyr/lib/libc/picolibc/liblib__libc__picolibc.a zephyr/lib/libc/common/liblib__libc__common.a zephyr/subsys/portability/posix/c_lib_ext/libsubsys__portability__posix__c_lib_ext.a zephyr/drivers/interrupt_controller/libdrivers__interrupt_controller.a zephyr/drivers/clock_control/libdrivers__clock_control.a zephyr/drivers/console/libdrivers__console.a zephyr/drivers/gpio/libdrivers__gpio.a zephyr/drivers/pinctrl/libdrivers__pinctrl.azephyr/drivers/reset/libdrivers__reset.a zephyr/drivers/serial/libdrivers__serial.a zephyr/drivers/timer/libdrivers__timer.a modules/hal_stm32/stm32cube/lib..__modules__hal__stm32__stm32cube.a -Wl,--no-whole-archive zephyr/kernel/libkernel.a -L/xxxx/src/zephyrproject/zephyr/build/zephyr zephyr/arch/common/libisr_tables.a -fuse-ld=bfd -mcpu=cortex-m0plus -mthumb -mabi=aapcs -mfp16-format=ieee -mtp=soft -Wl,--gc-sections -Wl,--build-id=none -Wl,--sort-common=descending -Wl,--sort-section=alignment -Wl,-u,_OffsetAbsSyms -Wl,-u,_ConfigAbsSyms -nostdlib -static -znoexecstack -Wl,-X -Wl,-N -Wl,--orphan-handling=warn -Wl,-no-pie -Wl,--undefined=_sw_isr_table -Wl,--undefined=_irq_vector_table -specs=picolibc.specs -DPICOLIBC_LONG_LONG_PRINTF_SCANF -L"/xxxx/zephyr-sdk-1.0.1/gnu/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/14.3.0/thumb/v6-m/nofp/space" -lc -lgcc && cd /xxxx/src/zephyrproject/zephyr/build/zephyr && /usr/bin/cmake -E true /xxxx/zephyr-sdk-1.0.1/gnu/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/14.3.0/../../../../arm-zephyr-eabi/bin/ld.bfd: app/libapp.a(main.c.obj): in function `main': /xxxx/src/zephyrproject/zephyr/samples/hello_world/src/main.c:39:(.text.main+0x78): undefined reference to `__device_dts_ord_39' collect2: error: ld returned 1 exit status ninja: build stopped: subcommand failed. FATAL ERROR: command exited with status 1: /usr/bin/cmake --build /xxxx/src/zephyrproject/zephyr/build ``` ### Impact Major – Severely degrades functionality; workaround is difficult or unavailable. ### Environment - OS: Ubuntu - Zephyr SDK - Zephyr 4.4.99 (454f92597639d56513a75c3b4300bf958a2baf2f) ### Additional Context I understand that in the most cases you will have a PHY when using MDIO but in my case I simply want to access the Ethernet switch chip registers to initialize the unmanaged switch. So, I definitely don't need PHYs in the device trees and built-in networking stack.
关闭于 2026-07-22 2 条评论