Skip to contentSkip to conversation

rockchip: board: assign up to 3 static Ethernet MAC addresses

PATCH In review MichaIng 3 participants 11 messages Jun 8, 2025 – Sep 13, 2025 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore

MichaIng

author
#0 lore raw

PATCH 1/1 rockchip: board: assign up to 3 static Ethernet MAC addresses

Some SBCs with Rockchip SoC provide 3 Ethernet ports, like the FriendlyELEC NanoPi R5S and NanoPi R6S. U-Boot assigns already eth*addr variables to ethernet* device tree node aliases, but for Rockchip boards, it generates only ethaddr and eth1addr so far.

To allow the assignment of 3 static MAC addresses, with this change, eth2addr is generated with a logic similar to how eth1addr is generated already:
- eth1addr is currently derived from ethaddr by inverting the last bit, which raises or decreases the last hex digit of the MAC address by one.
- Hereby, the eth2addr is derived from the value assigned to eth1addr, by inverting the last 2 bits. Hence, differs from the first ethaddr by an inverted second last bit, which raises or decreases the last hex digit of the MAC address by two. This assures a valid MAC address assigned to eth2addr, which always differs from ethaddr and eth1addr.

The change has been successfully tested on the NanoPi R5S and NanoPi R6S: With ethernet[0-2] device tree aliases (correctly) defined, both boards get 3 static MAC addresses.

---
 arch/arm/mach-rockchip/board.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/arm/mach-rockchip/board.c +4 -0
index 75d6693e28a..6b0d5715f5c 100644
@@ -357,6 +357,10 @@ int rockchip_setup_macaddr(void)
        /* Make a valid MAC address for ethernet1 */
        mac_addr[5] ^= 0x01;
        eth_env_set_enetaddr("eth1addr", mac_addr);
+
+       /* Make a valid MAC address for ethernet2 */
+       mac_addr[5] ^= 0x03;
+       eth_env_set_enetaddr("eth2addr", mac_addr);
 #endif
        return 0;
 }

--
2.47.2

Reviewed-by on v1 1/1
#1 lore raw

Hi MichaIng,

Quoted 18 lines · MichaIng

[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

Some SBCs with Rockchip SoC provide 3 Ethernet ports, like the FriendlyELEC NanoPi R5S and NanoPi R6S. U-Boot assigns already eth*addr variables to ethernet* device tree node aliases, but for Rockchip boards, it generates only ethaddr and eth1addr so far.

To allow the assignment of 3 static MAC addresses, with this change, eth2addr is generated with a logic similar to how eth1addr is generated already:
- eth1addr is currently derived from ethaddr by inverting the last bit, which raises or decreases the last hex digit of the MAC address by one.
- Hereby, the eth2addr is derived from the value assigned to eth1addr, by inverting the last 2 bits. Hence, differs from the first ethaddr by an inverted second last bit, which raises or decreases the last hex digit of the MAC address by two. This assures a valid MAC address assigned to eth2addr, which always differs from ethaddr and eth1addr.

Quoted 4 lines

The change has been successfully tested on the NanoPi R5S and NanoPi
R6S: With ethernet[0-2] device tree aliases (correctly) defined, both boards get 3 static MAC addresses.

What's the number when we'll decide this is too many? I have a board with 5 Ethernet ports for example :)

You could set the eth2addr in your board file if you wanted instead of setting it for everybody.

I don't know how far we want to go to avoid defining unused ethXaddr variables in the environment? We could use of_alias_get_highest_id for example and generate enough environment variables based on that info?

The change looks ok though, so:

Thanks!
Quentin

author
#2 lore raw

Hi Quentin,

thanks for the review!

Quoted 2 lines

You could set the eth2addr in your board file if you wanted instead of setting it for everybody.

We provide OS images for everyone, and our users complained about the changing MAC addresses. I agree with them that generally the exception is that MAC addresses are static by default, and randomising them being an optional privacy feature when connecting to untrusted networks, like a WiFi hotspot with a mobile phone. Setting eth2addr in boot script/environment would require a random MAC address generation our end on first boot or so on each system, to rule out collisions. Since U-Boot has the feature implemented already, it just makes sense to make use of it and extend it for the affected Rockchip builds, also to have the somewhat nicely aligned with the last digit deferring only. So we currently patch our sources.

