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 87DD6C4708D for ; Fri, 6 Jan 2023 14:56:42 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 264CF8562C; Fri, 6 Jan 2023 15:53:56 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org 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; unprotected) header.d=chromium.org header.i=@chromium.org header.b="R7RfBrp0"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D3411853E0; Fri, 6 Jan 2023 15:53:42 +0100 (CET) Received: from mail-il1-x129.google.com (mail-il1-x129.google.com [IPv6:2607:f8b0:4864:20::129]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id F0C09852B6 for ; Fri, 6 Jan 2023 15:53:02 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-il1-x129.google.com with SMTP id h26so1069047ila.11 for ; Fri, 06 Jan 2023 06:53:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kBo4dveQZ6q3nA9rM4cJRVGW9/18duoaDWzBTSPaLtg=; b=R7RfBrp0jzOXoXFqf5ogxZUMRWexssTJICJ1y7a/DYQLK2YUaQnph+SXfHqyRl29Kw 2YpHp9FW0IMaPiSLjWe93pSvXMgLKalL6khlfsCJTQlhaEfuWxV14vBjAyPHp+spTqZo K53UC/aTrkTlg4yQkLaSnmqSmxiUQVnEEU6sk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kBo4dveQZ6q3nA9rM4cJRVGW9/18duoaDWzBTSPaLtg=; b=OUB6CE/spxs92jFqg6S6CABQCSC3uB5pZp/+J7EMcPGUNCC2IT2sWizIWGaY7Ow8IW vIiIrqEEspeiq9g7MP1IBHbl8qZrSbotBmZwrC3WDu5RGGfNUryDHJrZh7fADwvmy2zM SISf4+cAQc6J+ZPnWEAP1+i6SweYBiJ7S1Iu5hSILp1uQw7UJS6meZ3ekGOM33VEXrQ2 7Njo4XOdGSMyNKKCMyNtrZbG1OjN3meiQESRdQszO/zCSP1Cqd5vsFPTsBGP8IHapuCK ysB0CDiOEpgHnylAZ/4I7sujHw4QVa64hb7zFFSLfTDTdbyCho2i8ynrmLcccfF+P5xo /7dw== X-Gm-Message-State: AFqh2krt8cxtgNVcsnvOysKH8Qi2Yhqa6zrC17r7z8WzP07Nqvje+WC3 4OjVIgOTlcA79PndYDH/vJH4iyJED6kn4wy0Hdk= X-Google-Smtp-Source: AMrXdXtS1+TSKQ1OUE6GPmT6EfUNz9XUNBZAcSzdihWbliicQ2ayOlVHNJqXH1QtysvmuQtvDIjn7Q== X-Received: by 2002:a92:6c03:0:b0:30d:7dcc:162a with SMTP id h3-20020a926c03000000b0030d7dcc162amr3868271ilc.22.1673016782384; Fri, 06 Jan 2023 06:53:02 -0800 (PST) Received: from sjg1.lan (c-71-56-217-229.hsd1.co.comcast.net. [71.56.217.229]) by smtp.gmail.com with ESMTPSA id w20-20020a05663800d400b00375783003fcsm360273jao.136.2023.01.06.06.53.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Jan 2023 06:53:02 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Anatolij Gustschin , Tom Rini , Heinrich Schuchardt , Simon Glass Subject: [PATCH v3 15/25] bootstd: Read the Operating System name for distro/scripts Date: Fri, 6 Jan 2023 08:52:33 -0600 Message-Id: <20230106145243.411626-16-sjg@chromium.org> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog In-Reply-To: <20230106145243.411626-1-sjg@chromium.org> References: <20230106145243.411626-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Add the concept of an OS name to the bootflow. This typically includes the 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. Signed-off-by: Simon Glass --- (no changes since v1) 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 bootflow_iter *iter) return 0; } +/** + * distro_fill_info() - Decode the extlinux file to find out distro info + * + * @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 = membuff_readline(&mb, line, sizeof(line) - 1, ' '), len) { + char *tok, *p = line; + + tok = strsep(&p, " "); + if (p) { + if (!strcmp("label", tok)) { + bflow->os_name = 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 = 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 16c5dadcca1..6f2a09846db 100644 --- a/boot/bootmeth_script.c +++ b/boot/bootmeth_script.c @@ -35,6 +35,36 @@ static int script_check(struct udevice *dev, struct bootflow_iter *iter) return 0; } +/** + * script_fill_info() - Decode the U-Boot script to find out distro info + * + * @bflow: Bootflow to process + * @return 0 if OK, -ve on error + */ +static int script_fill_info(struct bootflow *bflow) +{ + char *name = NULL; + char *data; + uint len; + int ret; + + log_debug("parsing bflow file size %x\n", bflow->size); + + ret = image_locate_script(bflow->buf, bflow->size, NULL, &data, &len); + if (!ret) { + if (strstr(data, "armbianEnv")) + name = "Armbian"; + } + + if (name) { + bflow->os_name = 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 = 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 = 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, int 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(); -- 2.39.0.314.g84b9a713c41-goog