From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web11.26667.1685610437847212099 for ; Thu, 01 Jun 2023 02:07:18 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JUT+P4xl; spf=pass (domain: kernel.org, ip: 139.178.84.217, mailfrom: ardb@kernel.org) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3041C61261 for ; Thu, 1 Jun 2023 09:07:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 97618C4339B for ; Thu, 1 Jun 2023 09:07:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685610436; bh=+VPil17UNyk7tzBl1sKAnEX9WbPG3J2Z65F333V84aM=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=JUT+P4xlQjO/RcA85wIlPqsZyreH50QSGovaR5TseJ2bCnLHtZOBrCin38+tJcDe3 Fwh8wq3YMYR7fdxmZPgwIkE/Z7UzpLrp8Y9PYYq5KT+vAvlv72PZ/xQCau4b4ox2E/ WIFo9B5q7XGo+TwuxRG1slZ46uHiKSAxq6Fru0RUYNyT+9utNHWPCflIBJ55cO3PUl m8t8Xz4gMxZj1V2eyWKRuxttISd3yYy+d6oEITW/zncPO//MfFJycSRDg3vBtDmNlX 7V9KBBeVm719B0AbSHAOIsS0ajlJoI0rEWvVfmFs7eD1sWvSk8hNmAYGjgbaz8RwgC C7KwNwSmByFYA== Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-4f4f8b94c06so662563e87.1 for ; Thu, 01 Jun 2023 02:07:16 -0700 (PDT) X-Gm-Message-State: AC+VfDzDm4tdNl7ihodShVRS7M9ULLVFdL8ii2vogxCPxGFxOsNPG/cs XnbfRcCdTvloNeVPn4sPUy9zjH07qxQSXyfyouM= X-Google-Smtp-Source: ACHHUZ45qcWh7370pF6FHlnZpuQ/YQSd5r8OsWRmTjiP6dB1i6zCjjneqdX9510aLZubJgxuOkPfZLSD5G8xo56VpDM= X-Received: by 2002:a2e:b2d0:0:b0:2ad:509a:22b8 with SMTP id 16-20020a2eb2d0000000b002ad509a22b8mr3973918ljz.16.1685610434618; Thu, 01 Jun 2023 02:07:14 -0700 (PDT) MIME-Version: 1.0 References: <20230601060803.183520-1-kraxel@redhat.com> In-Reply-To: From: "Ard Biesheuvel" Date: Thu, 1 Jun 2023 11:07:03 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 1/1] OvmfPkg/QemuFlashFvbServicesRuntimeDxe: refine flash detection To: Oliver Steffen Cc: Gerd Hoffmann , devel@edk2.groups.io, Ard Biesheuvel , Jordan Justen , Pawel Polawski , Jiewen Yao Content-Type: text/plain; charset="UTF-8" On Thu, 1 Jun 2023 at 10:22, Oliver Steffen wrote: > > 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 >,< > +1 Merged as #4461 > > 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 >