From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.groups.io with SMTP id smtpd.web10.25852.1685607755603311973 for ; Thu, 01 Jun 2023 01:22:36 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JRseWCdh; spf=pass (domain: redhat.com, ip: 170.10.133.124, mailfrom: osteffen@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685607754; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=KifjBD0WGeSewWJvUI+DuNGz92nrcZODl8t2hp59/xg=; b=JRseWCdhLca/YHFEYJL2UTvsBjQLmFlSw9NWZ7/merL2rChKle9QF0XFPlY9+Rw6Hl6gBd UmtGkotAcDBuSA4MrETewu3kiJEdcMt58mcRLDsZm5Z7FhZWxaw2/P9tG9KUN0E8MOAli9 Er4u27Rdy+ixgkuQwTcrlWFTa6aFJuU= Received: from mail-lj1-f200.google.com (mail-lj1-f200.google.com [209.85.208.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-46-jy4sJ2BWPXOjTd7EDzyhSg-1; Thu, 01 Jun 2023 04:22:33 -0400 X-MC-Unique: jy4sJ2BWPXOjTd7EDzyhSg-1 Received: by mail-lj1-f200.google.com with SMTP id 38308e7fff4ca-2b1a4be38efso1722251fa.3 for ; Thu, 01 Jun 2023 01:22:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685607752; x=1688199752; h=cc:to:subject:message-id:date:user-agent:from:references :in-reply-to:mime-version:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=KifjBD0WGeSewWJvUI+DuNGz92nrcZODl8t2hp59/xg=; b=GFXPcNHpcvc0UTYVT0Ww7Um55YduR7dIETlMfqe5A8pBmkkV012LcUksBHvHt+TGcP lAvUsmOPprLj79SGQpEd/8BVi3Sr2HyOogV5M/AsjNXe34vrqYoAETEWa0FDrysRxBHe Nmwquo8OnqxQjdf+eWWePpjJFFW/XHGHPAVW7xqVVz4tGWY7DndjbSm4OmBJfnd1UKRI lilrC3nEa0jr3oXHWxgImlP7IgAkVENhwjEFTv/WEt02pNBnzdXI+Ie6RghWfyOkytlV m5ZiDl0BAHUjqI3Zo+a67pbBOAm8RA08c/d7MJrverfiQdgLkB+nZ05/YTdEYSuhIAYu wFog== X-Gm-Message-State: AC+VfDycmnUHbHOEqOoBiRFRrdIR0XNaELmOuVFha5cL13tCy3nsT67D Yz0Rq5p8Zbb4+QJKdPdvcoWBgqBa/NoyffE5tVuC4xDxBdbLOUvzZZ5DbUm9N8Qm4sEJnfMWRnx +uS5NDRT7hHVhKvfO07s51Yr2DsxBIA== X-Received: by 2002:ac2:546d:0:b0:4f1:4526:1d80 with SMTP id e13-20020ac2546d000000b004f145261d80mr759310lfn.50.1685607752003; Thu, 01 Jun 2023 01:22:32 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7oKqAuErczn5b+3QYSysU2FZGLR4CmaDqJC7rFeYefPxlbnMAnYHA040AtOOyNM5hgBGVhvQ219kx3R8LMM8I= X-Received: by 2002:ac2:546d:0:b0:4f1:4526:1d80 with SMTP id e13-20020ac2546d000000b004f145261d80mr759299lfn.50.1685607751694; Thu, 01 Jun 2023 01:22:31 -0700 (PDT) Received: from 567203818698 named unknown by gmailapi.google.com with HTTPREST; Thu, 1 Jun 2023 01:22:31 -0700 MIME-Version: 1.0 In-Reply-To: <20230601060803.183520-1-kraxel@redhat.com> References: <20230601060803.183520-1-kraxel@redhat.com> From: "Oliver Steffen" User-Agent: alot/0.8.1 Date: Thu, 1 Jun 2023 01:22:31 -0700 Message-ID: Subject: Re: [PATCH v2 1/1] OvmfPkg/QemuFlashFvbServicesRuntimeDxe: refine flash detection To: Gerd Hoffmann , devel@edk2.groups.io Cc: Ard Biesheuvel , Jordan Justen , Pawel Polawski , Jiewen Yao X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Quoting Gerd Hoffmann (2023-06-01 08:08:03) > Flash can be write-protected in qemu (which is usually the case for > code). In case the variable store flash block is configured read-only > ovmf wouldn't be able to store EFI variables there, so not setting up > fvb in that case (and fallhack to emulation) is the better option. I like the term "fallhack", I'll keep that in mind for future use >,< > It'll avoid problems later due to flash writes failing. > > The patch tries to write back the original value read earlier, so flash > content doesn't change in case the write succeeds. But the status we > read back after the attempt to write will tell us whenever flash is > writable or not. > > Signed-off-by: Gerd Hoffmann > --- > OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c | 14 +++++++++++--- > 1 file changed, 11 insertions(+), 3 deletions(-) > > diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c > index 54f859de9ff9..a577aea55614 100644 > --- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c > +++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c > @@ -114,9 +114,17 @@ QemuFlashDetected ( > DEBUG ((DEBUG_INFO, "QemuFlashDetected => FD behaves as RAM\n")); > *Ptr = OriginalUint8; > } else if (ProbeUint8 == CLEARED_ARRAY_STATUS) { > - DEBUG ((DEBUG_INFO, "QemuFlashDetected => FD behaves as FLASH\n")); > - FlashDetected = TRUE; > - *Ptr = READ_ARRAY_CMD; > + *Ptr = WRITE_BYTE_CMD; > + *Ptr = OriginalUint8; > + *Ptr = READ_STATUS_CMD; > + ProbeUint8 = *Ptr; > + *Ptr = READ_ARRAY_CMD; > + if (ProbeUint8 & 0x10 /* programming error */) { > + DEBUG ((DEBUG_INFO, "QemuFlashDetected => FD behaves as FLASH, write-protected\n")); > + } else { > + DEBUG ((DEBUG_INFO, "QemuFlashDetected => FD behaves as FLASH, writable\n")); > + FlashDetected = TRUE; > + } > } > } > > -- > 2.40.1 > - Oliver