From patchwork Wed Dec 21 18:22:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 13079068 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 3BE87C4332F for ; Wed, 21 Dec 2022 18:25:43 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p83km-0008JJ-Es; Wed, 21 Dec 2022 13:23:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p83kl-0008Ig-0v for qemu-devel@nongnu.org; Wed, 21 Dec 2022 13:23:43 -0500 Received: from mail-oa1-x2f.google.com ([2001:4860:4864:20::2f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p83kj-0007p6-Ay for qemu-devel@nongnu.org; Wed, 21 Dec 2022 13:23:42 -0500 Received: by mail-oa1-x2f.google.com with SMTP id 586e51a60fabf-14455716674so20126416fac.7 for ; Wed, 21 Dec 2022 10:23:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=R5/g+vsti7lSiZsONctWIYs7IL7csCnpYe9T5na6ABg=; b=pDWPuhUOwiwYEEKPle1SfOnDyv2BbQJXP+mg5kZe9uQwgzr2m/bXb1HzDqIpw1Vhq4 v0bq/DgVmDk6taXFBm2TiSk+CblReg9p6YSyeeTF4tJV+FAGnMFYiLFFgl9vSrLiKaqg 7TaS8+m+wJpONK3GFnjruvSXJ0QHxA1lssd4Mu3DwYVJ6CdyEjLaQZ2IIu7NjgGTjYJW UUG6CsevUlM1XuNNj+G7o2q8cSkrnL2L9TmyfHXHG7iOE/KqtFpNYyeaMgQ7D2pw3tvq b0FWY59uZaRhBJxHTlcZkrDJ7pgwwNkC6bjHLZAXfO/wUB5XhbPxo2ka3g3LAJPvnyFr JK8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=R5/g+vsti7lSiZsONctWIYs7IL7csCnpYe9T5na6ABg=; b=xBJ1wKfOgx6KGMUyQ84ZgN2+F8/wjNzwIDBXqaDHxOiXDmoDzxjyn4E3WLqEOW+2l8 +uZw8U5eQ8FKrZp83ROds/z8CeWtRANywQcBFXiqYEpL6hXzqcYaDxvok4fCmyW/H70A cULjfkgs4aep9iZlx51E1PI3GBdCfdyjbxYP5gF4cygadUgQt1drsxa3p/xTK8qYhSZE cIuJDODxzC2LE/+ozhhm8rzclKUEEoxBWAsH49Mfk0wI77m13V2Rmja1MQz7BF6cTxYO dOPQrGyD8+oUkmVcePbt8tAr0S8dm9Pz7sWzrlqi6TnL8PpqZc9Ei4MkAK3vdP8sj5if X2Jg== X-Gm-Message-State: AFqh2kqZzIRYi4g5RPikupA2H4TyOsPhjOWy4WiJH8FM+Usks+K8Zf7g bIcrgOspc7+6wyNNi6pTC5Bsmh1CQVxpXHvO X-Google-Smtp-Source: AMrXdXsiTRF39pcr4kud/TzJUwgxBq6nvrr7YvTjseSCSuX1Y8rSW8RD38OkZBjMSMTJ0eJqxsnNdQ== X-Received: by 2002:a05:6871:8a6:b0:144:863a:8039 with SMTP id r38-20020a05687108a600b00144863a8039mr1582023oaq.21.1671647020396; Wed, 21 Dec 2022 10:23:40 -0800 (PST) Received: from fedora.. (201-43-103-101.dsl.telesp.net.br. [201.43.103.101]) by smtp.gmail.com with ESMTPSA id w8-20020a056871060800b0014c8685f229sm514577oan.10.2022.12.21.10.23.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Dec 2022 10:23:40 -0800 (PST) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, Daniel Henrique Barboza , Bin Meng , Palmer Dabbelt Subject: [PATCH 11/15] hw/riscv/boot.c: consolidate all kernel init in riscv_load_kernel() Date: Wed, 21 Dec 2022 15:22:56 -0300 Message-Id: <20221221182300.307900-12-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221221182300.307900-1-dbarboza@ventanamicro.com> References: <20221221182300.307900-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2001:4860:4864:20::2f; envelope-from=dbarboza@ventanamicro.com; helo=mail-oa1-x2f.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The microchip_icicle_kit, sifive_u, spike and virt boards are now doing the same steps when '-kernel' is used: - execute load_kernel() - load init_rd() - write kernel_cmdline Let's fold everything inside riscv_load_kernel() to avoid code repetition. Every other board that uses riscv_load_kernel() will have this same behavior, including boards that doesn't have a valid FDT, so we need to take care to not do FDT operations without checking it first. Cc: Palmer Dabbelt Signed-off-by: Daniel Henrique Barboza Reviewed-by: Bin Meng --- hw/riscv/boot.c | 21 ++++++++++++++++++--- hw/riscv/microchip_pfsoc.c | 9 --------- hw/riscv/sifive_u.c | 9 --------- hw/riscv/spike.c | 9 --------- hw/riscv/virt.c | 9 --------- 5 files changed, 18 insertions(+), 39 deletions(-) diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c index c79a08e6fe..afe5bae03d 100644 --- a/hw/riscv/boot.c +++ b/hw/riscv/boot.c @@ -166,6 +166,7 @@ target_ulong riscv_load_kernel(MachineState *machine, { const char *kernel_filename = machine->kernel_filename; uint64_t kernel_load_base, kernel_entry; + void *fdt = machine->fdt; /* * NB: Use low address not ELF entry point to ensure that the fw_dynamic @@ -177,21 +178,35 @@ target_ulong riscv_load_kernel(MachineState *machine, if (load_elf_ram_sym(kernel_filename, NULL, NULL, NULL, NULL, &kernel_load_base, NULL, NULL, 0, EM_RISCV, 1, 0, NULL, true, sym_cb) > 0) { - return kernel_load_base; + kernel_entry = kernel_load_base; + goto out; } if (load_uimage_as(kernel_filename, &kernel_entry, NULL, NULL, NULL, NULL, NULL) > 0) { - return kernel_entry; + goto out; } if (load_image_targphys_as(kernel_filename, kernel_start_addr, current_machine->ram_size, NULL) > 0) { - return kernel_start_addr; + kernel_entry = kernel_start_addr; + goto out; } error_report("could not load kernel '%s'", kernel_filename); exit(1); + +out: + if (machine->initrd_filename) { + riscv_load_initrd(machine, kernel_entry); + } + + if (fdt && machine->kernel_cmdline && *machine->kernel_cmdline) { + qemu_fdt_setprop_string(fdt, "/chosen", "bootargs", + machine->kernel_cmdline); + } + + return kernel_entry; } void riscv_load_initrd(MachineState *machine, uint64_t kernel_entry) diff --git a/hw/riscv/microchip_pfsoc.c b/hw/riscv/microchip_pfsoc.c index 82ae5e7023..57fd6739a5 100644 --- a/hw/riscv/microchip_pfsoc.c +++ b/hw/riscv/microchip_pfsoc.c @@ -631,15 +631,6 @@ static void microchip_icicle_kit_machine_init(MachineState *machine) kernel_entry = riscv_load_kernel(machine, kernel_start_addr, NULL); - if (machine->initrd_filename) { - riscv_load_initrd(machine, kernel_entry); - } - - if (machine->kernel_cmdline && *machine->kernel_cmdline) { - qemu_fdt_setprop_string(machine->fdt, "/chosen", - "bootargs", machine->kernel_cmdline); - } - /* Compute the fdt load address in dram */ fdt_load_addr = riscv_load_fdt(memmap[MICROCHIP_PFSOC_DRAM_LO].base, machine->ram_size, machine->fdt); diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c index bac394c959..0c9bf7fe6a 100644 --- a/hw/riscv/sifive_u.c +++ b/hw/riscv/sifive_u.c @@ -599,15 +599,6 @@ static void sifive_u_machine_init(MachineState *machine) firmware_end_addr); kernel_entry = riscv_load_kernel(machine, kernel_start_addr, NULL); - - if (machine->initrd_filename) { - riscv_load_initrd(machine, kernel_entry); - } - - if (machine->kernel_cmdline && *machine->kernel_cmdline) { - qemu_fdt_setprop_string(machine->fdt, "/chosen", "bootargs", - machine->kernel_cmdline); - } } else { /* * If dynamic firmware is used, it doesn't know where is the next mode diff --git a/hw/riscv/spike.c b/hw/riscv/spike.c index c9c69f92fc..2b9af5689e 100644 --- a/hw/riscv/spike.c +++ b/hw/riscv/spike.c @@ -274,15 +274,6 @@ static void spike_board_init(MachineState *machine) kernel_entry = riscv_load_kernel(machine, kernel_start_addr, htif_symbol_callback); - - if (machine->initrd_filename) { - riscv_load_initrd(machine, kernel_entry); - } - - if (machine->kernel_cmdline && *machine->kernel_cmdline) { - qemu_fdt_setprop_string(machine->fdt, "/chosen", "bootargs", - machine->kernel_cmdline); - } } else { /* * If dynamic firmware is used, it doesn't know where is the next mode diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index c8e35f861e..11c903a212 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -1282,15 +1282,6 @@ static void virt_machine_done(Notifier *notifier, void *data) firmware_end_addr); kernel_entry = riscv_load_kernel(machine, kernel_start_addr, NULL); - - if (machine->initrd_filename) { - riscv_load_initrd(machine, kernel_entry); - } - - if (machine->kernel_cmdline && *machine->kernel_cmdline) { - qemu_fdt_setprop_string(machine->fdt, "/chosen", "bootargs", - machine->kernel_cmdline); - } } else { /* * If dynamic firmware is used, it doesn't know where is the next mode