Quoted 2 lines

What's the number when we'll decide this is too many? I have a board with 5 Ethernet ports for example :)

Good question. In Germany we say "Aller guten Dinge sind drei" (All good things come in threes). Jokes aside: not sure whether there are Rockchip SoC boards which provide more Ethernet NICs, but I have 3 with 3 ones (in one case provided by an official expansion board), all RK3588 with two onboard PCIe adapters. There is another PCIe bus, but commonly used for an M.2 socket, not sure whether it could theoretically provide a 4th Ethernet adapter. I don't know the background about why the Ethernet driver/firmware is not able to read/assign the hardware MAC, or why there is no hardware MAC, as I understand that this is an IEEE requirement. So what U-Boot does seems a workaround, and I agree that, if there is no generic approach, it has limits.

Quoted 3 lines

I don't know how far we want to go to avoid defining unused ethXaddr variables in the environment? We could use of_alias_get_highest_id for example and generate enough environment variables based on that info?

This sounds reasonable. But are ethXaddr variables not generated before boot scripts are called, when the number of alias IDs cannot be known yet, and MAC addresses assigned afterwards, when the OS device tree was loaded? When generating the variables afterwards, all good, but then existing values assigned by boot script/env should not be overwritten, of course. Then a generic approach would be possible, incrementing the bit mask by one each loop, to assign up to a quite large number of MAC addresses to ethernet aliases.

Best regards,

Micha (aka MichaIng)
DietPi project lead

#3 lore raw

Hi Micha,

Quoted 9 lines · MichaIng

[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

Hi Quentin,

thanks for the review!

Quoted 2 lines

You could set the eth2addr in your board file if you wanted instead of setting it for everybody.

Quoted 7 lines

We provide OS images for everyone, and our users complained about the changing MAC addresses. I agree with them that generally the exception is that MAC addresses are static by default, and randomising them being an optional privacy feature when connecting to untrusted networks, like a WiFi hotspot with a mobile phone. Setting eth2addr in boot script/environment would require a random MAC address generation our end on first boot or so on each system, to rule out collisions. Since U-Boot

I didn't mean to suggest to have this as part of the boot script. Board file (for me) is any file in the board/ directory which applies to a board. See board/theobroma-systems/ringneck_px30 for example.

There you could replace misc_init_r entirely, or define your own rockchip_early_misc_init_r (like I do in board/theobroma-systems/ringneck_px30/ringneck-px30.c for example) or add a rockchip_late_misc_init_r callback after the ethernet addresses if you want?

That's what I was suggesting essentially.

Quoted 5 lines

has the feature implemented already, it just makes sense to make use of it and extend it for the affected Rockchip builds, also to have the somewhat nicely aligned with the last digit deferring only. So we currently patch our sources.

That's fair. The point is I'm not sure it makes sense to have X ethXaddr variables with X being the highest possible amount of Ethernet devices one can find on a Rockchip device.

Quoted 15 lines
Quoted 2 lines

What's the number when we'll decide this is too many? I have a board with 5 Ethernet ports for example :)

Good question. In Germany we say "Aller guten Dinge sind drei" (All good things come in threes). Jokes aside: not sure whether there are Rockchip SoC boards which provide more Ethernet NICs, but I have 3 with 3 ones (in one case provided by an official expansion board), all RK3588 with two onboard PCIe adapters. There is another PCIe bus, but commonly used for an M.2 socket, not sure whether it could theoretically provide a 4th Ethernet adapter. I don't know the background about why the Ethernet driver/firmware is not able to read/assign the hardware MAC, or why there is no hardware MAC, as I understand that this is an IEEE requirement. So what U-Boot does seems a workaround, and I agree that, if there is no generic approach, it has limits.

Quoted 8 lines
Quoted 3 lines

I don't know how far we want to go to avoid defining unused ethXaddr variables in the environment? We could use of_alias_get_highest_id for example and generate enough environment variables based on that info?

This sounds reasonable. But are ethXaddr variables not generated before boot scripts are called, when the number of alias IDs cannot be known yet, and MAC addresses assigned afterwards, when the OS device tree was loaded? When generating the variables afterwards, all good, but then

