Skip to contentSkip to conversation

hw/arm: sabrelite: Improve emulation fidelity to allow booting upstream U-Boot

PATCH Applied Bin Meng 4 participants 16 messages Jan 6, 2021 – May 2, 2021 Arm i.MX and Layerscape

lore
Share & tools
lore

Bin Meng

author
#0 lore raw

v3 cover hw/arm: sabrelite: Improve emulation fidelity to allow booting upstream U-Boot

From: Bin Meng <[email protected]>

At present the upstream U-Boot (as of today, v2021.01-rc3) does not boot on QEMU sabrelite machine.

This fixes several issues to improve emulation fidelity of the i.MX6 sabrelite board. With this series, upstream U-Boot can boot to U-Boot command shell. While we are here, add a target guide for this board to help people run Linux kernel and U-Boot on QEMU.

Changes in v3:
- correct 2 typos in sabrelite.rst

Changes in v2:
- new patch: add sabrelite target guide

Bin Meng (4):
hw/misc: imx6_ccm: Update PMU_MISC0 reset value hw/msic: imx6_ccm: Correct register value for silicon type hw/arm: sabrelite: Connect the Ethernet PHY at address 6 docs/system: arm: Add sabrelite board description

 docs/system/arm/sabrelite.rst | 119 ++++++++++++++++++++++++++++++++++
 docs/system/target-arm.rst    |   1 +
 hw/arm/sabrelite.c            |   4 ++
 hw/misc/imx6_ccm.c            |   4 +-
 4 files changed, 126 insertions(+), 2 deletions(-)
 create mode 100644 docs/system/arm/sabrelite.rst
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH v3 1/4 hw/misc: imx6_ccm: Update PMU_MISC0 reset value

From: Bin Meng <[email protected]>

U-Boot expects PMU_MISC0 register bit 7 is set (see init_bandgap() in arch/arm/mach-imx/mx6/soc.c) during boot. This bit indicates the bandgap has stabilized.

With this change, the latest upstream U-Boot (v2021.01-rc3) for imx6 sabrelite board (mx6qsabrelite_defconfig), with a slight change made by switching CONFIG_OF_SEPARATE to CONFIG_OF_EMBED, boots to U-Boot shell on QEMU with the following command:

$ qemu-system-arm -M sabrelite -smp 4 -m 1G -kernel u-boot \
    -display none -serial null -serial stdio

Boot log below:

U-Boot 2021.01-rc3 (Dec 12 2020 - 17:40:02 +0800)

CPU: Freescale i.MX?? rev1.0 at 792 MHz
Reset cause: POR
Model: Freescale i.MX6 Quad SABRE Lite Board
Board: SABRE Lite
I2C: ready
DRAM: 1 GiB
force_idle_bus: sda=0 scl=0 sda.gp=0x5c scl.gp=0x55
force_idle_bus: failed to clear bus, sda=0 scl=0
force_idle_bus: sda=0 scl=0 sda.gp=0x6d scl.gp=0x6c
force_idle_bus: failed to clear bus, sda=0 scl=0
force_idle_bus: sda=0 scl=0 sda.gp=0xcb scl.gp=0x5
force_idle_bus: failed to clear bus, sda=0 scl=0
MMC: FSL_SDHC: 0, FSL_SDHC: 1
Loading Environment from MMC... *** Warning - No block device, using default environment

  In:    serial
  Out:   serial
  Err:   serial
  Net:   Board Net Initialization Failed

No ethernet found.
starting USB...
Bus usb@2184000: usb dr_mode not found
USB EHCI 1.00
Bus usb@2184200: USB EHCI 1.00
scanning bus usb@2184000 for devices... 1 USB Device(s) found scanning bus usb@2184200 for devices... 1 USB Device(s) found
scanning usb for storage devices... 0 Storage Device(s) found scanning usb for ethernet devices... 0 Ethernet Device(s) found
Hit any key to stop autoboot: 0
=>

---

(no changes since v1)

 hw/misc/imx6_ccm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/misc/imx6_ccm.c +1 -1
index cb740427ec..7e031b6775 100644
@@ -450,7 +450,7 @@ static void imx6_ccm_reset(DeviceState *dev)
     s->analog[PMU_REG_3P0] = 0x00000F74;
     s->analog[PMU_REG_2P5] = 0x00005071;
     s->analog[PMU_REG_CORE] = 0x00402010;
-    s->analog[PMU_MISC0] = 0x04000000;
+    s->analog[PMU_MISC0] = 0x04000080;
     s->analog[PMU_MISC1] = 0x00000000;
     s->analog[PMU_MISC2] = 0x00272727;
 
Signature · 1 line
2.25.1
author
#2 lore raw

PATCH v3 2/4 hw/msic: imx6_ccm: Correct register value for silicon type

In reply to Bin Meng

From: Bin Meng <[email protected]>

Currently when U-Boot boots, it prints "??" for i.MX processor:

CPU: Freescale i.MX?? rev1.0 at 792 MHz

The register that was used to determine the silicon type is undocumented in the latest IMX6DQRM (Rev. 6, 05/2020), but we can refer to get_cpu_rev() in arch/arm/mach-imx/mx6/soc.c in the U-Boot source codes that USB_ANALOG_DIGPROG is used.

