From nobody Sat May 11 21:54:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1664875584486370.19533250116467; Tue, 4 Oct 2022 02:26:24 -0700 (PDT) Received: from localhost ([::1]:34264 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ofeBz-0006Zk-Gu for importer@patchew.org; Tue, 04 Oct 2022 05:26:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33644) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofe9n-00042Z-D6 for qemu-devel@nongnu.org; Tue, 04 Oct 2022 05:24:08 -0400 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]:35823) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ofe9k-0004MV-NT for qemu-devel@nongnu.org; Tue, 04 Oct 2022 05:24:07 -0400 Received: by mail-pf1-x42a.google.com with SMTP id i6so12675375pfb.2 for ; Tue, 04 Oct 2022 02:24:04 -0700 (PDT) Received: from localhost.localdomain ([49.206.9.142]) by smtp.gmail.com with ESMTPSA id s2-20020a17090b070200b001fba4716f11sm2934551pjz.22.2022.10.04.02.23.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 02:24:03 -0700 (PDT) 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; bh=tn1Lf1hywhKaXdBFMhzTN4ztaESwvV9b7qo9S+GKeVI=; b=S+xs67k6jFbRaa4GCYofhhRbpijcXN7bNuhlsxghdXsoMxuxtO2MB1p4/1XVzvgk3w dT3b5GDwW9ecyH6Ulhgjn+0orRCQ+ArDq6lKxX3KKAFiDEFuuj7Jduh3FUkSxgN/I3/U ccTwwytLvYx2rF8Kec6P5HqJoxdhW7cz05qLvSTn3zj6FDfo81jhyYK87gjpGvCV9DFK CnDaI3sTgxgmA5hAL+sE+RnXngMEeJLxnw0MHZJ3M3BZ7QmKt125s7sUMUyrUc49WH5y P2xuo6he99oI0jsuoEl5Y4i/Ue+z7DDbh27Dh7y8hyvGEbtmASIRK22UsHuLo2HQlmvg Z/bQ== 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; bh=tn1Lf1hywhKaXdBFMhzTN4ztaESwvV9b7qo9S+GKeVI=; b=6PQvJ5q1AAiUeetPbiqvKynIPSzFy89q3bF1c8LdLPkdgrHGDbDl+KVMlWq7PG8ezd Y7uB8gN8asQeONV/NKuBHfZZRYXZfZSHkFeeaXlwlzkDamR90A7nPKsUDFI0ao4Ip1os T6Jjp9UFQa2li+0Etq9UJ9FLP8Ld2xRWpM4ahBOdfFQF32b1qm6lZHsJ6D9UYHNqkmsw +8goyyTeJNT5OO2cGbc/ZNrUvbL9Mv53q8lsV91RCUsVlA5zt0K5hJLYW3OU1pO8V+Te eO3TPxkKESjoq3kqN0kfijCKUybv8VQNWK9Drt9QXl/kogkkFuQt+TUn48qaKW6U9nZV 8Dlg== X-Gm-Message-State: ACrzQf0NXM7NxIxSEBEqPOFdOLW9yeftCLiWcANIVKoxuiST1LvIYSkA B2F12VM+95K3ESzFdwmum6K5qA== X-Google-Smtp-Source: AMsMyM4+2q6g1WFEQPtLy61G62k0nSs3NDXTaHKleOujmf7w5UQ83VmwYdnt1A2w+d8tGixs5VAGSQ== X-Received: by 2002:a05:6a00:1989:b0:546:410f:bdd2 with SMTP id d9-20020a056a00198900b00546410fbdd2mr26628601pfl.83.1664875443484; Tue, 04 Oct 2022 02:24:03 -0700 (PDT) From: Sunil V L To: Peter Maydell , Xiaojuan Yang , Song Gao , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann , Palmer Dabbelt , Alistair Francis , Bin Meng Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, qemu-riscv@nongnu.org, Sunil V L , Andrew Jones Subject: [PATCH V5 1/3] hw/arm, loongarch: Move load_image_to_fw_cfg() to common location Date: Tue, 4 Oct 2022 14:53:49 +0530 Message-Id: <20221004092351.18209-2-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221004092351.18209-1-sunilvl@ventanamicro.com> References: <20221004092351.18209-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::42a; envelope-from=sunilvl@ventanamicro.com; helo=mail-pf1-x42a.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=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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1664875585405100003 Content-Type: text/plain; charset="utf-8" load_image_to_fw_cfg() is duplicated by both arm and loongarch. The same function will be required by riscv too. So, it's time to refactor and move this function to a common path. Signed-off-by: Sunil V L Reviewed-by: Andrew Jones Reviewed-by: Alistair Francis Reviewed-by: Song Gao --- hw/arm/boot.c | 49 --------------------------------------- hw/loongarch/virt.c | 33 -------------------------- hw/nvram/fw_cfg.c | 32 +++++++++++++++++++++++++ include/hw/nvram/fw_cfg.h | 21 +++++++++++++++++ 4 files changed, 53 insertions(+), 82 deletions(-) diff --git a/hw/arm/boot.c b/hw/arm/boot.c index ada2717f76..704f368d9c 100644 --- a/hw/arm/boot.c +++ b/hw/arm/boot.c @@ -818,55 +818,6 @@ static void do_cpu_reset(void *opaque) } } =20 -/** - * load_image_to_fw_cfg() - Load an image file into an fw_cfg entry identi= fied - * by key. - * @fw_cfg: The firmware config instance to store the data in. - * @size_key: The firmware config key to store the size of the loaded - * data under, with fw_cfg_add_i32(). - * @data_key: The firmware config key to store the loaded data under, - * with fw_cfg_add_bytes(). - * @image_name: The name of the image file to load. If it is NULL, the - * function returns without doing anything. - * @try_decompress: Whether the image should be decompressed (gunzipped) b= efore - * adding it to fw_cfg. If decompression fails, the image= is - * loaded as-is. - * - * In case of failure, the function prints an error message to stderr and = the - * process exits with status 1. - */ -static void load_image_to_fw_cfg(FWCfgState *fw_cfg, uint16_t size_key, - uint16_t data_key, const char *image_name, - bool try_decompress) -{ - size_t size =3D -1; - uint8_t *data; - - if (image_name =3D=3D NULL) { - return; - } - - if (try_decompress) { - size =3D load_image_gzipped_buffer(image_name, - LOAD_IMAGE_MAX_GUNZIP_BYTES, &dat= a); - } - - if (size =3D=3D (size_t)-1) { - gchar *contents; - gsize length; - - if (!g_file_get_contents(image_name, &contents, &length, NULL)) { - error_report("failed to load \"%s\"", image_name); - exit(1); - } - size =3D length; - data =3D (uint8_t *)contents; - } - - fw_cfg_add_i32(fw_cfg, size_key, size); - fw_cfg_add_bytes(fw_cfg, data_key, data, size); -} - static int do_arm_linux_init(Object *obj, void *opaque) { if (object_dynamic_cast(obj, TYPE_ARM_LINUX_BOOT_IF)) { diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c index 29df99727d..4b595a9ea4 100644 --- a/hw/loongarch/virt.c +++ b/hw/loongarch/virt.c @@ -598,39 +598,6 @@ static void reset_load_elf(void *opaque) } } =20 -/* Load an image file into an fw_cfg entry identified by key. */ -static void load_image_to_fw_cfg(FWCfgState *fw_cfg, uint16_t size_key, - uint16_t data_key, const char *image_name, - bool try_decompress) -{ - size_t size =3D -1; - uint8_t *data; - - if (image_name =3D=3D NULL) { - return; - } - - if (try_decompress) { - size =3D load_image_gzipped_buffer(image_name, - LOAD_IMAGE_MAX_GUNZIP_BYTES, &dat= a); - } - - if (size =3D=3D (size_t)-1) { - gchar *contents; - gsize length; - - if (!g_file_get_contents(image_name, &contents, &length, NULL)) { - error_report("failed to load \"%s\"", image_name); - exit(1); - } - size =3D length; - data =3D (uint8_t *)contents; - } - - fw_cfg_add_i32(fw_cfg, size_key, size); - fw_cfg_add_bytes(fw_cfg, data_key, data, size); -} - static void fw_cfg_add_kernel_info(FWCfgState *fw_cfg) { /* diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c index d605f3f45a..371a45dfe2 100644 --- a/hw/nvram/fw_cfg.c +++ b/hw/nvram/fw_cfg.c @@ -41,6 +41,7 @@ #include "qapi/error.h" #include "hw/acpi/aml-build.h" #include "hw/pci/pci_bus.h" +#include "hw/loader.h" =20 #define FW_CFG_FILE_SLOTS_DFLT 0x20 =20 @@ -1221,6 +1222,37 @@ FWCfgState *fw_cfg_find(void) return FW_CFG(object_resolve_path_type("", TYPE_FW_CFG, NULL)); } =20 +void load_image_to_fw_cfg(FWCfgState *fw_cfg, uint16_t size_key, + uint16_t data_key, const char *image_name, + bool try_decompress) +{ + size_t size =3D -1; + uint8_t *data; + + if (image_name =3D=3D NULL) { + return; + } + + if (try_decompress) { + size =3D load_image_gzipped_buffer(image_name, + LOAD_IMAGE_MAX_GUNZIP_BYTES, &dat= a); + } + + if (size =3D=3D (size_t)-1) { + gchar *contents; + gsize length; + + if (!g_file_get_contents(image_name, &contents, &length, NULL)) { + error_report("failed to load \"%s\"", image_name); + exit(1); + } + size =3D length; + data =3D (uint8_t *)contents; + } + + fw_cfg_add_i32(fw_cfg, size_key, size); + fw_cfg_add_bytes(fw_cfg, data_key, data, size); +} =20 static void fw_cfg_class_init(ObjectClass *klass, void *data) { diff --git a/include/hw/nvram/fw_cfg.h b/include/hw/nvram/fw_cfg.h index 0e7a8bc7af..c1f81a5f13 100644 --- a/include/hw/nvram/fw_cfg.h +++ b/include/hw/nvram/fw_cfg.h @@ -342,4 +342,25 @@ bool fw_cfg_dma_enabled(void *opaque); */ const char *fw_cfg_arch_key_name(uint16_t key); =20 +/** + * load_image_to_fw_cfg() - Load an image file into an fw_cfg entry identi= fied + * by key. + * @fw_cfg: The firmware config instance to store the data in. + * @size_key: The firmware config key to store the size of the loaded + * data under, with fw_cfg_add_i32(). + * @data_key: The firmware config key to store the loaded data under, + * with fw_cfg_add_bytes(). + * @image_name: The name of the image file to load. If it is NULL, the + * function returns without doing anything. + * @try_decompress: Whether the image should be decompressed (gunzipped) b= efore + * adding it to fw_cfg. If decompression fails, the image= is + * loaded as-is. + * + * In case of failure, the function prints an error message to stderr and = the + * process exits with status 1. + */ +void load_image_to_fw_cfg(FWCfgState *fw_cfg, uint16_t size_key, + uint16_t data_key, const char *image_name, + bool try_decompress); + #endif --=20 2.25.1 From nobody Sat May 11 21:54:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1664875830; cv=none; d=zohomail.com; s=zohoarc; b=URUkLtw8UztdoO7Q2pZ6FoOwh8c88pqJIO6eShFH0XzCwpCRtsGFYpv6Hs8usGypABEq4Hmbe+zyZBnDWOuR4uzbou2/jmlpKZcFMoQJg+SsK4sc1A0jCYDvrgYP7clj1LC4yxmXZuLCuyI3wYaqznxPNXLOx9NfAovZcL6rYWo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664875830; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/wY4wB/ohQK/ixOh+AwUZx64z8H5nK1+i4RzAT+ks7s=; b=fbfxhDyBw7aX8i01c1F0zpeOBznEZfkWZjrbptJ3zKSB73pLERwuSicHta7CzMiBt0y2fp66hObDCSdWyCp26vVaVAGMkWzpb79lAmCCdrOeYgZUbMk6nejomSyK65PHXtVhr1hO5Z7FR7qQs9CwtxOyPPhUZEiSCeCetHWFkfs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1664875830187779.2153680659962; Tue, 4 Oct 2022 02:30:30 -0700 (PDT) Received: from localhost ([::1]:35718 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ofeFw-0002yL-T8 for importer@patchew.org; Tue, 04 Oct 2022 05:30:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33654) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofe9r-00049X-M4 for qemu-devel@nongnu.org; Tue, 04 Oct 2022 05:24:11 -0400 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]:36601) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ofe9o-0004NU-Nh for qemu-devel@nongnu.org; Tue, 04 Oct 2022 05:24:11 -0400 Received: by mail-pg1-x530.google.com with SMTP id s206so12237439pgs.3 for ; Tue, 04 Oct 2022 02:24:08 -0700 (PDT) Received: from localhost.localdomain ([49.206.9.142]) by smtp.gmail.com with ESMTPSA id s2-20020a17090b070200b001fba4716f11sm2934551pjz.22.2022.10.04.02.24.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 02:24:07 -0700 (PDT) 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; bh=/wY4wB/ohQK/ixOh+AwUZx64z8H5nK1+i4RzAT+ks7s=; b=lCu02r5wosrs0/79F2h83fxLHGEQkzxp2gC513SNhno/2VuUq7tfsWFJoyEfeZO3m+ V2UKS8EsZCiIVNkV2syXpVnSfC3x0EAqJMlQ4G4uNhzZm62DoEQCW6H4+EDMQCTRPdbk VOfXtGzwngciR3sacGLMnkxZWemHl4ZIzttsQinoHoOm/cfGGyWD/1TfuaQy1mLlIqVw sURdFF2/e4vOa1g60KnM71zcNfu8g2KgMXI74bQUbp0X3V69D5OtXO8gBn5lyrrZLEL9 93T6/MYMn7E8dH8uO85J2ddiA/r2y2QtLKk9DIkjiXjsqrzd/ac96Qf3QuybRUzqqjjs oc0w== 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; bh=/wY4wB/ohQK/ixOh+AwUZx64z8H5nK1+i4RzAT+ks7s=; b=4yImRW94qD8pStGJ0Xsif1dhA4epH7bAEQmtqAo+ZRni5VltVHnnUEoUS6QNB2sp/2 EHV43Lkq/GIntXWIoS3nVUkRp3dmIDuCS2bgouik14fdt84AgKhy/Lk5trS53urpRMU4 LJaaPr/DbTglYTyjbm8Cd+TierYfnzBwm0U1nV2MThVdFhJSgxw1EXC6ZSy/kYwebS0c ldlShJOIWYq+e8jqryzuDH+9ayRnTk7DaW6ZrvwZHoFK0rd812T36WWNqWHSo5TZdbe8 RgwHeN08CCNh4kOIlvl9qm2+pPG5FG9PRV1ltkiPxXuS3Y/oyFhDh9xY8SIWQRn2uLQp f35Q== X-Gm-Message-State: ACrzQf31xebe9lTQjN3rSzWeA5SPl2N2nrvPvFUpy+R1vEtJWI/cg6lp GdrvpMg3LsAzScKN0px4rmSc/w== X-Google-Smtp-Source: AMsMyM75m/bJQI3JBriOhEmYCx4AEwO6hYD6He+dp0DVmyen50p4S6+u3n05+tft0VVkoVRVRdTn5Q== X-Received: by 2002:a63:6909:0:b0:41c:9f4f:a63c with SMTP id e9-20020a636909000000b0041c9f4fa63cmr23234360pgc.76.1664875447384; Tue, 04 Oct 2022 02:24:07 -0700 (PDT) From: Sunil V L To: Peter Maydell , Xiaojuan Yang , Song Gao , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann , Palmer Dabbelt , Alistair Francis , Bin Meng Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, qemu-riscv@nongnu.org, Sunil V L , Andrew Jones Subject: [PATCH V5 2/3] hw/riscv: virt: Move create_fw_cfg() prior to loading kernel Date: Tue, 4 Oct 2022 14:53:50 +0530 Message-Id: <20221004092351.18209-3-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221004092351.18209-1-sunilvl@ventanamicro.com> References: <20221004092351.18209-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::530; envelope-from=sunilvl@ventanamicro.com; helo=mail-pg1-x530.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=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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1664875830885100001 Content-Type: text/plain; charset="utf-8" To enable both -kernel and -pflash options, the fw_cfg needs to be created prior to loading the kernel. Signed-off-by: Sunil V L Reviewed-by: Andrew Jones Reviewed-by: Alistair Francis --- hw/riscv/virt.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index befa9d2c26..de2efccebf 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -1267,6 +1267,13 @@ static void virt_machine_done(Notifier *notifier, vo= id *data) RISCV64_BIOS_BIN, start_addr, NULL); } =20 + /* + * Init fw_cfg. Must be done before riscv_load_fdt, otherwise the dev= ice + * tree cannot be altered and we get FDT_ERR_NOSPACE. + */ + s->fw_cfg =3D create_fw_cfg(machine); + rom_set_fw(s->fw_cfg); + if (machine->kernel_filename) { kernel_start_addr =3D riscv_calc_kernel_start_addr(&s->soc[0], firmware_end_addr= ); @@ -1300,13 +1307,6 @@ static void virt_machine_done(Notifier *notifier, vo= id *data) start_addr =3D virt_memmap[VIRT_FLASH].base; } =20 - /* - * Init fw_cfg. Must be done before riscv_load_fdt, otherwise the dev= ice - * tree cannot be altered and we get FDT_ERR_NOSPACE. - */ - s->fw_cfg =3D create_fw_cfg(machine); - rom_set_fw(s->fw_cfg); - /* Compute the fdt load address in dram */ fdt_load_addr =3D riscv_load_fdt(memmap[VIRT_DRAM].base, machine->ram_size, machine->fdt); --=20 2.25.1 From nobody Sat May 11 21:54:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1664875911; cv=none; d=zohomail.com; s=zohoarc; b=Us1ttnpOlBmzZqFe/44Dag2d5iUz209hd5ee0XBxZT0pR4wauzSmuafM2Ymygxu9iza9ywt/e5WH7lhhMhXUaUE6A4SKl5ItOHuWwzkOzBtI7IAY3JXwqkjiETJozh84n3WLgUCHudpZIcvehZNgNkxw9/67tPLv+Boig0jrAzg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664875911; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=FRti7/w2G6ja63I+XSRHDfjXoUV0Jx/llmf+dyAA6jk=; b=j4R33xaL30vxUUGq2hdl3xtlB16Eu9NI1vGlAxJJX+kmahDhjgw87IkFwOsNSslhyoySqsQVGsmQjnVFOawCY7t38rV4rqAT9QIDOSb0NfyVtLLPEb1UtTWrgAwX1AVuz4CdPKb1jmqnv3qP+eHf5RQBETG22cAx6HZJLDucJ7I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1664875911902906.0415425119788; Tue, 4 Oct 2022 02:31:51 -0700 (PDT) Received: from localhost ([::1]:36960 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ofeHG-000413-PK for importer@patchew.org; Tue, 04 Oct 2022 05:31:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44316) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofe9y-0004MP-99 for qemu-devel@nongnu.org; Tue, 04 Oct 2022 05:24:18 -0400 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]:43764) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ofe9u-0004OJ-7i for qemu-devel@nongnu.org; Tue, 04 Oct 2022 05:24:18 -0400 Received: by mail-pf1-x429.google.com with SMTP id 83so5664394pfw.10 for ; Tue, 04 Oct 2022 02:24:12 -0700 (PDT) Received: from localhost.localdomain ([49.206.9.142]) by smtp.gmail.com with ESMTPSA id s2-20020a17090b070200b001fba4716f11sm2934551pjz.22.2022.10.04.02.24.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 02:24:10 -0700 (PDT) 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; bh=FRti7/w2G6ja63I+XSRHDfjXoUV0Jx/llmf+dyAA6jk=; b=NZAdq2nAZyjbpb0QfySd4nxQIUESqNUZO210AHcGBebFqHOR70LOGqQ8uUhEo+KCNr Ws1Ckcx7yKtuY0IrVMFdHte9ZzXbg/0jq/Len2xn43wUjtLPDgpcLWHVq1a0CuivXrTW En3xv9ObTO6zMN4+5dEjajdTAIsMRS0HI1MeDl2qxxdxbkhBsQi2m5+8Llz+Rf1vWzFh Bvj4J7jQepgX9F0mEFAoU2ia5DiWvOspSe6yj6ZLsJEiDsTZwbl5QV1gGnMSr0j9br25 EsVXxZLdMFE71jgpKtnmk6cQ0q8pd25hKXFv2DHb0XsAMjLKd2AzRzX7+mvppPvJwRA/ BwQA== 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; bh=FRti7/w2G6ja63I+XSRHDfjXoUV0Jx/llmf+dyAA6jk=; b=IMq7xk29Wul0T7+Yqx3N1EDeAJDgaDjrk3eF39yMOHg6SSDqTJukyBCDRnDT8X6ZaU 5tsV8ECIYMgVp3XyR+vMNe0PxgwAlgl/lYyYygV4pV4qXoV31u/plJLDjVlaK4vD6nLG v3cbehYVAN4bn1MTgfHleXXGLqBgJCbfC2gyr8e95CakRvmCfSenO5lS6kyFpDnX5rEF w16cycs68Xsk9I52kCYxvpk1YsHs+TGqqUZC5mjIgrByEP0tfKyqBzJebF9h0+wcXs08 +AcR7fBzLcR4uEO8SHYqG6kxiWk/z9aoG4uU4yLDlDH32qwWAqtK90rYPpc9qy+F1yBU W/yA== X-Gm-Message-State: ACrzQf2881iHQiTpgaulypDdV+uGh+a6W9MU615FoHokYyab0z30Z0iZ qsr/mHi92DX51crmkOu7rg0CWw== X-Google-Smtp-Source: AMsMyM4GAqtI6IyvZ1oD7bbMe2mZIMA/R8pej/pjcL8bk9N0+hLOaDgelxzqE11dfJP1/ZSQFiOxUQ== X-Received: by 2002:a63:1317:0:b0:42a:e7a5:ef5a with SMTP id i23-20020a631317000000b0042ae7a5ef5amr22876898pgl.392.1664875451273; Tue, 04 Oct 2022 02:24:11 -0700 (PDT) From: Sunil V L To: Peter Maydell , Xiaojuan Yang , Song Gao , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann , Palmer Dabbelt , Alistair Francis , Bin Meng Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, qemu-riscv@nongnu.org, Sunil V L , Andrew Jones Subject: [PATCH V5 3/3] hw/riscv: virt: Enable booting S-mode firmware from pflash Date: Tue, 4 Oct 2022 14:53:51 +0530 Message-Id: <20221004092351.18209-4-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221004092351.18209-1-sunilvl@ventanamicro.com> References: <20221004092351.18209-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::429; envelope-from=sunilvl@ventanamicro.com; helo=mail-pf1-x429.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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1664875912618100001 Content-Type: text/plain; charset="utf-8" To boot S-mode firmware payload like EDK2 from persistent flash storage, qemu needs to pass the flash address as the next_addr in fw_dynamic_info to the opensbi. When both -kernel and -pflash options are provided in command line, the kernel (and initrd if -initrd) will be copied to fw_cfg table. The S-mode FW will load the kernel/initrd from fw_cfg table. If only pflash is given but not -kernel, then it is the job of of the S-mode firmware to locate and load the kernel. In either case, update the kernel_entry with the flash address so that the opensbi can jump to the entry point of the S-mode firmware. Signed-off-by: Sunil V L Reviewed-by: Andrew Jones Reviewed-by: Alistair Francis --- hw/riscv/boot.c | 29 +++++++++++++++++++++++++++++ hw/riscv/virt.c | 18 +++++++++++++++++- include/hw/riscv/boot.h | 1 + 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c index 1ae7596873..fa8ad27da2 100644 --- a/hw/riscv/boot.c +++ b/hw/riscv/boot.c @@ -338,3 +338,32 @@ void riscv_setup_direct_kernel(hwaddr kernel_addr, hwa= ddr fdt_addr) riscv_cpu->env.fdt_addr =3D fdt_addr; } } + +void riscv_setup_firmware_boot(MachineState *machine) +{ + if (machine->kernel_filename) { + FWCfgState *fw_cfg; + fw_cfg =3D fw_cfg_find(); + + assert(fw_cfg); + /* + * Expose the kernel, the command line, and the initrd in fw_cfg. + * We don't process them here at all, it's all left to the + * firmware. + */ + load_image_to_fw_cfg(fw_cfg, + FW_CFG_KERNEL_SIZE, FW_CFG_KERNEL_DATA, + machine->kernel_filename, + true); + load_image_to_fw_cfg(fw_cfg, + FW_CFG_INITRD_SIZE, FW_CFG_INITRD_DATA, + machine->initrd_filename, false); + + if (machine->kernel_cmdline) { + fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, + strlen(machine->kernel_cmdline) + 1); + fw_cfg_add_string(fw_cfg, FW_CFG_CMDLINE_DATA, + machine->kernel_cmdline); + } + } +} diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index de2efccebf..a5bc7353b4 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -1274,7 +1274,23 @@ static void virt_machine_done(Notifier *notifier, vo= id *data) s->fw_cfg =3D create_fw_cfg(machine); rom_set_fw(s->fw_cfg); =20 - if (machine->kernel_filename) { + if (drive_get(IF_PFLASH, 0, 1)) { + /* + * S-mode FW like EDK2 will be kept in second plash (unit 1). + * When both kernel, initrd and pflash options are provided in the + * command line, the kernel and initrd will be copied to the fw_cfg + * table and opensbi will jump to the flash address which is the + * entry point of S-mode FW. It is the job of the S-mode FW to load + * the kernel and initrd using fw_cfg table. + * + * If only pflash is given but not -kernel, then it is the job of + * of the S-mode firmware to locate and load the kernel. + * In either case, the next_addr for opensbi will be the flash add= ress. + */ + riscv_setup_firmware_boot(machine); + kernel_entry =3D virt_memmap[VIRT_FLASH].base + + virt_memmap[VIRT_FLASH].size / 2; + } else if (machine->kernel_filename) { kernel_start_addr =3D riscv_calc_kernel_start_addr(&s->soc[0], firmware_end_addr= ); =20 diff --git a/include/hw/riscv/boot.h b/include/hw/riscv/boot.h index a36f7618f5..93e5f8760d 100644 --- a/include/hw/riscv/boot.h +++ b/include/hw/riscv/boot.h @@ -57,5 +57,6 @@ void riscv_rom_copy_firmware_info(MachineState *machine, = hwaddr rom_base, uint32_t reset_vec_size, uint64_t kernel_entry); void riscv_setup_direct_kernel(hwaddr kernel_addr, hwaddr fdt_addr); +void riscv_setup_firmware_boot(MachineState *machine); =20 #endif /* RISCV_BOOT_H */ --=20 2.25.1