I assume you should have a Device Tree in U-Boot, on Rockchip it's typically available in U-Boot SPL already (except on some TPL-less or SPL-extremly-size-limited configurations) so you can do that based on the aliases found in the U-Boot device tree.

Then you can also do additional fdt fixups on the kernel DT before booting the kernel if that is something you're worried about (U-Boot DT being different from kernel DT for example). There you could read the aliases node and generate a mac address for all controllers that do not already have one in the environment for example.

You likely need both, first one for consistent network support (MAC address) in U-Boot and the second one in case the kernel DT differs from the U-Boot DT (in terms of amount of Ethernet controllers for example). E.g. you could have an overlay for an adapter board that has multiple Ethernet ports each with their own MAC address. You don't necessarily need those enabled in U-Boot so the base DTB would be enough, but you for sure want all of them enabled in the kernel).

Cheers,
Quentin

A message that is not in the archive (sent off-list or not yet received): [email protected]

#5 lore raw

Hi Micha,

Please keep the ML in Cc.

Quoted 12 lines · MichaIng

Hi Quentin,

Quoted 10 lines

I didn't mean to suggest to have this as part of the boot script. Board file (for me) is any file in the board/ directory which applies to a board. See board/theobroma-systems/ringneck_px30 for example.

There you could replace misc_init_r entirely, or define your own rockchip_early_misc_init_r (like I do in board/theobroma-systems/ ringneck_px30/ringneck-px30.c for example) or add a rockchip_late_misc_init_r callback after the ethernet addresses if you want?

Quoted 3 lines
Quoted 1 line

That's what I was suggesting essentially.

Ah I see. Since it affects 3 different Rockchip boards relevant for me/ us, potentially more, doing it for all Rockchip boards seems reasonable,

We currently have 137 defconfigs for Rockchip boards (git grep -l ARCH_ROCKCHIP configs/ | wc -l), so not sure 3 is a reasonable threshold :)

Quoted 1 line

at least less code in one place. I will probably start to work on the Orange Pi R2S soon, a RISC-V board with 4 Ethernet adapters, which will most likely have random MAC addresses as well. So actually I would vote for a more generic solution which works the same way on all hardware. I

I am not too fond of how we handle the random MAC addresses in Rockchip either, we should be able to make this more generic indeed.

Now I see a possible issue in that. I believe the random MAC addresses are constant across reboots for a given board since it's based on the CPU ID. I am assuming we should be keeping this stable if we make the thing more generic. Sunxi seems to be setting the first byte of the MAC address depending on the ethernet controller index. Rockchip seems to be XOR'ing the last bit of the last byte (and you were looking into extending this to the 2LSB of the last byte for up to 4 addresses). So we already have different expectations of how the random MAC addresses need to be computed.

We could have a generic implementation that is overridable for boards/vendors or architectures (e.g. via weak symbols for example).

Quoted 4 lines

see the argument to not bloat the environment with often unused variables, so makes sense to generate those MAC addresses on demand only.

As you mention misc_init_r, I see sunxi boards override/use it to do it more that way: check for aliases ethernet0-4 in a loop, and generate an eth*addr variable only if the alias exist, and the variable does not: https://eur02.safelinks.protection.outlook.com/? url=https%3A%2F%2Fgithub.com%2Fu-boot%2Fu- boot%2Fblob%2Fmaster%2Fboard%2Fsunxi%2Fboard.c%23L776- L795&data=05%7C02%7Cquentin.schulz%40cherry.de%7C464204d1dfa844099a4208ddae0443dc%7C5e0e1b5221b54e7b83bb514ec460677e%7C0%7C0%7C638858055555459309%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=%2FD%2Fr88eFxZY%2Bf%2FMafL6AftJVswiA4uVClC1Hqn3xM1M%3D&reserved=0 But since it generates variables, I assume it is called before boot scripts and hence is based on the ethernet* aliases defined in U-Boot's device tree, rather than the kernel device tree, right? I mean I aim to

Yes. Remember that some boards do use U-Boot DTB as kernel DTB as well, so it's not that easy of a shortcut for everything supported by U-Boot.

Quoted 2 lines

send Linux patches to add those to respective device trees as well, if/ once this U-Boot patch gets merged, and those might be synced back into U-Boot device trees. But since this is all done on/for the kernel device tree, I would prefer it to depend on kernel dtb aliases only.

Not sure to understand what you want to do here or what's the issue sorry.

