From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0D0DBC636CD for ; Fri, 10 Feb 2023 11:32:24 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 918848585D; Fri, 10 Feb 2023 12:32:22 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=KARO-electronics.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id CD6E78584F; Fri, 10 Feb 2023 12:32:20 +0100 (CET) Received: from smtprelay01.ispgateway.de (smtprelay01.ispgateway.de [80.67.18.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 4EAA38573A for ; Fri, 10 Feb 2023 12:32:18 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=KARO-electronics.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=LW@KARO-electronics.de Received: from [89.1.81.74] (helo=karo-electronics.de) by smtprelay01.ispgateway.de with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pQRdZ-0002M2-Dq; Fri, 10 Feb 2023 12:32:17 +0100 Date: Fri, 10 Feb 2023 12:32:16 +0100 From: Lothar =?UTF-8?B?V2HDn21hbm4=?= To: Andre Przywara Cc: Simon Glass , Tom Rini , Heinrich Schuchardt , u-boot@lists.denx.de Subject: Re: [PATCH v2 3/3] fdt: introduce fsapply command Message-ID: <20230210123216.3906fdcf@karo-electronics.de> In-Reply-To: <20230210110213.2531190-4-andre.przywara@arm.com> References: <20230210110213.2531190-1-andre.przywara@arm.com> <20230210110213.2531190-4-andre.przywara@arm.com> Organization: Ka-Ro electronics GmbH MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Df-Sender: bHdAa2Fyby1lbGVjdHJvbmljcy5kb21haW5mYWN0b3J5LWt1bmRlLmRl X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Hi, On Fri, 10 Feb 2023 11:02:13 +0000 Andre Przywara wrote: > Explicitly specifying the exact filenames of devicetree overlays files > on a U-Boot command line can be quite tedious for users, especially > when it should be made persistent for every boot. >=20 > To simplify the task of applying (custom) DT overlays, introduce a > "fdt fsapply" subcommand, that iterates a given directory in any > supported filesystem, and tries to apply every .dtbo file found it > there. >=20 > This allows users to simply drop a DT overlay file into a magic > directory, and it will be applied on the next boot automatically, > by the virtue of just a generic U-Boot command call. >=20 > Signed-off-by: Andre Przywara > --- > cmd/fdt.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 87 insertions(+) >=20 > diff --git a/cmd/fdt.c b/cmd/fdt.c > index 1972490bdc2..00f92dbbb5d 100644 > --- a/cmd/fdt.c > +++ b/cmd/fdt.c > @@ -127,6 +129,81 @@ static int fdt_get_header_value(int argc, char *cons= t argv[]) > return CMD_RET_FAILURE; > } > =20 > +#ifdef CONFIG_OF_LIBFDT_OVERLAY > +static int apply_all_overlays(const char *ifname, const char *dev_part_s= tr, > + const char *dirname) > +{ > + unsigned long addr; > + struct fdt_header *dtbo; > + const char *addr_str; > + struct fs_dir_stream *dirs; > + struct fs_dirent *dent; > + char fname[256], *name_beg; > + int ret; > + > + addr_str =3D env_get("fdtoverlay_addr_r"); > + if (!addr_str) { > + printf("Invalid fdtoverlay_addr_r for loading overlays\n"); > + return CMD_RET_FAILURE; > + } > + addr =3D hextoul(addr_str, NULL); > + > + ret =3D fs_set_blk_dev(ifname, dev_part_str, FS_TYPE_ANY); > + if (ret) > + return CMD_RET_FAILURE; > + > + if (!dirname) > + dirname =3D "/"; > + dirs =3D fs_opendir(dirname); > + if (!dirs) { > + printf("Cannot find directory \"%s\"\n", dirname); > + return CMD_RET_FAILURE; > + } > + > + strcpy(fname, dirname); > + name_beg =3D strchr(fname, 0); > + if (name_beg[-1] !=3D '/') > + *name_beg++ =3D '/'; > + > + dtbo =3D map_sysmem(addr, 0); > + while ((dent =3D fs_readdir(dirs))) { > + loff_t size =3D 0; > + > + if (dent->type =3D=3D FS_DT_DIR) > + continue; > + > + if (strcmp(dent->name + strlen(dent->name) - 5, ".dtbo")) > + continue; > + > + printf("%s: ", dent->name); > + strcpy(name_beg, dent->name); > + fs_set_blk_dev(ifname, dev_part_str, FS_TYPE_ANY); > + if (dent->size > SZ_2M) > + size =3D SZ_2M; > + else > + size =3D dent->size; > + ret =3D fs_read(fname, addr, 0, size, &size); > + if (ret) { > + printf(" errno: %d\n", ret); > + continue; > + } > + if (!fdt_valid(&dtbo)) { > + /* fdt_valid() clears the pointer upon failure */ > + dtbo =3D map_sysmem(addr, 0); > + continue; > + } > + > + if (fdt_overlay_apply_verbose(working_fdt, dtbo) =3D=3D 0) > + printf("applied\n"); > + } > + unmap_sysmem(dtbo); > + > + fs_closedir(dirs); > + > + return 0; return CMD_RET_SUCCESS; Lothar Wa=C3=9Fmann