VIM3 M2X PoE Ethernet Support

Khadas VIM3, M2X, CoreELEC 9.2.7 (Krescue image on eMMC)

Hello!

I’m trying to enable second ethernet port on M2X extension. For linux it requires additional device tree overlay at /boot/env.txt, but obviously, it`s not available in CoreELEC.

I’ve dumped and decompiled separate m2x-eth.dtbo available in my porevious Ubuntu setup at /boot/dtb/overlays/kvim3, with dtc -I dtb -O dts m2x-eth.dtbo -o m2x-eth.dts and got device tree souce:

/dts-v1/;

/ {

	fragment@0 {
		target = <0xffffffff>;

		__overlay__ {
			status = "okay";
			mc_val = <0x4be04>;
			internal_phy = <0x01>;
		};
	};

	__fixups__ {
		ethmac = "/fragment@0:target:0";
	};
};

After that I was trying to merge it with CoreELEC Device Tree Blob from /dev/dtb. After dumping with dd if=/dev/dtb of=~/default.dtb bs=256k and decompiling it with dtc -I dts -O dtb default_m2x.dts -o default_m2x.dtb I’ve found this part of config:

...

ethernet@ff3f0000 {
		compatible = "amlogic, g12a-eth-dwmac\0snps,dwmac";
		reg = <0x00 0xff3f0000 0x00 0x10000 0x00 0xff634540 0x00 0x08 0x00 0xff64c000 0x00 0xa0>;
		reg-names = "eth_base\0eth_cfg\0eth_pll";
		interrupts = <0x00 0x08 0x01>;
		interrupt-names = "macirq";
		status = "okay";
		clocks = <0x02 0x38>;
		clock-names = "ethclk81";
		pll_val = <0x9c0040a 0x927e0000 0xac5f49e5>;
		analog_val = <0x20200000 0xc000 0x23>;
		pinctrl-names = "external_eth_pins";
		pinctrl-0 = <0x18>;
		mc_val = <0x1621>;
		internal_phy = <0x00>;
		phandle = <0x92>;
	};

...

I’ve checked DTS syntax, added new label, edited overlay fragment and added it after __symbols__ section:

	...

	eth: ethernet@ff3f0000 { ... };

	...

	__symbols__ { ... };

	...

	fragment@0 {
		target = <&eth>;

		__overlay__ {
			status = "okay";
			mc_val = <0x4be04>;
			internal_phy = <0x01>;
		};
	};

	__fixups__ {
		ethmac = "/fragment@0:target:0";
	};
...

Then I’ve compiled everything it with dtc -I dts -O dtb default_m2x.dts -o default_m2x.dtb, uploaded to CoreELEC /storage and written back to /dev/dtb with dd.

After reboot, nothing happened, first Ethernet port was still working second port was still not. Ive checked /dev/dtb` dupm source again and found that overlay fix was still present.

Later I’ve found a script at /flash/boot.ini which was loading /flash/dtb.img and other device tree blobs with fatload one by one on every boot. I’ve looked it up, and found that fatload could also load Device Tree Blob Overlays. I’m not that good at bash, so I do not know hot to edit boot.ini correctly.

@hyphop suggested to build CoreELEC from source, but I do not now hot to build it with overlay. My goal for now is to use M2X eternet port for network (even if without main port) and Im lookig for a way to enable it on installed CoreELEC.

Questions:

  1. Am I doing it correctly or what am I doing wrong?
  2. Is it possible to add this overlay into already installed CoreELEC setup?
  3. Is it better for me to merge m2x-eth.dtbo sorce with general g12b_a311d_khadas_vim3.dtb source and reinstall? If so, how do I put correct target label or path in overlay fragment?
  4. Do I have to build ny own version of CoreELEC from source and how to do it with needed device tree overlay?
  5. Is it possible for CoreELEC team to add support of M2X extension Ethernet port to main repo? I could help to test and debug it.

Thanks in advance.

You should edit file /flash/dtb.img.

