From nobody Thu Dec 14 17:50:34 2023 X-Original-To: freebsd-arm@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Srfyw3S5Sz52nYk for ; Thu, 14 Dec 2023 17:50:48 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Srfyw19yvz3fvH for ; Thu, 14 Dec 2023 17:50:48 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Authentication-Results: mx1.freebsd.org; none Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-a1d93da3eb7so977569166b.0 for ; Thu, 14 Dec 2023 09:50:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1702576245; x=1703181045; darn=freebsd.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=cq0QnHEhTXt2gUH0KGdNKEWcEwqHRKs+wyUrwNNFthQ=; b=vMq7CNIdr5xjFV/LzJc6gn05A6ZHfk+dsjR43dDci1l3J/8BLJsQ+zh8LO9d96ZznO n+6WPaqoNZvukW+LN2utjbpnvTTVbxwtx8eI9MZqvehtLXslhDTaSyaX8VdJ39nNs3/W Jj0U0ZbeiP3fEcZZvMAKzi5n09i8cCjdrSeXQACb96Li3xzt35ICP49MoPDaFpc9miEg fID//SZEhgBvVEHi1qgmKOC2Hlh2nIS0NJCb/3funKkrr+dHZZu2ndddlMciPBRRoWkx by2wgVj2OgDaPaiGllL+ZB6DR087g+zf1mxGAjukgnFk4F6QsziiMco+lIfnls0xXKXG eeRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702576245; x=1703181045; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=cq0QnHEhTXt2gUH0KGdNKEWcEwqHRKs+wyUrwNNFthQ=; b=hefC4Cc96qDyueLJu8PjQqZhfKWBdl5FcROQ+DPKD2chl8XGzORx9kuyQJNZCazjlC amJKnpu0tqDvet9y0Zhos7l/69dJYMlc3P5Q7cFr/Wu/xpYg54OIKLhlOmuSaZsYuBq8 M2pwhZR9Awl4sXXyH/gINf5ca+afWnrrEfIeqAYhXk49W2hRfH6KeU9Y6mZ2aHYi2QcS jfCUXff2qtUIuAZFEdT/T8JkpIm4zFvU6QAgea1+IjMaa6UL7IC57TtXLavJI6DvyXnh 0hXzK6WCdS41nITwRacuQzFIs+lV2m8h6buhbB2ZLYsvwvdOgH5ZS50GHdtWJzDTsmip ewLw== X-Gm-Message-State: AOJu0YwWwN65oea0soZSDjoGnX2QM5eD04/+zMN2yToyzVSq4S4zV01y PyZaK7C+Dlh5w4Uv3rVXlbIJpiIF0lendWiHZXYFvQ== X-Google-Smtp-Source: AGHT+IGlrP1MOBsQdNzx0E0mUdzSVg1bBV+1xhT7w1a8iJqwRvyFOItFd/uT+xQK+2TzSZSCT0XmLxYZzD8EC9oNBuU= X-Received: by 2002:a17:906:c281:b0:a1c:7dce:d416 with SMTP id r1-20020a170906c28100b00a1c7dced416mr5041475ejz.124.1702576245321; Thu, 14 Dec 2023 09:50:45 -0800 (PST) List-Id: Porting FreeBSD to ARM processors List-Archive: https://lists.freebsd.org/archives/freebsd-arm List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-arm@freebsd.org MIME-Version: 1.0 References: <881889965.11901.1702500020716@localhost> In-Reply-To: From: Warner Losh Date: Thu, 14 Dec 2023 10:50:34 -0700 Message-ID: Subject: Re: initarm() parsing bootargs? To: Ronald Klop Cc: "freebsd-arm@freebsd.org" Content-Type: multipart/alternative; boundary="0000000000004e41bc060c7bec57" X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:15169, ipnet:2a00:1450::/32, country:US] X-Spamd-Bar: ---- X-Rspamd-Queue-Id: 4Srfyw19yvz3fvH --0000000000004e41bc060c7bec57 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Dec 14, 2023 at 4:17=E2=80=AFAM Ronald Klop wr= ote: > Hi, > > I'm looking into some code but it is really early in the boot path so I > find it hard to debug. Do you have some pointers? > > Booting my RPI it gets a parameter "bootargs" passed. I used this in a > driver. See the forwarded email below for the details about this. > > But in sys/arm64/arm64/machdep_boot.c I found this code. It looks likes i= t > would nicely get and parse this "bootargs" which is called > "linux_command_line" here. > > void > parse_fdt_bootargs(void) > { > > if (loader_envp =3D=3D NULL && > fdt_get_chosen_bootargs(linux_command_line, > LBABI_MAX_COMMAND_LINE) =3D=3D 0) { > init_static_kenv(static_kenv, sizeof(static_kenv)); > cmdline_set_env(linux_command_line, CMDLINE_GUARD); > } > } > > But kern_getenv() does not give me any values from this "bootargs" string= . > > I started adding some printf() lines from initarm() up until this method > but that is never printed. Is it too early in the boot to print anything? > How do others debug these pieces of code? > You need EARLY_PRINTF defined. And maybe some more stuff as well. For Allwinner, I could tell you how, but I see nothing in the devices that the RPi uses. It most likely needs SOCDEV_PA and SOCDEV_VA assigned correctly. I've never done early arg parsing. But one thing you can do is to verify at runtime that the linux command line is really there in the FDT exported from the kernel. RPi has weird ways to pass stuff into the kernel historically, though I can't recall the details beyond that. Warner > Regards, > Ronald. > > > > > -------- Forwarded Message -------- > Subject: Re: git: 3878bbf1bb9e - main - Teach if_smsc to get MAC > from bootargs. > Date: Wed, 13 Dec 2023 21:40:20 +0100 (CET) > From: Ronald Klop > To: Emmanuel Vadot > CC: Ronald Klop > > > > *Van:* Emmanuel Vadot > *Datum:* donderdag, 7 december 2023 14:35 > *Aan:* Ronald Klop > *CC:* src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, > dev-commits-src-main@FreeBSD.org > *Onderwerp:* Re: git: 3878bbf1bb9e - main - Teach if_smsc to get MAC from > bootargs. > > On Thu, 7 Dec 2023 11:33:05 GMT > Ronald Klop wrote: > > > The branch main has been updated by ronald: > > > > URL: > https://cgit.FreeBSD.org/src/commit/?id=3D3878bbf1bb9e68f8579b57cde7d4e5c= 77de93320 > < > https://cgit.FreeBSD.org/src/commit/?id=3D3878bbf1bb9e68f8579b57cde7d4e5c= 77de93320 > > > > > > commit 3878bbf1bb9e68f8579b57cde7d4e5c77de93320 > > Author: Ronald Klop > > AuthorDate: 2023-11-04 14:14:00 +0000 > > Commit: Ronald Klop > > CommitDate: 2023-12-07 11:32:01 +0000 > > > > Teach if_smsc to get MAC from bootargs. > > > > Some Raspberry Pi pass smsc95xx.macaddr=3DXX:XX:XX:XX:XX:XX a= s > bootargs. > > Use this if no ethernet address is found in an EEPROM. > > As last resort fall back to ether_gen_addr() instead of rando= m > MAC. > > > > PR: 274092 > > Reported by: Patrick M. Hausen (via ML) > > Reviewed by: imp, karels, zlei > > Tested by: Patrick M. Hausen > > Approved by: karels > > MFC after: 1 month > > Relnotes: yes > > Differential Revision: https://reviews.freebsd.org/D42463 < > https://reviews.freebsd.org/D42463> > > --- > > sys/dev/usb/net/if_smsc.c | 86 > +++++++++++++++++++++++++++++++++++++++++++++-- > > sys/net/ethernet.h | 1 + > > sys/net/if_ethersubr.c | 10 ++++-- > > 3 files changed, 92 insertions(+), 5 deletions(-) > > > > diff --git a/sys/dev/usb/net/if_smsc.c b/sys/dev/usb/net/if_smsc.= c > > index ec8197229f17..54b18e0a67c9 100644 > > --- a/sys/dev/usb/net/if_smsc.c > > +++ b/sys/dev/usb/net/if_smsc.c > > @@ -179,6 +179,8 @@ static const struct usb_device_id smsc_devs[] > =3D { > > #define ETHER_IS_VALID(addr) \ > > (!ETHER_IS_MULTICAST(addr) && !ETHER_IS_ZERO(addr)) > > > > +#define BOOTARGS_SMSC95XX "smsc95xx.macaddr" > > + > > static device_probe_t smsc_probe; > > static device_attach_t smsc_attach; > > static device_detach_t smsc_detach; > > @@ -1538,6 +1540,76 @@ smsc_ioctl(if_t ifp, u_long cmd, caddr_t > data) > > return (rc); > > } > > > > +#ifdef FDT > > +static bool > > +smsc_get_smsc95xx_macaddr(char* bootargs, size_t len, struct > usb_ether *ue) > > +{ > > + int values[6]; > > + int i; > > + char* p; > > + > > + p =3D strnstr(bootargs, BOOTARGS_SMSC95XX, len); > > + if (p =3D=3D NULL) > > + return (false); > > + > > + if (sscanf(p, BOOTARGS_SMSC95XX "=3D%x:%x:%x:%x:%x:%x%*c", > > + &values[0], &values[1], &values[2], > > + &values[3], &values[4], &values[5]) !=3D 6) { > > + smsc_warn_printf((struct smsc_softc *)ue->ue_sc, > > + "invalid mac from bootargs '%s'.\n", p); > > + return (false); > > + } > > + > > + for (i =3D 0; i < ETHER_ADDR_LEN; ++i) > > + ue->ue_eaddr[i] =3D values[i]; > > + > > + smsc_dbg_printf((struct smsc_softc *)ue->ue_sc, > > + "bootargs mac=3D%6D.\n", ue->ue_eaddr, ":"); > > + return (true); > > +} > > + > > +/** > > + * Raspberry Pi is known to pass > smsc95xx.macaddr=3DXX:XX:XX:XX:XX:XX via > > + * bootargs. > > + */ > > +static bool > > +smsc_bootargs_get_mac_addr(device_t dev, struct usb_ether *ue) > > +{ > > + char *bootargs; > > + ssize_t len; > > + phandle_t node; > > + > > + /* only use bootargs for the first device > > + * to prevent duplicate mac addresses */ > > + if (device_get_unit(dev) !=3D 0) > > + return (false); > > + node =3D OF_finddevice("/chosen"); > > + if (node =3D=3D -1) > > + return (false); > > + if (OF_hasprop(node, "bootargs") =3D=3D 0) { > > + smsc_dbg_printf((struct smsc_softc *)ue->ue_sc, > > + "bootargs not found"); > > + return (false); > > + } > > + len =3D OF_getprop_alloc(node, "bootargs", (void **)&bootargs); > > + if (len =3D=3D -1 || bootargs =3D=3D NULL) { > > + smsc_warn_printf((struct smsc_softc *)ue->ue_sc, > > + "failed alloc for bootargs (%lu)", len); > > + return (false); > > + } > > All this can be replaced with a call to fdt_get_chosen_bootargs. > Also we already do this for arm and arm64 in machdep_boot.c and > store > the linux boot args in a static var called linux_command_line, maybe > make it not static and get it from this driver. > While you're at it make bcm2835_fbd.c and bcm2835_fb.c use this as > they also get and parse the bootargs. > > Cheers, > > [...snip...] > > -- > Emmanuel Vadot > > > > Dear Emmanuel, > > I'm looking into this function fdt_get_chosen_bootargs. Unfortunately it > uses static memory allocation which conflicts with another remark I got i= n > the review. > > But what I do see is that it parses this bootargs string into kern_setenv > in sys/kern/subr_boot.c: boot_parse_arg(...). > parse_fdt_bootargs (sys/arm64/arm64/machdep_boot.c) -> cmdline_set_env > -> boot_parse_cmdline (subr_boot.c) -> boot_parse_cmdline_delim -> > boot_parse_arg > Would that be usable? > > I don't see the value in the output of kenv(1) but maybe that is not > related. > > I'll try to come up with a testcase on my RPI to see if this bootargs end= s > up in kern_getenv in a parsed way. > > Regards, > Ronald. > > --0000000000004e41bc060c7bec57 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Thu, Dec 14, 2023 at 4:17=E2=80=AF= AM Ronald Klop <ronald@freebsd.org= > wrote:
= Hi,