Update its reset value to indicate i.MX6Q.

---

(no changes since v1)

 hw/misc/imx6_ccm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/misc/imx6_ccm.c +1 -1
index 7e031b6775..4c830fd89a 100644
@@ -462,7 +462,7 @@ static void imx6_ccm_reset(DeviceState *dev)
     s->analog[USB_ANALOG_USB2_VBUS_DETECT] = 0x00000004;
     s->analog[USB_ANALOG_USB2_CHRG_DETECT] = 0x00000000;
     s->analog[USB_ANALOG_USB2_MISC] = 0x00000002;
-    s->analog[USB_ANALOG_DIGPROG] = 0x00000000;
+    s->analog[USB_ANALOG_DIGPROG] = 0x00630000;
 
     /* all PLLs need to be locked */
     s->analog[CCM_ANALOG_PLL_ARM]   |= CCM_ANALOG_PLL_LOCK;
Signature · 1 line
2.25.1
author
#3 lore raw

PATCH v3 3/4 hw/arm: sabrelite: Connect the Ethernet PHY at address 6

In reply to Bin Meng

From: Bin Meng <[email protected]>

At present, when booting U-Boot on QEMU sabrelite, we see:

Net: Board Net Initialization Failed
No ethernet found.

U-Boot scans PHY at address 4/5/6/7 (see board_eth_init() in the U-Boot source: board/boundary/nitrogen6x/nitrogen6x.c). On the real board, the Ethernet PHY is at address 6. Adjust this by updating the "fec-phy-num" property of the fsl_imx6 SoC object.

With this change, U-Boot sees the PHY but complains MAC address:

Net: using phy at 6
FEC [PRIME]
Error: FEC address not set.

This is due to U-Boot tries to read the MAC address from the fuse, which QEMU does not have any valid content filled in. However this does not prevent the Ethernet from working in QEMU. We just need to set up the MAC address later in the U-Boot command shell, by:

=> setenv ethaddr 00:11:22:33:44:55

---

(no changes since v1)

 hw/arm/sabrelite.c | 4 ++++
 1 file changed, 4 insertions(+)
hw/arm/sabrelite.c +4 -0
index 91d8c43a7e..a3dbf85e0e 100644
@@ -51,6 +51,10 @@ static void sabrelite_init(MachineState *machine)
 
     s = FSL_IMX6(object_new(TYPE_FSL_IMX6));
     object_property_add_child(OBJECT(machine), "soc", OBJECT(s));
