From nobody Tue Jan 24 22:14:04 2023 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4P1h8D6BVqz3bgq7; Tue, 24 Jan 2023 22:14:04 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19: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 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4P1h8D5fdwz3KLn; Tue, 24 Jan 2023 22:14:04 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674598444; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=A1xPOXCDXHHrJr/exs3PyBrToujfXhMFaFwlh41up20=; b=WfZ/oCVF1gvwwotaRI1pH3suz6o4jb5z8AI0ZbHC1V6gOcdhXb2Pw5Ts2zZgnJslD+y46P j8iUp5ahgr7SS6cv93cMv/klrntPvNV4h4o8IIDzZcYOUUizEv7lB7f3Ei+kd7GMhM9KlL OCukBry46di60ZE172NfJ46D3GTa+xn2u3u7+PvaEqLb/kag8QEm4Gn6TPFRPRsvk1BWzl AdkkZvi+F4BGn8OGbUYLQjbP7J3Owd5V2/mpocs5iYD+xVDt0o15p+dfmhDI2JqlipunFz l8kh8Xdgqc/g/H7W/0uLP1xZjPl3PrlBe1CBJ9xudclheN+FcTpWzh7wtI6xmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674598444; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=A1xPOXCDXHHrJr/exs3PyBrToujfXhMFaFwlh41up20=; b=tign1N67nsf5vNwotI2Ac/7PCMME5oF/zRrMuDG5EBB6Wt7gGUqHjve0G3dLXCUEP3N3TW 63AVbzCWOZy65akQ5o/0V7rwiDXijvX22WQo6hJk2mNlPOzNU2RVcvn/362VU86G8PARtv m33r1lnpScMmLsU+tlFSbDx45vWIRF4L1RWeN1Lj3poOUS3u6z/ezFZ/XOUkz+aofkc7SQ SkP1htJNI9tVHD9JL6kZkicIeW8epeHmFAkoRceEZ38Zt5nsbBdHjT04PZ06I5xwvzi1JI FB9x9iFfv1WaG/fiEGeF8Ack2nBetZnI4qkUDyZNeYfInwUbOrvGP2Ju7vyjYQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1674598444; a=rsa-sha256; cv=none; b=ud586qWBVs9H2rcvLNY+Njqxbl8VLmrjQM9SjzQf/gOZJMoMIR/vx7BX+OvVWC0T+VM0Zt gF4gS/f0qaohyEe2Ail6bL4d1aI8gpm1aCVzCEJSp1jG0J0bXprXKAUCnJmo4Evoz0u+e0 PN/C1wXBuhqUYd8bumshWH7gU9Zc2Z0cZBFCDKFCbMhT7MrwvTKTep9lbCd9IXmCnTboIu w3uCfTbnurQ83fzxNh8AAy/z2LRHgoc3UQUMrBUarXrPWWOPZpRZ9x52vrHT/YngdcbLpo kwYec4o1Ux3T7P9M5pbcDGhfEh70l/V3hcUeNkDNQ8IE6GiaNgWVvxTG+FoKng== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4P1h8D4J37zQs5; Tue, 24 Jan 2023 22:14:04 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 30OME466089311; Tue, 24 Jan 2023 22:14:04 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30OME482089310; Tue, 24 Jan 2023 22:14:04 GMT (envelope-from git) Date: Tue, 24 Jan 2023 22:14:04 GMT Message-Id: <202301242214.30OME482089310@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Warner Losh Subject: git: 4bebad28e66f - stable/13 - stand/kboot: Parse the command line args List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 4bebad28e66fc421c0546378bde0cc9f02b24638 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=4bebad28e66fc421c0546378bde0cc9f02b24638 commit 4bebad28e66fc421c0546378bde0cc9f02b24638 Author: Warner Losh AuthorDate: 2022-12-07 17:58:44 +0000 Commit: Warner Losh CommitDate: 2023-01-24 21:49:44 +0000 stand/kboot: Parse the command line args Do the standard command line parsing... With a small twist to deal with the quirks of booting via linuxboot to the initrd from the command line in shell.efi and other observed oddities. Sponsored by: Netflix (cherry picked from commit e1ff7945e1b3a9af34f092d9cca72ed802671c20) --- stand/kboot/main.c | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/stand/kboot/main.c b/stand/kboot/main.c index e8a9365b2c4c..2bbe14d79253 100644 --- a/stand/kboot/main.c +++ b/stand/kboot/main.c @@ -28,6 +28,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include @@ -75,6 +76,32 @@ kboot_getdev(void **vdev, const char *devspec, const char **path) return (devparse(dev, devspec, path)); } +static int +parse_args(int argc, const char **argv) +{ + int howto = 0; + + /* + * When run as init, sometimes argv[0] is a EFI-ESP path, other times + * it's the name of the init program, and sometimes it's a placeholder + * string, so we exclude it here. For the other args, look for DOS-like + * and Unix-like absolte paths and exclude parsing it if we find that, + * otherwise parse it as a command arg (so looking for '-X', 'foo' or + * 'foo=bar'). This is a little different than EFI where it argv[0] + * often times is the first argument passed in. There are cases when + * linux-booting via EFI that we have the EFI path we used to run + * bootXXX.efi as the arguments to init, so we need to exclude the paths + * there as well. + */ + for (int i = 1; i < argc; i++) { + if (argv[i][0] != '\\' && argv[i][0] != '/') { + howto |= boot_parse_arg(argv[i]); + } + } + + return (howto); +} + int main(int argc, const char **argv) { @@ -107,13 +134,8 @@ main(int argc, const char **argv) /* Initialize all the devices */ devinit(); - /* Choose bootdev if provided */ - if (argc > 1) - bootdev = argv[1]; - else - bootdev = ""; - if (argc > 2) - hostfs_root = argv[2]; + /* Parse the command line args -- ignoring for now the console selection */ + parse_args(argc, argv); printf("Boot device: %s with hostfs_root %s\n", bootdev, hostfs_root);