You need also eth*addr for use in U-Boot (if you do PXE, TFTP, ping, whatever involving networking) so it makes sense to have them in U-Boot DT as well.

You can anticipate ethernet aliases being in DT of future Linux kernel releases by adding a temporary -u-boot.dtsi with a few properties in /chosen/aliases matching the ones in the Linux kernel. Once synced you can remove them. Note that obviously unless your system uses the exact same binary for U-Boot DTB and kernel DTB, you cannot guarantee that the aliases will point to the same controllers for example, so ethernet2 in U-Boot may point to ethernet1 in kernel for example, in which case MAC addresses may all get swapped between U-Boot and kernel. This is theoretically possible, not sure how likely it is to happen though.

Quoted 3 lines

Wouldn't it be possible to generate and generate and apply the MAC addresses [here](https://eur02.safelinks.protection.outlook.com/? url=https%3A%2F%2Fgithub.com%2Fu-boot%2Fu- boot%2Fblob%2Fmaster%2Fboot%2Ffdt_support.c%23L645- L664&data=05%7C02%7Cquentin.schulz%40cherry.de%7C464204d1dfa844099a4208ddae0443dc%7C5e0e1b5221b54e7b83bb514ec460677e%7C0%7C0%7C638858055555480725%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=zes5ZQmR4du9dygIIf6HLT2cVO5yWR2b5dwbaLzpWDA%3D&reserved=0), hence for all actually existing aliases, and only as fallback if the respective eth*addr variable is not set? If the method for obtaining the first ethaddr differs between boards, it could still rely on an existing ethaddr variable, to derive different MAC addresses for each ethernet* alias index in a consistent way.

I guess. I would rather have a fallback whenever env_get(mac) doesn't return successfully, in which case you can attempt to generate one randomly based on some callback. This would cover the case when you have a kernel DT with etherent aliases not present in U-Boot DT, this is reasonable for boards with adapters covered by Device Tree Overlays for example, which don't need to necessarily be applied on U-Boot DTB.

Cheers,
Quentin

author
#6 lore raw

Hi Quentin,

Quoted 1 line

Please keep the ML in Cc.

Was too late for me yesterday :).

Quoted 2 lines

We currently have 137 defconfigs for Rockchip boards (git grep -l ARCH_ROCKCHIP configs/ | wc -l), so not sure 3 is a reasonable threshold :)

I mean just for us/me, coding efforts and maintaining a patch, it is easier to do it right there, where it is done right now for ethaddr and eth1addr already for all Rockchip boards, instead of creating overrides for 3 particular boards. I hope an additional eth2addr is fine for now, until we found a better/more generic solution.

Quoted 10 lines

Now I see a possible issue in that. I believe the random MAC addresses are constant across reboots for a given board since it's based on the CPU ID. I am assuming we should be keeping this stable if we make the thing more generic. Sunxi seems to be setting the first byte of the MAC address depending on the ethernet controller index. Rockchip seems to be XOR'ing the last bit of the last byte (and you were looking into extending this to the 2LSB of the last byte for up to 4 addresses). So we already have different expectations of how the random MAC addresses need to be computed.

Quoted 2 lines

We could have a generic implementation that is overridable for boards/ vendors or architectures (e.g. via weak symbols for example).

Yes, whatever we do, it should be a non-breaking addition, at last for now, just generating those MAC addresses for existing ethernet* aliases, which have no related variable assigned yet. And seeing the different approaches on getting the first/initial ethaddr to derive further ones from, I think a new generic method needs to work on top of an existing ethaddr variable, generated in current board-specific way, or defined in boot env/script.

I also wondered about sunxi adjusting the first byte. Since the first block contains also unicast/multicast bit etc, I would always prefer varying addresses from the back, so the same method can theoretically be continued for a lot more MAC addresses, before running into bits we must not change. We can assign already 16 MAC addresses with the last xdigit only, when incrementing the bitwise mask by 1 each iteration, and apply it on the original ethaddr each time? And as far as I can think about it, incrementing it further to span the second last xdigit, hence the whole last MAC address block, would work just the same way, able to handle ethernet0 - ethernet255, theoretically.

Quoted 5 lines

Not sure to understand what you want to do here or what's the issue sorry.

