public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Tom Rini <trini@konsulko.com>
To: Michael Walle <michael@walle.cc>
Cc: u-boot@lists.denx.de
Subject: Re: [PATCH 10/10] board: sl28: disable random MAC address generation
Date: Wed, 17 Nov 2021 13:24:35 -0500	[thread overview]
Message-ID: <20211117182435.GC24579@bill-the-cat> (raw)
In-Reply-To: <e97dd0ab7729941514b1a8b61493a9d3@walle.cc>

[-- Attachment #1: Type: text/plain, Size: 5229 bytes --]

On Wed, Nov 17, 2021 at 05:45:58PM +0100, Michael Walle wrote:
> Am 2021-11-16 22:14, schrieb Tom Rini:
> > On Mon, Nov 15, 2021 at 11:45:51PM +0100, Michael Walle wrote:
> > 
> > > Nowadays, u-boot (when CONFIG_NET_RANDOM_ETHADDR is set) will set
> > > enetaddr to a random value if not set and then pass the randomly
> > > generated MAC address to linux.
> > 
> > First, for clarity I'm not nak'ing this.  I kind of would like to see a
> > slight reword as I think some things aren't 100% correct, even if the
> > "save random MAC to ethaddr environment variable" change goes in.  For
> > example, it's quite long standing that (dev|pdata)->enetaddr populates
> > "mac-address" and "local-mac-address" and it seems in some older cases
> > we only set the "local-mac-address" property.
> 
> fdt_fixup_memory() in common/fdt_support.c does a env_get(mac).

Whoops, yes, I misrecalled this.

> I'm not even sure, if there is a connection between what is fixed up
> in the kernel DT and the corresponding device in u-boot if
> CONFIG_DM_SEQ_ALIAS is not set.

And then yes, the logic here can be further fragile at times with
multiple interfaces.

> > > This is bad for the following reasons:
> > >  (1) it makes it impossible for linux to detect this error
> > >  (2) linux won't trigger any fallback mechanism for the case where
> > >      it didn't find any valid MAC address
> > 
> > This feels in some ways to be a limitation of the binding:
> > https://www.kernel.org/doc/Documentation/devicetree/bindings/net/ethernet-controller.yaml
> 
> Agreed. But it doesn't render my argument invalid ;)

"Bug" or "feature", but yes, OK.

> > And it reads like we really must be populating "mac-address" with that
> > random one and while providing a blank "local-mac-address" would be a
> > way to say we don't know the true device one, it seems that wouldn't be
> > used / noticed?
> 
> I guess it will just use the one populated in mac-address, i.e. the
> random one. Btw, the binding says "last used" what if u-boot never
> actually used that ethernet controller, should it then be empty or
> populated with the random mac address.

My gut feeling here is that we have an example of a binding that has
been formalized around what exists in the wild, and was not strictly
intentional and clear at all times.  What we do today in the case of
ethernet devices we haven't used is populate both, just like the one we
have used, based on the environment.  And popping over to current Linux
kernel git, the handful of boards that hard-code a non-zero mac-address
or local-mac-address in the dts just makes things even less-clear on
what to do.  Which probably leaves us with "populate mac-address with
whatever you can".

> > >  (3) a saveenv will store this randomly generated MAC address in the
> > >      environment
> > > 
> > > Probably, the user will also be unaware that something is wrong. He
> > > will
> > > just get different MAC addresses on each reboot, asking himself why
> > > this
> > > is the case.
> > > 
> > > As this board usually have a serial port, the user can just fix this
> > > by
> > > setting the MAC address manually in the environment. Also disable the
> > > netconsole just in case, because it cannot be guaranteed that it will
> > > work in any case. After all, this was just a convenience option,
> > > because
> > > the bootloader - right now - doesn't have the ability to read the MAC
> > > address, which is stored in the OTP. But it is far more important to
> > > have a clear view of whats wrong with a board and that means we can no
> > > longer use this Kconfig option.
> > > 
> > > Signed-off-by: Michael Walle <michael@walle.cc>
> > > ---
> > >  configs/kontron_sl28_defconfig | 2 --
> > >  1 file changed, 2 deletions(-)
> > > 
> > > diff --git a/configs/kontron_sl28_defconfig
> > > b/configs/kontron_sl28_defconfig
> > > index af907175f1..7fb6bdbe82 100644
> > > --- a/configs/kontron_sl28_defconfig
> > > +++ b/configs/kontron_sl28_defconfig
> > > @@ -59,8 +59,6 @@ CONFIG_OF_LIST=""
> > >  CONFIG_ENV_OVERWRITE=y
> > >  CONFIG_ENV_IS_IN_SPI_FLASH=y
> > >  CONFIG_SYS_REDUNDAND_ENVIRONMENT=y
> > > -CONFIG_NET_RANDOM_ETHADDR=y
> > > -CONFIG_NETCONSOLE=y
> > >  CONFIG_SPL_DM_SEQ_ALIAS=y
> > >  CONFIG_SCSI_AHCI=y
> > >  CONFIG_SATA_CEVA=y
> > 
> > Now, an alternate solution here would be to enable these two options
> > still and write an ft_board_setup() with:
> > ... if ethaddr is in the locally administered pool then
> >         fdt_delprop(... "mac-address");
> >         fdt_delprop(... "local-mac-address");
> 
> Which would also trigger if a user sets a "locally administered"
> mac himself. Even if unlikely, I'm opposed to such magic and
> unexpected behavior. Sooner or later it will bite you.

A fair point, yes.

> > And that should cause the kernel to fall through the cases to find out
> > where to get the real MAC from.  I'm not super happy with this at first,
> > but I also don't see anything clever in the binding we can do.
> 
> If I'll need this one again, then I'll just add the random mac
> generation in board_eth_init(), I think.

OK.

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

  reply	other threads:[~2021-11-17 18:24 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-15 22:45 [PATCH 00/10] board: sl28: add sl28cpld support and board cleanups Michael Walle
2021-11-15 22:45 ` [PATCH 01/10] misc: add sl28cpld base driver Michael Walle
2021-11-15 22:45 ` [PATCH 02/10] watchdog: add sl28cpld watchdog driver Michael Walle
2021-11-15 22:45 ` [PATCH 03/10] gpio: add sl28cpld driver Michael Walle
2021-11-15 22:45 ` [PATCH 04/10] board: sl28: fix DRAM pretty print Michael Walle
2021-11-15 22:45 ` [PATCH 05/10] board: sl28: print CPLD version on bootup Michael Walle
2021-11-15 22:45 ` [PATCH 06/10] board: sl28: enable sl28cpld support Michael Walle
2021-11-15 22:45 ` [PATCH 07/10] board: sl28: enable SoC watchdog support Michael Walle
2021-11-15 22:45 ` [PATCH 08/10] board: sl28: disable recovery watchdog Michael Walle
2021-11-15 22:45 ` [PATCH 09/10] board: sl28: remove "Useful I2C tricks" section from docs Michael Walle
2021-11-15 22:45 ` [PATCH 10/10] board: sl28: disable random MAC address generation Michael Walle
2021-11-16 21:14   ` Tom Rini
2021-11-17 16:45     ` Michael Walle
2021-11-17 18:24       ` Tom Rini [this message]
2021-11-18  8:29         ` Michael Walle
2021-11-18 14:58           ` Tom Rini
2022-01-31  7:51 ` [PATCH 00/10] board: sl28: add sl28cpld support and board cleanups Michael Walle
2022-01-31 15:25   ` Tom Rini
2022-02-02  6:38     ` Priyanka Jain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211117182435.GC24579@bill-the-cat \
    --to=trini@konsulko.com \
    --cc=michael@walle.cc \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox