From patchwork Thu Apr 21 05:56:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 12821118 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3AEB8C433EF for ; Thu, 21 Apr 2022 06:02:38 +0000 (UTC) Received: from localhost ([::1]:60352 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nhPtk-0003fr-Ue for qemu-devel@archiver.kernel.org; Thu, 21 Apr 2022 02:02:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46982) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nhPnz-0000Gw-Rw; Thu, 21 Apr 2022 01:56:40 -0400 Received: from mail-pg1-x534.google.com ([2607:f8b0:4864:20::534]:39896) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nhPny-0001pz-6g; Thu, 21 Apr 2022 01:56:39 -0400 Received: by mail-pg1-x534.google.com with SMTP id q19so3773201pgm.6; Wed, 20 Apr 2022 22:56:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=qHnzDGKqIh6N1cF4DxeQPk7+iSRYpnz5A7I979NUz/Q=; b=azh2mIswGaLx4j5hZnATirQxHgXHFVm716mCX3eOZcb/ntC4qoW9f0NEumJqAcSYyW c6knSx3c2w2fLb9lfxKCmd107ZareZBqRRNBb4fHYp0M1IFX19a/D2xx8aZOqC+mH9Xy VEdCLoAIo9TMIGJ6aodio4UL4uHfgOFt6kQHMGv5zki+Ag9rB+3yVkO39D5qEda5l3+s azqrCj+a/193Vm3KpAlx7l5CMzxB4j3shXLvSMHS2l+X6bk6/EFf/3z+jRW6XRVewWKf qnAr3ncGcWmwDsU58O8ISuDV0dJB96DAWN4MyNOuqxBTeV24eKRJ0ZObywvq9mSs1GEq 7ZPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=qHnzDGKqIh6N1cF4DxeQPk7+iSRYpnz5A7I979NUz/Q=; b=tZruULg47vq8pKT8u/yPgxbei0XfCuxxjaqctV1o8Pb2ZS1Zpk6PP584ZbR6RLcADM oia/nN7X/jsS1tzYpe3Y5N+9oVxEAaY8pcPomSafumaa0rhLFrIj8+Yaf8csnGvzlpAf uttvsZHlUBNtw8mDrSAFczm8akqdYYmGAA9kraJasWusVgTmGn4jHQaJfEdziwwD/fX9 1/kexLOv+jKc4NnXETFodNeZqmSfTIAFCTu3SnKgee1rnxMRvo4xeuBJcjdSvRXfB1Uk XhCUeQwI7iuuwDnUXOXv1QydTV0LHF3mGT5Nn7gFsgIDVCKFe/2SFRuhes30LzVU9sPw dwaQ== X-Gm-Message-State: AOAM532JYQJWwH6aqPhAqlpfdVkOQMcAQYU4y20NXATE1v5kmPtPLhdi kMJZUXI5RCcEg7WAkcAY4zE= X-Google-Smtp-Source: ABdhPJwJR/9NNxf/r2b8DR1gkCSH7bt5VrWdwTTavEXgNMPTpNVKmbh/umfA2tELsvy2W/lZnlQV+g== X-Received: by 2002:a63:5fcb:0:b0:3aa:5209:471d with SMTP id t194-20020a635fcb000000b003aa5209471dmr8298489pgb.36.1650520595912; Wed, 20 Apr 2022 22:56:35 -0700 (PDT) Received: from pek-vx-bsp2.wrs.com (unknown-176-192.windriver.com. [147.11.176.192]) by smtp.gmail.com with ESMTPSA id x16-20020a17090ab01000b001cd4989ff4bsm1169300pjq.18.2022.04.20.22.56.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Apr 2022 22:56:35 -0700 (PDT) From: Bin Meng To: Alistair Francis , qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH 1/2] hw/riscv: spike: Add '/chosen/stdout-path' in device tree unconditionally Date: Thu, 21 Apr 2022 13:56:28 +0800 Message-Id: <20220421055629.1177285-1-bmeng.cn@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::534; envelope-from=bmeng.cn@gmail.com; helo=mail-pg1-x534.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Bin Meng , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Bin Meng At present the adding '/chosen/stdout-path' property in device tree is determined by whether a kernel command line is provided, which is wrong. It should be added unconditionally. Fixes: 8d8897accb1c ("hw/riscv: spike: Allow using binary firmware as bios") Signed-off-by: Bin Meng Reviewed-by: Alistair Francis --- hw/riscv/spike.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hw/riscv/spike.c b/hw/riscv/spike.c index d059a67f9b..1562b000bb 100644 --- a/hw/riscv/spike.c +++ b/hw/riscv/spike.c @@ -174,10 +174,11 @@ static void create_fdt(SpikeState *s, const MemMapEntry *memmap, riscv_socket_fdt_write_distance_matrix(mc, fdt); + qemu_fdt_add_subnode(fdt, "/chosen"); + qemu_fdt_setprop_string(fdt, "/chosen", "stdout-path", "/htif"); + if (cmdline) { - qemu_fdt_add_subnode(fdt, "/chosen"); qemu_fdt_setprop_string(fdt, "/chosen", "bootargs", cmdline); - qemu_fdt_setprop_string(fdt, "/chosen", "stdout-path", "/htif"); } } From patchwork Thu Apr 21 05:56:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 12821119 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6A9B4C433F5 for ; Thu, 21 Apr 2022 06:03:10 +0000 (UTC) Received: from localhost ([::1]:60914 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nhPuH-0004CJ-89 for qemu-devel@archiver.kernel.org; Thu, 21 Apr 2022 02:03:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46996) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nhPo3-0000KS-2z; Thu, 21 Apr 2022 01:56:48 -0400 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]:43645) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nhPo1-0001qE-DG; Thu, 21 Apr 2022 01:56:42 -0400 Received: by mail-pg1-x536.google.com with SMTP id g9so3762028pgc.10; Wed, 20 Apr 2022 22:56:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=s6nteJyOWgHk0MoyoL2TKp3HlZWDYswLgM5u+BHfpFU=; b=P5QZ0JOhSvW1bH2LzG0rbY61YQcEjrlCBTuJNXcbx3LSZjOd5qLvY7byQo7C4p2SzB o5qgx8dom6qtIlCAeBi2laPEnOhlnhyO0zyhfA0Lg58ik86CCAw89RriP7lctZ3I2U6b kTO25IGp79jzJjUt/QUc6lmC/IMRmJPmNcE2bUKqOlTeN9PtNWo0LU+/SxNd5v9W0+14 r0AU1dAXfK9Kc97WAUrHMen2cRKLMoXtKDO+RHP3KbwnsbLDYyh1cZCR8MY2R9ixDEbT eJsEQR/iXoEc+nHh7c8483nWIDU3POitCl9K5A7d6W+8ak73AAxktLmd1oF2fIEb7O+3 963w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=s6nteJyOWgHk0MoyoL2TKp3HlZWDYswLgM5u+BHfpFU=; b=RW0N7zgxxeAl+YyEoJPcWJeys5lJ6FzN3TU4eBB2rhij2HUuu2Y04GTVBTLXtsi4j1 c1U3IUpMGKCUWT+gjGKVJ+G3XxsAceVJ3GKKpYVOH6+zvs9sHqlYSLezohokUtFAZjD1 FqfV7R0GlQEvaVQza1VhujBG/qBlRFQmeAM+pecAANiZ12uN/BbDWwjr+F1xJIo57VWl IFpyEisErN7u6a5VQFTWVBoXVPOIN9g55RXXEzjI2WwHDu4XwrnpannvLafkjstK2Yoj GEZpKscyYkGxXfgFyzKSwvZb9rGIO0e9HwUmB5W2g3n5TdBfqrsxwAqCRkXRv/e1Tmax xL+g== X-Gm-Message-State: AOAM533KI9LNL9nSrOrtl35cHcV8vgrb63ZSqprQgA/uwiR2d5ZYL2Z9 RizwQ3nRvXmiV2WUziG7zxb6etlhZ2c= X-Google-Smtp-Source: ABdhPJy0Vj/YSBj3brl0wBFw0avUwELQZwTtJ3J9IUQ9xiX39eg8tIe16a3Mu2+ogVeZNk+akY8xpQ== X-Received: by 2002:a05:6a00:1490:b0:4fb:1544:bc60 with SMTP id v16-20020a056a00149000b004fb1544bc60mr27022013pfu.73.1650520599624; Wed, 20 Apr 2022 22:56:39 -0700 (PDT) Received: from pek-vx-bsp2.wrs.com (unknown-176-192.windriver.com. [147.11.176.192]) by smtp.gmail.com with ESMTPSA id x16-20020a17090ab01000b001cd4989ff4bsm1169300pjq.18.2022.04.20.22.56.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Apr 2022 22:56:39 -0700 (PDT) From: Bin Meng To: Alistair Francis , qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH 2/2] hw/riscv: Don't add empty bootargs to device tree Date: Thu, 21 Apr 2022 13:56:29 +0800 Message-Id: <20220421055629.1177285-2-bmeng.cn@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220421055629.1177285-1-bmeng.cn@gmail.com> References: <20220421055629.1177285-1-bmeng.cn@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::536; envelope-from=bmeng.cn@gmail.com; helo=mail-pg1-x536.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Bin Meng , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Bin Meng Commit 7c28f4da20e5 ("RISC-V: Don't add NULL bootargs to device-tree") tried to avoid adding *NULL* bootargs to device tree, but unfortunately the changes were entirely useless, due to MachineState::kernel_cmdline can't be NULL at all as the default value is given as an empty string. (see hw/core/machine.c::machine_initfn()). Note the wording of *NULL* bootargs is wrong. It can't be NULL otherwise a segfault had already been observed by dereferencing the NULL pointer. It should be worded as *empty" bootargs. Fixes: 7c28f4da20e5 ("RISC-V: Don't add NULL bootargs to device-tree") Signed-off-by: Bin Meng Reviewed-by: Alistair Francis --- hw/riscv/microchip_pfsoc.c | 2 +- hw/riscv/sifive_u.c | 2 +- hw/riscv/spike.c | 2 +- hw/riscv/virt.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/hw/riscv/microchip_pfsoc.c b/hw/riscv/microchip_pfsoc.c index cafd1fc9ae..10a5d0e501 100644 --- a/hw/riscv/microchip_pfsoc.c +++ b/hw/riscv/microchip_pfsoc.c @@ -571,7 +571,7 @@ static void microchip_icicle_kit_machine_init(MachineState *machine) "linux,initrd-end", end); } - if (machine->kernel_cmdline) { + if (machine->kernel_cmdline && *machine->kernel_cmdline) { qemu_fdt_setprop_string(machine->fdt, "/chosen", "bootargs", machine->kernel_cmdline); } diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c index 7fbc7dea42..cc8c7637cb 100644 --- a/hw/riscv/sifive_u.c +++ b/hw/riscv/sifive_u.c @@ -511,7 +511,7 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap, g_free(nodename); update_bootargs: - if (cmdline) { + if (cmdline && *cmdline) { qemu_fdt_setprop_string(fdt, "/chosen", "bootargs", cmdline); } } diff --git a/hw/riscv/spike.c b/hw/riscv/spike.c index 1562b000bb..068ba3493e 100644 --- a/hw/riscv/spike.c +++ b/hw/riscv/spike.c @@ -177,7 +177,7 @@ static void create_fdt(SpikeState *s, const MemMapEntry *memmap, qemu_fdt_add_subnode(fdt, "/chosen"); qemu_fdt_setprop_string(fdt, "/chosen", "stdout-path", "/htif"); - if (cmdline) { + if (cmdline && *cmdline) { qemu_fdt_setprop_string(fdt, "/chosen", "bootargs", cmdline); } } diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index da50cbed43..a628a3abdf 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -998,7 +998,7 @@ static void create_fdt(RISCVVirtState *s, const MemMapEntry *memmap, create_fdt_flash(s, memmap); update_bootargs: - if (cmdline) { + if (cmdline && *cmdline) { qemu_fdt_setprop_string(mc->fdt, "/chosen", "bootargs", cmdline); } }