From nobody Thu Dec 14 11:17:36 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 4SrVFK1gFLz53qbw for ; Thu, 14 Dec 2023 11:17:41 +0000 (UTC) (envelope-from ronald@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [IPv6:2610:1c1:1:606c::24b:4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4SrVFK17Kxz4VPF for ; Thu, 14 Dec 2023 11:17:41 +0000 (UTC) (envelope-from ronald@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1702552661; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pUoGJuXnWcw7QvGfmrKqtPkxR56OlshzEm13MxTzN1s=; b=AgeBclVdaJ1vLvFDKTOidlbH9HzXo3NsWBkDl76a4zo8PQ1Dx1wHb1o9/ETC8WzlXyHlzJ 7VHJeF6+ex2ObpI6CmgEjKv9qxCHcDQClB2aCghSOTpnd20giRUnPnkphnRyvGtcpOWEy4 BNgLa4twO9j0NsQaH8fCdSCwu/n0qe3dWP18WHWbJv7mPGbzva8sGumV+O/ox8K2LNTP8O tMy4YpyAlvndCvbaxzhd3bySCXSXmqx0ZITcgNBzyXnza4Wnp9//r7MJSKXu+JmPzbP3pU mJVWZTK6hJAkpIi8z6vIzRajLrKkXVkQ8DBr7bJLFOcUtxzC4pCpP8poJ/XadQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1702552661; a=rsa-sha256; cv=none; b=GmqYZ8/xiCRGCfFkaC+lD4Dkd/yKB8AxXT3annfSeyYFx4AhFG1cIylFwBjll2y8tr0N9O RNwEZmM1zZfWWNVoDmHbwBykv9BFf88aag93t0X15N3egdgtCfUqH3O/Wgg9UZBz/E64cA X3VfPCxUjcxItPf5wOwjFoAdB1CLy0UtZ5NZ2TDMPy+h8ylZC+nPG9AvkhPUmzUPaqVxYW 2Ad4z/Lh5QQ5f6bHUULQC5gYhDtdy/wMPVrJ31/WpVHnxFG7PAnWMuPEcn6qrKrA1/xNp1 rx5jIjPYxyfCk6G7S2sTpFsRcfmg5nDOglyn5MZek6OlgNYrgobfr7Xlx/bRlw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1702552661; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pUoGJuXnWcw7QvGfmrKqtPkxR56OlshzEm13MxTzN1s=; b=Nkjs997uin30wvQTloq9HlgINhlg9FKXSzLVZjtCreyBF6/CUQ9b0o4UwjEjYUQE663WnP VwM7bfZilD7g+bt4BzRrS6diYozWBO28F8VNtg9tBFRM/XmBR+CrqcDxVmzIKk9n+BJMyr H6J0fg5fWa+hVCx45t/gkbOWm2vAMMt1FtwpPyV+xki/Ix+vcpYLBwmkhTsNL33c4rLLZz T4ajtLavr/wC4OcIgILAha6iHgPO+tzOPNlhHcdUJB9ZhN4z/9Tj7enh2SJaQZm7/PMm3n q8t7Gani+SHcA90q1jcHlfni7JNmZb2fQksUczTPRwVUhnBU3WHbAmgzX9oCaA== Received: from [IPV6:2001:1c00:2709:2010:493e:9031:fcc0:f007] (2001-1c00-2709-2010-493e-9031-fcc0-f007.cable.dynamic.v6.ziggo.nl [IPv6:2001:1c00:2709:2010:493e:9031:fcc0:f007]) (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 did not present a certificate) (Authenticated sender: ronald/mail) by smtp.freebsd.org (Postfix) with ESMTPSA id 4SrVFJ5jwvzk3f for ; Thu, 14 Dec 2023 11:17:40 +0000 (UTC) (envelope-from ronald@FreeBSD.org) Message-ID: Date: Thu, 14 Dec 2023 12:17:36 +0100 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 User-Agent: Mozilla Thunderbird Subject: initarm() parsing bootargs? References: <881889965.11901.1702500020716@localhost> Content-Language: en-US To: "freebsd-arm@freebsd.org" From: Ronald Klop In-Reply-To: <881889965.11901.1702500020716@localhost> X-Forwarded-Message-Id: <881889965.11901.1702500020716@localhost> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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) { if (loader_envp == NULL && fdt_get_chosen_bootargs(linux_command_line, LBABI_MAX_COMMAND_LINE) == 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? 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=3878bbf1bb9e68f8579b57cde7d4e5c77de93320 > > 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=XX:XX:XX:XX:XX:XX as bootargs. >     Use this if no ethernet address is found in an EEPROM. >     As last resort fall back to ether_gen_addr() instead of random 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 > --- >  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[] = { >  #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 = strnstr(bootargs, BOOTARGS_SMSC95XX, len); > + if (p == NULL) > +     return (false); > + > + if (sscanf(p, BOOTARGS_SMSC95XX "=%x:%x:%x:%x:%x:%x%*c", > +         &values[0], &values[1], &values[2], > +         &values[3], &values[4], &values[5]) != 6) { > +     smsc_warn_printf((struct smsc_softc *)ue->ue_sc, > +             "invalid mac from bootargs '%s'.\n", p); > +     return (false); > + } > + > + for (i = 0; i < ETHER_ADDR_LEN; ++i) > +     ue->ue_eaddr[i] = values[i]; > + > + smsc_dbg_printf((struct smsc_softc *)ue->ue_sc, > +         "bootargs mac=%6D.\n", ue->ue_eaddr, ":"); > + return (true); > +} > + > +/** > + * Raspberry Pi is known to pass smsc95xx.macaddr=XX: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) != 0) > +     return (false); > + node = OF_finddevice("/chosen"); > + if (node == -1) > +     return (false); > + if (OF_hasprop(node, "bootargs") == 0) { > +     smsc_dbg_printf((struct smsc_softc *)ue->ue_sc, > +             "bootargs not found"); > +     return (false); > + } > + len = OF_getprop_alloc(node, "bootargs", (void **)&bootargs); > + if (len == -1 || bootargs == 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 in 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 ends up in kern_getenv in a parsed way. Regards, Ronald.