You need also eth*addr for use in U-Boot (if you do PXE, TFTP, ping, whatever involving networking) so it makes sense to have them in U-Boot DT as well.

U-Boot assigns those variables to ethernet aliases on its own device tree as well? Would be reasonable, but for me this is minor. At least I did not hear from a case where someone was complaining about a random MAC address for network boot.

What I aim for is U-Boot assigning static MAC addresses to ethernet aliases defined in/for the kernel device tree, better in a more generic than specific way, so it does not need to be changed again each time a new SBC (with new SoC) with multiple onboard Ethernet adapters arrives. Adding the aliases to the kernel device tree is then a different topic, not related to U-Boot, which I however aim to achieve upstream as well. If U-Boot syncs these back, it allows static MAC addresses for related adapters in U-Boot phase as well, of course.

Quoted 3 lines

U-Boot may point to ethernet1 in kernel for example, in which case MAC addresses may all get swapped between U-Boot and kernel. This is theoretically possible, not sure how likely it is to happen though.

That could happpen already now with the often at least 2 aliases defined. I wonder whether it can cause issues with PXE boot etc. In the cases I know, a dedicated dtb is shipped as well, and I am not even sure whether the network connection remains the same between U-Boot phase and kernel phase? In any case, as long as any new generic MAC assignment does not overwrite existing eth*addr variables, and does not generate new/different MAC addresses for ethernet* aliases which have a related eth*addr variable, it should not be able to break anything, but only turns all those MAC addresses to static, which are otherwise random.

Best regards,

Micha (aka MichaIng)
DietPi project lead

Am 18.06.2025 um 11:49 schrieb Quentin Schulz:

Quoted 56 lines

Hi Micha,

Please keep the ML in Cc.

Quoted 14 lines · MichaIng

Hi Quentin,

 > I didn't mean to suggest to have this as part of the boot script. Board > file (for me) is any file in the board/ directory which applies to a > board. See board/theobroma-systems/ringneck_px30 for example. >
 > There you could replace misc_init_r entirely, or define your own > rockchip_early_misc_init_r (like I do in board/theobroma-systems/ > ringneck_px30/ringneck-px30.c for example) or add a
 > rockchip_late_misc_init_r callback after the ethernet addresses if you > want?
 >
 > That's what I was suggesting essentially.

Quoted 1 line

Ah I see. Since it affects 3 different Rockchip boards relevant for me/ us, potentially more, doing it for all Rockchip boards seems reasonable,

We currently have 137 defconfigs for Rockchip boards (git grep -l ARCH_ROCKCHIP configs/ | wc -l), so not sure 3 is a reasonable threshold :)

Quoted 1 line

at least less code in one place. I will probably start to work on the Orange Pi R2S soon, a RISC-V board with 4 Ethernet adapters, which will most likely have random MAC addresses as well. So actually I would vote for a more generic solution which works the same way on all hardware. I

I am not too fond of how we handle the random MAC addresses in Rockchip either, we should be able to make this more generic indeed.

Now I see a possible issue in that. I believe the random MAC addresses are constant across reboots for a given board since it's based on the CPU ID. I am assuming we should be keeping this stable if we make the thing more generic. Sunxi seems to be setting the first byte of the MAC address depending on the ethernet controller index. Rockchip seems to be XOR'ing the last bit of the last byte (and you were looking into extending this to the 2LSB of the last byte for up to 4 addresses). So we already have different expectations of how the random MAC addresses need to be computed.

We could have a generic implementation that is overridable for boards/ vendors or architectures (e.g. via weak symbols for example).

Quoted 4 lines

see the argument to not bloat the environment with often unused variables, so makes sense to generate those MAC addresses on demand only.

As you mention misc_init_r, I see sunxi boards override/use it to do it more that way: check for aliases ethernet0-4 in a loop, and generate an eth*addr variable only if the alias exist, and the variable does not: https://eur02.safelinks.protection.outlook.com/? url=https%3A%2F%2Fgithub.com%2Fu-boot%2Fu- boot%2Fblob%2Fmaster%2Fboard%2Fsunxi%2Fboard.c%23L776- L795&data=05%7C02%7Cquentin.schulz%40cherry.de%7C464204d1dfa844099a4208ddae0443dc%7C5e0e1b5221b54e7b83bb514ec460677e%7C0%7C0%7C638858055555459309%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=%2FD%2Fr88eFxZY%2Bf%2FMafL6AftJVswiA4uVClC1Hqn3xM1M%3D&reserved=0 But since it generates variables, I assume it is called before boot scripts and hence is based on the ethernet* aliases defined in U- Boot's device tree, rather than the kernel device tree, right? I mean I aim to

