From nobody Sun May 5 09:39:59 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=1685543063; cv=none; d=zohomail.com; s=zohoarc; b=UogeNKPUyKmKHB5ozY8k2A+QJ9rBgkJfPJ92Ac3kkD4NT3GHBxYkDtaZpkC6KdB2ZtNk5XXNhoUSA85XAssKIgJqho2kSmrc74GqUKZ5dqdt5wTMVjbzrD/3Ko2G6o68tTSUvTsI/ogO8LxuLKbr1qbQYtXi3csS3T9N259xohw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685543063; 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=FEcYs4t+MOUCygeXNP+05FAocSNvexzRgII5KybofLIZqUNa6YCKRCx1UpvLFz/VDmO60Fqft7WW4JYtIi1OQfAThD0gdlfgLAE9onSt+6r2s8/22AU0vZkf/98tI+/0TcU3x5WiO36ZEIEsen9MIk7sOLWfWEarigClKmgGp4s= 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 168554306354210.632045630997823; Wed, 31 May 2023 07:24:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q4Mjf-0005AF-NM; Wed, 31 May 2023 10:23:35 -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 1q4MjX-00053k-Uj for qemu-devel@nongnu.org; Wed, 31 May 2023 10:23:29 -0400 Received: from mail-oi1-x22b.google.com ([2607:f8b0:4864:20::22b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q4MjQ-0002jn-4h for qemu-devel@nongnu.org; Wed, 31 May 2023 10:23:23 -0400 Received: by mail-oi1-x22b.google.com with SMTP id 5614622812f47-38eb2984c82so2080531b6e.0 for ; Wed, 31 May 2023 07:23:19 -0700 (PDT) Received: from sunil-laptop.dc1.ventanamicro.com ([106.51.186.3]) by smtp.gmail.com with ESMTPSA id a19-20020a05680802d300b00397c07e8061sm574548oid.6.2023.05.31.07.23.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 May 2023 07:23:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1685542998; x=1688134998; 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=nlsvy+HpiKjixYGwJfASjXznLtgvcxCWVeR6QvQEXwD8Qmigd0RsQQd75i7kfY3hYv LFIWkPaw4W1xzEu7dDkSm8MwAkYPb7/OI2wrhRa7SmvCaI9/8zJVb2aV6Kq+tL7+rqKr wU6OdgWowwiO/BTzs/2WVBVVEVHXuY/5AyZN94wbubDcyTZ4MeG7yN8SG5ZZXjWgC7L7 lITyVu+KXgm+k3hwA4WVE8AwNIyA8U1e2yaCQFmFE+vUax2j5i6Ea6Ko1Hj7rYwGaZyB c1HO2I4jEYRLRthtxZNxpcREHsTVXFlyspREvpHnae4NRhFCe+PS0MTLr0MT+hADaycS kGyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685542998; x=1688134998; 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=S/emzs2W9A7xJ+HyFbJkaNeeYppn6FEXYXnMDOvEQUkzC1p+rZX/twZeoz74mHyxY8 Q0DggBG+4cptL5GKlstIJKfXdCQmijIj4PqBwGGqlFVUwMpBe/XDlawKhIXHXXNAC91/ oNVFeis9Or27mZqKqM09+BpV3qhtDd6RyPLe8FUnReOxb8TJbvXlSZqJFwFBTlw+FX2l kqJSGnApM3jgOTdKX4OJgqkB0CDGDnjqi34IrNM5oTQ0It+Km6T94huODwV5F3uS6tWt p4lLYZ9nvZCDDgXIrZlELrKtEMsFiQE/FPiIahdaNE4HkoMVnsJ4TMSYMYoCk+2jWkwq f2Zw== X-Gm-Message-State: AC+VfDxDw0YWonDcBwwfdMMnsCE2UQavJXyqtZCXPN9O3R/ahjUUSmtj n3jletS9YPkID3D+Oubyo7jURg== X-Google-Smtp-Source: ACHHUZ5u1UYIOMDDEfIOErvbcq4SvNx4A+VOLwTECD2Xl4Hmbcqun9M7QfWHNMLPSvxMgzaN5gp1EQ== X-Received: by 2002:a05:6808:245:b0:398:54a2:a9bd with SMTP id m5-20020a056808024500b0039854a2a9bdmr2995041oie.46.1685542998187; Wed, 31 May 2023 07:23:18 -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 v6 1/3] hw/riscv: virt: Assume M-mode FW in pflash0 only when "-bios none" Date: Wed, 31 May 2023 19:52:58 +0530 Message-Id: <20230531142300.9114-2-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230531142300.9114-1-sunilvl@ventanamicro.com> References: <20230531142300.9114-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::22b; envelope-from=sunilvl@ventanamicro.com; helo=mail-oi1-x22b.google.com X-Spam_score_int: -5 X-Spam_score: -0.6 X-Spam_bar: / X-Spam_report: (-0.6 / 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, RCVD_IN_SORBS_WEB=1.5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: 1685543064212100001 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 Sun May 5 09:39:59 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=1685543078; cv=none; d=zohomail.com; s=zohoarc; b=apladiBHpmTyxqHBWRDPJ6171J1FTU+y4KaQxA+suiHDyBmmQ7I4k0/3yEOE6SgxZOmc38Bl87g6ZbqxR+Gw1GwlDiRKtdRAqkDt9L0IzlAMRq8d4szIwmaq4rKgeOA9Q1ZGnMVqR2eFdJ17bh59v51BPHu8g4MQyeMRSrG3NxQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685543078; 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=LHRXf8Agq5DqWSGcYi0OaYwZjF1ICyfEH1fqg6d2A4lpc2Tj9NWWqm+QbQLeS666eck7o7DNTElXRuZW6tFNjG+DMv0vFlLH6TJ+vIbECf/R8QQDlpoKEthOD8/+e5hmOD0XOKoOUuWqE59IvWSA4dEMt06ichERnwZIqjaG/1w= 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 1685543078437424.0738505846707; Wed, 31 May 2023 07:24:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q4Mjg-0005EN-OM; Wed, 31 May 2023 10:23:37 -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 1q4MjZ-000545-RO for qemu-devel@nongnu.org; Wed, 31 May 2023 10:23:31 -0400 Received: from mail-oo1-xc31.google.com ([2607:f8b0:4864:20::c31]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q4MjX-0002kh-NM for qemu-devel@nongnu.org; Wed, 31 May 2023 10:23:29 -0400 Received: by mail-oo1-xc31.google.com with SMTP id 006d021491bc7-557c7ffea48so2540904eaf.1 for ; Wed, 31 May 2023 07:23:24 -0700 (PDT) Received: from sunil-laptop.dc1.ventanamicro.com ([106.51.186.3]) by smtp.gmail.com with ESMTPSA id a19-20020a05680802d300b00397c07e8061sm574548oid.6.2023.05.31.07.23.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 May 2023 07:23:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1685543003; x=1688135003; 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=l+NmEqRlqVYQRt5S0el11LHigb1LLWJ0X5CTKyzXz53ke4wbVWnqf7DSMgUn32DcLe 4gBryK9FctZBndF2Ynem89TzbKnLDa0ZijJ0WOZds8i3zvRHaKlk8TyVpv/MXxCpsFW7 sczTvEhOiHiqI3nyNk8KsNzNFivYX4hVS4C1kNSw2hXtk2osycsMVJY/cJinFt4P7eu/ WcLdgAqXlXz1nEcFTw5SZaz9R8YyRHB556K/lSuynyU3tCQiM4Yd2LvNQiMuqdD9UsY0 EIySgr7LLEeyo7bI25vLqD5y320J6TodeGxCtqyQ1CrW77tOzNlhnk+1yGcVvA0tcgKW 6T6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685543003; x=1688135003; 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=CLHwH+XEmWOBKcjPeiYwg8vKdZ/JOE3aPDRR2PDFprtFp1zsTx+xlgEPmT9c8kY105 r03fGMR8c2zSaWH/q5n20VuDbmLim2Y7R10NsISxdk6lf87TA5VAou8r08j0Qw4AS0u6 RmRTcAiRPT39EyXCY2RLbVfNeU2lxIybDMuosVKEbB/n6X3DOTzuaiQamZyDnKAQ9gY0 bw1AuUwNX1Pncbc6BkbePDt+FXkO85xNsGOdRJUn6cLlH8keeat3fpHR28DtagOIYDS5 RaR+2RmSJXNWjSKLt+f5mmPW5Xh0U69VMjTFULIGZWbDkib/spX50LbNwXoWC/CIaFCk NT7w== X-Gm-Message-State: AC+VfDylFCv284ZmnCcmVKToB3h8xMwyQenIjqEj1ib8J21XF3bR9HKX TSQRytOfy7IgGnYSFlO0JuzhLw== X-Google-Smtp-Source: ACHHUZ40VWyNhmseqQpCpsqyJDMOmeRbzGCWseQz2akmllPrHb2GG37vFhf3igDUukzzknj6eKGE4A== X-Received: by 2002:aca:d957:0:b0:398:2bbb:a2ea with SMTP id q84-20020acad957000000b003982bbba2eamr3996221oig.42.1685543003014; Wed, 31 May 2023 07:23: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 , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v6 2/3] riscv/virt: Support using pflash via -blockdev option Date: Wed, 31 May 2023 19:52:59 +0530 Message-Id: <20230531142300.9114-3-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230531142300.9114-1-sunilvl@ventanamicro.com> References: <20230531142300.9114-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::c31; envelope-from=sunilvl@ventanamicro.com; helo=mail-oo1-xc31.google.com X-Spam_score_int: -5 X-Spam_score: -0.6 X-Spam_bar: / X-Spam_report: (-0.6 / 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, RCVD_IN_SORBS_WEB=1.5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: 1685543079428100001 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 --- 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 Sun May 5 09:39:59 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=1685543084; cv=none; d=zohomail.com; s=zohoarc; b=SEmMNOCQWYPpgNcx+5hLt+d6jwcWzup1/G8uYJsLXXmQsi5EWAVN+JkrKkdBvV0m/MUtWpKCvsQrZAWo1fq0Pu3LG4dhEIXTFs2tHsMWIvhmhsHpXboqYJN1EAr2v9wecw4q6+EmzCNQPbJ/JDaP8jHKiGdsmW9qvTCsGoQVLKY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685543084; 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=wUcoHqBo0RA5TBavH7NT5dA3iOjs4Vli/rrWzbZB0zk=; b=aUGW78AENnC1hJ2MlJ00+7mXpq8qovjgRiwqTABdC54JRCDSzQANViyavJIU1z6J2HolDJcApcWoRyA0sKC9ECHIToO3EkkrVKZmCkhZm9i8EflkzwwT+AsKEuQq6bm7IBOjXvX/27vpiNJ64WrCq6PQl6eSQAIiIjzrN40iEIA= 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 1685543084268612.8081901406123; Wed, 31 May 2023 07:24:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q4Mjg-0005ES-OP; Wed, 31 May 2023 10:23:37 -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 1q4Mjf-0005A5-Jn for qemu-devel@nongnu.org; Wed, 31 May 2023 10:23:35 -0400 Received: from mail-oi1-x234.google.com ([2607:f8b0:4864:20::234]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q4Mjb-0002lZ-GC for qemu-devel@nongnu.org; Wed, 31 May 2023 10:23:34 -0400 Received: by mail-oi1-x234.google.com with SMTP id 5614622812f47-3985f70cf1bso3471580b6e.3 for ; Wed, 31 May 2023 07:23:30 -0700 (PDT) Received: from sunil-laptop.dc1.ventanamicro.com ([106.51.186.3]) by smtp.gmail.com with ESMTPSA id a19-20020a05680802d300b00397c07e8061sm574548oid.6.2023.05.31.07.23.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 May 2023 07:23:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1685543009; x=1688135009; 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=wUcoHqBo0RA5TBavH7NT5dA3iOjs4Vli/rrWzbZB0zk=; b=UBztMMGkRkzsefV0F+b1YDC4D9I9kVKCktNfibbNaxuQgsmiZKdHJ4vaI9V7qnFWKk yiFESqE1+HWVwozK+IcNZgR4PqQXSq2eZTVxvRKAFE8g9krdYA1dUllXGLcdGTPwDVdP puyDJwxIoIbmKUZGSPLqQt1ueUb2MxZgkP/q7lLy0UWqD7rEeIN761SBuPCfQ5oFME4R XxvQvKTSuxzLbzeTAeyO6Z16f57b9GIbLLEH1+sd0md5YLwSb33QpFb+YeByI/9PlD7M B79vCFE8AxElv79S4un874YInQdpwaMpggPfrcMFQOAQTmCnUoLRyvJmmCFh50AtvQYK qJDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685543009; x=1688135009; 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=wUcoHqBo0RA5TBavH7NT5dA3iOjs4Vli/rrWzbZB0zk=; b=QYUOTTpOG40Pd4hYW6s562lU6+yxZavi55fA56fcGfV2RFd9TC+LPe2qpssuUP2vYw 2q/IWw4iNbJKPCrfss8SXeox0z+rEvf6NlwxxaRrvytqnIEDHV1MGJKNLbJre74sWyBR Um4KU9VbgAL3QZaTrYmnPwg8aUsWwu8TP5qXvwj/JaUHaPd8SgIzCOdlsIbQyxqCm1/C h2BcMyT3Jwvvdb6uWS00kj8THJKaet1vqqHN7Rzyp5QsS7U/XkIVFf0HgwbGF/xw/zOi kVI40NKdTQUuO+nkQAaB/LjsvyvSKB6IE0jR7FMThEWj5wk/5ve+ovY2q1U6z/oUr83r FTBg== X-Gm-Message-State: AC+VfDx6AkrBsqV/JwYG7SxZ0zSUNvN0ABGtGxbJ20vzfCtAvhyrGQ/b O9lFQdlOFBl7vdePS27aPQWiWA== X-Google-Smtp-Source: ACHHUZ7tX9F2hgYZWFavsxDqE+P6QsHF4YSQAjWZvtvW89tRF64j8i7F/2Kkmjhl6+9OGJ0C6X1glg== X-Received: by 2002:a54:4e83:0:b0:38e:b9b:a85c with SMTP id c3-20020a544e83000000b0038e0b9ba85cmr3264421oiy.53.1685543007676; Wed, 31 May 2023 07:23: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 v6 3/3] docs/system: riscv: Add pflash usage details Date: Wed, 31 May 2023 19:53:00 +0530 Message-Id: <20230531142300.9114-4-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230531142300.9114-1-sunilvl@ventanamicro.com> References: <20230531142300.9114-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::234; envelope-from=sunilvl@ventanamicro.com; helo=mail-oi1-x234.google.com X-Spam_score_int: -5 X-Spam_score: -0.6 X-Spam_bar: / X-Spam_report: (-0.6 / 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, RCVD_IN_SORBS_WEB=1.5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: 1685543086037100001 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 --- docs/system/riscv/virt.rst | 43 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/docs/system/riscv/virt.rst b/docs/system/riscv/virt.rst index 4b16e41d7f..6c1d4fed3e 100644 --- a/docs/system/riscv/virt.rst +++ b/docs/system/riscv/virt.rst @@ -53,6 +53,49 @@ 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 +------------------- + +When KVM is not enabled, the first flash device (pflash0) can contain eith= er +the ROM code or S-mode payload firmware code. If the pflash0 contains the +ROM code, -bios should be set to none. If -bios is not set to +none, pflash0 is assumed to contain S-mode payload code. + +When KVM is enabled, pflash0 is always assumed to contain the S-mode paylo= ad +firmware. + +Firmware images used for pflash should be of size 32 MiB. + +To boot as ROM code: + +.. 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 .... + +To boot as read-only S-mode payload: + +.. 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 .... + +To boot as read-only S-mode payload in KVM guest: + +.. 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 \ + --enable-kvm \ + ... other args .... + Machine-specific options ------------------------ =20 --=20 2.34.1