From patchwork Wed Mar 14 16:31:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Palmer Dabbelt X-Patchwork-Id: 885912 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.b="NwDi7CDH"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 401cnR4pgQz9sTs for ; Thu, 15 Mar 2018 03:36:59 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752150AbeCNQg5 (ORCPT ); Wed, 14 Mar 2018 12:36:57 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:45390 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751456AbeCNQgy (ORCPT ); Wed, 14 Mar 2018 12:36:54 -0400 Received: by mail-pf0-f196.google.com with SMTP id h19so1622022pfd.12 for ; Wed, 14 Mar 2018 09:36:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=subject:date:message-id:cc:from:to; bh=OqkbVaZXKGTeb+bDRwq/93eJ35ur6B3wy2STMcQsy6s=; b=NwDi7CDHWzo3jHEsnrtXleV676SaFUhu8Hd+woJDZ9ZIeBz3bUUykL8OmiPfYuZXeE 5OfP/CnqZ4Ofvr9zalTN/sMQ2QhBCA3qZ7s07hVXhQjiOQXpiSAXqjOVPo1b21Kp8dCa prKFMSBs9HiJhCng3QthrJZd2eEBmHhRMnUUTcJgkroxLUSumIFCnmi8qHKBc12SwXte KmqyDfRE2SN0Mt1hFWJTCbRYVCjlGOAJI7ewLsJ7XL9Hf0uzWGbdcn1xRrmh38WhWHZc bUgHl5jr+jRC8/AxPXI3+WG6Qpzy2EkzjS7WIbWvw0r8yh93smAT7TmaoRZqh1P+CbYj Dehw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:date:message-id:cc:from:to; bh=OqkbVaZXKGTeb+bDRwq/93eJ35ur6B3wy2STMcQsy6s=; b=OL/mTFsPGmQNhC4qa4I531rjBd0FfpsfJ04Fa+ZTzi62cmI05FN+nG1aPS3cedLKXk AXVcaf+3j6XvPl05GPZcw54dI42wKSUiCK282Fc5GAfXborcRZ5WMQDd4ql5vKV606/d 0lXlI3AwnAbbI5Go+w3OMJ07ypNXM3Q6CjKR7l54Pdag9oTYYDK8oi1P7/mf01qunMRB FZ6fobr+31teaKPeCG88Gd0/kD+oYa8u0JWieqUGtLRH/ghczZv47lkiHzaLIYrOlG/L m94nZ8twUjSAXHc0xOeQY71Ey/lrFdGfQtqtcjSesGY6i0gb5vLejj8cw1fdCvrEWz9P w8yg== X-Gm-Message-State: AElRT7HKGfTspXXSdAOpxV7V3M0kkCybEIyQ3AbMwooP+kMCu2mU3K+3 iYtK6ypL9JEqNbTlnAnr6tuw/3yXIJ4= X-Google-Smtp-Source: AG47ELsWUPwMuEezHFB0fWV3tAEk3ZcnsgqUu0UUc+ud6K4q3iDEhOqSvzhhCHDo71kPKBYjITAqmQ== X-Received: by 10.101.101.205 with SMTP id y13mr4156566pgv.265.1521045413751; Wed, 14 Mar 2018 09:36:53 -0700 (PDT) Received: from localhost ([65.153.83.185]) by smtp.gmail.com with ESMTPSA id r9sm6477675pfg.11.2018.03.14.09.36.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Mar 2018 09:36:50 -0700 (PDT) Subject: [PATCH] of: Respect CONFIG_CMDLINE{, _EXTENED, _FORCE) with no chosen node Date: Wed, 14 Mar 2018 09:31:05 -0700 Message-Id: <20180314163105.8638-1-palmer@sifive.com> X-Mailer: git-send-email 2.16.1 Cc: Palmer Dabbelt , Michael J Clark , Trung Tran , Moritz Fischer From: Palmer Dabbelt To: robh+dt@kernel.org, frowand.list@gmail.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Systems that boot without a chosen node in the device tree should still respect the command lines that are built into the kernel. This patch avoids bailing out of the command line argument parsing code when there is no chosen node in the device tree. This is necessary to boot straight to a root file system (ie, without an initramfs) The intent here is that the only functional change is to copy CONFIG_CMDLINE into data if both of them are valid (ie, CONFIG_CMDLINE is defined and data is non-null) on systems where there is no chosen device tree node. I don't actually know what the return values do so I just preserved them. Thanks to Trung and Moritz for finding the bug during our ELC hackathon (and providing the first fix), and Michal for suggesting this fix (which is cleaner than what I was doing). I've given this very minimal testing: it fixes the RISC-V bug (in conjunction with a patch to move from COMMANDLINE_OVERRIDE to COMMANDLINE_FORCE), still works on systems with and without the chosen node, and builds on ARM64. CC: Michael J Clark CC: Trung Tran CC: Moritz Fischer Signed-off-by: Palmer Dabbelt --- drivers/of/fdt.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 84aa9d676375..60241b1cb024 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -1084,9 +1084,12 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname, pr_debug("search \"chosen\", depth: %d, uname: %s\n", depth, uname); - if (depth != 1 || !data || + if (!data) + goto no_data; + + if (depth != 1 || (strcmp(uname, "chosen") != 0 && strcmp(uname, "chosen@0") != 0)) - return 0; + goto no_chosen; early_init_dt_check_for_initrd(node); @@ -1117,6 +1120,13 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname, /* break now */ return 1; + +no_chosen: +#ifdef CONFIG_CMDLINE + strlcpy(data, CONFIG_CMDLINE, COMMAND_LINE_SIZE); +#endif +no_data: + return 0; } #ifdef CONFIG_HAVE_MEMBLOCK