From nobody Fri May 3 11:39:35 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=1685595630; cv=none; d=zohomail.com; s=zohoarc; b=UfSy0SIniQZFeS7cYli+JvKSVPWLge/2a2l9d1OqJWokJxHoTy3X7bTBvbmIIdBVIrafTlnTVhBA3nJf0D7kVDTysrBpMhJ7RqXdoo1GL9eLlHbpIgixbfrSckh8mCgli6cZHUFPHYU7wgYKBndh8zG4+9n3xMca5a9x4I6D6mo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685595630; 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=rb2DFlL8NbWJDkaOWudgl6M+ct2AD91DAIzG07niuWc=; b=DWFLr3XXFlsiM3gWiqFASrsKY8TDWiS0Yr4TVR6Qnue1iiaBG+1eIleH9JeJ3SffiZcQHPDA0F/frisWs0KFzEIO+ifdYmBYh1tAovXERYlMa7dpL/wGS5tjJxpZMPTXSbgv6sAWCJQAq5lJVmcoeGckt5Hs6ctk+hB+k453yUc= 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 1685595630342809.945353139586; Wed, 31 May 2023 22:00:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q4aPH-0004gw-U5; Thu, 01 Jun 2023 00:59:27 -0400 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 1q4aPF-0004g6-SE for qemu-devel@nongnu.org; Thu, 01 Jun 2023 00:59:25 -0400 Received: from mail-oo1-xc34.google.com ([2607:f8b0:4864:20::c34]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q4aPE-0006ED-46 for qemu-devel@nongnu.org; Thu, 01 Jun 2023 00:59:25 -0400 Received: by mail-oo1-xc34.google.com with SMTP id 006d021491bc7-557ca32515eso346248eaf.3 for ; Wed, 31 May 2023 21:59:23 -0700 (PDT) Received: from sunil-laptop.dc1.ventanamicro.com ([106.51.83.242]) by smtp.gmail.com with ESMTPSA id f8-20020a4ab648000000b0055530a42ce3sm3985608ooo.34.2023.05.31.21.59.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 May 2023 21:59:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1685595563; x=1688187563; 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=rb2DFlL8NbWJDkaOWudgl6M+ct2AD91DAIzG07niuWc=; b=aZEjXWrgOnQVmffdpIG7O/25uRlM+I+DFWckgXbPAYPfZmmmllxv5ThVgV1JcHNP9n a511EbujzRPOYbS/fCHRrL0n5GVgYtBczYllGv2If5OV7rg8AGG+jTkNBJ5iBuq8hetG WeksvTCASx2goHnPWkAaGdQZTQT9rXwH3PhhPqunkHmlquxU/NoGt40YrbxeGCUkI6h1 XNFxZ/FaALUNmU2mXcdry509ZJ/A64UUMN4JHYrwgN2xEV7G0zDhIEbH9TE2irDu9JBg U6a3SudWbfbEi6L3oD9ix9nbvwns4Bx/o9Cp2BUVXOAHSEf06CLojSNp+94gDDiSBJ9T aQyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685595563; x=1688187563; 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=rb2DFlL8NbWJDkaOWudgl6M+ct2AD91DAIzG07niuWc=; b=Y0E+r+M9IIOfeVridhlr0CEVNKRYC26S6VCm4g9eS9cBKDeGcTqHVeOWu426GuDVRO d/RlBBUmKzH8I5CPeTdq0JFBZC/e8rXyc42o6ViB0SYEiA9kXQsutEMfUl4zPjTdGHeJ r5SESiycKjCIKvouWpbCtlQA0D8l9XSzsbnBnaKaNzLonlEWr1ipIx4qJojzfV7kPV5w 5k32HkoJtH2qZo6pKlzaXpxoEMPhftr/p/EyuRM2KXDcC5BL06gSaBoYCbTi3e/c15R/ c6iB7LVT08AcVSy6IkalwxZG65sW/ATYuFBOHuxNIOK6+8bUW952/KKHZKow8QIR42g7 1uHw== X-Gm-Message-State: AC+VfDxXX1ylaLZ6nHevHAm2O6z9HizIHsDIagZh/LasTZW++vOUV+YV 6sKeHi1YONc9gT9bHD/4nwgRTw== X-Google-Smtp-Source: ACHHUZ5NzMMtAH2dPHnDuqfO+fZ2Q3WBcI74JOCYBxF2IvB3VIN/bsK1pGoyWfhVJVRzey6qSgkMIQ== X-Received: by 2002:a4a:4146:0:b0:54f:49ad:1c93 with SMTP id x67-20020a4a4146000000b0054f49ad1c93mr4443359ooa.0.1685595563477; Wed, 31 May 2023 21:59:23 -0700 (PDT) From: Sunil V L To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: Palmer Dabbelt , Alistair Francis , Bin Meng , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , Andrea Bolognani , Sunil V L , Heinrich Schuchardt Subject: [PATCH v7 1/3] hw/riscv: virt: Assume M-mode FW in pflash0 only when "-bios none" Date: Thu, 1 Jun 2023 10:29:08 +0530 Message-Id: <20230601045910.18646-2-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230601045910.18646-1-sunilvl@ventanamicro.com> References: <20230601045910.18646-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::c34; envelope-from=sunilvl@ventanamicro.com; helo=mail-oo1-xc34.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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1685595632010100009 Content-Type: text/plain; charset="utf-8" Currently, virt machine supports two pflash instances each with 32MB size. However, the first pflash is always assumed to contain M-mode firmware and reset vector is set to this if enabled. Hence, for S-mode payloads like EDK2, only one pflash instance is available for use. This means both code and NV variables of EDK2 will need to use the same pflash. The OS distros keep the EDK2 FW code as readonly. When non-volatile variables also need to share the same pflash, it is not possible to keep it as readonly since variables need write access. To resolve this issue, the code and NV variables need to be separated. But in that case we need an extra flash. Hence, modify the convention for non-KVM guests such that, pflash0 will contain the M-mode FW only when "-bios none" option is used. Otherwise, pflash0 will contain the S-mode payload FW. This enables both pflash instances available for EDK2 use. When KVM is enabled, pflash0 is always assumed to contain the S-mode payload firmware only. Example usage: 1) pflash0 containing M-mode FW qemu-system-riscv64 -bios none -pflash -machine virt or qemu-system-riscv64 -bios none \ -drive file=3D,if=3Dpflash,format=3Draw,unit=3D0 -machine virt 2) pflash0 containing S-mode payload like EDK2 qemu-system-riscv64 -pflash -pflash -machine = virt or qemu-system-riscv64 -bios \ -pflash \ -pflash \ -machine virt or qemu-system-riscv64 -bios \ -drive file=3D,if=3Dpflash,format=3Draw,unit=3D0,readonly=3D= on \ -drive file=3D,if=3Dpflash,format=3Draw,unit=3D1 \ -machine virt Signed-off-by: Sunil V L Reported-by: Heinrich Schuchardt Tested-by: Andrea Bolognani Reviewed-by: Alistair Francis --- hw/riscv/virt.c | 53 ++++++++++++++++++++----------------------------- 1 file changed, 21 insertions(+), 32 deletions(-) diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index 4e3efbee16..3e5dc649c3 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -1245,7 +1245,7 @@ static void virt_machine_done(Notifier *notifier, voi= d *data) target_ulong firmware_end_addr, kernel_start_addr; const char *firmware_name =3D riscv_default_firmware_name(&s->soc[0]); uint32_t fdt_load_addr; - uint64_t kernel_entry; + uint64_t kernel_entry =3D 0; =20 /* * Only direct boot kernel is currently supported for KVM VM, @@ -1266,42 +1266,31 @@ static void virt_machine_done(Notifier *notifier, v= oid *data) firmware_end_addr =3D riscv_find_and_load_firmware(machine, firmware_n= ame, start_addr, NULL); =20 - 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) { + if (drive_get(IF_PFLASH, 0, 0)) { + if (machine->firmware && !strcmp(machine->firmware, "none") && + !kvm_enabled()) { + /* + * Pflash was supplied but bios is none and not KVM guest, + * let's overwrite the address we jump to after reset to + * the base of the flash. + */ + start_addr =3D virt_memmap[VIRT_FLASH].base; + } else { + /* + * Pflash was supplied but either KVM guest or bios is not non= e. + * In this case, base of the flash would contain S-mode payloa= d. + */ + riscv_setup_firmware_boot(machine); + kernel_entry =3D virt_memmap[VIRT_FLASH].base; + } + } + + if (machine->kernel_filename && !kernel_entry) { kernel_start_addr =3D riscv_calc_kernel_start_addr(&s->soc[0], firmware_end_addr= ); =20 kernel_entry =3D riscv_load_kernel(machine, &s->soc[0], kernel_start_addr, true, NULL); - } else { - /* - * If dynamic firmware is used, it doesn't know where is the next m= ode - * if kernel argument is not set. - */ - kernel_entry =3D 0; - } - - if (drive_get(IF_PFLASH, 0, 0)) { - /* - * Pflash was supplied, let's overwrite the address we jump to aft= er - * reset to the base of the flash. - */ - start_addr =3D virt_memmap[VIRT_FLASH].base; } =20 fdt_load_addr =3D riscv_compute_fdt_addr(memmap[VIRT_DRAM].base, --=20 2.34.1 From nobody Fri May 3 11:39:35 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=1685595661; cv=none; d=zohomail.com; s=zohoarc; b=NAiaYysHntfBV6tr2Cut5img3nPRPx+kTnemx/iHn2ybGg8YQhRtfDGx/nRP/zDd9ChHH1bMLK2kfCS7yiwpM7TZPjLFNApYLzmQ0Xga30nGuldIm332sXWpoqX4CFJ0OG6gfMjvcITztP30Fp+RCVv6SqNjhjk9b3Tmn/zMfs8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685595661; h=Content-Type: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=oyoyB7K4g21QQhSn1QlP7nYODAnnSF7DtjAfnzuKxh8=; b=Qe5LeKPXCAE+od/4RWgxeuho133TQ7/Q0ym22E3XFfbmrkVmUfR2ZH/WBKbeOFoCjwGnNO2wbedPH4pTvIwANnZGkpKMfNmJp5s8tNA1+qlsiKMHZXfB7DPlzE/HEXITOp073kOWBP+M5LzbDlyU2QXjW68IR3rmUAAt35SsF8c= 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 1685595661923977.5024688731537; Wed, 31 May 2023 22:01:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q4aPL-0004hP-Ja; Thu, 01 Jun 2023 00:59:31 -0400 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 1q4aPK-0004h3-5n for qemu-devel@nongnu.org; Thu, 01 Jun 2023 00:59:30 -0400 Received: from mail-oi1-x22a.google.com ([2607:f8b0:4864:20::22a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q4aPI-0006Fs-Je for qemu-devel@nongnu.org; Thu, 01 Jun 2023 00:59:29 -0400 Received: by mail-oi1-x22a.google.com with SMTP id 5614622812f47-399dfeeb96aso1244794b6e.1 for ; Wed, 31 May 2023 21:59:28 -0700 (PDT) Received: from sunil-laptop.dc1.ventanamicro.com ([106.51.83.242]) by smtp.gmail.com with ESMTPSA id f8-20020a4ab648000000b0055530a42ce3sm3985608ooo.34.2023.05.31.21.59.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 May 2023 21:59:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1685595567; x=1688187567; 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=oyoyB7K4g21QQhSn1QlP7nYODAnnSF7DtjAfnzuKxh8=; b=iStWuPd/ZdyAwT5tJAOGFylL8FZTehQaTZVaCUESCggHGli9nMzJgZbA3poalAYPsC GsKJ2l1FFSMB/SYGqCMfgv4Q8aVC42XXayNb4zX9PR3Y+2Jotubb7Atn0XX8SPc1kE1y M4efPpUPdDagznc6Jnd4rI3c/8EAJT/IO9fpbdCegjfimyp8Phil1CQPFefn/MduALaY ZUQfcSItlZfdzMlax1jm/3Jeksw/i8WYOOHr0fysHZf/ZCMR3+qWR+CQZcxejQRZzQwX FUARh7N5kn9muKsfdGtRKfJPkc1YCE8SQtED+mu9fJc6Bd5YWZ0hwzH9KjLcgt43klUn flvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685595567; x=1688187567; 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=oyoyB7K4g21QQhSn1QlP7nYODAnnSF7DtjAfnzuKxh8=; b=AJGzn4ssOu1GoSIZgStUHvMl35Ag0Ph5S3UQbSEUlZYLsT+Cfu2Noe299fj+zNhhF5 SI8mkqUUb0FJqEfLvu13aXY8COXGaz7A+be+5Fe5KuGgf13lO7jrKf54soHsxsYjjid5 GI68OJOLtO5M7NR7lSe+qCnjyhiBKtuu53SH4L1SsldsIQwM70qW2pH7xM/B5Dsxnpe6 Z0CZGv2/s3qhkyLdzx0p5lCTsKLbWDJ4bOhkoQJhK/e7aeNvIuJ8opeQpMj0eia4R97I Gi0afeXoFUAR0O0Vcg66yU2fdgUV1t7Cj8tEJ0qGmHDXKZvFazaotqTRaSGUQ+6ZkIq0 t1jw== X-Gm-Message-State: AC+VfDzI9t0xKRU6oSd9yzuow5Nrrn8JVyo2TOpFOx/mslxDRN/HMejB ik717/cgyq+moLqMhIJ04OyKTQ== X-Google-Smtp-Source: ACHHUZ4D42p+GckBZGX5URxMgag/IQD4kTK9F838EilvOsS8slAUN15yW7Lbq9ZcdXwR8IasmbnWBw== X-Received: by 2002:aca:e1c4:0:b0:39a:4439:2626 with SMTP id y187-20020acae1c4000000b0039a44392626mr413859oig.2.1685595567520; Wed, 31 May 2023 21:59:27 -0700 (PDT) From: Sunil V L To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: Palmer Dabbelt , Alistair Francis , Bin Meng , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , Andrea Bolognani , Sunil V L , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v7 2/3] riscv/virt: Support using pflash via -blockdev option Date: Thu, 1 Jun 2023 10:29:09 +0530 Message-Id: <20230601045910.18646-3-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230601045910.18646-1-sunilvl@ventanamicro.com> References: <20230601045910.18646-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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::22a; envelope-from=sunilvl@ventanamicro.com; helo=mail-oi1-x22a.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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1685595662151100001 Currently, pflash devices can be configured only via -pflash or -drive options. This is the legacy way and the better way is to use -blockdev as in other architectures. libvirt also has moved to use -blockdev method. To support -blockdev option, pflash devices need to be created in instance_init itself. So, update the code to move the virt_flash_create() to instance_init. Also, use standard interfaces to detect whether pflash0 is configured or not. Signed-off-by: Sunil V L Reported-by: Andrea Bolognani Tested-by: Andrea Bolognani Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis --- hw/riscv/virt.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index 3e5dc649c3..76c7a3ba3b 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -1246,6 +1246,7 @@ static void virt_machine_done(Notifier *notifier, voi= d *data) const char *firmware_name =3D riscv_default_firmware_name(&s->soc[0]); uint32_t fdt_load_addr; uint64_t kernel_entry =3D 0; + BlockBackend *pflash_blk0; =20 /* * Only direct boot kernel is currently supported for KVM VM, @@ -1266,7 +1267,8 @@ static void virt_machine_done(Notifier *notifier, voi= d *data) firmware_end_addr =3D riscv_find_and_load_firmware(machine, firmware_n= ame, start_addr, NULL); =20 - if (drive_get(IF_PFLASH, 0, 0)) { + pflash_blk0 =3D pflash_cfi01_get_blk(s->flash[0]); + if (pflash_blk0) { if (machine->firmware && !strcmp(machine->firmware, "none") && !kvm_enabled()) { /* @@ -1499,8 +1501,6 @@ static void virt_machine_init(MachineState *machine) sysbus_create_simple("goldfish_rtc", memmap[VIRT_RTC].base, qdev_get_gpio_in(DEVICE(mmio_irqchip), RTC_IRQ)); =20 - virt_flash_create(s); - for (i =3D 0; i < ARRAY_SIZE(s->flash); i++) { /* Map legacy -drive if=3Dpflash to machine properties */ pflash_cfi01_legacy_drive(s->flash[i], @@ -1527,6 +1527,8 @@ static void virt_machine_instance_init(Object *obj) { RISCVVirtState *s =3D RISCV_VIRT_MACHINE(obj); =20 + virt_flash_create(s); + s->oem_id =3D g_strndup(ACPI_BUILD_APPNAME6, 6); s->oem_table_id =3D g_strndup(ACPI_BUILD_APPNAME8, 8); s->acpi =3D ON_OFF_AUTO_AUTO; --=20 2.34.1 From nobody Fri May 3 11:39:35 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=1685595630; cv=none; d=zohomail.com; s=zohoarc; b=cAT7qyoHjOERUDdnMU/1AftgB5v7dOvubW/p8QuVeb8YoO7Jk4O5SChF+5sP2C585QCL6dC5OvgcN+1AV2uzWYOz9Fjz6QSf6c2zKVplfu7OTVxIkCiHfNrtieZYFAzrm/bjlxbl7Nq9nVpfeN8ELU3wtq+/SQBl1rKDLJ2TsQI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685595630; h=Content-Type: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=oUp0Hkzi0ARsGZ5vAJModrlI2+NQ/dPTpIk4U6SEfYA=; b=UH74kk2cz+Wjxo8tqc5YiSHdRuU8A3hr+Z4i2F3zELgt+P/Ag4YKtwmQpRnzFa4mcO8w0DNpLGUAeHs1/fkFu8A9P+vzy0HrAjFuZGhnHVrcNccW410rxFK18GSPIQYt+OgALumsmfo50hQQwY72T6DSnTiFd5SqbQTfqoS2R20= 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 1685595630325734.7035843794603; Wed, 31 May 2023 22:00:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q4aPb-0004kt-N5; Thu, 01 Jun 2023 00:59:47 -0400 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 1q4aPZ-0004kQ-77 for qemu-devel@nongnu.org; Thu, 01 Jun 2023 00:59:46 -0400 Received: from mail-oo1-xc2f.google.com ([2607:f8b0:4864:20::c2f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q4aPM-0006GO-Ph for qemu-devel@nongnu.org; Thu, 01 Jun 2023 00:59:44 -0400 Received: by mail-oo1-xc2f.google.com with SMTP id 006d021491bc7-55554c33bf3so354304eaf.2 for ; Wed, 31 May 2023 21:59:32 -0700 (PDT) Received: from sunil-laptop.dc1.ventanamicro.com ([106.51.83.242]) by smtp.gmail.com with ESMTPSA id f8-20020a4ab648000000b0055530a42ce3sm3985608ooo.34.2023.05.31.21.59.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 May 2023 21:59:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1685595571; x=1688187571; 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=oUp0Hkzi0ARsGZ5vAJModrlI2+NQ/dPTpIk4U6SEfYA=; b=FOYIwsAzcPtI4cc9Rl3YwU+KWJ+shgFScyAePagcPF4VarTqbmusT0LfYdD6Gg6EoX mwAPtJF23rBSYvSzrNXMgAnD/tiQSCiPxI9Y/XwQ+5ua08iIu1TzzniossdCfykW/QRZ d7jn+5IvRCF1QtFQ/7wDPARiWetFGQmlt/knnA82co0XwCG4vfdGRcCkZ11yIuVAsEda u95EW+CGnjIPuILTof7mga2fPK9346dBK5eAoeKnp6NyFiHaWUsZyvuzP4V4dCZJQDXZ wbNyHjq0504sJ9872QVODwwVC1d49GB7CjHIwSxep4KMOLErRqyCU688oLam4FwuP9eG 5m3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685595571; x=1688187571; 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=oUp0Hkzi0ARsGZ5vAJModrlI2+NQ/dPTpIk4U6SEfYA=; b=X+yFRQ8chbVK6QuUSqizOrquBPbAiEkcdc98Mltpx2ElitVX7lbdcxBvGkzJaSk59E oHMiZ4/c5VMZ9dYyreUgopo81F0oIAdBruDckEmByqff27U9FpJ981B/RxZVbH3Z2EuB Rjf5Z023DPpMNwLp1rUi//y703aFmAXh08mqHuz3MPFpKgb3emtKDZz3MP50jpHqmBrU peXMqL+8REVVFrC6jcT+JBO5JOKEUDDcYuN5uKGWw7QiQNLQAWKlCYUPvWHLnWRMZY6N N2APQX3o9rgANfLxBmnuQwOSthI/kosaxn9tAvadPDqMoZ1VJw2wryUZirT+VIo1vXm1 F+BQ== X-Gm-Message-State: AC+VfDw1JEGKE2zctQ+Jnhu3R7sZ02dILWkKxIhcc7rhJP3Z9uBgjY3g wXpTzn2HRyh+WKLWwSF9qV+pQA== X-Google-Smtp-Source: ACHHUZ4RyYaSL3n9YE+qi6jw+L4Za0LHXhPxtaRgwUim6/Hm5RmboIdxZpcssZVNNMme7vNHkjTe/w== X-Received: by 2002:a4a:97ed:0:b0:555:2ba8:a75b with SMTP id x42-20020a4a97ed000000b005552ba8a75bmr4537638ooi.1.1685595571577; Wed, 31 May 2023 21:59:31 -0700 (PDT) From: Sunil V L To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: Palmer Dabbelt , Alistair Francis , Bin Meng , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , Andrea Bolognani , Sunil V L , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v7 3/3] docs/system: riscv: Add pflash usage details Date: Thu, 1 Jun 2023 10:29:10 +0530 Message-Id: <20230601045910.18646-4-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230601045910.18646-1-sunilvl@ventanamicro.com> References: <20230601045910.18646-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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::c2f; envelope-from=sunilvl@ventanamicro.com; helo=mail-oo1-xc2f.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=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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1685595630955100002 pflash devices can be used in virt machine for different purposes like for ROM code or S-mode FW payload. Add a section in the documentation on how to use pflash devices for different purposes. Signed-off-by: Sunil V L Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis --- docs/system/riscv/virt.rst | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/docs/system/riscv/virt.rst b/docs/system/riscv/virt.rst index 4b16e41d7f..b33f45e5b3 100644 --- a/docs/system/riscv/virt.rst +++ b/docs/system/riscv/virt.rst @@ -53,6 +53,37 @@ with the default OpenSBI firmware image as the -bios. It= also supports the recommended RISC-V bootflow: U-Boot SPL (M-mode) loads OpenSBI fw_dyna= mic firmware and U-Boot proper (S-mode), using the standard -bios functionalit= y. =20 +Using flash devices +------------------- + +By default, the first flash device (pflash0) is expected to contain +S-mode firmware code. It can be configured as read-only, with the +second flash device (pflash1) available to store configuration data. + +For example, booting edk2 looks like + +.. code-block:: bash + + $ qemu-system-riscv64 \ + -blockdev node-name=3Dpflash0,driver=3Dfile,read-only=3Don,filename= =3D \ + -blockdev node-name=3Dpflash1,driver=3Dfile,filename=3D \ + -M virt,pflash0=3Dpflash0,pflash1=3Dpflash1 \ + ... other args .... + +For TCG guests only, it is also possible to boot M-mode firmware from +the first flash device (pflash0) by additionally passing ``-bios +none``, as in + +.. code-block:: bash + + $ qemu-system-riscv64 \ + -bios none \ + -blockdev node-name=3Dpflash0,driver=3Dfile,read-only=3Don,filename= =3D \ + -M virt,pflash0=3Dpflash0 \ + ... other args .... + +Firmware images used for pflash must be exactly 32 MiB in size. + Machine-specific options ------------------------ =20 --=20 2.34.1