Do you have VIM3 or VIM3L?

VIM3.

I’ve tried, but /flash/dtb.img is read only, how to replace it with recompiled version? (CoreELEC on eMMC)

Then /dev/dtb is not something you should touch.

To enable writing in /flash

mount -o remount,rw /flash

and to put bck into read only mode

mount -o remount,ro /flash
1 Like

Thanks for advise!

So

  • I dumped /flash/dtb.img into flash.dtb with dd
  • decompiled it with dtc -I dts -O dtb flash.dts -o flash.dtb
  • added label eth to ethernet@ff3f0000 node as before
  • added overlay fragment with target = <&eth> and __fixups__ after __symbols__ block as before
  • compiled everithing back to flash_m2x.dtb
  • remounted /flash with right permissions
  • wrote .dtb with dd to /flash/dtb.img
  • remounted /flash back with readonly permissions
  • restarted

and still got nothing. M2X ethernet port isn’t working, while main port is working fine. I’ve also tried to remove cable while rebooting, and put it in M2X port before starting VIM. That’ve not helped :frowning:

Those instructions for decompile and compile looks strange.
I do

cd /storage/downloads
# decompile
dtc -I dtb -O dts /flash/dtb.img -o source.dts
# edit source.dts
# compile back
mount -o remount,rw /flash
dtc -I dts -O dtb source.dts -o /flash/dtb.img
reboot

Where can I download ubuntu or something else with this overlay enabled?

I’ve installed Ubuntu via Krescue, I’ve used `VIM3_Ubuntu-minimal-focal_Linux-4.9_arm64_EMMC_V0.9.6-201117.raw.img.xz

Keep in mind, overlay is present in system, but disabled by default. You’ll have to enable it in /boot/env.txt, additional info here.

I can’t extract this krescue image.

Can you provide original dtb and dtbo from this image?

I can’t upload files here, cause just signed up, but here is link to m2x-eth.dtbo Filebin

You also asked for original dtb, you mean CoreELEC /flash/dtb.img or full dtb from Ubuntu?

Also you can try extract any VIM3 Ubuntu SD-USB image from those repo, I’m sure they have this overlay too.

I tried 3 images and I saw no overlay.

And I need dtb from ubuntu. To see see the difference with CE dtb.

Extracted from my eMMC Ubuntu 20 setup with dtc -I fs -O dts|dtb /sys/firmware/devicetree/base: filebin

checked source and there is no overlay fragments, source of ethernet node just have config which is listed in m2x-eth.dtbo:

mc_val = <0x4be04>;
internal_phy = <0x01>;

and also there are no __symbols__ section compared to CoreELEC dts

Forget anything overlay specific: our kernel doesn’t support that.
That’s why you need to change 2 values above (mc_val and internal_phy) in node ethernet@ff3f0000 itself in coreelec dts.

1 Like

Thanks, it worked!

Excellent!

Now interesting, how to save this config while updating? And is it possible to add VIM3 M2X specific setting in Hardware => Device Tree section?

Now I have to rewrite /flash/dtb.img every time I update CoreELEC…

Can you try changing only internal_phy ? And leave mc_val with the default value from CE dtb.

So, after reverting mc_val to default and rebooting device lost connection on M2X ethernet port. It has self-assigned IP without any gateway address.

Here are logs ix.io/2W2L

P.S. Returned custom mc_val value.

1 Like

Can you try this image: 225.38 MB file on MEGA

Btw: you can download directly to your device

cd /storage/.update/
megadl https://mega.nz/file/..............
reboot

In CE settings you will see option to select ethernet to PCIe. After reboot it should be active.

1 Like

Updated to your branch, changed to PCIe, it works after reboot.

Besides, there is a huge time gap between applying setting and reboot notification. Its not clear for user that there is dtb rewrite is happening, and UI is lagging if you try to navigate it simultaniosly with update.

I think its better to show a loader, if possible, while changes are applied

About | FAQ | Terms of Service | Privacy Policy | Legal Notice