From patchwork Thu May 19 22:26:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1633593 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=seco.com header.i=@seco.com header.a=rsa-sha256 header.s=selector1 header.b=ovdfYi7a; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4L44G446SVz9sFx for ; Fri, 20 May 2022 08:26:36 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5094283E3C; Fri, 20 May 2022 00:26:27 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=seco.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=seco.com header.i=@seco.com header.b="ovdfYi7a"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9F76C83E4C; Fri, 20 May 2022 00:26:25 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on0629.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe0c::629]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id ED2CD83E0F for ; Fri, 20 May 2022 00:26:20 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=seco.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sean.anderson@seco.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MPgw6a4ozPWmszOVXz8zvdgrJfRI6ypGaEAaLkc1DGitW4Fud72vyRXR9E5DOWlc4MU8KfRvKEAmAy3Zp211CV+GhhRV5koBnGBYCQ6eIlrojsgHtmi0N4Q3UCZmmLFosX78/sLTMQat1D61/q7W0ZbjslEyjUBF5RJ9s8sy37vp28An8+l56ZmGgkieM5LJx86q8zjKDtWPl6TE7F2o7i6IHvlqaeIr3qQiNGf+F6Rc2rWcPmdOmek6DlfbFiUV5NAlVtjEAI7efoQi3zSBX8mft/vXCzvLqG1TDBfi75Imk8TeoIOn0v2Sc4DYujGGEmChAzSOFiDxqaESyvjMNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=pyeC5qYXIQevtDWxC40UkTmGT9UuLuiK8gfuYpwzCM0=; b=mPHEZTkPDANLsphW2U0LM2qf2sGMChRGuvXIJQ8qe19zB9anu/qZ6/y8VvLHdqpUe/6bxgX8jmkNFPoOK/KLB7pP5vkrqViI+DEaz8T9FJHJlGsiu9FFJd4aoZdTjWe/iRl8ZsCsCZrWT5VRzvvT08YIulZx1opmEPnTLCUlitBCh/fGUsX+hHw5ygXr5owd08Ippyg3F8rObcNE64m0AkE2OnUQFzSJuTKX0Jizsuf9qMq8NUQhbr2SXcnnVLqkDjoDW+dcvHfdW2UUU1X2mQjLlks9xdxBBmlPVlSasqquEcullHuXN9jleF+mZhar6wzCH2K6RRTf15qXaoVufg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=seco.com; dmarc=pass action=none header.from=seco.com; dkim=pass header.d=seco.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seco.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pyeC5qYXIQevtDWxC40UkTmGT9UuLuiK8gfuYpwzCM0=; b=ovdfYi7aqXlhNzGGGVtpuCIAKV96AMYYb2Zf57nUEN6eipKRTqyh6XBWp2f/OH4hs56Cpvcpww1IKLkadfhwlCSCd/LBKbj/myqTDwkT2Gs6azOjvK1RemH7Q0M+yuYBaUoyic6dVOcQJ6zodzwKWuWtahxbaSis0O3wHTE3Op9c8jQI4QxKF5Juz0NXlxhH8D3UyQeSGAWvMv7GdmuOd243gchHWlK/d+DyWoeUp4642DCY0EfkxIKC1sb9t5Hs2NlCJQ2UQ8oZzAY2kLjgu1SXKDDsOG/ZI7nywQemXPX5w6Ov1v/mx93OWPWOqp2JzyJmOI4Al7g7MPH1z93BfA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=seco.com; Received: from DB7PR03MB4972.eurprd03.prod.outlook.com (2603:10a6:10:7d::22) by VE1PR03MB5454.eurprd03.prod.outlook.com (2603:10a6:802:a1::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5273.14; Thu, 19 May 2022 22:26:18 +0000 Received: from DB7PR03MB4972.eurprd03.prod.outlook.com ([fe80::cc0b:c665:8330:89bc]) by DB7PR03MB4972.eurprd03.prod.outlook.com ([fe80::cc0b:c665:8330:89bc%3]) with mapi id 15.20.5273.017; Thu, 19 May 2022 22:26:18 +0000 From: Sean Anderson To: Simon Glass , u-boot@lists.denx.de Cc: Tom Rini , Sean Anderson Subject: [PATCH] bootm: Fix Linux silent console on newer kernels Date: Thu, 19 May 2022 18:26:05 -0400 Message-Id: <20220519222605.2380731-1-sean.anderson@seco.com> X-Mailer: git-send-email 2.35.1.1320.gc452695387.dirty X-ClientProxiedBy: BL0PR02CA0111.namprd02.prod.outlook.com (2603:10b6:208:35::16) To DB7PR03MB4972.eurprd03.prod.outlook.com (2603:10a6:10:7d::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8f573519-9c1e-4c96-950d-08da39e69801 X-MS-TrafficTypeDiagnostic: VE1PR03MB5454:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Y6tSY8hnJ0ZGo27Je1CSD3Kc3UN32MzfghoFo4maR4nuUaVf0+OpT7MZINTtVLq/S3tKO8wERE7SLK590RL40wu7eWYPknkKtNcQtfPJhQcRRtZMyY+EEIvOLG/+8ZQ30TXav7jzN4rMciDEFKbMkhne4rlIcKuvCyp9oQlkpXm2EV+e5kTohNyvELhYA+QVzWvW1L95t7jwsVzICMe5cWvkpfO3b0RpGR1JYrVnWbeAHWHCYc+HX0jQjVrbr9jDiL+Mf4b+Z9FntMVihrvK9M0xb2y7+JD50rWNUss4E7HiSt+tExIdaS3Stj9KOkHgTKj3HjeLI+MBm9GjjNFjkKLZV6HcgMnaPawerYlTy9v/j0GR1gqISRGmypKQkPvs2XLFU6MD1xJK3J/ApD+dIeYkbNFCX2pcpunTrvF58MOTUoZbcjuRDMEF49RnjGhZ+4KeAT298BoT1Y1NNk0T6Q7F0Iijf44Ll+ecqdOguaBEqLtt0jN5FpGEXBjTJ/iALiLuK587+gHmkNrDWUirLQAeqNv6/y546XicvYQ1NFK8GmxwFYjWbqGGoJpPoflnu1vQhTLztFgnmpRljrpSdwIJwUZoGiAlimjdkg4NtuESPeHHvS9P2LjIsN0/pD1Q2uZm9gNMc0/NBnllx/9J4Mp2hipYf9X6a3WMmOP6bHHzasRlr8vb2N7nDrsrYTmsj2P1ARLyeomccljfEyvX7fMAAIKruSUntmcBQcAk/DzpmFfuLY+mh5Fo4umwkNss8ma0wNrQBgEPGKVxa4qOtIjrf2UhuN4dQ4IrOG5nw1U= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB7PR03MB4972.eurprd03.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(54906003)(86362001)(316002)(6666004)(6512007)(38350700002)(38100700002)(2616005)(1076003)(66556008)(36756003)(2906002)(66946007)(52116002)(6506007)(186003)(8676002)(4326008)(83380400001)(966005)(26005)(6486002)(8936002)(44832011)(107886003)(508600001)(5660300002)(66476007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: /C0t9eoRhynSmEjvW48xvngy7aypOQU/rRizb8BlOQCFZore6crPIfuBIHepw5P52+2X/lNSRpH/BexhGYVwYCkEc8AImBDzZKJdEEv4i2KczCAiZYRMZOhhnQCIyUkj7YWCWYroxCylGGFZWyu7BRv29GIa/D2wpEpAmHW8KiUIAaMTkcrrfq1hvx6Uy9V5M5FpGbiufXmhIugaz9boWhtFmHX8Kr1yw9j+OLmemZHnLBivlgYsHsJFf+uZf6LLbsS7zJ1eFsTNXFM1hHNt3TKAraJZlnDyDkLDyvyVXR5UecduyeyMLA0rZvMCV35AYEPxmiBwj38Y+HmVlx5TXER5lhe/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V398dMxnEAFCon+6hsvsGWPPqUpaDJDmgUTpH5HE6aQt40eXD/+nU9Lsr6Hhwu2RrkBZi9FoEKSsYjsmn7OfxgL9Fil8IFBzChmc4NIwIsIHBMDg6TOdTz0iv8I41WCS1QGw2sLcgGxpylwE1X0JCyooTjcFXs27WReSHm18UrNW2/lmBnYzqgKwX1b8/DKiFhrjn3z41opP7F/NoywyQQccmadvzR1yBUU3h+Ki2t4QH2tJ/CwFLn6DT7XJNezAJPA6mKm7ahJVltoFTq6HBqCaMT9MNBioFZaL2I9s+8xiYRXRhrDvmFmA7WWkRE6tnPTJkEjgYBBUQWDq4vXXQqo= X-OriginatorOrg: seco.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8f573519-9c1e-4c96-950d-08da39e69801 X-MS-Exchange-CrossTenant-AuthSource: DB7PR03MB4972.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2022 22:26:18.3410 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bebe97c3-6438-442e-ade3-ff17aa50e733 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 9iSUF73GuXxHbtGQIiaW/sVud/KMIpJRKb3tt4Wz18pTltkBKLjRnkNhv1C635IurHgYHuxf+THFXJyG9+d3wg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR03MB5454 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean Linux determines its console based on several sources: 1. the console command line parameter 2. device tree (e.g. /chosen/stdout-path) 3. various other board- and arch-specific sources If the console parameter specifies a real console (e.g. ttyS0) then that is used as /dev/console. However, if it does not specify a real console (e.g. ttyDoesntExist) then *nothing* will be used as /dev/console. Reading/writing it will return ENODEV. Additionally, no other source will be used as a console source. Linux commit ab4af56ae250 ("printk/console: Allow to disable console output by using console="" or console=null") recently changed the semantics of the parameter. Previously, specifying console="" would be treated like specifying some other bad console. This commit changed things so that it added /dev/ttynull as a console (if available). However, it also allows for other console sources. If the device tree specifies a console (such as if U-Boot and Linux share a device tree), then it will be used in addition to /dev/ttynull. This can result in a non-silent console. To avoid this, explicitly set ttynull as the console. This will disable other console sources. If CONFIG_NULL_TTY is disabled, then this will have the same behavior as in the past (no output, and writing /dev/console returns ENODEV). [1] and [2] have additional background on this kernel change. [1] https://lore.kernel.org/all/20201006025935.GA597@jagdpanzerIV.localdomain/ [2] https://lore.kernel.org/all/20201111135450.11214-1-pmladek@suse.com/ Signed-off-by: Sean Anderson --- boot/bootm.c | 16 +++++++++------- test/bootm.c | 20 ++++++++++---------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/boot/bootm.c b/boot/bootm.c index 714406ab66..dfa65f125e 100644 --- a/boot/bootm.c +++ b/boot/bootm.c @@ -498,7 +498,8 @@ ulong bootm_disable_interrupts(void) } #define CONSOLE_ARG "console=" -#define CONSOLE_ARG_SIZE sizeof(CONSOLE_ARG) +#define NULL_CONSOLE (CONSOLE_ARG "ttynull") +#define CONSOLE_ARG_SIZE sizeof(NULL_CONSOLE) /** * fixup_silent_linux() - Handle silencing the linux boot if required @@ -550,21 +551,22 @@ static int fixup_silent_linux(char *buf, int maxlen) char *end = strchr(start, ' '); int start_bytes; - start_bytes = start - cmdline + CONSOLE_ARG_SIZE - 1; + start_bytes = start - cmdline; strncpy(buf, cmdline, start_bytes); + strncpy(buf + start_bytes, NULL_CONSOLE, CONSOLE_ARG_SIZE); if (end) - strcpy(buf + start_bytes, end); + strcpy(buf + start_bytes + CONSOLE_ARG_SIZE - 1, end); else - buf[start_bytes] = '\0'; + buf[start_bytes + CONSOLE_ARG_SIZE] = '\0'; } else { - sprintf(buf, "%s %s", cmdline, CONSOLE_ARG); + sprintf(buf, "%s %s", cmdline, NULL_CONSOLE); } if (buf + strlen(buf) >= cmdline) return -ENOSPC; } else { - if (maxlen < sizeof(CONSOLE_ARG)) + if (maxlen < CONSOLE_ARG_SIZE) return -ENOSPC; - strcpy(buf, CONSOLE_ARG); + strcpy(buf, NULL_CONSOLE); } debug("after silent fix-up: %s\n", buf); diff --git a/test/bootm.c b/test/bootm.c index 8528982ae1..7d03e1e0c6 100644 --- a/test/bootm.c +++ b/test/bootm.c @@ -83,12 +83,12 @@ static int bootm_test_silent(struct unit_test_state *uts) ut_assertok(env_set("silent_linux", "yes")); ut_assertok(bootm_process_cmdline(buf, BUF_SIZE, BOOTM_CL_SILENT)); - ut_asserteq_str("console=", buf); + ut_asserteq_str("console=ttynull", buf); /* Empty buffer should still add the string */ *buf = '\0'; ut_assertok(bootm_process_cmdline(buf, BUF_SIZE, BOOTM_CL_SILENT)); - ut_asserteq_str("console=", buf); + ut_asserteq_str("console=ttynull", buf); /* Check nothing happens when do_silent is false */ *buf = '\0'; @@ -97,21 +97,21 @@ static int bootm_test_silent(struct unit_test_state *uts) /* Not enough space */ *buf = '\0'; - ut_asserteq(-ENOSPC, bootm_process_cmdline(buf, 8, BOOTM_CL_SILENT)); + ut_asserteq(-ENOSPC, bootm_process_cmdline(buf, 15, BOOTM_CL_SILENT)); /* Just enough space */ *buf = '\0'; - ut_assertok(bootm_process_cmdline(buf, 9, BOOTM_CL_SILENT)); + ut_assertok(bootm_process_cmdline(buf, 16, BOOTM_CL_SILENT)); /* add at end */ strcpy(buf, "something"); ut_assertok(bootm_process_cmdline(buf, BUF_SIZE, BOOTM_CL_SILENT)); - ut_asserteq_str("something console=", buf); + ut_asserteq_str("something console=ttynull", buf); /* change at start */ strcpy(buf, CONSOLE_STR " something"); ut_assertok(bootm_process_cmdline(buf, BUF_SIZE, BOOTM_CL_SILENT)); - ut_asserteq_str("console= something", buf); + ut_asserteq_str("console=ttynull something", buf); return 0; } @@ -210,12 +210,12 @@ static int bootm_test_subst_var(struct unit_test_state *uts) { env_set("bootargs", NULL); ut_assertok(bootm_process_cmdline_env(BOOTM_CL_SILENT)); - ut_asserteq_str("console=", env_get("bootargs")); + ut_asserteq_str("console=ttynull", env_get("bootargs")); ut_assertok(env_set("var", "abc")); ut_assertok(env_set("bootargs", "some${var}thing")); ut_assertok(bootm_process_cmdline_env(BOOTM_CL_SILENT)); - ut_asserteq_str("some${var}thing console=", env_get("bootargs")); + ut_asserteq_str("some${var}thing console=ttynull", env_get("bootargs")); return 0; } @@ -227,12 +227,12 @@ static int bootm_test_subst_both(struct unit_test_state *uts) ut_assertok(env_set("silent_linux", "yes")); env_set("bootargs", NULL); ut_assertok(bootm_process_cmdline_env(BOOTM_CL_ALL)); - ut_asserteq_str("console=", env_get("bootargs")); + ut_asserteq_str("console=ttynull", env_get("bootargs")); ut_assertok(env_set("bootargs", "some${var}thing " CONSOLE_STR)); ut_assertok(env_set("var", "1234567890")); ut_assertok(bootm_process_cmdline_env(BOOTM_CL_ALL)); - ut_asserteq_str("some1234567890thing console=", env_get("bootargs")); + ut_asserteq_str("some1234567890thing console=ttynull", env_get("bootargs")); return 0; }