Yes. Remember that some boards do use U-Boot DTB as kernel DTB as well, so it's not that easy of a shortcut for everything supported by U-Boot.

Quoted 2 lines

send Linux patches to add those to respective device trees as well, if/ once this U-Boot patch gets merged, and those might be synced back into U-Boot device trees. But since this is all done on/for the kernel device tree, I would prefer it to depend on kernel dtb aliases only.

Not sure to understand what you want to do here or what's the issue sorry.

You need also eth*addr for use in U-Boot (if you do PXE, TFTP, ping, whatever involving networking) so it makes sense to have them in U-Boot DT as well.

You can anticipate ethernet aliases being in DT of future Linux kernel releases by adding a temporary -u-boot.dtsi with a few properties in / chosen/aliases matching the ones in the Linux kernel. Once synced you can remove them. Note that obviously unless your system uses the exact same binary for U-Boot DTB and kernel DTB, you cannot guarantee that the aliases will point to the same controllers for example, so ethernet2 in U-Boot may point to ethernet1 in kernel for example, in which case MAC addresses may all get swapped between U-Boot and kernel. This is theoretically possible, not sure how likely it is to happen though.

Quoted 3 lines

Wouldn't it be possible to generate and generate and apply the MAC addresses [here](https://eur02.safelinks.protection.outlook.com/? url=https%3A%2F%2Fgithub.com%2Fu-boot%2Fu- boot%2Fblob%2Fmaster%2Fboot%2Ffdt_support.c%23L645- L664&data=05%7C02%7Cquentin.schulz%40cherry.de%7C464204d1dfa844099a4208ddae0443dc%7C5e0e1b5221b54e7b83bb514ec460677e%7C0%7C0%7C638858055555480725%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=zes5ZQmR4du9dygIIf6HLT2cVO5yWR2b5dwbaLzpWDA%3D&reserved=0), hence for all actually existing aliases, and only as fallback if the respective eth*addr variable is not set? If the method for obtaining the first ethaddr differs between boards, it could still rely on an existing ethaddr variable, to derive different MAC addresses for each ethernet* alias index in a consistent way.

I guess. I would rather have a fallback whenever env_get(mac) doesn't return successfully, in which case you can attempt to generate one randomly based on some callback. This would cover the case when you have a kernel DT with etherent aliases not present in U-Boot DT, this is reasonable for boards with adapters covered by Device Tree Overlays for example, which don't need to necessarily be applied on U-Boot DTB.

Cheers,
Quentin

#7 lore raw

Hi Micha,

Quoted 4 lines · MichaIng

Hi Quentin,

Quoted 1 line

Please keep the ML in Cc.

Quoted 8 lines

Was too late for me yesterday :).

Quoted 2 lines

We currently have 137 defconfigs for Rockchip boards (git grep -l ARCH_ROCKCHIP configs/ | wc -l), so not sure 3 is a reasonable

threshold :)

I mean just for us/me, coding efforts and maintaining a patch, it is easier to do it right there, where it is done right now for ethaddr and eth1addr already for all Rockchip boards, instead of creating overrides for 3 particular boards. I hope an additional eth2addr is fine for now, until we found a better/more generic solution.

Up to Kever, no strong opinion on this.

[...]

Quoted 8 lines
Quoted 1 line

Not sure to understand what you want to do here or what's the issue

sorry.

Quoted 4 lines

You need also eth*addr for use in U-Boot (if you do PXE, TFTP, ping, whatever involving networking) so it makes sense to have them in U-Boot DT as well.

U-Boot assigns those variables to ethernet aliases on its own device tree as well? Would be reasonable, but for me this is minor. At least I

If DM_SEQ_ALIAS is enabled, I believe so.

Quoted 2 lines

did not hear from a case where someone was complaining about a random MAC address for network boot.

I would imagine people be surprised if the same device operates under two different MAC addresses depending on which SW is running at the moment (U-Boot or Linux for example).