I'm looking into some code but it is really early in the boot path so I= find it hard to debug. Do you have some pointers?

Booting my RPI it gets a parameter "bootargs" passed. I used this= in a driver. See the forwarded email below for the details about this.

But in sys/arm64/arm64/machdep_boot.c I found this code. It looks likes it = would nicely get and parse this "bootargs" which is called "= linux_command_line" here.

void
parse_fdt_bootargs(void)
{

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (loader_envp =3D=3D NULL && fd= t_get_chosen_bootargs(linux_command_line,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0LBABI_MAX_COMMAND_LINE) =3D= =3D 0) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0init_static_k= env(static_kenv, sizeof(static_kenv));
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0cmdline_set_e= nv(linux_command_line, CMDLINE_GUARD);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0}
}

But kern_getenv() does not give me any values from this "bootargs"= ; string.

I started adding some printf() lines from initarm() up until this method bu= t that is never printed. Is it too early in the boot to print anything?
How do others debug these pieces of code?

You need EARLY_PRINTF defined. And maybe some more stuff as well. For Al= lwinner, I could tell you how, but I see nothing in the devices that the RP= i uses. It most likely needs SOCDEV_PA and SOCDEV_VA assigned correctly. I&= #39;ve never done early arg parsing.

But one thing= you can do is to verify at runtime that the linux command line is really t= here in the FDT exported from the kernel. RPi has weird ways to pass stuff = into the kernel historically, though I can't recall the details beyond = that.

Warner
=C2=A0
Regards,
Ronald.




-------- Forwarded Message --------
Subject:=C2=A0 =C2=A0 =C2=A0 =C2=A0 Re: git: 3878bbf1bb9e - main - Teach if= _smsc to get MAC from bootargs.
Date:=C2=A0 =C2=A0Wed, 13 Dec 2023 21:40:20 +0100 (CET)
From:=C2=A0 =C2=A0Ronald Klop <ronald-lists@klop.ws>
To:=C2=A0 =C2=A0 =C2=A0Emmanuel Vadot <manu@bidouilliste.com>
CC:=C2=A0 =C2=A0 =C2=A0Ronald Klop <ronald@FreeBSD.org>



*Van:* Emmanuel Vadot <manu@bidouilliste.com>
*Datum:* donderdag, 7 december 2023 14:35
*Aan:* Ronald Klop <ronald@FreeBSD.org>
*CC:* src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-comm= its-src-main@FreeBSD.org
*Onderwerp:* Re: git: 3878bbf1bb9e - main - Teach if_smsc to get MAC from b= ootargs.

=C2=A0 =C2=A0 =C2=A0On Thu, 7 Dec 2023 11:33:05 GMT
=C2=A0 =C2=A0 =C2=A0Ronald Klop <ronald@FreeBSD.org> wrote:

=C2=A0 =C2=A0 =C2=A0 > The branch main has been updated by ronald:
=C2=A0 =C2=A0 =C2=A0 >
=C2=A0 =C2=A0 =C2=A0 > URL: https://cgit.FreeBSD.org/src/commit/?id=3D3878bbf1bb9e68f8579b= 57cde7d4e5c77de93320 <https://cgit.FreeBSD.org/src/commit/?id=3D3878bbf1bb9e68f8579b5= 7cde7d4e5c77de93320>
=C2=A0 =C2=A0 =C2=A0 >
=C2=A0 =C2=A0 =C2=A0 > commit 3878bbf1bb9e68f8579b57cde7d4e5c77de93320 =C2=A0 =C2=A0 =C2=A0 > Author: =C2=A0=C2=A0=C2=A0=C2=A0Ronald Klop <r= onald@FreeBSD.org>
=C2=A0 =C2=A0 =C2=A0 > AuthorDate: 2023-11-04 14:14:00 +0000
=C2=A0 =C2=A0 =C2=A0 > Commit: =C2=A0=C2=A0=C2=A0=C2=A0Ronald Klop <r= onald@FreeBSD.org>
=C2=A0 =C2=A0 =C2=A0 > CommitDate: 2023-12-07 11:32:01 +0000
=C2=A0 =C2=A0 =C2=A0 >
=C2=A0 =C2=A0 =C2=A0 > =C2=A0=C2=A0=C2=A0=C2=A0Teach if_smsc to get MAC = from bootargs.
=C2=A0 =C2=A0 =C2=A0 >
=C2=A0 =C2=A0 =C2=A0 > =C2=A0=C2=A0=C2=A0=C2=A0Some Raspberry Pi pass sm= sc95xx.macaddr=3DXX:XX:XX:XX:XX:XX as bootargs.
=C2=A0 =C2=A0 =C2=A0 > =C2=A0=C2=A0=C2=A0=C2=A0Use this if no ethernet a= ddress is found in an EEPROM.
=C2=A0 =C2=A0 =C2=A0 > =C2=A0=C2=A0=C2=A0=C2=A0As last resort fall back = to ether_gen_addr() instead of random MAC.
=C2=A0 =C2=A0 =C2=A0 >
=C2=A0 =C2=A0 =C2=A0 > =C2=A0=C2=A0=C2=A0=C2=A0PR: =C2=A0=C2=A0=C2=A0=C2= =A0274092
=C2=A0 =C2=A0 =C2=A0 > =C2=A0=C2=A0=C2=A0=C2=A0Reported by: =C2=A0=C2=A0= =C2=A0Patrick M. Hausen (via ML)
=C2=A0 =C2=A0 =C2=A0 > =C2=A0=C2=A0=C2=A0=C2=A0Reviewed by: =C2=A0=C2=A0= =C2=A0imp, karels, zlei
=C2=A0 =C2=A0 =C2=A0 > =C2=A0=C2=A0=C2=A0=C2=A0Tested by: =C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0Patrick M. Hausen
=C2=A0 =C2=A0 =C2=A0 > =C2=A0=C2=A0=C2=A0=C2=A0Approved by: =C2=A0=C2=A0= =C2=A0karels
=C2=A0 =C2=A0 =C2=A0 > =C2=A0=C2=A0=C2=A0=C2=A0MFC after: =C2=A0=C2=A0= =C2=A0=C2=A0=C2=A01 month
=C2=A0 =C2=A0 =C2=A0 > =C2=A0=C2=A0=C2=A0=C2=A0Relnotes: =C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0yes
=C2=A0 =C2=A0 =C2=A0 > =C2=A0=C2=A0=C2=A0=C2=A0Differential Revision: https://reviews.freebsd.org/D42463 <https://reviews.= freebsd.org/D42463>
=C2=A0 =C2=A0 =C2=A0 > ---
=C2=A0 =C2=A0 =C2=A0 > =C2=A0sys/dev/usb/net/if_smsc.c | 86 ++++++++++++= +++++++++++++++++++++++++++++++++--
=C2=A0 =C2=A0 =C2=A0 > =C2=A0sys/net/ethernet.h =C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0| =C2=A01 +
=C2=A0 =C2=A0 =C2=A0 > =C2=A0sys/net/if_ethersubr.c =C2=A0=C2=A0=C2=A0| = 10 ++++--
=C2=A0 =C2=A0 =C2=A0 > =C2=A03 files changed, 92 insertions(+), 5 deleti= ons(-)
=C2=A0 =C2=A0 =C2=A0 >
=C2=A0 =C2=A0 =C2=A0 > diff --git a/sys/dev/usb/net/if_smsc.c b/sys/dev/= usb/net/if_smsc.c
=C2=A0 =C2=A0 =C2=A0 > index ec8197229f17..54b18e0a67c9 100644
=C2=A0 =C2=A0 =C2=A0 > --- a/sys/dev/usb/net/if_smsc.c
=C2=A0 =C2=A0 =C2=A0 > +++ b/sys/dev/usb/net/if_smsc.c
=C2=A0 =C2=A0 =C2=A0 > @@ -179,6 +179,8 @@ static const struct usb_devic= e_id smsc_devs[] =3D {
=C2=A0 =C2=A0 =C2=A0 > =C2=A0#define ETHER_IS_VALID(addr) \
=C2=A0 =C2=A0 =C2=A0 > =C2=A0=C2=A0(!ETHER_IS_MULTICAST(addr) &&= !ETHER_IS_ZERO(addr))
=C2=A0 =C2=A0 =C2=A0 >
=C2=A0 =C2=A0 =C2=A0 > +#define BOOTARGS_SMSC95XX =C2=A0=C2=A0=C2=A0&quo= t;smsc95xx.macaddr"
=C2=A0 =C2=A0 =C2=A0 > +
=C2=A0 =C2=A0 =C2=A0 > =C2=A0static device_probe_t smsc_probe;
=C2=A0 =C2=A0 =C2=A0 > =C2=A0static device_attach_t smsc_attach;
=C2=A0 =C2=A0 =C2=A0 > =C2=A0static device_detach_t smsc_detach;
=C2=A0 =C2=A0 =C2=A0 > @@ -1538,6 +1540,76 @@ smsc_ioctl(if_t ifp, u_lon= g cmd, caddr_t data)
=C2=A0 =C2=A0 =C2=A0 > =C2=A0=C2=A0return (rc);
=C2=A0 =C2=A0 =C2=A0 > =C2=A0}
=C2=A0 =C2=A0 =C2=A0 >
=C2=A0 =C2=A0 =C2=A0 > +#ifdef FDT
=C2=A0 =C2=A0 =C2=A0 > +static bool
=C2=A0 =C2=A0 =C2=A0 > +smsc_get_smsc95xx_macaddr(char* bootargs, size_t= len, struct usb_ether *ue)
=C2=A0 =C2=A0 =C2=A0 > +{
=C2=A0 =C2=A0 =C2=A0 > + int values[6];
=C2=A0 =C2=A0 =C2=A0 > + int i;
=C2=A0 =C2=A0 =C2=A0 > + char* p;
=C2=A0 =C2=A0 =C2=A0 > +
=C2=A0 =C2=A0 =C2=A0 > + p =3D strnstr(bootargs, BOOTARGS_SMSC95XX, len)= ;
=C2=A0 =C2=A0 =C2=A0 > + if (p =3D=3D NULL)
=C2=A0 =C2=A0 =C2=A0 > + =C2=A0=C2=A0=C2=A0=C2=A0return (false);
=C2=A0 =C2=A0 =C2=A0 > +
=C2=A0 =C2=A0 =C2=A0 > + if (sscanf(p, BOOTARGS_SMSC95XX "=3D%x:%x:= %x:%x:%x:%x%*c",
=C2=A0 =C2=A0 =C2=A0 > + =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0&values[0], &values[1], &values[2],
=C2=A0 =C2=A0 =C2=A0 > + =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0&values[3], &values[4], &values[5]) !=3D 6) {
=C2=A0 =C2=A0 =C2=A0 > + =C2=A0=C2=A0=C2=A0=C2=A0smsc_warn_printf((struc= t smsc_softc *)ue->ue_sc,
=C2=A0 =C2=A0 =C2=A0 > + =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0"invalid mac from bootargs '%s'.\n&= quot;, p);
=C2=A0 =C2=A0 =C2=A0 > + =C2=A0=C2=A0=C2=A0=C2=A0return (false);
=C2=A0 =C2=A0 =C2=A0 > + }
=C2=A0 =C2=A0 =C2=A0 > +
=C2=A0 =C2=A0 =C2=A0 > + for (i =3D 0; i < ETHER_ADDR_LEN; ++i)
=C2=A0 =C2=A0 =C2=A0 > + =C2=A0=C2=A0=C2=A0=C2=A0ue->ue_eaddr[i] =3D = values[i];
=C2=A0 =C2=A0 =C2=A0 > +
=C2=A0 =C2=A0 =C2=A0 > + smsc_dbg_printf((struct smsc_softc *)ue->ue_= sc,
=C2=A0 =C2=A0 =C2=A0 > + =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0"bootargs mac=3D%6D.\n", ue->ue_eaddr, ":");
=C2=A0 =C2=A0 =C2=A0 > + return (true);
=C2=A0 =C2=A0 =C2=A0 > +}
=C2=A0 =C2=A0 =C2=A0 > +
=C2=A0 =C2=A0 =C2=A0 > +/**
=C2=A0 =C2=A0 =C2=A0 > + * Raspberry Pi is known to pass smsc95xx.macadd= r=3DXX:XX:XX:XX:XX:XX via
=C2=A0 =C2=A0 =C2=A0 > + * bootargs.
=C2=A0 =C2=A0 =C2=A0 > + */
=C2=A0 =C2=A0 =C2=A0 > +static bool
=C2=A0 =C2=A0 =C2=A0 > +smsc_bootargs_get_mac_addr(device_t dev, struct = usb_ether *ue)
=C2=A0 =C2=A0 =C2=A0 > +{
=C2=A0 =C2=A0 =C2=A0 > + char *bootargs;
=C2=A0 =C2=A0 =C2=A0 > + ssize_t len;
=C2=A0 =C2=A0 =C2=A0 > + phandle_t node;
=C2=A0 =C2=A0 =C2=A0 > +
=C2=A0 =C2=A0 =C2=A0 > + /* only use bootargs for the first device
=C2=A0 =C2=A0 =C2=A0 > + =C2=A0* to prevent duplicate mac addresses */ =C2=A0 =C2=A0 =C2=A0 > + if (device_get_unit(dev) !=3D 0)
=C2=A0 =C2=A0 =C2=A0 > + =C2=A0=C2=A0=C2=A0=C2=A0return (false);
=C2=A0 =C2=A0 =C2=A0 > + node =3D OF_finddevice("/chosen"); =C2=A0 =C2=A0 =C2=A0 > + if (node =3D=3D -1)
=C2=A0 =C2=A0 =C2=A0 > + =C2=A0=C2=A0=C2=A0=C2=A0return (false);
=C2=A0 =C2=A0 =C2=A0 > + if (OF_hasprop(node, "bootargs") =3D= =3D 0) {
=C2=A0 =C2=A0 =C2=A0 > + =C2=A0=C2=A0=C2=A0=C2=A0smsc_dbg_printf((struct= smsc_softc *)ue->ue_sc,
=C2=A0 =C2=A0 =C2=A0 > + =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0"bootargs not found");
=C2=A0 =C2=A0 =C2=A0 > + =C2=A0=C2=A0=C2=A0=C2=A0return (false);
=C2=A0 =C2=A0 =C2=A0 > + }
=C2=A0 =C2=A0 =C2=A0 > + len =3D OF_getprop_alloc(node, "bootargs&q= uot;, (void **)&bootargs);
=C2=A0 =C2=A0 =C2=A0 > + if (len =3D=3D -1 || bootargs =3D=3D NULL) { =C2=A0 =C2=A0 =C2=A0 > + =C2=A0=C2=A0=C2=A0=C2=A0smsc_warn_printf((struc= t smsc_softc *)ue->ue_sc,
=C2=A0 =C2=A0 =C2=A0 > + =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0"failed alloc for bootargs (%lu)", len= );
=C2=A0 =C2=A0 =C2=A0 > + =C2=A0=C2=A0=C2=A0=C2=A0return (false);
=C2=A0 =C2=A0 =C2=A0 > + }

=C2=A0 =C2=A0 =C2=A0 =C2=A0All this can be replaced with a call to fdt_get_= chosen_bootargs.
=C2=A0 =C2=A0 =C2=A0 =C2=A0Also we already do this for arm and arm64 in mac= hdep_boot.c and store
=C2=A0 =C2=A0 =C2=A0the linux boot args in a static var called linux_comman= d_line, maybe
=C2=A0 =C2=A0 =C2=A0make it not static and get it from this driver.
=C2=A0 =C2=A0 =C2=A0 =C2=A0While you're at it make bcm2835_fbd.c and bc= m2835_fb.c use this as
=C2=A0 =C2=A0 =C2=A0they also get and parse the bootargs.

=C2=A0 =C2=A0 =C2=A0 =C2=A0Cheers,

=C2=A0 =C2=A0 =C2=A0[...snip...]

=C2=A0 =C2=A0 =C2=A0--
=C2=A0 =C2=A0 =C2=A0Emmanuel Vadot <manu@bidouilliste.com> <manu@freebsd.org>



Dear Emmanuel,

I'm looking into this function fdt_get_chosen_bootargs. Unfortunately i= t uses static memory allocation which conflicts with another remark I got i= n the review.

But what I do see is that it parses this bootargs string into kern_setenv i= n sys/kern/subr_boot.c: boot_parse_arg(...).
parse_fdt_bootargs (sys/arm64/arm64/machdep_boot.c) ->=C2=A0cmdline_set_= env ->=C2=A0boot_parse_cmdline (subr_boot.c) -> boot_parse_cmdline_de= lim -> boot_parse_arg
Would that be usable?

I don't see the value in the output of kenv(1) but maybe that is not re= lated.

I'll try to come up with a testcase on my RPI to see if this bootargs e= nds up in kern_getenv in a parsed way.

Regards,
Ronald.

--0000000000004e41bc060c7bec57--