From patchwork Wed Nov 20 02:42:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Kerr X-Patchwork-Id: 1197784 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47Hngv0WlCz9sPV for ; Wed, 20 Nov 2019 14:08:11 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="TEwQRQFV"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47Hngt6gMLzDqxH for ; Wed, 20 Nov 2019 14:08:10 +1100 (AEDT) X-Original-To: petitboot@lists.ozlabs.org Delivered-To: petitboot@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [IPv6:2401:3900:2:1::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47Hn9W0ZtGzDqfY for ; Wed, 20 Nov 2019 13:45:19 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="TEwQRQFV"; dkim-atps=neutral Received: by ozlabs.org (Postfix, from userid 1023) id 47Hn9V66yFz9sPK; Wed, 20 Nov 2019 13:45:18 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1574217918; bh=rfR2YdduZtE8PFiuk2V3mZLyYnYD51/S/THjNQq1r8Q=; h=From:To:Subject:Date:In-Reply-To:References:From; b=TEwQRQFVz2RSq+ZnOJ4wmMywggt9Offv9Lof/5Ts3kJi0vRRdhtGIhrnIpQnD3KzM Z5kU0lTKUhk/RggWhlTe/Q/XqSwh84GVe3KCQTqXE7sG3d4r7u7PbzHPIxCJtfWru9 s8XaIH9ZMs4BEdlAEwDxvHSC6tpiOqT2+15It5M8edBvE9NScBdtaRFNQkChUEbXlE hMeZDLzQBofaGscIZ5fwfVWltkFv5yVxbL+ncDXxHIau4nCP8yh4VEZA7d6ja0TgpF g8YjGcax4iu+BbR2o0DnyAoOmAoZavPTMnPXTf53jvYIsxeo5h5DTFdST3/Rn/vJPn KVXoK8f1entqA== From: Jeremy Kerr To: petitboot@lists.ozlabs.org Subject: [PATCH 01/14] discover/grub2: 'search' set-variable defaults to root Date: Wed, 20 Nov 2019 10:42:53 +0800 Message-Id: <20191120024306.16526-2-jk@ozlabs.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191120024306.16526-1-jk@ozlabs.org> References: <20191120024306.16526-1-jk@ozlabs.org> MIME-Version: 1.0 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" If no --set= argument is specified, default to the variable named 'root', as per current grub docs. Signed-off-by: Jeremy Kerr --- discover/grub2/builtins.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/discover/grub2/builtins.c b/discover/grub2/builtins.c index 7e92299..3f09319 100644 --- a/discover/grub2/builtins.c +++ b/discover/grub2/builtins.c @@ -113,7 +113,7 @@ static int builtin_search(struct grub2_script *script, const char *env_var, *spec; int i; - env_var = NULL; + env_var = "root"; for (i = 1; i < argc - 1; i++) { if (!strncmp(argv[i], "--set=", strlen("--set="))) { @@ -122,7 +122,7 @@ static int builtin_search(struct grub2_script *script, } } - if (!env_var) + if (!strlen(env_var)) return 0; spec = argv[argc - 1]; From patchwork Wed Nov 20 02:42:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Kerr X-Patchwork-Id: 1197775 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47Hnfq64Nlz9sPV for ; Wed, 20 Nov 2019 14:07:15 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="TNFQSf9B"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47Hnfq2dkwzDqBh for ; Wed, 20 Nov 2019 14:07:15 +1100 (AEDT) X-Original-To: petitboot@lists.ozlabs.org Delivered-To: petitboot@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47Hn9T4JSJzDqgs for ; Wed, 20 Nov 2019 13:45:17 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="TNFQSf9B"; dkim-atps=neutral Received: by ozlabs.org (Postfix, from userid 1023) id 47Hn9R1C7Lz9sPK; Wed, 20 Nov 2019 13:45:14 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1574217915; bh=vbRUHv+aXFTgYX/1+39Y6kd7UehaZhB5gRtsItiFPdI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=TNFQSf9BdLnLwOtFW/SfWEIoufQpyHio3rcyxl9Babk+cVhV9BP+4zYG/koRACCu0 oMPhK3N6dfHWG4vu3RxUn1f5m+DBW29amensKEYSHxuaPA4tflM8ynBU58PpJHUNT6 KQBzU7/DQo//UwjGW/hnnA0gRqiHwBtTqvqgHDGqbe861Is+ylMMGX/G6muo/nwH6K 0US9o6mKnTnnlLum5DGl393QBISn3kJLcM/CL/QJt60p6p7xW0Epl7KdTwuX3YW3hw gn1jeML+R8ZNR7XLEiAebNfHX/e5oJoqmf2lb/0UdRM9mqxEt3TK0YT2KchY7cgMF5 qqB+4GiAiTXEA== From: Jeremy Kerr To: petitboot@lists.ozlabs.org Subject: [PATCH 02/14] discover/grub2: Use getopt for `search` argument parsing Date: Wed, 20 Nov 2019 10:42:54 +0800 Message-Id: <20191120024306.16526-3-jk@ozlabs.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191120024306.16526-1-jk@ozlabs.org> References: <20191120024306.16526-1-jk@ozlabs.org> MIME-Version: 1.0 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" The search command will be extended to add the full set of grub2-style arguments, so switch to using getopt, rather than manual parsing. This means we now support `--set=foo` and `--set foo` style arguments, both of which appear in the docs and common grub configs. Also, add a small test for the search argument handling. Signed-off-by: Jeremy Kerr --- discover/grub2/builtins.c | 33 +++++++++++++++++++++++----- test/parser/Makefile.am | 1 + test/parser/test-grub2-search-args.c | 33 ++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 test/parser/test-grub2-search-args.c diff --git a/discover/grub2/builtins.c b/discover/grub2/builtins.c index 3f09319..ab6b0ec 100644 --- a/discover/grub2/builtins.c +++ b/discover/grub2/builtins.c @@ -1,4 +1,7 @@ +#define _GNU_SOURCE + +#include #include #include @@ -106,18 +109,35 @@ static int builtin_initrd(struct grub2_script *script, return 0; } +static const struct option search_options[] = { + { + .name = "set", + .has_arg = required_argument, + .val = 's', + }, + { 0 }, +}; + static int builtin_search(struct grub2_script *script, void *data __attribute__((unused)), int argc, char *argv[]) { const char *env_var, *spec; - int i; env_var = "root"; + optind = 0; + + for (;;) { + int c = getopt_long(argc, argv, ":", search_options, NULL); + if (c == -1) + break; - for (i = 1; i < argc - 1; i++) { - if (!strncmp(argv[i], "--set=", strlen("--set="))) { - env_var = argv[i] + strlen("--set="); + switch (c) { + case 's': + env_var = optarg; + break; + case '?': + case ':': break; } } @@ -125,7 +145,10 @@ static int builtin_search(struct grub2_script *script, if (!strlen(env_var)) return 0; - spec = argv[argc - 1]; + if (optind >= argc) + return -1; + + spec = argv[optind]; script_env_set(script, env_var, spec); diff --git a/test/parser/Makefile.am b/test/parser/Makefile.am index 748c836..df9c539 100644 --- a/test/parser/Makefile.am +++ b/test/parser/Makefile.am @@ -29,6 +29,7 @@ parser_TESTS = \ test/parser/test-grub2-multiple-id \ test/parser/test-grub2-single-line-if \ test/parser/test-grub2-pos-param \ + test/parser/test-grub2-search-args \ test/parser/test-grub2-load-env \ test/parser/test-grub2-save-env \ test/parser/test-grub2-save-env-dash-f \ diff --git a/test/parser/test-grub2-search-args.c b/test/parser/test-grub2-search-args.c new file mode 100644 index 0000000..ffce853 --- /dev/null +++ b/test/parser/test-grub2-search-args.c @@ -0,0 +1,33 @@ + +/* check for multiple styles of option parsing for the 'search' command */ + +#include "parser-test.h" + +#if 0 /* PARSER_EMBEDDED_CONFIG */ + +# no --set arugment will set the 'root' var +search a +search --set=v1 b +search --set v2 c + +menuentry $root$v1$v2 { + linux /vmlinux +} + +#endif + +void run_test(struct parser_test *test) +{ + struct discover_boot_option *opt; + struct discover_context *ctx; + + ctx = test->ctx; + + test_read_conf_embedded(test, "/grub/grub.cfg"); + + test_run_parser(test, "grub2"); + + check_boot_option_count(ctx, 1); + opt = get_boot_option(ctx, 0); + check_name(opt, "abc"); +} From patchwork Wed Nov 20 02:42:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Kerr X-Patchwork-Id: 1197780 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47HngV1GYzz9sPV for ; Wed, 20 Nov 2019 14:07:50 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="OHsgSPLs"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47HngT5ZwjzDqlS for ; Wed, 20 Nov 2019 14:07:49 +1100 (AEDT) X-Original-To: petitboot@lists.ozlabs.org Delivered-To: petitboot@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47Hn9V2TxmzDqgs for ; Wed, 20 Nov 2019 13:45:18 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="OHsgSPLs"; dkim-atps=neutral Received: by ozlabs.org (Postfix, from userid 1023) id 47Hn9V06hGz9sR4; Wed, 20 Nov 2019 13:45:17 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1574217918; bh=7UB96DxNgw6+I+rFOsD4T5vwHtcCiDFb3BcJxvehi8E=; h=From:To:Subject:Date:In-Reply-To:References:From; b=OHsgSPLs85FnVEw27nwoSPJ/1b2gRnbRu/u2Wz+N4mKI2hVQGAKm5P/ZcLpj+JdQW IkLSlam5gQ3jgG08rhUoF376b1by/X4/2BKAC/oM3V55d4NjbCtVv2zKbbICmnmbPG VmqnDYPrSLn7UQUVXxy/RooqcD50BlxZ3NPU/JGonopWwIsouBtQfbBpwHsd5t4nFX Ts1TIm06Jbnfb7+yfbksQuauW4SenlCs/cBBTQ+HT3piuGIcuziFfDaqpzSY+IZ6rR f4CCmGYhs/ynXu4RESsXpC860gH6cFO7YpFR/uLFM6QYhuawHTqzKzV06fwsYV/Nf1 OjGrGxut+RKPg== From: Jeremy Kerr To: petitboot@lists.ozlabs.org Subject: [PATCH 03/14] discover/grub2: test for (ignored) --no-floppy argument Date: Wed, 20 Nov 2019 10:42:55 +0800 Message-Id: <20191120024306.16526-4-jk@ozlabs.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191120024306.16526-1-jk@ozlabs.org> References: <20191120024306.16526-1-jk@ozlabs.org> MIME-Version: 1.0 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" --no-floppy is used almost everywhere, so add it to the tests. The code will already ignore unknown arguments, but ensure that this works OK. Signed-off-by: Jeremy Kerr --- test/parser/test-grub2-search-args.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/parser/test-grub2-search-args.c b/test/parser/test-grub2-search-args.c index ffce853..0eb5762 100644 --- a/test/parser/test-grub2-search-args.c +++ b/test/parser/test-grub2-search-args.c @@ -9,8 +9,10 @@ search a search --set=v1 b search --set v2 c +search --set=v3 --no-floppy d +search --no-floppy --set=v4 e -menuentry $root$v1$v2 { +menuentry $root$v1$v2$v3$v4 { linux /vmlinux } @@ -29,5 +31,5 @@ void run_test(struct parser_test *test) check_boot_option_count(ctx, 1); opt = get_boot_option(ctx, 0); - check_name(opt, "abc"); + check_name(opt, "abcde"); } From patchwork Wed Nov 20 02:42:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Kerr X-Patchwork-Id: 1197777 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47Hng81sh6z9sPV for ; Wed, 20 Nov 2019 14:07:32 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="gZ/XgRaA"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47Hng80qkpzDqbv for ; Wed, 20 Nov 2019 14:07:32 +1100 (AEDT) X-Original-To: petitboot@lists.ozlabs.org Delivered-To: petitboot@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [IPv6:2401:3900:2:1::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47Hn9T6hDmzDqTk for ; Wed, 20 Nov 2019 13:45:17 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="gZ/XgRaA"; dkim-atps=neutral Received: by ozlabs.org (Postfix, from userid 1023) id 47Hn9S71JRz9sPf; Wed, 20 Nov 2019 13:45:16 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1574217916; bh=xZtP0SsbZdmx55fnbDR/jNe+X9ieeLPwSKs1pGlMxwU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=gZ/XgRaAjSGhpIjznqvRgP5K2gt2B350OBYoYbELSWMDHyXYcrWKQkNnKVV2xP475 JeZjYh99hd4bsdVn2bBJC+DSe0FWPguHG7UieHFYLaIhN52XPR0xwI//cGaROABUjN oVukKS2maTLq6lQXFPiR39C1vln7uzFc5KUNQa9/YHC+Icnu49PCfV8ckss8TY7aIG lHhyT+ouSe5qGan00r5RWc0WIsCqZLEDCq4OlMz20FCXfAbQX6MooYL+pX2tWyATBy y6wzMzFGWZpeKW7qhQK6WGPEeWKbCOlXkPQklsjZTOsk8SOr3aqMk2nP0phjTqGGkP YK09zLA0geauA== From: Jeremy Kerr To: petitboot@lists.ozlabs.org Subject: [PATCH 04/14] discover/grub2: Add support for UUID and label for 'search' command Date: Wed, 20 Nov 2019 10:42:56 +0800 Message-Id: <20191120024306.16526-5-jk@ozlabs.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191120024306.16526-1-jk@ozlabs.org> References: <20191120024306.16526-1-jk@ozlabs.org> MIME-Version: 1.0 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" This change adds support for searching by UUID and filesystem label. We still fall back to passthrough if the UUID is not found, but we now resolve to device ID strings. Signed-off-by: Jeremy Kerr --- discover/grub2/builtins.c | 55 +++++++++++++++++++++++++-- test/parser/Makefile.am | 2 + test/parser/test-grub2-search-label.c | 47 +++++++++++++++++++++++ test/parser/test-grub2-search-uuid.c | 55 +++++++++++++++++++++++++++ 4 files changed, 156 insertions(+), 3 deletions(-) create mode 100644 test/parser/test-grub2-search-label.c create mode 100644 test/parser/test-grub2-search-uuid.c diff --git a/discover/grub2/builtins.c b/discover/grub2/builtins.c index ab6b0ec..7cac9f1 100644 --- a/discover/grub2/builtins.c +++ b/discover/grub2/builtins.c @@ -115,6 +115,21 @@ static const struct option search_options[] = { .has_arg = required_argument, .val = 's', }, + { + .name = "file", + .has_arg = no_argument, + .val = 'f', + }, + { + .name = "label", + .has_arg = no_argument, + .val = 'l', + }, + { + .name = "fs-uuid", + .has_arg = no_argument, + .val = 'u', + }, { 0 }, }; @@ -122,13 +137,23 @@ static int builtin_search(struct grub2_script *script, void *data __attribute__((unused)), int argc, char *argv[]) { - const char *env_var, *spec; + const char *env_var, *spec, *res; + struct discover_device *dev; + enum { + LOOKUP_UUID = 'u', + LOOKUP_LABEL = 'l', + LOOKUP_FILE = 'f', + } lookup_type; env_var = "root"; optind = 0; + /* Default to UUID, for backwards compat with earlier petitboot + * versions. This argument is non-optional in GRUB. */ + lookup_type = LOOKUP_UUID; + for (;;) { - int c = getopt_long(argc, argv, ":", search_options, NULL); + int c = getopt_long(argc, argv, ":flu", search_options, NULL); if (c == -1) break; @@ -136,6 +161,11 @@ static int builtin_search(struct grub2_script *script, case 's': env_var = optarg; break; + case LOOKUP_UUID: + case LOOKUP_LABEL: + case LOOKUP_FILE: + lookup_type = c; + break; case '?': case ':': break; @@ -149,8 +179,27 @@ static int builtin_search(struct grub2_script *script, return -1; spec = argv[optind]; + res = NULL; + + switch (lookup_type) { + case LOOKUP_UUID: + dev = device_lookup_by_uuid(script->ctx->handler, + spec); + res = dev ? dev->device->id : spec; + break; + case LOOKUP_LABEL: + dev = device_lookup_by_label(script->ctx->handler, + spec); + if (dev) + res = dev->device->id; + break; + case LOOKUP_FILE: + /* not yet implemented */ + break; + } - script_env_set(script, env_var, spec); + if (res) + script_env_set(script, env_var, res); return 0; } diff --git a/test/parser/Makefile.am b/test/parser/Makefile.am index df9c539..f5985d6 100644 --- a/test/parser/Makefile.am +++ b/test/parser/Makefile.am @@ -30,6 +30,8 @@ parser_TESTS = \ test/parser/test-grub2-single-line-if \ test/parser/test-grub2-pos-param \ test/parser/test-grub2-search-args \ + test/parser/test-grub2-search-uuid \ + test/parser/test-grub2-search-label \ test/parser/test-grub2-load-env \ test/parser/test-grub2-save-env \ test/parser/test-grub2-save-env-dash-f \ diff --git a/test/parser/test-grub2-search-label.c b/test/parser/test-grub2-search-label.c new file mode 100644 index 0000000..b9ee034 --- /dev/null +++ b/test/parser/test-grub2-search-label.c @@ -0,0 +1,47 @@ +/* check for grub2 search command, searching by partition label */ + +#include "parser-test.h" + +#if 0 /* PARSER_EMBEDDED_CONFIG */ + +# valid label +search --set=v1 --label testlabel + +v2=prev +# invalid label: does not alter v2 +search --set=v2 --label invalidlabel + +menuentry $v1 { + linux /vmlinux +} + +menuentry $v2 { + linux /vmlinux +} + +#endif + +void run_test(struct parser_test *test) +{ + struct discover_boot_option *opt; + struct discover_context *ctx; + struct discover_device *dev; + + ctx = test->ctx; + + dev = test_create_device(test, "testdev"); + dev->label = "testlabel"; + device_handler_add_device(test->handler, dev); + + test_read_conf_embedded(test, "/grub/grub.cfg"); + + test_run_parser(test, "grub2"); + + check_boot_option_count(ctx, 2); + + opt = get_boot_option(ctx, 0); + check_name(opt, "testdev"); + + opt = get_boot_option(ctx, 1); + check_name(opt, "prev"); +} diff --git a/test/parser/test-grub2-search-uuid.c b/test/parser/test-grub2-search-uuid.c new file mode 100644 index 0000000..7eacd1d --- /dev/null +++ b/test/parser/test-grub2-search-uuid.c @@ -0,0 +1,55 @@ +/* check for grub2 search command, searching by FS UUID */ + +#include "parser-test.h" + +#if 0 /* PARSER_EMBEDDED_CONFIG */ + +# valid UUID +search --set=v1 --fs-uuid ee0cc6fa-1dba-48f2-8f5b-19e4b8de8c37 + +# invalid UUID: will fall back to passing the UUID through +search --set=v2 --fs-uuid 92b0da57-6e04-4e54-960b-85e6bb060433 + +# no 'type' argument defaults to UUID search +search --set=v3 ee0cc6fa-1dba-48f2-8f5b-19e4b8de8c37 + +menuentry $v1 { + linux /vmlinux +} + +menuentry $v2 { + linux /vmlinux +} + +menuentry $v3 { + linux /vmlinux +} +#endif + +void run_test(struct parser_test *test) +{ + struct discover_boot_option *opt; + struct discover_context *ctx; + struct discover_device *dev; + + ctx = test->ctx; + + dev = test_create_device(test, "testdev"); + dev->uuid = "ee0cc6fa-1dba-48f2-8f5b-19e4b8de8c37"; + device_handler_add_device(test->handler, dev); + + test_read_conf_embedded(test, "/grub/grub.cfg"); + + test_run_parser(test, "grub2"); + + check_boot_option_count(ctx, 3); + + opt = get_boot_option(ctx, 0); + check_name(opt, dev->device->id); + + opt = get_boot_option(ctx, 1); + check_name(opt, "92b0da57-6e04-4e54-960b-85e6bb060433"); + + opt = get_boot_option(ctx, 2); + check_name(opt, dev->device->id); +} From patchwork Wed Nov 20 02:42:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Kerr X-Patchwork-Id: 1197785 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47Hngz6LTXz9sPV for ; Wed, 20 Nov 2019 14:08:15 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="HYOv69+t"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47Hngz5TJszDqxl for ; Wed, 20 Nov 2019 14:08:15 +1100 (AEDT) X-Original-To: petitboot@lists.ozlabs.org Delivered-To: petitboot@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47Hn9W3PzRzDqHl for ; Wed, 20 Nov 2019 13:45:19 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="HYOv69+t"; dkim-atps=neutral Received: by ozlabs.org (Postfix, from userid 1023) id 47Hn9W1Kshz9sPW; Wed, 20 Nov 2019 13:45:19 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1574217919; bh=Y3QuwFuVlIis2jf2S0K7XvCMtpCBbIVy9QIQNckIS9Y=; h=From:To:Subject:Date:In-Reply-To:References:From; b=HYOv69+tv0tvtfVUERnxmbxqN+aIvhQtRW7DzTiZHJaZfl6zar39vXcFG7GPfd3B9 BWalKdYsKcigWfHIZHZrxml7gW5/mEE/H0b2R517f90/Yf1MleWD6lgZUC/GTQvJou ECoaAl95Omo7QuB6uvmRXOh0ITYODFeNUc4/p24JwVU+OBPO9RHmig7rT2vwB5pAZ9 aDKqUWs3F+6ZjAiPLh2CpjhEP9qPv9RhbZr4r3K4bkGuj3LcAJZnbB+FYGdK3VTMXO mXcdKu6//nddcwb7IvowjgyN/K2UtYd+bQrGlXQMp1gFQaKvUfAeFgsUpJGDtht+ML gs80I7kf2OrqQ== From: Jeremy Kerr To: petitboot@lists.ozlabs.org Subject: [PATCH 05/14] discover/grub2: expose a struct for grub2 file references Date: Wed, 20 Nov 2019 10:42:57 +0800 Message-Id: <20191120024306.16526-6-jk@ozlabs.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191120024306.16526-1-jk@ozlabs.org> References: <20191120024306.16526-1-jk@ozlabs.org> MIME-Version: 1.0 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" Currently, we have struct grub2_resource_info to keep references to boot payloads that may be returned in boot options, and be (conditionally) resolved by the parser. We'd also like to use the same semantics for other file references in the grub2 parser, for arbitrary usage in scripts - where files are also referenced by a path and an optional device. To do this, this change moves struct grub2_resource_info to grub2.h, and renames to struct grub2_file. Future changes will use this for script-internal file handling. Signed-off-by: Jeremy Kerr --- discover/grub2/grub2.c | 24 +++++++++--------------- discover/grub2/grub2.h | 8 ++++++++ 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/discover/grub2/grub2.c b/discover/grub2/grub2.c index f62ccdd..412298b 100644 --- a/discover/grub2/grub2.c +++ b/discover/grub2/grub2.c @@ -33,17 +33,12 @@ static const char *const grub2_conf_files[] = { NULL }; -struct grub2_resource_info { - char *root; - char *path; -}; - /* we use slightly different resources for grub2 */ struct resource *create_grub2_resource(struct discover_boot_option *opt, struct discover_device *orig_device, const char *root, const char *path) { - struct grub2_resource_info *info; + struct grub2_file *file; struct resource *res; if (strstr(path, "://")) { @@ -55,13 +50,12 @@ struct resource *create_grub2_resource(struct discover_boot_option *opt, res = talloc(opt, struct resource); if (root) { - info = talloc(res, struct grub2_resource_info); - talloc_reference(info, root); - info->root = talloc_strdup(info, root); - info->path = talloc_strdup(info, path); + file = talloc(res, struct grub2_file); + file->dev = talloc_strdup(file, root); + file->path = talloc_strdup(file, path); res->resolved = false; - res->info = info; + res->info = file; } else resolve_resource_against_device(res, orig_device, path); @@ -72,18 +66,18 @@ struct resource *create_grub2_resource(struct discover_boot_option *opt, bool resolve_grub2_resource(struct device_handler *handler, struct resource *res) { - struct grub2_resource_info *info = res->info; + struct grub2_file *file = res->info; struct discover_device *dev; assert(!res->resolved); - dev = device_lookup_by_uuid(handler, info->root); + dev = device_lookup_by_uuid(handler, file->dev); if (!dev) return false; - resolve_resource_against_device(res, dev, info->path); - talloc_free(info); + resolve_resource_against_device(res, dev, file->path); + talloc_free(file); return true; } diff --git a/discover/grub2/grub2.h b/discover/grub2/grub2.h index 68176fb..73d91b2 100644 --- a/discover/grub2/grub2.h +++ b/discover/grub2/grub2.h @@ -107,6 +107,14 @@ struct grub2_parser { bool inter_word; }; +/* References to files in grub2 consist of an optional device and a path + * (specified here by UUID). If the dev is unspecified, we fall back to a + * default - usually the 'root' environment variable. */ +struct grub2_file { + char *dev; + char *path; +}; + /* type for builtin functions */ typedef int (*grub2_function)(struct grub2_script *script, void *data, int argc, char *argv[]); From patchwork Wed Nov 20 02:42:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Kerr X-Patchwork-Id: 1197774 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (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) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47Hnfh032Pz9sPV for ; Wed, 20 Nov 2019 14:07:08 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="TLtXQd75"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47Hnfg1t8lzDqsp for ; Wed, 20 Nov 2019 14:07:07 +1100 (AEDT) X-Original-To: petitboot@lists.ozlabs.org Delivered-To: petitboot@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47Hn9T4L52zDqhC for ; Wed, 20 Nov 2019 13:45:17 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="TLtXQd75"; dkim-atps=neutral Received: by ozlabs.org (Postfix, from userid 1023) id 47Hn9S3nJtz9s7T; Wed, 20 Nov 2019 13:45:15 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1574217916; bh=hESQiWivjHsjHiAwV5sJUjWP4ol7Gsbkdu4q3NxpYy0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=TLtXQd75XXZVKF5uNO8d7roPp/KuH3+zjiN+KSD6rcJazlUDuFwWGOUA1oGnN+CGY ou4oHu1/qLgJ+QmS4a2ij6aIPBRg4ahcl0GpIFXZkjOwnjfki67iGo0qjvxf3cpW1I 5BAd72S50qHj9f0ZEYIeNC+vKh8FVx87SUAsMPHg0al2a/fJ8HEVdy9ITl1SshYYSw CNVA5Lj4LgrQFnEBkxsByH3O7Eqq0CFtzUrg6cBttFPkQu12oG0oMT0uwjBcrsbKHu 1Z+XM8Z1rnhcxte1ThZXkldZgW76b9jP7LgCEs6l+teUAPh16avB7z4DG9wXbYBRV1 KDFJnA0C5g8Zg== From: Jeremy Kerr To: petitboot@lists.ozlabs.org Subject: [PATCH 06/14] discover/grub2: Add parsing code for grub2 file specifiers Date: Wed, 20 Nov 2019 10:42:58 +0800 Message-Id: <20191120024306.16526-7-jk@ozlabs.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191120024306.16526-1-jk@ozlabs.org> References: <20191120024306.16526-1-jk@ozlabs.org> MIME-Version: 1.0 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" This change adds a (currently unused) function to parse (device)/path references from grub scripts. Signed-off-by: Jeremy Kerr --- discover/grub2/grub2.c | 38 ++++++++++++++++++++++++++++++++++++++ discover/grub2/grub2.h | 4 ++++ 2 files changed, 42 insertions(+) diff --git a/discover/grub2/grub2.c b/discover/grub2/grub2.c index 412298b..3873720 100644 --- a/discover/grub2/grub2.c +++ b/discover/grub2/grub2.c @@ -82,6 +82,44 @@ bool resolve_grub2_resource(struct device_handler *handler, return true; } +struct grub2_file *grub2_parse_file(struct grub2_script *script, + const char *str) +{ + struct grub2_file *file; + size_t dev_len; + char *pos; + + if (!str) + return NULL; + + file = talloc_zero(script, struct grub2_file); + + if (*str != '(') { + /* just a path - no device, return path as-is */ + file->path = talloc_strdup(file, str); + + } else { + /* device plus path - split into components */ + + pos = strchr(str, ')'); + + /* no closing bracket, or zero-length path? */ + if (!pos || *(pos+1) == '\0') { + talloc_free(file); + return NULL; + } + + file->path = talloc_strdup(file, pos + 1); + + dev_len = pos - str - 1; + if (dev_len) + file->dev = talloc_strndup(file, str + 1, dev_len); + } + + return file; +} + + static int grub2_parse(struct discover_context *dc) { const char * const *filename; diff --git a/discover/grub2/grub2.h b/discover/grub2/grub2.h index 73d91b2..8c4839b 100644 --- a/discover/grub2/grub2.h +++ b/discover/grub2/grub2.h @@ -198,6 +198,10 @@ struct resource *create_grub2_resource(struct discover_boot_option *opt, bool resolve_grub2_resource(struct device_handler *handler, struct resource *res); +/* grub-style device+path parsing */ +struct grub2_file *grub2_parse_file(struct grub2_script *script, + const char *str); + /* external parser api */ struct grub2_parser *grub2_parser_create(struct discover_context *ctx); void grub2_parser_parse(struct grub2_parser *parser, const char *filename, From patchwork Wed Nov 20 02:42:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Kerr X-Patchwork-Id: 1197782 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47Hngh74D4z9sPV for ; Wed, 20 Nov 2019 14:08:00 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="E4qNSElI"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47Hngh658wzDqw9 for ; Wed, 20 Nov 2019 14:08:00 +1100 (AEDT) X-Original-To: petitboot@lists.ozlabs.org Delivered-To: petitboot@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47Hn9V54ZkzDqWk for ; Wed, 20 Nov 2019 13:45:18 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="E4qNSElI"; dkim-atps=neutral Received: by ozlabs.org (Postfix, from userid 1023) id 47Hn9V3LbMz9s7T; Wed, 20 Nov 2019 13:45:18 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1574217918; bh=0V2P04QCX8k5jUjT9/gxPymlDnE3UjQdgWpZiFJxgg4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=E4qNSElIMqG/zGt044I3i6K55rX3NykHLSZKltmqCG64ruVrYE6+9Sd4dri6Bldck /TnX2VzaxgplCs/EsqHQcp2uBpl51y/RVCr7y0sJp7mWnejtBg2qLBM4a5VVQ26lrN sUJ6B0VLfYuhc03SAkTjfVkq8ObxV0Mbd2mSlIEZoa1lps0J1MU625/W0CfXQS8kgb FStJrUzQ8Na1A4NossJdsgt7RBwIEsX9karrGCEvPHZcUX9C3DraAeXfqkGejo8fs9 bm+O1sM3oM6cSv/P/EXrnt5xpXjCcgbaMb5mFr3BY82CuarJFcLfC0QxrBwUc1dL64 /N3yzESshbakw== From: Jeremy Kerr To: petitboot@lists.ozlabs.org Subject: [PATCH 07/14] discover/grub2: add support for grub2-style path specifiers in resources Date: Wed, 20 Nov 2019 10:42:59 +0800 Message-Id: <20191120024306.16526-8-jk@ozlabs.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191120024306.16526-1-jk@ozlabs.org> References: <20191120024306.16526-1-jk@ozlabs.org> MIME-Version: 1.0 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" This change incorporates the grub2-style (device)/path specifiers in the grub2 parser's resource code. This allows the boot option paths to use device-specific references. Device names are looked-up using the UUID and kernel IDs, but with the lookup logic specific to a new function (grub2_lookup_device), so that can be extended in a future change. Signed-off-by: Jeremy Kerr --- discover/grub2/blscfg.c | 19 +++---- discover/grub2/builtins.c | 15 ++---- discover/grub2/grub2.c | 56 +++++++++++++++----- discover/grub2/grub2.h | 5 +- test/parser/Makefile.am | 1 + test/parser/test-grub2-devpath.c | 88 ++++++++++++++++++++++++++++++++ 6 files changed, 147 insertions(+), 37 deletions(-) create mode 100644 test/parser/test-grub2-devpath.c diff --git a/discover/grub2/blscfg.c b/discover/grub2/blscfg.c index d4754aa..d08f8f0 100644 --- a/discover/grub2/blscfg.c +++ b/discover/grub2/blscfg.c @@ -166,7 +166,6 @@ static void bls_finish(struct conf_context *conf) struct discover_context *dc = conf->dc; struct discover_boot_option *opt = state->opt; struct boot_option *option = opt->option; - const char *root; char *filename; if (!state->image) { @@ -192,23 +191,21 @@ static void bls_finish(struct conf_context *conf) else option->name = talloc_strdup(option, state->image); - root = script_env_get(state->script, "root"); - - opt->boot_image = create_grub2_resource(opt, conf->dc->device, - root, state->image); + opt->boot_image = create_grub2_resource(state->script, opt, + state->image); if (state->initrd) - opt->initrd = create_grub2_resource(opt, conf->dc->device, - root, state->initrd); + opt->initrd = create_grub2_resource(state->script, opt, + state->initrd); if (state->dtb) - opt->dtb = create_grub2_resource(opt, conf->dc->device, - root, state->dtb); + opt->dtb = create_grub2_resource(state->script, opt, + state->dtb); char* args_sigfile_default = talloc_asprintf(opt, "%s.cmdline.sig", state->image); - opt->args_sig_file = create_grub2_resource(opt, conf->dc->device, - root, args_sigfile_default); + opt->args_sig_file = create_grub2_resource(state->script, opt, + args_sigfile_default); talloc_free(args_sigfile_default); option->is_default = option_is_default(state, option); diff --git a/discover/grub2/builtins.c b/discover/grub2/builtins.c index 7cac9f1..765c4d7 100644 --- a/discover/grub2/builtins.c +++ b/discover/grub2/builtins.c @@ -46,7 +46,6 @@ static int builtin_linux(struct grub2_script *script, int argc, char *argv[]) { struct discover_boot_option *opt = script->opt; - const char *root; int i; if (!opt) { @@ -61,10 +60,7 @@ static int builtin_linux(struct grub2_script *script, return -1; } - root = script_env_get(script, "root"); - - opt->boot_image = create_grub2_resource(opt, script->ctx->device, - root, argv[1]); + opt->boot_image = create_grub2_resource(script, opt, argv[1]); opt->option->boot_args = NULL; if (argc > 2) @@ -77,8 +73,8 @@ static int builtin_linux(struct grub2_script *script, char* args_sigfile_default = talloc_asprintf(opt, "%s.cmdline.sig", argv[1]); - opt->args_sig_file = create_grub2_resource(opt, script->ctx->device, - root, args_sigfile_default); + opt->args_sig_file = create_grub2_resource(script, opt, + args_sigfile_default); talloc_free(args_sigfile_default); return 0; } @@ -88,7 +84,6 @@ static int builtin_initrd(struct grub2_script *script, int argc, char *argv[]) { struct discover_boot_option *opt = script->opt; - const char *root; if (!opt) { pb_log("grub2 syntax error: 'initrd' statement outside " @@ -102,9 +97,7 @@ static int builtin_initrd(struct grub2_script *script, return -1; } - root = script_env_get(script, "root"); - opt->initrd = create_grub2_resource(opt, script->ctx->device, - root, argv[1]); + opt->initrd = create_grub2_resource(script, opt, argv[1]); return 0; } diff --git a/discover/grub2/grub2.c b/discover/grub2/grub2.c index 3873720..a08a320 100644 --- a/discover/grub2/grub2.c +++ b/discover/grub2/grub2.c @@ -33,13 +33,35 @@ static const char *const grub2_conf_files[] = { NULL }; +static struct discover_device *grub2_lookup_device( + struct device_handler *handler, const char *desc) +{ + struct discover_device *dev; + + if (!desc || !*desc) + return NULL; + + dev = device_lookup_by_id(handler, desc); + if (dev) + return dev; + + /* for now, only lookup by UUID */ + dev = device_lookup_by_uuid(handler, desc); + if (dev) + return dev; + + return NULL; +} + /* we use slightly different resources for grub2 */ -struct resource *create_grub2_resource(struct discover_boot_option *opt, - struct discover_device *orig_device, - const char *root, const char *path) +struct resource *create_grub2_resource(struct grub2_script *script, + struct discover_boot_option *opt, + const char *path) { + struct discover_device *dev; struct grub2_file *file; struct resource *res; + const char *root; if (strstr(path, "://")) { struct pb_url *url = pb_url_parse(opt, path); @@ -47,18 +69,29 @@ struct resource *create_grub2_resource(struct discover_boot_option *opt, return create_url_resource(opt, url); } + file = grub2_parse_file(script, path); + if (!file) + return NULL; + res = talloc(opt, struct resource); + root = script_env_get(script, "root"); - if (root) { - file = talloc(res, struct grub2_file); + if (!file->dev && root && strlen(root)) file->dev = talloc_strdup(file, root); - file->path = talloc_strdup(file, path); - res->resolved = false; - res->info = file; + /* if we don't have a device specified, or the lookup succeeds now, + * then we can resolve the resource right away */ + if (file->dev) + dev = grub2_lookup_device(script->ctx->handler, file->dev); + else + dev = script->ctx->device; - } else - resolve_resource_against_device(res, orig_device, path); + if (dev) { + resolve_resource_against_device(res, dev, file->path); + } else { + res->resolved = false; + res->info = talloc_steal(opt, file); + } return res; } @@ -71,8 +104,7 @@ bool resolve_grub2_resource(struct device_handler *handler, assert(!res->resolved); - dev = device_lookup_by_uuid(handler, file->dev); - + dev = grub2_lookup_device(handler, file->dev); if (!dev) return false; diff --git a/discover/grub2/grub2.h b/discover/grub2/grub2.h index 8c4839b..ef32d4b 100644 --- a/discover/grub2/grub2.h +++ b/discover/grub2/grub2.h @@ -191,9 +191,8 @@ void script_register_function(struct grub2_script *script, void register_builtins(struct grub2_script *script); /* resources */ -struct resource *create_grub2_resource(struct discover_boot_option *opt, - struct discover_device *orig_device, - const char *root, const char *path); +struct resource *create_grub2_resource(struct grub2_script *script, + struct discover_boot_option *opt, const char *path); bool resolve_grub2_resource(struct device_handler *handler, struct resource *res); diff --git a/test/parser/Makefile.am b/test/parser/Makefile.am index f5985d6..0378317 100644 --- a/test/parser/Makefile.am +++ b/test/parser/Makefile.am @@ -32,6 +32,7 @@ parser_TESTS = \ test/parser/test-grub2-search-args \ test/parser/test-grub2-search-uuid \ test/parser/test-grub2-search-label \ + test/parser/test-grub2-devpath \ test/parser/test-grub2-load-env \ test/parser/test-grub2-save-env \ test/parser/test-grub2-save-env-dash-f \ diff --git a/test/parser/test-grub2-devpath.c b/test/parser/test-grub2-devpath.c new file mode 100644 index 0000000..d1d00f1 --- /dev/null +++ b/test/parser/test-grub2-devpath.c @@ -0,0 +1,88 @@ +/* check grub2 device+path string parsing */ + +#include "parser-test.h" + +#if 0 /* PARSER_EMBEDDED_CONFIG */ + +# local +menuentry a { + linux /vmlinux +} + +# local, specified by root env var +root=00000000-0000-0000-0000-000000000001 +menuentry b { + linux /vmlinux +} + +# remote, specified by root env var +root=00000000-0000-0000-0000-000000000002 +menuentry c { + linux /vmlinux +} + +# local, full dev+path spec +menuentry d { + linux (00000000-0000-0000-0000-000000000001)/vmlinux +} + +# remote, full dev+path spec +menuentry e { + linux (00000000-0000-0000-0000-000000000002)/vmlinux +} + +# invalid: incomplete dev+path spec +menuentry f { + linux (00000000-0000-0000-0000-000000000001 +} + +# invalid: no path +menuentry g { + linux (00000000-0000-0000-0000-000000000001) +} + + +#endif + +void run_test(struct parser_test *test) +{ + struct discover_device *dev1, *dev2; + struct discover_boot_option *opt; + struct discover_context *ctx; + + ctx = test->ctx; + + /* set local uuid */ + dev1 = test->ctx->device; + dev1->uuid = "00000000-0000-0000-0000-000000000001"; + + dev2 = test_create_device(test, "extdev"); + dev2->uuid = "00000000-0000-0000-0000-000000000002"; + device_handler_add_device(ctx->handler, dev2); + + test_read_conf_embedded(test, "/grub/grub.cfg"); + + test_run_parser(test, "grub2"); + + check_boot_option_count(ctx, 5); + + opt = get_boot_option(ctx, 0); + check_name(opt, "a"); + check_resolved_local_resource(opt->boot_image, dev1, "/vmlinux"); + + opt = get_boot_option(ctx, 1); + check_name(opt, "b"); + check_resolved_local_resource(opt->boot_image, dev1, "/vmlinux"); + + opt = get_boot_option(ctx, 2); + check_name(opt, "c"); + check_resolved_local_resource(opt->boot_image, dev2, "/vmlinux"); + + opt = get_boot_option(ctx, 3); + check_name(opt, "d"); + check_resolved_local_resource(opt->boot_image, dev1, "/vmlinux"); + + opt = get_boot_option(ctx, 4); + check_name(opt, "e"); + check_resolved_local_resource(opt->boot_image, dev2, "/vmlinux"); +} From patchwork Wed Nov 20 02:43:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Kerr X-Patchwork-Id: 1197776 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47Hng20VTlz9sPV for ; Wed, 20 Nov 2019 14:07:26 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="KBt0xXgi"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47Hng15KRczDqsG for ; Wed, 20 Nov 2019 14:07:25 +1100 (AEDT) X-Original-To: petitboot@lists.ozlabs.org Delivered-To: petitboot@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [IPv6:2401:3900:2:1::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47Hn9V06f7zDqHl for ; Wed, 20 Nov 2019 13:45:18 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="KBt0xXgi"; dkim-atps=neutral Received: by ozlabs.org (Postfix, from userid 1023) id 47Hn9T1hhtz9sPc; Wed, 20 Nov 2019 13:45:16 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1574217917; bh=94PkWqYGMokyIgwrEWuqSl+bFj7lGb0aBnNltsnTyng=; h=From:To:Subject:Date:In-Reply-To:References:From; b=KBt0xXgiLQO4cTeJbLZ9wRr59B+rovqaBVDgiBVFdukVdi5yj0omzb3UNc2UpR2Iv ahM7VLOd6bm149+ZC2YT6FGPvlCGUSgg9A05wnU9BDijqXeab+Y0ervfimyNPx8g/+ F3Rl9bfBEcWkCHNlUiy05Owxnq+5UpZs+ClB73c/H6GeGtVYKEA5RvC6G/u0RcSryl e+ytBDyVfpud/KfORn4TFz15mm3Q+19XHfaDTTWHpyce3q3x1VWixPF+95vH5sQ4++ 1E6W++0CNIeUWUoeBmBc5bO+5vzHrFFoBrq//tbOquoWG+BWMllht3I5KaVRK0R9gz 6YpoG/tfw7UOA== From: Jeremy Kerr To: petitboot@lists.ozlabs.org Subject: [PATCH 08/14] discover/grub2: Allow (device)/path references in general script usage Date: Wed, 20 Nov 2019 10:43:00 +0800 Message-Id: <20191120024306.16526-9-jk@ozlabs.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191120024306.16526-1-jk@ozlabs.org> References: <20191120024306.16526-1-jk@ozlabs.org> MIME-Version: 1.0 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" Currently, we have support for grub2 (device)/path syntax for boot resources. This change allows this syntax for general paths in grub2 scripts (for example, -f tests). This involves exposing grub2_lookup_device, to allow the script execution code to resolve pathnames. Signed-off-by: Jeremy Kerr --- discover/grub2/builtins.c | 50 ++++++++++++++++--- discover/grub2/grub2.c | 4 +- discover/grub2/grub2.h | 2 + test/parser/Makefile.am | 1 + test/parser/test-grub2-devpath-scripting.c | 56 ++++++++++++++++++++++ 5 files changed, 104 insertions(+), 9 deletions(-) create mode 100644 test/parser/test-grub2-devpath-scripting.c diff --git a/discover/grub2/builtins.c b/discover/grub2/builtins.c index 765c4d7..c726216 100644 --- a/discover/grub2/builtins.c +++ b/discover/grub2/builtins.c @@ -197,6 +197,32 @@ static int builtin_search(struct grub2_script *script, return 0; } +static int parse_to_device_path(struct grub2_script *script, + const char *desc, struct discover_device **devp, + char **pathp) +{ + struct discover_device *dev; + struct grub2_file *file; + + file = grub2_parse_file(script, desc); + if (!file) + return -1; + + dev = script->ctx->device; + if (file->dev) + dev = grub2_lookup_device(script->ctx->handler, file->dev); + + if (!dev) + return -1; + + *devp = dev; + *pathp = talloc_strdup(script, file->path); + + talloc_free(file); + + return 0; +} + /* Note that GRUB does not follow symlinks in evaluating all file * tests but -s, unlike below. However, it seems like a bad idea to * emulate GRUB's behavior (e.g., it would take extra work), so we @@ -204,12 +230,17 @@ static int builtin_search(struct grub2_script *script, static bool builtin_test_op_file(struct grub2_script *script, char op, const char *file) { + struct discover_device *dev; + struct stat statbuf; bool result; + char *path; int rc; - struct stat statbuf; - rc = parser_stat_path(script->ctx, script->ctx->device, - file, &statbuf); + rc = parse_to_device_path(script, file, &dev, &path); + if (rc) + return false; + + rc = parser_stat_path(script->ctx, dev, path, &statbuf); if (rc) return false; @@ -237,16 +268,21 @@ static bool builtin_test_op_file(struct grub2_script *script, char op, static bool builtin_test_op_dir(struct grub2_script *script, char op, const char *dir) { - int rc; + struct discover_device *dev; struct stat statbuf; + char *path; + int rc; if (op != 'd') return false; - rc = parser_stat_path(script->ctx, script->ctx->device, dir, &statbuf); - if (rc) { + rc = parse_to_device_path(script, dir, &dev, &path); + if (rc) + return false; + + rc = parser_stat_path(script->ctx, dev, path, &statbuf); + if (rc) return false; - } return S_ISDIR(statbuf.st_mode); } diff --git a/discover/grub2/grub2.c b/discover/grub2/grub2.c index a08a320..a8d115f 100644 --- a/discover/grub2/grub2.c +++ b/discover/grub2/grub2.c @@ -33,8 +33,8 @@ static const char *const grub2_conf_files[] = { NULL }; -static struct discover_device *grub2_lookup_device( - struct device_handler *handler, const char *desc) +struct discover_device *grub2_lookup_device(struct device_handler *handler, + const char *desc) { struct discover_device *dev; diff --git a/discover/grub2/grub2.h b/discover/grub2/grub2.h index ef32d4b..eabd6d6 100644 --- a/discover/grub2/grub2.h +++ b/discover/grub2/grub2.h @@ -200,6 +200,8 @@ bool resolve_grub2_resource(struct device_handler *handler, /* grub-style device+path parsing */ struct grub2_file *grub2_parse_file(struct grub2_script *script, const char *str); +struct discover_device *grub2_lookup_device(struct device_handler *handler, + const char *desc); /* external parser api */ struct grub2_parser *grub2_parser_create(struct discover_context *ctx); diff --git a/test/parser/Makefile.am b/test/parser/Makefile.am index 0378317..c8e059b 100644 --- a/test/parser/Makefile.am +++ b/test/parser/Makefile.am @@ -33,6 +33,7 @@ parser_TESTS = \ test/parser/test-grub2-search-uuid \ test/parser/test-grub2-search-label \ test/parser/test-grub2-devpath \ + test/parser/test-grub2-devpath-scripting \ test/parser/test-grub2-load-env \ test/parser/test-grub2-save-env \ test/parser/test-grub2-save-env-dash-f \ diff --git a/test/parser/test-grub2-devpath-scripting.c b/test/parser/test-grub2-devpath-scripting.c new file mode 100644 index 0000000..9046ab6 --- /dev/null +++ b/test/parser/test-grub2-devpath-scripting.c @@ -0,0 +1,56 @@ +/* check grub2 device+path string parsing, as used in scripts */ + +#include "parser-test.h" + +#if 0 /* PARSER_EMBEDDED_CONFIG */ + +v= + +# local device, file present +if [ -f "/1-present" ]; then v=${v}a; fi + +# local device, file absent +if [ -f "/1-absent" ]; then v=${v}b; fi; + +# local device by UUID, file present +if [ -f "(00000000-0000-0000-0000-000000000001)/1-present" ]; then v=${v}c; fi; + +# remote device by UUID, file present +if [ -f "(00000000-0000-0000-0000-000000000002)/2-present" ]; then v=${v}d; fi; + +# non-existent device +if [ -f "(00000000-0000-0000-0000-000000000003)/present" ]; then v=${v}e; fi; + +menuentry $v { + linux /vmlinux +} + +#endif + +void run_test(struct parser_test *test) +{ + struct discover_device *dev1, *dev2; + struct discover_boot_option *opt; + struct discover_context *ctx; + + ctx = test->ctx; + + /* set local uuid */ + dev1 = test->ctx->device; + dev1->uuid = "00000000-0000-0000-0000-000000000001"; + + dev2 = test_create_device(test, "extdev"); + dev2->uuid = "00000000-0000-0000-0000-000000000002"; + device_handler_add_device(ctx->handler, dev2); + + test_add_file_data(test, dev1, "/1-present", "x", 1); + test_add_file_data(test, dev2, "/2-present", "x", 1); + + test_read_conf_embedded(test, "/grub/grub.cfg"); + + test_run_parser(test, "grub2"); + + check_boot_option_count(ctx, 1); + opt = get_boot_option(ctx, 0); + check_name(opt, "acd"); +} From patchwork Wed Nov 20 02:43:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Kerr X-Patchwork-Id: 1197778 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47HngG15t6z9sPV for ; Wed, 20 Nov 2019 14:07:38 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="xesOHZhr"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47HngF6wpdzDqv4 for ; Wed, 20 Nov 2019 14:07:37 +1100 (AEDT) X-Original-To: petitboot@lists.ozlabs.org Delivered-To: petitboot@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47Hn9V0mJmzDqWk for ; Wed, 20 Nov 2019 13:45:18 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="xesOHZhr"; dkim-atps=neutral Received: by ozlabs.org (Postfix, from userid 1023) id 47Hn9T4p4Yz9sPW; Wed, 20 Nov 2019 13:45:17 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1574217917; bh=NeaNMPyOOP2esd+l0MyO9HhQ0HF2hC1ucVL2fl0xC00=; h=From:To:Subject:Date:In-Reply-To:References:From; b=xesOHZhrdj1PIqKQniPCfH6PC7OxCeBv9icn7QZPig1vJnverYfvs+AaNSCvYe1/k jFgbkySuHWezU0LBocGxo4iRn58WEAzhQvQMgKzH9L+tXsN3gwZtkBZd+RGNqLjK/4 2AMgScfHMjzIgSFi1Van5ALyRp1j3sEVL5R3WzMWtL26hqBOdvW3gGg4a0ZXN6D3K0 TezgiOyjDFfqhzY29BeWpw3vip0OmQhh9S7GS8i5GtwwkOQLIr+aLSvUu4ZzFA7fvY FC3RQGBgqgpduYC+ckLDvQVMd5EbxnAsThbqyzaduheTaNaRo6tfY35b5U/gtKfR8J EkRjEZWnLWk5Q== From: Jeremy Kerr To: petitboot@lists.ozlabs.org Subject: [PATCH 09/14] discover/grub2: Add a reference from script to parser Date: Wed, 20 Nov 2019 10:43:01 +0800 Message-Id: <20191120024306.16526-10-jk@ozlabs.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191120024306.16526-1-jk@ozlabs.org> References: <20191120024306.16526-1-jk@ozlabs.org> MIME-Version: 1.0 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" Future commands will need to access the parser, so add a reference from struct grub2_script. Signed-off-by: Jeremy Kerr --- discover/grub2/grub2.h | 1 + discover/grub2/script.c | 1 + 2 files changed, 2 insertions(+) diff --git a/discover/grub2/grub2.h b/discover/grub2/grub2.h index eabd6d6..323b461 100644 --- a/discover/grub2/grub2.h +++ b/discover/grub2/grub2.h @@ -91,6 +91,7 @@ struct grub2_statement_for { }; struct grub2_script { + struct grub2_parser *parser; struct grub2_statements *statements; struct list environment; struct list symtab; diff --git a/discover/grub2/script.c b/discover/grub2/script.c index 8a9d91d..34e0400 100644 --- a/discover/grub2/script.c +++ b/discover/grub2/script.c @@ -518,6 +518,7 @@ struct grub2_script *create_script(struct grub2_parser *parser, script = talloc_zero(parser, struct grub2_script); script->ctx = ctx; + script->parser = parser; list_init(&script->symtab); list_init(&script->options); From patchwork Wed Nov 20 02:43:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Kerr X-Patchwork-Id: 1197779 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47HngM1WdLz9sPc for ; Wed, 20 Nov 2019 14:07:43 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="uVbjEfUD"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47HngM04g2zDqvT for ; Wed, 20 Nov 2019 14:07:43 +1100 (AEDT) X-Original-To: petitboot@lists.ozlabs.org Delivered-To: petitboot@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [IPv6:2401:3900:2:1::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47Hn9T71ZqzDqfY for ; Wed, 20 Nov 2019 13:45:17 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="uVbjEfUD"; dkim-atps=neutral Received: by ozlabs.org (Postfix, from userid 1023) id 47Hn9T3qHTz9sPj; Wed, 20 Nov 2019 13:45:17 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1574217917; bh=FMe8VNrF5WsayD51uUyOYmJjStsa1Y7U0hvhfYtvmXM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=uVbjEfUD5DZkJXA904h8LJp58bvcNq02qvEw8x4RnxKcUgM439yiMR+Uj8Js0rC+w K01PJ7tWoBA5ta/dQ/lKN3A+667tJthheyIEYeWqOFWRFgApAXYwQiwvEDBb+K3AHc ecrVBMBkCVymW9rLfVldWgQqds68lrt7DFU+nWWSTaNQP13IGlhGhZCpHrcsU6Q0ir 6cB5lvtRJB2EzX192NH91OveKhk5wkfp1WtLY3bpofXJ0v5uBSbC14nKLBmtglFKrV uqf+23lAOAYHSoZvnOqBlOwSYmuZfBSbdPpipaklRbo3PB6ZO70JBrLP94ydulqfQM cLz9jxDM8xnPA== From: Jeremy Kerr To: petitboot@lists.ozlabs.org Subject: [PATCH 10/14] discover/grub2: expose internal parse function Date: Wed, 20 Nov 2019 10:43:02 +0800 Message-Id: <20191120024306.16526-11-jk@ozlabs.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191120024306.16526-1-jk@ozlabs.org> References: <20191120024306.16526-1-jk@ozlabs.org> MIME-Version: 1.0 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" Upcoming changes will need a method to parse a secondary file (to support the 'source' command), but not execute it as a new script. This change exposes the parsing code, separate from the execution code. Signed-off-by: Jeremy Kerr --- discover/grub2/grub2-parser.y | 17 +++++++++++++++-- discover/grub2/grub2.c | 2 +- discover/grub2/grub2.h | 8 ++++++-- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/discover/grub2/grub2-parser.y b/discover/grub2/grub2-parser.y index 527a61c..f99bbfd 100644 --- a/discover/grub2/grub2-parser.y +++ b/discover/grub2/grub2-parser.y @@ -331,14 +331,15 @@ struct grub2_parser *grub2_parser_create(struct discover_context *ctx) return parser; } -void grub2_parser_parse(struct grub2_parser *parser, const char *filename, +/* performs a parse on buf, setting parser->script->statements */ +int grub2_parser_parse(struct grub2_parser *parser, const char *filename, char *buf, int len) { YY_BUFFER_STATE bufstate; int rc; if (!len) - return; + return -1; parser->script->filename = filename; @@ -349,6 +350,18 @@ void grub2_parser_parse(struct grub2_parser *parser, const char *filename, yy_delete_buffer(bufstate, parser->scanner); + parser->inter_word = false; + + return rc; +} + +void grub2_parser_parse_and_execute(struct grub2_parser *parser, + const char *filename, char *buf, int len) +{ + int rc; + + rc = grub2_parser_parse(parser, filename, buf, len); + if (!rc) script_execute(parser->script); } diff --git a/discover/grub2/grub2.c b/discover/grub2/grub2.c index a8d115f..b176ce2 100644 --- a/discover/grub2/grub2.c +++ b/discover/grub2/grub2.c @@ -169,7 +169,7 @@ static int grub2_parse(struct discover_context *dc) continue; parser = grub2_parser_create(dc); - grub2_parser_parse(parser, *filename, buf, len); + grub2_parser_parse_and_execute(parser, *filename, buf, len); device_handler_status_dev_info(dc->handler, dc->device, _("Parsed GRUB configuration from %s"), *filename); diff --git a/discover/grub2/grub2.h b/discover/grub2/grub2.h index 323b461..668d070 100644 --- a/discover/grub2/grub2.h +++ b/discover/grub2/grub2.h @@ -204,9 +204,13 @@ struct grub2_file *grub2_parse_file(struct grub2_script *script, struct discover_device *grub2_lookup_device(struct device_handler *handler, const char *desc); +/* internal parse api */ +int grub2_parser_parse(struct grub2_parser *parser, const char *filename, + char *buf, int len); + /* external parser api */ struct grub2_parser *grub2_parser_create(struct discover_context *ctx); -void grub2_parser_parse(struct grub2_parser *parser, const char *filename, - char *buf, int len); +void grub2_parser_parse_and_execute(struct grub2_parser *parser, + const char *filename, char *buf, int len); #endif /* GRUB2_H */ From patchwork Wed Nov 20 02:43:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Kerr X-Patchwork-Id: 1197787 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47HnhC4QZFz9sPV for ; Wed, 20 Nov 2019 14:08:27 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="nq8F/MR6"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47HnhC27wbzDqc7 for ; Wed, 20 Nov 2019 14:08:27 +1100 (AEDT) X-Original-To: petitboot@lists.ozlabs.org Delivered-To: petitboot@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47Hn9W5PvrzDqq0 for ; Wed, 20 Nov 2019 13:45:19 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="nq8F/MR6"; dkim-atps=neutral Received: by ozlabs.org (Postfix, from userid 1023) id 47Hn9W2m64z9sPc; Wed, 20 Nov 2019 13:45:19 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1574217919; bh=QPl/3R2UsZom6dlAIO08Omo36hxQo/tqwLs3W0Eugqo=; h=From:To:Subject:Date:In-Reply-To:References:From; b=nq8F/MR6GW1qlpxvDnMVgkQ84eW/LvAsVDjZ39JE9XgZigyvo72l7fzTOERr/dS1x vSpvmXwNuHBPKQcawhySKUNK/f4yf1mhSAByL6DIkhQFe0Ef2pmd5iTYOTAt/QpU+o /RE/+tbzgUvLRvig7CZ324HqyiasxC4nA+IBy2z5MpH/7Sxy+xkg6Hk8pJsFvNaxq9 l+rFuycZ4GPq1IQFgXAj6zIClnERKP9gBc6guQMgUwmQF2KuIF+T4VPrKwHJBFUVcB 1q2jOyK9XvoFpsk6RGncpK5RFTusnY8298YspDRuMQQgtA3DVSSwaPGcMVnSrFwnsF Raw4aHVWSi+9A== From: Jeremy Kerr To: petitboot@lists.ozlabs.org Subject: [PATCH 11/14] discover/grub2: make statements_execute non-static Date: Wed, 20 Nov 2019 10:43:03 +0800 Message-Id: <20191120024306.16526-12-jk@ozlabs.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191120024306.16526-1-jk@ozlabs.org> References: <20191120024306.16526-1-jk@ozlabs.org> MIME-Version: 1.0 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" We want to execute newly-parsed statements, so expose statements_execute() to the rest of the grub2 parser code. Signed-off-by: Jeremy Kerr --- discover/grub2/grub2.h | 3 +++ discover/grub2/script.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/discover/grub2/grub2.h b/discover/grub2/grub2.h index 668d070..deaf976 100644 --- a/discover/grub2/grub2.h +++ b/discover/grub2/grub2.h @@ -165,6 +165,9 @@ void word_append(struct grub2_word *w1, struct grub2_word *w2); /* script interface */ void script_execute(struct grub2_script *script); +int statements_execute(struct grub2_script *script, + struct grub2_statements *stmts); + int statement_simple_execute(struct grub2_script *script, struct grub2_statement *statement); int statement_block_execute(struct grub2_script *script, diff --git a/discover/grub2/script.c b/discover/grub2/script.c index 34e0400..14931f9 100644 --- a/discover/grub2/script.c +++ b/discover/grub2/script.c @@ -229,7 +229,7 @@ static void process_expansions(struct grub2_script *script, argv->argc--; } -static int statements_execute(struct grub2_script *script, +int statements_execute(struct grub2_script *script, struct grub2_statements *stmts) { struct grub2_statement *stmt; From patchwork Wed Nov 20 02:43:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Kerr X-Patchwork-Id: 1197781 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47Hngb1Lsjz9sPV for ; Wed, 20 Nov 2019 14:07:55 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="puhcKxpt"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47HngZ70wnzDqZw for ; Wed, 20 Nov 2019 14:07:54 +1100 (AEDT) X-Original-To: petitboot@lists.ozlabs.org Delivered-To: petitboot@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47Hn9V3jZMzDqHl for ; Wed, 20 Nov 2019 13:45:18 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="puhcKxpt"; dkim-atps=neutral Received: by ozlabs.org (Postfix, from userid 1023) id 47Hn9V26BQz9sPK; Wed, 20 Nov 2019 13:45:18 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1574217918; bh=45BaObIcCZT/lJRQ4xw2KFPAPD9MjD78hZUoWUPjatQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=puhcKxptnr/wOXEsVRV/JK7v56JTHMW0WsASKBm3gaemw+o3esPVmv7UlZO03y/C3 xk6AA8FRRIcje9B504GL8HIQi166lr8sFiM4yVgzdMmCTyuSx4MQJ98FEqZkgwfiq3 gW66g84pMw1W60iQS2ixN+HG+xuSwkhwU9OKNfJRkLtlJIe33ED0LZQFEvmPDknUW5 z3zMI/VeA3wApqJeFGYGTC6GhKlbA7CsjDutJcLgRuMNeLQyQxu/mh6pCpu9dm5An/ UNOnd4P4C4fcr184z4zGcktrWBxC+hdPZPNGMB4Pp2Gi5be8c1aNXuxQ/pZkLinYKD M6K/r6K7As9AA== From: Jeremy Kerr To: petitboot@lists.ozlabs.org Subject: [PATCH 12/14] discover/grub2: implement 'source' command Date: Wed, 20 Nov 2019 10:43:04 +0800 Message-Id: <20191120024306.16526-13-jk@ozlabs.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191120024306.16526-1-jk@ozlabs.org> References: <20191120024306.16526-1-jk@ozlabs.org> MIME-Version: 1.0 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" This change add support for the grub2 'source' command, executing a referenced script in the current parse context. We impose a limit of 10 (concurrent) source commands, to prevent infinite recursion. Signed-off-by: Jeremy Kerr --- discover/grub2/builtins.c | 51 +++++++++++++++- discover/grub2/grub2.h | 1 + test/parser/Makefile.am | 4 ++ test/parser/test-grub2-source-functions.c | 46 +++++++++++++++ .../test-grub2-source-recursion-infinite.c | 43 ++++++++++++++ test/parser/test-grub2-source-recursion.c | 58 +++++++++++++++++++ test/parser/test-grub2-source.c | 54 +++++++++++++++++ 7 files changed, 256 insertions(+), 1 deletion(-) create mode 100644 test/parser/test-grub2-source-functions.c create mode 100644 test/parser/test-grub2-source-recursion-infinite.c create mode 100644 test/parser/test-grub2-source-recursion.c create mode 100644 test/parser/test-grub2-source.c diff --git a/discover/grub2/builtins.c b/discover/grub2/builtins.c index c726216..ab1407a 100644 --- a/discover/grub2/builtins.c +++ b/discover/grub2/builtins.c @@ -401,6 +401,51 @@ static int builtin_test(struct grub2_script *script, return rc ? 0 : 1; } +static int builtin_source(struct grub2_script *script, + void *data __attribute__((unused)), + int argc, char *argv[]) +{ + struct grub2_statements *statements; + struct discover_device *dev; + const char *filename; + char *path, *buf; + int rc, len; + + if (argc != 2) + return false; + + /* limit script recursion */ + if (script->include_depth >= 10) + return false; + + rc = parse_to_device_path(script, argv[1], &dev, &path); + if (rc) + return false; + + rc = parser_request_file(script->ctx, dev, path, &buf, &len); + if (rc) + return false; + + /* save current script state */ + statements = script->statements; + filename = script->filename; + script->include_depth++; + + rc = grub2_parser_parse(script->parser, argv[1], buf, len); + + if (!rc) + statements_execute(script, script->statements); + + talloc_free(script->statements); + + /* restore state */ + script->statements = statements; + script->filename = filename; + script->include_depth--; + + return !rc; +} + static int builtin_true(struct grub2_script *script __attribute__((unused)), void *data __attribute__((unused)), int argc __attribute__((unused)), @@ -491,7 +536,11 @@ static struct { { .name = "blscfg", .fn = builtin_blscfg, - } + }, + { + .name = "source", + .fn = builtin_source, + }, }; static const char *nops[] = { diff --git a/discover/grub2/grub2.h b/discover/grub2/grub2.h index deaf976..75f6aa0 100644 --- a/discover/grub2/grub2.h +++ b/discover/grub2/grub2.h @@ -100,6 +100,7 @@ struct grub2_script { const char *filename; unsigned int n_options; struct list options; + int include_depth; }; struct grub2_parser { diff --git a/test/parser/Makefile.am b/test/parser/Makefile.am index c8e059b..5f1a93b 100644 --- a/test/parser/Makefile.am +++ b/test/parser/Makefile.am @@ -46,6 +46,10 @@ parser_TESTS = \ test/parser/test-grub2-lexer-error \ test/parser/test-grub2-parser-error \ test/parser/test-grub2-test-file-ops \ + test/parser/test-grub2-source \ + test/parser/test-grub2-source-functions \ + test/parser/test-grub2-source-recursion \ + test/parser/test-grub2-source-recursion-infinite \ test/parser/test-grub2-single-yocto \ test/parser/test-grub2-blscfg-default-filename \ test/parser/test-grub2-blscfg-default-index \ diff --git a/test/parser/test-grub2-source-functions.c b/test/parser/test-grub2-source-functions.c new file mode 100644 index 0000000..a9da934 --- /dev/null +++ b/test/parser/test-grub2-source-functions.c @@ -0,0 +1,46 @@ + +/* check that we can source other scripts, and functions can be defined + * and called across sourced scripts */ + +#include "parser-test.h" + +#if 0 /* PARSER_EMBEDDED_CONFIG */ + +function f1 { + menuentry "f1$1" { linux $2 } +} + +source /grub/2.cfg + +f2 a /vmlinux + +#endif + +void run_test(struct parser_test *test) +{ + struct discover_boot_option *opt; + struct discover_context *ctx; + struct discover_device *dev; + + ctx = test->ctx; + dev = ctx->device; + + test_read_conf_embedded(test, "/grub/grub.cfg"); + + test_add_file_string(test, dev, + "/grub/2.cfg", + "function f2 { menuentry \"f2$1\" { linux $2 } }\n" + "f1 a /vmlinux\n"); + + test_run_parser(test, "grub2"); + + check_boot_option_count(ctx, 2); + + opt = get_boot_option(ctx, 0); + check_name(opt, "f1a"); + check_resolved_local_resource(opt->boot_image, dev, "/vmlinux"); + + opt = get_boot_option(ctx, 1); + check_name(opt, "f2a"); + check_resolved_local_resource(opt->boot_image, dev, "/vmlinux"); +} diff --git a/test/parser/test-grub2-source-recursion-infinite.c b/test/parser/test-grub2-source-recursion-infinite.c new file mode 100644 index 0000000..fbcc5a3 --- /dev/null +++ b/test/parser/test-grub2-source-recursion-infinite.c @@ -0,0 +1,43 @@ + +/* check that have a maximum source recursion limit */ + +#include "parser-test.h" + +#if 0 /* PARSER_EMBEDDED_CONFIG */ + +name=a$name + +menuentry $name { + linux /a +} + +source /grub/grub.cfg + +#endif + +void run_test(struct parser_test *test) +{ + struct discover_boot_option *opt; + struct discover_context *ctx; + struct discover_device *dev; + + ctx = test->ctx; + dev = ctx->device; + + test_read_conf_embedded(test, "/grub/grub.cfg"); + + test_run_parser(test, "grub2"); + + /* we error out after 10 levels, but we should still have + * parse results up to that point + */ + check_boot_option_count(ctx, 11); + + opt = get_boot_option(ctx, 0); + check_name(opt, "a"); + check_resolved_local_resource(opt->boot_image, dev, "/a"); + + opt = get_boot_option(ctx,10); + check_name(opt, "aaaaaaaaaaa"); + check_resolved_local_resource(opt->boot_image, dev, "/a"); +} diff --git a/test/parser/test-grub2-source-recursion.c b/test/parser/test-grub2-source-recursion.c new file mode 100644 index 0000000..21b6bd2 --- /dev/null +++ b/test/parser/test-grub2-source-recursion.c @@ -0,0 +1,58 @@ +/* check that we can source other files recursively */ + +#include "parser-test.h" + +#if 0 /* PARSER_EMBEDDED_CONFIG */ + +menuentry a { + linux /a +} + +source /grub/2.cfg + +menuentry c { + linux /c +} + +#endif + +void run_test(struct parser_test *test) +{ + struct discover_boot_option *opt; + struct discover_context *ctx; + struct discover_device *dev; + + ctx = test->ctx; + dev = ctx->device; + + test_read_conf_embedded(test, "/grub/grub.cfg"); + + /* four levels of config files, the last defining a boot option */ + test_add_file_string(test, dev, + "/grub/2.cfg", + "source /grub/3.cfg\n"); + + test_add_file_string(test, dev, + "/grub/3.cfg", + "source /grub/4.cfg\n"); + + test_add_file_string(test, dev, + "/grub/4.cfg", + "menuentry b { linux /b }\n"); + + test_run_parser(test, "grub2"); + + check_boot_option_count(ctx, 3); + + opt = get_boot_option(ctx, 0); + check_name(opt, "a"); + check_resolved_local_resource(opt->boot_image, dev, "/a"); + + opt = get_boot_option(ctx, 1); + check_name(opt, "b"); + check_resolved_local_resource(opt->boot_image, dev, "/b"); + + opt = get_boot_option(ctx, 2); + check_name(opt, "c"); + check_resolved_local_resource(opt->boot_image, dev, "/c"); +} diff --git a/test/parser/test-grub2-source.c b/test/parser/test-grub2-source.c new file mode 100644 index 0000000..a14bef7 --- /dev/null +++ b/test/parser/test-grub2-source.c @@ -0,0 +1,54 @@ + +/* check that we can source other scripts, and variables get passed + * in to and out of sourced scripts */ + +#include "parser-test.h" + +#if 0 /* PARSER_EMBEDDED_CONFIG */ + +menuentry a { + linux /a +} + +# var: outer -> inner -> outer +v=b + +source /grub/2.cfg + +menuentry $v { + linux /c +} + +#endif + +void run_test(struct parser_test *test) +{ + struct discover_boot_option *opt; + struct discover_context *ctx; + struct discover_device *dev; + + ctx = test->ctx; + dev = ctx->device; + + test_read_conf_embedded(test, "/grub/grub.cfg"); + + test_add_file_string(test, dev, + "/grub/2.cfg", + "menuentry $v { linux /b }\nv=c\n"); + + test_run_parser(test, "grub2"); + + check_boot_option_count(ctx, 3); + + opt = get_boot_option(ctx, 0); + check_name(opt, "a"); + check_resolved_local_resource(opt->boot_image, dev, "/a"); + + opt = get_boot_option(ctx, 1); + check_name(opt, "b"); + check_resolved_local_resource(opt->boot_image, dev, "/b"); + + opt = get_boot_option(ctx, 2); + check_name(opt, "c"); + check_resolved_local_resource(opt->boot_image, dev, "/c"); +} From patchwork Wed Nov 20 02:43:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Kerr X-Patchwork-Id: 1197773 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (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) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47HnfV2svDz9sPV for ; Wed, 20 Nov 2019 14:06:58 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="ogkkcO5X"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47HnfT5DrzzDqlS for ; Wed, 20 Nov 2019 14:06:57 +1100 (AEDT) X-Original-To: petitboot@lists.ozlabs.org Delivered-To: petitboot@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47Hn9S44lrzDqfY for ; Wed, 20 Nov 2019 13:45:16 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="ogkkcO5X"; dkim-atps=neutral Received: by ozlabs.org (Postfix, from userid 1023) id 47Hn9Q64Bmz9sPW; Wed, 20 Nov 2019 13:45:14 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1574217914; bh=FjB7lhZNFmEX5BRgzgXtE6ieUmHxa4G6E0iZnUMr58I=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ogkkcO5XvuD+5K4I5YGSIuZAPeRzMLrgoQFOrbdvWhWuV/KrZRQEonqYK6cyOH4hj t548DVuRPDzV0pe2wo9ymo/vevx5kQsUZlpjtw3F7lMrBAgf0mZ13GUN0rv8A1tnO+ ug6z1At+BCK/kQdRc2OGYy8TEkisOPb24zEewfi+x7dWLkxVFPUvq6hT9BsaGzBhRD CRpDWKz2qcPD00TO7wo/Szut/B+Bjg4OwSelRyNrGQUlLdDKKQVWciApdZ/28jazNa Y/L3OlFFRXfEfk4LxL262Y9qsWplnQKqcN+FnWcjlON7z7QvXx3h/5vE0h9EzxybKr QYnHFEDPtbN7g== From: Jeremy Kerr To: petitboot@lists.ozlabs.org Subject: [PATCH 13/14] test/parser: Add test for recent RHCOS grub2 config Date: Wed, 20 Nov 2019 10:43:05 +0800 Message-Id: <20191120024306.16526-14-jk@ozlabs.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191120024306.16526-1-jk@ozlabs.org> References: <20191120024306.16526-1-jk@ozlabs.org> MIME-Version: 1.0 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" Add a test for a RHCOS grub2 boot config, using the ignition firstboot facility. Signed-off-by: Jeremy Kerr --- test/parser/Makefile.am | 1 + test/parser/data/grub2-rhcos-ootpa.conf | 194 ++++++++++++++++++++++++ test/parser/test-grub2-rhcos-ootpa.c | 38 +++++ 3 files changed, 233 insertions(+) create mode 100644 test/parser/data/grub2-rhcos-ootpa.conf create mode 100644 test/parser/test-grub2-rhcos-ootpa.c diff --git a/test/parser/Makefile.am b/test/parser/Makefile.am index 5f1a93b..5f7922c 100644 --- a/test/parser/Makefile.am +++ b/test/parser/Makefile.am @@ -43,6 +43,7 @@ parser_TESTS = \ test/parser/test-grub2-f20-ppc64 \ test/parser/test-grub2-ubuntu-13_04-x86 \ test/parser/test-grub2-sles-btrfs-snapshot \ + test/parser/test-grub2-rhcos-ootpa \ test/parser/test-grub2-lexer-error \ test/parser/test-grub2-parser-error \ test/parser/test-grub2-test-file-ops \ diff --git a/test/parser/data/grub2-rhcos-ootpa.conf b/test/parser/data/grub2-rhcos-ootpa.conf new file mode 100644 index 0000000..329980e --- /dev/null +++ b/test/parser/data/grub2-rhcos-ootpa.conf @@ -0,0 +1,194 @@ +# +# DO NOT EDIT THIS FILE +# +# It is automatically generated by grub2-mkconfig using templates +# from /etc/grub.d and settings from /etc/default/grub +# + +### BEGIN /etc/grub.d/00_header ### +set pager=1 + +if [ -f ${config_directory}/grubenv ]; then + load_env -f ${config_directory}/grubenv +elif [ -s $prefix/grubenv ]; then + load_env +fi +if [ "${next_entry}" ] ; then + set default="${next_entry}" + set next_entry= + save_env next_entry + set boot_once=true +else + set default="${saved_entry}" +fi + +if [ x"${feature_menuentry_id}" = xy ]; then + menuentry_id_option="--id" +else + menuentry_id_option="" +fi + +export menuentry_id_option + +if [ "${prev_saved_entry}" ]; then + set saved_entry="${prev_saved_entry}" + save_env saved_entry + set prev_saved_entry= + save_env prev_saved_entry + set boot_once=true +fi + +function savedefault { + if [ -z "${boot_once}" ]; then + saved_entry="${chosen}" + save_env saved_entry + fi +} + +function load_video { + if [ x$feature_all_video_module = xy ]; then + insmod all_video + else + insmod efi_gop + insmod efi_uga + insmod ieee1275_fb + insmod vbe + insmod vga + insmod video_bochs + insmod video_cirrus + fi +} + +terminal_output ofconsole +if [ x$feature_timeout_style = xy ] ; then + set timeout_style=menu + set timeout=1 +# Fallback normal timeout code in case the timeout_style feature is +# unavailable. +else + set timeout=1 +fi +### END /etc/grub.d/00_header ### + +### BEGIN /etc/grub.d/01_menu_auto_hide ### +if [ "${boot_success}" = "1" -o "${boot_indeterminate}" = "1" ]; then + set last_boot_ok=1 +else + set last_boot_ok=0 +fi + +# Reset boot_indeterminate after a successful boot +if [ "${boot_success}" = "1" ] ; then + set boot_indeterminate=0 +# Avoid boot_indeterminate causing the menu to be hidden more then once +elif [ "${boot_indeterminate}" = "1" ]; then + set boot_indeterminate=2 +fi +set boot_success=0 +save_env boot_success boot_indeterminate + +if [ x$feature_timeout_style = xy ] ; then + if [ "${menu_show_once}" ]; then + unset menu_show_once + save_env menu_show_once + set timeout_style=menu + set timeout=60 + elif [ "${menu_auto_hide}" -a "${last_boot_ok}" = "1" ]; then + set orig_timeout_style=${timeout_style} + set orig_timeout=${timeout} + if [ "${fastboot}" = "1" ]; then + # timeout_style=menu + timeout=0 avoids the countdown code keypress check + set timeout_style=menu + set timeout=0 + else + set timeout_style=hidden + set timeout=1 + fi + fi +fi +### END /etc/grub.d/01_menu_auto_hide ### + +### BEGIN /etc/grub.d/01_users ### +if [ -f ${prefix}/user.cfg ]; then + source ${prefix}/user.cfg + if [ -n "${GRUB2_PASSWORD}" ]; then + set superusers="root" + export superusers + password_pbkdf2 root ${GRUB2_PASSWORD} + fi +fi +### END /etc/grub.d/01_users ### + +### BEGIN /etc/grub.d/02_ignition_firstboot ### +# We store the file on the /boot/ partition so find the +# boot partition. On UEFI this may different than the grub +# $root so we search for it here. +# https://github.com/coreos/ignition-dracut/issues/51 +search --set=bootpart --label boot +# Determine if this is a first boot and set the variable +# to be used later on the kernel command line. +set ignition_firstboot="" +if [ -f "(${bootpart})/ignition.firstboot" ]; then + # default to dhcp networking parameters to be used with ignition + set ignition_network_kcmdline='rd.neednet=1 ip=dhcp' + + # source in the `ignition.firstboot` file which could override the + # above $ignition_network_kcmdline with static networking config. + # This override feature is primarily used by coreos-installer to + # persist static networking config provided during install to the + # first boot of the machine. + source "(${bootpart})/ignition.firstboot" + + # we support setting variables in the + set ignition_firstboot="ignition.firstboot $ignition_network_kcmdline $ignition_extra_kcmdline" +fi +### END /etc/grub.d/02_ignition_firstboot ### + +### BEGIN /etc/grub.d/10_linux_bls ### + +### END /etc/grub.d/10_linux_bls ### + +### BEGIN /etc/grub.d/15_ostree ### +menuentry 'Red Hat Enterprise Linux CoreOS 42.80.20191030.0 (Ootpa) (ostree)' --class gnu-linux --class gnu --class os --unrestricted 'ostree-0-645e1535-a6f3-4fa6-a82c-b8c032619a7b' { +load_video +set gfxpayload=keep +insmod gzio +insmod part_gpt +insmod ext2 +set root='hd0,gpt2' +if [ x$feature_platform_search_hint = xy ]; then + search --no-floppy --fs-uuid --set=root --hint='hd0,gpt2' 645e1535-a6f3-4fa6-a82c-b8c032619a7b +else + search --no-floppy --fs-uuid --set=root 645e1535-a6f3-4fa6-a82c-b8c032619a7b +fi +linux /ostree/rhcos-6264e4be818e20cf1021bd6e7aa8c76147ce07dec186468c7dfbbc9c5dfc7d8b/vmlinuz-4.18.0-80.11.2.el8_0.ppc64le console=tty0 console=hvc0,115200n8 rootflags=defaults,prjquota rw $ignition_firstboot root=UUID=8d8a5c3b-97e6-4d7b-bb87-206af5a9d851 ostree=/ostree/boot.0/rhcos/6264e4be818e20cf1021bd6e7aa8c76147ce07dec186468c7dfbbc9c5dfc7d8b/0 ignition.platform.id=openstack +initrd /ostree/rhcos-6264e4be818e20cf1021bd6e7aa8c76147ce07dec186468c7dfbbc9c5dfc7d8b/initramfs-4.18.0-80.11.2.el8_0.ppc64le.img +} +### END /etc/grub.d/15_ostree ### + +### BEGIN /etc/grub.d/20_linux_xen ### +### END /etc/grub.d/20_linux_xen ### + +### BEGIN /etc/grub.d/20_ppc_terminfo ### + terminfo -g 80x24 ofconsole +### END /etc/grub.d/20_ppc_terminfo ### + +### BEGIN /etc/grub.d/30_os-prober ### +### END /etc/grub.d/30_os-prober ### + +### BEGIN /etc/grub.d/30_uefi-firmware ### +### END /etc/grub.d/30_uefi-firmware ### + +### BEGIN /etc/grub.d/40_custom ### +# This file provides an easy way to add custom menu entries. Simply type the +# menu entries you want to add after this comment. Be careful not to change +# the 'exec tail' line above. +### END /etc/grub.d/40_custom ### + +### BEGIN /etc/grub.d/41_custom ### +if [ -f ${config_directory}/custom.cfg ]; then + source ${config_directory}/custom.cfg +elif [ -z "${config_directory}" -a -f $prefix/custom.cfg ]; then + source $prefix/custom.cfg; +fi +### END /etc/grub.d/41_custom ### diff --git a/test/parser/test-grub2-rhcos-ootpa.c b/test/parser/test-grub2-rhcos-ootpa.c new file mode 100644 index 0000000..19299be --- /dev/null +++ b/test/parser/test-grub2-rhcos-ootpa.c @@ -0,0 +1,38 @@ + +#include "parser-test.h" + +void run_test(struct parser_test *test) +{ + struct discover_boot_option *opt; + struct discover_context *ctx; + struct discover_device *dev; + + ctx = test->ctx; + + dev = test_create_device(test, "bootdev"); + dev->label = "boot"; + device_handler_add_device(test->handler, dev); + + test_read_conf_file(test, "grub2-rhcos-ootpa.conf", + "/grub/grub.cfg"); + + /* add the ignition.firstboot file on the boot-labelled partition, + * to check that we can source this correctly */ + test_add_file_string(test, dev, + "/ignition.firstboot", + "ignition_extra_kcmdline=meep\n"); + + test_run_parser(test, "grub2"); + + check_boot_option_count(ctx, 1); + + opt = get_boot_option(ctx, 0); + check_name(opt, + "Red Hat Enterprise Linux CoreOS 42.80.20191030.0 (Ootpa) (ostree)"); + check_args(opt, "console=tty0 console=hvc0,115200n8 " + "rootflags=defaults,prjquota rw " + "ignition.firstboot rd.neednet=1 ip=dhcp meep " + "root=UUID=8d8a5c3b-97e6-4d7b-bb87-206af5a9d851 " + "ostree=/ostree/boot.0/rhcos/6264e4be818e20cf1021bd6e7aa8c76147ce07dec186468c7dfbbc9c5dfc7d8b/0 " + "ignition.platform.id=openstack"); +} From patchwork Wed Nov 20 02:43:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Kerr X-Patchwork-Id: 1197783 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47Hngp18V3z9sPc for ; Wed, 20 Nov 2019 14:08:06 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="MOShBrDp"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47Hngn64ShzDqww for ; Wed, 20 Nov 2019 14:08:05 +1100 (AEDT) X-Original-To: petitboot@lists.ozlabs.org Delivered-To: petitboot@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47Hn9V6VYBzDqHl for ; Wed, 20 Nov 2019 13:45:18 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="MOShBrDp"; dkim-atps=neutral Received: by ozlabs.org (Postfix, from userid 1023) id 47Hn9V4j4Qz9sPc; Wed, 20 Nov 2019 13:45:18 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1574217918; bh=L9AP0bCpmNHGkuBMvQFdXkMYZqtJjdvFenatg6+I+t4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=MOShBrDp9RGGCJuppapJ9rhsxus0KvvTscp6vsUBcdpDLVAW7+rCplIDWbSX1DMYk niBTQBaNcAzhORS7Xc+agU3tTzCJOjf94hugl9M73H17aqFT3gph81FhrruyTJUX16 CauEzQpP94dg1YZ0wepJ3vOzzuL61wlguziCeAyZsxtZKFhqj9rpunQFXDMx5XY0Pk 5hBlDiDpBcJy3fMXVVVIIKv1gsZkTg0fWFx7rFPwJWcQsMUfaLSMepO+spFNpXCa06 L0ivPcXZJcmSGwu11xa8kKzRydXsY8Yie7yI3irWnauQJlbE5N9EcYTgobGz5xH7Z0 OjMF1MfSpMg+Q== From: Jeremy Kerr To: petitboot@lists.ozlabs.org Subject: [PATCH 14/14] test/parser: Add RHEL8 grub config test Date: Wed, 20 Nov 2019 10:43:06 +0800 Message-Id: <20191120024306.16526-15-jk@ozlabs.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191120024306.16526-1-jk@ozlabs.org> References: <20191120024306.16526-1-jk@ozlabs.org> MIME-Version: 1.0 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" Signed-off-by: Jeremy Kerr --- test/parser/Makefile.am | 1 + test/parser/data/grub2-rhel8.conf | 190 ++++++++++++++++++++++++++++++ test/parser/test-grub2-rhel8.c | 21 ++++ 3 files changed, 212 insertions(+) create mode 100644 test/parser/data/grub2-rhel8.conf create mode 100644 test/parser/test-grub2-rhel8.c diff --git a/test/parser/Makefile.am b/test/parser/Makefile.am index 5f7922c..9d1141c 100644 --- a/test/parser/Makefile.am +++ b/test/parser/Makefile.am @@ -43,6 +43,7 @@ parser_TESTS = \ test/parser/test-grub2-f20-ppc64 \ test/parser/test-grub2-ubuntu-13_04-x86 \ test/parser/test-grub2-sles-btrfs-snapshot \ + test/parser/test-grub2-rhel8 \ test/parser/test-grub2-rhcos-ootpa \ test/parser/test-grub2-lexer-error \ test/parser/test-grub2-parser-error \ diff --git a/test/parser/data/grub2-rhel8.conf b/test/parser/data/grub2-rhel8.conf new file mode 100644 index 0000000..563b3e5 --- /dev/null +++ b/test/parser/data/grub2-rhel8.conf @@ -0,0 +1,190 @@ +# +# DO NOT EDIT THIS FILE +# +# It is automatically generated by grub2-mkconfig using templates +# from /etc/grub.d and settings from /etc/default/grub +# + +### BEGIN /etc/grub.d/00_header ### +set pager=1 + +if [ -f ${config_directory}/grubenv ]; then + load_env -f ${config_directory}/grubenv +elif [ -s $prefix/grubenv ]; then + load_env +fi +if [ "${next_entry}" ] ; then + set default="${next_entry}" + set next_entry= + save_env next_entry + set boot_once=true +else + set default="${saved_entry}" +fi + +if [ x"${feature_menuentry_id}" = xy ]; then + menuentry_id_option="--id" +else + menuentry_id_option="" +fi + +export menuentry_id_option + +if [ "${prev_saved_entry}" ]; then + set saved_entry="${prev_saved_entry}" + save_env saved_entry + set prev_saved_entry= + save_env prev_saved_entry + set boot_once=true +fi + +function savedefault { + if [ -z "${boot_once}" ]; then + saved_entry="${chosen}" + save_env saved_entry + fi +} + +function load_video { + if [ x$feature_all_video_module = xy ]; then + insmod all_video + else + insmod efi_gop + insmod efi_uga + insmod ieee1275_fb + insmod vbe + insmod vga + insmod video_bochs + insmod video_cirrus + fi +} + +terminal_output ofconsole +if [ x$feature_timeout_style = xy ] ; then + set timeout_style=menu + set timeout=5 +# Fallback normal timeout code in case the timeout_style feature is +# unavailable. +else + set timeout=5 +fi +### END /etc/grub.d/00_header ### + +### BEGIN /etc/grub.d/00_tuned ### +set tuned_params="" +set tuned_initrd="" +### END /etc/grub.d/00_tuned ### + +### BEGIN /etc/grub.d/01_menu_auto_hide ### +if [ "${boot_success}" = "1" -o "${boot_indeterminate}" = "1" ]; then + set last_boot_ok=1 +else + set last_boot_ok=0 +fi + +# Reset boot_indeterminate after a successful boot +if [ "${boot_success}" = "1" ] ; then + set boot_indeterminate=0 +# Avoid boot_indeterminate causing the menu to be hidden more then once +elif [ "${boot_indeterminate}" = "1" ]; then + set boot_indeterminate=2 +fi +set boot_success=0 +save_env boot_success boot_indeterminate + +if [ x$feature_timeout_style = xy ] ; then + if [ "${menu_show_once}" ]; then + unset menu_show_once + save_env menu_show_once + set timeout_style=menu + set timeout=60 + elif [ "${menu_auto_hide}" -a "${last_boot_ok}" = "1" ]; then + set orig_timeout_style=${timeout_style} + set orig_timeout=${timeout} + if [ "${fastboot}" = "1" ]; then + # timeout_style=menu + timeout=0 avoids the countdown code keypress check + set timeout_style=menu + set timeout=0 + else + set timeout_style=hidden + set timeout=1 + fi + fi +fi +### END /etc/grub.d/01_menu_auto_hide ### + +### BEGIN /etc/grub.d/01_users ### +if [ -f ${prefix}/user.cfg ]; then + source ${prefix}/user.cfg + if [ -n "${GRUB2_PASSWORD}" ]; then + set superusers="root" + export superusers + password_pbkdf2 root ${GRUB2_PASSWORD} + fi +fi +### END /etc/grub.d/01_users ### + +### BEGIN /etc/grub.d/10_linux_bls ### +insmod part_msdos +insmod xfs +set root='hd0,msdos2' +if [ x$feature_platform_search_hint = xy ]; then + search --no-floppy --fs-uuid --set=root --hint-ieee1275='ieee1275//pciex@600c3c0100000/pci@0/pci@0/pci@9/raid@0/disk@8,msdos2' --hint-bios=hd0,msdos2 --hint-efi=hd0,msdos2 --hint-baremetal=ahci0,msdos2 --hint='hd0,msdos2' 9a8ea027-4829-45b9-829b-18ed6cc1f33b +else + search --no-floppy --fs-uuid --set=root 9a8ea027-4829-45b9-829b-18ed6cc1f33b +fi +insmod part_msdos +insmod xfs +set boot='hd0,msdos2' +if [ x$feature_platform_search_hint = xy ]; then + search --no-floppy --fs-uuid --set=boot --hint-ieee1275='ieee1275//pciex@600c3c0100000/pci@0/pci@0/pci@9/raid@0/disk@8,msdos2' --hint-bios=hd0,msdos2 --hint-efi=hd0,msdos2 --hint-baremetal=ahci0,msdos2 --hint='hd0,msdos2' 9a8ea027-4829-45b9-829b-18ed6cc1f33b +else + search --no-floppy --fs-uuid --set=boot 9a8ea027-4829-45b9-829b-18ed6cc1f33b +fi + +# This section was generated by a script. Do not modify the generated file - all changes +# will be lost the next time file is regenerated. Instead edit the BootLoaderSpec files. + +menuentry 'Red Hat Enterprise Linux (4.18.0-80.11.2.el8_0.ppc64le) 8.0 (Ootpa)' --class kernel --unrestricted --users $grub_users --id 8e15296c9cc14deb9e3f8548d49fd6fc-4.18.0-80.11.2.el8_0.ppc64le { + linux /vmlinuz-4.18.0-80.11.2.el8_0.ppc64le $kernelopts $tuned_params + initrd /initramfs-4.18.0-80.11.2.el8_0.ppc64le.img $tuned_initrd +} + +menuentry 'Red Hat Enterprise Linux (4.18.0-80.el8.ppc64le) 8.0 (Ootpa)' --class kernel --unrestricted --users $grub_users --id 8e15296c9cc14deb9e3f8548d49fd6fc-4.18.0-80.el8.ppc64le { + linux /vmlinuz-4.18.0-80.el8.ppc64le $kernelopts $tuned_params + initrd /initramfs-4.18.0-80.el8.ppc64le.img $tuned_initrd +} + +menuentry 'Red Hat Enterprise Linux (0-rescue-8e15296c9cc14deb9e3f8548d49fd6fc) 8.0 (Ootpa)' --class kernel --unrestricted --users $grub_users --id 8e15296c9cc14deb9e3f8548d49fd6fc-0-rescue { + linux /vmlinuz-0-rescue-8e15296c9cc14deb9e3f8548d49fd6fc $kernelopts + initrd /initramfs-0-rescue-8e15296c9cc14deb9e3f8548d49fd6fc.img +} + +### END /etc/grub.d/10_linux_bls ### + +### BEGIN /etc/grub.d/20_linux_xen ### +### END /etc/grub.d/20_linux_xen ### + +### BEGIN /etc/grub.d/20_ppc_terminfo ### + terminfo -g 80x24 ofconsole +### END /etc/grub.d/20_ppc_terminfo ### + +### BEGIN /etc/grub.d/30_os-prober ### +### END /etc/grub.d/30_os-prober ### + +### BEGIN /etc/grub.d/30_uefi-firmware ### +### END /etc/grub.d/30_uefi-firmware ### + +### BEGIN /etc/grub.d/40_custom ### +# This file provides an easy way to add custom menu entries. Simply type the +# menu entries you want to add after this comment. Be careful not to change +# the 'exec tail' line above. +### END /etc/grub.d/40_custom ### + +### BEGIN /etc/grub.d/41_custom ### +if [ -f ${config_directory}/custom.cfg ]; then + source ${config_directory}/custom.cfg +elif [ -z "${config_directory}" -a -f $prefix/custom.cfg ]; then + source $prefix/custom.cfg; +fi +### END /etc/grub.d/41_custom ### diff --git a/test/parser/test-grub2-rhel8.c b/test/parser/test-grub2-rhel8.c new file mode 100644 index 0000000..3e208bc --- /dev/null +++ b/test/parser/test-grub2-rhel8.c @@ -0,0 +1,21 @@ + +#include "parser-test.h" + +void run_test(struct parser_test *test) +{ + struct discover_context *ctx; + struct discover_device *dev; + + ctx = test->ctx; + + dev = test_create_device(test, "boot"); + dev->uuid = "9a8ea027-4829-45b9-829b-18ed6cc1f33b"; + device_handler_add_device(test->handler, dev); + + test_read_conf_file(test, "grub2-rhel8.conf", + "/grub/grub.cfg"); + + test_run_parser(test, "grub2"); + + check_boot_option_count(ctx, 3); +}