Quoted 7 lines

What I aim for is U-Boot assigning static MAC addresses to ethernet aliases defined in/for the kernel device tree, better in a more generic than specific way, so it does not need to be changed again each time a new SBC (with new SoC) with multiple onboard Ethernet adapters arrives. Adding the aliases to the kernel device tree is then a different topic, not related to U-Boot, which I however aim to achieve upstream as well. If U-Boot syncs these back, it allows static MAC addresses for related adapters in U-Boot phase as well, of course.

Quoted 3 lines

U-Boot may point to ethernet1 in kernel for example, in which case MAC addresses may all get swapped between U-Boot and kernel. This is theoretically possible, not sure how likely it is to happen though.

That could happpen already now with the often at least 2 aliases defined. I wonder whether it can cause issues with PXE boot etc. In the cases I know, a dedicated dtb is shipped as well, and I am not even sure whether the network connection remains the same between U-Boot phase and kernel phase? In any case, as long as any new generic MAC assignment

I would assume the kernel to be reconfiguring the network stack while booting anyway, with renegotiation and all, but just a gut feeling, nothing to back this up.

To sum up, not much against this patch except that it's not ideal to add an environment variable most boards don't have a use for (but probably so is eth1addr :) ), and I think we would benefit from some generic implementation to set random Ethernet MAC addresses based on ethernet aliases in DT.

Cheers,
Quentin

#8 lore raw

Hi,

Quoted 19 lines · Quentin Schulz

Hi Micha,

Quoted 16 lines · MichaIng

Hi Quentin,

Quoted 1 line

Please keep the ML in Cc.

Was too late for me yesterday :).

Quoted 2 lines

We currently have 137 defconfigs for Rockchip boards (git grep -l ARCH_ROCKCHIP configs/ | wc -l), so not sure 3 is a reasonable

threshold :)

I mean just for us/me, coding efforts and maintaining a patch, it is easier to do it right there, where it is done right now for ethaddr and eth1addr already for all Rockchip boards, instead of creating overrides for 3 particular boards. I hope an additional eth2addr is fine for now, until we found a better/more generic solution.

I cannot find any rockchip board in U-Boot or Linux that currently use a ethernet2 alias, have you sent a Linux patch that I have missed?

The addition of eth1addr was done because there are and was in-tree boards that have use for both ethaddr and eth1addr.

Suggest you send a Linux patch that adds or updates a rockchip dts to include an ethernet2 alias before this is applied.

Quoted 48 lines

Up to Kever, no strong opinion on this.

[...]

Quoted 9 lines
Quoted 1 line

Not sure to understand what you want to do here or what's the issue

sorry.

Quoted 4 lines

You need also eth*addr for use in U-Boot (if you do PXE, TFTP, ping, whatever involving networking) so it makes sense to have them in U-Boot DT as well.

U-Boot assigns those variables to ethernet aliases on its own device tree as well? Would be reasonable, but for me this is minor. At least I

If DM_SEQ_ALIAS is enabled, I believe so.

Quoted 3 lines

did not hear from a case where someone was complaining about a random MAC address for network boot.

I would imagine people be surprised if the same device operates under two different MAC addresses depending on which SW is running at the moment (U-Boot or Linux for example).

Quoted 13 lines

What I aim for is U-Boot assigning static MAC addresses to ethernet aliases defined in/for the kernel device tree, better in a more generic than specific way, so it does not need to be changed again each time a new SBC (with new SoC) with multiple onboard Ethernet adapters arrives. Adding the aliases to the kernel device tree is then a different topic, not related to U-Boot, which I however aim to achieve upstream as well. If U-Boot syncs these back, it allows static MAC addresses for related adapters in U-Boot phase as well, of course.

Quoted 3 lines

U-Boot may point to ethernet1 in kernel for example, in which case MAC addresses may all get swapped between U-Boot and kernel. This is theoretically possible, not sure how likely it is to happen though.

Quoted 5 lines

That could happpen already now with the often at least 2 aliases defined. I wonder whether it can cause issues with PXE boot etc. In the cases I know, a dedicated dtb is shipped as well, and I am not even sure whether the network connection remains the same between U-Boot phase and kernel phase? In any case, as long as any new generic MAC assignment

