From patchwork Sat May 15 02:36:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1478772 X-Patchwork-Delegate: uboot@andestech.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; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=BkTMnxSF; 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 4FhqKn5DTzz9sW5 for ; Sat, 15 May 2021 12:36:54 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8DE0882061; Sat, 15 May 2021 04:36:46 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.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=gmail.com header.i=@gmail.com header.b="BkTMnxSF"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BB36D82AE1; Sat, 15 May 2021 04:36:44 +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,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qv1-xf32.google.com (mail-qv1-xf32.google.com [IPv6:2607:f8b0:4864:20::f32]) (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 BFD8D82061 for ; Sat, 15 May 2021 04:36:37 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qv1-xf32.google.com with SMTP id z1so618871qvo.4 for ; Fri, 14 May 2021 19:36:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=zHo1O3v8UyTrrvp4w1mfIh49UpM6rzFPPprwaviWMIw=; b=BkTMnxSFEOCqlsgDeFXAaRjWnF62M/TEDPmY4KKUo5/mMCk9Bf9Lu5+md1nyKdXGZr 5ZDq7HahiDuc1YzJbBNcyeCQqDO8Ky/ULtL8dw9A080Xd1u76zzEek3OCf/EhOf5eiTf vg1l5Q6M+MlI6DSEnhANHzIHr11rfQluHJVILOT4nYDvdvR+ebuflcj4i4w9OciBi8TM kvd9oMEnKzp3JLMzA8cPFqQbvVLNMIP7mfiBzd6uTyYn2AzSR/BMPB1Z3e+jPr4fEXFo suciGDoeNU8mCceFYejzjprNOnf804lfOdRauDdclhRhmW6dfbVZLQ/jtB12sVit2gZn 9VFw== 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:mime-version :content-transfer-encoding; bh=zHo1O3v8UyTrrvp4w1mfIh49UpM6rzFPPprwaviWMIw=; b=LtRN50hz3khI8whCg+r4OTLPh3llE+fd58fY0XJKSZutrtZUQ8X21j4pJROq/PghGK RDJkTjTOHZNONnbjbZvyg0q0qyHHczaX/HT8IzwrBbscdcUvF0hLsl3k0b0oI8PsbRzg 2vU0NB4N7LJhnYHTorbkMpKbKNOUBOBssIMbG9y8eSh6mvRM1GdxeY1zgQSJQmhJrl3a GvGw0kTf8UKN06boDK7ut354LA24RAAbNfL5fdp1HwjIWo5WdGPZUw7DskNg2uOno7Ga vYtovzxRUBA0nCq0zb+E6AzP3/Q3Ln3xvyW6CAsDfe4pNpos51TBW96TTPTA/k1JSVRx No+Q== X-Gm-Message-State: AOAM533DfZHLqfmQakj0sRaGVzyKfI40TvKZqwaK7I9E4VLq5cFzUIyk QYJ56JZL8ANoESgcj15+fDj1Iqs19As= X-Google-Smtp-Source: ABdhPJwd0HjOLTb+cGWS8/D21vDZ2ZZSskDJOznPpfFONpYrBk5poWgWffuK7hZuO/7kihBtfXUKZA== X-Received: by 2002:a05:6214:76b:: with SMTP id f11mr49800757qvz.8.1621046196416; Fri, 14 May 2021 19:36:36 -0700 (PDT) Received: from godwin.fios-router.home (pool-108-51-35-162.washdc.fios.verizon.net. [108.51.35.162]) by smtp.gmail.com with ESMTPSA id g6sm5697336qkm.120.2021.05.14.19.36.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 May 2021 19:36:35 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de, Rick Chen Cc: Bin Meng , Heinrich Schuchardt , Atish Patra , Sean Anderson Subject: [PATCH v2] riscv: Fix arch_fixup_fdt always failing without /chosen Date: Fri, 14 May 2021 22:36:16 -0400 Message-Id: <20210515023616.2488191-1-seanga2@gmail.com> X-Mailer: git-send-email 2.31.0 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.4 at phobos.denx.de X-Virus-Status: Clean If /chosen was missing, chosen_offset would never get updated with the new /chosen node. This would cause fdt_setprop_u32 to fail. This patch fixes this by setting chosen_offset. In addition, log any errors from setting boot-hartid as well. Fixes: 5370478d1c7 ("riscv: Add boot hartid to device tree") Signed-off-by: Sean Anderson Reviewed-by: Bin Meng Reviewed-by: Rick Chen Reviewed-by: Atish Patra --- I have not actually tested this (nor observed the original failure). But this seemed buggy from inspection. Changes in v2: - Fix "Fixes" pointing to wrong commit arch/riscv/lib/fdt_fixup.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/arch/riscv/lib/fdt_fixup.c b/arch/riscv/lib/fdt_fixup.c index 1f3f23621c..f636b28449 100644 --- a/arch/riscv/lib/fdt_fixup.c +++ b/arch/riscv/lib/fdt_fixup.c @@ -151,14 +151,17 @@ int arch_fixup_fdt(void *blob) } chosen_offset = fdt_path_offset(blob, "/chosen"); if (chosen_offset < 0) { - err = fdt_add_subnode(blob, 0, "chosen"); - if (err < 0) { + chosen_offset = fdt_add_subnode(blob, 0, "chosen"); + if (chosen_offset < 0) { log_err("chosen node cannot be added\n"); - return err; + return chosen_offset; } } /* Overwrite the boot-hartid as U-Boot is the last stage BL */ - fdt_setprop_u32(blob, chosen_offset, "boot-hartid", gd->arch.boot_hart); + err = fdt_setprop_u32(blob, chosen_offset, "boot-hartid", + gd->arch.boot_hart); + if (err < 0) + return log_msg_ret("could not set boot-hartid", err); #endif /* Copy the reserved-memory node to the DT used by OS */