From patchwork Mon Oct 19 13:55:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1384321 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=ITDrIAmj; dkim-atps=neutral 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 (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CFJJL6xlqz9sPB for ; Tue, 20 Oct 2020 00:58:42 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3F39182444; Mon, 19 Oct 2020 15:56:37 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="ITDrIAmj"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2A3588236F; Mon, 19 Oct 2020 15:56:27 +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.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x141.google.com (mail-il1-x141.google.com [IPv6:2607:f8b0:4864:20::141]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E0D5E8236F for ; Mon, 19 Oct 2020 15:56:15 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-il1-x141.google.com with SMTP id l16so66982ilt.13 for ; Mon, 19 Oct 2020 06:56:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KDCqnaHnk2uhJ3cu2NqsovFVe5o/u01YqSgSY0143zE=; b=ITDrIAmjed/rqowBKkHwm8ld1DkXUm87egdEnKTw+KmfsaVrBZAzXRRPOgpc0JjfSk MuaYfz8im0wtmMRLr7Me8VLLvQHFi09dBwKtrNpEF2jCt2bHQNfQMgSQ4CBo4h2AJ6Cc kBS2f6mKwGHP2wUdEl6jhpyFr6tWPmP1yhNvc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KDCqnaHnk2uhJ3cu2NqsovFVe5o/u01YqSgSY0143zE=; b=Rdc7/rPTzg4XjmLJEI86rBSVAGvPCBSJ/+Liv8LDtkKI9TxTtHCeLYNKKrRr/ss6/N fVm8y7mSBSp2XDzGDTntg+Ai6CJtB9Poo22UtgG8ZR4VN3RTKfeCZtd+zm/2j/0K+pV6 PV5PL6VsTHRXU7vb2ATlJgoJdmqGNmRAmabTOaNEZCVorVNifZevek9HCG5vEHqbmyLZ 8sb9L1p/AjNOemygWAEZ29JVPaYRAca/QGkNoB39fOSsoPudXSjp9N40PzSxG+Xm20HJ WV/pttO3YBaK/o5rDxy/vrI9KhZNx98jRyCTmTu/BTezocBqisEVevHeaR7Luxlq8/lb QlGg== X-Gm-Message-State: AOAM530NNKAB9REMwfdGk674PTYFMR/rjuo5fL6iGGy8cX7qSkJ5KA5Q PTutPFBlRMUQbINfhwZBCS95/NHD+oiuFaqu X-Google-Smtp-Source: ABdhPJyyL6VM9LMzeeEgnDUmMqMISoQWZGU8N6G5I7/1oYXUwqi/cdgRJ9KYu0x0lGTHVkXf5k0pfw== X-Received: by 2002:a05:6e02:13ac:: with SMTP id h12mr31557ilo.142.1603115773265; Mon, 19 Oct 2020 06:56:13 -0700 (PDT) Received: from localhost.localdomain (c-73-14-175-90.hsd1.co.comcast.net. [73.14.175.90]) by smtp.gmail.com with ESMTPSA id r17sm10164078iov.7.2020.10.19.06.56.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Oct 2020 06:56:12 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Andy Shevchenko , Heinrich Schuchardt , Bernhard Messerklinger , Wolfgang Wallner , Walter Lozano , Simon Glass , Daniel Schwierzeck , Michael Walle , Tero Kristo Subject: [PATCH 03/11] bootm: Update fixup_silent_linux() to return an error Date: Mon, 19 Oct 2020 07:55:54 -0600 Message-Id: <20201019135602.3943835-4-sjg@chromium.org> X-Mailer: git-send-email 2.29.0.rc1.297.gfa9743e501-goog In-Reply-To: <20201019135602.3943835-1-sjg@chromium.org> References: <20201019135602.3943835-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.3 at phobos.denx.de X-Virus-Status: Clean At present this function fails silently on error. Update it to produce an error code. Report this error to the user and abort the boot, since it likely will prevent a successful start. No tests are added at this stage, since additional refactoring is taking place in subsequent patches. Signed-off-by: Simon Glass --- common/bootm.c | 22 +++++++++++++++------- include/bootm.h | 11 +++++++++-- test/bootm.c | 10 +++++----- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/common/bootm.c b/common/bootm.c index 8e1e5337036..0ca66188c2b 100644 --- a/common/bootm.c +++ b/common/bootm.c @@ -466,7 +466,7 @@ ulong bootm_disable_interrupts(void) #define CONSOLE_ARG "console=" #define CONSOLE_ARG_LEN (sizeof(CONSOLE_ARG) - 1) -void fixup_silent_linux(void) +int fixup_silent_linux(void) { char *buf; const char *env_val; @@ -475,7 +475,7 @@ void fixup_silent_linux(void) if (!IS_ENABLED(CONFIG_SILENT_CONSOLE) && !IS_ENABLED(CONFIG_SILENT_U_BOOT_ONLY)) - return; + return 0; cmdline = env_get("bootargs"); /* @@ -487,9 +487,9 @@ void fixup_silent_linux(void) */ want_silent = env_get_yesno("silent_linux"); if (want_silent == 0) - return; + return 0; else if (want_silent == -1 && !(gd->flags & GD_FLG_SILENT)) - return; + return 0; debug("before silent fix-up: %s\n", cmdline); if (cmdline && (cmdline[0] != '\0')) { @@ -499,7 +499,7 @@ void fixup_silent_linux(void) buf = malloc(strlen(cmdline) + 1 + CONSOLE_ARG_LEN + 1); if (!buf) { debug("%s: out of memory\n", __func__); - return; + return -ENOSPC; } if (start) { @@ -523,6 +523,8 @@ void fixup_silent_linux(void) env_set("bootargs", env_val); debug("after silent fix-up: %s\n", env_val); free(buf); + + return 0; } /** @@ -627,8 +629,14 @@ int do_bootm_states(struct cmd_tbl *cmdtp, int flag, int argc, if (!ret && (states & BOOTM_STATE_OS_BD_T)) ret = boot_fn(BOOTM_STATE_OS_BD_T, argc, argv, images); if (!ret && (states & BOOTM_STATE_OS_PREP)) { - if (images->os.os == IH_OS_LINUX) - fixup_silent_linux(); + if (images->os.os == IH_OS_LINUX) { + ret = fixup_silent_linux(); + if (ret) { + printf("Cmdline setup failed (err=%d)\n", ret); + ret = CMD_RET_FAILURE; + goto err; + } + } ret = boot_fn(BOOTM_STATE_OS_PREP, argc, argv, images); } diff --git a/include/bootm.h b/include/bootm.h index 6d675e64559..438829af0fe 100644 --- a/include/bootm.h +++ b/include/bootm.h @@ -85,7 +85,14 @@ void arch_preboot_os(void); */ void board_preboot_os(void); -/* Adjust the 'bootargs' to ensure that Linux boots silently, if required */ -void fixup_silent_linux(void); +/* + * fixup_silent_linux() - Process fix-ups for the command line + * + * Updates the 'bootargs' envvar as required. This handles making Linux boot + * silently if requested ('silent_linux' envvar) + * + * @return 0 if OK, -ENOMEM if out of memory + */ +int fixup_silent_linux(void); #endif diff --git a/test/bootm.c b/test/bootm.c index 59d16cb3df6..ab1711609ba 100644 --- a/test/bootm.c +++ b/test/bootm.c @@ -23,26 +23,26 @@ static int bootm_test_silent_var(struct unit_test_state *uts) /* 'silent_linux' not set should do nothing */ env_set("silent_linux", NULL); env_set("bootargs", CONSOLE_STR); - fixup_silent_linux(); + ut_assertok(fixup_silent_linux()); ut_asserteq_str(CONSOLE_STR, env_get("bootargs")); env_set("bootargs", NULL); - fixup_silent_linux(); + ut_assertok(fixup_silent_linux()); ut_assertnull(env_get("bootargs")); ut_assertok(env_set("silent_linux", "no")); env_set("bootargs", CONSOLE_STR); - fixup_silent_linux(); + ut_assertok(fixup_silent_linux()); ut_asserteq_str(CONSOLE_STR, env_get("bootargs")); ut_assertok(env_set("silent_linux", "yes")); env_set("bootargs", CONSOLE_STR); - fixup_silent_linux(); + ut_assertok(fixup_silent_linux()); ut_asserteq_str("console=", env_get("bootargs")); /* Empty buffer should still add the string */ env_set("bootargs", NULL); - fixup_silent_linux(); + ut_assertok(fixup_silent_linux()); ut_asserteq_str("console=", env_get("bootargs")); return 0;