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 63DD7C4332F for ; Mon, 17 Oct 2022 20:34:03 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9FF1484F9C; Mon, 17 Oct 2022 22:31:21 +0200 (CEST) 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="c1HqoxEG"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4A70584F87; Mon, 17 Oct 2022 22:31:02 +0200 (CEST) Received: from mail-io1-xd32.google.com (mail-io1-xd32.google.com [IPv6:2607:f8b0:4864:20::d32]) (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 9CE9C84E93 for ; Mon, 17 Oct 2022 22:30:30 +0200 (CEST) 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-io1-xd32.google.com with SMTP id 187so10094397iov.10 for ; Mon, 17 Oct 2022 13:30:30 -0700 (PDT) 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=WYyLuD1ryz7TwaohIhNCJcrKymjo9viJQdW33/6gj4A=; b=c1HqoxEGyuOI5h9Cb61COjnXw8m4xekLXmoASmri/hFxCAr/aO17LPm2KxkvU2qs7g tW35hJe7P+XIP2gNVwwwiGLgaaJ11Yn4vJlXOD/tTdfFLeWRhfTBpWzG4cpz1Iqa9gvy 9BzltJF1OXzvuxdp8v2dt6qcjmvJi3M19LeuA= 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=WYyLuD1ryz7TwaohIhNCJcrKymjo9viJQdW33/6gj4A=; b=gyqv4e1MbmXnFzLiC8wxyeuKh43IUZb3Mfoc/tig/MQxGJ+/l5dWikcSmFFGGHLp13 2DT9f0y5aYQN6gRF42hzxU1lXmfGNrwpel73abAWj0KPIEM2JWH/sqdz073xdCSmt3aS CsmOUNvsm3iHBpZWh5wt2uZ/WU/Ze8tB0kl+BJOvkxmaUSUjQ6sZAAs9wa0XdcxQLyFB tV1IiqhvKpgXMG9qq9clyfMCnbhFrHgUcH7VWKU3+FynUYpiT3pT8BMbkHE1CeTgQGj/ L93LwV5Tbf82E2Hn5DeFR3+iGDxUjGat2pJOESE2L/lVQG+ElVnsd2E1L0jg4ViHaTk7 agpQ== X-Gm-Message-State: ACrzQf3euMe/W42s64kitLPrXA6YnB5QejVyQYrnC2vbCw1RCa6ZUhcs paFHP/FEA6Ockqf95Z5nSZr4y7xrZzXG1w== X-Google-Smtp-Source: AMsMyM43FPSjakUMhTWpxVnjgWc50xJjSNks1xdUyfS7mNG5HzVVi5URkxrVvxLGyU0W0jRe+in6Cg== X-Received: by 2002:a05:6638:13c4:b0:35a:55df:29b2 with SMTP id i4-20020a05663813c400b0035a55df29b2mr6347872jaj.85.1666038627803; Mon, 17 Oct 2022 13:30:27 -0700 (PDT) Received: from kea.bld.corp.google.com ([2620:15c:183:200:91e:7804:2764:d161]) by smtp.gmail.com with ESMTPSA id j9-20020a926e09000000b002e939413e83sm258071ilc.48.2022.10.17.13.30.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 13:30:27 -0700 (PDT) From: Simon Glass To: u-boot@lists.denx.de Cc: Anatolij Gustschin , Tom Rini , Simon Glass Subject: [PATCH 14/24] bootstd: Read the Operating System name for distro/scripts Date: Mon, 17 Oct 2022 14:29:50 -0600 Message-Id: <20221017203000.2207887-15-sjg@chromium.org> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog In-Reply-To: <20221017203000.2207887-1-sjg@chromium.org> References: <20221017203000.2207887-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 --- 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 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 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.38.0.413.g74048e4d9e-goog