From nobody Tue May 21 05:58:23 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 1662438476695185.67809471171006; Mon, 5 Sep 2022 21:27:56 -0700 (PDT) Received: from localhost ([::1]:42874 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oVQBn-0001e1-AP for importer@patchew.org; Tue, 06 Sep 2022 00:27:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47550) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVQ95-0007Pw-4m for qemu-devel@nongnu.org; Tue, 06 Sep 2022 00:25:07 -0400 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]:47043) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oVQ92-00072A-Om for qemu-devel@nongnu.org; Tue, 06 Sep 2022 00:25:06 -0400 Received: by mail-pj1-x1030.google.com with SMTP id o15-20020a17090a3d4f00b002004ed4d77eso4704029pjf.5 for ; Mon, 05 Sep 2022 21:25:04 -0700 (PDT) Received: from localhost.localdomain ([49.206.11.92]) by smtp.gmail.com with ESMTPSA id g10-20020aa796aa000000b00537f029c94bsm8724967pfk.183.2022.09.05.21.24.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 21:25: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=ZBm3nLoiUBu04kY2LVi2GbBxIBiGqU5xHs6XU99y0Yo=; b=JNktW2HrQrw0Dani8CY4KJ/fzN+hIqaH5I783ieB3f03BqUMk9bi4KeSoyjUkCCrjx WK+0R6S3MyksTPQE0w1fkkRtPWqMvUH7bnr97b9gnuuEJ0gaN970aZCdCx9rsTJZH0Z/ 7okcXG/ixW9nvp5YpyCKB1XnMzPMCQYEZ5RAnOxbzeskkbZtdC5Pj2Wf0p/DqXoGD1E7 zBE/wT++WZzFCpiLQBOwqJEDW7M4IKVAkx2CHLIlL96xRCCOnCstH1u3tYImX4nZcXcA bNqPsWqYp7RtqyUx5EkMnkudqJE12v0wyy+FHe0XlNdgHiSLqz3FawlgRquySFzBLoPN Rx4A== 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=ZBm3nLoiUBu04kY2LVi2GbBxIBiGqU5xHs6XU99y0Yo=; b=i7+mTKwTRD/Ee3DfKsveKl0YkKr13rAl9hiphsx81bCwxAfMjoa45/AiUFZVOW5qEI l7tiAlhqxzFYuvS9xfXMVHvDs9/LafN1D56gwnh7PP8uLGXhw44hvHCOoHBKQawZXavH khGsyRdSY08fV+VYpdjTFHsHqikXCY9iXJzyGgZpawP/Gh17jQaYS7b5s43ot5/DP3Nl +9c6kV5junGMQVu/mY5R2w4ixKxvl09l9VBVroYcpNQovs1SQ1eMdKpaUxiZPfbGTTTN 2YAvmB+bO4pk2/8tzb0oAKaCYcPGz/7xCvq9fOXbyz9gYvoRPvJrvWQ28R6+9S3lVWJX 1WBQ== X-Gm-Message-State: ACgBeo1zJfZ3QC3nJkhxIUBNq0OR8wdOwpbqgUZEgeGXP956UPvc9s4S HYjKYsM055f1W2mf/ZHiMjUmiA== X-Google-Smtp-Source: AA6agR5GnvyItN9m5fzaptYHyReTwrUqRlVvmltOuaRPR1DXHdKcG7AUnakzTe5Zp3O2OoSksFbjMQ== X-Received: by 2002:a17:902:6b84:b0:172:f7cc:175 with SMTP id p4-20020a1709026b8400b00172f7cc0175mr50864072plk.158.1662438303483; Mon, 05 Sep 2022 21:25:03 -0700 (PDT) From: Sunil V L To: qemu-arm@nongnu.org, qemu-devel@nongnu.org, qemu-riscv@nongnu.org Cc: Peter Maydell , Xiaojuan Yang , Song Gao , Gerd Hoffmann , Palmer Dabbelt , Alistair Francis , Bin Meng , Andrew Jones , Anup Patel , Atish Kumar Patra , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Sunil V L Subject: [PATCH V3 1/3] hw/arm, loongarch: Move load_image_to_fw_cfg() to common location Date: Tue, 6 Sep 2022 09:54:49 +0530 Message-Id: <20220906042451.379611-2-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220906042451.379611-1-sunilvl@ventanamicro.com> References: <20220906042451.379611-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::1030; envelope-from=sunilvl@ventanamicro.com; helo=mail-pj1-x1030.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, 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: , 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: 1662438479362100001 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 --- 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 5cc0b05538..eee2c193c0 100644 --- a/hw/loongarch/virt.c +++ b/hw/loongarch/virt.c @@ -542,39 +542,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 Tue May 21 05:58:23 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=1662438676; cv=none; d=zohomail.com; s=zohoarc; b=RRwXgz6PTP8wMkAtT45B53qI4UxmU9jLaH8UrCEppFRJxcmWrtpqIa+roKuUGeOBASFH3AHUdBe73l0e2js6JwIa+q2WOJeSxAJrwnl/LQrriNhisssrFz/9KJ2s1cDWOvEIEy7rPtxGkQZy9XGN2brRqXyJG4Z2dssqJDMxUqA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662438676; 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=K9wefkWGERlorpQlskTuOFMvFh9QknFkKJmCeKsqGFs=; b=OF1cHdku3jtO3C2vsyah4LvdeHelYr1JBBa2+M/qQCt1sXw/USJbl7HolbV6UAGHr+oCf4SSHuRWXrjhPvoPUYr3LnV4aDF8Fxuf0cRhJ8TXTALjWynYDaR+3JH4zC1XqNbbSucu1tAVchkX6P9B7NODOLqg+PYZv2ocunWpecI= 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 1662438676399591.9062341257473; Mon, 5 Sep 2022 21:31:16 -0700 (PDT) Received: from localhost ([::1]:38122 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oVQF0-0006mq-Fs for importer@patchew.org; Tue, 06 Sep 2022 00:31:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47556) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVQ98-0007UI-Fb for qemu-devel@nongnu.org; Tue, 06 Sep 2022 00:25:10 -0400 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]:36453) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oVQ96-00073Z-RY for qemu-devel@nongnu.org; Tue, 06 Sep 2022 00:25:10 -0400 Received: by mail-pj1-x1035.google.com with SMTP id s14-20020a17090a6e4e00b0020057c70943so4478756pjm.1 for ; Mon, 05 Sep 2022 21:25:08 -0700 (PDT) Received: from localhost.localdomain ([49.206.11.92]) by smtp.gmail.com with ESMTPSA id g10-20020aa796aa000000b00537f029c94bsm8724967pfk.183.2022.09.05.21.25.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 21:25: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=K9wefkWGERlorpQlskTuOFMvFh9QknFkKJmCeKsqGFs=; b=HTLujvj53ViJ3NOAzY9LZKAptUnvqErsi9Tg9fpG/Sf8I7Oe3Paf365q4iZmno2acR xEqG4ba3lI/oneW3OvbTj7EOSpWOgz1iS7T7GGl/wc+cClH6gy4rOVgVVMUhT3Dssrp1 w8XMfCxsDwtDsdHoy5v2qKWn3sbltaSQkJvN8Q/zm0KXBjlckpjGYaNvgxffBwZjHHCD PBEsAXaqJuABCQQGAbGr/f3bFV/0ZdPaJ9iMEf+aSTjm3fsLJcBV/4n6n3QrFZ/2IOdM E7J/CPJaPx6d7LGhmTuPOn3MGw3uhtJ0+MlThgYoMHy3scdhWPsGdITAmFntkg6nl1qN uiRg== 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=K9wefkWGERlorpQlskTuOFMvFh9QknFkKJmCeKsqGFs=; b=IJg+5UyDSg5zcEU6Pd5eJtaNP1/psVSJqYMkw262ye0k1BLskC8ypQoye2lawZtuq9 GU7qw76BTlxntQhNLTbhOJajtjYlzPDHRP/f28/LDMYuVmxICcTMaCjRvHdJ+INaxSIf +xYCqgPPkjlPNKYPmagDU9nZxKPLIsPuV8nxSGqYVjhTEVxN2ysSwJ2cyjgrFldgtr30 OpwgHBke/VPMPbK1NMnK1WBPticabMkSDWpvqNZl/o2uVYi1ygNaXBSP+ZhtYvsktTLx 4EhJW4RHr2f1utafBpRMPS8Hz80k2+rXkQuRLRspYz+n0nkAe3gHWZw6chve0imwV41o SbgQ== X-Gm-Message-State: ACgBeo3HZ1mss6xrjiaGdc5dRxHg/M0nK5MaGdyZwx4DuWSzR1HPZreH 1dPAjZ6H8WLyMj8IwNc8PtVUww== X-Google-Smtp-Source: AA6agR4pIxkoTStNse70DJsozeEqFrbBNNK782iKzYZ06Nma6QVQRFYTWypKBJpS/RQDgoQtBwYKrA== X-Received: by 2002:a17:902:edd5:b0:174:a6e6:51f4 with SMTP id q21-20020a170902edd500b00174a6e651f4mr42534339plk.82.1662438307603; Mon, 05 Sep 2022 21:25:07 -0700 (PDT) From: Sunil V L To: qemu-arm@nongnu.org, qemu-devel@nongnu.org, qemu-riscv@nongnu.org Cc: Peter Maydell , Xiaojuan Yang , Song Gao , Gerd Hoffmann , Palmer Dabbelt , Alistair Francis , Bin Meng , Andrew Jones , Anup Patel , Atish Kumar Patra , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Sunil V L Subject: [PATCH V3 2/3] hw/riscv: virt: Move create_fw_cfg() prior to loading kernel Date: Tue, 6 Sep 2022 09:54:50 +0530 Message-Id: <20220906042451.379611-3-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220906042451.379611-1-sunilvl@ventanamicro.com> References: <20220906042451.379611-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::1035; envelope-from=sunilvl@ventanamicro.com; helo=mail-pj1-x1035.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, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1662438678288100001 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 --- 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 ff8c0df5cd..b6bbf03f61 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -1251,6 +1251,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= ); @@ -1284,13 +1291,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 Tue May 21 05:58:23 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=1662439121; cv=none; d=zohomail.com; s=zohoarc; b=M2TdhQkoL/GlTm4boi5kzQiwmi7VfDDsKeknlG4B01SPf4wxJ5jMz8ZZenA0KE5l91ZqgcdkUUm0T6zd9zAWiVJB+5gen448M2tfiS4/Mrgk+MqdCkQhvO2rfCNAk9JbcswYGRrW39ZgD2kfWbSoWJeTueRYJcLf9MX9kxTOA1s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662439121; 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=/Hfi1dqn7aBKUskyIzQv2SXHLLV50tRsQ66eiL+Qum8=; b=U2XXJTF3TU/PU+63sJdOwi/cM05aUr/EikQS9yR0NMrzC7Vep0TNVUu530PFfTomMzQfmXlTEp1ERe1rADQpV2PcTI6u8RhT9yL6aN8G4vx0a51ag6LOcOJi+KTfCLMLSudCf2Izm9XtQ7S26pvXW7mL6RRE74wBGFkBoNAQj7Y= 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 166243912191329.30242869392282; Mon, 5 Sep 2022 21:38:41 -0700 (PDT) Received: from localhost ([::1]:43132 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oVQMC-0004bz-VZ for importer@patchew.org; Tue, 06 Sep 2022 00:38:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35888) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVQ9Q-0007vb-6o for qemu-devel@nongnu.org; Tue, 06 Sep 2022 00:25:28 -0400 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]:34327) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oVQ9B-00074Y-0K for qemu-devel@nongnu.org; Tue, 06 Sep 2022 00:25:27 -0400 Received: by mail-pl1-x62f.google.com with SMTP id f24so10156535plr.1 for ; Mon, 05 Sep 2022 21:25:12 -0700 (PDT) Received: from localhost.localdomain ([49.206.11.92]) by smtp.gmail.com with ESMTPSA id g10-20020aa796aa000000b00537f029c94bsm8724967pfk.183.2022.09.05.21.25.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 21:25:11 -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=/Hfi1dqn7aBKUskyIzQv2SXHLLV50tRsQ66eiL+Qum8=; b=b8wQs6xbUu2WQuAhtQWF3RfAkahCEeTHL+Yczjj37AFturpo6wUjBUnvmR4yf3dtVN H0VcO4qdmOsKucQGBu4tV8TVW9hFm/KPUGo9EtvAQ67cLvL5vHgtzRi8L1jIyQK9j1YP 9xt7A1n57Kau5TqvLUHzHwdQt48zF81/v3LjLx8gd9aSh94/gdusrd9UpNMNn8t8idl/ VcD5ODsftWagrNT7ILOrA8l0A2wuSNTXbtLe6ZfQf+Tni+VLAmivBPw6VJ/1e9VH2vXT IK4vtm2uXQss5RziPLVuzAN2l1QhQKTSm+PbSbTXPd++6QIZMhjHAiDfPO+8Vxqo+YIk aV3A== 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=/Hfi1dqn7aBKUskyIzQv2SXHLLV50tRsQ66eiL+Qum8=; b=QV1e8ghHpLfyHIz6Oo56dBcsNnlc8lx2maSb9p3+NpK4bxmJJPSgYMrb9wFz02H3Bl dkHabvEhm+kFyhJoN2jKsauTZ5ywYNGhfwjylTkmJyihH1iGewgqdlH3mOO2euxw1skW dP3R9SuubxzlWfLpxyztZIADOoH13PfWXxRV1FSM1+inTCiw95mbDss+zH92Z5plko/i C5jO3PeRotERYy/5TUdVJ2DCFKfdtcBOE8bI9D1p0NrqUlS3/NEOUC/onQ8g06tFTIAV UELogikSO7MurliCu/EHwF3rwCv3u6cAeky53a6VvMgaaHW4i88nvUI0++vll29xKCyC b2Vg== X-Gm-Message-State: ACgBeo0EyVgiJypkWbCUoAqkWjXW481gvKz4hUg8TheOKv/uJddCEXEo LXLHPh5/kTnGqKIs34dbRnc5FA== X-Google-Smtp-Source: AA6agR7LeFpJMNtM6c9XUiw/J7IbjRVlCBe8VY64cYOis9bqpXVB4Axf5LmtfzwzYOzM1CWatp1piQ== X-Received: by 2002:a17:903:2282:b0:174:f9e1:b08c with SMTP id b2-20020a170903228200b00174f9e1b08cmr37203688plh.121.1662438311721; Mon, 05 Sep 2022 21:25:11 -0700 (PDT) From: Sunil V L To: qemu-arm@nongnu.org, qemu-devel@nongnu.org, qemu-riscv@nongnu.org Cc: Peter Maydell , Xiaojuan Yang , Song Gao , Gerd Hoffmann , Palmer Dabbelt , Alistair Francis , Bin Meng , Andrew Jones , Anup Patel , Atish Kumar Patra , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Sunil V L Subject: [PATCH V3 3/3] hw/riscv: virt: Enable booting S-mode firmware from pflash Date: Tue, 6 Sep 2022 09:54:51 +0530 Message-Id: <20220906042451.379611-4-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220906042451.379611-1-sunilvl@ventanamicro.com> References: <20220906042451.379611-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::62f; envelope-from=sunilvl@ventanamicro.com; helo=mail-pl1-x62f.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, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1662439123529100001 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 --- hw/riscv/boot.c | 28 ++++++++++++++++++++++++++++ hw/riscv/virt.c | 17 ++++++++++++++++- include/hw/riscv/boot.h | 1 + 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c index 1ae7596873..39436b8d56 100644 --- a/hw/riscv/boot.c +++ b/hw/riscv/boot.c @@ -338,3 +338,31 @@ 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 b6bbf03f61..b985df9b16 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -1258,7 +1258,22 @@ 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 and -pflash options are provided in command line, + * the kernel, initrd will be copied to fw_cfg table and opensbi + * will jump to flash address which is the entry point of S-mode F= W. + * It is the job of the S-mode FW to load the kernel/initrd and la= unch. + * + * 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