I would assume the kernel to be reconfiguring the network stack while booting anyway, with renegotiation and all, but just a gut feeling, nothing to back this up.

Quoted 5 lines

To sum up, not much against this patch except that it's not ideal to add an environment variable most boards don't have a use for (but probably so is eth1addr :) ), and I think we would benefit from some generic implementation to set random Ethernet MAC addresses based on ethernet aliases in DT.

I fully agree, adding a new environment variable for all boards when there is currently no upstream use for it does not seem very practical and such proper solution should probably be worked on.

Regards,
Jonas

Quoted 3 lines

Cheers,
Quentin

author
#9 lore raw

Hi Jonas,

Quoted 8 lines

I cannot find any rockchip board in U-Boot or Linux that currently use a ethernet2 alias, have you sent a Linux patch that I have missed?

The addition of eth1addr was done because there are and was in-tree boards that have use for both ethaddr and eth1addr.

Suggest you send a Linux patch that adds or updates a rockchip dts to include an ethernet2 alias before this is applied.

sorry I missed your message that time. I thought about the chicken&egg issue with the aliases being defined in Linux and used in U-Boot, and chose to offer the patch for U-Boot first, since the aliases can be defined in Linux via device tree overlays, without touching sources and recompiling the kernel.

I will offer a patch to Linux then, hope the reaction is not similar there like "why should we define aliases which are not used by anything?" :)

Maybe this is the common order, and certainly has the benefit that you can sync the aliases back into U-Boot device trees, so those benefit from the same static MAC addresses, in case they are really applied to U-Boot device tree aliases as well.

I'll keep you updated regarding Linux patch.

Best regards,
Micha

author
#10 lore raw
In reply to Quentin Schulz

Hi Quentin,

many thanks for all your feedback and input.

Quoted 2 lines

If DM_SEQ_ALIAS is enabled, I believe so.
I would imagine people be surprised if the same device operates under two different MAC addresses depending on which SW is running at the moment (U-Boot or Linux for example).

So far I only found https://github.com/u-boot/u-boot/blob/master/boot/fdt_support.c#L645-L664, the fdt_fixup_ethernet() function, which, as far as I can see, is called after/with boot* commands. Ah, but if U-Boots device tree is used to boot, then of course it is applied there as well. What I meant is in bootloader stage before that, when it is about looping through boot media, and in case network boot options, searching for/executing boot.scr, in case U-Boot console.

In any case, I will wait for one more opinion/input about this, and are then happy to try implementing a more generic method: E.g. right into the above function, generating and directly applying MAC addresses to aliases which do not have a variable to apply from yet, based on an existing eth0?addr to start with.

Best regards,

Micha

#11 lore raw

Hi Micha,

Quoted 10 lines · MichaIng

Hi Quentin,

many thanks for all your feedback and input.

Quoted 2 lines

If DM_SEQ_ALIAS is enabled, I believe so.
I would imagine people be surprised if the same device operates under

two different MAC addresses depending on which SW is running at the moment (U-Boot or Linux for example).

So far I only found https://eur02.safelinks.protection.outlook.com/? url=https%3A%2F%2Fgithub.com%2Fu-boot%2Fu- boot%2Fblob%2Fmaster%2Fboot%2Ffdt_support.c%23L645- L664&data=05%7C02%7Cquentin.schulz%40cherry.de%7Cce3f16cb7ffc4282428c08ddb58ea1dd%7C5e0e1b5221b54e7b83bb514ec460677e%7C0%7C0%7C638866346409088334%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=QoEVV9ymbETho9Zaz%2F%2BD7NDTv3al4GiweS4BdEM9v5w%3D&reserved=0, the fdt_fixup_ethernet() function, which, as far as I can see, is called after/with boot* commands. Ah, but if U-Boots device tree is used to boot, then of course it is applied there as well. What I meant is in bootloader stage before that, when it is about looping through boot media, and in case network boot options, searching for/executing boot.scr, in case U-Boot console.

U-Boot code is sometimes much more convoluted than a quick grep :)

I don't remember the whole path I took but essentially it led me to look for enetaddr, net_enetaddr, eth_env_set_enetaddr, etc... which calls dev_seq() on the udevice, which returns dev->seq_, which is set (if DM_SEQ_ALIAS is enabled) by dev_read_alias_seq() when binding the driver.

Cheers,
Quentin