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.web11.24848.1685599689660697908 for ; Wed, 31 May 2023 23:08:09 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=U4/OZ6Mp; spf=pass (domain: redhat.com, ip: 170.10.133.124, mailfrom: kraxel@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685599688; 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: content-transfer-encoding:content-transfer-encoding; bh=s7KD6dP7Q0w/KfpEyygggDxbIbwZXcyR8jwvQ2MYEGA=; b=U4/OZ6MpqbxWkd9lZXLoBGL0JpfKsefX37I8EppUK/XNLoES70XOWy9jfZn7Yf9nGZR2fS rX/RjDcnkFmHooMquDSbhPoyslDh0CANRjQPhAujvLWfbEKHL8VX8L6IRJERccQCYPQaSO Tx1HiubJmBJujvv4iia03hWHKASyWBE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-660-dWSX6ISgOfyzg7sM7F69QA-1; Thu, 01 Jun 2023 02:08:05 -0400 X-MC-Unique: dWSX6ISgOfyzg7sM7F69QA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 67FC3810BD9; Thu, 1 Jun 2023 06:08:05 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 271A740C6EC4; Thu, 1 Jun 2023 06:08:05 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id C85F81800626; Thu, 1 Jun 2023 08:08:03 +0200 (CEST) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Oliver Steffen , Jordan Justen , Pawel Polawski , Jiewen Yao , Gerd Hoffmann Subject: [PATCH v2 1/1] OvmfPkg/QemuFlashFvbServicesRuntimeDxe: refine flash detection Date: Thu, 1 Jun 2023 08:08:03 +0200 Message-Id: <20230601060803.183520-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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. 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