+
+    /* Ethernet PHY address is 6 */
+    object_property_set_int(OBJECT(s), "fec-phy-num", 6, &error_fatal);
+
     qdev_realize(DEVICE(s), NULL, &error_fatal);
 
     memory_region_add_subregion(get_system_memory(), FSL_IMX6_MMDC_ADDR,
Signature · 1 line
2.25.1
#4 lore raw

Re: [PATCH v3 3/4] hw/arm: sabrelite: Connect the Ethernet PHY at address 6

Hi,

Quoted 18 lines · Bin Meng

From: Bin Meng <[email protected]>

At present, when booting U-Boot on QEMU sabrelite, we see:

Net: Board Net Initialization Failed
No ethernet found.

U-Boot scans PHY at address 4/5/6/7 (see board_eth_init() in the U-Boot source: board/boundary/nitrogen6x/nitrogen6x.c). On the real board, the Ethernet PHY is at address 6. Adjust this by updating the "fec-phy-num" property of the fsl_imx6 SoC object.

With this change, U-Boot sees the PHY but complains MAC address:

Net: using phy at 6
FEC [PRIME]
Error: FEC address not set.

Quoted 7 lines

This is due to U-Boot tries to read the MAC address from the fuse, which QEMU does not have any valid content filled in. However this does not prevent the Ethernet from working in QEMU. We just need to set up the MAC address later in the U-Boot command shell, by:

=> setenv ethaddr 00:11:22:33:44:55

With this patch in place, the standard Ethernet interface no longer works when booting sabrelite Linux images directly (without u-boot) using the following qemu command.

	qemu-system-arm -M sabrelite -kernel arch/arm/boot/zImage
	...

The Ethernet interface still instantiates, but packet transfer to the host no longer works. Reverting this patch fixes the problem for me.

Is there a qemu command line parameter that is now necessary to instantiate the Ethernet interface when booting Linux ?

Thanks,
Guenter

author
#5 lore raw

Re: [PATCH v3 3/4] hw/arm: sabrelite: Connect the Ethernet PHY at address 6

Quoted 36 lines · Guenter Roeck

Hi,

Quoted 18 lines · Bin Meng

From: Bin Meng <[email protected]>

At present, when booting U-Boot on QEMU sabrelite, we see:

Net: Board Net Initialization Failed
No ethernet found.

U-Boot scans PHY at address 4/5/6/7 (see board_eth_init() in the U-Boot source: board/boundary/nitrogen6x/nitrogen6x.c). On the real board, the Ethernet PHY is at address 6. Adjust this by updating the "fec-phy-num" property of the fsl_imx6 SoC object.

With this change, U-Boot sees the PHY but complains MAC address:

Net: using phy at 6
FEC [PRIME]
Error: FEC address not set.

Quoted 7 lines

This is due to U-Boot tries to read the MAC address from the fuse, which QEMU does not have any valid content filled in. However this does not prevent the Ethernet from working in QEMU. We just need to set up the MAC address later in the U-Boot command shell, by:

=> setenv ethaddr 00:11:22:33:44:55

With this patch in place, the standard Ethernet interface no longer works when booting sabrelite Linux images directly (without u-boot) using the following qemu command.
qemu-system-arm -M sabrelite -kernel arch/arm/boot/zImage
...

Quoted 5 lines

The Ethernet interface still instantiates, but packet transfer to the host no longer works. Reverting this patch fixes the problem for me.

Is there a qemu command line parameter that is now necessary to instantiate the Ethernet interface when booting Linux ?

Enabling "guest_errors" shows that Linux kernel fec driver is trying to read PHY at address 0, which is not what we want.

[imx.fec.phy]imx_phy_read: Bad phy num 0

The device tree blob of the sabrelite does not contain a node for the ethernet phy specifying phy address, so I suspect Linux kernel driver is using default phy address 0 instead.

Could you please test on a real hardware to see what happens?

Regards,
Bin

#6 lore raw

Re: [PATCH v3 3/4] hw/arm: sabrelite: Connect the Ethernet PHY at address 6

Quoted 46 lines · Bin Meng
Quoted 36 lines · Guenter Roeck

Hi,

Quoted 18 lines · Bin Meng

From: Bin Meng <[email protected]>

At present, when booting U-Boot on QEMU sabrelite, we see:

Net: Board Net Initialization Failed
No ethernet found.

U-Boot scans PHY at address 4/5/6/7 (see board_eth_init() in the U-Boot source: board/boundary/nitrogen6x/nitrogen6x.c). On the real board, the Ethernet PHY is at address 6. Adjust this by updating the "fec-phy-num" property of the fsl_imx6 SoC object.

With this change, U-Boot sees the PHY but complains MAC address:

Net: using phy at 6
FEC [PRIME]
Error: FEC address not set.

Quoted 7 lines

This is due to U-Boot tries to read the MAC address from the fuse, which QEMU does not have any valid content filled in. However this does not prevent the Ethernet from working in QEMU. We just need to set up the MAC address later in the U-Boot command shell, by:

=> setenv ethaddr 00:11:22:33:44:55

With this patch in place, the standard Ethernet interface no longer works when booting sabrelite Linux images directly (without u-boot) using the following qemu command.
qemu-system-arm -M sabrelite -kernel arch/arm/boot/zImage
...

Quoted 5 lines

The Ethernet interface still instantiates, but packet transfer to the host no longer works. Reverting this patch fixes the problem for me.

Is there a qemu command line parameter that is now necessary to instantiate the Ethernet interface when booting Linux ?

Enabling "guest_errors" shows that Linux kernel fec driver is trying to read PHY at address 0, which is not what we want.

Quoted 8 lines

[imx.fec.phy]imx_phy_read: Bad phy num 0

The device tree blob of the sabrelite does not contain a node for the ethernet phy specifying phy address, so I suspect Linux kernel driver is using default phy address 0 instead.

Could you please test on a real hardware to see what happens?

I don't have access to real hardware, sorry.

Guenter

#7 lore raw

Re: [PATCH v3 3/4] hw/arm: sabrelite: Connect the Ethernet PHY at address 6

In reply to Bin Meng
Quoted 46 lines · Bin Meng
Quoted 36 lines · Guenter Roeck

Hi,

Quoted 18 lines · Bin Meng

From: Bin Meng <[email protected]>

At present, when booting U-Boot on QEMU sabrelite, we see:

Net: Board Net Initialization Failed
No ethernet found.

U-Boot scans PHY at address 4/5/6/7 (see board_eth_init() in the U-Boot source: board/boundary/nitrogen6x/nitrogen6x.c). On the real board, the Ethernet PHY is at address 6. Adjust this by updating the "fec-phy-num" property of the fsl_imx6 SoC object.

With this change, U-Boot sees the PHY but complains MAC address:

Net: using phy at 6
FEC [PRIME]
Error: FEC address not set.

Quoted 7 lines

This is due to U-Boot tries to read the MAC address from the fuse, which QEMU does not have any valid content filled in. However this does not prevent the Ethernet from working in QEMU. We just need to set up the MAC address later in the U-Boot command shell, by:

=> setenv ethaddr 00:11:22:33:44:55

With this patch in place, the standard Ethernet interface no longer works when booting sabrelite Linux images directly (without u-boot) using the following qemu command.
qemu-system-arm -M sabrelite -kernel arch/arm/boot/zImage
...

Quoted 5 lines

The Ethernet interface still instantiates, but packet transfer to the host no longer works. Reverting this patch fixes the problem for me.

Is there a qemu command line parameter that is now necessary to instantiate the Ethernet interface when booting Linux ?

Enabling "guest_errors" shows that Linux kernel fec driver is trying to read PHY at address 0, which is not what we want.

Quoted 8 lines

[imx.fec.phy]imx_phy_read: Bad phy num 0

The device tree blob of the sabrelite does not contain a node for the ethernet phy specifying phy address, so I suspect Linux kernel driver is using default phy address 0 instead.

Could you please test on a real hardware to see what happens?

The problem is that qemu returns 0 when the OS tries to read from a non-existing PHY. Linux expects it to return 0xffff, and believes that a PHY is there if 0 is returned. This helps:

hw/net/imx_fec.c +1 -1
index f03450c028..3c90c38e26 100644
@@ -285,7 +285,7 @@ static uint32_t imx_phy_read(IMXFECState *s, int reg)
     if (phy != s->phy_num) {
         qemu_log_mask(LOG_GUEST_ERROR, "[%s.phy]%s: Bad phy num %u\n",
                       TYPE_IMX_FEC, __func__, phy);
-        return 0;
+        return 0xffff;
     }
 

Note that this is not really a guest error; any OS can and likely will scan the MII bus for connected phy chips.

Guenter

#8 lore raw

Re: [PATCH v3 3/4] hw/arm: sabrelite: Connect the Ethernet PHY at address 6

Quoted 53 lines · Guenter Roeck
Quoted 52 lines · Bin Meng
Quoted 36 lines · Guenter Roeck

Hi,

Quoted 18 lines · Bin Meng

From: Bin Meng <[email protected]>

At present, when booting U-Boot on QEMU sabrelite, we see:

Net: Board Net Initialization Failed
No ethernet found.

U-Boot scans PHY at address 4/5/6/7 (see board_eth_init() in the U-Boot source: board/boundary/nitrogen6x/nitrogen6x.c). On the real board, the Ethernet PHY is at address 6. Adjust this by updating the "fec-phy-num" property of the fsl_imx6 SoC object.

With this change, U-Boot sees the PHY but complains MAC address:

Net: using phy at 6
FEC [PRIME]
Error: FEC address not set.

Quoted 7 lines

This is due to U-Boot tries to read the MAC address from the fuse, which QEMU does not have any valid content filled in. However this does not prevent the Ethernet from working in QEMU. We just need to set up the MAC address later in the U-Boot command shell, by:

=> setenv ethaddr 00:11:22:33:44:55

With this patch in place, the standard Ethernet interface no longer works when booting sabrelite Linux images directly (without u-boot) using the following qemu command.
qemu-system-arm -M sabrelite -kernel arch/arm/boot/zImage
...

Quoted 5 lines

The Ethernet interface still instantiates, but packet transfer to the host no longer works. Reverting this patch fixes the problem for me.

Is there a qemu command line parameter that is now necessary to instantiate the Ethernet interface when booting Linux ?

Enabling "guest_errors" shows that Linux kernel fec driver is trying to read PHY at address 0, which is not what we want.

[imx.fec.phy]imx_phy_read: Bad phy num 0

The device tree blob of the sabrelite does not contain a node for the ethernet phy specifying phy address, so I suspect Linux kernel driver is using default phy address 0 instead.

Quoted 6 lines
Quoted 2 lines

Could you please test on a real hardware to see what happens?

The problem is that qemu returns 0 when the OS tries to read from a non-existing PHY. Linux expects it to return 0xffff, and believes that a PHY is there if 0 is returned.

Correct.

Quoted 14 lines

This helps:

hw/net/imx_fec.c +1 -1
index f03450c028..3c90c38e26 100644
@@ -285,7 +285,7 @@ static uint32_t imx_phy_read(IMXFECState *s, int reg)
     if (phy != s->phy_num) {
         qemu_log_mask(LOG_GUEST_ERROR, "[%s.phy]%s: Bad phy num %u\n",
                       TYPE_IMX_FEC, __func__, phy);
-        return 0;
+        return 0xffff;
     }
 
Quoted 2 lines

Note that this is not really a guest error; any OS can and likely will scan the MII bus for connected phy chips.

Correct. This should be a trace event instead.

#9 lore raw

Re: [PATCH v3 3/4] hw/arm: sabrelite: Connect the Ethernet PHY at address 6

Quoted 54 lines · Philippe Mathieu-Daudé
Quoted 53 lines · Guenter Roeck
Quoted 52 lines · Bin Meng
Quoted 36 lines · Guenter Roeck

Hi,

Quoted 18 lines · Bin Meng

From: Bin Meng <[email protected]>

At present, when booting U-Boot on QEMU sabrelite, we see:

Net: Board Net Initialization Failed
No ethernet found.

U-Boot scans PHY at address 4/5/6/7 (see board_eth_init() in the U-Boot source: board/boundary/nitrogen6x/nitrogen6x.c). On the real board, the Ethernet PHY is at address 6. Adjust this by updating the "fec-phy-num" property of the fsl_imx6 SoC object.

With this change, U-Boot sees the PHY but complains MAC address:

Net: using phy at 6
FEC [PRIME]
Error: FEC address not set.

Quoted 7 lines

This is due to U-Boot tries to read the MAC address from the fuse, which QEMU does not have any valid content filled in. However this does not prevent the Ethernet from working in QEMU. We just need to set up the MAC address later in the U-Boot command shell, by:

=> setenv ethaddr 00:11:22:33:44:55

With this patch in place, the standard Ethernet interface no longer works when booting sabrelite Linux images directly (without u-boot) using the following qemu command.
qemu-system-arm -M sabrelite -kernel arch/arm/boot/zImage
...

Quoted 5 lines

The Ethernet interface still instantiates, but packet transfer to the host no longer works. Reverting this patch fixes the problem for me.

Is there a qemu command line parameter that is now necessary to instantiate the Ethernet interface when booting Linux ?

Enabling "guest_errors" shows that Linux kernel fec driver is trying to read PHY at address 0, which is not what we want.

[imx.fec.phy]imx_phy_read: Bad phy num 0

The device tree blob of the sabrelite does not contain a node for the ethernet phy specifying phy address, so I suspect Linux kernel driver is using default phy address 0 instead.

Quoted 9 lines
Quoted 6 lines
Quoted 2 lines

Could you please test on a real hardware to see what happens?

The problem is that qemu returns 0 when the OS tries to read from a non-existing PHY. Linux expects it to return 0xffff, and believes that a PHY is there if 0 is returned.

Correct.

I'll send a patch. Next question is why the Ethernet interfaces on mcimx6ul-evk and mcimx7d-sabre don't work. I either get no connectivity at all (similar to the above) or something like

fec 2188000.ethernet eth1: Unable to connect to phy
ifconfig: SIOCSIFFLAGS: No such device

Any idea ?

Thanks,
Guenter

author
#10 lore raw

Re: [PATCH v3 3/4] hw/arm: sabrelite: Connect the Ethernet PHY at address 6

Quoted 66 lines · Guenter Roeck
Quoted 54 lines · Philippe Mathieu-Daudé
Quoted 53 lines · Guenter Roeck
Quoted 52 lines · Bin Meng
Quoted 36 lines · Guenter Roeck

Hi,

Quoted 18 lines · Bin Meng

From: Bin Meng <[email protected]>

At present, when booting U-Boot on QEMU sabrelite, we see:

Net: Board Net Initialization Failed
No ethernet found.

U-Boot scans PHY at address 4/5/6/7 (see board_eth_init() in the U-Boot source: board/boundary/nitrogen6x/nitrogen6x.c). On the real board, the Ethernet PHY is at address 6. Adjust this by updating the "fec-phy-num" property of the fsl_imx6 SoC object.

With this change, U-Boot sees the PHY but complains MAC address:

Net: using phy at 6
FEC [PRIME]
Error: FEC address not set.

Quoted 7 lines

This is due to U-Boot tries to read the MAC address from the fuse, which QEMU does not have any valid content filled in. However this does not prevent the Ethernet from working in QEMU. We just need to set up the MAC address later in the U-Boot command shell, by:

=> setenv ethaddr 00:11:22:33:44:55

With this patch in place, the standard Ethernet interface no longer works when booting sabrelite Linux images directly (without u-boot) using the following qemu command.
qemu-system-arm -M sabrelite -kernel arch/arm/boot/zImage
...

Quoted 5 lines

The Ethernet interface still instantiates, but packet transfer to the host no longer works. Reverting this patch fixes the problem for me.

Is there a qemu command line parameter that is now necessary to instantiate the Ethernet interface when booting Linux ?

Enabling "guest_errors" shows that Linux kernel fec driver is trying to read PHY at address 0, which is not what we want.

[imx.fec.phy]imx_phy_read: Bad phy num 0

The device tree blob of the sabrelite does not contain a node for the ethernet phy specifying phy address, so I suspect Linux kernel driver is using default phy address 0 instead.

Quoted 9 lines
Quoted 6 lines
Quoted 2 lines

Could you please test on a real hardware to see what happens?

The problem is that qemu returns 0 when the OS tries to read from a non-existing PHY. Linux expects it to return 0xffff, and believes that a PHY is there if 0 is returned.

Correct.

Quoted 8 lines

I'll send a patch. Next question is why the Ethernet interfaces on mcimx6ul-evk and mcimx7d-sabre don't work. I either get no connectivity at all (similar to the above) or something like

fec 2188000.ethernet eth1: Unable to connect to phy
ifconfig: SIOCSIFFLAGS: No such device

Any idea ?

I don't see these 2 are supported targets of QEMU:
https://wiki.qemu.org/Documentation/Platforms/ARM

Regards,
Bin

#11 lore raw

Re: [PATCH v3 3/4] hw/arm: sabrelite: Connect the Ethernet PHY at address 6

Quoted 71 lines · Bin Meng
Quoted 70 lines · Guenter Roeck
Quoted 54 lines · Philippe Mathieu-Daudé
Quoted 53 lines · Guenter Roeck
Quoted 52 lines · Bin Meng
Quoted 36 lines · Guenter Roeck

Hi,

Quoted 18 lines · Bin Meng

From: Bin Meng <[email protected]>

At present, when booting U-Boot on QEMU sabrelite, we see:

Net: Board Net Initialization Failed
No ethernet found.

U-Boot scans PHY at address 4/5/6/7 (see board_eth_init() in the U-Boot source: board/boundary/nitrogen6x/nitrogen6x.c). On the real board, the Ethernet PHY is at address 6. Adjust this by updating the "fec-phy-num" property of the fsl_imx6 SoC object.

With this change, U-Boot sees the PHY but complains MAC address:

Net: using phy at 6
FEC [PRIME]
Error: FEC address not set.

Quoted 7 lines

This is due to U-Boot tries to read the MAC address from the fuse, which QEMU does not have any valid content filled in. However this does not prevent the Ethernet from working in QEMU. We just need to set up the MAC address later in the U-Boot command shell, by:

=> setenv ethaddr 00:11:22:33:44:55

With this patch in place, the standard Ethernet interface no longer works when booting sabrelite Linux images directly (without u-boot) using the following qemu command.
qemu-system-arm -M sabrelite -kernel arch/arm/boot/zImage
...

Quoted 5 lines

The Ethernet interface still instantiates, but packet transfer to the host no longer works. Reverting this patch fixes the problem for me.

Is there a qemu command line parameter that is now necessary to instantiate the Ethernet interface when booting Linux ?

Enabling "guest_errors" shows that Linux kernel fec driver is trying to read PHY at address 0, which is not what we want.

[imx.fec.phy]imx_phy_read: Bad phy num 0

The device tree blob of the sabrelite does not contain a node for the ethernet phy specifying phy address, so I suspect Linux kernel driver is using default phy address 0 instead.

Quoted 9 lines
Quoted 6 lines
Quoted 2 lines

Could you please test on a real hardware to see what happens?

The problem is that qemu returns 0 when the OS tries to read from a non-existing PHY. Linux expects it to return 0xffff, and believes that a PHY is there if 0 is returned.

Correct.

I'll send a patch. Next question is why the Ethernet interfaces on mcimx6ul-evk and mcimx7d-sabre don't work. I either get no connectivity at all (similar to the above) or something like

Quoted 8 lines
Quoted 4 lines

fec 2188000.ethernet eth1: Unable to connect to phy
ifconfig: SIOCSIFFLAGS: No such device

Any idea ?

I don't see these 2 are supported targets of QEMU:
https://wiki.qemu.org/Documentation/Platforms/ARM

Reality says otherwise.

$ qemu-system-arm --version
QEMU emulator version 6.0.0 (v6.0.0-25-geac5bb0cc1-dirty)
Copyright (c) 2003-2021 Fabrice Bellard and the QEMU Project developers
$ qemu-system-arm -M ? | grep mcim
mcimx6ul-evk         Freescale i.MX6UL Evaluation Kit (Cortex A7)
mcimx7d-sabre        Freescale i.MX7 DUAL SABRE (Cortex A7)

Guenter

#12 lore raw

Re: [PATCH v3 3/4] hw/arm: sabrelite: Connect the Ethernet PHY at address 6

Quoted 81 lines · Guenter Roeck
Quoted 71 lines · Bin Meng
Quoted 70 lines · Guenter Roeck
Quoted 54 lines · Philippe Mathieu-Daudé
Quoted 53 lines · Guenter Roeck
Quoted 52 lines · Bin Meng
Quoted 36 lines · Guenter Roeck

Hi,

Quoted 18 lines · Bin Meng

From: Bin Meng <[email protected]>

At present, when booting U-Boot on QEMU sabrelite, we see:

Net: Board Net Initialization Failed
No ethernet found.

U-Boot scans PHY at address 4/5/6/7 (see board_eth_init() in the U-Boot source: board/boundary/nitrogen6x/nitrogen6x.c). On the real board, the Ethernet PHY is at address 6. Adjust this by updating the "fec-phy-num" property of the fsl_imx6 SoC object.

With this change, U-Boot sees the PHY but complains MAC address:

Net: using phy at 6
FEC [PRIME]
Error: FEC address not set.

Quoted 7 lines

This is due to U-Boot tries to read the MAC address from the fuse, which QEMU does not have any valid content filled in. However this does not prevent the Ethernet from working in QEMU. We just need to set up the MAC address later in the U-Boot command shell, by:

=> setenv ethaddr 00:11:22:33:44:55

With this patch in place, the standard Ethernet interface no longer works when booting sabrelite Linux images directly (without u-boot) using the following qemu command.
qemu-system-arm -M sabrelite -kernel arch/arm/boot/zImage
...

Quoted 5 lines

The Ethernet interface still instantiates, but packet transfer to the host no longer works. Reverting this patch fixes the problem for me.

Is there a qemu command line parameter that is now necessary to instantiate the Ethernet interface when booting Linux ?

Enabling "guest_errors" shows that Linux kernel fec driver is trying to read PHY at address 0, which is not what we want.

[imx.fec.phy]imx_phy_read: Bad phy num 0

The device tree blob of the sabrelite does not contain a node for the ethernet phy specifying phy address, so I suspect Linux kernel driver is using default phy address 0 instead.

Quoted 9 lines
Quoted 6 lines
Quoted 2 lines

Could you please test on a real hardware to see what happens?

The problem is that qemu returns 0 when the OS tries to read from a non-existing PHY. Linux expects it to return 0xffff, and believes that a PHY is there if 0 is returned.

Correct.

I'll send a patch. Next question is why the Ethernet interfaces on mcimx6ul-evk and mcimx7d-sabre don't work. I either get no connectivity at all (similar to the above) or something like

Quoted 8 lines
Quoted 4 lines

fec 2188000.ethernet eth1: Unable to connect to phy
ifconfig: SIOCSIFFLAGS: No such device

Any idea ?

I don't see these 2 are supported targets of QEMU:
https://wiki.qemu.org/Documentation/Platforms/ARM

Quoted 9 lines

Reality says otherwise.

$ qemu-system-arm --version
QEMU emulator version 6.0.0 (v6.0.0-25-geac5bb0cc1-dirty)
Copyright (c) 2003-2021 Fabrice Bellard and the QEMU Project developers
$ qemu-system-arm -M ? | grep mcim
mcimx6ul-evk         Freescale i.MX6UL Evaluation Kit (Cortex A7)
mcimx7d-sabre        Freescale i.MX7 DUAL SABRE (Cortex A7)

Anyway, the underlying problem is that the phy chips are not connected to the MDIO bus associated with each Ethernet controller. In other words, unlike the current imx fec emulation suggests, there is no 1:1 connection between Ethernet and phy. This is even mentioned in commit 461c51ad42 ("Add a phy-num property to the i.MX FEC emulator"):

"As an example with the i.MX6UL the NXP SOC has 2 Ethernet devices but
only one MDIO bus on which the 2 related PHY are connected but at unique addresses."

Unfortunately that commit doesn't actually solve the problem where 2 Ethernet devices are connected to a single MDIO bus; it just adds support for setting the phy address.

I have no idea how to solve that in a clean way in qemu.

Guenter

author
#13 lore raw

Re: [PATCH v3 3/4] hw/arm: sabrelite: Connect the Ethernet PHY at address 6

In reply to Guenter Roeck
Quoted 54 lines · Guenter Roeck
Quoted 52 lines · Bin Meng
Quoted 36 lines · Guenter Roeck

Hi,

Quoted 18 lines · Bin Meng

From: Bin Meng <[email protected]>

At present, when booting U-Boot on QEMU sabrelite, we see:

Net: Board Net Initialization Failed
No ethernet found.

U-Boot scans PHY at address 4/5/6/7 (see board_eth_init() in the U-Boot source: board/boundary/nitrogen6x/nitrogen6x.c). On the real board, the Ethernet PHY is at address 6. Adjust this by updating the "fec-phy-num" property of the fsl_imx6 SoC object.

With this change, U-Boot sees the PHY but complains MAC address:

Net: using phy at 6
FEC [PRIME]
Error: FEC address not set.

Quoted 7 lines

This is due to U-Boot tries to read the MAC address from the fuse, which QEMU does not have any valid content filled in. However this does not prevent the Ethernet from working in QEMU. We just need to set up the MAC address later in the U-Boot command shell, by:

=> setenv ethaddr 00:11:22:33:44:55

With this patch in place, the standard Ethernet interface no longer works when booting sabrelite Linux images directly (without u-boot) using the following qemu command.
qemu-system-arm -M sabrelite -kernel arch/arm/boot/zImage
...

Quoted 5 lines

The Ethernet interface still instantiates, but packet transfer to the host no longer works. Reverting this patch fixes the problem for me.

Is there a qemu command line parameter that is now necessary to instantiate the Ethernet interface when booting Linux ?

Enabling "guest_errors" shows that Linux kernel fec driver is trying to read PHY at address 0, which is not what we want.

[imx.fec.phy]imx_phy_read: Bad phy num 0

The device tree blob of the sabrelite does not contain a node for the ethernet phy specifying phy address, so I suspect Linux kernel driver is using default phy address 0 instead.

Quoted 6 lines
Quoted 2 lines

Could you please test on a real hardware to see what happens?

The problem is that qemu returns 0 when the OS tries to read from a non-existing PHY. Linux expects it to return 0xffff, and believes that a PHY is there if 0 is returned. This helps:

Good catch! Please send a patch for this.

Quoted 13 lines
hw/net/imx_fec.c +1 -1
index f03450c028..3c90c38e26 100644
@@ -285,7 +285,7 @@ static uint32_t imx_phy_read(IMXFECState *s, int reg)
     if (phy != s->phy_num) {
         qemu_log_mask(LOG_GUEST_ERROR, "[%s.phy]%s: Bad phy num %u\n",
                       TYPE_IMX_FEC, __func__, phy);
-        return 0;
+        return 0xffff;
     }
 
Quoted 2 lines

Note that this is not really a guest error; any OS can and likely will scan the MII bus for connected phy chips.

Agree.

Regards,
Bin

author
#14 lore raw

PATCH v3 4/4 docs/system: arm: Add sabrelite board description

In reply to Bin Meng

From: Bin Meng <[email protected]>

This adds the target guide for SABRE Lite board, and documents how to boot a Linux kernel and U-Boot bootloader.

---

Changes in v3:
- correct 2 typos in sabrelite.rst

Changes in v2:
- new patch: add sabrelite target guide

 docs/system/arm/sabrelite.rst | 119 ++++++++++++++++++++++++++++++++++
 docs/system/target-arm.rst    |   1 +
 2 files changed, 120 insertions(+)
 create mode 100644 docs/system/arm/sabrelite.rst
docs/system/arm/sabrelite.rst new file +119 -0
new file mode 100644
index 0000000000..71713310e3
@@ -0,0 +1,119 @@
+Boundary Devices SABRE Lite (``sabrelite``)
+===========================================
+
+Boundary Devices SABRE Lite i.MX6 Development Board is a low-cost development
+platform featuring the powerful Freescale / NXP Semiconductor's i.MX 6 Quad
+Applications Processor.
+
+Supported devices
+-----------------
+
+The SABRE Lite machine supports the following devices:
+
+ * Up to 4 Cortex A9 cores
+ * Generic Interrupt Controller
+ * 1 Clock Controller Module
+ * 1 System Reset Controller
+ * 5 UARTs
+ * 2 EPIC timers
+ * 1 GPT timer
+ * 2 Watchdog timers
+ * 1 FEC Ethernet controller
+ * 3 I2C controllers
+ * 7 GPIO controllers
+ * 4 SDHC storage controllers
+ * 4 USB 2.0 host controllers
+ * 5 ECSPI controllers
+ * 1 SST 25VF016B flash
+
+Please note above list is a complete superset the QEMU SABRE Lite machine can
+support. For a normal use case, a device tree blob that represents a real world
+SABRE Lite board, only exposes a subset of devices to the guest software.
+
+Boot options
+------------
+
+The SABRE Lite machine can start using the standard -kernel functionality
+for loading a Linux kernel, U-Boot bootloader or ELF executable.
+
+Running Linux kernel
+--------------------
+
+Linux mainline v5.10 release is tested at the time of writing. To build a Linux
+mainline kernel that can be booted by the SABRE Lite machine, simply configure
+the kernel using the imx_v6_v7_defconfig configuration:
+
+.. code-block:: bash
+
+  $ export ARCH=arm
+  $ export CROSS_COMPILE=arm-linux-gnueabihf-
+  $ make imx_v6_v7_defconfig
+  $ make
+
+To boot the newly built Linux kernel in QEMU with the SABRE Lite machine, use:
+
+.. code-block:: bash
+
+  $ qemu-system-arm -M sabrelite -smp 4 -m 1G \
+      -display none -serial null -serial stdio \
+      -kernel arch/arm/boot/zImage \
+      -dtb arch/arm/boot/dts/imx6q-sabrelite.dtb \
+      -initrd /path/to/rootfs.ext4 \
+      -append "root=/dev/ram"
+
+Running U-Boot
+--------------
+
+U-Boot mainline v2020.10 release is tested at the time of writing. To build a
+U-Boot mainline bootloader that can be booted by the SABRE Lite machine, use
+the mx6qsabrelite_defconfig with similar commands as described above for Linux:
+
+.. code-block:: bash
+
+  $ export CROSS_COMPILE=arm-linux-gnueabihf-
+  $ make mx6qsabrelite_defconfig
+
+Note we need to adjust settings by:
+
+.. code-block:: bash
+
+  $ make menuconfig
+
+then manually select the following configuration in U-Boot:
+
+  Device Tree Control > Provider of DTB for DT Control > Embedded DTB
+
+To start U-Boot using the SABRE Lite machine, provide the u-boot binary to
+the -kernel argument, along with an SD card image with rootfs:
+
+.. code-block:: bash
+
+  $ qemu-system-arm -M sabrelite -smp 4 -m 1G \
+      -display none -serial null -serial stdio \
+      -kernel u-boot
+
+The following example shows booting Linux kernel from dhcp, and uses the
+rootfs on an SD card. This requires some additional command line parameters
+for QEMU:
+
+.. code-block:: none
+
+  -nic user,tftp=/path/to/kernel/zImage \
+  -drive file=sdcard.img,id=rootfs -device sd-card,drive=rootfs
+
+The directory for the built-in TFTP server should also contain the device tree
+blob of the SABRE Lite board. The sample SD card image was populated with the
+root file system with one single partition. You may adjust the kernel "root="
+boot parameter accordingly.
+
+After U-Boot boots, type the following commands in the U-Boot command shell to
+boot the Linux kernel:
+
+.. code-block:: none
+
+  => setenv ethaddr 00:11:22:33:44:55
+  => setenv bootfile zImage
+  => dhcp
+  => tftpboot 14000000 imx6q-sabrelite.dtb
+  => setenv bootargs root=/dev/mmcblk3p1
+  => bootz 12000000 - 14000000
docs/system/target-arm.rst +1 -0
index bde4b8e044..edd013c7bb 100644
@@ -83,6 +83,7 @@ undocumented; you can get a complete list by running
    arm/versatile
    arm/vexpress
    arm/aspeed
+   arm/sabrelite
    arm/digic
    arm/musicpal
    arm/gumstix
Signature · 1 line
2.25.1
#15 lore raw
In reply to Bin Meng
Quoted 15 lines · Bin Meng

From: Bin Meng <[email protected]>

At present the upstream U-Boot (as of today, v2021.01-rc3) does not boot on QEMU sabrelite machine.

This fixes several issues to improve emulation fidelity of the i.MX6 sabrelite board. With this series, upstream U-Boot can boot to U-Boot command shell. While we are here, add a target guide for this board to help people run Linux kernel and U-Boot on QEMU.

Changes in v3:
- correct 2 typos in sabrelite.rst

Quoted 8 lines

Changes in v2:
- new patch: add sabrelite target guide

Bin Meng (4):
hw/misc: imx6_ccm: Update PMU_MISC0 reset value hw/msic: imx6_ccm: Correct register value for silicon type hw/arm: sabrelite: Connect the Ethernet PHY at address 6 docs/system: arm: Add sabrelite board description

Applied to target-arm.next, thanks.

-- PMM