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.122108.1683007188870390540 for ; Mon, 01 May 2023 22:59:49 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ENjCLpH+; 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=1683007187; 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=16J15Bja13XxDsMIdbHVoxdD0bciBxBjTDUYeVr/RIU=; b=ENjCLpH+jHfZnmWksMgG9M5Hy2P7CaC3TJ+R9in3qpJZWdVfx75EOgR4HZmxj2IZWoogSS HL+Y9ceXPSwnwjRvSo842SwnS6Ld+PHqQcCs0t3bNRQGL2r8cORAe2EXV06P7sdq4hDas6 D2+ZI+xd0+vuWdtAL14ftzwlegSFJxw= 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-400-jl5CFTj1MaOHukubB8xpGg-1; Tue, 02 May 2023 01:59:44 -0400 X-MC-Unique: jl5CFTj1MaOHukubB8xpGg-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C407810726A1; Tue, 2 May 2023 05:59:43 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.192.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8E67F4021B1; Tue, 2 May 2023 05:59:43 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 619FA18012CF; Tue, 2 May 2023 07:59:42 +0200 (CEST) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: Pawel Polawski , Gerd Hoffmann , Jiewen Yao , Ard Biesheuvel , Oliver Steffen , Jordan Justen Subject: [PATCH 1/1] OvmfPkg/QemuFlashFvbServicesRuntimeDxe: refine flash detection Date: Tue, 2 May 2023 07:59:42 +0200 Message-Id: <20230502055942.22929-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true Check whenever flash is actually writable. 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.0