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 89E1EC4332F for ; Mon, 17 Oct 2022 22:14:28 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 872D584F80; Tue, 18 Oct 2022 00:14:26 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="gqEJK8ZE"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 730CF84F77; Tue, 18 Oct 2022 00:14:24 +0200 (CEST) Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 89EB184E6F for ; Tue, 18 Oct 2022 00:14:20 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1666044859; bh=vyMnmGmUJc3h3joorqI3VqLK3+swbtRXpqlvFwffxnQ=; h=X-UI-Sender-Class:Date:Subject:To:Cc:References:From:In-Reply-To; b=gqEJK8ZEKIJjUelD5bchAb9lrrBn06M5+s8d7xEyr53ZVEtAMZ1f0S61jgVlGii/O lq72LfQVdsHYlBiARvHqcsorvjkd6RVRQATpc1qMhSG+C2hKv8ZkU3ByowPDQ5uUcM hDGUfCHhoDp6Cm3oyQ0Hmas0odXQmvVNs4wevQ+k= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [192.168.123.94] ([84.118.157.2]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MNt0M-1oV4qo4A1I-00OE0K; Tue, 18 Oct 2022 00:14:19 +0200 Message-ID: Date: Tue, 18 Oct 2022 00:14:18 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.3 Subject: Re: [PATCH 14/24] bootstd: Read the Operating System name for distro/scripts Content-Language: en-US To: Simon Glass Cc: Anatolij Gustschin , Tom Rini , u-boot@lists.denx.de References: <20221017203000.2207887-1-sjg@chromium.org> <20221017203000.2207887-15-sjg@chromium.org> From: Heinrich Schuchardt In-Reply-To: <20221017203000.2207887-15-sjg@chromium.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:ilaLTXJKBUbhbOzsxzKa7FVzKHsTi2ZZx0ODNphLaR3+2v+6DU+ S8UGmsClXVRBaL+5WaG7WC2s/G/jk4jbRvN9opUcjCKVXVWloGUinp+LOIMlUWR8/rIJm39 b7yosSivPJcJrZjZkEcBsa/QL12kGkmbSnd8c79RwztEZc+Y5QBSNq9+JeXip2r+tdgbpNA imgXJYuZpMZmef5fuGJLQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:QaPsInxQAXM=:SbY6zAyC2jfa4DmaQCnwgR jVImllKCy6Ld3gTMOHnpIOGBWix2r53MbMUzrpGi6ZNi3m4v7OoYk5TjOymqU0UfMYPQ403P3 kbNH129LM/hnapzR7xi9M52C1+Dka0Zj7of9g4c9BvMwjzMDaEr9pEee4xmjaqVFNcZi3Pm9G 6eIvx7yhGDnxGNPh7444fOKOTQJI09lGKtUfcko/rvmzunZ66NXezKdJcH6BUjlOC9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3ePPi1lw8VNp5Hr+b5E9g9oNORn3fysn7qBwfkEocM21oIKjjo9 oj/KAq5ocLFS10YgWzvx3nsN9dMLrIVrBQPw2tqWVHHwOt3T5X8hqUvSkJ/7ucy90o587+XVW Nt3caLTiEePdyapNlOc8gGIe5my0xqSyv0VqT5ir/L9jEioYrVLJ2j6tBo9C11cxC5q14vksZ da2Jc4da3ZeymMC+OG4jGq/Jjw1EruCYxIW0Yk/YLvBVD6m5eaEPZXGJUbwgXu4yKWjinAzPC lGWqbEEfW3UhkdeKbI3jZLN58pg4Fr5M4clWygWNFFO+3 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 On 10/17/22 22:29, Simon Glass wrote: > Add the concept of an OS name to the bootflow. This typically includes t= he > OS name, version and kernel version. > > Implement this for the distro and script bootmeths so that it works with > Armbian and older version of Fedora. How do you plan to detect the distro? Best regards Heinrich > > Signed-off-by: Simon Glass > --- > > boot/bootflow.c | 1 + > boot/bootmeth_distro.c | 36 ++++++++++++++++++++++++++++++++++++ > boot/bootmeth_script.c | 34 ++++++++++++++++++++++++++++++++++ > cmd/bootflow.c | 1 + > include/bootflow.h | 3 +++ > test/boot/bootflow.c | 1 + > 6 files changed, 76 insertions(+) > > diff --git a/boot/bootflow.c b/boot/bootflow.c > index f9ad4099244..163cd4953dd 100644 > --- a/boot/bootflow.c > +++ b/boot/bootflow.c > @@ -354,6 +354,7 @@ void bootflow_free(struct bootflow *bflow) > free(bflow->subdir); > free(bflow->fname); > free(bflow->buf); > + free(bflow->os_name); > } > > void bootflow_remove(struct bootflow *bflow) > diff --git a/boot/bootmeth_distro.c b/boot/bootmeth_distro.c > index 5c6c687f0a6..6ef0fa1f2c9 100644 > --- a/boot/bootmeth_distro.c > +++ b/boot/bootmeth_distro.c > @@ -66,6 +66,38 @@ static int distro_check(struct udevice *dev, struct b= ootflow_iter *iter) > return 0; > } > > +/** > + * distro_fill_info() - Decode the extlinux file to find out distro inf= o > + * > + * @bflow: Bootflow to process > + * @return 0 if OK, -ve on error > + */ > +static int distro_fill_info(struct bootflow *bflow) > +{ > + struct membuff mb; > + char line[200]; > + char *data; > + int len; > + > + log_debug("parsing bflow file size %x\n", bflow->size); > + membuff_init(&mb, bflow->buf, bflow->size); > + membuff_putraw(&mb, bflow->size, true, &data); > + while (len =3D membuff_readline(&mb, line, sizeof(line) - 1, ' '), len= ) { > + char *tok, *p =3D line; > + > + tok =3D strsep(&p, " "); > + if (p) { > + if (!strcmp("label", tok)) { > + bflow->os_name =3D strdup(p); > + if (!bflow->os_name) > + return log_msg_ret("os", -ENOMEM); > + } > + } > + } > + > + return 0; > +} > + > static int distro_read_bootflow(struct udevice *dev, struct bootflow *= bflow) > { > struct blk_desc *desc; > @@ -99,6 +131,10 @@ static int distro_read_bootflow(struct udevice *dev,= struct bootflow *bflow) > if (ret) > return log_msg_ret("read", ret); > > + ret =3D distro_fill_info(bflow); > + if (ret) > + return log_msg_ret("inf", ret); > + > return 0; > } > > diff --git a/boot/bootmeth_script.c b/boot/bootmeth_script.c > index d1c3f940037..8ba9d93a080 100644 > --- a/boot/bootmeth_script.c > +++ b/boot/bootmeth_script.c > @@ -35,6 +35,36 @@ static int script_check(struct udevice *dev, struct b= ootflow_iter *iter) > return 0; > } > > +/** > + * script_fill_info() - Decode the U-Boot script to find out distro inf= o > + * > + * @bflow: Bootflow to process > + * @return 0 if OK, -ve on error > + */ > +static int script_fill_info(struct bootflow *bflow) > +{ > + char *name =3D NULL; > + char *data; > + uint len; > + int ret; > + > + log_debug("parsing bflow file size %x\n", bflow->size); > + > + ret =3D image_locate_script(bflow->buf, bflow->size, NULL, &data, &len= ); > + if (!ret) { > + if (strstr(data, "armbianEnv")) > + name =3D "Armbian"; > + } > + > + if (name) { > + bflow->os_name =3D strdup(name); > + if (!bflow->os_name) > + return log_msg_ret("os", -ENOMEM); > + } > + > + return 0; > +} > + > static int script_read_bootflow(struct udevice *dev, struct bootflow *= bflow) > { > struct blk_desc *desc =3D NULL; > @@ -75,6 +105,10 @@ static int script_read_bootflow(struct udevice *dev,= struct bootflow *bflow) > if (ret) > return log_msg_ret("read", ret); > > + ret =3D script_fill_info(bflow); > + if (ret) > + return log_msg_ret("inf", ret); > + > return 0; > } > > diff --git a/cmd/bootflow.c b/cmd/bootflow.c > index 313103d2775..6b8ac8c8504 100644 > --- a/cmd/bootflow.c > +++ b/cmd/bootflow.c > @@ -337,6 +337,7 @@ static int do_bootflow_info(struct cmd_tbl *cmdtp, i= nt flag, int argc, > printf("Filename: %s\n", bflow->fname); > printf("Buffer: %lx\n", (ulong)map_to_sysmem(bflow->buf)); > printf("Size: %x (%d bytes)\n", bflow->size, bflow->size); > + printf("OS: %s\n", bflow->os_name ? bflow->os_name : "(none)"); > printf("Error: %d\n", bflow->err); > if (dump && bflow->buf) { > /* Set some sort of maximum on the size */ > diff --git a/include/bootflow.h b/include/bootflow.h > index 32dbbbbe261..776158c65df 100644 > --- a/include/bootflow.h > +++ b/include/bootflow.h > @@ -52,6 +52,8 @@ enum bootflow_state_t { > * @buf: Bootflow file contents (allocated) > * @size: Size of bootflow file in bytes > * @err: Error number received (0 if OK) > + * @os_name: Name of the OS / distro being booted, or NULL if not known > + * (allocated) > */ > struct bootflow { > struct list_head bm_node; > @@ -68,6 +70,7 @@ struct bootflow { > char *buf; > int size; > int err; > + char *os_name; > }; > > /** > diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c > index e1e07082105..3296316cf0d 100644 > --- a/test/boot/bootflow.c > +++ b/test/boot/bootflow.c > @@ -188,6 +188,7 @@ static int bootflow_cmd_info(struct unit_test_state = *uts) > ut_assert_nextline("Filename: /extlinux/extlinux.conf"); > ut_assert_nextlinen("Buffer: "); > ut_assert_nextline("Size: 253 (595 bytes)"); > + ut_assert_nextline("OS: Fedora-Workstation-armhfp-31-1.9 (5.3.7= -301.fc31.armv7hl)"); > ut_assert_nextline("Error: 0"); > ut_assert_console_end(); >